X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dde19c2180ef8d6415af7bb2492bfcb0a2d5c7e4..96c9640205933ad0673d5af2c96af0816c50160c:/src/msw/app.cpp diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 8222bb7060..8df236020f 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -121,13 +121,15 @@ extern void wxSetKeyboardHook(bool doIt); // see http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/110282 struct ClassRegInfo { - // the base name of the class: this is used to construct the unique name in - // RegisterClassWithUniqueNames() - wxString basename; + ClassRegInfo(const wxChar *name) + : regname(name), + regnameNR(regname + wxApp::GetNoRedrawClassSuffix()) + { + } // the name of the registered class with and without CS_[HV]REDRAW styles - wxString regname, - regnameNR; + wxString regname; + wxString regnameNR; }; namespace @@ -200,11 +202,6 @@ void *wxGUIAppTraits::BeforeChildWaitLoop() return new ChildWaitLoopData(wd, winActive); } -void wxGUIAppTraits::AlwaysYield() -{ - wxYield(); -} - void wxGUIAppTraits::AfterChildWaitLoop(void *dataOrig) { wxEndBusyCursor(); @@ -222,6 +219,7 @@ void wxGUIAppTraits::AfterChildWaitLoop(void *dataOrig) delete data; } +#if wxUSE_THREADS bool wxGUIAppTraits::DoMessageFromThreadWait() { // we should return false only if the app should exit, i.e. only if @@ -236,14 +234,20 @@ bool wxGUIAppTraits::DoMessageFromThreadWait() return evtLoop->Dispatch(); } -DWORD wxGUIAppTraits::WaitForThread(WXHANDLE hThread) +DWORD wxGUIAppTraits::WaitForThread(WXHANDLE hThread, int flags) { - // if we don't have a running event loop, we shouldn't wait for the - // messages as we never remove them from the message queue and so we enter - // an infinite loop as MsgWaitForMultipleObjects() keeps returning - // WAIT_OBJECT_0 + 1 - if ( !wxEventLoop::GetActive() ) + // We only ever dispatch messages from the main thread and, additionally, + // even from the main thread we shouldn't wait for the message if we don't + // have a running event loop as we would never remove them from the message + // queue then and so we would enter an infinite loop as + // MsgWaitForMultipleObjects() keeps returning WAIT_OBJECT_0 + 1. + if ( flags == wxTHREAD_WAIT_BLOCK || + !wxIsMainThread() || + !wxEventLoop::GetActive() ) + { + // Simple blocking wait. return DoSimpleWaitForThread(hThread); + } return ::MsgWaitForMultipleObjects ( @@ -255,6 +259,7 @@ DWORD wxGUIAppTraits::WaitForThread(WXHANDLE hThread) QS_ALLPOSTMESSAGE ); } +#endif // wxUSE_THREADS wxPortId wxGUIAppTraits::GetToolkitVersion(int *majVer, int *minVer) const { @@ -299,6 +304,8 @@ wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() #ifndef __WXWINCE__ +#if wxUSE_DYNLIB_CLASS + #include namespace @@ -337,7 +344,7 @@ public: { if ( !::FreeConsole() ) { - wxLogLastError(_T("FreeConsole")); + wxLogLastError(wxT("FreeConsole")); } } } @@ -406,7 +413,7 @@ bool wxConsoleStderr::DoInit() if ( hStderr == INVALID_HANDLE_VALUE || !hStderr ) return false; - if ( !m_dllKernel32.Load(_T("kernel32.dll")) ) + if ( !m_dllKernel32.Load(wxT("kernel32.dll")) ) return false; typedef BOOL (WINAPI *AttachConsole_t)(DWORD dwProcessId); @@ -439,7 +446,7 @@ bool wxConsoleStderr::DoInit() if ( !::GetConsoleScreenBufferInfo(m_hStderr, &csbi) ) { - wxLogLastError(_T("GetConsoleScreenBufferInfo")); + wxLogLastError(wxT("GetConsoleScreenBufferInfo")); return false; } @@ -456,7 +463,7 @@ bool wxConsoleStderr::DoInit() if ( !::ReadConsoleOutputCharacterA(m_hStderr, buf, WXSIZEOF(buf), pos, &ret) ) { - wxLogLastError(_T("ReadConsoleOutputCharacterA")); + wxLogLastError(wxT("ReadConsoleOutputCharacterA")); return false; } } while ( wxStrncmp(" ", buf, WXSIZEOF(buf)) != 0 ); @@ -471,7 +478,7 @@ bool wxConsoleStderr::DoInit() if ( !::ReadConsoleOutputCharacterA(m_hStderr, m_data.data(), m_dataLen, pos, &ret) ) { - wxLogLastError(_T("ReadConsoleOutputCharacterA")); + wxLogLastError(wxT("ReadConsoleOutputCharacterA")); return false; } } @@ -482,7 +489,7 @@ bool wxConsoleStderr::DoInit() int wxConsoleStderr::GetCommandHistory(wxWxCharBuffer& buf) const { // these functions are internal and may only be called by cmd.exe - static const wxChar *CMD_EXE = _T("cmd.exe"); + static const wxChar *CMD_EXE = wxT("cmd.exe"); const int len = m_pfnGetConsoleCommandHistoryLength(CMD_EXE); if ( len ) @@ -499,7 +506,7 @@ int wxConsoleStderr::GetCommandHistory(wxWxCharBuffer& buf) const if ( len2 != len ) { - wxFAIL_MSG( _T("failed getting history?") ); + wxFAIL_MSG( wxT("failed getting history?") ); } } @@ -508,7 +515,7 @@ int wxConsoleStderr::GetCommandHistory(wxWxCharBuffer& buf) const bool wxConsoleStderr::IsHistoryUnchanged() const { - wxASSERT_MSG( m_ok == 1, _T("shouldn't be called if not initialized") ); + wxASSERT_MSG( m_ok == 1, wxT("shouldn't be called if not initialized") ); // get (possibly changed) command history wxWxCharBuffer history; @@ -522,13 +529,13 @@ bool wxConsoleStderr::IsHistoryUnchanged() const bool wxConsoleStderr::Write(const wxString& text) { wxASSERT_MSG( m_hStderr != INVALID_HANDLE_VALUE, - _T("should only be called if Init() returned true") ); + wxT("should only be called if Init() returned true") ); // get current position CONSOLE_SCREEN_BUFFER_INFO csbi; if ( !::GetConsoleScreenBufferInfo(m_hStderr, &csbi) ) { - wxLogLastError(_T("GetConsoleScreenBufferInfo")); + wxLogLastError(wxT("GetConsoleScreenBufferInfo")); return false; } @@ -538,21 +545,21 @@ bool wxConsoleStderr::Write(const wxString& text) if ( !::SetConsoleCursorPosition(m_hStderr, csbi.dwCursorPosition) ) { - wxLogLastError(_T("SetConsoleCursorPosition")); + wxLogLastError(wxT("SetConsoleCursorPosition")); return false; } DWORD ret; - if ( !::FillConsoleOutputCharacter(m_hStderr, _T(' '), m_dataLen, + if ( !::FillConsoleOutputCharacter(m_hStderr, wxT(' '), m_dataLen, csbi.dwCursorPosition, &ret) ) { - wxLogLastError(_T("FillConsoleOutputCharacter")); + wxLogLastError(wxT("FillConsoleOutputCharacter")); return false; } if ( !::WriteConsole(m_hStderr, text.wx_str(), text.length(), &ret, NULL) ) { - wxLogLastError(_T("WriteConsole")); + wxLogLastError(wxT("WriteConsole")); return false; } @@ -575,6 +582,20 @@ bool wxGUIAppTraits::WriteToStderr(const wxString& text) return s_consoleStderr.IsOkToUse() && s_consoleStderr.Write(text); } +#else // !wxUSE_DYNLIB_CLASS + +bool wxGUIAppTraits::CanUseStderr() +{ + return false; +} + +bool wxGUIAppTraits::WriteToStderr(const wxString& WXUNUSED(text)) +{ + return false; +} + +#endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS + #endif // !__WXWINCE__ // =========================================================================== @@ -655,7 +676,7 @@ const wxChar *wxApp::GetRegisteredClassName(const wxChar *name, const size_t count = gs_regClassesInfo.size(); for ( size_t n = 0; n < count; n++ ) { - if ( gs_regClassesInfo[n].basename == name ) + if ( gs_regClassesInfo[n].regname == name ) return gs_regClassesInfo[n].regname.c_str(); } @@ -664,22 +685,13 @@ const wxChar *wxApp::GetRegisteredClassName(const wxChar *name, wxZeroMemory(wndclass); wndclass.lpfnWndProc = (WNDPROC)wxWndProc; - wndclass.hInstance = wxhInstance; + wndclass.hInstance = wxGetInstance(); wndclass.hCursor = ::LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)wxUIntToPtr(bgBrushCol + 1); wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | extraStyles; - ClassRegInfo regClass; - regClass.basename = name; - - // constuct a unique suffix to allow registering the class with the same - // base name in a main application using wxWidgets and a DLL using - // wxWidgets loaded into its address space: as gs_regClassesInfo variable - // is different in them, we're going to obtain a unique prefix by using its - // address here - regClass.regname = regClass.basename + - wxString::Format(wxT("@%p"), &gs_regClassesInfo); + ClassRegInfo regClass(name); wndclass.lpszClassName = regClass.regname.wx_str(); if ( !::RegisterClass(&wndclass) ) { @@ -688,17 +700,13 @@ const wxChar *wxApp::GetRegisteredClassName(const wxChar *name, return NULL; } - // NB: remember that code elsewhere supposes that no redraw class names - // use the same names as normal classes with "NR" suffix so we must put - // "NR" at the end instead of using more natural basename+"NR"+suffix - regClass.regnameNR = regClass.regname + GetNoRedrawClassSuffix(); wndclass.style &= ~(CS_HREDRAW | CS_VREDRAW); wndclass.lpszClassName = regClass.regnameNR.wx_str(); if ( !::RegisterClass(&wndclass) ) { wxLogLastError(wxString::Format(wxT("RegisterClass(%s)"), regClass.regname)); - ::UnregisterClass(regClass.regname.c_str(), wxhInstance); + ::UnregisterClass(regClass.regname.c_str(), wxGetInstance()); return NULL; } @@ -730,13 +738,13 @@ void wxApp::UnregisterWindowClasses() for ( size_t n = 0; n < count; n++ ) { const ClassRegInfo& regClass = gs_regClassesInfo[n]; - if ( !::UnregisterClass(regClass.regname.c_str(), wxhInstance) ) + if ( !::UnregisterClass(regClass.regname.c_str(), wxGetInstance()) ) { wxLogLastError(wxString::Format(wxT("UnregisterClass(%s)"), regClass.regname)); } - if ( !::UnregisterClass(regClass.regnameNR.c_str(), wxhInstance) ) + if ( !::UnregisterClass(regClass.regnameNR.c_str(), wxGetInstance()) ) { wxLogLastError(wxString::Format(wxT("UnregisterClass(%s)"), regClass.regnameNR)); @@ -825,6 +833,10 @@ void wxApp::WakeUpIdle() } } } +#if wxUSE_THREADS + else + wxWakeUpMainThread(); +#endif // wxUSE_THREADS } // ---------------------------------------------------------------------------- @@ -891,7 +903,7 @@ int CallDllGetVersion(wxDynamicLibrary& dll) HRESULT hr = (*pfnDllGetVersion)(&dvi); if ( FAILED(hr) ) { - wxLogApiError(_T("DllGetVersion"), hr); + wxLogApiError(wxT("DllGetVersion"), hr); return 0; } @@ -919,7 +931,7 @@ int wxApp::GetComCtl32Version() // depending on the OS version and the presence of the manifest, it can // be either v5 or v6 and instead of trying to guess it just get the // handle of the already loaded version - wxLoadedDLL dllComCtl32(_T("comctl32.dll")); + wxLoadedDLL dllComCtl32(wxT("comctl32.dll")); if ( !dllComCtl32.IsLoaded() ) { s_verComCtl32 = 0; @@ -934,7 +946,7 @@ int wxApp::GetComCtl32Version() if ( !s_verComCtl32 ) { // InitCommonControlsEx is unique to 4.70 and later - void *pfn = dllComCtl32.GetSymbol(_T("InitCommonControlsEx")); + void *pfn = dllComCtl32.GetSymbol(wxT("InitCommonControlsEx")); if ( !pfn ) { // not found, must be 4.00 @@ -944,7 +956,7 @@ int wxApp::GetComCtl32Version() { // many symbols appeared in comctl32 4.71, could use any of // them except may be DllInstall() - pfn = dllComCtl32.GetSymbol(_T("InitializeFlatSB")); + pfn = dllComCtl32.GetSymbol(wxT("InitializeFlatSB")); if ( !pfn ) { // not found, must be 4.70 @@ -971,7 +983,7 @@ int wxApp::GetShell32Version() // we're prepared to handle the errors wxLogNull noLog; - wxDynamicLibrary dllShell32(_T("shell32.dll"), wxDL_VERBATIM); + wxDynamicLibrary dllShell32(wxT("shell32.dll"), wxDL_VERBATIM); if ( dllShell32.IsLoaded() ) { s_verShell32 = CallDllGetVersion(dllShell32); @@ -1025,10 +1037,10 @@ bool wxApp::OnExceptionInMainLoop() ::MessageBox ( NULL, - _T("An unhandled exception occurred. Press \"Abort\" to \ + wxT("An unhandled exception occurred. Press \"Abort\" to \ terminate the program,\r\n\ \"Retry\" to exit the program normally and \"Ignore\" to try to continue."), - _T("Unhandled exception"), + wxT("Unhandled exception"), MB_ABORTRETRYIGNORE | MB_ICONERROR| MB_TASKMODAL @@ -1039,7 +1051,7 @@ terminate the program,\r\n\ throw; default: - wxFAIL_MSG( _T("unexpected MessageBox() return code") ); + wxFAIL_MSG( wxT("unexpected MessageBox() return code") ); // fall through case IDRETRY: