1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/evtloop.cpp
3 // Purpose: wxEventLoop implementation
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ===========================================================================
13 // ===========================================================================
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
22 #include "wx/evtloop.h"
28 #include "wx/thread.h"
30 #include "wx/private/socketevtdispatch.h"
31 #include "wx/dfb/private.h"
32 #include "wx/nonownedwnd.h"
34 #define TRACE_EVENTS _T("events")
36 // ===========================================================================
38 // ===========================================================================
40 //-----------------------------------------------------------------------------
41 // wxEventLoop initialization
42 //-----------------------------------------------------------------------------
44 wxIDirectFBEventBufferPtr
wxEventLoop::ms_buffer
;
46 wxEventLoop::wxEventLoop()
53 void wxEventLoop::InitBuffer()
55 ms_buffer
= wxIDirectFB::Get()->CreateEventBuffer();
59 void wxEventLoop::CleanUp()
65 wxIDirectFBEventBufferPtr
wxEventLoop::GetDirectFBEventBuffer()
73 //-----------------------------------------------------------------------------
74 // events dispatch and loop handling
75 //-----------------------------------------------------------------------------
77 bool wxEventLoop::Pending() const
79 wxCHECK_MSG( ms_buffer
, false, _T("invalid event buffer") );
81 return ms_buffer
->HasEvent();
84 bool wxEventLoop::Dispatch()
86 wxCHECK_MSG( ms_buffer
, false, _T("invalid event buffer") );
88 // NB: we don't block indefinitely waiting for an event, but instead
89 // time out after a brief period in order to make sure that
90 // OnNextIteration() will be called frequently enough
91 const int TIMEOUT
= 100;
93 // release the GUI mutex so that other threads have a chance to post
97 bool rv
= ms_buffer
->WaitForEventWithTimeout(0, TIMEOUT
);
99 // and acquire it back before calling any event handlers:
104 switch ( ms_buffer
->GetLastResult() )
109 ms_buffer
->GetEvent(e
);
115 // timed out, pretend we processed an event so that
116 // OnNextIteration is called
120 // don't terminate the loop due to errors (they were reported
121 // already by ms_buffer)
129 void wxEventLoop::WakeUp()
131 wxCHECK_RET( ms_buffer
, _T("invalid event buffer") );
136 void wxEventLoop::OnNextIteration()
139 wxTimer::NotifyTimers();
143 // handle any pending socket events:
144 wxSocketEventDispatcher::Get().RunLoop();
148 void wxEventLoop::Yield()
150 // process all pending events:
154 // handle timers, sockets etc.
159 //-----------------------------------------------------------------------------
160 // DirectFB -> wxWidgets events translation
161 //-----------------------------------------------------------------------------
163 void wxEventLoop::HandleDFBEvent(const wxDFBEvent
& event
)
165 switch ( event
.GetClass() )
169 wxDFBWindowEvent
winevent(((const DFBEvent
&)event
).window
);
170 wxNonOwnedWindow::HandleDFBWindowEvent(winevent
);
177 #if wxCHECK_DFB_VERSION(0,9,23)
181 wxLogTrace(TRACE_EVENTS
,
182 _T("ignoring event of unsupported class %i"),
183 (int)event
.GetClass());