Programmer Reference : Common Widgets : Menus : Non-simple menu example
Non-simple menu example
The following code creates a window with a menu bar containing the same File menu illustrated in "Creating a menu bar and pull-down menu using simple menu protocol", except that this time, non-simple widget creation methods are used.
| shell main menuBar menu1 menu1Title item1 item2 item3 |
shell := CwTopLevelShell
createApplicationShell: 'shell'
argBlock: [:w | w title: 'Pull-down Menu Example'].
main := shell
createMainWindow: 'main'
argBlock: nil.
main manageChild.
menuBar := main
"First, a menu bar is created as a child of the main window."
createMenuBar: 'bar'
argBlock: nil.
menuBar manageChild.
menu1 := menuBar
"Second, a pull-down menu is created as a child of the menu bar."
createPulldownMenu: 'menu'
argBlock: nil.
menu1Title := menuBar
"Third, a cascade button is added to the menu bar. It is associated
with the pull-down menu using the subMenuId: method. The name of
the cascade button appears in the menu bar. Note that the pull-down
menu is created before the cascade button."
createCascadeButton: 'File'
argBlock: [:w |
w
subMenuId: menu1].
menu1Title manageChild.
item1 := menu1
"Fourth, a push-button widget is created. The parent is menu1.
When the File menu is clicked on, a pull-down menu appears
with Open as the first entry. If Open is selected, an
XmNactivateCallback is issued and the message
open:clientData:callData is sent to the receiver."
createPushButton: 'Open'
argBlock: nil.
item1
addCallback: XmNactivateCallback
receiver: self
selector: #open:clientData:callData:
clientData: nil.
item1 manageChild.
item2 := menu1
"Fifth, a separator widget is created as a child of menu1,
to separate the first and third menu items. The separatorType
resource is set to a single line separator."
createSeparator: 'sep'
argBlock: [:w |
w
separatorType: XmSINGLELINE].
item2 manageChild.
item3 := menu1
"Finally, another push-button widget is created for the third menu item.
If Close is selected, an XmNactivateCallback is issued and the message
close:clientData:callData: is sent to the receiver."
createPushButton: 'Close'
argBlock: nil.
item3
addCallback: XmNactivateCallback
receiver: self
selector: #close:clientData:callData:
clientData: nil.
item3 manageChild.
shell realizeWidget.
Last modified date: 12/22/2017