dialog widgets dialog widgets present information and collect input from the user: dialogs are...
DESCRIPTION
Pre-Defined Motif Dialogs The following kinds of dialogs are pre-defined by the XmMessageBox class: Error Warning Information Working Question They differ primarily in the type of icon presentedTRANSCRIPT
![Page 1: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/1.jpg)
Dialog Widgets
Dialog widgets present information and collectinput from the user:
Dialogs are windows that are often displayed fora relatively short amount of time.
The user is expected to dismiss them when theyare no longer needed.
![Page 2: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/2.jpg)
Dialog Classes The basis of all dialogs is the TransientShell
widget class provided by Xt Motif provides an XmDialogShell widget class
which is a subclass of TransientShell Motif also provides an XmMessageBox class
upon which several pre-defined dialog types are based
All dialogs have a modality, which controls screen input while they are displayed
![Page 3: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/3.jpg)
Pre-Defined Motif Dialogs
The following kinds of dialogs are pre-defined by the XmMessageBox class: Error Warning Information Working Question
They differ primarily in the type of icon presented
![Page 4: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/4.jpg)
Example
Widget shell, errord, infod, warnd, workd, questiond; XtAppContext app; XmString msg; ArgList args = new Arg[10]; Integer n = 0;
XtSetArg(args[n], XmNdefaultPosition, FALSE); n++; XtSetArg(args[n], XmNheight, 100); n++; XtSetArg(args[n], XmNwidth, 100); n++; XtSetArg(args[n], XmNx, 400); n++; XtSetArg(args[n], XmNy, 400); n++; shell = XtAppInitialize ( &app, "Test", NULL, 0, &argc, argv, NULL, args, n );
XtRealizeWidget ( shell ); XtAppMainLoop ( app );
The following code creates a top-level shell to actas a parent for some example dialogs:
![Page 5: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/5.jpg)
Shell Widget Display
Height and width are 100 pixels.
Upper left corner is at (400,400) in root window.
Does not have any children yet.
![Page 6: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/6.jpg)
Example Error Dialog errord = XmCreateErrorDialog(shell, "error", NULL, 0); msg = XmStringCreateLocalized("Bad input. Try again."); XtVaSetValues(errord, XmNmessageString, msg, NULL);
XtManageChild(errord);
XmCreateErrorDialog is a convenience function.errord is made a child of shell.Note use of variable arguments instead of an ArgList.
XtManageChild will allow the dialog to appear whenshell is realized.
![Page 7: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/7.jpg)
Error Dialog Display
![Page 8: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/8.jpg)
About the Error Dialog
Note the message icon Note the default placement of the dialog at (0,0) Note the default set of buttons
![Page 9: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/9.jpg)
Example Warning Dialogwarnd = XmCreateWarningDialog(shell, "warning", NULL, 0);msg = XmStringCreateLocalized( "Bad input. Using default value.");XtVaSetValues(warnd, XmNmessageString, msg, XmNdefaultPosition, FALSE, XmNx, 300, XmNy, 0, NULL);XtManageChild(warnd);
The convenience function takes the same arguments.
Note that the placement (300,0) is explicitly given.
Still must set XmNdefaultPosition to FALSE.
![Page 10: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/10.jpg)
Warning Dialog Display
![Page 11: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/11.jpg)
About the Warning Dialog The only difference is the icon Both dialogs are children of the shell If the shell is quit all windows disappear
![Page 12: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/12.jpg)
Example Information Dialoginfod = XmCreateInformationDialog(shell, "information", NULL, 0);msg = XmStringCreateLocalized( "Next we will get personal data.");XtVaSetValues(infod, XmNmessageString, msg, XmNdefaultPosition, FALSE, XmNx, 0, XmNy, 200, XmNokLabelString,XmStringCreateLocalized( "CONTINUE"), NULL);XtManageChild(infod);
Note that the default label on the OK button is changed.
![Page 13: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/13.jpg)
Information Dialog Display
![Page 14: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/14.jpg)
Example Working Dialog workd = XmCreateWorkingDialog(shell, "working", NULL, 0); msg = XmStringCreateLocalized( "Processing... click Cancel to quit."); XtVaSetValues(workd,
XmNmessageString, msg,XmNdefaultPosition, FALSE,XmNx, 350,XmNy, 200,XmNdefaultButtonType, XmDIALOG_CANCEL_BUTTON,NULL);
XtManageChild(workd);
Note that the Cancel button has been made thedefault button type.
![Page 15: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/15.jpg)
Working Dialog Display
![Page 16: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/16.jpg)
Example Question Dialog questiond = XmCreateQuestionDialog(shell, "question", NULL, 0); msg = XmStringCreateLocalized("Shall we proceed?"); XtVaSetValues(questiond,
XmNmessageString, msg,XmNdefaultPosition, FALSE,XmNx, 0,XmNy, 400,XmNokLabelString, XmStringCreateLocalized("Yes"),XmNcancelLabelString, XmStringCreateLocalized("No"),NULL);
XtManageChild(questiond);
Note that both the Ok and Cancel button labelshave been changed.
![Page 17: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/17.jpg)
Question Dialog Display
![Page 18: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/18.jpg)
Dialog Modality The previous examples use nonmodal dialogs. Even though the dialog box is visible, the user is
not prevented from interacting with other windows on the desktop.
There are 4 levels of modality: Nonmodal Primary application modal: input to the window that
launched the dialog is locked out but not others Full application modal: input to all windows in the
application is locked out Full system modal: input to all windows in all
applications in the system is locked out
![Page 19: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/19.jpg)
Setting Dialog Modality
Resource: XmNdialogStyle Values:
XmDIALOG_MODELESS XmDIALOG_PRIMARY_APPLICATION_MODAL XmDIALOG_FULL_APPLICATION_MODAL XmDIALOG_SYSTEM_MODAL
![Page 20: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/20.jpg)
Modal Dialog Example questiond = XmCreateQuestionDialog(shell, "question", NULL, 0); msg = XmStringCreateLocalized("Shall we proceed?"); XtVaSetValues(questiond,
XmNmessageString, msg,XmNdefaultPosition, FALSE,XmNx, 0,XmNy, 400,XmNokLabelString, XmStringCreateLocalized("Yes"),XmNcancelLabelString, XmStringCreateLocalized("No"),
XmNdialogStyle, XmDIALOG_SYSTEM_MODAL,NULL);
XtManageChild(questiond);
The question dialog will now insist that it be answeredbefore input to any other application is accepted.
![Page 21: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/21.jpg)
Dialogs and Callbacks
Recall the opening dialog for the Tic-Tac-Toe game:
The program must deal (at least) with clicks onthe OK and Cancel buttons.
![Page 22: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/22.jpg)
Recall the Class Diagram
Boardcanvas: Widgetdisplay: Displaygc: GC
Gamestate: CharArraycount: IntegerplayerX: Player
Dialogdialog: Widget
Mainshell: Widgetapp: XtAppContext
board game
board
game
game
startdenddsummaryd
*
The start dialog startd is owned by the main programobject.
![Page 23: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/23.jpg)
Tic-Tac-Toe Main Program
shell = XtAppInitialize ( &app, "TicTacToe", NULL, 0, &argc, argv, NULL, NULL, 0 );
XtVaSetValues(shell, XmNdefaultPosition, FALSE,XmNheight, 300, XmNwidth, 300,XmNx, 400, XmNy, 400, NULL);
game = new GameInfo(); // Create a new game
board = new BoardInfo(shell, game); // Create a board drawing area
game->setBoard(board); // Tell game about board
startd = new DialogInfo("start", shell, game); // Create dialog
startd->manage("Computer plays first? (Cancel for NO)"); // expose dialog XtRealizeWidget ( shell ); XtAppMainLoop ( app );
![Page 24: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/24.jpg)
Tic-Tac-Toe Main Program (cont'd) startd is not a Motif object but a C++ DialogInfo object
The Motif start dialog is an attribute of the DialogInfo object
Multiple instances of DialogInfo will ultimately be made for the program, including: game ending dialog endd game summary dialog summaryd
The message to be carried by the dialog is given as a parameter to the manage method
![Page 25: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/25.jpg)
Dialog Class
Recall that a Dialog object has a Game attributeby association.
![Page 26: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/26.jpg)
DialogInfo Class Definition
class DialogInfo {private: Widget dialog; // the dialog widget Game game; // the game statepublic: DialogInfo(Text name, Widget parent, Game g); void manage(Text msg); // expose dialog with msgprivate: DECL_CALLBACK(startOk); // Computer plays first DECL_CALLBACK(startCancel); // User plays first};
![Page 27: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/27.jpg)
DialogInfo Class ConstructorDialogInfo::DialogInfo(Text name, Widget parent, Game g){ game = g; dialog = XmCreateQuestionDialog (parent, name, NULL, 0); XtVaSetValues (dialog,
XmNdefaultPosition, FALSE, XmNx, 400,
XmNy, 200, XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
NULL); if (strcmp(name,"start")==0) { // creating the start dialog XtAddCallback (dialog, XmNokCallback,
&DialogInfo::startOkCallback, (XtPointer) this); XtAddCallback (dialog, XmNcancelCallback,
&DialogInfo::startCancelCallback, (XtPointer) this); }}
![Page 28: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/28.jpg)
DialogInfo Class Constructor (cont'd)
Callbacks are registered depending on the type of the dialog
Currently there is just one type (start) The if statement could be extended to register
other callbacks for other dialog types (end and summary)
![Page 29: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/29.jpg)
Start Dialog Callbacks
IMPL_CALLBACK(DialogInfo, startOk) { // Computer plays first game->init(COMPUTER);}
IMPL_CALLBACK(DialogInfo, startCancel) { // User plays first game->init(USER);}
![Page 30: Dialog Widgets Dialog widgets present information and collect input from the user: Dialogs are windows that are often displayed for a relatively short](https://reader036.vdocuments.us/reader036/viewer/2022062401/5a4d1b1f7f8b9ab059994c37/html5/thumbnails/30.jpg)
DialogInfo::manage Method
void DialogInfo::manage(Text msg) { // expose dialog with message XmString xmstr = XmStringCreateLocalized(msg); XtVaSetValues (dialog, XmNmessageString, xmstr, NULL); XtManageChild(dialog);}
startd->manage("Computer plays first? (Cancel for NO)");
Recall how the main program gets the start dialogto display: