X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..87df17a11b0017d31c09f767bd921abb27193bee:/src/msw/app.cpp diff --git a/src/msw/app.cpp b/src/msw/app.cpp index d994f7b343..6277236d8e 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -86,7 +86,7 @@ #include #include -#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) +#if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) && !defined(__CYGWIN10__)) #include #endif @@ -601,7 +601,9 @@ void wxApp::CleanUp() #if wxUSE_THREADS delete wxPendingEventsLocker; // If we don't do the following, we get an apparent memory leak. +#if wxUSE_VALIDATORS ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker(); +#endif #endif wxClassInfo::CleanUpClasses(); @@ -724,15 +726,33 @@ int wxEntry(WXHINSTANCE hInstance, int retValue = 0; - if ( wxTheApp->OnInit() ) + // it is common to create a modal dialog in OnInit() (to ask/notify the + // user about something) but it wouldn't work if we don't change the + // "exit on delete last frame" flag here as when this dialog is + // deleted, the app would terminate (it was the last top level window + // as the main frame wasn't created yet!), so disable this behaviour + // temproarily + bool exitOnLastFrameDelete = wxTheApp->GetExitOnFrameDelete(); + wxTheApp->SetExitOnFrameDelete(FALSE); + + // init the app + retValue = wxTheApp->OnInit() ? 0 : -1; + + // restore the old flag value + wxTheApp->SetExitOnFrameDelete(exitOnLastFrameDelete); + + if ( retValue == 0 ) { if ( enterLoop ) { + // run the main loop retValue = wxTheApp->OnRun(); } else - // We want to initialize, but not run or exit immediately. + { + // we want to initialize, but not run or exit immediately. return 1; + } } //else: app initialization failed, so we skipped OnRun() @@ -937,16 +957,21 @@ bool wxApp::DoMessage() #endif // wxUSE_THREADS // Process the message - if ( !ProcessMessage((WXMSG *)&s_currentMsg) ) - { - ::TranslateMessage(&s_currentMsg); - ::DispatchMessage(&s_currentMsg); - } + DoMessage((WXMSG *)&s_currentMsg); } return TRUE; } +void wxApp::DoMessage(WXMSG *pMsg) +{ + if ( !ProcessMessage(pMsg) ) + { + ::TranslateMessage((MSG *)pMsg); + ::DispatchMessage((MSG *)pMsg); + } +} + /* * Keep trying to process messages until WM_QUIT * received. @@ -1035,17 +1060,20 @@ bool wxApp::ProcessMessage(WXMSG *wxmsg) // Try translations first; find the youngest window with // a translation table. wxWindow *wnd; - for ( wnd = wndThis; wnd; wnd = wnd->GetParent() ) - { - if ( wnd->MSWTranslateMessage(wxmsg) ) - return TRUE; - } - // Anyone for a non-translation message? Try youngest descendants first. + bool pastTopLevelWindow = FALSE; for ( wnd = wndThis; wnd; wnd = wnd->GetParent() ) { + if ( !pastTopLevelWindow && wnd->MSWTranslateMessage(wxmsg)) + return TRUE; if ( wnd->MSWProcessMessage(wxmsg) ) return TRUE; + + // stop at first top level window, i.e. don't try to process the key + // strokes originating in a dialog using the accelerators of the parent + // frame - this doesn't make much sense + if ( wnd->IsTopLevel() ) + pastTopLevelWindow = TRUE; } return FALSE; @@ -1261,12 +1289,22 @@ void wxExit() } // Yield to incoming messages + +static bool gs_inYield = FALSE; + bool wxYield() { // disable log flushing from here because a call to wxYield() shouldn't // normally result in message boxes popping up &c wxLog::Suspend(); +#ifdef __WXDEBUG__ + if (gs_inYield) + wxFAIL_MSG( wxT("wxYield called recursively" ) ); +#endif + + gs_inYield = TRUE; + // we don't want to process WM_QUIT from here - it should be processed in // the main event loop in order to stop it MSG msg; @@ -1288,9 +1326,20 @@ bool wxYield() // let the logs be flashed again wxLog::Resume(); + gs_inYield = FALSE; + return TRUE; } +// Yield to incoming messages; but fail silently if recursion is detected. +bool wxYieldIfNeeded() +{ + if (gs_inYield) + return FALSE; + + return wxYield(); +} + bool wxHandleFatalExceptions(bool doit) { #if wxUSE_ON_FATAL_EXCEPTION @@ -1300,7 +1349,8 @@ bool wxHandleFatalExceptions(bool doit) return TRUE; #else wxFAIL_MSG(_T("set wxUSE_ON_FATAL_EXCEPTION to 1 to sue this function")); - + + (void)doit; return FALSE; #endif }