Exemplo n.º 1
0
wxVideoMode wxDisplay::GetCurrentMode() const
{
    unsigned long dwDMVer;
    wxVideoMode RetMode;
    
    Gestalt(gestaltDisplayMgrVers, (long*) &dwDMVer);    
    //Check DM version (for backward compatibility only - 7.5.3+ use 2.0)
    if (dwDMVer >= 0x020000) //version 2?
    {
    	VDSwitchInfoRec sMode; //Note - csMode member also contains the bit depth
    	if (DMGetDisplayMode(m_priv->m_hndl, &sMode) == noErr) 
    	{
    	    DMListIndexType nNumModes;
    	    DMListType pModes;
    		DMDisplayModeListIteratorUPP uppMLI;
    	    DisplayIDType nDisplayID;

    	    wxASSERT(DMGetDisplayIDByGDevice(m_priv->m_hndl, &nDisplayID, false) == noErr);
    	    //Create a new list...
    	    wxASSERT_MSG(DMNewDisplayModeList(nDisplayID, NULL, NULL, &nNumModes, &pModes) == noErr,
    				  wxT("Could not create a new display mode list") );
    		
    		uppMLI = NewDMDisplayModeListIteratorUPP(DMModeTransProc);
    		wxASSERT(uppMLI);

    		DMModeTransRec sModeInfo;
    		sModeInfo.bMatched = false;
    		sModeInfo.psMode = &sMode;
    		for (DMListIndexType i = 0; i < nNumModes; ++i)
    		{
    			wxASSERT(DMGetIndexedDisplayModeFromList(pModes, i, NULL,
    											uppMLI, &sModeInfo) == noErr);

    			if ( sModeInfo.bMatched == true )
    			{
    				RetMode = sModeInfo.Mode;
    				break;
    			}
    		}

    	    DisposeDMDisplayModeListIteratorUPP(uppMLI);
    	    wxASSERT(DMDisposeList(pModes) == noErr);
    	}
    	else //Can't get current mode?
    	{
    		wxLogSysError(wxString::Format(wxT("Couldn't obtain current display mode!!!\ndwDMVer:%u"),
    								(unsigned int) dwDMVer));
    	}
    }
    else //DM ver 1
    {
    	wxLogSysError(wxString::Format(wxT("Display Manager Version %u Not Supported!  Present? %s"),
    				(unsigned int) dwDMVer / 0x10000,
    				(dwDMVer & (1 << gestaltDisplayMgrPresent) ? wxT("Yes") : wxT("No")) )
    	             );
    }
	 
    return RetMode;
}
Exemplo n.º 2
0
OSErr RVGetCurrentVideoSetting (VideoRequestRecPtr requestRecPtr)
{
	unsigned long		displayMgrVersion;
	OSErr				error = paramErr;
	CntrlParam			pBlock;
	VDSwitchInfoRec		switchInfo;
	AuxDCEHandle		theDCE;
	VDSwitchInfoRec		videoMode;		

	requestRecPtr->availBitDepth			= 0;	// init to default - you can do it if it is important to you
	requestRecPtr->availHorizontal			= 0;
	requestRecPtr->availVertical			= 0;
	requestRecPtr->availFlags				= 0;
	requestRecPtr->displayMode				= -1; 
	requestRecPtr->depthMode				= -1;
	requestRecPtr->switchInfo.csMode		= 0;
	requestRecPtr->switchInfo.csData		= 0;
	requestRecPtr->switchInfo.csPage		= 0;
	requestRecPtr->switchInfo.csBaseAddr	= 0;
	requestRecPtr->switchInfo.csReserved	= 0;
	
	Gestalt(gestaltDisplayMgrVers, (long*)&displayMgrVersion);
	if (requestRecPtr->screenDevice)
	{
		if (displayMgrVersion >= 0x00020000)
		{	// get the info the DM 2.0 way
			error = DMGetDisplayMode(requestRecPtr->screenDevice, &switchInfo);
			if (noErr == error)
			{
				requestRecPtr->depthMode			= switchInfo.csMode;
				requestRecPtr->displayMode			= switchInfo.csData; 
				requestRecPtr->switchInfo.csMode	= switchInfo.csMode;
				requestRecPtr->switchInfo.csData	= switchInfo.csData;
			}
			return (error);	// we (maybe) set the world back to a known setting
		}
		else
		{	// get the info the DM 1.0 way
			videoMode.csMode = -1;		// init to bogus value
			videoMode.csData = -1;		// init to bogus value			
			pBlock.ioNamePtr = nil;
			pBlock.ioCRefNum = (*(requestRecPtr->screenDevice))->gdRefNum;
			pBlock.csCode = cscGetCurMode;
			*(Ptr *)&pBlock.csParam[0] = (Ptr)&videoMode;
				
			error = PBStatusSync((ParmBlkPtr )&pBlock);	// ask the driver first....since we trust it the most
				
			if ( noErr == error && ((-1 == videoMode.csMode) || (-1 == videoMode.csData)) )
				error = statusErr;
			
			if (noErr != error)	// if the driver has no clue fill it videoMode by hand as a last resort
			{	
				theDCE = (AuxDCEHandle)GetDCtlEntry((*(requestRecPtr->screenDevice))->gdRefNum);
				
				if( theDCE )
				{
					videoMode.csData = (unsigned char)(*theDCE)->dCtlSlotId; 
					videoMode.csMode = (*(requestRecPtr->screenDevice))->gdMode;
					error = noErr;
				}
			}
			if (noErr == error)	// Set our data
			{
				requestRecPtr->displayMode			= videoMode.csData; 
				requestRecPtr->depthMode			= videoMode.csMode;
				requestRecPtr->switchInfo.csMode	= videoMode.csMode;
				requestRecPtr->switchInfo.csData	= videoMode.csData;
			}
			return (error);	// we (maybe) set the world back to a known setting
		}
	}
	return (-1);
}