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