1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11 
12 
13 #ifndef _Application_h
14 #define _Application_h
15 
16 
17 #include <Xm/Xm.h>
18 #include "UIComponent.h"
19 #include "Server.h"
20 
21 //
22 // Class name definition:
23 //
24 #define ClassApplication	"Application"
25 
26 //
27 // XtCallbackProc (*CB), XtEventHandler (*EH) and XtActionProc (*AP)
28 // DialogCallback (*DCB) functions for this and derived classes
29 //
30 extern "C" void Application_XtWarningHandler(char*);
31 extern "C" int  Application_XErrorHandler(Display *display, XErrorEvent *event);
32 
33 //
34 // Application class definition:
35 //
36 class Application : public UIComponent, public Server
37 {
38   private:
39     //
40     // Private class data:
41     //
42     static boolean ApplicationClassInitialized;
43     friend void Application_XtWarningHandler(char *message);
44     friend int  Application_XErrorHandler(Display *display, XErrorEvent *event);
45 
46 
47     int 	busyCursors; 	// Keeps track of setBusyCursor calls.
48 
49     //
50     // The main program needs to access protected member functions.
51     //
52     friend int main(int argc,
53 		     char**       argv);
54 
55 
56     //
57     // Bubble help information
58     //
59     boolean  show_bubbles;
60     Widget   help_viewer;
61 
62   protected:
63     //
64     // Protected member data:
65     //
66     Display*     display;		// X Display pointer
67     XtAppContext applicationContext;	// Xt application context
68     char*        applicationClass;	// application class name
69 
70 
71     //
72     // Initialize the window system.
73     //
74     virtual boolean initializeWindowSystem(int *argcp, char **argv);
75 
76     virtual void parseCommand(int* argcp, char** argv,
77 			       XrmOptionDescList optlist, int optlistsize);
78 
79     //
80     // Handles application events.
81     //   This routine should be called by main() only.
82     //
83     virtual void handleEvent(XEvent *xev);
84 
85     //
86     // Load application specific action routines
87     //
addActions()88     virtual void addActions() {}
89 
90     //
91     // Post the copyright notice that is returned by this->getCopyrightNotice().
92     // If it returns NULL, then don't post any notice.
93     //
94     virtual void postCopyrightNotice();
95 
96     //
97     // Handle Xt Warnings (called by Application_XtWarningHandler, static, above)
98     // Handle X Errors (called by XErrorHandler, static, above)
99     //
100     virtual void handleXtWarning(char *message);
101     virtual int  handleXError(Display *display, XErrorEvent *event);
102 
103     //
104     // Constructor for the subclasses:
105     //
106     Application(char* className);
107 
108     //
109     // Install the default resources for this class and then call the
110     // same super class method to get the default resources from the
111     // super classes.
112     //
113     virtual void installDefaultResources(Widget baseWidget);
114 
115     //
116     // test the file to ensure that's is a regular file, and writable.
117     //
118     boolean isUsableDefaultsFile(const char* res_file, boolean create=FALSE);
119 
120   public:
121     //
122     // Busy indicator cursor to be used globally:
123     //
124     static Cursor BusyCursor;
125 
126     // Currently used only for debugging.
127     static void DumpApplicationResources(const char *filename);
128 
129     //
130     // Notification messages:
131     //
132     static Symbol MsgCreate;
133     static Symbol MsgManage;
134     static Symbol MsgUnmanage;
135     static Symbol MsgSetBusyCursor;
136     static Symbol MsgResetCursor;
137     static Symbol MsgManageByLeafClassName;
138     static Symbol MsgUnmanageByLeafClassName;
139     static Symbol MsgManageByTitle;
140     static Symbol MsgUnmanageByTitle;
141 
142     //
143     // Initializes the Xt Intrinsics (creating the first widget),
144     // by calling initializeWindowSytstem() if not already called.
145     // Initializes any Application specfic state.  This routine should
146     // be called by main() or subclasses only.
147     //
148     virtual boolean initialize(int* argcp, char** argv);
149 
150     //
151     // Allow others to access our event processing mechanism
152     //
passEventToHandler(XEvent * xev)153     void passEventToHandler(XEvent *xev) { this->handleEvent(xev); }
154 
155     //
156     // Virtual methods that are called by Command::ExecuteCommandCallback()
157     // before and after Command::execute().
158     // Send a message to all clients that we are beginngin/ending execution
159     // of a command.
160     //
161     virtual void startCommandInterfaceExecution();
162     virtual void endCommandInterfaceExecution();
163 
164     //
165     // Destructor:
166     //
167     ~Application();
168 
169     //
170     // Manages all the application windows.
171     //
172     void manage();
173 
174     //
175     // Unmanages all the application windows.
176     //
177     void unmanage();
178 
179     //
180     // Iconfies all the application windows.
181     //
182     void iconify();
183 
184     //
185     // Sets/resets busy cursor for the application.
186     // Calls to this routine can be 'stacked' so that the first call
187     // sets the cursor and the last call resets the cursor.
188     // setBusyCursor(TRUE);         // Sets busy cursor
189     // setBusyCursor(TRUE);         // does not effect cursor
190     // setBusyCursor(TRUE);         // does not effect cursor
191     // setBusyCursor(FALSE);        // does not effect cursor
192     // setBusyCursor(TRUE);         // does not effect cursor
193     // setBusyCursor(FALSE);        // does not effect cursor
194     // setBusyCursor(FALSE);        // does not effect cursor
195     // setBusyCursor(FALSE);        // resets cursor
196     //
197     void setBusyCursor(boolean setting);
198 
199     //
200     // Shutdown application (without deleting it out from under itself.
201     //
202     virtual void shutdownApplication() = 0;
203 
204     //
205     // Returns the Display pointer.
206     //
getDisplay()207     Display* getDisplay()
208     {
209 	return this->display;
210     }
211 
212     //
213     // Returns the application context pointer.
214     //
getApplicationContext()215     XtAppContext getApplicationContext()
216     {
217 	return this->applicationContext;
218     }
219 
220     //
221     // Returns the application class name.
222     //
getApplicationClass()223     const char* getApplicationClass()
224     {
225 	return this->applicationClass;
226     }
227 
228     //
229     // Return the name of the application (i.e. 'Data Explorer',
230     // 'Data Prompter', 'Medical Visualizer'...).
231     //
232     virtual const char *getInformalName();
233 
234     //
235     // Return the formal name of the application (i.e.
236     // 'Open Visualization Data Explorer', 'Open Visualization Data Prompter'...)
237     //
238     virtual const char *getFormalName();
239 
240     //
241     // Get the applications copyright notice, for example...
242     // "Copyright International Business Machines Corporation 1991-1993
243     // All rights reserved"
244     //
245     virtual const char *getCopyrightNotice();
246 
247     //
248     // Displays any help required.
249     //
250     virtual void helpOn(const char *topic);
251     virtual const char *getHelpDirectory();
252     virtual const char *getHelpDirFileName();
253     virtual const char *getHTMLDirectory();
254     virtual const char *getHTMLDirFileName();
255 
256     //
257     // Start a tutorial on behalf of the application.
258     // Return TRUE if successful.  At this level in the class hierachy
259     // we don't know how to start a tutorial so we always return FALSE.
260     //
261     virtual boolean startTutorial();
262 
263     //
264     // Return a pixmap with the logo in it.
265     //
getLogoPixmap(boolean)266     virtual Pixmap getLogoPixmap(boolean ){return XtUnspecifiedPixmap;};
cleanupLogo()267     virtual void cleanupLogo(){};
268 
269     //
270     // Return a pixmap with the icon in it.
271     //
getIconPixmap()272     virtual Pixmap getIconPixmap(){return XtUnspecifiedPixmap;};
273 
274     //
275     // A virtual method that allows other applications to handle ASSERT
276     // failures among other things.
277     //
278     virtual void abortApplication();
279 
280     //
281     // Control the display of bubble help
282     //
bubbleHelpEnabled()283     virtual boolean bubbleHelpEnabled() { return this->show_bubbles; }
284     virtual void    enableBubbleHelp (boolean state = TRUE)
285 	{ this->show_bubbles = state; }
setHelpViewer(Widget viewer)286     virtual void    setHelpViewer (Widget viewer) { this->help_viewer = viewer; }
getHelpViewer()287     virtual Widget  getHelpViewer () { return this->help_viewer; }
288 
289     virtual void handleEvents();
290 
291     virtual boolean getApplicationDefaultsFileName(char* res_file, boolean create=FALSE);
292 
293     //
294     // Returns a pointer to the class name.
295     //
getClassName()296     const char* getClassName()
297     {
298 	return ClassApplication;
299     }
300 };
301 
302 //
303 // Pointer to the single (hopefully) global instance:
304 //
305 extern Application* theApplication;
306 
307 
308 #endif // _Application_h
309