1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: wx/osx/app.h 3 // Purpose: wxApp class 4 // Author: Stefan Csomor 5 // Modified by: 6 // Created: 1998-01-01 7 // Copyright: (c) Stefan Csomor 8 // Licence: wxWindows licence 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WX_APP_H_ 12 #define _WX_APP_H_ 13 14 #include "wx/defs.h" 15 #include "wx/object.h" 16 #include "wx/gdicmn.h" 17 #include "wx/event.h" 18 19 class WXDLLIMPEXP_FWD_CORE wxFrame; 20 class WXDLLIMPEXP_FWD_CORE wxWindowMac; 21 class WXDLLIMPEXP_FWD_CORE wxApp ; 22 class WXDLLIMPEXP_FWD_CORE wxKeyEvent; 23 class WXDLLIMPEXP_FWD_BASE wxLog; 24 class WXDLLIMPEXP_FWD_CORE wxMacAutoreleasePool; 25 26 // Force an exit from main loop 27 void WXDLLIMPEXP_CORE wxExit(); 28 29 // Yield to other apps/messages 30 bool WXDLLIMPEXP_CORE wxYield(); 31 32 // Represents the application. Derive OnInit and declare 33 // a new App object to start application 34 class WXDLLIMPEXP_CORE wxApp: public wxAppBase 35 { 36 DECLARE_DYNAMIC_CLASS(wxApp) 37 38 wxApp(); 39 virtual ~wxApp(); 40 41 virtual void WakeUpIdle(); 42 SetPrintMode(int mode)43 virtual void SetPrintMode(int mode) { m_printMode = mode; } GetPrintMode()44 virtual int GetPrintMode() const { return m_printMode; } 45 46 // calling OnInit with an auto-release pool ready ... 47 virtual bool CallOnInit(); 48 #if wxUSE_GUI 49 // setting up all MacOS Specific Event-Handlers etc 50 virtual bool OnInitGui(); 51 #endif // wxUSE_GUI 52 53 virtual int OnRun(); 54 55 virtual bool ProcessIdle(); 56 57 // implementation only 58 void OnIdle(wxIdleEvent& event); 59 void OnEndSession(wxCloseEvent& event); 60 void OnQueryEndSession(wxCloseEvent& event); 61 62 protected: 63 int m_printMode; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT 64 wxMacAutoreleasePool* m_macPool; 65 66 public: 67 68 static bool sm_isEmbedded; 69 // Implementation 70 virtual bool Initialize(int& argc, wxChar **argv); 71 virtual void CleanUp(); 72 73 // the installed application event handler MacGetEventHandler()74 WXEVENTHANDLERREF MacGetEventHandler() { return m_macEventHandler ; } MacGetCurrentEventHandlerCallRef()75 WXEVENTHANDLERREF MacGetCurrentEventHandlerCallRef() { return m_macCurrentEventHandlerCallRef ; } MacSetCurrentEvent(WXEVENTREF event,WXEVENTHANDLERCALLREF handler)76 void MacSetCurrentEvent( WXEVENTREF event , WXEVENTHANDLERCALLREF handler ) 77 { m_macCurrentEvent = event ; m_macCurrentEventHandlerCallRef = handler ; } 78 79 // adding a CFType object to be released only at the end of the current event cycle (increases the 80 // refcount of the object passed), needed in case we are in the middle of an event concering an object 81 // we want to delete and cannot do it immediately 82 // TODO change semantics to be in line with cocoa (make autrelease NOT increase the count) 83 void MacAddToAutorelease( void* cfrefobj ); 84 void MacReleaseAutoreleasePool(); 85 86 public: 87 static wxWindow* s_captureWindow ; 88 static long s_lastModifiers ; 89 90 int m_nCmdShow; 91 92 // mac specifics 93 protected: 94 #if wxOSX_USE_COCOA 95 // override for support of custom app controllers 96 virtual WX_NSObject OSXCreateAppController(); 97 #endif 98 99 private: 100 virtual bool DoInitGui(); 101 virtual void DoCleanUp(); 102 103 WXEVENTHANDLERREF m_macEventHandler ; 104 WXEVENTHANDLERCALLREF m_macCurrentEventHandlerCallRef ; 105 WXEVENTREF m_macCurrentEvent ; 106 107 public: 108 static long s_macAboutMenuItemId ; 109 static long s_macPreferencesMenuItemId ; 110 static long s_macExitMenuItemId ; 111 static wxString s_macHelpMenuTitleName ; 112 MacGetCurrentEvent()113 WXEVENTREF MacGetCurrentEvent() { return m_macCurrentEvent ; } 114 115 // For embedded use. By default does nothing. 116 virtual void MacHandleUnhandledEvent( WXEVENTREF ev ); 117 118 bool MacSendKeyDownEvent( wxWindow* focus , long keyval , long modifiers , long when , wxChar uniChar ) ; 119 bool MacSendKeyUpEvent( wxWindow* focus , long keyval , long modifiers , long when , wxChar uniChar ) ; 120 bool MacSendCharEvent( wxWindow* focus , long keymessage , long modifiers , long when , wxChar uniChar ) ; 121 void MacCreateKeyEvent( wxKeyEvent& event, wxWindow* focus , long keymessage , long modifiers , long when , wxChar uniChar ) ; 122 #if wxOSX_USE_CARBON 123 // we only have applescript on these 124 virtual short MacHandleAEODoc(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ; 125 virtual short MacHandleAEGURL(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ; 126 virtual short MacHandleAEPDoc(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ; 127 virtual short MacHandleAEOApp(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ; 128 virtual short MacHandleAEQuit(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ; 129 virtual short MacHandleAERApp(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ; 130 #endif 131 // in response of an openFiles message with Cocoa and an 132 // open-document apple event 133 virtual void MacOpenFiles(const wxArrayString &fileNames) ; 134 // called by MacOpenFiles for each file. 135 virtual void MacOpenFile(const wxString &fileName) ; 136 // in response of a get-url apple event 137 virtual void MacOpenURL(const wxString &url) ; 138 // in response of a print-document apple event 139 virtual void MacPrintFiles(const wxArrayString &fileNames) ; 140 // called by MacPrintFiles for each file 141 virtual void MacPrintFile(const wxString &fileName) ; 142 // in response of a open-application apple event 143 virtual void MacNewFile() ; 144 // in response of a reopen-application apple event 145 virtual void MacReopenApp() ; 146 147 // Notice that this is just a placeholder and doesn't work yet! 148 // 149 // Override this to return false from a non-bundled console app in order to 150 // stay in background instead of being made a foreground application as 151 // happens by default. OSXIsGUIApplication()152 virtual bool OSXIsGUIApplication() { return true; } 153 154 #if wxOSX_USE_COCOA_OR_IPHONE 155 // immediately before the native event loop launches 156 virtual void OSXOnWillFinishLaunching(); 157 // immediately when the native event loop starts, no events have been served yet 158 virtual void OSXOnDidFinishLaunching(); 159 // OS asks to terminate app, return no to stay running 160 virtual bool OSXOnShouldTerminate(); 161 // before application terminates 162 virtual void OSXOnWillTerminate(); 163 164 private: 165 bool m_onInitResult; 166 bool m_inited; 167 wxArrayString m_openFiles; 168 wxArrayString m_printFiles; 169 wxString m_getURL; 170 171 public: OSXInitWasCalled()172 bool OSXInitWasCalled() { return m_inited; } OSXStoreOpenFiles(const wxArrayString & files)173 void OSXStoreOpenFiles(const wxArrayString &files ) { m_openFiles = files ; } OSXStorePrintFiles(const wxArrayString & files)174 void OSXStorePrintFiles(const wxArrayString &files ) { m_printFiles = files ; } OSXStoreOpenURL(const wxString & url)175 void OSXStoreOpenURL(const wxString &url ) { m_getURL = url ; } 176 #endif 177 178 // Hide the application windows the same as the system hide command would do it. 179 void MacHideApp(); 180 181 DECLARE_EVENT_TABLE() 182 }; 183 184 #endif 185 // _WX_APP_H_ 186 187