]>
Commit | Line | Data |
---|---|---|
a536e411 | 1 | ///////////////////////////////////////////////////////////////////////////// |
2ad495fb | 2 | // Name: src/msw/display.cpp |
a536e411 | 3 | // Purpose: MSW Implementation of wxDisplay class |
fd921f35 VZ |
4 | // Author: Royce Mitchell III, Vadim Zeitlin |
5 | // Modified by: Ryan Norton (IsPrimary override) | |
a536e411 JS |
6 | // Created: 06/21/02 |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
fd921f35 | 9 | // Copyright: (c) 2002-2006 wxWidgets team |
65571936 | 10 | // Licence: wxWindows licence |
a536e411 JS |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
13 | // =========================================================================== | |
14 | // declarations | |
15 | // =========================================================================== | |
16 | ||
17 | // --------------------------------------------------------------------------- | |
18 | // headers | |
19 | // --------------------------------------------------------------------------- | |
20 | ||
a536e411 JS |
21 | // For compilers that support precompilation, includes "wx.h". |
22 | #include "wx/wxprec.h" | |
23 | ||
24 | #ifdef __BORLANDC__ | |
25 | #pragma hdrstop | |
26 | #endif | |
27 | ||
28 | #if wxUSE_DISPLAY | |
29 | ||
7212d155 PC |
30 | #include "wx/display.h" |
31 | ||
a536e411 | 32 | #ifndef WX_PRECOMP |
ad9835c9 WS |
33 | #include "wx/dynarray.h" |
34 | #include "wx/app.h" | |
35 | #include "wx/frame.h" | |
a536e411 JS |
36 | #endif |
37 | ||
8585e2b5 | 38 | #include "wx/dynload.h" |
ef1717a9 | 39 | #include "wx/sysopt.h" |
8585e2b5 | 40 | |
ef1717a9 | 41 | #include "wx/display_impl.h" |
52778e00 | 42 | #include "wx/msw/wrapwin.h" |
7212d155 | 43 | #include "wx/msw/missing.h" |
142ae7b3 | 44 | #include "wx/msw/private.h" |
a536e411 | 45 | |
2ad495fb | 46 | #ifndef __WXWINCE__ |
01c54165 | 47 | // Older versions of windef.h don't define HMONITOR. Unfortunately, we |
bcc1153a VZ |
48 | // can't directly test whether HMONITOR is defined or not in windef.h as |
49 | // it's not a macro but a typedef, so we test for an unrelated symbol which | |
50 | // is only defined in winuser.h if WINVER >= 0x0500 | |
51 | #if !defined(HMONITOR_DECLARED) && !defined(MNS_NOCHECK) | |
52 | DECLARE_HANDLE(HMONITOR); | |
e5570318 JS |
53 | typedef BOOL(CALLBACK * MONITORENUMPROC )(HMONITOR, HDC, LPRECT, LPARAM); |
54 | typedef struct tagMONITORINFO | |
55 | { | |
56 | DWORD cbSize; | |
57 | RECT rcMonitor; | |
58 | RECT rcWork; | |
59 | DWORD dwFlags; | |
60 | } MONITORINFO, *LPMONITORINFO; | |
61 | typedef struct tagMONITORINFOEX : public tagMONITORINFO | |
62 | { | |
63 | TCHAR szDevice[CCHDEVICENAME]; | |
64 | } MONITORINFOEX, *LPMONITORINFOEX; | |
65 | #define MONITOR_DEFAULTTONULL 0x00000000 | |
66 | #define MONITOR_DEFAULTTOPRIMARY 0x00000001 | |
67 | #define MONITOR_DEFAULTTONEAREST 0x00000002 | |
ad9835c9 | 68 | #define MONITORINFOF_PRIMARY 0x00000001 |
bcc1153a VZ |
69 | #define HMONITOR_DECLARED |
70 | #endif | |
2ad495fb | 71 | #endif // !__WXWINCE__ |
a536e411 | 72 | |
d238d403 VZ |
73 | // display functions are found in different DLLs under WinCE and normal Win32 |
74 | #ifdef __WXWINCE__ | |
9a83f860 | 75 | static const wxChar displayDllName[] = wxT("coredll.dll"); |
d238d403 | 76 | #else |
9a83f860 | 77 | static const wxChar displayDllName[] = wxT("user32.dll"); |
d238d403 VZ |
78 | #endif |
79 | ||
a536e411 | 80 | // ---------------------------------------------------------------------------- |
06efac1f | 81 | // typedefs for dynamically loaded Windows functions |
a536e411 JS |
82 | // ---------------------------------------------------------------------------- |
83 | ||
8585e2b5 VZ |
84 | typedef LONG (WINAPI *ChangeDisplaySettingsEx_t)(LPCTSTR lpszDeviceName, |
85 | LPDEVMODE lpDevMode, | |
86 | HWND hwnd, | |
87 | DWORD dwFlags, | |
88 | LPVOID lParam); | |
a536e411 | 89 | |
01c54165 VZ |
90 | typedef BOOL (WINAPI *EnumDisplayMonitors_t)(HDC,LPCRECT,MONITORENUMPROC,LPARAM); |
91 | typedef HMONITOR (WINAPI *MonitorFromPoint_t)(POINT,DWORD); | |
92 | typedef HMONITOR (WINAPI *MonitorFromWindow_t)(HWND,DWORD); | |
93 | typedef BOOL (WINAPI *GetMonitorInfo_t)(HMONITOR,LPMONITORINFO); | |
94 | ||
ef1717a9 VZ |
95 | #ifndef __WXWINCE__ |
96 | // emulation of ChangeDisplaySettingsEx() for Win95 | |
97 | LONG WINAPI ChangeDisplaySettingsExForWin95(LPCTSTR WXUNUSED(lpszDeviceName), | |
98 | LPDEVMODE lpDevMode, | |
99 | HWND WXUNUSED(hwnd), | |
100 | DWORD dwFlags, | |
101 | LPVOID WXUNUSED(lParam)) | |
102 | { | |
103 | return ::ChangeDisplaySettings(lpDevMode, dwFlags); | |
104 | } | |
105 | #endif // !__WXWINCE__ | |
06efac1f | 106 | |
8585e2b5 | 107 | // ---------------------------------------------------------------------------- |
ef1717a9 | 108 | // display information classes |
8585e2b5 | 109 | // ---------------------------------------------------------------------------- |
a536e411 | 110 | |
ef1717a9 | 111 | struct wxDisplayInfo |
a536e411 | 112 | { |
ef1717a9 VZ |
113 | wxDisplayInfo(HMONITOR hmon = NULL) |
114 | { | |
115 | m_hmon = hmon; | |
116 | m_flags = (DWORD)-1; | |
117 | } | |
8585e2b5 | 118 | |
ef1717a9 | 119 | virtual ~wxDisplayInfo() { } |
06efac1f | 120 | |
ef1717a9 VZ |
121 | |
122 | // use GetMonitorInfo() to fill in all of our fields if needed (i.e. if it | |
123 | // hadn't been done before) | |
124 | void Initialize(); | |
125 | ||
126 | ||
127 | // handle of this monitor used by MonitorXXX() functions, never NULL | |
128 | HMONITOR m_hmon; | |
06efac1f | 129 | |
8585e2b5 | 130 | // the entire area of this monitor in virtual screen coordinates |
a536e411 | 131 | wxRect m_rect; |
8585e2b5 | 132 | |
6c5d6291 VZ |
133 | // the work or client area, i.e. the area available for the normal windows |
134 | wxRect m_rectClient; | |
135 | ||
8585e2b5 VZ |
136 | // the display device name for this monitor, empty initially and retrieved |
137 | // on demand by DoGetName() | |
138 | wxString m_devName; | |
139 | ||
ef1717a9 VZ |
140 | // the flags of this monitor, also used as initialization marker: if this |
141 | // is -1, GetMonitorInfo() hadn't been called yet | |
142 | DWORD m_flags; | |
8585e2b5 VZ |
143 | }; |
144 | ||
ef1717a9 | 145 | WX_DEFINE_ARRAY_PTR(wxDisplayInfo *, wxDisplayInfoArray); |
a536e411 | 146 | |
06efac1f | 147 | // ---------------------------------------------------------------------------- |
ef1717a9 | 148 | // common base class for all Win32 wxDisplayImpl versions |
06efac1f VZ |
149 | // ---------------------------------------------------------------------------- |
150 | ||
ef1717a9 | 151 | class wxDisplayImplWin32Base : public wxDisplayImpl |
01c54165 | 152 | { |
ef1717a9 | 153 | public: |
4e675101 | 154 | wxDisplayImplWin32Base(unsigned n, wxDisplayInfo& info) |
ef1717a9 VZ |
155 | : wxDisplayImpl(n), |
156 | m_info(info) | |
01c54165 | 157 | { |
01c54165 | 158 | } |
01c54165 | 159 | |
ef1717a9 | 160 | virtual wxRect GetGeometry() const; |
6c5d6291 | 161 | virtual wxRect GetClientArea() const; |
ef1717a9 VZ |
162 | virtual wxString GetName() const; |
163 | virtual bool IsPrimary() const; | |
06efac1f | 164 | |
ef1717a9 | 165 | virtual wxVideoMode GetCurrentMode() const; |
06efac1f | 166 | |
ef1717a9 VZ |
167 | protected: |
168 | // convert a DEVMODE to our wxVideoMode | |
169 | static wxVideoMode ConvertToVideoMode(const DEVMODE& dm) | |
170 | { | |
171 | // note that dmDisplayFrequency may be 0 or 1 meaning "standard one" | |
172 | // and although 0 is ok for us we don't want to return modes with 1hz | |
173 | // refresh | |
174 | return wxVideoMode(dm.dmPelsWidth, | |
175 | dm.dmPelsHeight, | |
176 | dm.dmBitsPerPel, | |
177 | dm.dmDisplayFrequency > 1 ? dm.dmDisplayFrequency : 0); | |
178 | } | |
179 | ||
180 | wxDisplayInfo& m_info; | |
181 | }; | |
a536e411 | 182 | |
8585e2b5 | 183 | // ---------------------------------------------------------------------------- |
ef1717a9 | 184 | // common base class for all Win32 wxDisplayFactory versions |
8585e2b5 VZ |
185 | // ---------------------------------------------------------------------------- |
186 | ||
ef1717a9 VZ |
187 | // functions dynamically bound by wxDisplayFactoryWin32Base::Initialize() |
188 | static MonitorFromPoint_t gs_MonitorFromPoint = NULL; | |
189 | static MonitorFromWindow_t gs_MonitorFromWindow = NULL; | |
190 | static GetMonitorInfo_t gs_GetMonitorInfo = NULL; | |
8585e2b5 | 191 | |
ef1717a9 VZ |
192 | class wxDisplayFactoryWin32Base : public wxDisplayFactory |
193 | { | |
194 | public: | |
195 | virtual ~wxDisplayFactoryWin32Base(); | |
8585e2b5 | 196 | |
ef1717a9 | 197 | bool IsOk() const { return !m_displays.empty(); } |
8585e2b5 | 198 | |
4e675101 | 199 | virtual unsigned GetCount() { return unsigned(m_displays.size()); } |
ef1717a9 | 200 | virtual int GetFromPoint(const wxPoint& pt); |
1e93d595 | 201 | virtual int GetFromWindow(const wxWindow *window); |
a536e411 | 202 | |
ef1717a9 VZ |
203 | protected: |
204 | // ctor checks if the current system supports multimon API and dynamically | |
205 | // bind the functions we need if this is the case and sets | |
206 | // ms_supportsMultimon if they're available | |
207 | wxDisplayFactoryWin32Base(); | |
a536e411 | 208 | |
ef1717a9 | 209 | // delete all m_displays elements: can be called from the derived class |
16e45865 VZ |
210 | // dtor if it is important to do this before destroying it, |
211 | // otherwise will be done by our dtor | |
ef1717a9 | 212 | void Clear(); |
06efac1f | 213 | |
ef1717a9 VZ |
214 | // find the monitor corresponding to the given handle, return wxNOT_FOUND |
215 | // if not found | |
216 | int FindDisplayFromHMONITOR(HMONITOR hmon) const; | |
06efac1f | 217 | |
06efac1f | 218 | |
ef1717a9 VZ |
219 | // flag indicating whether gs_MonitorXXX functions are available |
220 | static int ms_supportsMultimon; | |
06efac1f | 221 | |
ef1717a9 VZ |
222 | // the array containing information about all available displays, should be |
223 | // filled by the derived class ctors | |
224 | wxDisplayInfoArray m_displays; | |
06efac1f | 225 | |
06efac1f | 226 | |
c0c133e1 | 227 | wxDECLARE_NO_COPY_CLASS(wxDisplayFactoryWin32Base); |
ef1717a9 | 228 | }; |
06efac1f VZ |
229 | |
230 | // ---------------------------------------------------------------------------- | |
ef1717a9 | 231 | // wxDisplay implementation using Windows multi-monitor support functions |
06efac1f VZ |
232 | // ---------------------------------------------------------------------------- |
233 | ||
ef1717a9 | 234 | class wxDisplayImplMultimon : public wxDisplayImplWin32Base |
06efac1f | 235 | { |
ef1717a9 | 236 | public: |
4e675101 | 237 | wxDisplayImplMultimon(unsigned n, wxDisplayInfo& info) |
ef1717a9 VZ |
238 | : wxDisplayImplWin32Base(n, info) |
239 | { | |
240 | } | |
a536e411 | 241 | |
ef1717a9 VZ |
242 | virtual wxArrayVideoModes GetModes(const wxVideoMode& mode) const; |
243 | virtual bool ChangeMode(const wxVideoMode& mode); | |
a536e411 | 244 | |
ef1717a9 | 245 | private: |
c0c133e1 | 246 | wxDECLARE_NO_COPY_CLASS(wxDisplayImplMultimon); |
ef1717a9 | 247 | }; |
06efac1f | 248 | |
d14e03f5 | 249 | class wxDisplayFactoryMultimon : public wxDisplayFactoryWin32Base |
ef1717a9 VZ |
250 | { |
251 | public: | |
252 | wxDisplayFactoryMultimon(); | |
06efac1f | 253 | |
4e675101 | 254 | virtual wxDisplayImpl *CreateDisplay(unsigned n); |
06efac1f | 255 | |
ef1717a9 VZ |
256 | private: |
257 | // EnumDisplayMonitors() callback | |
258 | static BOOL CALLBACK MultimonEnumProc(HMONITOR hMonitor, | |
259 | HDC hdcMonitor, | |
260 | LPRECT lprcMonitor, | |
261 | LPARAM dwData); | |
06efac1f | 262 | |
ef1717a9 VZ |
263 | // add a monitor description to m_displays array |
264 | void AddDisplay(HMONITOR hMonitor, LPRECT lprcMonitor); | |
265 | }; | |
06efac1f | 266 | |
8585e2b5 | 267 | |
ef1717a9 VZ |
268 | // ============================================================================ |
269 | // common classes implementation | |
270 | // ============================================================================ | |
a536e411 | 271 | |
ef1717a9 VZ |
272 | // ---------------------------------------------------------------------------- |
273 | // wxDisplay | |
274 | // ---------------------------------------------------------------------------- | |
275 | ||
276 | /* static */ wxDisplayFactory *wxDisplay::CreateFactory() | |
a536e411 | 277 | { |
ef1717a9 | 278 | wxDisplayFactoryMultimon *factoryMM = new wxDisplayFactoryMultimon; |
16e45865 | 279 | |
ef1717a9 VZ |
280 | if ( factoryMM->IsOk() ) |
281 | return factoryMM; | |
a536e411 | 282 | |
ef1717a9 VZ |
283 | delete factoryMM; |
284 | ||
ef1717a9 VZ |
285 | // finally fall back to a stub implementation if all else failed (Win95?) |
286 | return new wxDisplayFactorySingle; | |
8585e2b5 | 287 | } |
a536e411 | 288 | |
16e45865 | 289 | |
ef1717a9 VZ |
290 | // ---------------------------------------------------------------------------- |
291 | // wxDisplayInfo | |
292 | // ---------------------------------------------------------------------------- | |
293 | ||
294 | void wxDisplayInfo::Initialize() | |
8585e2b5 | 295 | { |
ef1717a9 | 296 | if ( m_flags == (DWORD)-1 ) |
01c54165 | 297 | { |
ef1717a9 VZ |
298 | WinStruct<MONITORINFOEX> monInfo; |
299 | if ( !gs_GetMonitorInfo(m_hmon, (LPMONITORINFO)&monInfo) ) | |
01c54165 | 300 | { |
9a83f860 | 301 | wxLogLastError(wxT("GetMonitorInfo")); |
ef1717a9 VZ |
302 | m_flags = 0; |
303 | return; | |
01c54165 | 304 | } |
01c54165 | 305 | |
ef1717a9 | 306 | wxCopyRECTToRect(monInfo.rcMonitor, m_rect); |
6c5d6291 | 307 | wxCopyRECTToRect(monInfo.rcWork, m_rectClient); |
ef1717a9 VZ |
308 | m_devName = monInfo.szDevice; |
309 | m_flags = monInfo.dwFlags; | |
310 | } | |
8585e2b5 VZ |
311 | } |
312 | ||
06efac1f | 313 | // ---------------------------------------------------------------------------- |
ef1717a9 | 314 | // wxDisplayImplWin32Base |
06efac1f VZ |
315 | // ---------------------------------------------------------------------------- |
316 | ||
ef1717a9 | 317 | wxRect wxDisplayImplWin32Base::GetGeometry() const |
8585e2b5 | 318 | { |
ef1717a9 VZ |
319 | if ( m_info.m_rect.IsEmpty() ) |
320 | m_info.Initialize(); | |
06efac1f | 321 | |
ef1717a9 VZ |
322 | return m_info.m_rect; |
323 | } | |
06efac1f | 324 | |
6c5d6291 VZ |
325 | wxRect wxDisplayImplWin32Base::GetClientArea() const |
326 | { | |
327 | if ( m_info.m_rectClient.IsEmpty() ) | |
328 | m_info.Initialize(); | |
329 | ||
330 | return m_info.m_rectClient; | |
331 | } | |
332 | ||
ef1717a9 VZ |
333 | wxString wxDisplayImplWin32Base::GetName() const |
334 | { | |
57bd4c60 | 335 | if ( m_info.m_devName.empty() ) |
ef1717a9 | 336 | m_info.Initialize(); |
06efac1f | 337 | |
ef1717a9 VZ |
338 | return m_info.m_devName; |
339 | } | |
06efac1f | 340 | |
ef1717a9 VZ |
341 | bool wxDisplayImplWin32Base::IsPrimary() const |
342 | { | |
343 | if ( m_info.m_flags == (DWORD)-1 ) | |
344 | m_info.Initialize(); | |
06efac1f | 345 | |
ef1717a9 | 346 | return (m_info.m_flags & MONITORINFOF_PRIMARY) != 0; |
06efac1f VZ |
347 | } |
348 | ||
ef1717a9 | 349 | wxVideoMode wxDisplayImplWin32Base::GetCurrentMode() const |
06efac1f | 350 | { |
ef1717a9 | 351 | wxVideoMode mode; |
01c54165 | 352 | |
ef1717a9 VZ |
353 | // The first parameter of EnumDisplaySettings() must be NULL under Win95 |
354 | // according to MSDN. The version of GetName() we implement for Win95 | |
355 | // returns an empty string. | |
356 | const wxString name = GetName(); | |
c9f78968 VS |
357 | const wxChar * const deviceName = name.empty() |
358 | ? (const wxChar*)NULL | |
359 | : (const wxChar*)name.c_str(); | |
06efac1f | 360 | |
ef1717a9 VZ |
361 | DEVMODE dm; |
362 | dm.dmSize = sizeof(dm); | |
363 | dm.dmDriverExtra = 0; | |
364 | if ( !::EnumDisplaySettings(deviceName, ENUM_CURRENT_SETTINGS, &dm) ) | |
06efac1f | 365 | { |
9a83f860 | 366 | wxLogLastError(wxT("EnumDisplaySettings(ENUM_CURRENT_SETTINGS)")); |
06efac1f | 367 | } |
ef1717a9 VZ |
368 | else |
369 | { | |
370 | mode = ConvertToVideoMode(dm); | |
371 | } | |
372 | ||
373 | return mode; | |
06efac1f VZ |
374 | } |
375 | ||
376 | // ---------------------------------------------------------------------------- | |
ef1717a9 | 377 | // wxDisplayFactoryWin32Base |
06efac1f VZ |
378 | // ---------------------------------------------------------------------------- |
379 | ||
ef1717a9 | 380 | int wxDisplayFactoryWin32Base::ms_supportsMultimon = -1; |
8585e2b5 | 381 | |
ef1717a9 | 382 | wxDisplayFactoryWin32Base::wxDisplayFactoryWin32Base() |
8585e2b5 | 383 | { |
ef1717a9 | 384 | if ( ms_supportsMultimon == -1 ) |
01c54165 | 385 | { |
ef1717a9 | 386 | ms_supportsMultimon = 0; |
01c54165 | 387 | |
d238d403 | 388 | wxDynamicLibrary dllDisplay(displayDllName, wxDL_VERBATIM | wxDL_QUIET); |
ef1717a9 | 389 | |
d238d403 VZ |
390 | if ( (wxDL_INIT_FUNC(gs_, MonitorFromPoint, dllDisplay)) == NULL || |
391 | (wxDL_INIT_FUNC(gs_, MonitorFromWindow, dllDisplay)) == NULL || | |
392 | (wxDL_INIT_FUNC_AW(gs_, GetMonitorInfo, dllDisplay)) == NULL ) | |
ef1717a9 VZ |
393 | return; |
394 | ||
395 | ms_supportsMultimon = 1; | |
396 | ||
d238d403 VZ |
397 | // we can safely let dllDisplay go out of scope, the DLL itself will |
398 | // still remain loaded as all programs link to it statically anyhow | |
06efac1f | 399 | } |
ef1717a9 | 400 | } |
06efac1f | 401 | |
ef1717a9 VZ |
402 | void wxDisplayFactoryWin32Base::Clear() |
403 | { | |
404 | WX_CLEAR_ARRAY(m_displays); | |
8585e2b5 VZ |
405 | } |
406 | ||
ef1717a9 | 407 | wxDisplayFactoryWin32Base::~wxDisplayFactoryWin32Base() |
8585e2b5 | 408 | { |
ef1717a9 VZ |
409 | Clear(); |
410 | } | |
01c54165 | 411 | |
ef1717a9 VZ |
412 | // helper for GetFromPoint() and GetFromWindow() |
413 | int wxDisplayFactoryWin32Base::FindDisplayFromHMONITOR(HMONITOR hmon) const | |
414 | { | |
415 | if ( hmon ) | |
a536e411 | 416 | { |
ef1717a9 VZ |
417 | const size_t count = m_displays.size(); |
418 | for ( size_t n = 0; n < count; n++ ) | |
8585e2b5 | 419 | { |
ef1717a9 VZ |
420 | if ( hmon == m_displays[n]->m_hmon ) |
421 | return n; | |
8585e2b5 | 422 | } |
a536e411 JS |
423 | } |
424 | ||
ef1717a9 | 425 | return wxNOT_FOUND; |
a536e411 JS |
426 | } |
427 | ||
ef1717a9 VZ |
428 | int wxDisplayFactoryWin32Base::GetFromPoint(const wxPoint& pt) |
429 | { | |
430 | POINT pt2; | |
431 | pt2.x = pt.x; | |
432 | pt2.y = pt.y; | |
433 | ||
434 | return FindDisplayFromHMONITOR(gs_MonitorFromPoint(pt2, | |
435 | MONITOR_DEFAULTTONULL)); | |
436 | } | |
437 | ||
1e93d595 | 438 | int wxDisplayFactoryWin32Base::GetFromWindow(const wxWindow *window) |
ef1717a9 VZ |
439 | { |
440 | return FindDisplayFromHMONITOR(gs_MonitorFromWindow(GetHwndOf(window), | |
441 | MONITOR_DEFAULTTONULL)); | |
442 | } | |
443 | ||
444 | // ============================================================================ | |
445 | // wxDisplay implementation using Win32 multimon API | |
446 | // ============================================================================ | |
447 | ||
24d2b4f5 | 448 | // ---------------------------------------------------------------------------- |
ef1717a9 | 449 | // wxDisplayFactoryMultimon initialization |
24d2b4f5 RN |
450 | // ---------------------------------------------------------------------------- |
451 | ||
ef1717a9 | 452 | wxDisplayFactoryMultimon::wxDisplayFactoryMultimon() |
24d2b4f5 | 453 | { |
ef1717a9 VZ |
454 | if ( !ms_supportsMultimon ) |
455 | return; | |
01c54165 | 456 | |
16e45865 | 457 | // look up EnumDisplayMonitors() |
ef1717a9 VZ |
458 | EnumDisplayMonitors_t pfnEnumDisplayMonitors; |
459 | { | |
d238d403 VZ |
460 | wxDynamicLibrary dllDisplay(displayDllName, wxDL_VERBATIM | wxDL_QUIET); |
461 | if ( (wxDL_INIT_FUNC(pfn, EnumDisplayMonitors, dllDisplay)) == NULL ) | |
ef1717a9 VZ |
462 | return; |
463 | } | |
24d2b4f5 | 464 | |
ef1717a9 VZ |
465 | // enumerate all displays |
466 | if ( !pfnEnumDisplayMonitors(NULL, NULL, MultimonEnumProc, (LPARAM)this) ) | |
24d2b4f5 | 467 | { |
ef1717a9 | 468 | wxLogLastError(wxT("EnumDisplayMonitors")); |
24d2b4f5 | 469 | } |
ef1717a9 VZ |
470 | } |
471 | ||
472 | /* static */ | |
473 | BOOL CALLBACK | |
474 | wxDisplayFactoryMultimon::MultimonEnumProc( | |
475 | HMONITOR hMonitor, // handle to display monitor | |
476 | HDC WXUNUSED(hdcMonitor), // handle to monitor-appropriate device context | |
477 | LPRECT lprcMonitor, // pointer to monitor intersection rectangle | |
478 | LPARAM dwData // data passed from EnumDisplayMonitors (this) | |
479 | ) | |
480 | { | |
481 | wxDisplayFactoryMultimon *const self = (wxDisplayFactoryMultimon *)dwData; | |
482 | self->AddDisplay(hMonitor, lprcMonitor); | |
24d2b4f5 | 483 | |
ef1717a9 VZ |
484 | // continue the enumeration |
485 | return TRUE; | |
24d2b4f5 RN |
486 | } |
487 | ||
06efac1f | 488 | // ---------------------------------------------------------------------------- |
ef1717a9 | 489 | // wxDisplayFactoryMultimon helper functions |
06efac1f VZ |
490 | // ---------------------------------------------------------------------------- |
491 | ||
ef1717a9 | 492 | void wxDisplayFactoryMultimon::AddDisplay(HMONITOR hMonitor, LPRECT lprcMonitor) |
06efac1f | 493 | { |
ef1717a9 | 494 | wxDisplayInfo *info = new wxDisplayInfo(hMonitor); |
06efac1f | 495 | |
ef1717a9 VZ |
496 | // we also store the display geometry |
497 | info->m_rect = wxRect(lprcMonitor->left, lprcMonitor->top, | |
498 | lprcMonitor->right - lprcMonitor->left, | |
499 | lprcMonitor->bottom - lprcMonitor->top); | |
06efac1f | 500 | |
ef1717a9 VZ |
501 | // now add this monitor to the array |
502 | m_displays.Add(info); | |
503 | } | |
06efac1f | 504 | |
ef1717a9 VZ |
505 | // ---------------------------------------------------------------------------- |
506 | // wxDisplayFactoryMultimon inherited pure virtuals implementation | |
507 | // ---------------------------------------------------------------------------- | |
06efac1f | 508 | |
4e675101 | 509 | wxDisplayImpl *wxDisplayFactoryMultimon::CreateDisplay(unsigned n) |
ef1717a9 | 510 | { |
9a83f860 | 511 | wxCHECK_MSG( n < m_displays.size(), NULL, wxT("invalid display index") ); |
ef1717a9 VZ |
512 | |
513 | return new wxDisplayImplMultimon(n, *(m_displays[n])); | |
06efac1f | 514 | } |
ef1717a9 VZ |
515 | |
516 | // ---------------------------------------------------------------------------- | |
517 | // wxDisplayImplMultimon implementation | |
518 | // ---------------------------------------------------------------------------- | |
06efac1f VZ |
519 | |
520 | wxArrayVideoModes | |
ef1717a9 | 521 | wxDisplayImplMultimon::GetModes(const wxVideoMode& modeMatch) const |
a536e411 | 522 | { |
8585e2b5 VZ |
523 | wxArrayVideoModes modes; |
524 | ||
01c54165 VZ |
525 | // The first parameter of EnumDisplaySettings() must be NULL under Win95 |
526 | // according to MSDN. The version of GetName() we implement for Win95 | |
527 | // returns an empty string. | |
528 | const wxString name = GetName(); | |
c9f78968 VS |
529 | const wxChar * const deviceName = name.empty() |
530 | ? (const wxChar*)NULL | |
531 | : (const wxChar*)name.c_str(); | |
8585e2b5 VZ |
532 | |
533 | DEVMODE dm; | |
01c54165 VZ |
534 | dm.dmSize = sizeof(dm); |
535 | dm.dmDriverExtra = 0; | |
8585e2b5 VZ |
536 | for ( int iModeNum = 0; |
537 | ::EnumDisplaySettings(deviceName, iModeNum, &dm); | |
538 | iModeNum++ ) | |
539 | { | |
540 | const wxVideoMode mode = ConvertToVideoMode(dm); | |
541 | if ( mode.Matches(modeMatch) ) | |
542 | { | |
543 | modes.Add(mode); | |
544 | } | |
545 | } | |
546 | ||
547 | return modes; | |
a536e411 JS |
548 | } |
549 | ||
ef1717a9 | 550 | bool wxDisplayImplMultimon::ChangeMode(const wxVideoMode& mode) |
a536e411 | 551 | { |
8585e2b5 | 552 | // prepare ChangeDisplaySettingsEx() parameters |
61373fa8 WS |
553 | DEVMODE dm; |
554 | DEVMODE *pDevMode; | |
555 | ||
8585e2b5 VZ |
556 | int flags; |
557 | ||
558 | if ( mode == wxDefaultVideoMode ) | |
559 | { | |
560 | // reset the video mode to default | |
561 | pDevMode = NULL; | |
562 | flags = 0; | |
563 | } | |
564 | else // change to the given mode | |
565 | { | |
2edac25b | 566 | wxCHECK_MSG( mode.GetWidth() && mode.GetHeight(), false, |
9a83f860 | 567 | wxT("at least the width and height must be specified") ); |
8585e2b5 VZ |
568 | |
569 | wxZeroMemory(dm); | |
570 | dm.dmSize = sizeof(dm); | |
01c54165 | 571 | dm.dmDriverExtra = 0; |
8585e2b5 | 572 | dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; |
2edac25b RR |
573 | dm.dmPelsWidth = mode.GetWidth(); |
574 | dm.dmPelsHeight = mode.GetHeight(); | |
8585e2b5 | 575 | |
2edac25b | 576 | if ( mode.GetDepth() ) |
8585e2b5 VZ |
577 | { |
578 | dm.dmFields |= DM_BITSPERPEL; | |
2edac25b | 579 | dm.dmBitsPerPel = mode.GetDepth(); |
8585e2b5 VZ |
580 | } |
581 | ||
2edac25b | 582 | if ( mode.GetRefresh() ) |
8585e2b5 VZ |
583 | { |
584 | dm.dmFields |= DM_DISPLAYFREQUENCY; | |
2edac25b | 585 | dm.dmDisplayFrequency = mode.GetRefresh(); |
8585e2b5 VZ |
586 | } |
587 | ||
588 | pDevMode = &dm; | |
589 | ||
2ad495fb WS |
590 | #ifdef __WXWINCE__ |
591 | flags = 0; | |
592 | #else // !__WXWINCE__ | |
8585e2b5 | 593 | flags = CDS_FULLSCREEN; |
2ad495fb | 594 | #endif // __WXWINCE__/!__WXWINCE__ |
8585e2b5 VZ |
595 | } |
596 | ||
597 | ||
598 | // get pointer to the function dynamically | |
599 | // | |
600 | // we're only called from the main thread, so it's ok to use static | |
601 | // variable | |
602 | static ChangeDisplaySettingsEx_t pfnChangeDisplaySettingsEx = NULL; | |
603 | if ( !pfnChangeDisplaySettingsEx ) | |
604 | { | |
d238d403 VZ |
605 | wxDynamicLibrary dllDisplay(displayDllName, wxDL_VERBATIM | wxDL_QUIET); |
606 | if ( dllDisplay.IsLoaded() ) | |
8585e2b5 | 607 | { |
d238d403 | 608 | wxDL_INIT_FUNC_AW(pfn, ChangeDisplaySettingsEx, dllDisplay); |
8585e2b5 | 609 | } |
d238d403 | 610 | //else: huh, no this DLL must always be present, what's going on?? |
8585e2b5 | 611 | |
2ad495fb | 612 | #ifndef __WXWINCE__ |
8585e2b5 VZ |
613 | if ( !pfnChangeDisplaySettingsEx ) |
614 | { | |
615 | // we must be under Win95 and so there is no multiple monitors | |
616 | // support anyhow | |
617 | pfnChangeDisplaySettingsEx = ChangeDisplaySettingsExForWin95; | |
618 | } | |
2ad495fb | 619 | #endif // !__WXWINCE__ |
8585e2b5 VZ |
620 | } |
621 | ||
622 | // do change the mode | |
623 | switch ( pfnChangeDisplaySettingsEx | |
624 | ( | |
e0a050e3 VS |
625 | GetName().wx_str(), // display name |
626 | pDevMode, // dev mode or NULL to reset | |
627 | NULL, // reserved | |
8585e2b5 | 628 | flags, |
e0a050e3 | 629 | NULL // pointer to video parameters (not used) |
8585e2b5 VZ |
630 | ) ) |
631 | { | |
632 | case DISP_CHANGE_SUCCESSFUL: | |
633 | // ok | |
920b9675 JS |
634 | { |
635 | // If we have a top-level, full-screen frame, emulate | |
636 | // the DirectX behavior and resize it. This makes this | |
637 | // API quite a bit easier to use. | |
638 | wxWindow *winTop = wxTheApp->GetTopWindow(); | |
639 | wxFrame *frameTop = wxDynamicCast(winTop, wxFrame); | |
640 | if (frameTop && frameTop->IsFullScreen()) | |
641 | { | |
642 | wxVideoMode current = GetCurrentMode(); | |
2edac25b | 643 | frameTop->SetClientSize(current.GetWidth(), current.GetHeight()); |
920b9675 JS |
644 | } |
645 | } | |
06efac1f | 646 | return true; |
8585e2b5 VZ |
647 | |
648 | case DISP_CHANGE_BADMODE: | |
649 | // don't complain about this, this is the only "expected" error | |
650 | break; | |
651 | ||
652 | default: | |
9a83f860 | 653 | wxFAIL_MSG( wxT("unexpected ChangeDisplaySettingsEx() return value") ); |
8585e2b5 VZ |
654 | } |
655 | ||
06efac1f VZ |
656 | return false; |
657 | } | |
658 | ||
8585e2b5 | 659 | #endif // wxUSE_DISPLAY |