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