]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/dfb/app.cpp | |
3 | // Purpose: wxApp implementation | |
4 | // Author: Vaclav Slavik | |
5 | // Created: 2006-08-16 | |
6 | // Copyright: (c) 2006 REA Elektronik GmbH | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // For compilers that support precompilation, includes "wx.h". | |
11 | #include "wx/wxprec.h" | |
12 | ||
13 | #ifdef __BORLANDC__ | |
14 | #pragma hdrstop | |
15 | #endif | |
16 | ||
17 | #include "wx/app.h" | |
18 | ||
19 | #include "wx/evtloop.h" | |
20 | #include "wx/thread.h" | |
21 | #include "wx/dfb/private.h" | |
22 | #include "wx/private/fontmgr.h" | |
23 | ||
24 | //----------------------------------------------------------------------------- | |
25 | // wxApp initialization | |
26 | //----------------------------------------------------------------------------- | |
27 | ||
28 | IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) | |
29 | ||
30 | wxApp::wxApp() | |
31 | { | |
32 | } | |
33 | ||
34 | wxApp::~wxApp() | |
35 | { | |
36 | } | |
37 | ||
38 | bool wxApp::Initialize(int& argc, wxChar **argv) | |
39 | { | |
40 | if ( !wxAppBase::Initialize(argc, argv) ) | |
41 | return false; | |
42 | ||
43 | // FIXME-UTF8: This code is taken from wxGTK and duplicated here. This | |
44 | // is just a temporary fix to make wxDFB compile in Unicode | |
45 | // build, the real fix is to change Initialize()'s signature | |
46 | // to use char* on Unix. | |
47 | #if wxUSE_UNICODE | |
48 | // DirectFBInit() wants UTF-8, not wchar_t, so convert | |
49 | int i; | |
50 | char **argvDFB = new char *[argc + 1]; | |
51 | for ( i = 0; i < argc; i++ ) | |
52 | { | |
53 | argvDFB[i] = strdup(wxConvUTF8.cWX2MB(argv[i])); | |
54 | } | |
55 | ||
56 | argvDFB[argc] = NULL; | |
57 | ||
58 | int argcDFB = argc; | |
59 | ||
60 | if ( !wxDfbCheckReturn(DirectFBInit(&argcDFB, &argvDFB)) ) | |
61 | return false; | |
62 | ||
63 | if ( argcDFB != argc ) | |
64 | { | |
65 | // we have to drop the parameters which were consumed by DFB+ | |
66 | for ( i = 0; i < argcDFB; i++ ) | |
67 | { | |
68 | while ( strcmp(wxConvUTF8.cWX2MB(argv[i]), argvDFB[i]) != 0 ) | |
69 | { | |
70 | memmove(argv + i, argv + i + 1, (argc - i)*sizeof(*argv)); | |
71 | } | |
72 | } | |
73 | ||
74 | argc = argcDFB; | |
75 | } | |
76 | //else: DirectFBInit() didn't modify our parameters | |
77 | ||
78 | // free our copy | |
79 | for ( i = 0; i < argcDFB; i++ ) | |
80 | { | |
81 | free(argvDFB[i]); | |
82 | } | |
83 | ||
84 | delete [] argvDFB; | |
85 | ||
86 | #else // ANSI | |
87 | ||
88 | if ( !wxDfbCheckReturn(DirectFBInit(&argc, &argv)) ) | |
89 | return false; | |
90 | ||
91 | #endif // Unicode/ANSI | |
92 | ||
93 | // update internal arg[cv] as DFB may have removed processed options: | |
94 | this->argc = argc; | |
95 | this->argv = argv; | |
96 | ||
97 | if ( !wxIDirectFB::Get() ) | |
98 | return false; | |
99 | ||
100 | return true; | |
101 | } | |
102 | ||
103 | void wxApp::CleanUp() | |
104 | { | |
105 | wxAppBase::CleanUp(); | |
106 | ||
107 | wxFontsManager::CleanUp(); | |
108 | ||
109 | wxEventLoop::CleanUp(); | |
110 | wxIDirectFB::CleanUp(); | |
111 | } | |
112 | ||
113 | //----------------------------------------------------------------------------- | |
114 | // display mode | |
115 | //----------------------------------------------------------------------------- | |
116 | ||
117 | static wxVideoMode GetCurrentVideoMode() | |
118 | { | |
119 | wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer()); | |
120 | if ( !layer ) | |
121 | return wxVideoMode(); // invalid | |
122 | ||
123 | return layer->GetVideoMode(); | |
124 | } | |
125 | ||
126 | wxVideoMode wxApp::GetDisplayMode() const | |
127 | { | |
128 | if ( !m_videoMode.IsOk() ) | |
129 | wxConstCast(this, wxApp)->m_videoMode = GetCurrentVideoMode(); | |
130 | ||
131 | return m_videoMode; | |
132 | } | |
133 | ||
134 | bool wxApp::SetDisplayMode(const wxVideoMode& mode) | |
135 | { | |
136 | if ( !wxIDirectFB::Get()->SetVideoMode(mode.w, mode.h, mode.bpp) ) | |
137 | return false; | |
138 | ||
139 | m_videoMode = mode; | |
140 | return true; | |
141 | } | |
142 | ||
143 | //----------------------------------------------------------------------------- | |
144 | // events processing related | |
145 | //----------------------------------------------------------------------------- | |
146 | ||
147 | void wxApp::WakeUpIdle() | |
148 | { | |
149 | // we don't need a mutex here, since we use the wxConsoleEventLoop | |
150 | // and wxConsoleEventLoop::WakeUp() is thread-safe | |
151 | wxEventLoopBase * const loop = wxEventLoop::GetActive(); | |
152 | if ( loop ) | |
153 | loop->WakeUp(); | |
154 | } |