XtPopup (XtParent (dialog), XtGrabNone);
}
The intent of this function is to create a dialog that tries to discourage the user from performing a destructive
action. By using a WarningDialog and by making the Cancel button the default choice, we have given the
user adequate warning that the action may have dangerous consequences. The output of a program running
this code fragment is shown in the figure.
Output of WarningMsg()
You can also set the default button for a dialog by the setting the BulletinBoard resource
-XmNdefaultButton. This technique works for both MessageDialogs and SelectionDialogs. The resource
value must be a widget ID, which means that you have to get a handle to a subwidget in the dialog to set the
resource. You can get the handle to subwidgets using XmMessageBoxGetChild() or
XmSelectionBoxGetChild(). Since this method breaks the Motif dialog abstraction, we describe it
later in Section #sinternwid.
6.4.2 Initial Keyboard Focus
When a dialog widget is popped up, one of the internal widgets in the dialog has the keyboard focus. This widget is
typically the default button for the dialog, which makes sense in most cases. However, there are situations where it is
appropriate for another widget to have the initial keyboard focus. For example, when a PromptDialog is popped up, it
makes sense for the TextField to have the keyboard focus so that the user can immediately start typing a response.
In Motif 1.1, it is not easy to set the initial keyboard focus in a dialog widget to anything other than a button in the
action area. Motif 1.2 has introduced the XmNinitialFocus resource to deal with this situation. Since this resource
is a Manager widget resource, it can be used for both MessageDialogs and SelectionDialogs, although it is normally
only used for SelectionDialogs. The resource specifies the subwidget that has the keyboard focus the first time that the
dialog is popped up. If the dialog is popped down and popped up again later, it remembers the widget that had the
keyboard focus when it was popped down and that widget is given the keyboard focus again. The resource value must
again be a widget ID. The default value of XmNinitialFocus for MessageDialogs is the subwidget that is also the
XmNdefaultButton for the dialog. For SelectionDialogs, the text entry area is the default value for the resource.
6.4.3 Button Sizes
The XmNminimizeButtons resource controls how the dialog sets the widths of the action area buttons. If the
resource is set to True, the width of each button is set so that it is as small as possible while still enclosing the entire
6 Introduction to Dialogs 6.4.2 Initial Keyboard Focus
122

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

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.