]>
Commit | Line | Data |
---|---|---|
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 | 39 | WX_DEFINE_OBJARRAY(wxArrayVideoModes) |
c6985199 VZ |
40 | |
41 | const 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 | |
52 | static wxDisplayFactory *gs_factory = NULL; | |
53 | ||
54 | // ---------------------------------------------------------------------------- | |
55 | // wxDisplayImplSingle: trivial implementation working for main display only | |
56 | // ---------------------------------------------------------------------------- | |
57 | ||
58 | class WXDLLEXPORT wxDisplayImplSingle : public wxDisplayImpl | |
59 | { | |
60 | public: | |
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 | ||
95 | class wxDisplayModule : public wxModule | |
96 | { | |
97 | public: | |
98 | virtual bool OnInit() { return true; } | |
99 | virtual void OnExit() | |
100 | { | |
5276b0a5 | 101 | wxDELETE(gs_factory); |
ef1717a9 VZ |
102 | } |
103 | ||
104 | DECLARE_DYNAMIC_CLASS(wxDisplayModule) | |
105 | }; | |
106 | ||
107 | IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule, wxModule) | |
108 | ||
c6985199 | 109 | // ============================================================================ |
ef1717a9 | 110 | // wxDisplay implementation |
c6985199 VZ |
111 | // ============================================================================ |
112 | ||
ef1717a9 VZ |
113 | // ---------------------------------------------------------------------------- |
114 | // ctor/dtor | |
115 | // ---------------------------------------------------------------------------- | |
116 | ||
4e675101 | 117 | wxDisplay::wxDisplay(unsigned n) |
c6985199 | 118 | { |
ef1717a9 | 119 | wxASSERT_MSG( n < GetCount(), |
c6985199 | 120 | wxT("An invalid index was passed to wxDisplay") ); |
ef1717a9 VZ |
121 | |
122 | m_impl = Factory().CreateDisplay(n); | |
123 | } | |
124 | ||
125 | wxDisplay::~wxDisplay() | |
126 | { | |
127 | delete m_impl; | |
128 | } | |
129 | ||
130 | // ---------------------------------------------------------------------------- | |
131 | // static functions forwarded to wxDisplayFactory | |
132 | // ---------------------------------------------------------------------------- | |
133 | ||
4e675101 | 134 | /* static */ unsigned wxDisplay::GetCount() |
ef1717a9 VZ |
135 | { |
136 | return Factory().GetCount(); | |
c6985199 VZ |
137 | } |
138 | ||
ef1717a9 VZ |
139 | /* static */ int wxDisplay::GetFromPoint(const wxPoint& pt) |
140 | { | |
141 | return Factory().GetFromPoint(pt); | |
142 | } | |
dae6a419 | 143 | |
1e93d595 | 144 | /* static */ int wxDisplay::GetFromWindow(const wxWindow *window) |
dae6a419 | 145 | { |
9a83f860 | 146 | wxCHECK_MSG( window, wxNOT_FOUND, wxT("invalid window") ); |
dae6a419 | 147 | |
ef1717a9 VZ |
148 | return Factory().GetFromWindow(window); |
149 | } | |
150 | ||
151 | // ---------------------------------------------------------------------------- | |
152 | // functions forwarded to wxDisplayImpl | |
153 | // ---------------------------------------------------------------------------- | |
154 | ||
155 | wxRect wxDisplay::GetGeometry() const | |
156 | { | |
9a83f860 | 157 | wxCHECK_MSG( IsOk(), wxRect(), wxT("invalid wxDisplay object") ); |
ef1717a9 VZ |
158 | |
159 | return m_impl->GetGeometry(); | |
160 | } | |
161 | ||
6c5d6291 VZ |
162 | wxRect wxDisplay::GetClientArea() const |
163 | { | |
9a83f860 | 164 | wxCHECK_MSG( IsOk(), wxRect(), wxT("invalid wxDisplay object") ); |
6c5d6291 VZ |
165 | |
166 | return m_impl->GetClientArea(); | |
167 | } | |
168 | ||
ef1717a9 VZ |
169 | wxString wxDisplay::GetName() const |
170 | { | |
9a83f860 | 171 | wxCHECK_MSG( IsOk(), wxString(), wxT("invalid wxDisplay object") ); |
ef1717a9 VZ |
172 | |
173 | return m_impl->GetName(); | |
174 | } | |
175 | ||
176 | bool wxDisplay::IsPrimary() const | |
177 | { | |
178 | return m_impl && m_impl->GetIndex() == 0; | |
179 | } | |
180 | ||
181 | #if wxUSE_DISPLAY | |
182 | ||
183 | wxArrayVideoModes wxDisplay::GetModes(const wxVideoMode& mode) const | |
184 | { | |
9a83f860 | 185 | wxCHECK_MSG( IsOk(), wxArrayVideoModes(), wxT("invalid wxDisplay object") ); |
ef1717a9 VZ |
186 | |
187 | return m_impl->GetModes(mode); | |
188 | } | |
189 | ||
190 | wxVideoMode wxDisplay::GetCurrentMode() const | |
191 | { | |
9a83f860 | 192 | wxCHECK_MSG( IsOk(), wxVideoMode(), wxT("invalid wxDisplay object") ); |
ef1717a9 VZ |
193 | |
194 | return m_impl->GetCurrentMode(); | |
195 | } | |
196 | ||
197 | bool wxDisplay::ChangeMode(const wxVideoMode& mode) | |
198 | { | |
9a83f860 | 199 | wxCHECK_MSG( IsOk(), false, wxT("invalid wxDisplay object") ); |
ef1717a9 VZ |
200 | |
201 | return m_impl->ChangeMode(mode); | |
202 | } | |
203 | ||
b0f76951 | 204 | #endif // wxUSE_DISPLAY |
ef1717a9 VZ |
205 | |
206 | // ---------------------------------------------------------------------------- | |
207 | // static functions implementation | |
208 | // ---------------------------------------------------------------------------- | |
209 | ||
210 | // if wxUSE_DISPLAY == 1 this is implemented in port-specific code | |
211 | #if !wxUSE_DISPLAY | |
212 | ||
213 | /* static */ wxDisplayFactory *wxDisplay::CreateFactory() | |
214 | { | |
215 | return new wxDisplayFactorySingle; | |
216 | } | |
217 | ||
218 | #endif // !wxUSE_DISPLAY | |
219 | ||
220 | /* static */ wxDisplayFactory& wxDisplay::Factory() | |
221 | { | |
222 | if ( !gs_factory ) | |
223 | { | |
224 | gs_factory = CreateFactory(); | |
225 | } | |
226 | ||
227 | return *gs_factory; | |
228 | } | |
229 | ||
230 | // ============================================================================ | |
231 | // wxDisplayFactory implementation | |
232 | // ============================================================================ | |
233 | ||
1e93d595 | 234 | int wxDisplayFactory::GetFromWindow(const wxWindow *window) |
ef1717a9 VZ |
235 | { |
236 | // consider that the window belongs to the display containing its centre | |
dae6a419 VZ |
237 | const wxRect r(window->GetRect()); |
238 | return GetFromPoint(wxPoint(r.x + r.width/2, r.y + r.height/2)); | |
239 | } | |
240 | ||
ef1717a9 VZ |
241 | // ============================================================================ |
242 | // wxDisplayFactorySingle implementation | |
243 | // ============================================================================ | |
244 | ||
245 | /* static */ | |
4e675101 | 246 | wxDisplayImpl *wxDisplayFactorySingle::CreateDisplay(unsigned n) |
ef1717a9 VZ |
247 | { |
248 | // we recognize the main display only | |
249 | return n != 0 ? NULL : new wxDisplayImplSingle; | |
250 | } | |
251 | ||
252 | int wxDisplayFactorySingle::GetFromPoint(const wxPoint& pt) | |
253 | { | |
254 | if ( pt.x >= 0 && pt.y >= 0 ) | |
255 | { | |
256 | int w, h; | |
257 | wxDisplaySize(&w, &h); | |
258 | ||
259 | if ( pt.x < w && pt.y < h ) | |
260 | return 0; | |
261 | } | |
262 | ||
263 | // the point is outside of the screen | |
264 | return wxNOT_FOUND; | |
265 | } |