]> git.saurik.com Git - wxWidgets.git/blob - src/dfb/app.cpp
Fix setting the clipping region for a DC when the region is an
[wxWidgets.git] / src / dfb / app.cpp
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
28 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
29
30 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
31 EVT_IDLE(wxAppBase::OnIdle)
32 END_EVENT_TABLE()
33
34 wxApp::wxApp()
35 {
36 }
37
38 wxApp::~wxApp()
39 {
40 }
41
42 bool wxApp::Initialize(int& argc, wxChar **argv)
43 {
44 if ( !wxAppBase::Initialize(argc, argv) )
45 return false;
46
47 if ( !wxDfbCheckReturn(DirectFBInit(&argc, &argv)) )
48 return false;
49
50 if ( !wxIDirectFB::Get() )
51 return false;
52
53 return true;
54 }
55
56 void wxApp::CleanUp()
57 {
58 wxAppBase::CleanUp();
59
60 wxEventLoop::CleanUp();
61 wxIDirectFB::CleanUp();
62 }
63
64 //-----------------------------------------------------------------------------
65 // display mode
66 //-----------------------------------------------------------------------------
67
68 static wxVideoMode GetCurrentVideoMode()
69 {
70 wxVideoMode m;
71
72 wxIDirectFBSurfacePtr surface(wxIDirectFB::Get()->GetPrimarySurface());
73 if ( !surface )
74 return m; // invalid
75
76 surface->GetSize(&m.w, &m.h);
77 m.bpp = surface->GetDepth();
78
79 return m;
80 }
81
82 wxVideoMode wxApp::GetDisplayMode() const
83 {
84 if ( !m_videoMode.IsOk() )
85 wxConstCast(this, wxApp)->m_videoMode = GetCurrentVideoMode();
86
87 return m_videoMode;
88 }
89
90 bool wxApp::SetDisplayMode(const wxVideoMode& mode)
91 {
92 if ( !wxIDirectFB::Get()->SetVideoMode(mode.w, mode.h, mode.bpp) )
93 return false;
94
95 m_videoMode = mode;
96 return true;
97 }
98
99 //-----------------------------------------------------------------------------
100 // events processing related
101 //-----------------------------------------------------------------------------
102
103 void 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
119 bool 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 }