2001-10-19 19:41:13 +00:00
# include "ResourceObject.h"
# include "Errors.h"
# include "string.h"
/*** CREATOR ***/
2007-02-20 00:03:43 +00:00
ResourceObject : : ResourceObject ( FileWindowPtr owner )
2001-10-19 19:41:13 +00:00
{
// set contents to zero
2007-02-20 00:03:43 +00:00
memset ( this , 0 , sizeof ( ResourceObject ) ) ;
2001-10-19 19:41:13 +00:00
file = owner ;
nameIconRgn = NewRgn ( ) ;
}
/*** DESTRUCTOR ***/
2007-02-20 00:03:43 +00:00
ResourceObject : : ~ ResourceObject ( void )
2001-10-19 19:41:13 +00:00
{
2007-02-20 00:03:43 +00:00
if ( nameIconRgn ) DisposeRgn ( nameIconRgn ) ;
if ( data ) DisposeHandle ( data ) ;
2001-10-19 19:41:13 +00:00
}
/*** RETAIN ***/
2007-02-20 00:03:43 +00:00
OSStatus ResourceObject : : Retain ( void )
2001-10-19 19:41:13 +00:00
{
OSStatus error = noErr ;
2007-02-20 00:03:43 +00:00
/* if(retainCount == 0)
2001-10-19 19:41:13 +00:00
{
2007-02-20 00:03:43 +00:00
if ( dataFork )
2001-10-19 19:41:13 +00:00
{
// open file for reading
SInt16 refNum ;
2007-02-20 00:03:43 +00:00
error = FSpOpenDF ( file - > GetFileSpec ( ) , fsRdPerm , & refNum ) ;
if ( error )
2001-10-19 19:41:13 +00:00
{
2007-02-20 00:03:43 +00:00
DisplayError ( " \ pData fork could not be read " , " \ pThis file appears to be corrupted. Although the resources could be read in correctly, the data fork could not be found. Please run Disk First Aid to correct the problem. " ) ;
2001-10-19 19:41:13 +00:00
return error ;
}
// get new handle
2007-02-20 00:03:43 +00:00
data = NewHandleClear ( size ) ;
if ( ! data | | MemError ( ) )
2001-10-19 19:41:13 +00:00
{
2007-02-20 00:03:43 +00:00
DisplayError ( " \ pNot enough memory to read data fork " , " \ pPlease quit other applications and try again. " ) ;
FSClose ( refNum ) ;
2001-10-19 19:41:13 +00:00
return memFullErr ;
}
// read data fork
2007-02-20 00:03:43 +00:00
HLock ( data ) ;
error = FSRead ( refNum , ( long * ) & size , * data ) ;
HUnlock ( data ) ;
FSClose ( refNum ) ;
2001-10-19 19:41:13 +00:00
}
else
{
2007-02-20 00:03:43 +00:00
LoadResource ( data ) ;
2001-10-19 19:41:13 +00:00
}
}
*/ retainCount + + ;
return error ;
}
/*** RELEASE ***/
2007-02-20 00:03:43 +00:00
void ResourceObject : : Release ( void )
2001-10-19 19:41:13 +00:00
{
2007-02-20 00:03:43 +00:00
if ( retainCount > 0 )
2001-10-19 19:41:13 +00:00
{
2007-02-20 00:03:43 +00:00
/* if(retainCount == 1)
DisposeHandle ( data ) ;
2001-10-19 19:41:13 +00:00
*/ retainCount - - ;
}
}
/*** SET RESOURCE DIRTY ***/
2007-02-20 00:03:43 +00:00
void ResourceObject : : SetDirty ( Boolean value )
2001-10-19 19:41:13 +00:00
{
dirty = value ;
2007-02-20 00:03:43 +00:00
file - > SetFileDirty ( value ) ;
2001-10-19 19:41:13 +00:00
// being here indicates the resource size parameter also needs updating
2007-02-20 00:03:43 +00:00
size = GetHandleSize ( data ) ;
2001-10-19 19:41:13 +00:00
// bug: should now tell all open copies of this resource to update themselves
}
/*** RES INFO RECORD ACCESSORS ***/
2007-02-20 00:03:43 +00:00
FileWindowPtr ResourceObject : : File ( void ) { return file ; }
ResourceObjectPtr ResourceObject : : Next ( void ) { return next ; }
Boolean ResourceObject : : Dirty ( void ) { return dirty ; }
void ResourceObject : : Select ( Boolean select ) { selected = select ; }
Boolean ResourceObject : : Selected ( void ) { return selected ; }
DataBrowserItemID ResourceObject : : Number ( void ) { return number ; }
Boolean ResourceObject : : RepresentsDataFork ( void ) { return dataFork ; }
2001-10-19 19:41:13 +00:00
2007-02-20 00:03:43 +00:00
Handle ResourceObject : : Data ( void ) { return data ; }
UInt8 * ResourceObject : : Name ( void ) { return name ; }
UInt32 ResourceObject : : Size ( void ) { return size ; }
ResType ResourceObject : : Type ( void ) { return type ; }
SInt16 ResourceObject : : ID ( void ) { return resID ; }
SInt16 ResourceObject : : Attributes ( void ) { return attribs ; }