| Prev | Next | Start of Chapter | Next Chapter | Contents | Glossary | Index | Comments | (4 out of 4)

Displaying Popup Menus

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.

G2 includes a predefined popup menu capability that operates below the level of GMS. When you use GMS, you can configure objects to display GMS popups rather than G2 popups. GMS offers three ways to associate a GMS popup menu with an item:

Using gms-popup-subscriber 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:

  1. On the table for the class definition of the initiating object, give the attribute Direct-superior-classes the additional class gms-popup-subscriber.

    This mixin adds the attribute Gms-popup-pointer to the class definition.

  2. Edit the Attribute-initializations of the class to read:

    where popup-key is the key of the root template of a popup menu.

This makes an association between the 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.

Accessing G2 Tables and Modifying G2 Attributes

Since the 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:

To modify programmatically an item that inherits Gms-popup-subscriber:

To provide G2 menu capabilities in a GMS menu:

Using G2 Configurations to Display a Popup Menu

GMS provides two API calls that display a popup menu. You can use either of these calls in conjunction with G2 configurations to display a popup menu. The calls are:

gms-display-popup-menu 
(handle: integer, menu-index: integer, X: integer, Y: integer,
initiating-item: item-or-value)
gms-display-popup-menu-at-last-event-location 
(handle: integer, menu-index: integer, initiating-item: item-or-value)
To use G2 configurations to associate a GMS popup menu with a class:

  1. Create a User Menu Choice that calls a procedure that calls either gms-display-popup-menu or gms-display-popup-menu-at-last-event-location and passes it appropriate arguments, as in the previous example.

  2. Configure the class that is to use GMS popup menus to execute the User Menu Choice in response to a mouse-up event. Use either of the Configuration clauses:


Caution: Call 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.

| Prev | Next | Start of Chapter | Next Chapter | Contents | Glossary | Index | Comments | (4 out of 4)

Copyright © 1997 Gensym Corporation, Inc.