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