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
This commit is contained in:
Vadim Zeitlin
2007-05-22 02:30:01 +00:00
parent 30c15c1d73
commit 2ddff00c92
24 changed files with 58 additions and 56 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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_

View File

@@ -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

View File

@@ -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);

View File

@@ -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);

View File

@@ -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<wxEventLoop*>(new wxGUIEventLoop);
return new wxGUIEventLoop;
}
wxWindow* wxFindWindowAtPoint(const wxPoint& pt)

View File

@@ -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();
}

View File

@@ -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)

View File

@@ -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();

View File

@@ -40,10 +40,11 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
}
wxEventLoop* wxGUIAppTraits::CreateEventLoop()
wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
{
return new wxEventLoop;
};
}
// ----------------------------------------------------------------------------
// display characteristics
// ----------------------------------------------------------------------------

View File

@@ -364,7 +364,7 @@ static wxString GetSM()
// wxGUIAppTraits
//-----------------------------------------------------------------------------
wxEventLoop *wxGUIAppTraits::CreateEventLoop()
wxEventLoopBase *wxGUIAppTraits::CreateEventLoop()
{
return new wxEventLoop();
}

View File

@@ -203,7 +203,7 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
return wxPORT_GTK;
}
wxEventLoop* wxGUIAppTraits::CreateEventLoop()
wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
{
return new wxEventLoop;
}

View File

@@ -381,7 +381,7 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
return wxPORT_MAC;
}
wxEventLoop* wxGUIAppTraits::CreateEventLoop()
wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
{
return new wxEventLoop;
}

View File

@@ -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

View File

@@ -123,7 +123,7 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
return wxPORT_MGL;
}
wxEventLoop* wxGUIAppTraits::CreateEventLoop()
wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
{
return new wxEventLoop;
}

View File

@@ -136,7 +136,7 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
return wxPORT_MOTIF;
}
wxEventLoop* wxGUIAppTraits::CreateEventLoop()
wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
{
return new wxEventLoop;
}

View File

@@ -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;
}

View File

@@ -87,7 +87,7 @@ wxTimerImpl *wxConsoleAppTraits::CreateTimerImpl(wxTimer *timer)
return new wxMSWTimerImpl(timer);
}
wxEventLoop *wxConsoleAppTraits::CreateEventLoop()
wxEventLoopBase *wxConsoleAppTraits::CreateEventLoop()
{
return new wxEventLoop();
}

View File

@@ -268,7 +268,7 @@ wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
return new wxOS2TimerImpl(timer);
}
wxEventLoop* wxGUIAppTraits::CreateEventLoop()
wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
{
return new wxEventLoop;
}

View File

@@ -125,7 +125,7 @@ wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
return new wxPalmOSTimerImpl(timer);
};
wxEventLoop* wxGUIAppTraits::CreateEventLoop()
wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
{
return new wxEventLoop;
}

View File

@@ -90,7 +90,7 @@ wxTimerImpl *wxConsoleAppTraits::CreateTimerImpl(wxTimer *timer)
return new wxUnixTimerImpl(timer);
}
wxEventLoop *wxConsoleAppTraits::CreateEventLoop()
wxEventLoopBase *wxConsoleAppTraits::CreateEventLoop()
{
return new wxEventLoop();
}

View File

@@ -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)
{

View File

@@ -171,7 +171,7 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
return wxPORT_X11;
}
wxEventLoop* wxGUIAppTraits::CreateEventLoop()
wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
{
return new wxEventLoop;
}