X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/42bcb12b405f19915ed009f6aa323d0e48cd89f6..2cc78389312dce6285d0d6b6e891d24372252ada:/src/msw/app.cpp diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 97db714527..f542a094a8 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -86,11 +86,13 @@ #include #include -#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__)) +#if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__) || defined(__WXMICROWIN__)) && !defined(__CYGWIN10__)) #include #endif +#ifndef __WXMICROWIN__ #include "wx/msw/msvcrt.h" +#endif // ---------------------------------------------------------------------------- // conditional compilation @@ -113,7 +115,8 @@ #define _WIN32_IE 0x0200 #endif -#if _WIN32_IE >= 0x0300 +#if _WIN32_IE >= 0x0300 \ + && !( defined(__MINGW32__) && !wxCHECK_W32API_VERSION( 1, 0 ) ) #include #endif @@ -124,7 +127,9 @@ extern wxChar *wxBuffer; extern wxList *wxWinHandleList; extern wxList WXDLLEXPORT wxPendingDelete; +#ifndef __WXMICROWIN__ extern void wxSetKeyboardHook(bool doIt); +#endif MSG s_currentMsg; wxApp *wxTheApp = NULL; @@ -234,12 +239,11 @@ bool wxApp::Initialize() wxBitmap::InitStandardHandlers(); -#if defined(__WIN95__) +#if defined(__WIN95__) && !defined(__WXMICROWIN__) InitCommonControls(); - #endif // __WIN95__ -#if wxUSE_OLE +#if wxUSE_OLE || wxUSE_DRAG_AND_DROP #ifdef __WIN16__ // for OLE, enlarge message queue to be as large as possible @@ -247,9 +251,11 @@ bool wxApp::Initialize() while (!SetMessageQueue(iMsg) && (iMsg -= 8)) ; #endif // Win16 + // we need to initialize OLE library if ( FAILED(::OleInitialize(NULL)) ) wxLogError(_("Cannot initialize OLE")); + #endif // wxUSE_OLE #if wxUSE_CTL3D @@ -257,7 +263,7 @@ bool wxApp::Initialize() wxLogError(wxT("Cannot register CTL3D")); Ctl3dAutoSubclass(wxhInstance); -#endif +#endif // wxUSE_CTL3D // VZ: these icons are not in wx.rc anyhow (but should they?)! #if 0 @@ -272,6 +278,7 @@ bool wxApp::Initialize() RegisterWindowClasses(); +#ifndef __WXMICROWIN__ // Create the brush for disabling bitmap buttons LOGBRUSH lb; @@ -283,6 +290,7 @@ bool wxApp::Initialize() ::DeleteObject( (HGDIOBJ)lb.lbHatch ); } //else: wxWindows resources are probably not linked in +#endif #if wxUSE_PENWINDOWS wxRegisterPenWin(); @@ -297,7 +305,9 @@ bool wxApp::Initialize() if (wxDummyChar) wxDummyChar++; #endif +#ifndef __WXMICROWIN__ wxSetKeyboardHook(TRUE); +#endif wxModule::RegisterModules(); if (!wxModule::InitializeModules()) @@ -561,7 +571,9 @@ void wxApp::CleanUp() //// WINDOWS-SPECIFIC CLEANUP +#ifndef __WXMICROWIN__ wxSetKeyboardHook(FALSE); +#endif #if wxUSE_PENWINDOWS wxCleanUpPenWin(); @@ -598,11 +610,14 @@ void wxApp::CleanUp() // GL: I'm annoyed ... I don't know where to put this and I don't want to // create a module for that as it's part of the core. delete wxPendingEvents; + #if wxUSE_THREADS delete wxPendingEventsLocker; - // If we don't do the following, we get an apparent memory leak. + // If we don't do the following, we get an apparent memory leak +#if wxUSE_VALIDATORS ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker(); -#endif +#endif // wxUSE_VALIDATORS +#endif // wxUSE_THREADS wxClassInfo::CleanUpClasses(); @@ -640,8 +655,7 @@ int WXDLLEXPORT wxEntryStart( int WXUNUSED(argc), char** WXUNUSED(argv) ) int WXDLLEXPORT wxEntryInitGui() { - wxTheApp->OnInitGui(); - return 0; + return wxTheApp->OnInitGui(); } void WXDLLEXPORT wxEntryCleanup() @@ -670,7 +684,10 @@ int wxEntry(WXHINSTANCE hInstance, // do check for memory leaks on program exit // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free // deallocated memory which may be used to simulate low-memory condition) +#ifndef __WXMICROWIN__ wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF); +#endif + #ifdef __MWERKS__ #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT // This seems to be necessary since there are 'rogue' @@ -702,7 +719,7 @@ int wxEntry(WXHINSTANCE hInstance, wxCHECK_MSG( wxApp::GetInitializerFunction(), 0, wxT("No initializer - use IMPLEMENT_APP macro.") ); - wxTheApp = (*wxApp::GetInitializerFunction()) (); + wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) (); } wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") ); @@ -711,10 +728,6 @@ int wxEntry(WXHINSTANCE hInstance, wxTheApp->ConvertToStandardCommandArgs(lpCmdLine); wxTheApp->m_nCmdShow = nCmdShow; - // GUI-specific initialisation. In fact on Windows we don't have any, - // but this call is provided for compatibility across platforms. - wxEntryInitGui(); - // We really don't want timestamps by default, because it means // we can't simply double-click on the error message and get to that // line in the source. So VC++ at least, let's have a sensible default. @@ -724,15 +737,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 = wxEntryInitGui() && 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() @@ -828,14 +859,9 @@ wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NUL wxApp::wxApp() { - m_topWindow = NULL; - wxTheApp = this; - m_wantDebugOutput = TRUE; - argc = 0; argv = NULL; m_printMode = wxPRINT_WINDOWS; - m_exitOnFrameDelete = TRUE; m_auto3D = TRUE; } @@ -937,16 +963,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. @@ -1036,17 +1067,19 @@ bool wxApp::ProcessMessage(WXMSG *wxmsg) // a translation table. wxWindow *wnd; + bool pastTopLevelWindow = FALSE; for ( wnd = wndThis; wnd; wnd = wnd->GetParent() ) { - if ( wnd->MSWTranslateMessage(wxmsg) ) + if ( !pastTopLevelWindow && wnd->MSWTranslateMessage(wxmsg)) return TRUE; - } - - // Anyone for a non-translation message? Try youngest descendants first. - for ( wnd = wndThis; wnd; wnd = wnd->GetParent() ) - { 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; @@ -1079,6 +1112,14 @@ void wxApp::OnIdle(wxIdleEvent& event) wxLog::FlushActive(); #endif // wxUSE_LOG +#if wxUSE_DC_CACHEING + // automated DC cache management: clear the cached DCs and bitmap + // if it's likely that the app has finished with them, that is, we + // get an idle event and we're not dragging anything. + if (!::GetKeyState(MK_LBUTTON) && !::GetKeyState(MK_MBUTTON) && !::GetKeyState(MK_RBUTTON)) + wxDC::ClearCache(); +#endif // wxUSE_DC_CACHEING + // Send OnIdle events to all windows if ( SendIdleEvents() ) { @@ -1169,6 +1210,9 @@ void wxApp::OnQueryEndSession(wxCloseEvent& event) /* static */ int wxApp::GetComCtl32Version() { +#ifdef __WXMICROWIN__ + return 0; +#else // cache the result static int s_verComCtl32 = -1; @@ -1251,6 +1295,7 @@ int wxApp::GetComCtl32Version() } return s_verComCtl32; +#endif } void wxExit() @@ -1262,12 +1307,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; @@ -1289,9 +1344,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 @@ -1301,7 +1367,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 }