]> git.saurik.com Git - wxWidgets.git/blob - src/dfb/app.cpp
Fix my last fix. The method is pure virtual in the base class so it
[wxWidgets.git] / src / dfb / app.cpp
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
42 bool wxApp::Initialize(int& argc, wxChar **argv)
43 {
44 if ( !wxAppBase::Initialize(argc, argv) )
45 return false;
46
47 if ( !wxDfbCheckReturn(DirectFBInit(&argc, &argv)) )
48 return false;
49
50 if ( !wxIDirectFB::Get() )
51 return false;
52
53 #warning "FIXME: theme override is temporary"
54 wxTheme::Set(wxTheme::Create(_T("gtk")));
55
56 return true;
57 }
58
59 void wxApp::CleanUp()
60 {
61 wxAppBase::CleanUp();
62
63 wxIDirectFB::CleanUp();
64 }
65
66 //-----------------------------------------------------------------------------
67 // display mode
68 //-----------------------------------------------------------------------------
69
70 static wxVideoMode GetCurrentVideoMode()
71 {
72 wxVideoMode m;
73
74 wxIDirectFBSurfacePtr surface(wxIDirectFB::Get()->GetPrimarySurface());
75 if ( !surface )
76 return m; // invalid
77
78 surface->GetSize(&m.w, &m.h);
79 m.bpp = surface->GetDepth();
80
81 return m;
82 }
83
84 wxVideoMode wxApp::GetDisplayMode() const
85 {
86 if ( !m_videoMode.IsOk() )
87 wxConstCast(this, wxApp)->m_videoMode = GetCurrentVideoMode();
88
89 return m_videoMode;
90 }
91
92 bool wxApp::SetDisplayMode(const wxVideoMode& mode)
93 {
94 if ( !wxIDirectFB::Get()->SetVideoMode(mode.w, mode.h, mode.bpp) )
95 return false;
96
97 m_videoMode = mode;
98 return true;
99 }
100
101 //-----------------------------------------------------------------------------
102 // events processing related
103 //-----------------------------------------------------------------------------
104
105 void wxApp::WakeUpIdle()
106 {
107 #if wxUSE_THREADS
108 if (!wxThread::IsMain())
109 wxMutexGuiEnter();
110 #endif
111
112 wxEventLoop::GetActive()->WakeUp();
113
114 #if wxUSE_THREADS
115 if (!wxThread::IsMain())
116 wxMutexGuiLeave();
117 #endif
118 }
119
120
121 bool wxApp::Yield(bool onlyIfNeeded)
122 {
123 #if wxUSE_THREADS
124 if ( !wxThread::IsMain() )
125 return true; // can't process events from other threads
126 #endif // wxUSE_THREADS
127
128 static bool s_inYield = false;
129
130 if ( s_inYield )
131 {
132 if ( !onlyIfNeeded )
133 {
134 wxFAIL_MSG( wxT("wxYield called recursively" ) );
135 }
136
137 return false;
138 }
139
140 s_inYield = true;
141
142 wxLog::Suspend();
143
144 if ( wxEventLoop::GetActive() )
145 {
146 while (wxEventLoop::GetActive()->Pending())
147 wxEventLoop::GetActive()->Dispatch();
148 }
149
150 // it's necessary to call ProcessIdle() to update the frames sizes which
151 // might have been changed (it also will update other things set from
152 // OnUpdateUI() which is a nice (and desired) side effect)
153 while ( ProcessIdle() ) {}
154
155 wxLog::Resume();
156
157 s_inYield = false;
158
159 return true;
160 }