]> git.saurik.com Git - wxWidgets.git/blob - src/dfb/app.cpp
take into account DirectFB's removal of some command line arguments
[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 #include "wx/private/fontmgr.h"
24
25 //-----------------------------------------------------------------------------
26 // wxApp initialization
27 //-----------------------------------------------------------------------------
28
29 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
30
31 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
32 EVT_IDLE(wxAppBase::OnIdle)
33 END_EVENT_TABLE()
34
35 wxApp::wxApp()
36 {
37 }
38
39 wxApp::~wxApp()
40 {
41 }
42
43 bool wxApp::Initialize(int& argc, wxChar **argv)
44 {
45 if ( !wxAppBase::Initialize(argc, argv) )
46 return false;
47
48 if ( !wxDfbCheckReturn(DirectFBInit(&argc, &argv)) )
49 return false;
50
51 // update internal arg[cv] as DFB may have removed processed options:
52 this->argc = argc;
53 this->argv = argv;
54
55 if ( !wxIDirectFB::Get() )
56 return false;
57
58 return true;
59 }
60
61 void wxApp::CleanUp()
62 {
63 wxAppBase::CleanUp();
64
65 wxFontsManager::CleanUp();
66
67 wxEventLoop::CleanUp();
68 wxIDirectFB::CleanUp();
69 }
70
71 //-----------------------------------------------------------------------------
72 // display mode
73 //-----------------------------------------------------------------------------
74
75 static wxVideoMode GetCurrentVideoMode()
76 {
77 wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer());
78 if ( !layer )
79 return wxVideoMode(); // invalid
80
81 return layer->GetVideoMode();
82 }
83
84 wxVideoMode wxApp::GetDisplayMode() const
85 {
86 if ( !m_videoMode.IsOk() )
87 wxConstCast(this, wxApp)->m_videoMode = GetCurrentVideoMode();
88
89 return m_videoMode;
90 }
91
92 bool wxApp::SetDisplayMode(const wxVideoMode& mode)
93 {
94 if ( !wxIDirectFB::Get()->SetVideoMode(mode.w, mode.h, mode.bpp) )
95 return false;
96
97 m_videoMode = mode;
98 return true;
99 }
100
101 //-----------------------------------------------------------------------------
102 // events processing related
103 //-----------------------------------------------------------------------------
104
105 void wxApp::WakeUpIdle()
106 {
107 #if wxUSE_THREADS
108 if (!wxThread::IsMain())
109 wxMutexGuiEnter();
110 #endif
111
112 wxEventLoop * const loop = wxEventLoop::GetActive();
113 if ( loop )
114 loop->WakeUp();
115
116 #if wxUSE_THREADS
117 if (!wxThread::IsMain())
118 wxMutexGuiLeave();
119 #endif
120 }
121
122
123 bool wxApp::Yield(bool onlyIfNeeded)
124 {
125 #if wxUSE_THREADS
126 if ( !wxThread::IsMain() )
127 return true; // can't process events from other threads
128 #endif // wxUSE_THREADS
129
130 static bool s_inYield = false;
131
132 if ( s_inYield )
133 {
134 if ( !onlyIfNeeded )
135 {
136 wxFAIL_MSG( wxT("wxYield called recursively" ) );
137 }
138
139 return false;
140 }
141
142 s_inYield = true;
143
144 wxLog::Suspend();
145
146 wxEventLoop * const loop = wxEventLoop::GetActive();
147 if ( loop )
148 loop->Yield();
149
150 // it's necessary to call ProcessIdle() to update the frames sizes which
151 // might have been changed (it also will update other things set from
152 // OnUpdateUI() which is a nice (and desired) side effect)
153 while ( ProcessIdle() ) {}
154
155 wxLog::Resume();
156
157 s_inYield = false;
158
159 return true;
160 }