]> git.saurik.com Git - wxWidgets.git/blob - src/dfb/app.cpp
changed wxDC::GetTextExtent() and related methods to take const wxFont pointer, for...
[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 #include "wx/private/fontmgr.h"
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
43 bool wxApp::Initialize(int& argc, wxChar **argv)
44 {
45 if ( !wxAppBase::Initialize(argc, argv) )
46 return false;
47
48 if ( !wxDfbCheckReturn(DirectFBInit(&argc, &argv)) )
49 return false;
50
51 if ( !wxIDirectFB::Get() )
52 return false;
53
54 return true;
55 }
56
57 void wxApp::CleanUp()
58 {
59 wxAppBase::CleanUp();
60
61 wxFontsManager::CleanUp();
62
63 wxEventLoop::CleanUp();
64 wxIDirectFB::CleanUp();
65 }
66
67 //-----------------------------------------------------------------------------
68 // display mode
69 //-----------------------------------------------------------------------------
70
71 static wxVideoMode GetCurrentVideoMode()
72 {
73 wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer());
74 if ( !layer )
75 return wxVideoMode(); // invalid
76
77 return layer->GetVideoMode();
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 {
90 if ( !wxIDirectFB::Get()->SetVideoMode(mode.w, mode.h, mode.bpp) )
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 * const loop = wxEventLoop::GetActive();
109 if ( loop )
110 loop->WakeUp();
111
112 #if wxUSE_THREADS
113 if (!wxThread::IsMain())
114 wxMutexGuiLeave();
115 #endif
116 }
117
118
119 bool wxApp::Yield(bool onlyIfNeeded)
120 {
121 #if wxUSE_THREADS
122 if ( !wxThread::IsMain() )
123 return true; // can't process events from other threads
124 #endif // wxUSE_THREADS
125
126 static bool s_inYield = false;
127
128 if ( s_inYield )
129 {
130 if ( !onlyIfNeeded )
131 {
132 wxFAIL_MSG( wxT("wxYield called recursively" ) );
133 }
134
135 return false;
136 }
137
138 s_inYield = true;
139
140 wxLog::Suspend();
141
142 wxEventLoop * const loop = wxEventLoop::GetActive();
143 if ( loop )
144 loop->Yield();
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 }