]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/dfb/app.cpp
document that SetValue() accepts values in 0..GetRange interval, inclusive
[wxWidgets.git] / src / dfb / app.cpp
... / ...
CommitLineData
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
29IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
30
31BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
32 EVT_IDLE(wxAppBase::OnIdle)
33END_EVENT_TABLE()
34
35wxApp::wxApp()
36{
37}
38
39wxApp::~wxApp()
40{
41}
42
43bool wxApp::Initialize(int& argc, wxChar **argv)
44{
45 if ( !wxAppBase::Initialize(argc, argv) )
46 return false;
47
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
93 if ( !wxDfbCheckReturn(DirectFBInit(&argc, &argv)) )
94 return false;
95
96#endif // Unicode/ANSI
97
98 // update internal arg[cv] as DFB may have removed processed options:
99 this->argc = argc;
100 this->argv = argv;
101
102 if ( !wxIDirectFB::Get() )
103 return false;
104
105 return true;
106}
107
108void wxApp::CleanUp()
109{
110 wxAppBase::CleanUp();
111
112 wxFontsManager::CleanUp();
113
114 wxEventLoop::CleanUp();
115 wxIDirectFB::CleanUp();
116}
117
118//-----------------------------------------------------------------------------
119// display mode
120//-----------------------------------------------------------------------------
121
122static wxVideoMode GetCurrentVideoMode()
123{
124 wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer());
125 if ( !layer )
126 return wxVideoMode(); // invalid
127
128 return layer->GetVideoMode();
129}
130
131wxVideoMode wxApp::GetDisplayMode() const
132{
133 if ( !m_videoMode.IsOk() )
134 wxConstCast(this, wxApp)->m_videoMode = GetCurrentVideoMode();
135
136 return m_videoMode;
137}
138
139bool wxApp::SetDisplayMode(const wxVideoMode& mode)
140{
141 if ( !wxIDirectFB::Get()->SetVideoMode(mode.w, mode.h, mode.bpp) )
142 return false;
143
144 m_videoMode = mode;
145 return true;
146}
147
148//-----------------------------------------------------------------------------
149// events processing related
150//-----------------------------------------------------------------------------
151
152void wxApp::WakeUpIdle()
153{
154#if wxUSE_THREADS
155 if (!wxThread::IsMain())
156 wxMutexGuiEnter();
157#endif
158
159 wxEventLoopBase * const loop = wxEventLoop::GetActive();
160 if ( loop )
161 loop->WakeUp();
162
163#if wxUSE_THREADS
164 if (!wxThread::IsMain())
165 wxMutexGuiLeave();
166#endif
167}
168
169
170bool 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
193 wxEventLoop * const
194 loop = wx_static_cast(wxEventLoop *, wxEventLoop::GetActive());
195 if ( loop )
196 loop->Yield();
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}