1 /* $XConsortium: RoamInterruptibleCmd.C /main/3 1995/11/06 16:12:29 rswiston $ */
5 * RESTRICTED CONFIDENTIAL INFORMATION:
7 * The information in this document is subject to special
8 * restrictions in a confidential disclosure agreement bertween
9 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
10 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
11 * Sun's specific written approval. This documment and all copies
12 * and derivative works thereof must be returned or destroyed at
15 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
19 ///////////////////////////////////////////////////////////////
20 // RoamInterruptibleCmd.C: Abstract class that supports lengthy,
21 // user-interruptible activities
22 //////////////////////////////////////////////////////////////
23 #include "RoamInterruptibleCmd.hh"
24 #include "DtMailWDM.hh"
25 #include "Application.h"
27 #include <Xm/MessageB.h>
29 extern forceUpdate( Widget );
32 RoamInterruptibleCmd::RoamInterruptibleCmd ( char *name,
35 NoUndoCmd ( name, label, active )
37 _wpId = NULL; // There is no work procedure yet
38 _callback = NULL; // Callbacks are specified in execute()
44 RoamInterruptibleCmd::~RoamInterruptibleCmd()
46 // Clean up by removing all callbacks
49 XtRemoveWorkProc ( _wpId );
53 RoamInterruptibleCmd::execute (
54 RoamTaskDoneCallback callback,
59 _clientData = clientData;
64 RoamInterruptibleCmd::execute()
68 name_str = (char *) name();
70 _done = FALSE; // Initialize flag
72 // Let the derived class post the dialog.
73 // Updates happen when derived classes call update() or
78 // Call the Cmd execute function to handle the Undo, and other
79 // general mechanisms supported by Cmd.
80 // execute() calls doit() of derived class.
84 // If the task was completed in a single call,
85 // don't bother to set up a work procedure. Just
86 // give derived classes a chance to cleanup and
87 // call the application's callback function
89 // If it was interrupted, the interruptCallback would have been
90 // called already and the dialog would have been unposted...
92 // We need to focus on only two cases here: what if the task was
93 // was completed in one call without interruptions (unpost dialog
94 // and call callback indicating task completed), and what if the
95 // task was not completed in one call (install a workProc...)
98 // if it done but not interrupted, it was genuinely done.
99 if (_done && !_interrupted)
101 unpost_dialog(); // derived classes implement this
104 if ( _callback ) // the FALSE is to say it was not interrupted.
105 ( *_callback )( this, FALSE, _clientData );
108 // If the task is not done and it was not interrupted and there is
109 // a callback to install, install a work procedure to continue the
110 // task as soon as possible. Call the callback via the work proc
114 else if ((!_done && !_interrupted && _callback))
117 _wpId = XtAppAddWorkProc ( theApplication->appContext(),
118 &RoamInterruptibleCmd::workProcCallback,
124 RoamInterruptibleCmd::workProcCallback (
128 RoamInterruptibleCmd *obj = (RoamInterruptibleCmd *) clientData;
130 // The work procedure just returns the value returned by the
131 // workProc member function.
133 return ( obj->workProc() );
137 RoamInterruptibleCmd::workProc()
139 // Call derived class's check_if_done() and see if they think the
140 // work is already done.
149 // the TRUE is to say task was interrupted
152 ( *_callback )( this, TRUE, _clientData );
155 // If the task has been completed, hide the dialog,
156 // give the derived class a chance to clean up, and notify
157 // the application that instantiated this object.
163 // the FALSE is to say task completed without interruptions
166 ( *_callback )( this, FALSE, _clientData );
173 RoamInterruptibleCmd::cleanup()
178 // The task has been interrupted. The user clicked on interrupt...
181 RoamInterruptibleCmd::interruptCallback (
185 RoamInterruptibleCmd *obj = ( RoamInterruptibleCmd * ) clientData;
187 // Just set the _interrupt flag to TRUE. The workProc()
188 // function will notice the next time it is called
194 RoamInterruptibleCmd::interrupt()
199 // Remove the work procedure
201 XtRemoveWorkProc ( _wpId );
204 // Remove the working dialog and give derived
205 // classes a chance to clean up
210 // Notify the application that the task was interrupted
213 ( *_callback )( this, TRUE, _clientData);
217 RoamInterruptibleCmd::updateMessage (
221 theDtMailWDM->updateDialog ( msg );
222 forceUpdate(theDtMailWDM->baseWidget());
226 RoamInterruptibleCmd::interrupted()
232 RoamInterruptibleCmd::update()
234 forceUpdate(theDtMailWDM->baseWidget());