app.h 7.0 KB

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