A GMS popup menu typically appears because the user clicked the mouse on an item. This item is called the initiating item. The popup menu disappears automatically when the user selects a leaf entry from the menu or a subsidiary cascade menu. If the user of the popup menu decides to take none of the menu choices, clicking on the header dismisses the menu.
gms-popup-subscriber in the item's class definition, as described in Using gms-popup-subscriber to Display a Popup Menu.
gms-display-popup-menu or gms-display-popup-menu-at-last-event-location when the user clicks on the item, as described in Using G2 Configurations to Display a Popup Menu.
GMS provides a mixin class called
GMS-POPUP-SUBSCRIBER that you can include in a class definition. Clicking an instance of a class that inherits gms-popup-subscriber causes GMS to display a popup menu.
To use gms-popup-subscriber to associate a GMS popup menu with a class:
Direct-superior-classes the additional class gms-popup-subscriber.
Gms-popup-pointer to the class definition.
Attribute-initializations of the class to read:
Gms-popup-pointer initially is popup-key
Gms-user-key on the root template of the popup menu and the class of the object. Whenever the user clicks the mouse on an instance of the class, GMS displays the popup menu whose root template specifies popup-key as its Gms-user-key. If no such menu exists, GMS signals an error.When the user clicks a leaf entry selected through a GMS popup displayed via
gms-popup-subscriber, GMS automatically includes the initiating item in the arguments to the leaf entry's callback procedure.
gms-popup-subscriber mixin substitutes GMS menus for G2 menus, you cannot directly edit the table of an item that inherits gms-popup-subscriber. However, the table and its attributes remain accessible in other ways.
To edit the table of an item that inherits Gms-popup-subscriber:
Use Inspect to obtain the instance and display its table.
To modify programmatically an item that inherits Gms-popup-subscriber:
Use the conclude and change actions, as with any G2 item.
To provide G2 menu capabilities in a GMS menu:
Define GMS menu entries and callback procedures as needed to provide the same effect as the G2 menu entries.
gms-display-popup-menu
(handle: integer, menu-index: integer, X: integer, Y: integer,
initiating-item: item-or-value)
false. Do not specify any other dummy value, or GMS signals an error.
gms-display-popup-menu-at-last-event-location
(handle: integer, menu-index: integer, initiating-item: item-or-value)
gms-display-popup-menu-at-last-event-location determines the last event like the system procedures g2-last-input-event and g2-last-input-event-info. The gms-display-popup-menu-at-last-event-location procedure uses g2-last-input-event-info to determine the coordinates of the location for posting the menu.
GMS passes initiating-item to any callback procedure that is invoked via the popup menu.
You can set initiating-item to be the item that the user clicked to display the popup. If you do not need to pass this item to a callback procedure, specify a dummy value of false. Do not specify any other dummy value, or GMS signals an error.
Typically, you would use this procedure to post a menu in response to a mouse click by the user. To post a menu when the user selects an item, the item must have a configuration clause that specifies a procedure that calls gms-display-popup-menu-at-last-event-location, as in the following example:
selecting any item implies post-menu
Where post-menu is a user-menu-choice that does the following:
start my-posting-procedure (the item, this window);
my-posting-procedure (InitiatingItm: class item, Win: class g2-window)
GMSHandle: integer;
PopupMenuIndex: integer;
begin
GMSHandle = call gms-get-handle-for-window (Win);
PopupMenuIndex = call gms-get-index-for-key
(the symbol POPUP-MENU);
call gms-display-popup-menu-at-last-event-location (GMSHandle,
PopupMenuIndex, InitiatingItm);
end
To use G2 configurations to associate a GMS popup menu with a class:
gms-display-popup-menu or gms-display-popup-menu-at-last-event-location and passes it appropriate arguments, as in the previous example.
releasing any mouse button on...
selecting any item...
gms-display-popup-menu and gms-display-popup-menu-at-last-event-location only in response to a mouse-up event, or while the mouse button is already raised. If you call gms-display-popup-menu or gms-display-popup-menu-at-last-event-location in response to a mouse-down event, or while the mouse button is already depressed, GMS will be unable to detect the mouse state and will be corrupted. To recover from this error, reset G2 or call gms-reset, as described under Resetting GMS Without Resetting G2.
To display a popup menu in response to a mouse-down event, or while the mouse button is already depressed, use gms-manage-popup-menu as described under Handling Mouse Events for Popup Menus.