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