Misc changes for DOS compatibility, plus added wxApp::CreateConfig
[wxWidgets.git] / include / wx / msw / app.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: app.h
3 // Purpose: wxApp class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __APPH__
13 #define __APPH__
14
15 #ifdef __GNUG__
16 #pragma interface "app.h"
17 #endif
18
19 #include "wx/defs.h"
20 #include "wx/object.h"
21
22 class WXDLLEXPORT wxFrame;
23 class WXDLLEXPORT wxWindow;
24 class WXDLLEXPORT wxApp ;
25 class WXDLLEXPORT wxKeyEvent;
26 class WXDLLEXPORT wxLog;
27
28 #define wxPRINT_WINDOWS 1
29 #define wxPRINT_POSTSCRIPT 2
30
31 WXDLLEXPORT_DATA(extern wxApp*) wxTheApp;
32
33 void WXDLLEXPORT wxCleanUp(void);
34 void WXDLLEXPORT wxCommonCleanUp(void); // Call this from the platform's wxCleanUp()
35 void WXDLLEXPORT wxCommonInit(void); // Call this from the platform's initialization
36
37 // Force an exit from main loop
38 void WXDLLEXPORT wxExit(void);
39
40 // Yield to other apps/messages
41 bool WXDLLEXPORT wxYield(void);
42
43 // Represents the application. Derive OnInit and declare
44 // a new App object to start application
45 class wxConfig;
46 class WXDLLEXPORT wxApp: public wxEvtHandler
47 {
48 DECLARE_DYNAMIC_CLASS(wxApp)
49 wxApp(void);
50 inline ~wxApp(void) {}
51
52 static void SetInitializerFunction(wxAppInitializerFunction fn) { m_appInitFn = fn; }
53 static wxAppInitializerFunction GetInitializerFunction(void) { return m_appInitFn; }
54
55 virtual int MainLoop(void);
56 void ExitMainLoop(void);
57 bool Initialized(void);
58 virtual bool Pending(void) ;
59 virtual void Dispatch(void) ;
60
61 virtual void OnIdle(wxIdleEvent& event);
62
63 // Windows specific. Intercept keyboard input.
64 #if WXWIN_COMPATIBILITY == 2
65 virtual bool OldOnCharHook(wxKeyEvent& event);
66 #endif
67
68 // Generic
69 virtual bool OnInit(void) { return FALSE; };
70
71 // No specific tasks to do here.
72 virtual bool OnInitGui(void) { return TRUE; }
73
74 // override this function to create a global wxConfig object of different
75 // than default type (right now the default implementation returns NULL)
76 virtual wxConfig *CreateConfig(void) { return NULL; }
77
78 // Called to set off the main loop
79 virtual int OnRun(void) { return MainLoop(); };
80 virtual int OnExit(void) { return 0; };
81 inline void SetPrintMode(int mode) { m_printMode = mode; }
82 inline int GetPrintMode(void) const { return m_printMode; }
83
84 inline void SetExitOnFrameDelete(bool flag) { m_exitOnFrameDelete = flag; }
85 inline bool GetExitOnFrameDelete(void) const { return m_exitOnFrameDelete; }
86
87 /*
88 inline void SetShowFrameOnInit(bool flag) { m_showOnInit = flag; }
89 inline bool GetShowFrameOnInit(void) const { return m_showOnInit; }
90 */
91
92 inline wxString GetAppName(void) const {
93 if (m_appName != "")
94 return m_appName;
95 else return m_className;
96 }
97
98 inline void SetAppName(const wxString& name) { m_appName = name; };
99 inline wxString GetClassName(void) const { return m_className; }
100 inline void SetClassName(const wxString& name) { m_className = name; }
101 wxWindow *GetTopWindow(void) const ;
102 inline void SetTopWindow(wxWindow *win) { m_topWindow = win; }
103
104 inline void SetWantDebugOutput(bool flag) { m_wantDebugOutput = flag; }
105 inline bool GetWantDebugOutput(void) { return m_wantDebugOutput; }
106
107 // Send idle event to all top-level windows.
108 // Returns TRUE if more idle time is requested.
109 bool SendIdleEvents(void);
110
111 // Send idle event to window and all subwindows
112 // Returns TRUE if more idle time is requested.
113 bool SendIdleEvents(wxWindow* win);
114
115 inline void SetAuto3D(const bool flag) { m_auto3D = flag; }
116 inline bool GetAuto3D(void) const { return m_auto3D; }
117
118 // Creates a log object
119 virtual wxLog* CreateLogTarget(void);
120
121 public:
122 // void (*work_proc)(wxApp*app); // work procedure;
123 int argc;
124 char ** argv;
125
126 protected:
127 bool m_wantDebugOutput ;
128 wxString m_className;
129 wxString m_appName;
130 wxWindow * m_topWindow;
131 bool m_exitOnFrameDelete;
132 bool m_showOnInit;
133 int m_printMode; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT
134 bool m_auto3D ; // Always use 3D controls, except
135 // where overriden
136 static wxAppInitializerFunction m_appInitFn;
137
138 /* Windows-specific wxApp definitions */
139
140 public:
141
142 // Implementation
143 static bool Initialize(WXHINSTANCE instance);
144 static void CommonInit(void);
145 static bool RegisterWindowClasses(void);
146 static void CleanUp(void);
147 static void CommonCleanUp(void);
148 virtual bool DoMessage(void);
149 virtual bool ProcessMessage(WXMSG* pMsg);
150 void DeletePendingObjects(void);
151 bool ProcessIdle(void);
152
153 /*
154 inline void SetPendingCleanup(bool flag) { m_pendingCleanup = flag; }
155 inline bool GetPendingCleanup(void) { return m_pendingCleanup; }
156
157 bool DoResourceCleanup(void);
158 // Set resource collection scheme on or off.
159 inline void SetResourceCollection(bool flag) { m_resourceCollection = flag; }
160 inline bool GetResourceCollection(void) { return m_resourceCollection; }
161 */
162
163 public:
164 static long sm_lastMessageTime;
165 int m_nCmdShow;
166
167 protected:
168 bool m_keepGoing ;
169 // bool m_resourceCollection;
170 // bool m_pendingCleanup; // TRUE if we need to check the GDI object lists for cleanup
171
172 DECLARE_EVENT_TABLE()
173 };
174
175 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
176 int WXDLLEXPORT wxEntry(WXHINSTANCE hInstance, WXHINSTANCE hPrevInstance, char *lpszCmdLine,
177 int nCmdShow, bool enterLoop = TRUE);
178 #else
179 int WXDLLEXPORT wxEntry(WXHINSTANCE hInstance);
180 #endif
181
182 #endif
183 // __APPH__
184