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