]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/dpycmn.cpp
Workaround for #15404: wxRichTextCtrl: caret does not disappear when focus is lost...
[wxWidgets.git] / src / common / dpycmn.cpp
... / ...
CommitLineData
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/common/dpycmn.cpp
3// Purpose: wxDisplay and wxDisplayImplSingle implementation
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 01.03.03
7// Copyright: (c) 2003-2006 Vadim Zeitlin <vadim@wxwindows.org>
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#ifndef WX_PRECOMP
27 #include "wx/gdicmn.h"
28 #include "wx/window.h"
29 #include "wx/module.h"
30#endif //WX_PRECOMP
31
32#include "wx/display.h"
33#include "wx/display_impl.h"
34
35#if wxUSE_DISPLAY
36
37#include "wx/arrimpl.cpp"
38WX_DEFINE_OBJARRAY(wxArrayVideoModes)
39
40const wxVideoMode wxDefaultVideoMode;
41
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
69 virtual wxRect GetClientArea() const { return wxGetClientDisplayRect(); }
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 wxDECLARE_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 wxDELETE(gs_factory);
101 }
102
103 DECLARE_DYNAMIC_CLASS(wxDisplayModule)
104};
105
106IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule, wxModule)
107
108// ============================================================================
109// wxDisplay implementation
110// ============================================================================
111
112// ----------------------------------------------------------------------------
113// ctor/dtor
114// ----------------------------------------------------------------------------
115
116wxDisplay::wxDisplay(unsigned n)
117{
118 wxASSERT_MSG( n < GetCount(),
119 wxT("An invalid index was passed to wxDisplay") );
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
133/* static */ unsigned wxDisplay::GetCount()
134{
135 return Factory().GetCount();
136}
137
138/* static */ int wxDisplay::GetFromPoint(const wxPoint& pt)
139{
140 return Factory().GetFromPoint(pt);
141}
142
143/* static */ int wxDisplay::GetFromWindow(const wxWindow *window)
144{
145 wxCHECK_MSG( window, wxNOT_FOUND, wxT("invalid window") );
146
147 return Factory().GetFromWindow(window);
148}
149
150// ----------------------------------------------------------------------------
151// functions forwarded to wxDisplayImpl
152// ----------------------------------------------------------------------------
153
154wxRect wxDisplay::GetGeometry() const
155{
156 wxCHECK_MSG( IsOk(), wxRect(), wxT("invalid wxDisplay object") );
157
158 return m_impl->GetGeometry();
159}
160
161wxRect wxDisplay::GetClientArea() const
162{
163 wxCHECK_MSG( IsOk(), wxRect(), wxT("invalid wxDisplay object") );
164
165 return m_impl->GetClientArea();
166}
167
168wxString wxDisplay::GetName() const
169{
170 wxCHECK_MSG( IsOk(), wxString(), wxT("invalid wxDisplay object") );
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{
184 wxCHECK_MSG( IsOk(), wxArrayVideoModes(), wxT("invalid wxDisplay object") );
185
186 return m_impl->GetModes(mode);
187}
188
189wxVideoMode wxDisplay::GetCurrentMode() const
190{
191 wxCHECK_MSG( IsOk(), wxVideoMode(), wxT("invalid wxDisplay object") );
192
193 return m_impl->GetCurrentMode();
194}
195
196bool wxDisplay::ChangeMode(const wxVideoMode& mode)
197{
198 wxCHECK_MSG( IsOk(), false, wxT("invalid wxDisplay object") );
199
200 return m_impl->ChangeMode(mode);
201}
202
203#endif // wxUSE_DISPLAY
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
233int wxDisplayFactory::GetFromWindow(const wxWindow *window)
234{
235 // consider that the window belongs to the display containing its centre
236 const wxRect r(window->GetScreenRect());
237 return GetFromPoint(wxPoint(r.x + r.width/2, r.y + r.height/2));
238}
239
240// ============================================================================
241// wxDisplayFactorySingle implementation
242// ============================================================================
243
244/* static */
245wxDisplayImpl *wxDisplayFactorySingle::CreateDisplay(unsigned n)
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}