From 2ddff00c923d454f651aba32c8fe3654fd303e43 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 22 May 2007 02:30:01 +0000 Subject: [PATCH] don't define wxEventLoop class differently in GUI and base, this breaks the ODR and hence results in many problems in practice; instead use wxEventLoopBase whenever possible and #define wxEventLoop differently in console applications git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46158 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/app.h | 7 +++---- include/wx/apptrait.h | 4 ++-- include/wx/evtloop.h | 29 ++++++++++++++++------------- include/wx/msdos/apptrait.h | 4 ++-- include/wx/msw/apptrait.h | 4 ++-- include/wx/unix/apptrait.h | 4 ++-- src/cocoa/utils.mm | 7 ++----- src/common/appbase.cpp | 10 +++++----- src/common/evtloopcmn.cpp | 2 +- src/dfb/app.cpp | 5 +++-- src/dfb/utils.cpp | 5 +++-- src/gtk/utilsgtk.cpp | 2 +- src/gtk1/utilsgtk.cpp | 2 +- src/mac/carbon/utils.cpp | 2 +- src/mgl/app.cpp | 7 ++++--- src/mgl/utils.cpp | 2 +- src/motif/utils.cpp | 2 +- src/msw/app.cpp | 4 ++-- src/msw/basemsw.cpp | 2 +- src/os2/utilsgui.cpp | 2 +- src/palmos/app.cpp | 2 +- src/unix/baseunix.cpp | 2 +- src/x11/app.cpp | 2 +- src/x11/utils.cpp | 2 +- 24 files changed, 58 insertions(+), 56 deletions(-) diff --git a/include/wx/app.h b/include/wx/app.h index f744a92ecb..5dfe9a037d 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -25,12 +25,11 @@ class WXDLLIMPEXP_BASE wxAppConsole; class WXDLLIMPEXP_BASE wxAppTraits; class WXDLLIMPEXP_BASE wxCmdLineParser; -class WXDLLIMPEXP_BASE wxEventLoop; +class WXDLLIMPEXP_BASE wxEventLoopBase; class WXDLLIMPEXP_BASE wxLog; class WXDLLIMPEXP_BASE wxMessageOutput; #if wxUSE_GUI - class WXDLLEXPORT wxEventLoop; struct WXDLLIMPEXP_CORE wxVideoMode; #endif @@ -327,7 +326,7 @@ protected: // create main loop from AppTraits or return NULL if // there is no main loop implementation - wxEventLoop *CreateMainLoop(); + wxEventLoopBase *CreateMainLoop(); // application info (must be set from the user code) wxString m_vendorName, // vendor name (ACME Inc) @@ -340,7 +339,7 @@ protected: // the main event loop of the application (may be NULL if the loop hasn't // been started yet or has already terminated) - wxEventLoop *m_mainLoop; + wxEventLoopBase *m_mainLoop; // the application object is a singleton anyhow, there is no sense in // copying it diff --git a/include/wx/apptrait.h b/include/wx/apptrait.h index 6d6084e3a1..d9147fdd24 100644 --- a/include/wx/apptrait.h +++ b/include/wx/apptrait.h @@ -18,7 +18,7 @@ class WXDLLIMPEXP_BASE wxArrayString; class WXDLLIMPEXP_BASE wxObject; class WXDLLEXPORT wxAppTraits; -class WXDLLIMPEXP_BASE wxEventLoop; +class WXDLLIMPEXP_BASE wxEventLoopBase; #if wxUSE_FONTMAP class WXDLLEXPORT wxFontMapper; #endif // wxUSE_FONTMAP @@ -122,7 +122,7 @@ public: #endif // create a new, port specific, instance of the event loop used by wxApp - virtual wxEventLoop *CreateEventLoop() = 0; + virtual wxEventLoopBase *CreateEventLoop() = 0; #if wxUSE_TIMER // return platform and toolkit dependent wxTimer implementation diff --git a/include/wx/evtloop.h b/include/wx/evtloop.h index ff0ee61d3f..254f8fe078 100644 --- a/include/wx/evtloop.h +++ b/include/wx/evtloop.h @@ -14,8 +14,6 @@ #include "wx/utils.h" -class WXDLLEXPORT wxEventLoop; - // ---------------------------------------------------------------------------- // wxEventLoopBase: interface for wxEventLoop // ---------------------------------------------------------------------------- @@ -46,10 +44,10 @@ public: virtual bool Dispatch() = 0; // return currently active (running) event loop, may be NULL - static wxEventLoop *GetActive() { return ms_activeLoop; } + static wxEventLoopBase *GetActive() { return ms_activeLoop; } // set currently active (running) event loop - static void SetActive(wxEventLoop* loop) { ms_activeLoop = loop; } + static void SetActive(wxEventLoopBase* loop) { ms_activeLoop = loop; } // is this event loop running now? // @@ -69,7 +67,7 @@ protected: // the pointer to currently active loop - static wxEventLoop *ms_activeLoop; + static wxEventLoopBase *ms_activeLoop; DECLARE_NO_COPY_CLASS(wxEventLoopBase) }; @@ -151,13 +149,18 @@ protected: #include "wx/unix/evtloop.h" #endif -// cannot use typedef because wxEventLoop is forward-declared in many places +// we use a class rather than a typedef because wxEventLoop is forward-declared +// in many places #if wxUSE_GUI -class wxEventLoop : public wxGUIEventLoop { }; -#elif defined(__WXMSW__) || defined(__UNIX__) -class wxEventLoop : public wxConsoleEventLoop { }; -#else // we still must define it somehow for the code below... -class wxEventLoop : public wxEventLoopBase { }; + class wxEventLoop : public wxGUIEventLoop { }; +#else // !GUI + // we can't define wxEventLoop differently in GUI and base libraries so use + // a #define to still allow writing wxEventLoop in the user code + #if defined(__WXMSW__) || defined(__UNIX__) + #define wxEventLoop wxConsoleEventLoop + #else // we still must define it somehow for the code below... + #define wxEventLoop wxEventLoopBase + #endif #endif inline bool wxEventLoopBase::IsRunning() const { return GetActive() == this; } @@ -207,7 +210,7 @@ public: wxEventLoopActivator(wxEventLoopBase *evtLoop) { m_evtLoopOld = wxEventLoopBase::GetActive(); - wxEventLoopBase::SetActive(wx_static_cast(wxEventLoop *, evtLoop)); + wxEventLoopBase::SetActive(evtLoop); } ~wxEventLoopActivator() @@ -217,7 +220,7 @@ public: } private: - wxEventLoop *m_evtLoopOld; + wxEventLoopBase *m_evtLoopOld; }; #endif // _WX_EVTLOOP_H_ diff --git a/include/wx/msdos/apptrait.h b/include/wx/msdos/apptrait.h index 6790aaec3f..6b377ff7a1 100644 --- a/include/wx/msdos/apptrait.h +++ b/include/wx/msdos/apptrait.h @@ -12,7 +12,7 @@ class wxConsoleAppTraits : public wxConsoleAppTraitsBase { public: - virtual wxEventLoop *CreateEventLoop() { return NULL; } + virtual wxEventLoopBase *CreateEventLoop() { return NULL; } #if wxUSE_TIMER virtual wxTimerImpl *CreateTimerImpl(wxTimer *) { return NULL; } #endif // wxUSE_TIMER @@ -23,7 +23,7 @@ public: class wxGUIAppTraits : public wxGUIAppTraitsBase { public: - virtual wxEventLoop *CreateEventLoop(); + virtual wxEventLoopBase *CreateEventLoop(); virtual wxPortId GetToolkitVersion(int *majVer, int *minVer) const; #if wxUSE_TIMER diff --git a/include/wx/msw/apptrait.h b/include/wx/msw/apptrait.h index 276d4ec0b5..40cf996c8d 100644 --- a/include/wx/msw/apptrait.h +++ b/include/wx/msw/apptrait.h @@ -19,7 +19,7 @@ class WXDLLIMPEXP_BASE wxConsoleAppTraits : public wxConsoleAppTraitsBase { public: - virtual wxEventLoop *CreateEventLoop(); + virtual wxEventLoopBase *CreateEventLoop(); virtual void *BeforeChildWaitLoop(); virtual void AlwaysYield(); virtual void AfterChildWaitLoop(void *data); @@ -35,7 +35,7 @@ public: class WXDLLIMPEXP_CORE wxGUIAppTraits : public wxGUIAppTraitsBase { public: - virtual wxEventLoop *CreateEventLoop(); + virtual wxEventLoopBase *CreateEventLoop(); virtual void *BeforeChildWaitLoop(); virtual void AlwaysYield(); virtual void AfterChildWaitLoop(void *data); diff --git a/include/wx/unix/apptrait.h b/include/wx/unix/apptrait.h index aa8a3b0f83..b8de87f393 100644 --- a/include/wx/unix/apptrait.h +++ b/include/wx/unix/apptrait.h @@ -19,7 +19,7 @@ class WXDLLEXPORT wxConsoleAppTraits : public wxConsoleAppTraitsBase { public: - virtual wxEventLoop *CreateEventLoop(); + virtual wxEventLoopBase *CreateEventLoop(); virtual bool CreateEndProcessPipe(wxExecuteData& execData); virtual bool IsWriteFDOfEndProcessPipe(wxExecuteData& execData, int fd); virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData); @@ -34,7 +34,7 @@ public: class WXDLLEXPORT wxGUIAppTraits : public wxGUIAppTraitsBase { public: - virtual wxEventLoop *CreateEventLoop(); + virtual wxEventLoopBase *CreateEventLoop(); virtual bool CreateEndProcessPipe(wxExecuteData& execData); virtual bool IsWriteFDOfEndProcessPipe(wxExecuteData& execData, int fd); virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData); diff --git a/src/cocoa/utils.mm b/src/cocoa/utils.mm index c6958cfa43..462b68de61 100644 --- a/src/cocoa/utils.mm +++ b/src/cocoa/utils.mm @@ -73,12 +73,9 @@ wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer* timer) return new wxCocoaTimerImpl(timer); } -wxEventLoop* wxGUIAppTraits::CreateEventLoop() +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() { - // MAJOR HACK: wxEventLoop is implemented in both core and base libraries. - // Fortunately, it has an empty implementation so an instance of the - // wxGUIEventLoop parent class will be fine until this issue is fixed. - return static_cast(new wxGUIEventLoop); + return new wxGUIEventLoop; } wxWindow* wxFindWindowAtPoint(const wxPoint& pt) diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index aeeb572a1b..9fdb525f77 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -119,7 +119,7 @@ wxAppInitializerFunction wxAppConsole::ms_appInitFn = NULL; // ---------------------------------------------------------------------------- // this defines wxEventLoopPtr -wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoop) +wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoopBase) // ============================================================================ // wxAppConsole implementation @@ -185,7 +185,7 @@ bool wxAppConsole::Initialize(int& argcOrig, wxChar **argvOrig) return true; } -wxEventLoop *wxAppConsole::CreateMainLoop() +wxEventLoopBase *wxAppConsole::CreateMainLoop() { return GetTraits()->CreateEventLoop(); } @@ -290,7 +290,7 @@ wxAppTraits *wxAppConsole::GetTraits() int wxAppConsole::MainLoop() { - wxEventLoopTiedPtr mainLoop(&m_mainLoop, CreateMainLoop()); + wxEventLoopBaseTiedPtr mainLoop(&m_mainLoop, CreateMainLoop()); return m_mainLoop ? m_mainLoop->Run() : -1; } @@ -310,7 +310,7 @@ bool wxAppConsole::Pending() // use the currently active message loop here, not m_mainLoop, because if // we're showing a modal dialog (with its own event loop) currently the // main event loop is not running anyhow - wxEventLoop * const loop = wxEventLoopBase::GetActive(); + wxEventLoopBase * const loop = wxEventLoopBase::GetActive(); return loop && loop->Pending(); } @@ -318,7 +318,7 @@ bool wxAppConsole::Pending() bool wxAppConsole::Dispatch() { // see comment in Pending() - wxEventLoop * const loop = wxEventLoopBase::GetActive(); + wxEventLoopBase * const loop = wxEventLoopBase::GetActive(); return loop && loop->Dispatch(); } diff --git a/src/common/evtloopcmn.cpp b/src/common/evtloopcmn.cpp index ccbbb71126..e90bf2f2eb 100644 --- a/src/common/evtloopcmn.cpp +++ b/src/common/evtloopcmn.cpp @@ -34,7 +34,7 @@ // globals // ---------------------------------------------------------------------------- -wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL; +wxEventLoopBase *wxEventLoopBase::ms_activeLoop = NULL; // wxEventLoopManual is unused in the other ports #if defined(__WXMSW__) || defined(__WXMAC__) || defined(__WXDFB__) || (defined(__UNIX__) && !wxUSE_GUI) diff --git a/src/dfb/app.cpp b/src/dfb/app.cpp index c78010f081..bfde03508e 100644 --- a/src/dfb/app.cpp +++ b/src/dfb/app.cpp @@ -156,7 +156,7 @@ void wxApp::WakeUpIdle() wxMutexGuiEnter(); #endif - wxEventLoop * const loop = wxEventLoop::GetActive(); + wxEventLoopBase * const loop = wxEventLoop::GetActive(); if ( loop ) loop->WakeUp(); @@ -190,7 +190,8 @@ bool wxApp::Yield(bool onlyIfNeeded) wxLog::Suspend(); - wxEventLoop * const loop = wxEventLoop::GetActive(); + wxEventLoop * const + loop = wx_static_cast(wxEventLoop *, wxEventLoop::GetActive()); if ( loop ) loop->Yield(); diff --git a/src/dfb/utils.cpp b/src/dfb/utils.cpp index 78240916a9..385616fb95 100644 --- a/src/dfb/utils.cpp +++ b/src/dfb/utils.cpp @@ -40,10 +40,11 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const } -wxEventLoop* wxGUIAppTraits::CreateEventLoop() +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() { return new wxEventLoop; -}; +} + // ---------------------------------------------------------------------------- // display characteristics // ---------------------------------------------------------------------------- diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index 7f0a931e38..445a5f3bb7 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -364,7 +364,7 @@ static wxString GetSM() // wxGUIAppTraits //----------------------------------------------------------------------------- -wxEventLoop *wxGUIAppTraits::CreateEventLoop() +wxEventLoopBase *wxGUIAppTraits::CreateEventLoop() { return new wxEventLoop(); } diff --git a/src/gtk1/utilsgtk.cpp b/src/gtk1/utilsgtk.cpp index 8e8b604bda..7cd7c37ef9 100644 --- a/src/gtk1/utilsgtk.cpp +++ b/src/gtk1/utilsgtk.cpp @@ -203,7 +203,7 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const return wxPORT_GTK; } -wxEventLoop* wxGUIAppTraits::CreateEventLoop() +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() { return new wxEventLoop; } diff --git a/src/mac/carbon/utils.cpp b/src/mac/carbon/utils.cpp index 696fe6e94e..edf0c4a45c 100644 --- a/src/mac/carbon/utils.cpp +++ b/src/mac/carbon/utils.cpp @@ -381,7 +381,7 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const return wxPORT_MAC; } -wxEventLoop* wxGUIAppTraits::CreateEventLoop() +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() { return new wxEventLoop; } diff --git a/src/mgl/app.cpp b/src/mgl/app.cpp index 1a614e3f81..f94600c41e 100644 --- a/src/mgl/app.cpp +++ b/src/mgl/app.cpp @@ -74,10 +74,11 @@ bool wxApp::Yield(bool onlyIfNeeded) wxLog::Suspend(); - if ( wxEventLoop::GetActive() ) + wxEventLoopBase * const eventLoop = wxEventLoop::GetActive(); + if ( eventLoop ) { - while (wxEventLoop::GetActive()->Pending()) - wxEventLoop::GetActive()->Dispatch(); + while (eventLoop->Pending()) + eventLoop->Dispatch(); } /* it's necessary to call ProcessIdle() to update the frames sizes which diff --git a/src/mgl/utils.cpp b/src/mgl/utils.cpp index 4a3045cef1..114277e970 100644 --- a/src/mgl/utils.cpp +++ b/src/mgl/utils.cpp @@ -123,7 +123,7 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const return wxPORT_MGL; } -wxEventLoop* wxGUIAppTraits::CreateEventLoop() +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() { return new wxEventLoop; } diff --git a/src/motif/utils.cpp b/src/motif/utils.cpp index e6309b2e51..b56aa96fe7 100644 --- a/src/motif/utils.cpp +++ b/src/motif/utils.cpp @@ -136,7 +136,7 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const return wxPORT_MOTIF; } -wxEventLoop* wxGUIAppTraits::CreateEventLoop() +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() { return new wxEventLoop; } diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 549a8d77da..28e359be38 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -213,7 +213,7 @@ bool wxGUIAppTraits::DoMessageFromThreadWait() { // we should return false only if the app should exit, i.e. only if // Dispatch() determines that the main event loop should terminate - wxEventLoop *evtLoop = wxEventLoop::GetActive(); + wxEventLoopBase * const evtLoop = wxEventLoop::GetActive(); if ( !evtLoop || !evtLoop->Pending() ) { // no events means no quit event @@ -271,7 +271,7 @@ wxTimerImpl *wxGUIAppTraits::CreateTimerImpl(wxTimer *timer) return new wxMSWTimerImpl(timer); } -wxEventLoop* wxGUIAppTraits::CreateEventLoop() +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() { return new wxEventLoop; } diff --git a/src/msw/basemsw.cpp b/src/msw/basemsw.cpp index 1989549dc1..754dbc7ea3 100644 --- a/src/msw/basemsw.cpp +++ b/src/msw/basemsw.cpp @@ -87,7 +87,7 @@ wxTimerImpl *wxConsoleAppTraits::CreateTimerImpl(wxTimer *timer) return new wxMSWTimerImpl(timer); } -wxEventLoop *wxConsoleAppTraits::CreateEventLoop() +wxEventLoopBase *wxConsoleAppTraits::CreateEventLoop() { return new wxEventLoop(); } diff --git a/src/os2/utilsgui.cpp b/src/os2/utilsgui.cpp index 75ab669b22..79b584d217 100644 --- a/src/os2/utilsgui.cpp +++ b/src/os2/utilsgui.cpp @@ -268,7 +268,7 @@ wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer) return new wxOS2TimerImpl(timer); } -wxEventLoop* wxGUIAppTraits::CreateEventLoop() +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() { return new wxEventLoop; } diff --git a/src/palmos/app.cpp b/src/palmos/app.cpp index 1344607c9f..7efb190ac6 100644 --- a/src/palmos/app.cpp +++ b/src/palmos/app.cpp @@ -125,7 +125,7 @@ wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer) return new wxPalmOSTimerImpl(timer); }; -wxEventLoop* wxGUIAppTraits::CreateEventLoop() +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() { return new wxEventLoop; } diff --git a/src/unix/baseunix.cpp b/src/unix/baseunix.cpp index 9dd19ba020..16aa2c8c58 100644 --- a/src/unix/baseunix.cpp +++ b/src/unix/baseunix.cpp @@ -90,7 +90,7 @@ wxTimerImpl *wxConsoleAppTraits::CreateTimerImpl(wxTimer *timer) return new wxUnixTimerImpl(timer); } -wxEventLoop *wxConsoleAppTraits::CreateEventLoop() +wxEventLoopBase *wxConsoleAppTraits::CreateEventLoop() { return new wxEventLoop(); } diff --git a/src/x11/app.cpp b/src/x11/app.cpp index ab6b3fc909..9677cf46fc 100644 --- a/src/x11/app.cpp +++ b/src/x11/app.cpp @@ -796,7 +796,7 @@ bool wxApp::Yield(bool onlyIfNeeded) // Make sure we have an event loop object, // or Pending/Dispatch will fail - wxEventLoop* eventLoop = wxEventLoop::GetActive(); + wxEventLoopBase * const eventLoop = wxEventLoop::GetActive(); wxEventLoop* newEventLoop = NULL; if (!eventLoop) { diff --git a/src/x11/utils.cpp b/src/x11/utils.cpp index 7448c3ab24..2f06547b2d 100644 --- a/src/x11/utils.cpp +++ b/src/x11/utils.cpp @@ -171,7 +171,7 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const return wxPORT_X11; } -wxEventLoop* wxGUIAppTraits::CreateEventLoop() +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() { return new wxEventLoop; } -- 2.45.2