2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: PromptDialogManager.C /main/4 1996/04/21 19:40:30 drk $ */
27 * $XConsortium: PromptDialogManager.C /main/4 1996/04/21 19:40:30 drk $
29 * RESTRICTED CONFIDENTIAL INFORMATION:
31 * The information in this document is subject to special
32 * restrictions in a confidential disclosure agreement bertween
33 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
35 * Sun's specific written approval. This documment and all copies
36 * and derivative works thereof must be returned or destroyed at
39 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
44 ///////////////////////////////////////////////////////////////////////////////
45 //////////////////////////////////////////////////////////////////////////////
46 // This example code is from the book:
48 // Object-Oriented Programming with C++ and OSF/Motif
51 // Prentice Hall, 1992
54 // Copyright 1991 by Prentice Hall
55 // All Rights Reserved
57 // Permission to use, copy, modify, and distribute this software for
58 // any purpose except publication and without fee is hereby granted, provided
59 // that the above copyright notice appear in all copies of the software.
60 ///////////////////////////////////////////////////////////////////////////////
61 //////////////////////////////////////////////////////////////////////////////
64 ///////////////////////////////////////////////////////////
65 // PromptDialogManager.C:
66 //////////////////////////////////////////////////////////
67 #include "PromptDialogManager.h"
69 #include <Xm/SelectioB.h>
71 // Define an instance to be available throughout the framework.
73 PromptDialogManager *thePromptDialogManager =
74 new PromptDialogManager ( "PromptDialog" );
76 PromptDialogManager::PromptDialogManager ( char *name ) :
77 DialogManager ( name )
82 Widget PromptDialogManager::createDialog ( Widget parent )
84 Widget dialog = XmCreatePromptDialog ( parent, _name, NULL, 0);
86 XtVaSetValues ( dialog,
87 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
95 PromptDialogManager::post( char *title,
99 DialogCallback cancel,
100 DialogCallback help )
103 // Get a dialog widget from the cache
105 Widget dialog = getDialog();
107 // Make sure the dialog exists, and that it is an XmMessageBox
108 // or subclass, since the callbacks assume this widget type
110 assert ( dialog != NULL );
111 assert ( XtIsSubclass ( dialog, xmSelectionBoxWidgetClass ) );
113 // Convert the text string to a compound string and
114 // specify this to be the message displayed in the dialog.
116 XmString titleStr = XmStringCreateLocalized (title);
117 XmString xmstr = XmStringCreateLocalized ( text );
118 XtVaSetValues ( dialog,
119 XmNmessageString, xmstr,
120 XmNdialogTitle, titleStr,
122 XmStringFree ( xmstr );
123 XmStringFree ( titleStr );
125 // Create an object to carry the additional data needed
126 // to cache the dialogs.
128 DialogCallbackData *dcb = new DialogCallbackData( this,
132 // Install callback function for each button
133 // support by Motif dialogs. If there is no help callback
134 // unmanage the corresponding button instead, if possible.
137 XtAddCallback ( dialog,
139 &DialogManager::okCallback,
143 Widget w = XmSelectionBoxGetChild ( dialog,
144 XmDIALOG_OK_BUTTON );
145 XtUnmanageChild ( w );
150 XtAddCallback ( dialog,
152 &DialogManager::cancelCallback,
156 Widget w = XmSelectionBoxGetChild ( dialog,
157 XmDIALOG_CANCEL_BUTTON );
158 XtUnmanageChild ( w );
163 XtAddCallback ( dialog,
165 &DialogManager::helpCallback,
169 Widget w = XmSelectionBoxGetChild ( dialog,
170 XmDIALOG_HELP_BUTTON );
171 XtUnmanageChild ( w );
176 XtManageChild ( dialog );
183 PromptDialogManager::post( char *title,
188 DialogCallback cancel,
189 DialogCallback help )
192 // Get a dialog widget from the cache
194 Widget dialog = getDialog(wid);
196 // Make sure the dialog exists, and that it is an XmMessageBox
197 // or subclass, since the callbacks assume this widget type
199 assert ( dialog != NULL );
200 assert ( XtIsSubclass ( dialog, xmSelectionBoxWidgetClass ) );
202 // Convert the text string to a compound string and
203 // specify this to be the message displayed in the dialog.
205 XmString titleStr = XmStringCreateLocalized (title);
206 XmString xmstr = XmStringCreateLocalized ( text );
207 XtVaSetValues ( dialog,
208 XmNmessageString, xmstr,
209 XmNdialogTitle, titleStr,
211 XmStringFree ( xmstr );
212 XmStringFree ( titleStr );
214 // Create an object to carry the additional data needed
215 // to cache the dialogs.
217 DialogCallbackData *dcb = new DialogCallbackData( this,
221 // Install callback function for each button
222 // support by Motif dialogs. If there is no help callback
223 // unmanage the corresponding button instead, if possible.
226 XtAddCallback ( dialog,
228 &DialogManager::okCallback,
232 Widget w = XmSelectionBoxGetChild ( dialog,
233 XmDIALOG_OK_BUTTON );
234 XtUnmanageChild ( w );
239 XtAddCallback ( dialog,
241 &DialogManager::cancelCallback,
245 Widget w = XmSelectionBoxGetChild ( dialog,
246 XmDIALOG_CANCEL_BUTTON );
247 XtUnmanageChild ( w );
252 XtAddCallback ( dialog,
254 &DialogManager::helpCallback,
258 Widget w = XmSelectionBoxGetChild ( dialog,
259 XmDIALOG_HELP_BUTTON );
260 XtUnmanageChild ( w );
265 XtManageChild ( dialog );