]>
Commit | Line | Data |
---|---|---|
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 | ||
29 | IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) | |
30 | ||
31 | BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) | |
32 | EVT_IDLE(wxAppBase::OnIdle) | |
33 | END_EVENT_TABLE() | |
34 | ||
35 | wxApp::wxApp() | |
36 | { | |
37 | } | |
38 | ||
39 | wxApp::~wxApp() | |
40 | { | |
41 | } | |
42 | ||
b3c86150 VS |
43 | bool wxApp::Initialize(int& argc, wxChar **argv) |
44 | { | |
45 | if ( !wxAppBase::Initialize(argc, argv) ) | |
46 | return false; | |
47 | ||
52c8d32a | 48 | if ( !wxDfbCheckReturn(DirectFBInit(&argc, &argv)) ) |
b3c86150 VS |
49 | return false; |
50 | ||
52c8d32a | 51 | if ( !wxIDirectFB::Get() ) |
b3c86150 VS |
52 | return false; |
53 | ||
b3c86150 VS |
54 | return true; |
55 | } | |
56 | ||
57 | void wxApp::CleanUp() | |
58 | { | |
59 | wxAppBase::CleanUp(); | |
60 | ||
d7ae4a62 VS |
61 | wxFontsManager::CleanUp(); |
62 | ||
e48a3055 | 63 | wxEventLoop::CleanUp(); |
52c8d32a | 64 | wxIDirectFB::CleanUp(); |
b3c86150 VS |
65 | } |
66 | ||
67 | //----------------------------------------------------------------------------- | |
68 | // display mode | |
69 | //----------------------------------------------------------------------------- | |
70 | ||
71 | static wxVideoMode GetCurrentVideoMode() | |
72 | { | |
fa28b00c VS |
73 | wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer()); |
74 | if ( !layer ) | |
75 | return wxVideoMode(); // invalid | |
b3c86150 | 76 | |
fa28b00c | 77 | return layer->GetVideoMode(); |
b3c86150 VS |
78 | } |
79 | ||
80 | wxVideoMode wxApp::GetDisplayMode() const | |
81 | { | |
82 | if ( !m_videoMode.IsOk() ) | |
83 | wxConstCast(this, wxApp)->m_videoMode = GetCurrentVideoMode(); | |
84 | ||
85 | return m_videoMode; | |
86 | } | |
87 | ||
88 | bool wxApp::SetDisplayMode(const wxVideoMode& mode) | |
89 | { | |
52c8d32a | 90 | if ( !wxIDirectFB::Get()->SetVideoMode(mode.w, mode.h, mode.bpp) ) |
b3c86150 VS |
91 | return false; |
92 | ||
93 | m_videoMode = mode; | |
94 | return true; | |
95 | } | |
96 | ||
97 | //----------------------------------------------------------------------------- | |
98 | // events processing related | |
99 | //----------------------------------------------------------------------------- | |
100 | ||
101 | void wxApp::WakeUpIdle() | |
102 | { | |
103 | #if wxUSE_THREADS | |
104 | if (!wxThread::IsMain()) | |
105 | wxMutexGuiEnter(); | |
106 | #endif | |
107 | ||
108 | wxEventLoop::GetActive()->WakeUp(); | |
109 | ||
110 | #if wxUSE_THREADS | |
111 | if (!wxThread::IsMain()) | |
112 | wxMutexGuiLeave(); | |
113 | #endif | |
114 | } | |
115 | ||
116 | ||
117 | bool wxApp::Yield(bool onlyIfNeeded) | |
118 | { | |
119 | #if wxUSE_THREADS | |
120 | if ( !wxThread::IsMain() ) | |
121 | return true; // can't process events from other threads | |
122 | #endif // wxUSE_THREADS | |
123 | ||
124 | static bool s_inYield = false; | |
125 | ||
126 | if ( s_inYield ) | |
127 | { | |
128 | if ( !onlyIfNeeded ) | |
129 | { | |
130 | wxFAIL_MSG( wxT("wxYield called recursively" ) ); | |
131 | } | |
132 | ||
133 | return false; | |
134 | } | |
135 | ||
136 | s_inYield = true; | |
137 | ||
138 | wxLog::Suspend(); | |
139 | ||
140 | if ( wxEventLoop::GetActive() ) | |
141 | { | |
142 | while (wxEventLoop::GetActive()->Pending()) | |
143 | wxEventLoop::GetActive()->Dispatch(); | |
144 | } | |
145 | ||
146 | // it's necessary to call ProcessIdle() to update the frames sizes which | |
147 | // might have been changed (it also will update other things set from | |
148 | // OnUpdateUI() which is a nice (and desired) side effect) | |
149 | while ( ProcessIdle() ) {} | |
150 | ||
151 | wxLog::Resume(); | |
152 | ||
153 | s_inYield = false; | |
154 | ||
155 | return true; | |
156 | } |