@@ -327,6 +327,8 @@ MCButton::MCButton()
327327
328328 // MM-2014-07-31: [[ ThreadedRendering ]] Used to ensure the default button animate message is only posted from a single thread.
329329 m_animate_posted = false ;
330+
331+ m_menu_handler = nil;
330332}
331333
332334MCButton::MCButton (const MCButton &bref) : MCControl(bref)
@@ -378,6 +380,8 @@ MCButton::MCButton(const MCButton &bref) : MCControl(bref)
378380
379381 // MM-2014-07-31: [[ ThreadedRendering ]] Used to ensure the default button animate message is only posted from a single thread.
380382 m_animate_posted = false ;
383+
384+ m_menu_handler = nil;
381385}
382386
383387MCButton::~MCButton ()
@@ -732,7 +736,7 @@ Boolean MCButton::kdown(MCStringRef p_string, KeySym key)
732736 flags |= F_LABEL ;
733737 if (entry != NULL )
734738 entry->settext (0 , *t_pick, False);
735- Exec_stat es = message_with_valueref_args (MCM_menu_pick, *t_pick);
739+ Exec_stat es = handlemenupick ( *t_pick, nil );
736740 if (es == ES_NOT_HANDLED || es == ES_PASS )
737741 message_with_args (MCM_mouse_up, menubutton);
738742 // MW-2011-08-18: [[ Layers ]] Invalidate the whole object.
@@ -766,7 +770,7 @@ Boolean MCButton::kdown(MCStringRef p_string, KeySym key)
766770 t_label = mbptr->getlabeltext ();
767771
768772 menu->menukdown (p_string, key, &t_pick, menuhistory);
769- Exec_stat es = message_with_valueref_args (MCM_menu_pick, t_label );
773+ Exec_stat es = handlemenupick (t_label, nil );
770774 if (es == ES_NOT_HANDLED || es == ES_PASS )
771775 message_with_args (MCM_mouse_up, menubutton);
772776 }
@@ -1190,7 +1194,7 @@ Boolean MCButton::mdown(uint2 which)
11901194 setmenuhistoryprop (starttab + 1 );
11911195 // MW-2011-08-18: [[ Layers ]] Invalidate the whole object.
11921196 layer_redrawall ();
1193- message_with_valueref_args (MCM_menu_pick, t_tab, t_oldhist);
1197+ handlemenupick ( t_tab, t_oldhist);
11941198 }
11951199 }
11961200 }
@@ -1452,7 +1456,7 @@ Boolean MCButton::mup(uint2 which, bool p_release)
14521456 setmenuhistoryprop (starttab + 1 );
14531457 // MW-2011-08-18: [[ Layers ]] Invalidate the whole object.
14541458 layer_redrawall ();
1455- message_with_valueref_args (MCM_menu_pick, t_tab, t_oldhist);
1459+ handlemenupick ( t_tab, t_oldhist);
14561460 }
14571461 }
14581462 else
@@ -2882,7 +2886,7 @@ void MCButton::activate(Boolean notify, KeySym p_key)
28822886 else
28832887 {
28842888 if (!t_disabled)
2885- message_with_valueref_args (MCM_menu_pick, *t_pick);
2889+ handlemenupick ( *t_pick, nil );
28862890 }
28872891 }
28882892 else
@@ -3576,6 +3580,25 @@ Boolean MCButton::findmenu(bool p_just_for_accel)
35763580 return menu != NULL ;
35773581}
35783582
3583+ void MCButton::setmenuhandler (MCButtonMenuHandler *p_handler)
3584+ {
3585+ m_menu_handler = p_handler;
3586+ }
3587+
3588+ Exec_stat MCButton::handlemenupick (MCValueRef p_pick, MCValueRef p_old_pick)
3589+ {
3590+ if (m_menu_handler != nil)
3591+ {
3592+ if (m_menu_handler->OnMenuPick (this , p_pick, p_old_pick))
3593+ return ES_NORMAL ;
3594+ }
3595+
3596+ if (p_old_pick == nil)
3597+ return message_with_valueref_args (MCM_menu_pick, p_pick);
3598+ else
3599+ return message_with_valueref_args (MCM_menu_pick, p_pick, p_old_pick);
3600+ }
3601+
35793602bool MCSystemPick (MCStringRef p_options, bool p_use_checkmark, uint32_t p_initial_index, uint32_t & r_chosen_index, MCRectangle p_button_rect);
35803603
35813604void MCButton::openmenu (Boolean grab)
@@ -3625,7 +3648,7 @@ void MCButton::openmenu(Boolean grab)
36253648 &t_label);
36263649 MCValueAssign (label, *t_label);
36273650 flags |= F_LABEL ;
3628- message_with_valueref_args (MCM_menu_pick, *t_label);
3651+ handlemenupick ( *t_label, nil );
36293652 }
36303653 return ;
36313654 }
@@ -3792,13 +3815,16 @@ void MCButton::docascade(MCStringRef p_pick)
37923815
37933816 if (pptr != this )
37943817 {
3795- MCParameter *param = new MCParameter;
3796- param->setvalueref_argument (*t_pick);
3797- MCscreen->addmessage (pptr, MCM_menu_pick, MCS_time (), param);
3818+ if (m_menu_handler != nil && !m_menu_handler->OnMenuPick (pptr, *t_pick, nil))
3819+ {
3820+ MCParameter *param = new MCParameter;
3821+ param->setvalueref_argument (*t_pick);
3822+ MCscreen->addmessage (pptr, MCM_menu_pick, MCS_time (), param);
3823+ }
37983824 }
37993825 else
38003826 {
3801- Exec_stat es = pptr->message_with_valueref_args (MCM_menu_pick, *t_pick);
3827+ Exec_stat es = pptr->handlemenupick ( *t_pick, nil );
38023828 if (es == ES_NOT_HANDLED || es == ES_PASS )
38033829 pptr->message_with_args (MCM_mouse_up, menubutton);
38043830 }
@@ -4096,7 +4122,7 @@ void MCButton::setmenuhistory(int2 newline)
40964122
40974123 MCStringRef t_which;
40984124 t_builder.GetPickString (t_which);
4099- message_with_valueref_args (MCM_menu_pick, t_which );
4125+ handlemenupick (t_which, nil );
41004126
41014127 resetlabel ();
41024128 }
@@ -4122,7 +4148,7 @@ void MCButton::setmenuhistory(int2 newline)
41224148 MCValueRef t_oldline = nil;
41234149 /* UNCHECKED */ MCArrayFetchValueAtIndex (tabs, menuhistory, t_menuhistory);
41244150 /* UNCHECKED */ MCArrayFetchValueAtIndex (tabs, oldline, t_oldline);
4125- message_with_valueref_args (MCM_menu_pick, t_menuhistory, t_oldline);
4151+ handlemenupick ( t_menuhistory, t_oldline);
41264152 }
41274153
41284154 resetlabel ();
0 commit comments