OSErr RVRequestVideoSetting (VideoRequestRecPtr requestRecPtr) { Boolean displayMgrPresent; short iCount = 0; // just a counter of GDevices we have seen DMDisplayModeListIteratorUPP myModeIteratorProc = nil; // for DM2.0 searches SpBlock spBlock; Boolean suppliedGDevice; DisplayIDType theDisplayID; // for DM2.0 searches DMListIndexType theDisplayModeCount; // for DM2.0 searches DMListType theDisplayModeList; // for DM2.0 searches long value = 0; GDHandle walkDevice = nil; // for everybody Gestalt(gestaltDisplayMgrAttr,&value); displayMgrPresent=value&(1<<gestaltDisplayMgrPresent); displayMgrPresent=displayMgrPresent && (SVersion(&spBlock)==noErr); // need slot manager if (displayMgrPresent) { // init the needed data before we start if (requestRecPtr->screenDevice) // user wants a specifc device? { walkDevice = requestRecPtr->screenDevice; suppliedGDevice = true; } else { walkDevice = DMGetFirstScreenDevice (dmOnlyActiveDisplays); // for everybody suppliedGDevice = false; } myModeIteratorProc = NewDMDisplayModeListIteratorProc(ModeListIterator); // for DM2.0 searches // Note that we are hosed if somebody changes the gdevice list behind our backs while we are iterating.... // ...now do the loop if we can start if( walkDevice && myModeIteratorProc) do // start the search { iCount++; // GDevice we are looking at (just a counter) if( noErr == DMGetDisplayIDByGDevice( walkDevice, &theDisplayID, false ) ) // DM1.0 does not need this, but it fits in the loop { theDisplayModeCount = 0; // for DM2.0 searches if (noErr == DMNewDisplayModeList(theDisplayID, 0, 0, &theDisplayModeCount, &theDisplayModeList) ) { // search NuBus & PCI the new kool way through Display Manager 2.0 GetRequestTheDM2Way (requestRecPtr, walkDevice, myModeIteratorProc, theDisplayModeCount, &theDisplayModeList); DMDisposeList(theDisplayModeList); // now toss the lists for this gdevice and go on to the next one } else { // search NuBus only the old disgusting way through the slot manager GetRequestTheDM1Way (requestRecPtr, walkDevice); } } } while ( !suppliedGDevice && nil != (walkDevice = DMGetNextScreenDevice ( walkDevice, dmOnlyActiveDisplays )) ); // go until no more gdevices if( myModeIteratorProc ) DisposeRoutineDescriptor(myModeIteratorProc); return (noErr); // we were able to get the look for a match } return (-1); // return a generic error }
//-------------------------------------------------------------- // // Implementation of sample code // //-------------------------------------------------------------- OSErr RVSetVideoRequest (VideoRequestRecPtr requestRecPtr) { GDHandle aMonitor; Boolean displayMgrPresent; unsigned long displayMgrVersion; OSErr err; Boolean isColor; long value = 0; Gestalt(gestaltDisplayMgrVers, (long*)&displayMgrVersion); Gestalt(gestaltDisplayMgrAttr,&value); displayMgrPresent=value&(1<<gestaltDisplayMgrPresent); if (displayMgrPresent) { if (requestRecPtr->displayMode && requestRecPtr->depthMode) { if (requestRecPtr->availBitDepth == 1) // Based on avail bit depth, isColor = KMonoDev; // set the device to a mono device, or else isColor = kColorDev; // set the device to a color device SetDeviceAttribute(requestRecPtr->screenDevice,gdDevType,isColor); // see how many monitors we have, aMonitor will be nil if we have only one. aMonitor = DMGetFirstScreenDevice (dmOnlyActiveDisplays); // get the first guy aMonitor = DMGetNextScreenDevice ( aMonitor, dmOnlyActiveDisplays ); // get the next guy if (nil == aMonitor || displayMgrVersion >= 0x00020000) { // only call DMSetDisplayMode if we have one monitor or DM2.0 is installed // since DM1.0 does not automatically gravitate monitors and our gravitate code // is not implemented. err = DMSetDisplayMode( requestRecPtr->screenDevice, // GDevice requestRecPtr->displayMode, // DM1.0 uses this &requestRecPtr->depthMode, // DM1.0 uses this (unsigned long) &(requestRecPtr->switchInfo), // DM2.0 uses this rather than displayMode/depthMode combo nil); if (noErr == err) { // Do the monitor gravitate here if we are using a version less than DM2.0 if (displayMgrVersion < 0x00020000) GravitateMonitors (); } else if (kDMDriverNotDisplayMgrAwareErr == err) { // DM not supported by driver, so all we can do is set the bit depth err = SetDepth (requestRecPtr->screenDevice, requestRecPtr->depthMode, gdDevType, isColor); } } else { // we have more than one monitor and DM1.0 is installed, so all we can do is set the bit depth err = SetDepth (requestRecPtr->screenDevice, requestRecPtr->depthMode, gdDevType, isColor); } return (err); // we did try to set the request } } return (-1); // return a generic error }
size_t wxDisplayBase::GetCount() { GDHandle hndl; size_t num = 0; hndl = DMGetFirstScreenDevice(true); while(hndl) { num++; hndl = DMGetNextScreenDevice(hndl, true); } return num; }
wxDisplay::wxDisplay(size_t index) : wxDisplayBase ( index ), m_priv ( new wxDisplayMacPriv() ) { GDHandle hndl; hndl = DMGetFirstScreenDevice(true); m_priv->m_hndl = NULL; while(hndl) { if (index == 0) { m_priv->m_hndl = hndl; } index--; hndl = DMGetNextScreenDevice(hndl, true); } }
int wxDisplayBase::GetFromPoint(const wxPoint &p) { GDHandle hndl; size_t num = 0; hndl = DMGetFirstScreenDevice(true); while(hndl) { Rect screenrect = (*hndl)->gdRect; if (p.x >= screenrect.left && p.x <= screenrect.right && p.y >= screenrect.top && p.y <= screenrect.bottom) { return num; } num++; hndl = DMGetNextScreenDevice(hndl, true); } return -1; }