]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/app.cpp
avoiding nesting dcs on the same window concurrently
[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
b3c86150
VS
42bool wxApp::Initialize(int& argc, wxChar **argv)
43{
44 if ( !wxAppBase::Initialize(argc, argv) )
45 return false;
46
52c8d32a 47 if ( !wxDfbCheckReturn(DirectFBInit(&argc, &argv)) )
b3c86150
VS
48 return false;
49
52c8d32a 50 if ( !wxIDirectFB::Get() )
b3c86150
VS
51 return false;
52
b3c86150
VS
53 return true;
54}
55
56void wxApp::CleanUp()
57{
58 wxAppBase::CleanUp();
59
e48a3055 60 wxEventLoop::CleanUp();
52c8d32a 61 wxIDirectFB::CleanUp();
b3c86150
VS
62}
63
64//-----------------------------------------------------------------------------
65// display mode
66//-----------------------------------------------------------------------------
67
68static wxVideoMode GetCurrentVideoMode()
69{
70 wxVideoMode m;
71
a5b31f4e 72 wxIDirectFBSurfacePtr surface(wxIDirectFB::Get()->GetPrimarySurface());
b3c86150
VS
73 if ( !surface )
74 return m; // invalid
75
52c8d32a 76 surface->GetSize(&m.w, &m.h);
a5b31f4e 77 m.bpp = surface->GetDepth();
b3c86150
VS
78
79 return m;
80}
81
82wxVideoMode wxApp::GetDisplayMode() const
83{
84 if ( !m_videoMode.IsOk() )
85 wxConstCast(this, wxApp)->m_videoMode = GetCurrentVideoMode();
86
87 return m_videoMode;
88}
89
90bool wxApp::SetDisplayMode(const wxVideoMode& mode)
91{
52c8d32a 92 if ( !wxIDirectFB::Get()->SetVideoMode(mode.w, mode.h, mode.bpp) )
b3c86150
VS
93 return false;
94
95 m_videoMode = mode;
96 return true;
97}
98
99//-----------------------------------------------------------------------------
100// events processing related
101//-----------------------------------------------------------------------------
102
103void wxApp::WakeUpIdle()
104{
105#if wxUSE_THREADS
106 if (!wxThread::IsMain())
107 wxMutexGuiEnter();
108#endif
109
110 wxEventLoop::GetActive()->WakeUp();
111
112#if wxUSE_THREADS
113 if (!wxThread::IsMain())
114 wxMutexGuiLeave();
115#endif
116}
117
118
119bool wxApp::Yield(bool onlyIfNeeded)
120{
121#if wxUSE_THREADS
122 if ( !wxThread::IsMain() )
123 return true; // can't process events from other threads
124#endif // wxUSE_THREADS
125
126 static bool s_inYield = false;
127
128 if ( s_inYield )
129 {
130 if ( !onlyIfNeeded )
131 {
132 wxFAIL_MSG( wxT("wxYield called recursively" ) );
133 }
134
135 return false;
136 }
137
138 s_inYield = true;
139
140 wxLog::Suspend();
141
142 if ( wxEventLoop::GetActive() )
143 {
144 while (wxEventLoop::GetActive()->Pending())
145 wxEventLoop::GetActive()->Dispatch();
146 }
147
148 // it's necessary to call ProcessIdle() to update the frames sizes which
149 // might have been changed (it also will update other things set from
150 // OnUpdateUI() which is a nice (and desired) side effect)
151 while ( ProcessIdle() ) {}
152
153 wxLog::Resume();
154
155 s_inYield = false;
156
157 return true;
158}