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: RoamInterruptibleCmd.C /main/3 1995/11/06 16:12:29 rswiston $ */
27 * RESTRICTED CONFIDENTIAL INFORMATION:
29 * The information in this document is subject to special
30 * restrictions in a confidential disclosure agreement bertween
31 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
32 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
33 * Sun's specific written approval. This documment and all copies
34 * and derivative works thereof must be returned or destroyed at
37 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 ///////////////////////////////////////////////////////////////
42 // RoamInterruptibleCmd.C: Abstract class that supports lengthy,
43 // user-interruptible activities
44 //////////////////////////////////////////////////////////////
45 #include "RoamInterruptibleCmd.hh"
46 #include "DtMailWDM.hh"
47 #include "Application.h"
49 #include <Xm/MessageB.h>
51 extern forceUpdate( Widget );
54 RoamInterruptibleCmd::RoamInterruptibleCmd ( char *name,
57 NoUndoCmd ( name, label, active )
59 _wpId = NULL; // There is no work procedure yet
60 _callback = NULL; // Callbacks are specified in execute()
66 RoamInterruptibleCmd::~RoamInterruptibleCmd()
68 // Clean up by removing all callbacks
71 XtRemoveWorkProc ( _wpId );
75 RoamInterruptibleCmd::execute (
76 RoamTaskDoneCallback callback,
81 _clientData = clientData;
86 RoamInterruptibleCmd::execute()
90 name_str = (char *) name();
92 _done = FALSE; // Initialize flag
94 // Let the derived class post the dialog.
95 // Updates happen when derived classes call update() or
100 // Call the Cmd execute function to handle the Undo, and other
101 // general mechanisms supported by Cmd.
102 // execute() calls doit() of derived class.
106 // If the task was completed in a single call,
107 // don't bother to set up a work procedure. Just
108 // give derived classes a chance to cleanup and
109 // call the application's callback function
111 // If it was interrupted, the interruptCallback would have been
112 // called already and the dialog would have been unposted...
114 // We need to focus on only two cases here: what if the task was
115 // was completed in one call without interruptions (unpost dialog
116 // and call callback indicating task completed), and what if the
117 // task was not completed in one call (install a workProc...)
120 // if it done but not interrupted, it was genuinely done.
121 if (_done && !_interrupted)
123 unpost_dialog(); // derived classes implement this
126 if ( _callback ) // the FALSE is to say it was not interrupted.
127 ( *_callback )( this, FALSE, _clientData );
130 // If the task is not done and it was not interrupted and there is
131 // a callback to install, install a work procedure to continue the
132 // task as soon as possible. Call the callback via the work proc
136 else if ((!_done && !_interrupted && _callback))
139 _wpId = XtAppAddWorkProc ( theApplication->appContext(),
140 &RoamInterruptibleCmd::workProcCallback,
146 RoamInterruptibleCmd::workProcCallback (
150 RoamInterruptibleCmd *obj = (RoamInterruptibleCmd *) clientData;
152 // The work procedure just returns the value returned by the
153 // workProc member function.
155 return ( obj->workProc() );
159 RoamInterruptibleCmd::workProc()
161 // Call derived class's check_if_done() and see if they think the
162 // work is already done.
171 // the TRUE is to say task was interrupted
174 ( *_callback )( this, TRUE, _clientData );
177 // If the task has been completed, hide the dialog,
178 // give the derived class a chance to clean up, and notify
179 // the application that instantiated this object.
185 // the FALSE is to say task completed without interruptions
188 ( *_callback )( this, FALSE, _clientData );
195 RoamInterruptibleCmd::cleanup()
200 // The task has been interrupted. The user clicked on interrupt...
203 RoamInterruptibleCmd::interruptCallback (
207 RoamInterruptibleCmd *obj = ( RoamInterruptibleCmd * ) clientData;
209 // Just set the _interrupt flag to TRUE. The workProc()
210 // function will notice the next time it is called
216 RoamInterruptibleCmd::interrupt()
221 // Remove the work procedure
223 XtRemoveWorkProc ( _wpId );
226 // Remove the working dialog and give derived
227 // classes a chance to clean up
232 // Notify the application that the task was interrupted
235 ( *_callback )( this, TRUE, _clientData);
239 RoamInterruptibleCmd::updateMessage (
243 theDtMailWDM->updateDialog ( msg );
244 forceUpdate(theDtMailWDM->baseWidget());
248 RoamInterruptibleCmd::interrupted()
254 RoamInterruptibleCmd::update()
256 forceUpdate(theDtMailWDM->baseWidget());