uuUndo/DSUtils.c

1 line
8.0 KiB
C
Raw Normal View History

2015-02-06 08:56:41 +00:00
/****************************************************************************** ** ** Project Name: DropShell ** File Name: DSUtils.c ** ** Description: Utility routines that may be useful to DropBoxes ** ******************************************************************************* ** A U T H O R I D E N T I T Y ******************************************************************************* ** ** Initials Name ** -------- ----------------------------------------------- ** LDR Leonard Rosenthol ** ******************************************************************************* ** R E V I S I O N H I S T O R Y ******************************************************************************* ** ** Date Time Author Description ** -------- ----- ------ --------------------------------------------- ** 12/09/91 LDR Added the Apple event routines ** 11/24/91 LDR Original Version ** ******************************************************************************/ #include "DSGlobals.h" #include "DSUtils.h" /* This routine is used to properly center an Alert before showing. It is per Human Interface specs by putting it in the top 1/3 of screen. NOTE: This same technique can be used with DLOG resources as well. */ #pragma segment Main void CenterAlert ( short theID ) { short theX, theY; AlertTHndl theAlertHandle; Rect screen, alrt; theAlertHandle = (AlertTHndl) GetResource ( 'ALRT', theID ); if ( theAlertHandle != NULL ) { HLock ((Handle) theAlertHandle ); alrt = (*theAlertHandle)->boundsRect; screen = qd.screenBits.bounds; theX = (( screen.right - screen.left ) - (alrt.right - alrt.left )) >> 1; theY = (( screen.bottom - screen.top ) + GetMBarHeight () - (alrt.bottom - alrt.top)) >> 1; theY -= ( screen.bottom - screen.top ) >> 2; /* this moves it up for better viewing! */ OffsetRect ( &(*theAlertHandle)->boundsRect, theX - alrt.left, theY - alrt.top ); } SetCursor ( &qd.arrow ); // change this for code resources! } /* This routine is just a quick & dirty error reporter */ #pragma segment Main void ErrorAlert ( short stringListID, short stringIndexID, short errorID ) { #define kAlertID 200 Str255 param, errorStr; NumToString ( errorID, errorStr ); GetIndString ( param, stringListID, stringIndexID ); ParamText ( param, errorStr, NULL, NULL ); CenterAlert ( kAlertID ); (void) Alert ( kAlertID, NULL ); } /*** These routines use the Process Manager to give you information about yourself ***/ #pragma segment Main void GetAppName(Str255 appName) { OSErr err; ProcessInfoRec info; ProcessSerialNumber curPSN; err = GetCurrentProcess(&curPSN); info.processInfoLength = sizeof(ProcessInfoRec); // ALWAYS USE sizeof! info.processName = appName; // so it returned somewhere info.processAppSpec = NULL; // I don't care! err = GetProcessInformation(&curPSN, &info); } #pragma segment Main void GetAppFSSpec(FSSpec *appSpec) { OSErr err; Str255 appName; ProcessInfoRec info; ProcessSerialNumber curPSN; err = GetCurrentProcess(&curPSN); info.processInfoLength = sizeof(ProcessInfoRec); // ALWAYS USE sizeof! info.processName = appName; // so it returned somewhere info.processAppSpec = appSpec; // so it can get returned! err = GetProcessInformation(&curPSN, &info); } /* <20><><EFBFBD> Apple event routines begin here <20><><EFBFBD> */ /* This routine will create a targetDesc for sending to self. We take IM VI's advice and use the typePSN form with kCurrentProcess as the targetPSN. */ OSErr GetTargetFromSelf (AEAddressDesc *targetDesc) { ProcessSerialNumber psn; psn.highLongOfPSN = 0; psn.lowLongOfPSN = kCurrentProcess; return( AECreateDesc(typeProcessSerialNumber, (Ptr)&psn, sizeof(ProcessSerialNumber), targetDesc) ); } /* This routine will create a targetDesc using the apps signature */ OSErr GetTargetFromSignature (OSType processSig, AEAddressDesc *targetDesc) { return( AECreateDesc(typeApplSignature, (Ptr)&processSig, sizeof(processSig), targetDesc) ); } /* This routine will create a tar