-fpermissive to allow GCC to compile old C++
[oweals/cde.git] / cde / programs / dtmail / MotifApp / WorkingDialogManager.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $XConsortium: WorkingDialogManager.C /main/4 1996/04/21 19:40:36 drk $ */
24 /*
25  *+SNOTICE
26  *
27  *      $XConsortium: WorkingDialogManager.C /main/4 1996/04/21 19:40:36 drk $
28  *
29  *      RESTRICTED CONFIDENTIAL INFORMATION:
30  *      
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
37  *      Sun's request.
38  *
39  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
40  *
41  *+ENOTICE
42  */
43
44 ///////////////////////////////////////////////////////////////////////////////
45 //////////////////////////////////////////////////////////////////////////////
46 //         This example code is from the book:
47 //
48 //           Object-Oriented Programming with C++ and OSF/Motif
49 //         by
50 //           Douglas Young
51 //           Prentice Hall, 1992
52 //           ISBN 0-13-630252-1 
53 //
54 //         Copyright 1991 by Prentice Hall
55 //         All Rights Reserved
56 //
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 //////////////////////////////////////////////////////////////////////////////
62
63
64 ///////////////////////////////////////////////////////////
65 // WorkingDialogManager.C: 
66 //////////////////////////////////////////////////////////
67 #include "WorkingDialogManager.h"
68 #include "Application.h"
69 #include <Xm/Xm.h>
70 #include <Xm/MessageB.h>
71 #include <Xm/Scale.h>
72 #include "BusyPixmap.h"
73 #include <assert.h>
74
75 WorkingDialogManager *theWorkingDialogManager =
76         new WorkingDialogManager ( "WorkingDialog" );
77
78 WorkingDialogManager::WorkingDialogManager ( char   *name ) : 
79                            DialogManager ( name )
80 {
81     _intervalId  = NULL;
82     _busyPixmaps = NULL;
83 }
84
85 Widget WorkingDialogManager::createDialog ( Widget parent )
86 {
87     Widget dialog = XmCreateWorkingDialog ( parent, _name, NULL, 0 );
88     
89     XtVaSetValues ( dialog,
90                    XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL,
91                    NULL );
92     
93     XtAddCallback ( dialog, 
94                    XmNokCallback, 
95                    &WorkingDialogManager::unpostCallback,
96                    (XtPointer) this );
97     
98     XtAddCallback ( dialog, 
99                    XmNcancelCallback, 
100                    &WorkingDialogManager::unpostCallback,
101                    (XtPointer) this );
102     
103 //    if ( !_busyPixmaps )
104 //      _busyPixmaps = new BusyPixmap ( dialog );    
105     
106     return dialog;
107 }
108
109 Widget WorkingDialogManager::post (char *title,
110                                    char          *text, 
111                                    void          *clientData,
112                                    DialogCallback ok,
113                                    DialogCallback cancel,
114                                    DialogCallback help )
115 {
116     // The the dialog already exists, and is currently in use,
117     // just return this dialog. The WorkingDialogManager
118     // only supports one dialog.
119     
120     if ( _w && XtIsManaged ( _w ) )
121         return _w;
122     
123     // Pass the message on to the base class
124     
125     DialogManager::post (title, text, clientData, ok, cancel, help );
126     
127     // Call timer to start an animation sequence for this dialog
128     
129     timer();
130     forceUpdate( _w );
131     return _w;
132 }
133
134 Widget 
135 WorkingDialogManager::post (char *title,
136                            char          *text, 
137                            Widget wid,
138                            void          *clientData,
139                            DialogCallback ok,
140                            DialogCallback cancel,
141                            DialogCallback help )
142 {
143     // The the dialog already exists, and is currently in use,
144     // just return this dialog. The WorkingDialogManager
145     // only supports one dialog.
146     
147     if ( _w && XtIsManaged ( _w ) )
148         return _w;
149     
150     // Pass the message on to the base class
151     
152     DialogManager::post (title, text, wid, clientData, ok, cancel, help );
153     
154     // Call timer to start an animation sequence for this dialog
155     
156     timer();
157     forceUpdate( _w );
158     return _w;
159 }
160
161 void WorkingDialogManager::timerCallback ( XtPointer clientData,
162                                           XtIntervalId * )
163 {
164     WorkingDialogManager *obj = ( WorkingDialogManager * ) clientData;
165     
166     obj->timer();
167 }
168
169 void WorkingDialogManager::timer ()
170 {
171     if ( !_w )
172         return;
173
174     
175     // Reinstall the time-out callback to be called again
176     
177     _intervalId = 
178       XtAppAddTimeOut ( XtWidgetToApplicationContext ( _w ),
179                         250, 
180                         &WorkingDialogManager::timerCallback,
181                         ( XtPointer ) this );    
182
183     // Get the next pixmap in the animation sequence and display
184     // it in the dialog's symbol area.
185     
186 //    XtVaSetValues ( _w, 
187 //                  XmNsymbolPixmap, _busyPixmaps->next(),
188 //                  NULL );
189     forceUpdate( _w );
190     
191 }
192
193 void WorkingDialogManager::unpostCallback ( Widget , 
194                                            XtPointer clientData, 
195                                            XtPointer )
196 {
197     WorkingDialogManager *obj = ( WorkingDialogManager* ) clientData;
198     
199     obj->unpost();
200 }
201
202 void WorkingDialogManager::unpost ()
203 {
204     assert ( _w != NULL );
205     
206     // Remove the dialog from the screen
207     
208     XtUnmanageChild ( _w );
209     
210     // Stop the animation
211     
212     if ( _intervalId )
213         XtRemoveTimeOut ( _intervalId );
214 }
215
216 void WorkingDialogManager::updateMessage ( char *text )
217 {
218     if ( _w )
219     {
220     
221         // Just change the string displayed in the dialog
222     
223         XmString xmstr = XmStringCreateLocalized ( text ); 
224         XtVaSetValues ( _w, XmNmessageString, xmstr, NULL );
225         XmStringFree ( xmstr );
226     }
227     forceUpdate( _w );
228 }
229
230
231
232
233