]> git.saurik.com Git - wxWidgets.git/blob - src/common/dpycmn.cpp
Have wxGenericListCtrl record and store the selection state of each column, and on...
[wxWidgets.git] / src / common / dpycmn.cpp
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 // RCS-ID: $Id$
8 // Copyright: (c) 2003-2006 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/gdicmn.h"
29 #include "wx/window.h"
30 #include "wx/module.h"
31 #endif //WX_PRECOMP
32
33 #include "wx/display.h"
34 #include "wx/display_impl.h"
35
36 #if wxUSE_DISPLAY
37
38 #include "wx/arrimpl.cpp"
39 WX_DEFINE_OBJARRAY(wxArrayVideoModes)
40
41 const wxVideoMode wxDefaultVideoMode;
42
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
70 virtual wxRect GetClientArea() const { return wxGetClientDisplayRect(); }
71
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
88 DECLARE_NO_COPY_CLASS(wxDisplayImplSingle)
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 {
101 if ( gs_factory )
102 {
103 delete gs_factory;
104 gs_factory = NULL;
105 }
106 }
107
108 DECLARE_DYNAMIC_CLASS(wxDisplayModule)
109 };
110
111 IMPLEMENT_DYNAMIC_CLASS(wxDisplayModule, wxModule)
112
113 // ============================================================================
114 // wxDisplay implementation
115 // ============================================================================
116
117 // ----------------------------------------------------------------------------
118 // ctor/dtor
119 // ----------------------------------------------------------------------------
120
121 wxDisplay::wxDisplay(unsigned n)
122 {
123 wxASSERT_MSG( n < GetCount(),
124 wxT("An invalid index was passed to wxDisplay") );
125
126 m_impl = Factory().CreateDisplay(n);
127 }
128
129 wxDisplay::~wxDisplay()
130 {
131 delete m_impl;
132 }
133
134 // ----------------------------------------------------------------------------
135 // static functions forwarded to wxDisplayFactory
136 // ----------------------------------------------------------------------------
137
138 /* static */ unsigned wxDisplay::GetCount()
139 {
140 return Factory().GetCount();
141 }
142
143 /* static */ int wxDisplay::GetFromPoint(const wxPoint& pt)
144 {
145 return Factory().GetFromPoint(pt);
146 }
147
148 /* static */ int wxDisplay::GetFromWindow(wxWindow *window)
149 {
150 wxCHECK_MSG( window, wxNOT_FOUND, _T("invalid window") );
151
152 return Factory().GetFromWindow(window);
153 }
154
155 // ----------------------------------------------------------------------------
156 // functions forwarded to wxDisplayImpl
157 // ----------------------------------------------------------------------------
158
159 wxRect wxDisplay::GetGeometry() const
160 {
161 wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
162
163 return m_impl->GetGeometry();
164 }
165
166 wxRect wxDisplay::GetClientArea() const
167 {
168 wxCHECK_MSG( IsOk(), wxRect(), _T("invalid wxDisplay object") );
169
170 return m_impl->GetClientArea();
171 }
172
173 wxString wxDisplay::GetName() const
174 {
175 wxCHECK_MSG( IsOk(), wxString(), _T("invalid wxDisplay object") );
176
177 return m_impl->GetName();
178 }
179
180 bool wxDisplay::IsPrimary() const
181 {
182 return m_impl && m_impl->GetIndex() == 0;
183 }
184
185 #if wxUSE_DISPLAY
186
187 wxArrayVideoModes 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
194 wxVideoMode wxDisplay::GetCurrentMode() const
195 {
196 wxCHECK_MSG( IsOk(), wxVideoMode(), _T("invalid wxDisplay object") );
197
198 return m_impl->GetCurrentMode();
199 }
200
201 bool wxDisplay::ChangeMode(const wxVideoMode& mode)
202 {
203 wxCHECK_MSG( IsOk(), false, _T("invalid wxDisplay object") );
204
205 return m_impl->ChangeMode(mode);
206 }
207
208 #endif // wxUSE_DIRECTDRAW
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
238 int wxDisplayFactory::GetFromWindow(wxWindow *window)
239 {
240 // consider that the window belongs to the display containing its centre
241 const wxRect r(window->GetRect());
242 return GetFromPoint(wxPoint(r.x + r.width/2, r.y + r.height/2));
243 }
244
245 // ============================================================================
246 // wxDisplayFactorySingle implementation
247 // ============================================================================
248
249 /* static */
250 wxDisplayImpl *wxDisplayFactorySingle::CreateDisplay(unsigned n)
251 {
252 // we recognize the main display only
253 return n != 0 ? NULL : new wxDisplayImplSingle;
254 }
255
256 int 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 }