]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/evtloop.cpp
restore SetSelection(-1, -1) behaviour which was broken during wxTextEntry refactoring
[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
f7a50432 28#include "wx/thread.h"
c2ca375c 29#include "wx/generic/private/timer.h"
4eba3923 30#include "wx/private/fdiodispatcher.h"
b3c86150 31#include "wx/dfb/private.h"
0edbcd60 32#include "wx/nonownedwnd.h"
b3c86150 33
a5001e93 34#define TRACE_EVENTS "events"
b3c86150
VS
35
36// ===========================================================================
37// implementation
38// ===========================================================================
39
40//-----------------------------------------------------------------------------
41// wxEventLoop initialization
42//-----------------------------------------------------------------------------
43
b46b1d59 44wxIDirectFBEventBufferPtr wxGUIEventLoop::ms_buffer;
b3c86150 45
b46b1d59 46wxGUIEventLoop::wxGUIEventLoop()
b3c86150
VS
47{
48 if ( !ms_buffer )
49 InitBuffer();
50}
51
52/* static */
b46b1d59 53void wxGUIEventLoop::InitBuffer()
b3c86150 54{
52c8d32a 55 ms_buffer = wxIDirectFB::Get()->CreateEventBuffer();
b3c86150
VS
56}
57
e48a3055 58/* static */
b46b1d59 59void wxGUIEventLoop::CleanUp()
e48a3055
VS
60{
61 ms_buffer.Reset();
62}
63
b3c86150 64/* static */
b46b1d59 65wxIDirectFBEventBufferPtr wxGUIEventLoop::GetDirectFBEventBuffer()
b3c86150
VS
66{
67 if ( !ms_buffer )
68 InitBuffer();
69
70 return ms_buffer;
71}
72
73//-----------------------------------------------------------------------------
74// events dispatch and loop handling
75//-----------------------------------------------------------------------------
76
b46b1d59 77bool wxGUIEventLoop::Pending() const
b3c86150 78{
a5001e93 79 wxCHECK_MSG( ms_buffer, false, "invalid event buffer" );
b3c86150 80
52c8d32a 81 return ms_buffer->HasEvent();
b3c86150
VS
82}
83
b46b1d59 84bool wxGUIEventLoop::Dispatch()
b3c86150 85{
a5001e93 86 wxCHECK_MSG( ms_buffer, false, "invalid event buffer" );
b3c86150
VS
87
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
b3c86150
VS
91 const int TIMEOUT = 100;
92
f7a50432
VS
93 // release the GUI mutex so that other threads have a chance to post
94 // events:
95 wxMutexGuiLeave();
96
97 bool rv = ms_buffer->WaitForEventWithTimeout(0, TIMEOUT);
98
99 // and acquire it back before calling any event handlers:
100 wxMutexGuiEnter();
101
102 if ( rv )
b3c86150 103 {
52c8d32a 104 switch ( ms_buffer->GetLastResult() )
b3c86150 105 {
52c8d32a
VS
106 case DFB_OK:
107 {
108 wxDFBEvent e;
109 ms_buffer->GetEvent(e);
110 HandleDFBEvent(e);
111 break;
112 }
113
114 case DFB_TIMEOUT:
115 // timed out, pretend we processed an event so that
116 // OnNextIteration is called
117 break;
118
119 default:
120 // don't terminate the loop due to errors (they were reported
121 // already by ms_buffer)
122 break;
b3c86150 123 }
b3c86150
VS
124 }
125
126 return true;
127}
128
b46b1d59 129void wxGUIEventLoop::WakeUp()
b3c86150 130{
a5001e93 131 wxCHECK_RET( ms_buffer, "invalid event buffer" );
b3c86150 132
52c8d32a 133 ms_buffer->WakeUp();
b3c86150
VS
134}
135
b46b1d59 136void wxGUIEventLoop::OnNextIteration()
b3c86150 137{
6b44a335 138#if wxUSE_TIMER
c2ca375c 139 wxGenericTimerImpl::NotifyTimers();
b3c86150 140#endif
6b44a335
VS
141
142#if wxUSE_SOCKETS
143 // handle any pending socket events:
4eba3923 144 wxFDIODispatcher::DispatchPending();
6b44a335 145#endif
b3c86150
VS
146}
147
b46b1d59 148void wxGUIEventLoop::Yield()
757b694b
VS
149{
150 // process all pending events:
151 while ( Pending() )
152 Dispatch();
153
154 // handle timers, sockets etc.
155 OnNextIteration();
156}
157
b3c86150
VS
158
159//-----------------------------------------------------------------------------
160// DirectFB -> wxWidgets events translation
161//-----------------------------------------------------------------------------
162
b46b1d59 163void wxGUIEventLoop::HandleDFBEvent(const wxDFBEvent& event)
b3c86150
VS
164{
165 switch ( event.GetClass() )
166 {
167 case DFEC_WINDOW:
168 {
169 wxDFBWindowEvent winevent(((const DFBEvent&)event).window);
0edbcd60 170 wxNonOwnedWindow::HandleDFBWindowEvent(winevent);
b3c86150
VS
171 break;
172 }
173
174 case DFEC_NONE:
175 case DFEC_INPUT:
176 case DFEC_USER:
dc4451c2 177#if wxCHECK_DFB_VERSION(0,9,23)
b3c86150 178 case DFEC_UNIVERSAL:
dc4451c2 179#endif
b3c86150
VS
180 {
181 wxLogTrace(TRACE_EVENTS,
a5001e93 182 "ignoring event of unsupported class %i",
b3c86150
VS
183 (int)event.GetClass());
184 }
185 }
186}