X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9482617091b084d4ee006679a450176715d465e0..b37023dca3a8627cee3fd26bf9cd9dae46e4a5b1:/src/mac/app.cpp diff --git a/src/mac/app.cpp b/src/mac/app.cpp index 9c3502089d..58ee11d265 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -288,6 +288,9 @@ void wxApp::MacNewFile() { kEventClassCommand, kEventProcessCommand } , { kEventClassCommand, kEventCommandUpdateStatus } , + { kEventClassMenu, kEventMenuOpening }, + { kEventClassMenu, kEventMenuClosed }, + { kEventClassApplication , kEventAppActivated } , { kEventClassApplication , kEventAppDeactivated } , // handling the quit event is not recommended by apple @@ -299,9 +302,35 @@ void wxApp::MacNewFile() { 'WXMC' , 'WXMC' } } ; -static pascal OSStatus MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) +static pascal OSStatus +MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) { - return eventNotHandledErr ; + // FIXME: this doesn't work for multiple windows + wxWindow *win = wxTheApp->GetTopWindow(); + if ( win ) + { + // VZ: we could find the menu from its handle here by examining all + // the menus in the menu bar recursively but knowing that neither + // wxMSW nor wxGTK do it why bother... +#if 0 + MenuRef menuRef; + + GetEventParameter(event, + kEventParamDirectObject, + typeMenuRef, NULL, + sizeof(menuRef), NULL, + &menuRef); +#endif // 0 + + wxMenuEvent wxevent(GetEventKind(event) == kEventMenuOpening + ? wxEVT_MENU_OPEN + : wxEVT_MENU_CLOSE); + wxevent.SetEventObject(win); + + (void)win->GetEventHandler()->ProcessEvent(wxevent); + } + + return eventNotHandledErr; } // due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop @@ -447,7 +476,7 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler ) WXIMPORT char std::__throws_bad_alloc ; #endif -bool wxApp::Initialize(int argc, wxChar **argv) +bool wxApp::Initialize(int& argc, wxChar **argv) { int error = 0 ; @@ -535,6 +564,20 @@ bool wxApp::Initialize(int argc, wxChar **argv) s_macCursorRgn = ::NewRgn() ; + // Mac OS X passes a process serial number command line argument when + // the application is launched from the Finder. This argument must be + // removed from the command line arguments before being handled by the + // application (otherwise applications would need to handle it) + if ( argc > 1 ) + { + static const wxChar *ARG_PSN = _T("-psn_"); + if ( wxStrncmp(argv[1], ARG_PSN, sizeof(ARG_PSN) - 1) == 0 ) + { + // remove this argument + memmove(argv, argv + 1, argc--); + } + } + if ( !wxAppBase::Initialize(argc, argv) ) return false; @@ -634,7 +677,7 @@ void wxApp::CleanUp() } //---------------------------------------------------------------------- -// wxEntry +// misc initialization stuff //---------------------------------------------------------------------- // extern variable for shared library resource id @@ -813,126 +856,6 @@ pascal void __wxterminate(void) #endif /* WXMAKINGDLL && !__DARWIN__ */ -int WXDLLEXPORT wxEntryStart( int WXUNUSED(argc), char *WXUNUSED(argv)[] ) -{ - return wxApp::Initialize(); -} - -int WXDLLEXPORT wxEntryInitGui() -{ - return wxTheApp->OnInitGui(); -} - -void WXDLLEXPORT wxEntryCleanup() -{ - wxApp::CleanUp(); -} - -int wxEntry( int argc, char *argv[] , bool enterLoop ) -{ -#ifdef __MWERKS__ -#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT - // This seems to be necessary since there are 'rogue' - // objects present at this point (perhaps global objects?) - // Setting a checkpoint will ignore them as far as the - // memory checking facility is concerned. - // Of course you may argue that memory allocated in globals should be - // checked, but this is a reasonable compromise. - wxDebugContext::SetCheckpoint(); -#endif -#endif - if (!wxEntryStart(argc, argv)) { - return 0; - } - // create the application object or ensure that one already exists - if (!wxTheApp) - { - // The app may have declared a global application object, but we recommend - // the IMPLEMENT_APP macro is used instead, which sets an initializer - // function for delayed, dynamic app object construction. - wxCHECK_MSG( wxApp::GetInitializerFunction(), 0, - wxT("No initializer - use IMPLEMENT_APP macro.") ); - - wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) (); - } - - wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") ); - -#ifdef __DARWIN__ - // Mac OS X passes a process serial number command line argument when - // the application is launched from the Finder. This argument must be - // removed from the command line arguments before being handled by the - // application (otherwise applications would need to handle it) - - if (argc > 1) { - if (strncmp(argv[1], "-psn_", 5) == 0) { - // assume the argument is always the only one and remove it - --argc; - } - } -#else - argc = 0 ; // currently we don't support files as parameters -#endif - // we could try to get the open apple events here to adjust argc and argv better - - wxTheApp->argc = argc; -#if wxUSE_UNICODE - wxTheApp->argv = new wxChar*[argc+1]; - int mb_argc ; - for ( mb_argc = 0; mb_argc < argc; mb_argc++ ) - { - wxTheApp->argv[mb_argc] = wxStrdup(wxConvLocal.cMB2WX(argv[mb_argc])); - } - wxTheApp->argv[mb_argc] = (wxChar *)NULL; -#else - wxTheApp->argv = argv; -#endif - - // GUI-specific initialization, such as creating an app context. - wxEntryInitGui(); - - // Here frames insert themselves automatically - // into wxTopLevelWindows by getting created - // in OnInit(). - - int retValue = 0; - - if ( wxTheApp->OnInit() ) - { - if ( enterLoop ) - { - retValue = wxTheApp->OnRun(); - } - else - // We want to initialize, but not run or exit immediately. - return 1; - } - //else: app initialization failed, so we skipped OnRun() - - wxWindow *topWindow = wxTheApp->GetTopWindow(); - if ( topWindow ) - { - // Forcibly delete the window. - if ( topWindow->IsKindOf(CLASSINFO(wxFrame)) || - topWindow->IsKindOf(CLASSINFO(wxDialog)) ) - { - topWindow->Close(TRUE); - wxTheApp->DeletePendingObjects(); - } - else - { - delete topWindow; - wxTheApp->SetTopWindow(NULL); - } - } - - wxTheApp->OnExit(); - - wxEntryCleanup(); - - return retValue; -} - #if TARGET_CARBON bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) @@ -1050,10 +973,6 @@ wxApp::wxApp() m_topWindow = NULL; wxTheApp = this; -#if WXWIN_COMPATIBILITY_2_2 - m_wantDebugOutput = TRUE; -#endif - argc = 0; argv = NULL; @@ -1081,16 +1000,6 @@ int wxApp::MainLoop() return 0; } -// Returns TRUE if more time is needed. -bool wxApp::ProcessIdle() -{ - wxIdleEvent event; - event.SetEventObject(this); - ProcessEvent(event); - - return event.MoreRequested(); -} - void wxApp::ExitMainLoop() { m_keepGoing = FALSE; @@ -1104,7 +1013,7 @@ bool wxApp::Pending() #else EventRecord event ; - return EventAvail( everyEvent , &event ) ; + return EventAvail( everyEvent , &event ) ; #endif } @@ -1116,33 +1025,13 @@ void wxApp::Dispatch() void wxApp::OnIdle(wxIdleEvent& event) { - // Avoid recursion (via ProcessEvent default case) - if ( s_inOnIdle ) - return; - - - s_inOnIdle = TRUE; - - // 'Garbage' collection of windows deleted with Close(). - DeletePendingObjects(); - - // flush the logged messages if any - wxLog *pLog = wxLog::GetActiveTarget(); - if ( pLog != NULL && pLog->HasPendingMessages() ) - pLog->Flush(); - - // Send OnIdle events to all windows - bool needMore = SendIdleEvents(); - - if (needMore) - event.RequestMore(TRUE); - + wxAppBase::OnIdle(event); + // If they are pending events, we must process them: pending events are // either events to the threads other than main or events posted with // wxPostEvent() functions wxMacProcessNotifierAndPendingEvents(); - s_inOnIdle = FALSE; if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar()) wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar(); } @@ -1152,46 +1041,6 @@ void wxApp::WakeUpIdle() wxMacWakeUp() ; } -// Send idle event to all top-level windows -bool wxApp::SendIdleEvents() -{ - bool needMore = FALSE; - wxWindowListNode* node = wxTopLevelWindows.GetFirst(); - while (node) - { - wxWindow* win = node->GetData(); - if (SendIdleEvents(win)) - needMore = TRUE; - - node = node->GetNext(); - } - return needMore; -} - -// Send idle event to window and all subwindows -bool wxApp::SendIdleEvents(wxWindow* win) -{ - bool needMore = FALSE; - - wxIdleEvent event; - event.SetEventObject(win); - win->ProcessEvent(event); - - if (event.MoreRequested()) - needMore = TRUE; - - wxWindowListNode* node = win->GetChildren().GetFirst(); - while (node) - { - wxWindow* win = node->GetData(); - if (SendIdleEvents(win)) - needMore = TRUE; - - node = node->GetNext(); - } - return needMore ; -} - void wxApp::Exit() { wxApp::CleanUp();