1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxApp class
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "app.h"
20 #include "wx/object.h"
21 #include "wx/gdicmn.h"
24 class WXDLLEXPORT wxFrame
;
25 class WXDLLEXPORT wxWindow
;
26 class WXDLLEXPORT wxApp
;
27 class WXDLLEXPORT wxKeyEvent
;
28 class WXDLLEXPORT wxLog
;
30 #define wxPRINT_WINDOWS 1
31 #define wxPRINT_POSTSCRIPT 2
33 WXDLLEXPORT_DATA(extern wxApp
*) wxTheApp
;
35 // Force an exit from main loop
36 void WXDLLEXPORT
wxExit();
38 // Yield to other apps/messages
39 bool WXDLLEXPORT
wxYield();
41 // Represents the application. Derive OnInit and declare
42 // a new App object to start application
43 class WXDLLEXPORT wxApp
: public wxEvtHandler
45 DECLARE_DYNAMIC_CLASS(wxApp
)
49 static void SetInitializerFunction(wxAppInitializerFunction fn
) { m_appInitFn
= fn
; }
50 static wxAppInitializerFunction
GetInitializerFunction() { return m_appInitFn
; }
52 virtual int MainLoop();
55 virtual bool Pending() ;
56 virtual void Dispatch() ;
58 void OnIdle(wxIdleEvent
& event
);
61 virtual bool OnInit() { return FALSE
; };
63 // No specific tasks to do here.
64 virtual bool OnInitGui() { return TRUE
; }
66 // Called to set off the main loop
67 virtual int OnRun() { return MainLoop(); };
68 virtual int OnExit() { return 0; }
70 inline void SetPrintMode(int mode
) { m_printMode
= mode
; }
71 inline int GetPrintMode() const { return m_printMode
; }
73 inline void SetExitOnFrameDelete(bool flag
) { m_exitOnFrameDelete
= flag
; }
74 inline bool GetExitOnFrameDelete() const { return m_exitOnFrameDelete
; }
76 inline wxString
GetAppName() const {
79 else return m_className
;
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
; }
86 void SetVendorName(const wxString
& vendorName
) { m_vendorName
= vendorName
; }
87 const wxString
& GetVendorName() const { return m_vendorName
; }
89 wxWindow
*GetTopWindow() const ;
90 inline void SetTopWindow(wxWindow
*win
) { m_topWindow
= win
; }
92 inline void SetWantDebugOutput(bool flag
) { m_wantDebugOutput
= flag
; }
93 inline bool GetWantDebugOutput() { return m_wantDebugOutput
; }
95 // Send idle event to all top-level windows.
96 // Returns TRUE if more idle time is requested.
97 bool SendIdleEvents();
99 // Send idle event to window and all subwindows
100 // Returns TRUE if more idle time is requested.
101 bool SendIdleEvents(wxWindow
* win
);
103 // Windows only, but for compatibility...
104 inline void SetAuto3D(bool flag
) { m_auto3D
= flag
; }
105 inline bool GetAuto3D() const { return m_auto3D
; }
107 // Creates a log object
108 virtual wxLog
* CreateLogTarget();
111 // Will always be set to the appropriate, main-style values.
116 bool m_wantDebugOutput
;
117 wxString m_className
;
120 wxWindow
* m_topWindow
;
121 bool m_exitOnFrameDelete
;
123 int m_printMode
; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT
124 bool m_auto3D
; // Always use 3D controls, except
126 static wxAppInitializerFunction m_appInitFn
;
131 static bool Initialize();
132 static void CleanUp();
134 void DeletePendingObjects();
138 static long sm_lastMessageTime
;
139 static wxWindow
* s_captureWindow
;
140 static int s_lastMouseDown
; // 0 = none , 1 = left , 2 = right
141 static RgnHandle s_macCursorRgn
;
142 EventRecord
* m_macCurrentEvent
;
152 static bool s_macDefaultEncodingIsPC
;
153 static bool s_macSupportPCMenuShortcuts
;
154 static long s_macAboutMenuItemId
;
155 static wxString s_macHelpMenuTitleName
;
157 static bool s_macHasAppearance
;
158 static long s_macAppearanceVersion
;
159 static bool s_macHasNavigation
;
160 static bool s_macNavigationVersion
;
161 static bool s_macHasWindowManager
;
162 static long s_macWindowManagerVersion
;
163 static bool s_macHasMenuManager
;
164 static long s_macMenuManagerVersion
;
165 static bool s_macHasDialogManager
;
166 static long s_macDialogManagerVersion
;
168 RgnHandle m_macCursorRgn
;
169 RgnHandle m_macSleepRgn
;
170 RgnHandle m_macHelpRgn
;
172 virtual void MacSuspend( bool convertClipboard
) ;
173 virtual void MacResume( bool convertClipboard
) ;
175 virtual void MacConvertPrivateToPublicScrap() ;
176 virtual void MacConvertPublicToPrivateScrap() ;
178 // event main methods
180 void MacDoOneEvent() ;
181 void MacHandleOneEvent( EventRecord
*ev
) ;
182 EventRecord
* MacGetCurrentEvent() { return m_macCurrentEvent
; }
185 virtual void MacHandleMouseDownEvent( EventRecord
*ev
) ;
186 virtual void MacHandleMouseUpEvent( EventRecord
*ev
) ;
187 virtual void MacHandleActivateEvent( EventRecord
*ev
) ;
188 virtual void MacHandleUpdateEvent( EventRecord
*ev
) ;
189 virtual void MacHandleKeyDownEvent( EventRecord
*ev
) ;
190 virtual void MacHandleKeyUpEvent( EventRecord
*ev
) ;
191 virtual void MacHandleDiskEvent( EventRecord
*ev
) ;
192 virtual void MacHandleOSEvent( EventRecord
*ev
) ;
193 virtual void MacHandleHighLevelEvent( EventRecord
*ev
) ;
194 virtual void MacHandleMenuSelect( int menuid
, int menuitem
) ;
196 virtual OSErr
MacHandleAEODoc(AppleEvent
*event
, AppleEvent
*reply
) ;
197 virtual OSErr
MacHandleAEPDoc(AppleEvent
*event
, AppleEvent
*reply
) ;
198 virtual OSErr
MacHandleAEOApp(AppleEvent
*event
, AppleEvent
*reply
) ;
199 virtual OSErr
MacHandleAEQuit(AppleEvent
*event
, AppleEvent
*reply
) ;
201 DECLARE_EVENT_TABLE()
204 // TODO: add platform-specific arguments
205 int WXDLLEXPORT
wxEntry( int argc
, char *argv
[] );
207 void wxMacConvertFromPCForControls( char * p
) ;
209 void wxMacConvertToPC( const char *from
, char *to
, int len
) ;
210 void wxMacConvertFromPC( const char *from
, char *to
, int len
) ;
211 void wxMacConvertToPC( const char *from
, char *to
, int len
) ;
212 void wxMacConvertFromPC( char * p
) ;
213 void wxMacConvertFromPC( unsigned char *p
) ;
214 wxString
wxMacMakeMacStringFromPC( const char * p
) ;
215 void wxMacConvertToPC( char * p
) ;
216 void wxMacConvertToPC( unsigned char *p
) ;
217 wxString
wxMacMakePCStringFromMac( const char * p
) ;