1 /* $XConsortium: PromptDialogManager.C /main/4 1996/04/21 19:40:30 drk $ */
5 * $XConsortium: PromptDialogManager.C /main/4 1996/04/21 19:40:30 drk $
7 * RESTRICTED CONFIDENTIAL INFORMATION:
9 * The information in this document is subject to special
10 * restrictions in a confidential disclosure agreement bertween
11 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
12 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
13 * Sun's specific written approval. This documment and all copies
14 * and derivative works thereof must be returned or destroyed at
17 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
22 ///////////////////////////////////////////////////////////////////////////////
23 //////////////////////////////////////////////////////////////////////////////
24 // This example code is from the book:
26 // Object-Oriented Programming with C++ and OSF/Motif
29 // Prentice Hall, 1992
32 // Copyright 1991 by Prentice Hall
33 // All Rights Reserved
35 // Permission to use, copy, modify, and distribute this software for
36 // any purpose except publication and without fee is hereby granted, provided
37 // that the above copyright notice appear in all copies of the software.
38 ///////////////////////////////////////////////////////////////////////////////
39 //////////////////////////////////////////////////////////////////////////////
42 ///////////////////////////////////////////////////////////
43 // PromptDialogManager.C:
44 //////////////////////////////////////////////////////////
45 #include "PromptDialogManager.h"
47 #include <Xm/SelectioB.h>
49 // Define an instance to be available throughout the framework.
51 PromptDialogManager *thePromptDialogManager =
52 new PromptDialogManager ( "PromptDialog" );
54 PromptDialogManager::PromptDialogManager ( char *name ) :
55 DialogManager ( name )
60 Widget PromptDialogManager::createDialog ( Widget parent )
62 Widget dialog = XmCreatePromptDialog ( parent, _name, NULL, 0);
64 XtVaSetValues ( dialog,
65 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
73 PromptDialogManager::post( char *title,
77 DialogCallback cancel,
81 // Get a dialog widget from the cache
83 Widget dialog = getDialog();
85 // Make sure the dialog exists, and that it is an XmMessageBox
86 // or subclass, since the callbacks assume this widget type
88 assert ( dialog != NULL );
89 assert ( XtIsSubclass ( dialog, xmSelectionBoxWidgetClass ) );
91 // Convert the text string to a compound string and
92 // specify this to be the message displayed in the dialog.
94 XmString titleStr = XmStringCreateLocalized (title);
95 XmString xmstr = XmStringCreateLocalized ( text );
96 XtVaSetValues ( dialog,
97 XmNmessageString, xmstr,
98 XmNdialogTitle, titleStr,
100 XmStringFree ( xmstr );
101 XmStringFree ( titleStr );
103 // Create an object to carry the additional data needed
104 // to cache the dialogs.
106 DialogCallbackData *dcb = new DialogCallbackData( this,
110 // Install callback function for each button
111 // support by Motif dialogs. If there is no help callback
112 // unmanage the corresponding button instead, if possible.
115 XtAddCallback ( dialog,
117 &DialogManager::okCallback,
121 Widget w = XmSelectionBoxGetChild ( dialog,
122 XmDIALOG_OK_BUTTON );
123 XtUnmanageChild ( w );
128 XtAddCallback ( dialog,
130 &DialogManager::cancelCallback,
134 Widget w = XmSelectionBoxGetChild ( dialog,
135 XmDIALOG_CANCEL_BUTTON );
136 XtUnmanageChild ( w );
141 XtAddCallback ( dialog,
143 &DialogManager::helpCallback,
147 Widget w = XmSelectionBoxGetChild ( dialog,
148 XmDIALOG_HELP_BUTTON );
149 XtUnmanageChild ( w );
154 XtManageChild ( dialog );
161 PromptDialogManager::post( char *title,
166 DialogCallback cancel,
167 DialogCallback help )
170 // Get a dialog widget from the cache
172 Widget dialog = getDialog(wid);
174 // Make sure the dialog exists, and that it is an XmMessageBox
175 // or subclass, since the callbacks assume this widget type
177 assert ( dialog != NULL );
178 assert ( XtIsSubclass ( dialog, xmSelectionBoxWidgetClass ) );
180 // Convert the text string to a compound string and
181 // specify this to be the message displayed in the dialog.
183 XmString titleStr = XmStringCreateLocalized (title);
184 XmString xmstr = XmStringCreateLocalized ( text );
185 XtVaSetValues ( dialog,
186 XmNmessageString, xmstr,
187 XmNdialogTitle, titleStr,
189 XmStringFree ( xmstr );
190 XmStringFree ( titleStr );
192 // Create an object to carry the additional data needed
193 // to cache the dialogs.
195 DialogCallbackData *dcb = new DialogCallbackData( this,
199 // Install callback function for each button
200 // support by Motif dialogs. If there is no help callback
201 // unmanage the corresponding button instead, if possible.
204 XtAddCallback ( dialog,
206 &DialogManager::okCallback,
210 Widget w = XmSelectionBoxGetChild ( dialog,
211 XmDIALOG_OK_BUTTON );
212 XtUnmanageChild ( w );
217 XtAddCallback ( dialog,
219 &DialogManager::cancelCallback,
223 Widget w = XmSelectionBoxGetChild ( dialog,
224 XmDIALOG_CANCEL_BUTTON );
225 XtUnmanageChild ( w );
230 XtAddCallback ( dialog,
232 &DialogManager::helpCallback,
236 Widget w = XmSelectionBoxGetChild ( dialog,
237 XmDIALOG_HELP_BUTTON );
238 XtUnmanageChild ( w );
243 XtManageChild ( dialog );