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