Session management changes for wxMSW.
[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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_APP_H_
13 #define _WX_APP_H_
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 // Force an exit from main loop
34 void WXDLLEXPORT wxExit();
35
36 // Yield to other apps/messages
37 bool WXDLLEXPORT wxYield();
38
39 // Represents the application. Derive OnInit and declare
40 // a new App object to start application
41 class WXDLLEXPORT wxApp: public wxEvtHandler
42 {
43 DECLARE_DYNAMIC_CLASS(wxApp)
44 wxApp();
45 ~wxApp();
46
47 static void SetInitializerFunction(wxAppInitializerFunction fn) { m_appInitFn = fn; }
48 static wxAppInitializerFunction GetInitializerFunction() { return m_appInitFn; }
49
50 virtual int MainLoop();
51 void ExitMainLoop();
52 bool Initialized();
53 virtual bool Pending() ;
54 virtual void Dispatch() ;
55
56 void OnIdle(wxIdleEvent& event);
57 void OnEndSession(wxCloseEvent& event);
58 void OnQueryEndSession(wxCloseEvent& event);
59
60 // Generic
61 virtual bool OnInit() { return FALSE; };
62
63 // No specific tasks to do here.
64 virtual bool OnInitGui() { return TRUE; }
65
66 // Called to set off the main loop
67 virtual int OnRun() { return MainLoop(); };
68 virtual int OnExit() { return 0; }
69
70 inline void SetPrintMode(int mode) { m_printMode = mode; }
71 inline int GetPrintMode() const { return m_printMode; }
72
73 inline void SetExitOnFrameDelete(bool flag) { m_exitOnFrameDelete = flag; }
74 inline bool GetExitOnFrameDelete() const { return m_exitOnFrameDelete; }
75
76 inline wxString GetAppName() const {
77 if (m_appName != "")
78 return m_appName;
79 else return m_className;
80 }
81
82 inline void SetAppName(const wxString& name) { m_appName = name; };
83 inline wxString GetClassName() const { return m_className; }
84 inline void SetClassName(const wxString& name) { m_className = name; }
85
86 void SetVendorName(const wxString& vendorName) { m_vendorName = vendorName; }
87 const wxString& GetVendorName() const { return m_vendorName; }
88
89 wxWindow *GetTopWindow() const ;
90 inline void SetTopWindow(wxWindow *win) { m_topWindow = win; }
91
92 inline void SetWantDebugOutput(bool flag) { m_wantDebugOutput = flag; }
93 inline bool GetWantDebugOutput() { return m_wantDebugOutput; }
94
95 // Send idle event to all top-level windows.
96 // Returns TRUE if more idle time is requested.
97 bool SendIdleEvents();
98
99 // Send idle event to window and all subwindows
100 // Returns TRUE if more idle time is requested.
101 bool SendIdleEvents(wxWindow* win);
102
103 inline void SetAuto3D(bool flag) { m_auto3D = flag; }
104 inline bool GetAuto3D() const { return m_auto3D; }
105
106 // Creates a log object
107 virtual wxLog* CreateLogTarget();
108
109 public:
110 // void (*work_proc)(wxApp*app); // work procedure;
111 int argc;
112 char ** argv;
113
114 protected:
115 bool m_wantDebugOutput ;
116 wxString m_className;
117 wxString m_appName,
118 m_vendorName;
119 wxWindow * m_topWindow;
120 bool m_exitOnFrameDelete;
121 bool m_showOnInit;
122 int m_printMode; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT
123 bool m_auto3D ; // Always use 3D controls, except
124 // where overriden
125 static wxAppInitializerFunction m_appInitFn;
126
127 /* Windows-specific wxApp definitions */
128
129 public:
130
131 // Implementation
132 static bool Initialize();
133 static void CleanUp();
134
135 static bool RegisterWindowClasses();
136 // Convert Windows to argc, argv style
137 void ConvertToStandardCommandArgs(char* p);
138 virtual bool DoMessage();
139 virtual bool ProcessMessage(WXMSG* pMsg);
140 void DeletePendingObjects();
141 bool ProcessIdle();
142 int GetComCtl32Version() const;
143
144 public:
145 static long sm_lastMessageTime;
146 int m_nCmdShow;
147
148 protected:
149 bool m_keepGoing ;
150
151 DECLARE_EVENT_TABLE()
152 };
153
154 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
155 int WXDLLEXPORT wxEntry(WXHINSTANCE hInstance, WXHINSTANCE hPrevInstance, char *lpszCmdLine,
156 int nCmdShow, bool enterLoop = TRUE);
157 #else
158 int WXDLLEXPORT wxEntry(WXHINSTANCE hInstance);
159 #endif
160
161 #endif
162 // _WX_APP_H_
163