home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacFormat España 21
/
macformat_21.iso
/
Shareware
/
Programación
/
VideoToolbox
/
VideoToolboxSources
/
GetScreenDevice.c
< prev
next >
Wrap
Text File
|
1995-10-14
|
8KB
|
239 lines
/* GetScreenDevice.c
device=GetScreenDevice(n);
returns a handle to the n-th screen, where the MainDevice is the zero-th screen.
This is similar, but not identical, to the screen number in the Monitors
Control panel.
n=GetScreenIndex(device);
returns the inverse of GetScreenDevice().
slot=GetDeviceSlot(device);
gets the "slot" for any screen device.
device=SlotToScreenDevice(n);
returns a handle to the screen device in slot n.
device=GetWindowDevice(window);
returns GDHandle of screen with largest intersection with the window's content.
GDHandle GetDeviceByRefNum(int n);
GDHandle GetRectDevice(Rect *r);
void LocalToGlobalRect(Rect *r);
void GlobalToLocalRect(Rect *r);
Copyright © 1989-1995 Denis G. Pelli
HISTORY:
3/20/90 dgp make compatible with MPW C.
3/22/90 dgp changed GetDeviceSlot to use the AuxDCEHandle instead of deducing it
from the baseAddr of the PixMap. This is a cleaner way to do it.
4/9/90 dgp eliminated #define for Mainscrn mispelling in Color.h
10/17/90 dgp Added AddressToScreenDevice() for compatibility with built-in video on
the Mac IIci, IIsi, and LC.
10/18/90 dgp Added LocalToGlobalRect() and GetWindowDevice().
8/24/91 dgp Made compatible with THINK C 5.0.
2/1/92 dgp Fixed bugs in GetWindowDevice() which resulted in returning garbage GDHandle.
3/3/92 dgp In GetScreenDevice(), skip inactive screens.
8/20/92 dgp expanded comments of GetDeviceSlot(), noting that it works even with
built-in video, e.g. on Mac IIci.
8/26/92 dgp GetDeviceSlot() now returns -1 if none, since zero is a legal slot.
GetScreenDevice() first checks for 8-bit QuickDraw().
9/10/92 dgp Actually implemented the 8/26 change instead of just changing the
documentation. Oops.
4/17/93 dgp Deleted obsolete AddressToSlot and AddressToScreenDevice.
5/21/93 dgp Fixed GetWindowDevice() to support GWorld's.
8/14/93 dgp Based on answer from DEVSUPPORT, I cleaned up GetWindowDevice().
4/11/94 dgp Added GetRectDevice() based on code extracted from GetWindowDevice().
11/30/94 dgp added GetDeviceByRefNum().
6/1/95 dgp moved LocalToGlobalRect() and GlobalToLocalRect() to CenterRectInRect.c
10/4/95 dgp GetDeviceSlot() nows checks for presence of Slot Manager and returns -1 if it's absent.
10/14/95 dgp added GetDeviceSlotName(), which works on all Macs, including PCI.
*/
#include "VideoToolbox.h"
void GetVideoProperties(GDHandle device,char *slotName,char *cardName,char *modelName);
char *GetDeviceSlotName(GDHandle device);
GDHandle GetScreenDevice(int n)
// Returns a handle to the n-th screen, where the MainDevice is the zero-th screen.
// Returns NULL if request can't be satisfied.
{
GDHandle device;
int i,error;
long value;
if(n<0)return NULL;
error=Gestalt(gestaltQuickdrawVersion,&value);
if(error || value<gestalt8BitQD)return NULL; // need 8-bit quickdraw
if(n==0) return GetMainDevice();
device=GetDeviceList();
i=0;
while(device!=NULL){
if (TestDeviceAttribute(device,screenDevice)
&& !TestDeviceAttribute(device,mainScreen)
&& TestDeviceAttribute(device,screenActive)){
i++;
if(i==n)break;
}
device = GetNextDevice(device);
}
return device;
}
GDHandle GetDeviceByRefNum(int n)
{
int j;
GDHandle device;
for(j=0;;j++){
device=GetScreenDevice(j);
if(device==NULL || n==(**device).gdRefNum)break;
}
return device;
}
int GetScreenIndex(GDHandle device)
// Inverse of GetScreenDevice(). Returns -1 if request can't be satisfied.
{
int i,error;
long value;
error=Gestalt(gestaltQuickdrawVersion,&value);
if(error || value<gestalt8BitQD)return 0;
if(device==NULL)return -1;
for(i=0;i<16;i++)if(device==GetScreenDevice(i))return i;
return -1;
}
short int GetDeviceSlot(GDHandle device)
// Gets the "slot" for any screen device, even if it's built-in video, e.g. on Mac
// IIci or Quadra. See 1992 Inside Mac "Processes" page 4-11. Returns -1 if none.
// Zero is a legal slot for built-in video devices.
// WARNING: gives nonsense answer on PCI Macs. Use GetDeviceSlotName() instead.
{
AuxDCEHandle myAuxDCEHandle;
SpBlock spBlock;
Boolean slotMgrPresent;
if(TrapAvailable(_SlotManager))slotMgrPresent=(SVersion(&spBlock)==noErr);
else slotMgrPresent=0;
if(!slotMgrPresent || device==NULL || (*device)->gdRefNum==0)return -1;
myAuxDCEHandle=(AuxDCEHandle) GetDCtlEntry((**device).gdRefNum);
return ((**myAuxDCEHandle).dCtlSlot);
}
char *GetDeviceSlotName(GDHandle device)
// Gets the "slot" name for any screen device, even built-in video, on Macs with NuBus,
// PCI bus, and no bus. Returns "" if none.
// Zero is a legal slot for built-in video devices.
{
static char slotName[32]="";
char cardName[32],modelName[32];
if(device==NULL || (*device)->gdRefNum==0)return "";
GetVideoProperties(device,slotName,cardName,modelName);
if(strlen(cardName)==0)sprintf(slotName,"%d",(int)GetDeviceSlot(device));
return slotName;
}
GDHandle SlotToScreenDevice(int n)
// Returns a handle to the screen device in slot n.
// Returns NULL if request can't be satisfied.
{
GDHandle device;
device=GetDeviceList();
while(device!=NULL) {
if (TestDeviceAttribute(device,screenDevice) &&
GetDeviceSlot(device)==n)
break;
device=GetNextDevice(device);
}
return device;
}
GDHandle GetWindowDevice(WindowPtr window)
// For on-screen window, returns GDHandle of screen with largest intersection with the
// window's content.
// For off-screen window (i.e. GWorld), it returns the GDHandle of the associated device.
{
Rect r;
WindowPtr oldWindow;
long qD;
if(window==NULL)return NULL;
Gestalt(gestaltQuickdrawVersion,&qD);
if(qD>=gestalt32BitQD && (((CWindowPtr)window)->portVersion&0xc001)==0xc001){
// It's a GWorld iff the portVersion has both high bits set (cGrafPort) and
// the low bit set (GWorld). See Apple Tech Note “RowBytes Revealed II”.
return GetGWorldDevice((GWorldPtr)window);
}
r=window->portRect;
GetPort(&oldWindow);
SetPort(window);
LocalToGlobalRect(&r);
SetPort(oldWindow);
return GetRectDevice(&r);
}
GDHandle GetRectDevice(Rect *r)
// Returns GDHandle of screen with largest intersection with the global rect.
{
Rect overlap;
GDHandle device,dominantDevice=NULL;
long area,greatestArea;
long qD;
if(r==NULL)return NULL;
Gestalt(gestaltQuickdrawVersion,&qD);
if(qD<gestalt8BitQD)return NULL; // need 8-bit quickdraw
device=GetDeviceList();
greatestArea=0;
while(device!=NULL){
if(TestDeviceAttribute(device,screenDevice)
&& TestDeviceAttribute(device,screenActive)){
SectRect(r,&(*device)->gdRect,&overlap);
area=(long)(overlap.right-overlap.left)*(overlap.bottom-overlap.top);
if(area>greatestArea){
greatestArea=area;
dominantDevice=device;
}
}
device=GetNextDevice(device);
}
return dominantDevice;
}
#if 0
#if UNIVERSAL_HEADERS
#ifndef __DISPLAYS__
#include <Displays.h>
#endif
#else
enum{kDMDriverNotDisplayMgrAwareErr = -6228};
extern pascal OSErr DMSetDisplayMode(GDHandle theDevice,unsigned long mode
,unsigned long *depthMode,unsigned long reserved,Handle displayState)
={0x303C,0x0A11,0xABEB};
extern pascal OSErr DMCheckDisplayMode(GDHandle theDevice,unsigned long mode
,unsigned long depthMode,unsigned long *switchFlags,unsigned long reserved
,Boolean *modeOk)={0x303C,0x0C12,0xABEB};
enum {
gestaltDisplayMgrAttr = 'dply', /* Display Manager attributes */
gestaltDisplayMgrPresent = 0 /* True if Display Mgr is present */
};
#endif
/*
These enum definitions for use with the cscGetNextResolution driver status call
are taken from the A7 draft (Feb 10,'95) of Apple's Designing PCI Cards and Drivers for
Power Mac Computers. Undoubtedly these enum definitions will appear in some future
version of Video.h, perhaps with CodeWarrior 6, at which time they can be deleted from here.
*/
enum{
kDisplayModeIDCurrent=0
,kDisplayModeIDInvalid=0xffffffff
,kDisplayModeIDFindFirstResolution=0xfffffffe
,kDisplayModeIDNoMoreResolutions=0xfffffffd
};
#endif