]> git.saurik.com Git - wxWidgets.git/blob - src/dfb/app.cpp
guarding agains NULL
[wxWidgets.git] / src / dfb / app.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/app.cpp
3 // Purpose: wxApp implementation
4 // Author: Vaclav Slavik
5 // Created: 2006-08-16
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #include "wx/app.h"
19
20 #include "wx/evtloop.h"
21 #include "wx/thread.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 // we don't need a mutex here, since we use the wxConsoleEventLoop
151 // and wxConsoleEventLoop::WakeUp() is thread-safe
152 wxEventLoopBase * const loop = wxEventLoop::GetActive();
153 if ( loop )
154 loop->WakeUp();
155 }