1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxApp class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "app.h"
20 #include "wx/object.h"
22 class WXDLLEXPORT wxFrame
;
23 class WXDLLEXPORT wxWindow
;
24 class WXDLLEXPORT wxApp
;
25 class WXDLLEXPORT wxKeyEvent
;
26 class WXDLLEXPORT wxLog
;
28 #define wxPRINT_WINDOWS 1
29 #define wxPRINT_POSTSCRIPT 2
31 WXDLLEXPORT_DATA(extern wxApp
*) wxTheApp
;
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
37 // Force an exit from main loop
38 void WXDLLEXPORT
wxExit(void);
40 // Yield to other apps/messages
41 bool WXDLLEXPORT
wxYield(void);
43 // Represents the application. Derive OnInit and declare
44 // a new App object to start application
45 class WXDLLEXPORT wxApp
: public wxEvtHandler
47 DECLARE_DYNAMIC_CLASS(wxApp
)
49 inline ~wxApp(void) {}
51 static void SetInitializerFunction(wxAppInitializerFunction fn
) { m_appInitFn
= fn
; }
52 static wxAppInitializerFunction
GetInitializerFunction(void) { return m_appInitFn
; }
54 virtual int MainLoop(void);
55 void ExitMainLoop(void);
56 bool Initialized(void);
57 virtual bool Pending(void) ;
58 virtual void Dispatch(void) ;
60 virtual void OnIdle(wxIdleEvent
& event
);
62 // Windows specific. Intercept keyboard input.
63 #if WXWIN_COMPATIBILITY == 2
64 virtual bool OldOnCharHook(wxKeyEvent
& event
);
68 virtual bool OnInit(void) { return FALSE
; };
70 // No specific tasks to do here.
71 virtual bool OnInitGui(void) { return TRUE
; }
73 // Called to set off the main loop
74 virtual int OnRun(void) { return MainLoop(); };
75 virtual int OnExit(void) { return 0; };
76 inline void SetPrintMode(int mode
) { m_printMode
= mode
; }
77 inline int GetPrintMode(void) const { return m_printMode
; }
79 inline void SetExitOnFrameDelete(bool flag
) { m_exitOnFrameDelete
= flag
; }
80 inline bool GetExitOnFrameDelete(void) const { return m_exitOnFrameDelete
; }
83 inline void SetShowFrameOnInit(bool flag) { m_showOnInit = flag; }
84 inline bool GetShowFrameOnInit(void) const { return m_showOnInit; }
87 inline wxString
GetAppName(void) const {
90 else return m_className
;
93 inline void SetAppName(const wxString
& name
) { m_appName
= name
; };
94 inline wxString
GetClassName(void) const { return m_className
; }
95 inline void SetClassName(const wxString
& name
) { m_className
= name
; }
96 wxWindow
*GetTopWindow(void) const ;
97 inline void SetTopWindow(wxWindow
*win
) { m_topWindow
= win
; }
99 inline void SetWantDebugOutput(bool flag
) { m_wantDebugOutput
= flag
; }
100 inline bool GetWantDebugOutput(void) { return m_wantDebugOutput
; }
102 // Send idle event to all top-level windows.
103 // Returns TRUE if more idle time is requested.
104 bool SendIdleEvents(void);
106 // Send idle event to window and all subwindows
107 // Returns TRUE if more idle time is requested.
108 bool SendIdleEvents(wxWindow
* win
);
110 inline void SetAuto3D(const bool flag
) { m_auto3D
= flag
; }
111 inline bool GetAuto3D(void) const { return m_auto3D
; }
113 // Creates a log object
114 virtual wxLog
* CreateLogTarget(void);
117 // void (*work_proc)(wxApp*app); // work procedure;
122 bool m_wantDebugOutput
;
123 wxString m_className
;
125 wxWindow
* m_topWindow
;
126 bool m_exitOnFrameDelete
;
128 int m_printMode
; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT
129 bool m_auto3D
; // Always use 3D controls, except
131 static wxAppInitializerFunction m_appInitFn
;
133 /* Windows-specific wxApp definitions */
138 static bool Initialize(WXHINSTANCE instance
);
139 static void CommonInit(void);
140 static bool RegisterWindowClasses(void);
141 static void CleanUp(void);
142 static void CommonCleanUp(void);
143 virtual bool DoMessage(void);
144 virtual bool ProcessMessage(WXMSG
* pMsg
);
145 void DeletePendingObjects(void);
146 bool ProcessIdle(void);
149 inline void SetPendingCleanup(bool flag) { m_pendingCleanup = flag; }
150 inline bool GetPendingCleanup(void) { return m_pendingCleanup; }
152 bool DoResourceCleanup(void);
153 // Set resource collection scheme on or off.
154 inline void SetResourceCollection(bool flag) { m_resourceCollection = flag; }
155 inline bool GetResourceCollection(void) { return m_resourceCollection; }
159 static long sm_lastMessageTime
;
164 // bool m_resourceCollection;
165 // bool m_pendingCleanup; // TRUE if we need to check the GDI object lists for cleanup
167 DECLARE_EVENT_TABLE()
170 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
171 int WXDLLEXPORT
wxEntry(WXHINSTANCE hInstance
, WXHINSTANCE hPrevInstance
, char *lpszCmdLine
,
172 int nCmdShow
, bool enterLoop
= TRUE
);
174 int WXDLLEXPORT
wxEntry(WXHINSTANCE hInstance
);