X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1aff8b0241145ab734b1efc880aeff17b5a6e955..c05cbb7f5eeb6da774e4e5528318a55e24b595cf:/src/msw/app.cpp diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 91d1c05287..2ca841caa5 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -92,6 +92,10 @@ extern char *wxBuffer; extern char *wxOsVersion; extern wxList *wxWinHandleList; extern wxList WXDLLEXPORT wxPendingDelete; +#if wxUSE_THREADS +extern wxList *wxPendingEvents; +extern wxCriticalSection *wxPendingEventsLocker; +#endif extern void wxSetKeyboardHook(bool doIt); extern wxCursor *g_globalCursor; @@ -165,6 +169,12 @@ bool wxApp::Initialize() wxGetResource("wxWindows", "OsVersion", &wxOsVersion); #endif + // 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. +#if wxUSE_THREADS + wxPendingEvents = new wxList(); + wxPendingEventsLocker = new wxCriticalSection(); +#endif + wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING); wxTheColourDatabase->Initialize(); @@ -398,12 +408,8 @@ void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine) char name[260]; // 260 is MAX_PATH value from windef.h ::GetModuleFileName(wxhInstance, name, WXSIZEOF(name)); - // GNUWIN32 already fills in the first arg with the application name. - // JACS: apparently not now (b20 and above?) -#if 0 // !defined(__GNUWIN32__) args.Add(name); - count ++; -#endif + count++; strcpy(name, wxFileNameFromPath(name)); wxStripExtension(name); @@ -491,6 +497,7 @@ void wxApp::CleanUp() // (double deletion of the cursor). wxSetCursor(wxNullCursor); delete g_globalCursor; + g_globalCursor = NULL; wxDeleteStockObjects() ; @@ -550,6 +557,15 @@ void wxApp::CleanUp() if (wxWinHandleList) delete wxWinHandleList ; + // 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. +#if wxUSE_THREADS + delete wxPendingEvents; + delete wxPendingEventsLocker; + // If we don't do the following, we get an apparent memory leak. + ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker(); +#endif + wxClassInfo::CleanUpClasses(); delete wxTheApp; @@ -560,7 +576,7 @@ void wxApp::CleanUp() // blocks that aren't part of the wxDebugContext itself, // as a special case. Then when dumping we need to ignore // wxDebugContext, too. - if (wxDebugContext::CountObjectsLeft() > 0) + if (wxDebugContext::CountObjectsLeft(TRUE) > 0) { wxLogDebug("There were memory leaks."); wxDebugContext::Dump(); @@ -896,7 +912,13 @@ int wxApp::MainLoop() { } + DoMessage(); + + // If they are pending events, we must process them. +#if wxUSE_THREADS + ProcessPendingEvents(); +#endif } return s_currentMsg.wParam; @@ -912,6 +934,25 @@ bool wxApp::ProcessIdle() return event.MoreRequested(); } +#if wxUSE_THREADS +void wxApp::ProcessPendingEvents() +{ + wxNode *node = wxPendingEvents->First(); + wxCriticalSectionLocker locker(*wxPendingEventsLocker); + + while (node) + { + wxEvtHandler *handler = (wxEvtHandler *)node->Data(); + + handler->ProcessPendingEvents(); + + delete node; + node = wxPendingEvents->First(); + } +} +#endif + + void wxApp::ExitMainLoop() { m_keepGoing = FALSE; @@ -932,34 +973,28 @@ void wxApp::Dispatch() * the message. Some may have accelerator tables, or have * MDI complications. */ -bool wxApp::ProcessMessage(WXMSG *Msg) -{ - MSG *msg = (MSG *)Msg; - HWND hWnd; +bool wxApp::ProcessMessage(WXMSG *wxmsg) +{ + MSG *msg = (MSG *)wxmsg; + HWND hWnd = msg->hwnd; + wxWindow *wndThis = wxFindWinFromHandle((WXHWND)hWnd), *wnd; // Try translations first; find the youngest window with // a translation table. - for (hWnd = msg->hwnd; hWnd != (HWND) NULL; hWnd = ::GetParent(hWnd)) + for ( wnd = wndThis; wnd; wnd = wnd->GetParent() ) { - wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd); - if (wnd) - { - if (wnd->MSWTranslateMessage(Msg)) - return TRUE; - } + if ( wnd->MSWTranslateMessage(wxmsg) ) + return TRUE; } // Anyone for a non-translation message? Try youngest descendants first. - for (hWnd = msg->hwnd; hWnd != (HWND) NULL; hWnd = ::GetParent(hWnd)) + for ( wnd = wndThis; wnd; wnd = wnd->GetParent() ) { - wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd); - if (wnd) - { - if (wnd->MSWProcessMessage(Msg)) - return TRUE; - } + if ( wnd->MSWProcessMessage(wxmsg) ) + return TRUE; } + return FALSE; } @@ -996,14 +1031,14 @@ void wxApp::OnIdle(wxIdleEvent& event) bool wxApp::SendIdleEvents() { bool needMore = FALSE; - wxNode* node = wxTopLevelWindows.First(); + + wxWindowList::Node* node = wxTopLevelWindows.GetFirst(); while (node) { - wxWindow* win = (wxWindow*) node->Data(); + wxWindow* win = node->GetData(); if (SendIdleEvents(win)) needMore = TRUE; - - node = node->Next(); + node = node->GetNext(); } return needMore; @@ -1077,8 +1112,8 @@ wxWindow* wxApp::GetTopWindow() const { if (m_topWindow) return m_topWindow; - else if (wxTopLevelWindows.Number() > 0) - return (wxWindow*) wxTopLevelWindows.First()->Data(); + else if (wxTopLevelWindows.GetCount() > 0) + return wxTopLevelWindows.GetFirst()->GetData(); else return NULL; }