]> git.saurik.com Git - wxWidgets.git/blob - src/dfb/evtloop.cpp
647e52ec7b0fe5b4565b620bab68bb82a5f91c03
[wxWidgets.git] / src / dfb / evtloop.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/evtloop.cpp
3 // Purpose: wxEventLoop implementation
4 // Author: Vaclav Slavik
5 // Created: 2006-08-16
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ===========================================================================
12 // declarations
13 // ===========================================================================
14
15 // ---------------------------------------------------------------------------
16 // headers
17 // ---------------------------------------------------------------------------
18
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #include "wx/evtloop.h"
23
24 #ifndef WX_PRECOMP
25 #include "wx/app.h"
26 #endif
27
28 #include "wx/timer.h"
29 #include "wx/dfb/private.h"
30
31 #define TRACE_EVENTS _T("events")
32
33 // ===========================================================================
34 // implementation
35 // ===========================================================================
36
37 //-----------------------------------------------------------------------------
38 // wxEventLoop initialization
39 //-----------------------------------------------------------------------------
40
41 IDirectFBEventBufferPtr wxEventLoop::ms_buffer;
42
43 wxEventLoop::wxEventLoop()
44 {
45 if ( !ms_buffer )
46 InitBuffer();
47 }
48
49 /* static */
50 void wxEventLoop::InitBuffer()
51 {
52 IDirectFBPtr dfb(wxTheApp->GetDirectFBInterface());
53 DFB_CALL( dfb->CreateEventBuffer(dfb, &ms_buffer) );
54 }
55
56 /* static */
57 IDirectFBEventBufferPtr wxEventLoop::GetDirectFBEventBuffer()
58 {
59 if ( !ms_buffer )
60 InitBuffer();
61
62 return ms_buffer;
63 }
64
65 //-----------------------------------------------------------------------------
66 // events dispatch and loop handling
67 //-----------------------------------------------------------------------------
68
69 bool wxEventLoop::Pending() const
70 {
71 wxCHECK_MSG( ms_buffer, false, _T("invalid event buffer") );
72
73 // returns DFB_OK if there is >=1 event, DFB_BUFFER_EMPTY otherwise
74 return ms_buffer->HasEvent(ms_buffer) == DFB_OK;
75 }
76
77 bool wxEventLoop::Dispatch()
78 {
79 wxCHECK_MSG( ms_buffer, false, _T("invalid event buffer") );
80
81 // NB: we don't block indefinitely waiting for an event, but instead
82 // time out after a brief period in order to make sure that
83 // OnNextIteration() will be called frequently enough
84 //
85 // FIXME: call NotifyTimers() from here (and loop) instead?
86 const int TIMEOUT = 100;
87
88 DFBResult ret = ms_buffer->WaitForEventWithTimeout(ms_buffer, 0, TIMEOUT);
89
90 switch ( ret )
91 {
92 case DFB_OK:
93 {
94 wxDFBEvent e;
95 ms_buffer->GetEvent(ms_buffer, &e);
96 HandleDFBEvent(e);
97 break;
98 }
99
100 case DFB_TIMEOUT:
101 // timed out, pretend we processed an event so that OnNextIteration
102 // is called
103 break;
104
105 default:
106 // report any errors, but don't terminate the loop due to them
107 wxDfbCheckReturn(ret);
108 break;
109 }
110
111 return true;
112 }
113
114 void wxEventLoop::WakeUp()
115 {
116 wxCHECK_RET( ms_buffer, _T("invalid event buffer") );
117
118 DFB_CALL( ms_buffer->WakeUp(ms_buffer) );
119 }
120
121 void wxEventLoop::OnNextIteration()
122 {
123 #if wxUSE_TIMER
124 // see the comment in Dispatch
125 wxTimer::NotifyTimers();
126 #endif
127 }
128
129 #warning "FIXME: cleanup wxEventLoop::ms_buffer before exiting"
130
131
132 //-----------------------------------------------------------------------------
133 // DirectFB -> wxWidgets events translation
134 //-----------------------------------------------------------------------------
135
136 void wxEventLoop::HandleDFBEvent(const wxDFBEvent& event)
137 {
138 switch ( event.GetClass() )
139 {
140 case DFEC_WINDOW:
141 {
142 wxDFBWindowEvent winevent(((const DFBEvent&)event).window);
143 wxTopLevelWindowDFB::HandleDFBWindowEvent(winevent);
144 break;
145 }
146
147 case DFEC_NONE:
148 case DFEC_INPUT:
149 case DFEC_USER:
150 #if wxCHECK_DFB_VERSION(0,9,23)
151 case DFEC_UNIVERSAL:
152 #endif
153 {
154 wxLogTrace(TRACE_EVENTS,
155 _T("ignoring event of unsupported class %i"),
156 (int)event.GetClass());
157 }
158 }
159 }