]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/evtloop.cpp
Wrap module in #if wxUSE_GRAPHICS_CONTEXT
[wxWidgets.git] / src / dfb / evtloop.cpp
CommitLineData
b3c86150
VS
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
52c8d32a 41wxIDirectFBEventBufferPtr wxEventLoop::ms_buffer;
b3c86150
VS
42
43wxEventLoop::wxEventLoop()
44{
45 if ( !ms_buffer )
46 InitBuffer();
47}
48
49/* static */
50void wxEventLoop::InitBuffer()
51{
52c8d32a 52 ms_buffer = wxIDirectFB::Get()->CreateEventBuffer();
b3c86150
VS
53}
54
e48a3055
VS
55/* static */
56void wxEventLoop::CleanUp()
57{
58 ms_buffer.Reset();
59}
60
b3c86150 61/* static */
52c8d32a 62wxIDirectFBEventBufferPtr wxEventLoop::GetDirectFBEventBuffer()
b3c86150
VS
63{
64 if ( !ms_buffer )
65 InitBuffer();
66
67 return ms_buffer;
68}
69
70//-----------------------------------------------------------------------------
71// events dispatch and loop handling
72//-----------------------------------------------------------------------------
73
74bool wxEventLoop::Pending() const
75{
76 wxCHECK_MSG( ms_buffer, false, _T("invalid event buffer") );
77
52c8d32a 78 return ms_buffer->HasEvent();
b3c86150
VS
79}
80
81bool wxEventLoop::Dispatch()
82{
83 wxCHECK_MSG( ms_buffer, false, _T("invalid event buffer") );
84
85 // NB: we don't block indefinitely waiting for an event, but instead
86 // time out after a brief period in order to make sure that
87 // OnNextIteration() will be called frequently enough
88 //
89 // FIXME: call NotifyTimers() from here (and loop) instead?
90 const int TIMEOUT = 100;
91
52c8d32a 92 if ( ms_buffer->WaitForEventWithTimeout(0, TIMEOUT) )
b3c86150 93 {
52c8d32a 94 switch ( ms_buffer->GetLastResult() )
b3c86150 95 {
52c8d32a
VS
96 case DFB_OK:
97 {
98 wxDFBEvent e;
99 ms_buffer->GetEvent(e);
100 HandleDFBEvent(e);
101 break;
102 }
103
104 case DFB_TIMEOUT:
105 // timed out, pretend we processed an event so that
106 // OnNextIteration is called
107 break;
108
109 default:
110 // don't terminate the loop due to errors (they were reported
111 // already by ms_buffer)
112 break;
b3c86150 113 }
b3c86150
VS
114 }
115
116 return true;
117}
118
119void wxEventLoop::WakeUp()
120{
121 wxCHECK_RET( ms_buffer, _T("invalid event buffer") );
122
52c8d32a 123 ms_buffer->WakeUp();
b3c86150
VS
124}
125
126void wxEventLoop::OnNextIteration()
127{
128#if wxUSE_TIMER
129 // see the comment in Dispatch
130 wxTimer::NotifyTimers();
131#endif
132}
133
b3c86150
VS
134
135//-----------------------------------------------------------------------------
136// DirectFB -> wxWidgets events translation
137//-----------------------------------------------------------------------------
138
139void wxEventLoop::HandleDFBEvent(const wxDFBEvent& event)
140{
141 switch ( event.GetClass() )
142 {
143 case DFEC_WINDOW:
144 {
145 wxDFBWindowEvent winevent(((const DFBEvent&)event).window);
146 wxTopLevelWindowDFB::HandleDFBWindowEvent(winevent);
147 break;
148 }
149
150 case DFEC_NONE:
151 case DFEC_INPUT:
152 case DFEC_USER:
dc4451c2 153#if wxCHECK_DFB_VERSION(0,9,23)
b3c86150 154 case DFEC_UNIVERSAL:
dc4451c2 155#endif
b3c86150
VS
156 {
157 wxLogTrace(TRACE_EVENTS,
158 _T("ignoring event of unsupported class %i"),
159 (int)event.GetClass());
160 }
161 }
162}