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