Navigation: ABC Library Reference > PopupClass >====== PopupClass Overview ====== | |
The PopupClass object defines and manages a full featured popup (context) menu. The PopupClass object makes it easy to add fully functional popup menus to your procedures.
PopupClass Concepts
You can set the popup menu items to mimic existing buttons on a window, so that associated menu item text matches the button text, is enabled only when the button is enabled, and, when selected, invokes the button action.
Alternatively, you can set the popup menu item to POST a particular event or simply return its ID so you can trap it and custom code the item's functionality.
PopupClass Relationship to Other Application Builder Classes
The PopupClass optionally uses the TranslatorClass so you can translate menu text to other languages without changing your popup menu code. The PopupClass optionally uses the INIClass to save and restore menu definitions to a configuration (.INI) file. Neither class is required by the PopupClass; however, if you use either facility, you must instantiate them in your program. See the Conceptual Example.
The ASCIIViewerClass, BrowseClass, and PrintPreviewClass all use the PopupClass to manage their popup menus. This PopupClass use is automatic when you INCLUDE the class header (ABASCII.INC, ABBROWSE.INC, or ABPRINT.INC) in your program's data section.
PopupClass ABC Template Implementation
The ABC Templates declare a local PopupClass class and object for each instance of the Popup code template.
The class is named PopupMgr# where # is the instance number of the Popup code template. The templates provide the derived class so you can use the Popup code template Classes tab to easily modify the popup menu behavior on an instance-by-instance basis.
The template generated code does not reference the PopupClass objects encapsulated within the ASCIIViewerClass, BrowseClass, and PrintPreviewClass.
PopupClass Source Files
The PopupClass source code is installed by default to the Clarion \LIBSRC folder. The PopupClass source code and its respective components are contained in:
ABPOPUP.INC | PopupClass declarations | |
ABPOPUP.CLW | PopupClass method definitions | |
ABPOPUP.TRN | PopupClass translation strings |
PopupClass Conceptual Example
The following example shows a typical sequence of statements to declare, instantiate, initialize, use, and terminate a PopupClass object.
This example displays a dialog with a right-click popup menu that mimics the dialog buttons with three different PopupClass techniques. The dialog buttons demonstrate the PopupClass' ability to save and restore menus to and from an INI file.
PROGRAM
MAP
END
INCLUDE('ABPOPUP.INC') !declare PopupClass
INCLUDE('ABUTIL.INC') !declare INIClass & Translator
INCLUDE('KEYCODES.CLW') !declare right-click EQUATE
PopupString STRING(20) !to receive menu selection
PopupMgr PopupClass !declare PopupMgr object
Translator TranslatorClass !declare Translator object
INIMgr INIClass !declare INIMgr object
INIFile EQUATE('.\Popup.ini') !declare INI pathname EQUATE
PopupWin WINDOW('Popup Demo'),AT(,,184,50),ALRT(MouseRight),GRAY
BUTTON('&Save Popup'),AT(17,16),USE(?Save)
BUTTON('&Restore Popup'),AT(74,16),USE(?Restore),DISABLE
BUTTON('Close'),AT(140,16),USE(?Close)
END
CODE
OPEN(PopupWin)
Translator.Init !initialize Translator object
INIMgr.Init(INIFile) !initialize INIMgr object
PopupMgr.Init(INIMgr) !initialize PopupMgr object
PopupMgr.AddItemMimic('Save',?Save) !Save item mimics ?Save button
PopupMgr.AddItem('Restore Popup','Restore')!add menu item: Restore
PopupMgr.SetItemEnable('Restore',False) !initially disable Restore item
PopupMgr.AddItem('-','Separator1') !add a menu item separator
PopupMgr.AddItem('Disable Save','Disable') !add a menu item: Disable
PopupMgr.AddItem('-','Separator2') !add a menu item separator
PopupMgr.AddItem('Close (EVENT:Accepted)','Close')!add a menu item: Close
PopupMgr.AddItemEvent('Close',EVENT:Accepted,?Close)!Close POSTs event to a control
PopupMgr.AddItem('Close (EVENT:CloseWindow)','Close2')!add a menu item: Close2
!Close2 POSTs independent event
PopupMgr.AddItemEvent('Close2',EVENT:CloseWindow,0)
PopupMgr.SetTranslator(Translator) !enable popup text translation
ACCEPT
CASE EVENT()
OF EVENT:AlertKey !trap for alerted keys
IF KEYCODE() = MouseRight !if right-click
PopupString=PopupMgr.Ask() !display popup menu
CASE PopupString !check for selected item
OF 'Disable' !if Disable item selected
IF PopupMgr.GetItemChecked('Disable')
PopupMgr.SetItemCheck('Disable',False) !toggle the menu check mark
ENABLE(?Save) !toggle ?Save button state
ELSE !which automatically toggles
PopupMgr.SetItemCheck('Disable',True) !the Save menu item, because
DISABLE(?Save) !it mimics the ?Save button
END
OF 'Restore' !if Restore item selected
POST(EVENT:Accepted,?Restore) !code your own functionality
ELSE !if any other item selected
END !Ask automatically handled it
END
END
CASE FIELD()
OF ?Save !Save button mimiced by Save item
CASE EVENT()
OF EVENT:Accepted
PopupMgr.Save('MyPopup') !save menu definition to INI
RUN('NotePad '&INIFile) !display/edit menu definition
ENABLE(?Restore) !enable the Restore button
PopupMgr.SetItemEnable('Restore',True) !enable the Restore item
END
OF ?Restore
CASE EVENT()
OF EVENT:Accepted
PopupMgr.Restore('MyPopup') !restore/define menu from INI
END
OF ?Close !Close btn Accepted by Close item
CASE EVENT()
OF EVENT:Accepted
POST(Event:CloseWindow)
END
END
END
PopupMgr.Kill