X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/52c8d32a71bb7553dd89324fa6d56faac95eb5d0..6f3f9b50aa275243ade3541ecccb95de22cf57a9:/src/dfb/evtloop.cpp diff --git a/src/dfb/evtloop.cpp b/src/dfb/evtloop.cpp index 78bca48df8..9581c327f1 100644 --- a/src/dfb/evtloop.cpp +++ b/src/dfb/evtloop.cpp @@ -25,10 +25,13 @@ #include "wx/app.h" #endif -#include "wx/timer.h" +#include "wx/thread.h" +#include "wx/generic/private/timer.h" +#include "wx/private/selectdispatcher.h" #include "wx/dfb/private.h" +#include "wx/nonownedwnd.h" -#define TRACE_EVENTS _T("events") +#define TRACE_EVENTS "events" // =========================================================================== // implementation @@ -38,22 +41,28 @@ // wxEventLoop initialization //----------------------------------------------------------------------------- -wxIDirectFBEventBufferPtr wxEventLoop::ms_buffer; +wxIDirectFBEventBufferPtr wxGUIEventLoop::ms_buffer; -wxEventLoop::wxEventLoop() +wxGUIEventLoop::wxGUIEventLoop() { if ( !ms_buffer ) InitBuffer(); } /* static */ -void wxEventLoop::InitBuffer() +void wxGUIEventLoop::InitBuffer() { ms_buffer = wxIDirectFB::Get()->CreateEventBuffer(); } /* static */ -wxIDirectFBEventBufferPtr wxEventLoop::GetDirectFBEventBuffer() +void wxGUIEventLoop::CleanUp() +{ + ms_buffer.Reset(); +} + +/* static */ +wxIDirectFBEventBufferPtr wxGUIEventLoop::GetDirectFBEventBuffer() { if ( !ms_buffer ) InitBuffer(); @@ -65,25 +74,32 @@ wxIDirectFBEventBufferPtr wxEventLoop::GetDirectFBEventBuffer() // events dispatch and loop handling //----------------------------------------------------------------------------- -bool wxEventLoop::Pending() const +bool wxGUIEventLoop::Pending() const { - wxCHECK_MSG( ms_buffer, false, _T("invalid event buffer") ); + wxCHECK_MSG( ms_buffer, false, "invalid event buffer" ); return ms_buffer->HasEvent(); } -bool wxEventLoop::Dispatch() +bool wxGUIEventLoop::Dispatch() { - wxCHECK_MSG( ms_buffer, false, _T("invalid event buffer") ); + wxCHECK_MSG( ms_buffer, false, "invalid event buffer" ); // NB: we don't block indefinitely waiting for an event, but instead // time out after a brief period in order to make sure that // OnNextIteration() will be called frequently enough - // - // FIXME: call NotifyTimers() from here (and loop) instead? const int TIMEOUT = 100; - if ( ms_buffer->WaitForEventWithTimeout(0, TIMEOUT) ) + // release the GUI mutex so that other threads have a chance to post + // events: + wxMutexGuiLeave(); + + bool rv = ms_buffer->WaitForEventWithTimeout(0, TIMEOUT); + + // and acquire it back before calling any event handlers: + wxMutexGuiEnter(); + + if ( rv ) { switch ( ms_buffer->GetLastResult() ) { @@ -110,36 +126,48 @@ bool wxEventLoop::Dispatch() return true; } -void wxEventLoop::WakeUp() +void wxGUIEventLoop::WakeUp() { - wxCHECK_RET( ms_buffer, _T("invalid event buffer") ); + wxCHECK_RET( ms_buffer, "invalid event buffer" ); ms_buffer->WakeUp(); } -void wxEventLoop::OnNextIteration() +void wxGUIEventLoop::OnNextIteration() { #if wxUSE_TIMER - // see the comment in Dispatch - wxTimer::NotifyTimers(); + wxGenericTimerImpl::NotifyTimers(); +#endif + +#if wxUSE_SOCKETS + // handle any pending socket events: + wxSelectDispatcher::DispatchPending(); #endif } -#warning "FIXME: cleanup wxEventLoop::ms_buffer before exiting" +void wxGUIEventLoop::Yield() +{ + // process all pending events: + while ( Pending() ) + Dispatch(); + + // handle timers, sockets etc. + OnNextIteration(); +} //----------------------------------------------------------------------------- // DirectFB -> wxWidgets events translation //----------------------------------------------------------------------------- -void wxEventLoop::HandleDFBEvent(const wxDFBEvent& event) +void wxGUIEventLoop::HandleDFBEvent(const wxDFBEvent& event) { switch ( event.GetClass() ) { case DFEC_WINDOW: { wxDFBWindowEvent winevent(((const DFBEvent&)event).window); - wxTopLevelWindowDFB::HandleDFBWindowEvent(winevent); + wxNonOwnedWindow::HandleDFBWindowEvent(winevent); break; } @@ -151,7 +179,7 @@ void wxEventLoop::HandleDFBEvent(const wxDFBEvent& event) #endif { wxLogTrace(TRACE_EVENTS, - _T("ignoring event of unsupported class %i"), + "ignoring event of unsupported class %i", (int)event.GetClass()); } }