dialog widgets dialog widgets present information and collect input from the user: dialogs are...

30
Dialog Widgets log widgets present information and collec ut from the user: logs are windows that are often displayed elatively short amount of time. user is expected to dismiss them when the no longer needed.

Upload: alyson-harvey

Post on 18-Jan-2018

223 views

Category:

Documents


0 download

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 presented

TRANSCRIPT

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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: