]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/app.cpp
offset the text correctly inside the item rect in DrawItem(), it was off by 1
[wxWidgets.git] / src / dfb / app.cpp
CommitLineData
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
28IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
29
30BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
31 EVT_IDLE(wxAppBase::OnIdle)
32END_EVENT_TABLE()
33
34wxApp::wxApp()
35{
36}
37
38wxApp::~wxApp()
39{
40}
41
b3c86150
VS
42bool 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
56void wxApp::CleanUp()
57{
58 wxAppBase::CleanUp();
59
52c8d32a 60 wxIDirectFB::CleanUp();
b3c86150
VS
61}
62
63//-----------------------------------------------------------------------------
64// display mode
65//-----------------------------------------------------------------------------
66
67static wxVideoMode GetCurrentVideoMode()
68{
69 wxVideoMode m;
70
a5b31f4e 71 wxIDirectFBSurfacePtr surface(wxIDirectFB::Get()->GetPrimarySurface());
b3c86150
VS
72 if ( !surface )
73 return m; // invalid
74
52c8d32a 75 surface->GetSize(&m.w, &m.h);
a5b31f4e 76 m.bpp = surface->GetDepth();
b3c86150
VS
77
78 return m;
79}
80
81wxVideoMode wxApp::GetDisplayMode() const
82{
83 if ( !m_videoMode.IsOk() )
84 wxConstCast(this, wxApp)->m_videoMode = GetCurrentVideoMode();
85
86 return m_videoMode;
87}
88
89bool wxApp::SetDisplayMode(const wxVideoMode& mode)
90{
52c8d32a 91 if ( !wxIDirectFB::Get()->SetVideoMode(mode.w, mode.h, mode.bpp) )
b3c86150
VS
92 return false;
93
94 m_videoMode = mode;
95 return true;
96}
97
98//-----------------------------------------------------------------------------
99// events processing related
100//-----------------------------------------------------------------------------
101
102void wxApp::WakeUpIdle()
103{
104#if wxUSE_THREADS
105 if (!wxThread::IsMain())
106 wxMutexGuiEnter();
107#endif
108
109 wxEventLoop::GetActive()->WakeUp();
110
111#if wxUSE_THREADS
112 if (!wxThread::IsMain())
113 wxMutexGuiLeave();
114#endif
115}
116
117
118bool wxApp::Yield(bool onlyIfNeeded)
119{
120#if wxUSE_THREADS
121 if ( !wxThread::IsMain() )
122 return true; // can't process events from other threads
123#endif // wxUSE_THREADS
124
125 static bool s_inYield = false;
126
127 if ( s_inYield )
128 {
129 if ( !onlyIfNeeded )
130 {
131 wxFAIL_MSG( wxT("wxYield called recursively" ) );
132 }
133
134 return false;
135 }
136
137 s_inYield = true;
138
139 wxLog::Suspend();
140
141 if ( wxEventLoop::GetActive() )
142 {
143 while (wxEventLoop::GetActive()->Pending())
144 wxEventLoop::GetActive()->Dispatch();
145 }
146
147 // it's necessary to call ProcessIdle() to update the frames sizes which
148 // might have been changed (it also will update other things set from
149 // OnUpdateUI() which is a nice (and desired) side effect)
150 while ( ProcessIdle() ) {}
151
152 wxLog::Resume();
153
154 s_inYield = false;
155
156 return true;
157}