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