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: InterruptibleCmd.C /main/3 1995/11/06 16:00:32 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 //////////////////////////////////////////////////////////////////////////////
43 // This example code is from the book:
45 // Object-Oriented Programming with C++ and OSF/Motif
48 // Prentice Hall, 1992
51 // Copyright 1991 by Prentice Hall
52 // All Rights Reserved
54 // Permission to use, copy, modify, and distribute this software for
55 // any purpose except publication and without fee is hereby granted, provided
56 // that the above copyright notice appear in all copies of the software.
57 ///////////////////////////////////////////////////////////////////////////////
58 //////////////////////////////////////////////////////////////////////////////
61 ///////////////////////////////////////////////////////////////
62 // InterruptibleCmd.C: Abstract class that supports lengthy,
63 // user-interruptible activities
64 //////////////////////////////////////////////////////////////
65 #include "InterruptibleCmd.h"
66 #include "WorkingDialogManager.h"
67 #include "Application.h"
69 #include <Xm/MessageB.h>
73 extern forceUpdate( Widget );
76 InterruptibleCmd::InterruptibleCmd ( char *name, char *label, int active ) :
77 NoUndoCmd ( name, label, active )
79 _wpId = NULL; // There is no work procedure yet
80 _callback = NULL; // Callbacks are specified in execute()
85 InterruptibleCmd::~InterruptibleCmd()
87 // Clean up by removing all callbacks
90 XtRemoveWorkProc ( _wpId );
93 void InterruptibleCmd::execute ( TaskDoneCallback callback, void *clientData )
96 _clientData = clientData;
100 void InterruptibleCmd::execute()
105 name_str = (char *) name();
106 label_str = (char *) getLabel();
108 _done = FALSE; // Initialize flag
110 // Call the Cmd execute function to handle the Undo, and other
111 // general mechanisms supported by Cmd. Execute calls doit()
115 // If the task was completed in a single call,
116 // don't bother to set up a work procedure. Just
117 // give derived classes a chance to cleanup and
118 // call the application's callback function
125 ( *_callback )( this, FALSE, _clientData );
128 // If the task is not done, post a WorkingDialog and
129 // install a work procedure to continue the task
130 // as soon as possible.
134 theWorkingDialogManager->post (label_str,
138 &InterruptibleCmd::interruptCallback );
140 _wpId = XtAppAddWorkProc ( theApplication->appContext(),
141 &InterruptibleCmd::workProcCallback,
146 Boolean InterruptibleCmd::workProcCallback ( XtPointer clientData )
148 InterruptibleCmd *obj = (InterruptibleCmd *) clientData;
150 // The work procedure just returns the value returned by the
151 // workProc member function.
153 return ( obj->workProc() );
156 Boolean InterruptibleCmd::workProc()
160 // If the task has been completed, hide the dialog,
161 // give the derived class a chance to clean up, and notify
162 // the application that instantiated this object.
166 theWorkingDialogManager->unpost();
170 ( *_callback )( this, FALSE, _clientData );
176 void InterruptibleCmd::cleanup()
181 void InterruptibleCmd::interruptCallback ( void * clientData )
183 InterruptibleCmd *obj = ( InterruptibleCmd * ) clientData;
185 // Just set the _interrupt flag to TRUE. The workProc()
186 // function will notice the next time it is called
191 void InterruptibleCmd::interrupt()
193 // Remove the work procedure
195 XtRemoveWorkProc ( _wpId );
197 // Remove the working dialog and give derived
198 // classes a chance to clean up
200 theWorkingDialogManager->unpost();
203 // Notify the application that the task was interrupted
206 ( *_callback )( this, TRUE, _clientData);
209 void InterruptibleCmd::updateMessage ( char * msg )
211 theWorkingDialogManager->updateMessage ( msg );