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"
29 #include "wx/generic/private/timer.h"
30 #include "wx/private/fdiodispatcher.h"
31 #include "wx/dfb/private.h"
32 #include "wx/nonownedwnd.h"
34 #define TRACE_EVENTS "events"
36 // ===========================================================================
38 // ===========================================================================
40 //-----------------------------------------------------------------------------
41 // wxEventLoop initialization
42 //-----------------------------------------------------------------------------
44 wxIDirectFBEventBufferPtr
wxGUIEventLoop::ms_buffer
;
46 wxGUIEventLoop::wxGUIEventLoop()
53 void wxGUIEventLoop::InitBuffer()
55 ms_buffer
= wxIDirectFB::Get()->CreateEventBuffer();
59 void wxGUIEventLoop::CleanUp()
65 wxIDirectFBEventBufferPtr
wxGUIEventLoop::GetDirectFBEventBuffer()
73 //-----------------------------------------------------------------------------
74 // events dispatch and loop handling
75 //-----------------------------------------------------------------------------
77 bool wxGUIEventLoop::Pending() const
79 wxCHECK_MSG( ms_buffer
, false, "invalid event buffer" );
81 return ms_buffer
->HasEvent();
84 bool wxGUIEventLoop::Dispatch()
86 wxCHECK_MSG( ms_buffer
, false, "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 wxGUIEventLoop::WakeUp()
131 wxCHECK_RET( ms_buffer
, "invalid event buffer" );
136 void wxGUIEventLoop::OnNextIteration()
139 wxGenericTimerImpl::NotifyTimers();
143 // handle any pending socket events:
144 wxFDIODispatcher::DispatchPending();
148 void wxGUIEventLoop::Yield()
150 // process all pending events:
154 // handle timers, sockets etc.
159 //-----------------------------------------------------------------------------
160 // DirectFB -> wxWidgets events translation
161 //-----------------------------------------------------------------------------
163 void wxGUIEventLoop::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 "ignoring event of unsupported class %i",
183 (int)event
.GetClass());