1 /*****************************************************************************/
2 /* */
3 /* PROGRAM.H */
4 /* */
5 /* (C) 1993-96 Ullrich von Bassewitz */
6 /* Wacholderweg 14 */
7 /* D-70597 Stuttgart */
8 /* EMail: uz@ibb.schwaben.com */
9 /* */
10 /*****************************************************************************/
11
12
13
14 // $Id$
15 //
16 // $Log$
17 //
18 //
19
20
21
22 #ifndef _PROGRAM_H
23 #define _PROGRAM_H
24
25
26
27 #include "statline.h"
28 #include "event.h"
29 #include "thread.h"
30 #include "menue.h"
31 #include "msgcoll.h"
32 #include "resource.h"
33 #include "datetime.h"
34
35
36
37 /*****************************************************************************/
38 /* Data */
39 /*****************************************************************************/
40
41
42
43 // Instance of class Program
44 extern class Program *App;
45
46
47
48 /*****************************************************************************/
49 /* class Program */
50 /*****************************************************************************/
51
52
53
54 class Program: public EventHandler, public Thread {
55
56 private:
57 void (*OldFailVec) (const char*, const char*, int, const char*, int);
58 // Old fail vector
59
60 static void _CheckFailed (const char* Msg, const char* Cond,
61 int Code, const char* File, int Line);
62 // Function that is called if a fatal error occurs. The function simply
63 // calls the virtual function AppError, which can be overridden by derived
64 // classes. After returning from CheckFailed, the screen is cleared and
65 // the program is aborted.
66
67 static void _InitCheckFailed (const char* Msg, const char* Cond,
68 int Code, const char* File, int Line);
69 // Temporary function that is installed while initializing. It avoids
70 // calling other high level spunk functions since they may not be
71 // initialized.
72
73 protected:
74 ResourceFile* MainResource;
75 MsgCollection* MsgBase; // Messages for the library
76 MsgCollection* AppMsgBase; // Messages for the application
77 String ProgramName; // Base name for the program
78 String SupportPath; // Path for support files
79 String HelpFileName; // Name+path of the help file
80 unsigned PID; // Process ID
81 int GotSigWinCh; // true if a SIGWINCH occured
82 EventQueue EvQueue; // EventQueue
83 Time LastIdleTime; // Time of last update
84
85
86 virtual int SigUsr3 ();
87 // Handle the SIGUSR3 signal. This is used as a replacement for
88 // SIGWINCH under NT. The function will do nothing if not running
89 // under NT.
90
91 virtual int SigWinCh ();
92 // Handle the SIGWINCH signal (Unices only)
93
94 virtual void Cleanup ();
95 // Clean up in the destructor or in a emergeny situation
96
97 virtual void AppError (const char* Msg, const char* Cond,
98 int Code, const char* File, int Line);
99 // Function that is called in case of errors. The function is usually
100 // called from _CheckFailed. It should not be called directly because
101 // it does no cleanup and simply returns to the caller after displaying
102 // an error message.
103
104 virtual String AppMsgBaseName ();
105 // This function builds the name for the application message resource.
106 // The default is to use ProgramName in uppercase, preceeded by a '@'
107 // and with '.Messages' added (e.g. "@RESED.Messages").
108
109 virtual void DeliverEvents ();
110 // Deliver all events currently in the event queue.
111
112 virtual void SendEvent (Event* E);
113 // Send the event to all event handlers without going over the event
114 // queue. E is deleted after delivery. Use with care!
115
116
117 public:
118 // Public accessible variables
119 BottomStatusLine* StatusLine;
120 TopMenueBar* MainMenue;
121 int ArgCount; // Expanded argc from main()
122 char** ArgVec; // Expanded argv from main()
123
124 public:
125 Program (int argc, char** argv,
126 TopMenueBar* (*GetMenueBar) (),
127 BottomStatusLine* (*GetStatusLine) (),
128 const String& ProgBaseName);
129 // Create a program object. argc/argv are the arguments from main. On
130 // OS/2 and DOS systems, they will be expanded, on all systems they end up
131 // in the global accessible variables ArgCount and ArgVec.
132 // GetMenueBar ist a function pointer that is called to create the menue
133 // bar. GetStatusLine is a function pointer that is called to create the
134 // status line. Both may be NULL if no menue bar and/or status line is
135 // needed. Beware: Many functions of the library assume that a statusline
136 // exists!
137 // ProgBaseName is the base name of the program. It is used as basename
138 // for resource and help files and for window titles (if needed).
139
140 virtual ~Program ();
141 // Destruct a program object
142
143 Streamable* LoadResource (const String& Name, int MustHave = 1);
144 // Load a program resource from the resource file. The usual language
145 // resolving algorithm is applied. If MustHave is set to 1, the function
146 // will abort the program (via FAIL) if the resource is not available
147
148 virtual const Msg& LoadMsg (u16 MsgNum);
149 // Load a message from the library message base. Application functions
150 // should use LoadAppMsg instead. If the MsgBase is not already loaded,
151 // this function will load it.
152
153 virtual const Msg& LoadAppMsg (u16 MsgNum);
154 // Load a message from the application message base. Library functions
155 // should use LoadMsg instead. If AppMsgBase is not already loaded,
156 // this function will load it.
157
158 virtual void FreeMsgBase ();
159 // The library message base will be deleted. This is useful if you are
160 // temporary short on memory. The next call to LoadMsg will reload the
161 // MsgBase, so repeatedly calling this function will slow down the
162 // program. Beware: After calling this function, references to messages
163 // are no longer valid!
164
165 virtual void FreeAppMsgBase ();
166 // The application message base will be deleted. This is useful if you are
167 // temporary short on memory. The next call to LoadAppMsg will reload the
168 // AppMsgBase, so repeatedly calling this function will slow down the
169 // program. Beware: After calling this function, references to messages
170 // are no longer valid!
171
172 virtual void Idle ();
173 // This is the idle function of the application class. Default is to
174 // do some housekeeping. This function may be called by anyone
175 // at anytime but it's not guaranteed to be called regularly.
176
177 void ChangeVideoMode (u16 NewMode);
178 // Change video mode to NewMode. Use the constants from screen.h
179
180 void RedrawScreen ();
181 // Redraw the complete screen in case it's garbled
182
183 unsigned GetPID () const;
184 // Get process ID
185
186 const String& GetSupportPath () const;
187 // Access the protected variable
188
189 const String& GetProgName () const;
190 // Return the program base name
191
192 int HasHelp () const;
193 // Return true if we have help available. This is assumed to be true if
194 // the help file exists and is readable.
195
196 void CallHelp (const String& HelpTopic);
197 // Call the help with the specified topic
198
199 virtual void PostEvent (Event* E, int ImmediateDelivery = 1);
200 // Post an event to the event queue, eventually call DeliverEvents.
201 // The event will be deleted after successful delivery.
202
203 void RemoveArg (int Index);
204 // Remove the program argument with the given index. The function will
205 // call FAIL if the index is invalid.
206
207 };
208
209
210
GetPID()211 inline unsigned Program::GetPID () const
212 {
213 return PID;
214 }
215
216
217
GetSupportPath()218 inline const String& Program::GetSupportPath () const
219 // Access the protected variable
220 {
221 return SupportPath;
222 }
223
224
225
GetProgName()226 inline const String& Program::GetProgName () const
227 // Access the protected variable
228 {
229 return ProgramName;
230 }
231
232
233
HasHelp()234 inline int Program::HasHelp () const
235 // Return true if we have help available. This is assumed to be true if the
236 // help file exists and is readable.
237 {
238 return HelpFileName.IsEmpty () == 0;
239 }
240
241
242
243 // End of PROGRAM.H
244
245 #endif
246
247
248