]> git.saurik.com Git - wxWidgets.git/blame - src/common/dpycmn.cpp
extend wxXLocale with wxStrto[d,l,ul] functions; make wxXLocale::Init() a little...
[wxWidgets.git] / src / common / dpycmn.cpp
CommitLineData
c6985199 1///////////////////////////////////////////////////////////////////////////////
e77138c0 2// Name: src/common/dpycmn.cpp
ef1717a9 3// Purpose: wxDisplay and wxDisplayImplSingle implementation
c6985199
VZ
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 01.03.03
7// RCS-ID: $Id$
ef1717a9 8// Copyright: (c) 2003-2006 Vadim Zeitlin <vadim@wxwindows.org>
65571936 9// License: wxWindows licence
c6985199
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
c6985199
VZ
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
e77138c0
WS
27#ifndef WX_PRECOMP
28 #include "wx/gdicmn.h"
29 #include "wx/window.h"
02761f6c 30 #include "wx/module.h"
e77138c0
WS
31#endif //WX_PRECOMP
32
33#include "wx/display.h"
ef1717a9 34#include "wx/display_impl.h"
ef1717a9
VZ
35
36#if wxUSE_DISPLAY
e77138c0 37
c6985199 38#include "wx/arrimpl.cpp"
28c91b7d 39WX_DEFINE_OBJARRAY(wxArrayVideoModes)
c6985199
VZ
40
41const wxVideoMode wxDefaultVideoMode;
42
ef1717a9
VZ
43#endif // wxUSE_DISPLAY
44
45// ----------------------------------------------------------------------------
46// globals
47// ----------------------------------------------------------------------------
48
49// the factory object used by wxDisplay
50//
51// created on demand and destroyed by wxDisplayModule
52static wxDisplayFactory *gs_factory = NULL;
53
54// ----------------------------------------------------------------------------
55// wxDisplayImplSingle: trivial implementation working for main display only
56// ----------------------------------------------------------------------------
57
58class WXDLLEXPORT wxDisplayImplSingle : public wxDisplayImpl
59{
60public:
61 wxDisplayImplSingle() : wxDisplayImpl(0) { }
62
63 virtual wxRect GetGeometry() const
64 {
65 wxRect r;
66 wxDisplaySize(&r.width, &r.height);
67 return r;
68 }
69
6c5d6291
VZ
70 virtual wxRect GetClientArea() const { return wxGetClientDisplayRect(); }
71
ef1717a9
VZ
72 virtual wxString GetName() const { return wxString(); }
73
74#if wxUSE_DISPLAY
75 // no video modes support for us, provide just the stubs
76
77 virtual wxArrayVideoModes GetModes(const wxVideoMode& WXUNUSED(mode)) const
78 {
79 return wxArrayVideoModes();
80 }
81
82 virtual wxVideoMode GetCurrentMode() const { return wxVideoMode(); }
83
84 virtual bool ChangeMode(const wxVideoMode& WXUNUSED(mode)) { return false; }
85#endif // wxUSE_DISPLAY
86
87
c0c133e1 88 wxDECLARE_NO_COPY_CLASS(wxDisplayImplSingle);
ef1717a9
VZ
89};
90
91// ----------------------------------------------------------------------------
92// wxDisplayModule is used to cleanup gs_factory
93// ----------------------------------------------------------------------------
94
95class wxDisplayModule : public wxModule
96{
97public:
98 virtual bool OnInit() { return true; }
99 virtual void OnExit()
100 {
101 if ( gs_factory )
102 {
103 delete gs_factory;
104 gs_factory = NULL;
105 }
106 }
107
108 DECLARE_DYNAMIC_CLASS(wxDisplayModule)
109};
110
111IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule, wxModule)
112
c6985199 113// ============================================================================
ef1717a9 114// wxDisplay implementation
c6985199
VZ
115// ============================================================================
116
ef1717a9
VZ
117// ----------------------------------------------------------------------------
118// ctor/dtor
119// ----------------------------------------------------------------------------
120
4e675101 121wxDisplay::wxDisplay(unsigned n)
c6985199 122{
ef1717a9 123 wxASSERT_MSG( n < GetCount(),
c6985199 124 wxT("An invalid index was passed to wxDisplay") );
ef1717a9
VZ
125
126 m_impl = Factory().CreateDisplay(n);
127}
128
129wxDisplay::~wxDisplay()
130{
131 delete m_impl;
132}
133
134// ----------------------------------------------------------------------------
135// static functions forwarded to wxDisplayFactory
136// ----------------------------------------------------------------------------
137
4e675101 138/* static */ unsigned wxDisplay::GetCount()
ef1717a9
VZ
139{
140 return Factory().GetCount();
c6985199
VZ
141}
142
ef1717a9
VZ
143/* static */ int wxDisplay::GetFromPoint(const wxPoint& pt)
144{
145 return Factory().GetFromPoint(pt);
146}
dae6a419 147
1e93d595 148/* static */ int wxDisplay::GetFromWindow(const wxWindow *window)
dae6a419 149{
ef1717a9 150 wxCHECK_MSG( window, wxNOT_FOUND, _T("invalid window") );
dae6a419 151
ef1717a9
VZ
152 return Factory().GetFromWindow(window);
153}
154
155// ----------------------------------------------------------------------------
156// functions forwarded to wxDisplayImpl
157// ----------------------------------------------------------------------------
158
159wxRect wxDisplay::GetGeometry() const
160{
161 wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
162
163 return m_impl->GetGeometry();
164}
165
6c5d6291
VZ
166wxRect wxDisplay::GetClientArea() const
167{
168 wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
169
170 return m_impl->GetClientArea();
171}
172
ef1717a9
VZ
173wxString wxDisplay::GetName() const
174{
175 wxCHECK_MSG( IsOk(), wxString(), _T("invalid wxDisplay object") );
176
177 return m_impl->GetName();
178}
179
180bool wxDisplay::IsPrimary() const
181{
182 return m_impl && m_impl->GetIndex() == 0;
183}
184
185#if wxUSE_DISPLAY
186
187wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const
188{
189 wxCHECK_MSG( IsOk(), wxArrayVideoModes(), _T("invalid wxDisplay object") );
190
191 return m_impl->GetModes(mode);
192}
193
194wxVideoMode wxDisplay::GetCurrentMode() const
195{
196 wxCHECK_MSG( IsOk(), wxVideoMode(), _T("invalid wxDisplay object") );
197
198 return m_impl->GetCurrentMode();
199}
200
201bool wxDisplay::ChangeMode(const wxVideoMode& mode)
202{
203 wxCHECK_MSG( IsOk(), false, _T("invalid wxDisplay object") );
204
205 return m_impl->ChangeMode(mode);
206}
207
b0f76951 208#endif // wxUSE_DISPLAY
ef1717a9
VZ
209
210// ----------------------------------------------------------------------------
211// static functions implementation
212// ----------------------------------------------------------------------------
213
214// if wxUSE_DISPLAY == 1 this is implemented in port-specific code
215#if !wxUSE_DISPLAY
216
217/* static */ wxDisplayFactory *wxDisplay::CreateFactory()
218{
219 return new wxDisplayFactorySingle;
220}
221
222#endif // !wxUSE_DISPLAY
223
224/* static */ wxDisplayFactory& wxDisplay::Factory()
225{
226 if ( !gs_factory )
227 {
228 gs_factory = CreateFactory();
229 }
230
231 return *gs_factory;
232}
233
234// ============================================================================
235// wxDisplayFactory implementation
236// ============================================================================
237
1e93d595 238int wxDisplayFactory::GetFromWindow(const wxWindow *window)
ef1717a9
VZ
239{
240 // consider that the window belongs to the display containing its centre
dae6a419
VZ
241 const wxRect r(window->GetRect());
242 return GetFromPoint(wxPoint(r.x + r.width/2, r.y + r.height/2));
243}
244
ef1717a9
VZ
245// ============================================================================
246// wxDisplayFactorySingle implementation
247// ============================================================================
248
249/* static */
4e675101 250wxDisplayImpl *wxDisplayFactorySingle::CreateDisplay(unsigned n)
ef1717a9
VZ
251{
252 // we recognize the main display only
253 return n != 0 ? NULL : new wxDisplayImplSingle;
254}
255
256int wxDisplayFactorySingle::GetFromPoint(const wxPoint& pt)
257{
258 if ( pt.x >= 0 && pt.y >= 0 )
259 {
260 int w, h;
261 wxDisplaySize(&w, &h);
262
263 if ( pt.x < w && pt.y < h )
264 return 0;
265 }
266
267 // the point is outside of the screen
268 return wxNOT_FOUND;
269}