home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-12 | 2.8 KB | 103 lines | [TEXT/KAHL] |
- //----------------------------------------------------------------------------------
- // File : miscCDEF.c
- // Date : November 2,1991
- // Author : Jim Stout
- // Purpose : support routines CDEFs.
- //----------------------------------------------------------------------------------
-
- #include <GestaltEqu.h>
- #include <Traps.h>
- #include "miscCDEF.h"
-
- //----------------------------------------------------------------------------------
- // Get the pixel depth of the current GDevice
- //----------------------------------------------------------------------------------
- short getPixDepth(Rect *r)
- {
- Rect gRect, iRect;
- GDHandle gDev;
- short thisDepth, pixDepth = 32;
-
- if(!trapAvailable(_GetDeviceList)) // Must have Device Mgr
- return(1);
-
- gRect = *r;
-
- LocalToGlobal((Point *)&gRect.top);
- LocalToGlobal((Point *)&gRect.bottom);
-
- gDev = GetDeviceList();
- while(gDev) {
- if(SectRect(&gRect, &(*gDev)->gdRect, &iRect) &&
- TestDeviceAttribute(gDev,screenDevice) &&
- TestDeviceAttribute(gDev,screenActive)) {
-
- thisDepth = (*(*gDev)->gdPMap)->pixelSize;
- if(thisDepth < pixDepth)
- pixDepth = thisDepth;
- }
- gDev = GetNextDevice(gDev);
- }
- return(pixDepth);
- }
-
- //----------------------------------------------------------------------------------
- // Use Gestalt to find out the MacOS version.
- //----------------------------------------------------------------------------------
- short getOSVers()
- {
- OSErr err;
- short ret=0x0600;
- long gResult;
-
- if(trapAvailable(_Gestalt)) { // is Gestalt available ?
- err = Gestalt(gestaltSystemVersion,&gResult);
- if(err == noErr)
- ret = LoWord(gResult);
- }
- return(ret);
- }
- //----------------------------------------------------------------------------------
- // Generic routine to see if a given trap is available
- //----------------------------------------------------------------------------------
-
- Boolean trapAvailable(theTrap)
- short theTrap;
- {
- TrapType tType;
-
- tType = getTrapType(theTrap);
-
- if(tType == ToolTrap) {
- theTrap &= 0x07ff;
- if(theTrap >= numToolBoxTraps())
- theTrap = _Unimplemented;
- }
- return(( NGetTrapAddress(theTrap, tType) !=
- NGetTrapAddress(_Unimplemented, ToolTrap) ));
- }
-
- //----------------------------------------------------------------------------------
- // Needed for "trapAvailable" routine
- //----------------------------------------------------------------------------------
-
- TrapType getTrapType(theTrap)
- short theTrap;
- {
- if((theTrap &= 0x0800))
- return(ToolTrap);
- return(OSTrap);
- }
-
- //----------------------------------------------------------------------------------
- // Needed for "trapAvailable" routine
- //----------------------------------------------------------------------------------
-
- short numToolBoxTraps()
- {
- if(NGetTrapAddress(_InitGraf, ToolTrap) ==
- NGetTrapAddress(0xaa6e, ToolTrap))
- return(0x0200);
- return(0x0400);
- }
-