1 /* $XConsortium: InterruptibleCmd.C /main/3 1995/11/06 16:00:32 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 //////////////////////////////////////////////////////////////////////////////
21 // This example code is from the book:
23 // Object-Oriented Programming with C++ and OSF/Motif
26 // Prentice Hall, 1992
29 // Copyright 1991 by Prentice Hall
30 // All Rights Reserved
32 // Permission to use, copy, modify, and distribute this software for
33 // any purpose except publication and without fee is hereby granted, provided
34 // that the above copyright notice appear in all copies of the software.
35 ///////////////////////////////////////////////////////////////////////////////
36 //////////////////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////
40 // InterruptibleCmd.C: Abstract class that supports lengthy,
41 // user-interruptible activities
42 //////////////////////////////////////////////////////////////
43 #include "InterruptibleCmd.h"
44 #include "WorkingDialogManager.h"
45 #include "Application.h"
47 #include <Xm/MessageB.h>
49 extern forceUpdate( Widget );
50 InterruptibleCmd::InterruptibleCmd ( char *name, char *label, int active ) :
51 NoUndoCmd ( name, label, active )
53 _wpId = NULL; // There is no work procedure yet
54 _callback = NULL; // Callbacks are specified in execute()
59 InterruptibleCmd::~InterruptibleCmd()
61 // Clean up by removing all callbacks
64 XtRemoveWorkProc ( _wpId );
67 void InterruptibleCmd::execute ( TaskDoneCallback callback, void *clientData )
70 _clientData = clientData;
74 void InterruptibleCmd::execute()
79 name_str = (char *) name();
80 label_str = (char *) getLabel();
82 _done = FALSE; // Initialize flag
84 // Call the Cmd execute function to handle the Undo, and other
85 // general mechanisms supported by Cmd. Execute calls doit()
89 // If the task was completed in a single call,
90 // don't bother to set up a work procedure. Just
91 // give derived classes a chance to cleanup and
92 // call the application's callback function
99 ( *_callback )( this, FALSE, _clientData );
102 // If the task is not done, post a WorkingDialog and
103 // install a work procedure to continue the task
104 // as soon as possible.
108 theWorkingDialogManager->post (label_str,
112 &InterruptibleCmd::interruptCallback );
114 _wpId = XtAppAddWorkProc ( theApplication->appContext(),
115 &InterruptibleCmd::workProcCallback,
120 Boolean InterruptibleCmd::workProcCallback ( XtPointer clientData )
122 InterruptibleCmd *obj = (InterruptibleCmd *) clientData;
124 // The work procedure just returns the value returned by the
125 // workProc member function.
127 return ( obj->workProc() );
130 Boolean InterruptibleCmd::workProc()
134 // If the task has been completed, hide the dialog,
135 // give the derived class a chance to clean up, and notify
136 // the application that instantiated this object.
140 theWorkingDialogManager->unpost();
144 ( *_callback )( this, FALSE, _clientData );
150 void InterruptibleCmd::cleanup()
155 void InterruptibleCmd::interruptCallback ( void * clientData )
157 InterruptibleCmd *obj = ( InterruptibleCmd * ) clientData;
159 // Just set the _interrupt flag to TRUE. The workProc()
160 // function will notice the next time it is called
165 void InterruptibleCmd::interrupt()
167 // Remove the work procedure
169 XtRemoveWorkProc ( _wpId );
171 // Remove the working dialog and give derived
172 // classes a chance to clean up
174 theWorkingDialogManager->unpost();
177 // Notify the application that the task was interrupted
180 ( *_callback )( this, TRUE, _clientData);
183 void InterruptibleCmd::updateMessage ( char * msg )
185 theWorkingDialogManager->updateMessage ( msg );