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>
71 extern forceUpdate( Widget );
72 InterruptibleCmd::InterruptibleCmd ( char *name, char *label, int active ) :
73 NoUndoCmd ( name, label, active )
75 _wpId = NULL; // There is no work procedure yet
76 _callback = NULL; // Callbacks are specified in execute()
81 InterruptibleCmd::~InterruptibleCmd()
83 // Clean up by removing all callbacks
86 XtRemoveWorkProc ( _wpId );
89 void InterruptibleCmd::execute ( TaskDoneCallback callback, void *clientData )
92 _clientData = clientData;
96 void InterruptibleCmd::execute()
101 name_str = (char *) name();
102 label_str = (char *) getLabel();
104 _done = FALSE; // Initialize flag
106 // Call the Cmd execute function to handle the Undo, and other
107 // general mechanisms supported by Cmd. Execute calls doit()
111 // If the task was completed in a single call,
112 // don't bother to set up a work procedure. Just
113 // give derived classes a chance to cleanup and
114 // call the application's callback function
121 ( *_callback )( this, FALSE, _clientData );
124 // If the task is not done, post a WorkingDialog and
125 // install a work procedure to continue the task
126 // as soon as possible.
130 theWorkingDialogManager->post (label_str,
134 &InterruptibleCmd::interruptCallback );
136 _wpId = XtAppAddWorkProc ( theApplication->appContext(),
137 &InterruptibleCmd::workProcCallback,
142 Boolean InterruptibleCmd::workProcCallback ( XtPointer clientData )
144 InterruptibleCmd *obj = (InterruptibleCmd *) clientData;
146 // The work procedure just returns the value returned by the
147 // workProc member function.
149 return ( obj->workProc() );
152 Boolean InterruptibleCmd::workProc()
156 // If the task has been completed, hide the dialog,
157 // give the derived class a chance to clean up, and notify
158 // the application that instantiated this object.
162 theWorkingDialogManager->unpost();
166 ( *_callback )( this, FALSE, _clientData );
172 void InterruptibleCmd::cleanup()
177 void InterruptibleCmd::interruptCallback ( void * clientData )
179 InterruptibleCmd *obj = ( InterruptibleCmd * ) clientData;
181 // Just set the _interrupt flag to TRUE. The workProc()
182 // function will notice the next time it is called
187 void InterruptibleCmd::interrupt()
189 // Remove the work procedure
191 XtRemoveWorkProc ( _wpId );
193 // Remove the working dialog and give derived
194 // classes a chance to clean up
196 theWorkingDialogManager->unpost();
199 // Notify the application that the task was interrupted
202 ( *_callback )( this, TRUE, _clientData);
205 void InterruptibleCmd::updateMessage ( char * msg )
207 theWorkingDialogManager->updateMessage ( msg );