]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/app.cpp
convert bitmap's surface to RGB24/ARGB in wxBitmap::GetRawData() if it uses different...
[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"
22#include "wx/dfb/private.h"
d7ae4a62 23#include "wx/private/fontmgr.h"
b3c86150
VS
24
25//-----------------------------------------------------------------------------
26// wxApp initialization
27//-----------------------------------------------------------------------------
28
29IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
30
b3c86150
VS
31wxApp::wxApp()
32{
33}
34
35wxApp::~wxApp()
36{
37}
38
b3c86150
VS
39bool wxApp::Initialize(int& argc, wxChar **argv)
40{
41 if ( !wxAppBase::Initialize(argc, argv) )
42 return false;
43
b11af9ed
VS
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
52c8d32a 89 if ( !wxDfbCheckReturn(DirectFBInit(&argc, &argv)) )
b3c86150
VS
90 return false;
91
b11af9ed
VS
92#endif // Unicode/ANSI
93
50f1747a
VS
94 // update internal arg[cv] as DFB may have removed processed options:
95 this->argc = argc;
96 this->argv = argv;
97
52c8d32a 98 if ( !wxIDirectFB::Get() )
b3c86150
VS
99 return false;
100
b3c86150
VS
101 return true;
102}
103
104void wxApp::CleanUp()
105{
106 wxAppBase::CleanUp();
107
d7ae4a62
VS
108 wxFontsManager::CleanUp();
109
e48a3055 110 wxEventLoop::CleanUp();
52c8d32a 111 wxIDirectFB::CleanUp();
b3c86150
VS
112}
113
114//-----------------------------------------------------------------------------
115// display mode
116//-----------------------------------------------------------------------------
117
118static wxVideoMode GetCurrentVideoMode()
119{
fa28b00c
VS
120 wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer());
121 if ( !layer )
122 return wxVideoMode(); // invalid
b3c86150 123
fa28b00c 124 return layer->GetVideoMode();
b3c86150
VS
125}
126
127wxVideoMode wxApp::GetDisplayMode() const
128{
129 if ( !m_videoMode.IsOk() )
130 wxConstCast(this, wxApp)->m_videoMode = GetCurrentVideoMode();
131
132 return m_videoMode;
133}
134
135bool wxApp::SetDisplayMode(const wxVideoMode& mode)
136{
52c8d32a 137 if ( !wxIDirectFB::Get()->SetVideoMode(mode.w, mode.h, mode.bpp) )
b3c86150
VS
138 return false;
139
140 m_videoMode = mode;
141 return true;
142}
143
144//-----------------------------------------------------------------------------
145// events processing related
146//-----------------------------------------------------------------------------
147
148void wxApp::WakeUpIdle()
149{
150#if wxUSE_THREADS
151 if (!wxThread::IsMain())
152 wxMutexGuiEnter();
153#endif
154
2ddff00c 155 wxEventLoopBase * const loop = wxEventLoop::GetActive();
655c20fc
VS
156 if ( loop )
157 loop->WakeUp();
b3c86150
VS
158
159#if wxUSE_THREADS
160 if (!wxThread::IsMain())
161 wxMutexGuiLeave();
162#endif
163}
164
165
166bool 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 wxLog::Suspend();
188
2ddff00c
VZ
189 wxEventLoop * const
190 loop = wx_static_cast(wxEventLoop *, wxEventLoop::GetActive());
655c20fc
VS
191 if ( loop )
192 loop->Yield();
b3c86150
VS
193
194 // it's necessary to call ProcessIdle() to update the frames sizes which
195 // might have been changed (it also will update other things set from
196 // OnUpdateUI() which is a nice (and desired) side effect)
197 while ( ProcessIdle() ) {}
198
199 wxLog::Resume();
200
201 s_inYield = false;
202
203 return true;
204}