home *** CD-ROM | disk | FTP | other *** search
- // This file contains useful routines for loading
- // common resource data types.
- //
- // 9/16/94 david first cut
- // 9/20/95 david improved comments
-
-
- #include <Errors.h>
- #include <Resources.h>
- #include <TextUtils.h>
- #include "resourceUtils.h"
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE TYPEDEFS
- |**| ==============================================================================
- \**/
- typedef struct OSTypeList
- {
- short count ; // 1-based count of structs to follow
- struct
- {
- OSType type ;
- Str27 string ;
- } entry[];
- } OSTypeList, *OSTypeListPtr, **OSTypeListHdl ;
-
-
-
- /**\
- |**| ==============================================================================
- |**| PUBLIC FUNCTIONS
- |**| ==============================================================================
- \**/
-
-
- /*------------------------------------------------------------------------------*\
- GetRect
- *------------------------------------------------------------------------------*
- This routine loads a 'RECT' resource.
- If the resource id can't be found then it return the rest {0,0,0,0}.
- \*------------------------------------------------------------------------------*/
- Rect GetRect ( short id )
- {
- Handle rectHndl ;
- Rect rect = {0,0,0,0} ;
-
- rectHndl = GetResource( 'RECT', id ) ;
- if (rectHndl != nil )
- {
- rect = **((Rect**)(rectHndl)) ;
- ReleaseResource( rectHndl ) ;
- }
- return rect ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- GetStringPtr
- *------------------------------------------------------------------------------*
- This routine loads a 'STR ' resource.
- It is similar to the GetString routine except that it returns a StringPtr
- instead of a StringHandle.
- \*------------------------------------------------------------------------------*/
- OSErr GetStringPtr ( short id, StringPtr dest )
- {
- StringHandle strHndl ;
-
- strHndl = GetString( id ) ;
- if (!strHndl) return ResError() ;
-
- HLock( (Handle)strHndl ) ;
- BlockMove( *strHndl, dest, (*strHndl)[0]+1) ;
- ReleaseResource( (Handle)strHndl ) ;
- return noErr ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- GetErrStringPtr
- *------------------------------------------------------------------------------*
- This routine loads a 'Estr' resource.
- It is similar to the GetString routine except that it returns a StringPtr
- instead of a StringHandle.
- \*------------------------------------------------------------------------------*/
- OSErr GetErrStringPtr ( short id, StringPtr dest )
- {
- Handle strHndl ;
-
- strHndl = GetResource( 'Estr', id ) ;
- if (!strHndl) return ResError() ;
-
- HLock( strHndl ) ;
- BlockMove( *strHndl, dest, (*strHndl)[0]+1) ;
- ReleaseResource( strHndl ) ;
- return noErr ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- GetOSTypeListStringPtr
- *------------------------------------------------------------------------------*
- This routine loads a 'OST#' resource and loops through it looking
- for the string that coresponds to the type parameter.
- \*------------------------------------------------------------------------------*/
- OSErr GetOSTypeListStringPtr ( short id, OSType type, StringPtr dest )
- {
- short i, count ;
- OSTypeListHdl list ;
- StringPtr src ;
-
- list = (OSTypeListHdl) GetResource('OST#', id) ;
- if (list==nil) return ResError() ;
-
- // try to find the type in the list
- count = (**list).count ;
- for (i=0; i<count; i++ )
- if ((**list).entry[i].type == type )
- {
- src = (StringPtr)&((**list).entry[i].string);
- HLock( (Handle)list ) ;
- BlockMove(src, dest, src[0]+1) ;
- ReleaseResource( (Handle)list ) ;
- return noErr ;
- }
-
- // we didnt find a match
- ReleaseResource( (Handle)list ) ;
- return paramErr ;
- }
-