- unsigned long dwDMVer;
- Gestalt(gestaltDisplayMgrVers, (long*)&dwDMVer);
- if (GetCount() == 1 || dwDMVer >= 0x020000)
- {
- if (mode == wxDefaultVideoMode)
- {
-//#ifndef __DARWIN__
-// Handle hDisplayState;
-// if (DMBeginConfigureDisplays(&hDisplayState) != noErr)
-// {
-// wxLogSysError(wxT("Could not lock display for display mode changing!"));
-// return false;
-// }
-// wxASSERT( DMUseScreenPrefs(true, hDisplayState) == noErr);
-// DMEndConfigureDisplays(hDisplayState);
-// return true;
-//#else
- //hmmmmm....
- return true;
-//#endif
- }
-
- //0 & NULL for params 2 & 3 of DMSetVideoMode signal it to use defaults (current mode)
- //DM 2.0+ doesn't use params 2 & 3 of DMSetDisplayMode
- //so we have to use this icky structure
- VDSwitchInfoRec sMode;
- memset(&sMode, 0, sizeof(VDSwitchInfoRec) );
-
- DMListIndexType nNumModes;
- DMListType pModes;
- DMDisplayModeListIteratorUPP uppMLI;
- DisplayIDType nDisplayID;
- OSErr err;
-
- err = DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false);
- wxASSERT(err == noErr);
-
- //Create a new list...
- err = DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes);
- wxASSERT_MSG(err == noErr, wxT("Could not create a new display mode list") );
-
- uppMLI = NewDMDisplayModeListIteratorUPP(DMModeInfoProc);
- wxASSERT(uppMLI);
-
- DMModeInfoRec sModeInfo;
- sModeInfo.bMatched = false;
- sModeInfo.pMode = &mode;
- unsigned int i;
- for(i = 0; i < nNumModes; ++i)
- {
- err = DMGetIndexedDisplayModeFromList(pModes, i, NULL, uppMLI, &sModeInfo);
- wxASSERT(err == noErr);
-
- if (sModeInfo.bMatched == true)
- {
- sMode = sModeInfo.sMode;
- break;
- }
- }
- if(i == nNumModes)
- return false;
-
- DisposeDMDisplayModeListIteratorUPP(uppMLI);
-
- err = DMDisposeList(pModes);
- wxASSERT(err == noErr);
-
- // For the really paranoid -
- // unsigned long flags;
- // Boolean bok;
- // wxASSERT(noErr == DMCheckDisplayMode(m_priv->m_hndl, sMode.csData,
- // sMode.csMode, &flags, NULL, &bok));
- // wxASSERT(bok);
-
- Handle hDisplayState;
- if (DMBeginConfigureDisplays(&hDisplayState) != noErr)
- {
- wxLogSysError(wxT("Could not lock display for display mode changing!"));
- return false;
- }
-
- unsigned long dwBPP = (unsigned long) mode.bpp;
- if (DMSetDisplayMode(m_priv->m_hndl, sMode.csData,
- (unsigned long*) &(dwBPP), NULL
- //(unsigned long) &sMode
- , hDisplayState
- ) != noErr)
- {
- DMEndConfigureDisplays(hDisplayState);
- wxMessageBox(wxString::Format(wxT("Could not set the display mode")));
- return false;
- }
- DMEndConfigureDisplays(hDisplayState);
- }
- else //DM 1.0, 1.2, 1.x
- {
- wxLogSysError(wxString::Format(wxT("Monitor gravitation not supported yet. dwDMVer:%u"),
- (unsigned int) dwDMVer));
- return false;
- }
-
- return true;