]> git.saurik.com Git - wxWidgets.git/blame - src/common/dpycmn.cpp
Albanian translation added (Besnik Bleta)
[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"
30#endif //WX_PRECOMP
31
32#include "wx/display.h"
ef1717a9
VZ
33#include "wx/display_impl.h"
34#include "wx/module.h"
35#include "wx/gdicmn.h" // for wxDisplaySize()
36
37#if wxUSE_DISPLAY
e77138c0 38
c6985199 39#include "wx/arrimpl.cpp"
28c91b7d 40WX_DEFINE_OBJARRAY(wxArrayVideoModes)
c6985199
VZ
41
42const wxVideoMode wxDefaultVideoMode;
43
ef1717a9
VZ
44#endif // wxUSE_DISPLAY
45
46// ----------------------------------------------------------------------------
47// globals
48// ----------------------------------------------------------------------------
49
50// the factory object used by wxDisplay
51//
52// created on demand and destroyed by wxDisplayModule
53static wxDisplayFactory *gs_factory = NULL;
54
55// ----------------------------------------------------------------------------
56// wxDisplayImplSingle: trivial implementation working for main display only
57// ----------------------------------------------------------------------------
58
59class WXDLLEXPORT wxDisplayImplSingle : public wxDisplayImpl
60{
61public:
62 wxDisplayImplSingle() : wxDisplayImpl(0) { }
63
64 virtual wxRect GetGeometry() const
65 {
66 wxRect r;
67 wxDisplaySize(&r.width, &r.height);
68 return r;
69 }
70
71 virtual wxString GetName() const { return wxString(); }
72
73#if wxUSE_DISPLAY
74 // no video modes support for us, provide just the stubs
75
76 virtual wxArrayVideoModes GetModes(const wxVideoMode& WXUNUSED(mode)) const
77 {
78 return wxArrayVideoModes();
79 }
80
81 virtual wxVideoMode GetCurrentMode() const { return wxVideoMode(); }
82
83 virtual bool ChangeMode(const wxVideoMode& WXUNUSED(mode)) { return false; }
84#endif // wxUSE_DISPLAY
85
86
87 DECLARE_NO_COPY_CLASS(wxDisplayImplSingle)
88};
89
90// ----------------------------------------------------------------------------
91// wxDisplayModule is used to cleanup gs_factory
92// ----------------------------------------------------------------------------
93
94class wxDisplayModule : public wxModule
95{
96public:
97 virtual bool OnInit() { return true; }
98 virtual void OnExit()
99 {
100 if ( gs_factory )
101 {
102 delete gs_factory;
103 gs_factory = NULL;
104 }
105 }
106
107 DECLARE_DYNAMIC_CLASS(wxDisplayModule)
108};
109
110IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule, wxModule)
111
c6985199 112// ============================================================================
ef1717a9 113// wxDisplay implementation
c6985199
VZ
114// ============================================================================
115
ef1717a9
VZ
116// ----------------------------------------------------------------------------
117// ctor/dtor
118// ----------------------------------------------------------------------------
119
120wxDisplay::wxDisplay(size_t n)
c6985199 121{
ef1717a9 122 wxASSERT_MSG( n < GetCount(),
c6985199 123 wxT("An invalid index was passed to wxDisplay") );
ef1717a9
VZ
124
125 m_impl = Factory().CreateDisplay(n);
126}
127
128wxDisplay::~wxDisplay()
129{
130 delete m_impl;
131}
132
133// ----------------------------------------------------------------------------
134// static functions forwarded to wxDisplayFactory
135// ----------------------------------------------------------------------------
136
137/* static */ size_t wxDisplay::GetCount()
138{
139 return Factory().GetCount();
c6985199
VZ
140}
141
ef1717a9
VZ
142/* static */ int wxDisplay::GetFromPoint(const wxPoint& pt)
143{
144 return Factory().GetFromPoint(pt);
145}
dae6a419 146
ef1717a9 147/* static */ int wxDisplay::GetFromWindow(wxWindow *window)
dae6a419 148{
ef1717a9 149 wxCHECK_MSG( window, wxNOT_FOUND, _T("invalid window") );
dae6a419 150
ef1717a9
VZ
151 return Factory().GetFromWindow(window);
152}
153
154// ----------------------------------------------------------------------------
155// functions forwarded to wxDisplayImpl
156// ----------------------------------------------------------------------------
157
158wxRect wxDisplay::GetGeometry() const
159{
160 wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
161
162 return m_impl->GetGeometry();
163}
164
165wxString wxDisplay::GetName() const
166{
167 wxCHECK_MSG( IsOk(), wxString(), _T("invalid wxDisplay object") );
168
169 return m_impl->GetName();
170}
171
172bool wxDisplay::IsPrimary() const
173{
174 return m_impl && m_impl->GetIndex() == 0;
175}
176
177#if wxUSE_DISPLAY
178
179wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const
180{
181 wxCHECK_MSG( IsOk(), wxArrayVideoModes(), _T("invalid wxDisplay object") );
182
183 return m_impl->GetModes(mode);
184}
185
186wxVideoMode wxDisplay::GetCurrentMode() const
187{
188 wxCHECK_MSG( IsOk(), wxVideoMode(), _T("invalid wxDisplay object") );
189
190 return m_impl->GetCurrentMode();
191}
192
193bool wxDisplay::ChangeMode(const wxVideoMode& mode)
194{
195 wxCHECK_MSG( IsOk(), false, _T("invalid wxDisplay object") );
196
197 return m_impl->ChangeMode(mode);
198}
199
200#endif // wxUSE_DIRECTDRAW
201
202// ----------------------------------------------------------------------------
203// static functions implementation
204// ----------------------------------------------------------------------------
205
206// if wxUSE_DISPLAY == 1 this is implemented in port-specific code
207#if !wxUSE_DISPLAY
208
209/* static */ wxDisplayFactory *wxDisplay::CreateFactory()
210{
211 return new wxDisplayFactorySingle;
212}
213
214#endif // !wxUSE_DISPLAY
215
216/* static */ wxDisplayFactory& wxDisplay::Factory()
217{
218 if ( !gs_factory )
219 {
220 gs_factory = CreateFactory();
221 }
222
223 return *gs_factory;
224}
225
226// ============================================================================
227// wxDisplayFactory implementation
228// ============================================================================
229
230int wxDisplayFactory::GetFromWindow(wxWindow *window)
231{
232 // consider that the window belongs to the display containing its centre
dae6a419
VZ
233 const wxRect r(window->GetRect());
234 return GetFromPoint(wxPoint(r.x + r.width/2, r.y + r.height/2));
235}
236
ef1717a9
VZ
237// ============================================================================
238// wxDisplayFactorySingle implementation
239// ============================================================================
240
241/* static */
242wxDisplayImpl *wxDisplayFactorySingle::CreateDisplay(size_t n)
243{
244 // we recognize the main display only
245 return n != 0 ? NULL : new wxDisplayImplSingle;
246}
247
248int wxDisplayFactorySingle::GetFromPoint(const wxPoint& pt)
249{
250 if ( pt.x >= 0 && pt.y >= 0 )
251 {
252 int w, h;
253 wxDisplaySize(&w, &h);
254
255 if ( pt.x < w && pt.y < h )
256 return 0;
257 }
258
259 // the point is outside of the screen
260 return wxNOT_FOUND;
261}
dae6a419 262