11. Managing Event Queues : Event-based Programming : Event Types : Menu Events
 
Share this page                  
Menu Events
Menu events are events triggered when a user selects a menu item. Menu events are simpler than field events because they have fewer available events. These menu events are:
Click event
The three menu fields (menu button, menu toggle, and menu list) all have a Click event, which is triggered when the user selects the menu item.
SetValue event
The menu toggle and menu list fields also have a SetValue event, which is triggered when the user changes the value of the menu item—that is, switches the toggle setting or selects a new item from the list.
Validate event
The menu toggle and menu list fields also have a Validate event, which is triggered at exactly the same places as the SetValue event, but is processed before the SetValue chain. Therefore, if a Validate event block contains a resume statement, control returns to the frame without triggering the SetValue event.
The following sample frame script is the Click event block for the Graphic operation on the View menu. This menu operation functions as a toggle field that lets the user turn on or turn off the display of the photograph associated with a given video.
on click menu.view_menu.show_graphic =
begin
    if menu.view_menu.show_graphic = FALSE then
        graphic_frame.Terminate();
        graphic_frame = null;
    else
        graphic_frame = openframe
            video_graphic(vid_graphic_bitmap =
            video.vid_graphic_bitmapobject)
                with windowtitle = video.title,
                windowxleft = CurFrame.WindowWidth,
                windowytop = 0;
    endif;

Show_video_graphic = menu.view_menu.show_graphic;
end
Based on user interaction, this block of code either terminates the graphic frame and reinitializes its FrameExec pointer to null, or opens it with the appropriate photograph and window location.
The difference between the Click event and the SetValue event is meaningful for the menu list, as follows:
The Click event is triggered when the user clicks any list item, even the currently highlighted list item.
The SetValue event is triggered only when the user actually changes the value of the field.
For example, assume there is a frame with a Get menu that contains a menu list called initial_acct, which offers the following choices:
New Account
Existing Account
All Accounts
Closed Accounts
Because the user might need to repeat the command, New Account, the event block for this menu list uses the Click event. If SetValue were used, nothing would happen the second time the user clicked New Account.
The Click, Validate, and SetValue events create an event chain in this order for menu toggles and menu lists.
Note:  The form associated with each frame (CurFrame.TopForm) contains only non-menu fields. Menu fields are separate from the form because they are toolkit‑specific. Therefore, menu events do not trigger corresponding child events for the frame. There are no child events for a menu stack or for the menu as a whole.