]>
Commit | Line | Data |
---|---|---|
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" | |
d7ae4a62 | 23 | #include "wx/private/fontmgr.h" |
b3c86150 VS |
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 | ||
b3c86150 VS |
43 | bool wxApp::Initialize(int& argc, wxChar **argv) |
44 | { | |
45 | if ( !wxAppBase::Initialize(argc, argv) ) | |
46 | return false; | |
47 | ||
b11af9ed VS |
48 | // FIXME-UTF8: This code is taken from wxGTK and duplicated here. This |
49 | // is just a temporary fix to make wxDFB compile in Unicode | |
50 | // build, the real fix is to change Initialize()'s signature | |
51 | // to use char* on Unix. | |
52 | #if wxUSE_UNICODE | |
53 | // DirectFBInit() wants UTF-8, not wchar_t, so convert | |
54 | int i; | |
55 | char **argvDFB = new char *[argc + 1]; | |
56 | for ( i = 0; i < argc; i++ ) | |
57 | { | |
58 | argvDFB[i] = strdup(wxConvUTF8.cWX2MB(argv[i])); | |
59 | } | |
60 | ||
61 | argvDFB[argc] = NULL; | |
62 | ||
63 | int argcDFB = argc; | |
64 | ||
65 | if ( !wxDfbCheckReturn(DirectFBInit(&argcDFB, &argvDFB)) ) | |
66 | return false; | |
67 | ||
68 | if ( argcDFB != argc ) | |
69 | { | |
70 | // we have to drop the parameters which were consumed by DFB+ | |
71 | for ( i = 0; i < argcDFB; i++ ) | |
72 | { | |
73 | while ( strcmp(wxConvUTF8.cWX2MB(argv[i]), argvDFB[i]) != 0 ) | |
74 | { | |
75 | memmove(argv + i, argv + i + 1, (argc - i)*sizeof(*argv)); | |
76 | } | |
77 | } | |
78 | ||
79 | argc = argcDFB; | |
80 | } | |
81 | //else: DirectFBInit() didn't modify our parameters | |
82 | ||
83 | // free our copy | |
84 | for ( i = 0; i < argcDFB; i++ ) | |
85 | { | |
86 | free(argvDFB[i]); | |
87 | } | |
88 | ||
89 | delete [] argvDFB; | |
90 | ||
91 | #else // ANSI | |
92 | ||
52c8d32a | 93 | if ( !wxDfbCheckReturn(DirectFBInit(&argc, &argv)) ) |
b3c86150 VS |
94 | return false; |
95 | ||
b11af9ed VS |
96 | #endif // Unicode/ANSI |
97 | ||
50f1747a VS |
98 | // update internal arg[cv] as DFB may have removed processed options: |
99 | this->argc = argc; | |
100 | this->argv = argv; | |
101 | ||
52c8d32a | 102 | if ( !wxIDirectFB::Get() ) |
b3c86150 VS |
103 | return false; |
104 | ||
b3c86150 VS |
105 | return true; |
106 | } | |
107 | ||
108 | void wxApp::CleanUp() | |
109 | { | |
110 | wxAppBase::CleanUp(); | |
111 | ||
d7ae4a62 VS |
112 | wxFontsManager::CleanUp(); |
113 | ||
e48a3055 | 114 | wxEventLoop::CleanUp(); |
52c8d32a | 115 | wxIDirectFB::CleanUp(); |
b3c86150 VS |
116 | } |
117 | ||
118 | //----------------------------------------------------------------------------- | |
119 | // display mode | |
120 | //----------------------------------------------------------------------------- | |
121 | ||
122 | static wxVideoMode GetCurrentVideoMode() | |
123 | { | |
fa28b00c VS |
124 | wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer()); |
125 | if ( !layer ) | |
126 | return wxVideoMode(); // invalid | |
b3c86150 | 127 | |
fa28b00c | 128 | return layer->GetVideoMode(); |
b3c86150 VS |
129 | } |
130 | ||
131 | wxVideoMode wxApp::GetDisplayMode() const | |
132 | { | |
133 | if ( !m_videoMode.IsOk() ) | |
134 | wxConstCast(this, wxApp)->m_videoMode = GetCurrentVideoMode(); | |
135 | ||
136 | return m_videoMode; | |
137 | } | |
138 | ||
139 | bool wxApp::SetDisplayMode(const wxVideoMode& mode) | |
140 | { | |
52c8d32a | 141 | if ( !wxIDirectFB::Get()->SetVideoMode(mode.w, mode.h, mode.bpp) ) |
b3c86150 VS |
142 | return false; |
143 | ||
144 | m_videoMode = mode; | |
145 | return true; | |
146 | } | |
147 | ||
148 | //----------------------------------------------------------------------------- | |
149 | // events processing related | |
150 | //----------------------------------------------------------------------------- | |
151 | ||
152 | void wxApp::WakeUpIdle() | |
153 | { | |
154 | #if wxUSE_THREADS | |
155 | if (!wxThread::IsMain()) | |
156 | wxMutexGuiEnter(); | |
157 | #endif | |
158 | ||
2ddff00c | 159 | wxEventLoopBase * const loop = wxEventLoop::GetActive(); |
655c20fc VS |
160 | if ( loop ) |
161 | loop->WakeUp(); | |
b3c86150 VS |
162 | |
163 | #if wxUSE_THREADS | |
164 | if (!wxThread::IsMain()) | |
165 | wxMutexGuiLeave(); | |
166 | #endif | |
167 | } | |
168 | ||
169 | ||
170 | bool wxApp::Yield(bool onlyIfNeeded) | |
171 | { | |
172 | #if wxUSE_THREADS | |
173 | if ( !wxThread::IsMain() ) | |
174 | return true; // can't process events from other threads | |
175 | #endif // wxUSE_THREADS | |
176 | ||
177 | static bool s_inYield = false; | |
178 | ||
179 | if ( s_inYield ) | |
180 | { | |
181 | if ( !onlyIfNeeded ) | |
182 | { | |
183 | wxFAIL_MSG( wxT("wxYield called recursively" ) ); | |
184 | } | |
185 | ||
186 | return false; | |
187 | } | |
188 | ||
189 | s_inYield = true; | |
190 | ||
191 | wxLog::Suspend(); | |
192 | ||
2ddff00c VZ |
193 | wxEventLoop * const |
194 | loop = wx_static_cast(wxEventLoop *, wxEventLoop::GetActive()); | |
655c20fc VS |
195 | if ( loop ) |
196 | loop->Yield(); | |
b3c86150 VS |
197 | |
198 | // it's necessary to call ProcessIdle() to update the frames sizes which | |
199 | // might have been changed (it also will update other things set from | |
200 | // OnUpdateUI() which is a nice (and desired) side effect) | |
201 | while ( ProcessIdle() ) {} | |
202 | ||
203 | wxLog::Resume(); | |
204 | ||
205 | s_inYield = false; | |
206 | ||
207 | return true; | |
208 | } |