]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/app.cpp
compile fixes for Python 2.5
[wxWidgets.git] / src / dfb / app.cpp
CommitLineData
b3c86150
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/dfb/app.cpp
3// Purpose: wxApp implementation
4// Author: Vaclav Slavik
5// based on MGL implementation
6// Created: 2006-08-16
7// RCS-ID: $Id$
8// Copyright: (c) 2006 REA Elektronik GmbH
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#include "wx/app.h"
20
21#include "wx/evtloop.h"
22#include "wx/dfb/private.h"
23
24//-----------------------------------------------------------------------------
25// wxApp initialization
26//-----------------------------------------------------------------------------
27
28IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
29
30BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
31 EVT_IDLE(wxAppBase::OnIdle)
32END_EVENT_TABLE()
33
34wxApp::wxApp()
35{
36}
37
38wxApp::~wxApp()
39{
40}
41
42IDirectFBPtr wxApp::GetDirectFBInterface()
43{
44 return m_dfb;
45}
46
47bool wxApp::Initialize(int& argc, wxChar **argv)
48{
49 if ( !wxAppBase::Initialize(argc, argv) )
50 return false;
51
52 if ( !DFB_CALL( DirectFBInit(&argc, &argv) ) )
53 return false;
54
55 if ( !DFB_CALL( DirectFBCreate(&m_dfb) ) )
56 return false;
57
58 #warning "FIXME: theme override is temporary"
59 wxTheme::Set(wxTheme::Create(_T("gtk")));
60
61 return true;
62}
63
64void wxApp::CleanUp()
65{
66 wxAppBase::CleanUp();
67
68 m_dfb.Reset();
69}
70
71//-----------------------------------------------------------------------------
72// display mode
73//-----------------------------------------------------------------------------
74
75static wxVideoMode GetCurrentVideoMode()
76{
77 wxVideoMode m;
78
79 IDirectFBSurfacePtr surface(wxDfbGetPrimarySurface());
80 if ( !surface )
81 return m; // invalid
82
83 DFB_CALL( surface->GetSize(surface, &m.w, &m.h) );
84 m.bpp = wxDfbGetSurfaceDepth(surface);
85
86 return m;
87}
88
89wxVideoMode wxApp::GetDisplayMode() const
90{
91 if ( !m_videoMode.IsOk() )
92 wxConstCast(this, wxApp)->m_videoMode = GetCurrentVideoMode();
93
94 return m_videoMode;
95}
96
97bool wxApp::SetDisplayMode(const wxVideoMode& mode)
98{
99 if ( !DFB_CALL( m_dfb->SetVideoMode(m_dfb, mode.w, mode.h, mode.bpp) ) )
100 return false;
101
102 m_videoMode = mode;
103 return true;
104}
105
106//-----------------------------------------------------------------------------
107// events processing related
108//-----------------------------------------------------------------------------
109
110void wxApp::WakeUpIdle()
111{
112#if wxUSE_THREADS
113 if (!wxThread::IsMain())
114 wxMutexGuiEnter();
115#endif
116
117 wxEventLoop::GetActive()->WakeUp();
118
119#if wxUSE_THREADS
120 if (!wxThread::IsMain())
121 wxMutexGuiLeave();
122#endif
123}
124
125
126bool wxApp::Yield(bool onlyIfNeeded)
127{
128#if wxUSE_THREADS
129 if ( !wxThread::IsMain() )
130 return true; // can't process events from other threads
131#endif // wxUSE_THREADS
132
133 static bool s_inYield = false;
134
135 if ( s_inYield )
136 {
137 if ( !onlyIfNeeded )
138 {
139 wxFAIL_MSG( wxT("wxYield called recursively" ) );
140 }
141
142 return false;
143 }
144
145 s_inYield = true;
146
147 wxLog::Suspend();
148
149 if ( wxEventLoop::GetActive() )
150 {
151 while (wxEventLoop::GetActive()->Pending())
152 wxEventLoop::GetActive()->Dispatch();
153 }
154
155 // it's necessary to call ProcessIdle() to update the frames sizes which
156 // might have been changed (it also will update other things set from
157 // OnUpdateUI() which is a nice (and desired) side effect)
158 while ( ProcessIdle() ) {}
159
160 wxLog::Resume();
161
162 s_inYield = false;
163
164 return true;
165}