XtRealizeWidget (toplevel);
XtAppMainLoop (app);
}
The code follows the steps that we just outlined. The MenuBar is created as a child of the MainWindow, and the
PulldownMenu is created as a child of the MenuBar. The CascadeButton acts as the File title item in the MenuBar, so
it is also created as the child of the MenuBar. Both the menu title and the PulldownMenu are children of the MenuBar.
The CascadeButton sets its XmNsubMenuId resource to the PulldownMenu so that when the button is selected, it
knows which PulldownMenu to display. When you create a PulldownMenu using the simple menu creation routine, it
sets this resource behind the scenes.
We also set the label of the CascadeButton using the XmNlabelString resource. This value is a compound string,
just as in the simple creation function. If we had not set the label directly, the name of the widget itself would appear
as the label, and we could override it with a specification in a resource file. Since we are not using the simple creation
routine, we can choose whether or not we hard−code the label for the CascadeButton. After we create the items in the
menu, we manage the MenuBar using XtManageChild(). The output of the source code both before and after the
PulldownMenu is posted, is shown in the figure.
Output of file_menu.c
16.3.1 Menu Titles
The titles in a MenuBar are actually the labels of the CascadeButtons. The labels can be specified using the
XmNlabelString resource, either in the application code or in a resource file. Every CascadeButton must have a
submenu associated with it via the XmN-subMenuId resource. When the user selects the CascadeButton, the
associated PulldownMenu is displayed. You should never attach a callback function directly to a CascadeButton in the
MenuBar as it would confuse the user. Callback functions should only be attached to menu items in PulldownMenus
that are posted from the MenuBar.
The PulldownMenu that is associated with a CascadeButton is created using XmCreatePulldownMenu(). This
routine returns the RowColumn widget that manages the menu items. The routine creates the RowColumn as a child
of a MenuShell widget. Since the routine returns the RowColumn widget, the resource list provided to the function
only sets resources for the RowColumn widget, not for the MenuShell that contains it.
16 Menus 16.3.1 Menu Titles
444

Get Volume 6A: Motif Programming Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.