]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/display.cpp
Mac compilation fix after const patch
[wxWidgets.git] / src / mac / carbon / display.cpp
CommitLineData
a536e411
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: display.cpp
3// Purpose: Mac implementation of wxDisplay class
cc9d56b0 4// Author: Ryan Norton & Brian Victor
d0ee33f5 5// Modified by: Royce Mitchell III
a536e411
JS
6// Created: 06/21/02
7// RCS-ID: $Id$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
a536e411
JS
10/////////////////////////////////////////////////////////////////////////////
11
a536e411
JS
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#if wxUSE_DISPLAY
20
21#ifndef WX_PRECOMP
22 #include "wx/dynarray.h"
1ed1a609 23 #include "wx/log.h"
92094b09 24 #include "wx/msgdlg.h"
a536e411
JS
25#endif
26
27#ifdef __DARWIN__
28 #include <Carbon/Carbon.h>
29#else
7c4a8e41 30 #include <Gestalt.h>
a536e411
JS
31 #include <Displays.h>
32 #include <Quickdraw.h>
1ed1a609 33 #include <Video.h> //for VDSwitchInfoRec
7c4a8e41 34 #include <FixMath.h>
a536e411
JS
35#endif
36
37#include "wx/display.h"
38#include "wx/gdicmn.h"
39#include "wx/string.h"
40
41// ----------------------------------------------------------------------------
42// private classes
43// ----------------------------------------------------------------------------
44
20b69855
SC
45#ifdef __WXMAC_OSX__
46
47class wxDisplayMacPriv
48{
49public:
50 CGDirectDisplayID m_id;
51};
52
53size_t wxDisplayBase::GetCount()
54{
55 CGDisplayCount count;
56#ifdef __WXDEBUG__
d0ee33f5 57 CGDisplayErr err =
20b69855
SC
58#endif
59 CGGetActiveDisplayList(0, NULL, &count);
60
61 wxASSERT(err == CGDisplayNoErr);
62 return count;
63}
64
65int wxDisplayBase::GetFromPoint(const wxPoint &p)
d0ee33f5 66{
20b69855
SC
67 CGPoint thePoint = {(float)p.x, (float)p.y};
68 CGDirectDisplayID theID;
69 CGDisplayCount theCount;
70 CGDisplayErr err = CGGetDisplaysWithPoint(thePoint, 1, &theID, &theCount);
71 wxASSERT(err == CGDisplayNoErr);
72 int nWhich = -1;
d0ee33f5 73
20b69855
SC
74 if (theCount)
75 {
76 theCount = GetCount();
77 CGDirectDisplayID* theIDs = new CGDirectDisplayID[theCount];
78 err = CGGetActiveDisplayList(theCount, theIDs, &theCount);
79 wxASSERT(err == CGDisplayNoErr);
80
81 for(nWhich = 0; nWhich < (int) theCount; ++nWhich)
82 {
83 if(theIDs[nWhich] == theID)
84 break;
85 }
d0ee33f5 86
20b69855 87 delete[] theIDs;
d0ee33f5 88
20b69855
SC
89 if(nWhich == (int) theCount)
90 {
91 wxFAIL_MSG(wxT("Failed to find display in display list"));
92 nWhich = -1;
93 }
94 }
d0ee33f5 95
20b69855
SC
96 return nWhich;
97}//CFUserNotification[NSBundle bundleForClass:[self class]]
98
99wxDisplay::wxDisplay(size_t index) : wxDisplayBase ( index ) ,
100 m_priv ( new wxDisplayMacPriv() )
101{
102 CGDisplayCount theCount = GetCount();
103 CGDirectDisplayID* theIDs = new CGDirectDisplayID[theCount];
104#ifdef __WXDEBUG__
d0ee33f5 105 CGDisplayErr err =
20b69855
SC
106#endif
107 CGGetActiveDisplayList(theCount, theIDs, &theCount);
108
109 wxASSERT(err == CGDisplayNoErr);
110 wxASSERT(index < theCount);
d0ee33f5 111
20b69855 112 m_priv->m_id = theIDs[index];
d0ee33f5 113
20b69855
SC
114 delete[] theIDs;
115}
116
117wxRect wxDisplay::GetGeometry() const
118{
119 CGRect theRect = CGDisplayBounds(m_priv->m_id);
d0ee33f5
WS
120 return wxRect( (int)theRect.origin.x,
121 (int)theRect.origin.y,
122 (int)theRect.size.width,
123 (int)theRect.size.height ); //floats
20b69855
SC
124}
125
126int wxDisplay::GetDepth() const
127{
128 return (int) CGDisplayBitsPerPixel(m_priv->m_id); //size_t
129}
130
131wxString wxDisplay::GetName() const
132{
133 // Macs don't name their displays...
134 return wxEmptyString;
135}
136
137static int wxCFDictKeyToInt( CFDictionaryRef desc, CFStringRef key )
138{
139 CFNumberRef value;
140 int num = 0;
141
142 if ( (value = (CFNumberRef) CFDictionaryGetValue(desc, key)) == NULL )
143 return 0;
144 CFNumberGetValue(value, kCFNumberIntType, &num);
145 return num;
146}
147
148wxArrayVideoModes
149 wxDisplay::GetModes(const wxVideoMode& mode) const
150{
151 wxArrayVideoModes Modes;
d0ee33f5 152
20b69855
SC
153 CFArrayRef theArray = CGDisplayAvailableModes(m_priv->m_id);
154
155 for(CFIndex i = 0; i < CFArrayGetCount(theArray); ++i)
156 {
157 CFDictionaryRef theValue = (CFDictionaryRef) CFArrayGetValueAtIndex(theArray, i);
d0ee33f5 158
20b69855
SC
159 wxVideoMode theMode(wxCFDictKeyToInt(theValue, kCGDisplayWidth),
160 wxCFDictKeyToInt(theValue, kCGDisplayHeight),
161 wxCFDictKeyToInt(theValue, kCGDisplayBitsPerPixel),
162 wxCFDictKeyToInt(theValue, kCGDisplayRefreshRate));
d0ee33f5 163
20b69855
SC
164 if (theMode.Matches(mode))
165 Modes.Add(theMode);
166 }
d0ee33f5 167
20b69855
SC
168 return Modes;
169}
170
171wxVideoMode wxDisplay::GetCurrentMode() const
172{
173 CFDictionaryRef theValue = CGDisplayCurrentMode (m_priv->m_id);
d0ee33f5 174
20b69855
SC
175 return wxVideoMode(wxCFDictKeyToInt(theValue, kCGDisplayWidth),
176 wxCFDictKeyToInt(theValue, kCGDisplayHeight),
177 wxCFDictKeyToInt(theValue, kCGDisplayBitsPerPixel),
178 wxCFDictKeyToInt(theValue, kCGDisplayRefreshRate));
179}
180
181bool wxDisplay::ChangeMode(const wxVideoMode& mode)
182{
183 //Changing to default mode (wxDefualtVideoMode) doesn't
184 //work because we don't have access to the system's 'scrn'
185 //resource which holds the user's mode which the system
186 //will return to after this app is done
187 boolean_t bExactMatch;
188 CFDictionaryRef theCGMode = CGDisplayBestModeForParametersAndRefreshRate (
189 m_priv->m_id,
190 (size_t)mode.bpp,
191 (size_t)mode.w,
192 (size_t)mode.h,
193 (double)mode.refresh,
194 &bExactMatch);
d0ee33f5 195
20b69855 196 bool bOK = bExactMatch;
d0ee33f5 197
20b69855
SC
198 if(bOK)
199 bOK = CGDisplaySwitchToMode(m_priv->m_id, theCGMode) == CGDisplayNoErr;
200
201 return bOK;
202}
203
204wxDisplay::~wxDisplay()
205{
206 if ( m_priv )
207 {
208 delete m_priv;
209 m_priv = 0;
210 }
211}
212
213#else
214
a536e411
JS
215class wxDisplayMacPriv
216{
217public:
e40298d5 218 GDHandle m_hndl;
a536e411
JS
219};
220
221size_t wxDisplayBase::GetCount()
222{
223 GDHandle hndl;
224 size_t num = 0;
225 hndl = DMGetFirstScreenDevice(true);
226 while(hndl)
227 {
228 num++;
229 hndl = DMGetNextScreenDevice(hndl, true);
230 }
231 return num;
232}
233
234int wxDisplayBase::GetFromPoint(const wxPoint &p)
235{
236 GDHandle hndl;
237 size_t num = 0;
238 hndl = DMGetFirstScreenDevice(true);
239 while(hndl)
240 {
241 Rect screenrect = (*hndl)->gdRect;
242 if (p.x >= screenrect.left &&
243 p.x <= screenrect.right &&
244 p.y >= screenrect.top &&
245 p.y <= screenrect.bottom)
246 {
247 return num;
248 }
249 num++;
250 hndl = DMGetNextScreenDevice(hndl, true);
251 }
252 return -1;
253}
254
255wxDisplay::wxDisplay(size_t index) : wxDisplayBase ( index ),
256 m_priv ( new wxDisplayMacPriv() )
257{
258 GDHandle hndl;
259 hndl = DMGetFirstScreenDevice(true);
260 m_priv->m_hndl = NULL;
261 while(hndl)
262 {
263 if (index == 0)
264 {
265 m_priv->m_hndl = hndl;
266 }
267 index--;
268 hndl = DMGetNextScreenDevice(hndl, true);
269 }
270}
271
272wxRect wxDisplay::GetGeometry() const
273{
274 if (!(m_priv)) return wxRect(0, 0, 0, 0);
275 if (!(m_priv->m_hndl)) return wxRect(0, 0, 0, 0);
276 Rect screenrect = (*(m_priv->m_hndl))->gdRect;
d0ee33f5 277 return wxRect( screenrect.left, screenrect.top,
a536e411
JS
278 screenrect.right - screenrect.left, screenrect.bottom - screenrect.top);
279}
280
281int wxDisplay::GetDepth() const
282{
283 if (!(m_priv)) return 0;
284 if (!(m_priv->m_hndl)) return 0;
285
286 // This cryptic looking code is based on Apple's sample code:
287 // http://developer.apple.com/samplecode/Sample_Code/Graphics_2D/GDevVideo/Gen.cp.htm
1ed1a609
SC
288
289 //RN - according to the docs
d0ee33f5
WS
290 //gdPMap is a bitmap-type representation of the GDevice, and all
291 //0x0000FFFF does is get the lower 16 bits of pixelSize. However,
292 //since pixelSize is only 16 bits (a short)...
a536e411
JS
293 return ((*(*(m_priv->m_hndl))->gdPMap)->pixelSize) & 0x0000FFFF;
294}
295
296wxString wxDisplay::GetName() const
297{
298 // Macs don't name their displays...
1e1cc1ce
DS
299 return wxEmptyString;
300}
301
1ed1a609
SC
302struct DMModeIteratorRec
303{
d0ee33f5
WS
304 wxArrayVideoModes* pModes;
305 const wxVideoMode* pMatchMode;
1ed1a609
SC
306};
307
d0ee33f5
WS
308pascal void DMModeListIteratorProc ( void* pData,
309 DMListIndexType nIndex,
310 DMDisplayModeListEntryPtr pInfo)
1ed1a609
SC
311{
312 DMModeIteratorRec* pInfoData = (DMModeIteratorRec*) pData;
313
d0ee33f5 314 //Note that in testing the refresh rate is always 0 on my ibook - RN
1ed1a609
SC
315 int refresh = (int) Fix2Long(pInfo->displayModeResolutionInfo->csRefreshRate);
316
d0ee33f5
WS
317 for(unsigned long i = 0; i < pInfo->displayModeDepthBlockInfo->depthBlockCount; ++i)
318 {
1ed1a609
SC
319#define pDBI pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthVPBlock
320
d0ee33f5
WS
321 if (wxVideoMode((int) pInfo->displayModeResolutionInfo->csHorizontalPixels,
322 (int) pInfo->displayModeResolutionInfo->csVerticalLines,
323 (int) pDBI->vpPixelSize,
324 refresh).Matches(*pInfoData->pMatchMode) )
325 {
326 pInfoData->pModes->Add(wxVideoMode((int) pInfo->displayModeResolutionInfo->csHorizontalPixels,
327 (int) pInfo->displayModeResolutionInfo->csVerticalLines,
328 (int) pDBI->vpPixelSize,
329 refresh));
330 }
1ed1a609 331#undef pDBI
d0ee33f5 332 }
1ed1a609
SC
333}
334
335struct DMModeInfoRec
336{
d0ee33f5
WS
337 const wxVideoMode* pMode;
338 VDSwitchInfoRec sMode;
339 bool bMatched;
1ed1a609
SC
340};
341
d0ee33f5
WS
342pascal void DMModeInfoProc ( void* pData,
343 DMListIndexType nIndex,
344 DMDisplayModeListEntryPtr pInfo)
1ed1a609 345{
d0ee33f5
WS
346 DMModeInfoRec* pInfoData = (DMModeInfoRec*) pData;
347 Fixed refresh = Long2Fix(pInfoData->pMode->refresh);
1ed1a609 348
d0ee33f5
WS
349 for(unsigned long i = 0; i < pInfo->displayModeDepthBlockInfo->depthBlockCount; ++i)
350 {
1ed1a609 351#define pDBI pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthVPBlock
d0ee33f5
WS
352 if (pInfoData->pMode->w == (int&) pInfo->displayModeResolutionInfo->csHorizontalPixels &&
353 pInfoData->pMode->h == (int&) pInfo->displayModeResolutionInfo->csVerticalLines &&
354 pInfoData->pMode->bpp == (int) pDBI->vpPixelSize &&
355 refresh == pInfo->displayModeResolutionInfo->csRefreshRate)
356 {
357 memcpy(&pInfoData->sMode, pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthSwitchInfo,
358 sizeof(VDSwitchInfoRec));
359 pInfoData->sMode.csMode = pDBI->vpPixelSize;
360 pInfoData->bMatched = true;
361 break;
362 }
1ed1a609 363#undef pDBI
d0ee33f5 364 }
1ed1a609
SC
365}
366
367struct DMModeTransRec
368{
d0ee33f5
WS
369 wxVideoMode Mode;
370 const VDSwitchInfoRec* psMode;
371 bool bMatched;
1ed1a609
SC
372};
373
d0ee33f5
WS
374pascal void DMModeTransProc ( void* pData,
375 DMListIndexType nIndex,
376 DMDisplayModeListEntryPtr pInfo)
1ed1a609 377{
d0ee33f5 378 DMModeTransRec* pInfoData = (DMModeTransRec*) pData;
1ed1a609 379
d0ee33f5
WS
380 for(unsigned long i = 0; i < pInfo->displayModeDepthBlockInfo->depthBlockCount; ++i)
381 {
1ed1a609 382#define pDBI pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthVPBlock
d0ee33f5
WS
383 if (pInfoData->psMode->csData == pInfo->displayModeDepthBlockInfo->depthVPBlock[i].depthSwitchInfo->csData)
384 {
385 pInfoData->Mode = wxVideoMode((int) pInfo->displayModeResolutionInfo->csHorizontalPixels,
386 (int) pInfo->displayModeResolutionInfo->csVerticalLines,
387 (int) pDBI->vpPixelSize,
388 (int) Fix2Long(pInfo->displayModeResolutionInfo->csRefreshRate) );
389 pInfoData->bMatched = true;
390 break;
391 }
1ed1a609 392#undef pDBI
d0ee33f5 393 }
1ed1a609
SC
394}
395
396wxArrayVideoModes
1e1cc1ce
DS
397 wxDisplay::GetModes(const wxVideoMode& mode) const
398{
1ed1a609
SC
399
400 wxArrayVideoModes Modes;
401
402 unsigned long dwDMVer;
403 Gestalt(gestaltDisplayMgrVers, (long*) &dwDMVer);
404
405 //Check DM version (for backward compatibility only - 7.5.3+ use 2.0)
406 if (dwDMVer >= 0x020000) //version 2?
407 {
408
d0ee33f5
WS
409 DMListIndexType nNumModes;
410 DMListType pModes;
411 DMDisplayModeListIteratorUPP uppMLI;
412 DisplayIDType nDisplayID;
cc9d56b0 413 OSErr err;
1ed1a609 414
cc9d56b0 415 err = DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false);
d0ee33f5
WS
416 wxASSERT(err == noErr);
417
418 //Create a new list...
cc9d56b0 419 err = DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes);
d0ee33f5 420 wxASSERT_MSG(err == noErr, wxT("Could not create a new display mode list") );
1ed1a609 421
d0ee33f5
WS
422 uppMLI = NewDMDisplayModeListIteratorUPP(DMModeListIteratorProc);
423 wxASSERT(uppMLI);
1ed1a609 424
d0ee33f5
WS
425 DMModeIteratorRec sModeInfo;
426 sModeInfo.pModes = &Modes;
427 sModeInfo.pMatchMode = &mode;
428 for (DMListIndexType i = 0; i < nNumModes; ++i)
429 {
cc9d56b0 430 err = DMGetIndexedDisplayModeFromList(pModes, i, NULL, uppMLI, &sModeInfo);
d0ee33f5
WS
431 wxASSERT(err == noErr);
432 }
433 DisposeDMDisplayModeListIteratorUPP(uppMLI);
434
cc9d56b0 435 err = DMDisposeList(pModes);
d0ee33f5 436 wxASSERT(err == noErr);
1ed1a609
SC
437 }
438 else //DM 1.0, 1.2, 1.x
439 {
d0ee33f5
WS
440 wxLogSysError(wxString::Format(wxT("Display Manager Version %u Not Supported! Present? %s"),
441 (unsigned int) dwDMVer / 0x10000,
442 (dwDMVer & (1 << gestaltDisplayMgrPresent) ? wxT("Yes") : wxT("No")) )
443 );
1ed1a609
SC
444 }
445
446 return Modes;
1e1cc1ce
DS
447}
448
449wxVideoMode wxDisplay::GetCurrentMode() const
450{
1ed1a609
SC
451 unsigned long dwDMVer;
452 wxVideoMode RetMode;
d0ee33f5
WS
453
454 Gestalt(gestaltDisplayMgrVers, (long*) &dwDMVer);
1ed1a609
SC
455 //Check DM version (for backward compatibility only - 7.5.3+ use 2.0)
456 if (dwDMVer >= 0x020000) //version 2?
457 {
d0ee33f5
WS
458 VDSwitchInfoRec sMode; //Note - csMode member also contains the bit depth
459 if (DMGetDisplayMode(m_priv->m_hndl, &sMode) == noErr)
460 {
461 DMListIndexType nNumModes;
462 DMListType pModes;
463 DMDisplayModeListIteratorUPP uppMLI;
464 DisplayIDType nDisplayID;
cc9d56b0 465 OSErr err;
1ed1a609 466
cc9d56b0 467 err = DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false);
d0ee33f5
WS
468 wxASSERT(err == noErr);
469
470 //Create a new list...
cc9d56b0 471 err = DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes);
d0ee33f5
WS
472 wxASSERT_MSG(err == noErr, wxT("Could not create a new display mode list") );
473
474 uppMLI = NewDMDisplayModeListIteratorUPP(DMModeTransProc);
475 wxASSERT(uppMLI);
476
477 DMModeTransRec sModeInfo;
478 sModeInfo.bMatched = false;
479 sModeInfo.psMode = &sMode;
480 for (DMListIndexType i = 0; i < nNumModes; ++i)
481 {
cc9d56b0 482 err = DMGetIndexedDisplayModeFromList(pModes, i, NULL, uppMLI, &sModeInfo);
d0ee33f5 483 wxASSERT(err == noErr);
1ed1a609 484
d0ee33f5
WS
485 if ( sModeInfo.bMatched )
486 {
487 RetMode = sModeInfo.Mode;
488 break;
489 }
490 }
491
492 DisposeDMDisplayModeListIteratorUPP(uppMLI);
1ed1a609 493
cc9d56b0 494 err = DMDisposeList(pModes);
d0ee33f5
WS
495 wxASSERT(err == noErr);
496 }
497 else //Can't get current mode?
498 {
499 wxLogSysError(wxString::Format(wxT("Couldn't obtain current display mode!!!\ndwDMVer:%u"),
500 (unsigned int) dwDMVer));
501 }
1ed1a609
SC
502 }
503 else //DM ver 1
504 {
d0ee33f5
WS
505 wxLogSysError(wxString::Format(wxT("Display Manager Version %u Not Supported! Present? %s"),
506 (unsigned int) dwDMVer / 0x10000,
507 (dwDMVer & (1 << gestaltDisplayMgrPresent) ? wxT("Yes") : wxT("No")) )
508 );
1ed1a609 509 }
d0ee33f5 510
1ed1a609 511 return RetMode;
1e1cc1ce
DS
512}
513
514bool wxDisplay::ChangeMode(const wxVideoMode& mode)
515{
1ed1a609
SC
516 unsigned long dwDMVer;
517 Gestalt(gestaltDisplayMgrVers, (long*)&dwDMVer);
518 if (GetCount() == 1 || dwDMVer >= 0x020000)
519 {
d0ee33f5
WS
520 if (mode == wxDefaultVideoMode)
521 {
1ed1a609 522//#ifndef __DARWIN__
d0ee33f5
WS
523// Handle hDisplayState;
524// if (DMBeginConfigureDisplays(&hDisplayState) != noErr)
525// {
526// wxLogSysError(wxT("Could not lock display for display mode changing!"));
527// return false;
528// }
529// wxASSERT( DMUseScreenPrefs(true, hDisplayState) == noErr);
530// DMEndConfigureDisplays(hDisplayState);
531// return true;
1ed1a609 532//#else
d0ee33f5
WS
533 //hmmmmm....
534 return true;
1ed1a609 535//#endif
d0ee33f5
WS
536 }
537
538 //0 & NULL for params 2 & 3 of DMSetVideoMode signal it to use defaults (current mode)
539 //DM 2.0+ doesn't use params 2 & 3 of DMSetDisplayMode
540 //so we have to use this icky structure
541 VDSwitchInfoRec sMode;
542 memset(&sMode, 0, sizeof(VDSwitchInfoRec) );
543
544 DMListIndexType nNumModes;
545 DMListType pModes;
546 DMDisplayModeListIteratorUPP uppMLI;
547 DisplayIDType nDisplayID;
cc9d56b0 548 OSErr err;
1ed1a609 549
cc9d56b0 550 err = DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false);
d0ee33f5
WS
551 wxASSERT(err == noErr);
552
553 //Create a new list...
cc9d56b0 554 err = DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes);
d0ee33f5 555 wxASSERT_MSG(err == noErr, wxT("Could not create a new display mode list") );
1ed1a609 556
d0ee33f5
WS
557 uppMLI = NewDMDisplayModeListIteratorUPP(DMModeInfoProc);
558 wxASSERT(uppMLI);
1ed1a609 559
d0ee33f5
WS
560 DMModeInfoRec sModeInfo;
561 sModeInfo.bMatched = false;
562 sModeInfo.pMode = &mode;
563 unsigned int i;
564 for(i = 0; i < nNumModes; ++i)
565 {
cc9d56b0 566 err = DMGetIndexedDisplayModeFromList(pModes, i, NULL, uppMLI, &sModeInfo);
d0ee33f5
WS
567 wxASSERT(err == noErr);
568
569 if (sModeInfo.bMatched)
570 {
571 sMode = sModeInfo.sMode;
572 break;
573 }
574 }
575 if(i == nNumModes)
576 return false;
577
578 DisposeDMDisplayModeListIteratorUPP(uppMLI);
579
cc9d56b0
RN
580 err = DMDisposeList(pModes);
581 wxASSERT(err == noErr);
1ed1a609 582
d0ee33f5
WS
583 // For the really paranoid -
584 // unsigned long flags;
585 // Boolean bok;
586 // wxASSERT(noErr == DMCheckDisplayMode(m_priv->m_hndl, sMode.csData,
587 // sMode.csMode, &flags, NULL, &bok));
588 // wxASSERT(bok);
589
590 Handle hDisplayState;
591 if (DMBeginConfigureDisplays(&hDisplayState) != noErr)
592 {
593 wxLogSysError(wxT("Could not lock display for display mode changing!"));
594 return false;
595 }
596
597 unsigned long dwBPP = (unsigned long) mode.bpp;
598 if (DMSetDisplayMode(m_priv->m_hndl, sMode.csData,
599 (unsigned long*) &(dwBPP), NULL
600 //(unsigned long) &sMode
601 , hDisplayState
602 ) != noErr)
603 {
604 DMEndConfigureDisplays(hDisplayState);
605 wxMessageBox(wxString::Format(wxT("Could not set the display mode")));
1ed1a609 606 return false;
d0ee33f5
WS
607 }
608 DMEndConfigureDisplays(hDisplayState);
1ed1a609
SC
609 }
610 else //DM 1.0, 1.2, 1.x
611 {
d0ee33f5
WS
612 wxLogSysError(wxString::Format(wxT("Monitor gravitation not supported yet. dwDMVer:%u"),
613 (unsigned int) dwDMVer));
614 return false;
1ed1a609 615 }
d0ee33f5 616
1ed1a609 617 return true;
a536e411
JS
618}
619
620wxDisplay::~wxDisplay()
621{
622 if ( m_priv )
623 {
624 delete m_priv;
625 m_priv = 0;
626 }
627}
628
20b69855
SC
629#endif // !OSX
630
a536e411 631#endif // wxUSE_DISPLAY