The following code creates a window with a menu bar containing the menu
illustrated at right. Simple menu creation methods are used.
| shell main menuBar fileMenu | shell := CwTopLevelShell createApplicationShell: 'shell' argBlock: [:w | w title: 'Pull-down Menu Example']. |
![]() |
main := shell createMainWindow: 'main' argBlock: nil. main manageChild.
"A simple menu bar is created as a child of the main window. The label for the button and its mnemonic is specified. In a menu bar, all items are cascade buttons, so the buttonType resource need not be explicitly set." menuBar := main createSimpleMenuBar: 'bar' argBlock: [:w | w buttons: #('File'); buttonMnemonics: #($F)]. menuBar manageChild.
fileMenu := menuBar "A simple pull-down menu is created as a child of the menu bar." createSimplePulldownMenu: 'file' argBlock: [:w | w buttons: #('Open' 'separator' 'Close'); buttonType: (Array
"Two normal items and a separator are specified" with: XmPUSHBUTTON with: XmSEPARATOR with: XmPUSHBUTTON); buttonMnemonics: (Array with: $O with: 0 asCharacter with: $C);
"The menu is attached to (dropped down from) the first (0th) item i the menu bar: the File cascade button." postFromButton: 0].
fileMenu "A simple callback runs whenever an item is selected from the File menu." addCallback: XmNsimpleCallback receiver: self selector: #fileMenu:clientData:callData: clientData: nil.
main setAreas: menuBar horizontalScrollbar: nil verticalScrollbar: nil workRegion: nil. shell realizeWidget.
fileMenu: widget clientData: clientData callData: callData "Execute the desired operation." self perform: (#(#doOpen #doClose) at: clientData + 1).