No more Carbon.

This commit is contained in:
Nate Weaver 2013-08-26 08:19:02 -05:00
parent 3a2572708e
commit 5f3978744c
40 changed files with 0 additions and 10871 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,178 +0,0 @@
#include "ResKnife.h"
#ifndef _ResKnife_Application_
#define _ResKnife_Application_
/*!
@header Application
@discussion The Application.cpp file manages all critical workings to keep the program running, these include initalizing the environment, maintaining an event queue and parsing received events. It also manages the menubar.
*/
/***********************/
/* EVENT INITALIZATION */
/***********************/
/*!
@function InitToolbox
*/
OSStatus InitToolbox( void );
/*!
@function InitMenubar
*/
OSStatus InitMenubar( void );
/*!
@function InitAppleEvents
*/
OSStatus InitAppleEvents( void );
/*!
@function InitCarbonEvents
*/
OSStatus InitCarbonEvents( void );
/*!
@function InitGlobals
*/
OSStatus InitGlobals( void );
/*****************/
/* EVENT PARSING */
/*****************/
#if !TARGET_API_MAC_CARBON
/*!
@function ParseEvents
*/
OSStatus ParseEvents( EventRecord *event );
/*!
@function ParseDialogEvents
*/
pascal Boolean ParseDialogEvents( DialogPtr dialog, EventRecord *event, DialogItemIndex *itemHit );
/*!
@function ParseOSEvents
*/
OSStatus ParseOSEvents( EventRecord *event );
#endif
/*!
@function ParseAppleEvents
*/
pascal OSErr ParseAppleEvents( const AppleEvent *event, AppleEvent *reply, SInt32 refCon );
/******************/
/* EVENT HANDLING */
/******************/
#if !TARGET_API_MAC_CARBON
/*!
@function MouseDownEventOccoured
*/
OSStatus MouseDownEventOccoured( EventRecord *event );
/*!
@function MouseUpEventOccoured
*/
OSStatus MouseUpEventOccoured( EventRecord *event );
/*!
@function KeyDownEventOccoured
*/
OSStatus KeyDownEventOccoured( EventRecord *event );
/*!
@function KeyRepeatEventOccoured
*/
OSStatus KeyRepeatEventOccoured( EventRecord *event );
/*!
@function KeyUpEventOccoured
*/
OSStatus KeyUpEventOccoured( EventRecord *event );
/*!
@function UpdateEventOccoured
*/
OSStatus UpdateEventOccoured( EventRecord *event );
/*!
@function ActivateEventOccoured
*/
OSStatus ActivateEventOccoured( EventRecord *event );
/*!
@function IdleEvent
*/
OSStatus IdleEvent( void );
#endif
/*!
@function QuitResKnife
*/
void QuitResKnife( void );
/*****************/
/* MENU HANDLING */
/*****************/
#if TARGET_API_MAC_CARBON
/*!
@function CarbonEventUpdateMenus
*/
pascal OSStatus CarbonEventUpdateMenus( EventHandlerCallRef callRef, EventRef event, void *userData );
/*!
@function CarbonEventParseMenuSelection
*/
pascal OSStatus CarbonEventParseMenuSelection( EventHandlerCallRef callRef, EventRef event, void *userData );
/*!
@function DefaultIdleTimer
*/
pascal void DefaultIdleTimer( EventLoopTimerRef timer, void *data );
#else
/*!
@function UpdateMenus
*/
OSStatus UpdateMenus( WindowRef window );
/*!
@function ParseMenuSelection
*/
OSStatus ParseMenuSelection( UInt16 menu, UInt16 item );
#endif
/****************/
/* APPLE EVENTS */
/****************/
/*!
@function AppleEventSendSelf
*/
OSStatus AppleEventSendSelf( DescType eventClass, DescType eventID, AEDescList list );
/*!
@function GotRequiredParams
*/
Boolean GotRequiredParams( const AppleEvent *event );
/*!
@function AppleEventOpen
*/
OSStatus AppleEventOpen( const AppleEvent *event );
/*!
@function AppleEventPrint
*/
OSStatus AppleEventPrint( const AppleEvent *event );
/*********************/
/* NIBÑBASED WINDOWS */
/*********************/
/*!
@function ShowAboutBox
*/
OSStatus ShowAboutBox( void );
/*!
@function ShowPrefsWindow
*/
OSStatus ShowPrefsWindow( void );
/*!
@function PrefsTabEventHandler
*/
pascal OSStatus PrefsTabEventHandler( EventHandlerCallRef handlerRef, EventRef event, void* userData );
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,121 +0,0 @@
#if defined(__MWERKS__)
#include <Resources.h>
#include <Sound.h>
#else
#include <Carbon/Carbon.h>
#endif
// enumerations
typedef enum
{
shpError = -1,
shpFinished = 0,
shpPaused = 1,
shpPlaying = 2
} SHPlayStat;
typedef enum
{
shrError = -1,
shrFinished = 0,
shrPaused = 1,
shrRecording = 2
} SHRecordStat;
// Sound Helper error codes
enum
{
kSHErrOutaChannels = 1, // No more output records are available
kSHErrBadRefNum, // Invalid reference number
kSHErrNonAsychDevice, // Input device can't handle asynchronous input
kSHErrNoRecording, // There's no recording to return
kSHErrNotRecording, // Not allowed because we're not recording
kSHErrAlreadyPaused, // Already paused
kSHErrAlreadyContinued // Already continued
};
// Contants used by the Asynchronous Sound Helper
const SInt16 kSHDefChannels = 4; // Default number of channels to preallocate
const SInt16 kSHCompleteSig = 'SH'; // Flag we use to know a "true" completion callback
const SInt32 kSHComplete = 'SHcp'; // Flag that a given channel has completed playback
const SInt16 kSHHeaderSlop = 100; // Extra bytes for the sound header when recording
const SInt16 kSHBaseNote = 60; // Middle C base note for new recordings
const SInt16 kSHSyncWaitTimeout = 60; // Ticks to sync-wait when killing the Helper
// Constants that should be in Sound.h but aren't
const SInt16 kSHNoSynth = 0; // Don't associate any synth to this channel
const SInt16 kSHNoInit = 0; // No specific initialization
const SInt8 kSHQuietNow = true; // Stop playing this sound immediately
const SInt8 kSHAsync = true; // Play asynchronously
const SInt8 kSHWait = false; // Wait for there to be enough room in the queue
// structures
typedef struct
{
SHRecordStat recordStatus; // Current record status
unsigned long totalRecordTime; // Total (maximum) record time in ms
unsigned long currentRecordTime; // Current recorded time in ms
short meterLevel; // 0..255, the current input level
} SHRecordStatusRec;
typedef struct
{
SndChannel channel; // Our sound channel
long refNum; // Our Helper ref num
Handle sound; // The sound we're playing
Fixed rate; // The rate at which a sampled sound is playing
char handleState; // The handle state to restore this handle to
Boolean inUse; // Tells whether this SHOutRec is in use
Boolean paused; // Tells whether this sound is currently paused
} SHOutRec, *SHOutPtr;
typedef struct
{
short numOutRecs; // The number of output records in outArray
SHOutRec *outArray; // Our pre-allocated output records
long nextRef; // The next available output reference number
} SHOutputVars;
typedef struct
{
long inRefNum; // Sound Input Manager's device refNum
SPB inPB; // The input parameter block
Handle inHandle; // The handle we're recording into
short headerLength; // The length of the sound's header
Boolean recording; // Tells whether we're actually recording
Boolean recordComplete; // Tells whether recording is complete
OSErr recordErr; // Error, if error terminated recording
short numChannels; // Number of channels for recording
short sampleSize; // Sample size for recording
Fixed sampleRate; // Sample rate for recording
OSType compType; // Compression type for recording
Boolean *appComplete; // Flag to caller that recording is done
Boolean paused; // Tells whether recording has been paused
} SHInputVars;
// Initialization, idle, and termination
pascal OSErr SHInitSoundHelper( Boolean *attnFlag, short numChannels );
pascal void SHIdle( void );
pascal void SHKillSoundHelper(void );
// Easy sound output
pascal OSErr SHPlayByID( short resID, long *refNum );
pascal OSErr SHPlayByHandle( Handle sound, long *refNum );
pascal OSErr SHPlayStop( long refNum );
pascal OSErr SHPlayStopAll( void );
// Advanced sound output
pascal OSErr SHPlayPause( long refNum );
pascal OSErr SHPlayContinue( long refNum );
pascal SHPlayStat SHPlayStatus( long refNum );
pascal OSErr SHGetChannel( long refNum, SndChannelPtr *channel );
// Easy sound input
pascal OSErr SHRecordStart( short maxK, OSType quality, Boolean *doneFlag );
pascal OSErr SHGetRecordedSound( Handle *theSound );
pascal OSErr SHRecordStop( void );
// Advanced sound input
pascal OSErr SHRecordPause( void );
pascal OSErr SHRecordContinue( void );
pascal OSErr SHRecordStatus( SHRecordStatusRec *recordStatus );

View File

@ -1,634 +0,0 @@
#include "DataBrowser.h"
#include "ResourceObject.h"
#include "InspectorWindow.h"
#include "Errors.h"
#include "Utility.h" // for TypeToCFString() et cetera
extern globals g;
#if TARGET_API_MAC_CARBON // CarbonLib 1.1+ or Public Beta only
/*** INITALISE DATA BROWSER ***/
OSStatus FileWindow::InitDataBrowser( void )
{
OSStatus error = noErr;
// get the db control - compatable with both CarbonLib and nib based versions
ControlID id = { kDataBrowserSignature, 0 };
GetControlByID( window, &id, &dataBrowser );
// set control ref to FileWindow
SetControlReference( dataBrowser, (long) this );
// turn off frame and focus
Boolean frame = false;
SetControlData( dataBrowser, kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, sizeof(Boolean), &frame );
#if !USE_NIBS
// add empty columns
AddDataBrowserColumn( dataBrowser, kDBNameColumn, 0 ); // save column order into prefs file: Get/SetDataBrowserUserState()
AddDataBrowserColumn( dataBrowser, kDBTypeColumn, 1 );
AddDataBrowserColumn( dataBrowser, kDBIDColumn, 2 );
AddDataBrowserColumn( dataBrowser, kDBSizeColumn, 3 );
#endif
// add callbacks
DataBrowserCallbacks theCallbacks;
theCallbacks.version = kDataBrowserLatestCallbacks;
InitDataBrowserCallbacks( &theCallbacks );
theCallbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP( DataBrowserItemData );
theCallbacks.u.v1.itemCompareCallback = NewDataBrowserItemCompareUPP( SortDataBrowser );
theCallbacks.u.v1.itemNotificationCallback = NewDataBrowserItemNotificationUPP( DataBrowserMessage );
theCallbacks.u.v1.addDragItemCallback = NewDataBrowserAddDragItemUPP( DataBrowserAddDragItem );
theCallbacks.u.v1.acceptDragCallback = NewDataBrowserAcceptDragUPP( DataBrowserAcceptDrag );
theCallbacks.u.v1.receiveDragCallback = NewDataBrowserReceiveDragUPP( DataBrowserReceiveDrag );
theCallbacks.u.v1.postProcessDragCallback = NewDataBrowserPostProcessDragUPP( DataBrowserPostProcessDrag );
SetDataBrowserCallbacks( dataBrowser, &theCallbacks );
// setup rest of browser, inc. adding all resources
DataBrowserItemID item;
for( UInt32 n = 1; n <= numResources; n++ )
{
item = n;
error = AddDataBrowserItems( dataBrowser, kDataBrowserNoItem, 1, &item, kDataBrowserItemNoProperty );
if( error ) DebugError( "\pError occoured adding resource to data browser." );
}
// add data fork if present
if( resourceMap->RepresentsDataFork() ) // requires data fork to be first in chain
{
item = kDataBrowserDataForkItem; // curently 0xFFFFFFFF
error = AddDataBrowserItems( dataBrowser, kDataBrowserNoItem, 1, &item, kDataBrowserItemNoProperty );
if( error ) DebugError( "\pError occoured adding data fork to data browser." );
}
SetDataBrowserSortProperty( dataBrowser, kDBTypeColumn );
SetDataBrowserTableViewRowHeight( dataBrowser, 16 +2 );
SetDataBrowserListViewDisclosureColumn( dataBrowser, kDBNameColumn, true );
// set up drag tracking
SetControlDragTrackingEnabled( dataBrowser, true );
return error;
}
/*** ADD DATA BROWSER COLUMN ***/
void AddDataBrowserColumn( ControlRef browser, DataBrowserPropertyID column, UInt16 position )
{
DataBrowserListViewColumnDesc columnDesc;
switch( column )
{
case kDataBrowserNameColumn:
columnDesc.propertyDesc.propertyID = kDataBrowserNameColumn;
columnDesc.propertyDesc.propertyType = kDataBrowserIconAndTextType;
columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewDefaultColumnFlags | kDataBrowserListViewSelectionColumn;
columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
columnDesc.headerBtnDesc.minimumWidth = 150;
columnDesc.headerBtnDesc.maximumWidth = 250;
columnDesc.headerBtnDesc.titleOffset = 0;
columnDesc.headerBtnDesc.titleString = CFSTR("Resource Name"); // these should be resources for ease of localisation
columnDesc.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing;
columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault;
columnDesc.headerBtnDesc.btnFontStyle.style = normal;
columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
break;
case kDataBrowserTypeColumn:
columnDesc.propertyDesc.propertyID = kDataBrowserTypeColumn;
columnDesc.propertyDesc.propertyType = kDataBrowserTextType;
columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewDefaultColumnFlags;
columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
columnDesc.headerBtnDesc.minimumWidth = (g.systemVersion < kMacOSX)? 56:72;
columnDesc.headerBtnDesc.maximumWidth = columnDesc.headerBtnDesc.minimumWidth;
columnDesc.headerBtnDesc.titleOffset = 0;
columnDesc.headerBtnDesc.titleString = CFSTR("Type"); // these should be resources for ease of localisation
columnDesc.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing;
columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
columnDesc.headerBtnDesc.btnFontStyle.just = teFlushRight;
columnDesc.headerBtnDesc.btnFontStyle.style = normal;
columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
break;
case kDataBrowserIDColumn:
columnDesc.propertyDesc.propertyID = kDataBrowserIDColumn;
columnDesc.propertyDesc.propertyType = kDataBrowserTextType;
columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewDefaultColumnFlags;
columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
columnDesc.headerBtnDesc.minimumWidth = (g.systemVersion < kMacOSX)? 56:72;
columnDesc.headerBtnDesc.maximumWidth = columnDesc.headerBtnDesc.minimumWidth;
columnDesc.headerBtnDesc.titleOffset = 0;
columnDesc.headerBtnDesc.titleString = CFSTR("ID"); // these should be resources for ease of localisation
columnDesc.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing;
columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
columnDesc.headerBtnDesc.btnFontStyle.just = teFlushRight;
columnDesc.headerBtnDesc.btnFontStyle.style = normal;
columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
break;
case kDataBrowserSizeColumn:
columnDesc.propertyDesc.propertyID = kDataBrowserSizeColumn;
columnDesc.propertyDesc.propertyType = kDataBrowserTextType;
columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewDefaultColumnFlags;
columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
columnDesc.headerBtnDesc.minimumWidth = (g.systemVersion < kMacOSX)? 56:72;
columnDesc.headerBtnDesc.maximumWidth = columnDesc.headerBtnDesc.minimumWidth;
columnDesc.headerBtnDesc.titleOffset = 0;
columnDesc.headerBtnDesc.titleString = CFSTR("Size"); // these should be resources for ease of localisation
columnDesc.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing;
columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
columnDesc.headerBtnDesc.btnFontStyle.just = teFlushRight;
columnDesc.headerBtnDesc.btnFontStyle.style = normal;
columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
break;
}
// create column and make respond to sorting
AddDataBrowserListViewColumn( browser, &columnDesc, position );
}
/*** HANDLE ITEM DATA I/O ***/
pascal OSStatus DataBrowserItemData( ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean setValue )
{
#pragma unused( setValue )
OSStatus result = noErr;
if( setValue ) return result;
FileWindowPtr file = (FileWindowPtr) GetControlReference( browser );
ResourceObjectPtr resource = file->GetResource( itemID );
if( resource == null )
DebugError( "\pNull resource returned within DataBrowserItemData()" );
switch( property )
{
case kDataBrowserItemIsEditableProperty:
if( true ) // should item be editable? (i.e. is it a name, ID or type?)
SetDataBrowserItemDataBooleanValue( itemData, true );
break;
case kDataBrowserItemIsContainerProperty:
if( resource->Type() == kIconFamilyType )
SetDataBrowserItemDataBooleanValue( itemData, true );
break;
case kDBNameColumn:
{ // icon Ñ no resource for the icon!
IconRef theIcon = null;
#if !USE_NIBS
if( itemID != kDataBrowserDataForkItem )
{
Str255 iconString;
TypeToPString( resource->Type(), iconString );
IconFamilyHandle iconFamily = (IconFamilyHandle) Get1NamedResource( kIconFamilyType, iconString );
if( iconFamily )
{
RegisterIconRefFromIconFamily( kResKnifeCreator, resource->Type(), iconFamily, &theIcon );
ReleaseResource( (Handle) iconFamily ); // when dragging a rect this call caused other columns not to be displayed !?!
}
}
#endif
if( theIcon == null )
GetIconRef( kOnSystemDisk, kResKnifeCreator, kResourceFileType, &theIcon );
SetDataBrowserItemDataIcon( itemData, theIcon );
ReleaseIconRef( theIcon );
// resource name
CFStringRef nameCFStr;
if( itemID == kDataBrowserDataForkItem )
{
#if USE_NIBS // OS 9 version is not bundled at the present time
nameCFStr = CFBundleCopyLocalizedString( CFBundleGetMainBundle(), CFSTR("Data Fork"), null, null ); // bug: doesn't actually get localized string!
#else
nameCFStr = CFSTR("Data Fork");
#endif
SetDataBrowserItemDataRGBColor( itemData, &g.textColour );
}
else if( *resource->Name() == 0x00 )
{
#if USE_NIBS // OS 9 version is not bundled at the present time
nameCFStr = CFBundleCopyLocalizedString( CFBundleGetMainBundle(), CFSTR("Untitled Resource"), null, null ); // bug: doesn't actually get localized string!
#else
nameCFStr = CFSTR("Untitled Resource");
#endif
SetDataBrowserItemDataRGBColor( itemData, &g.textColour );
}
else nameCFStr = CFStringCreateWithPascalString( CFAllocatorGetDefault(), resource->Name(), kCFStringEncodingMacRoman );
SetDataBrowserItemDataText( itemData, nameCFStr );
#if USE_NIBS // OS 9 uses CFSTR()
CFRelease( nameCFStr );
#endif
} break;
case kDBTypeColumn:
{ // resource type
if( itemID == kDataBrowserDataForkItem )
{
SetDataBrowserItemDataText( itemData, CFSTR("-") );
}
else
{
CFStringRef typeString;
TypeToCFString( resource->Type(), &typeString );
SetDataBrowserItemDataText( itemData, typeString );
CFRelease( typeString );
}
} break;
case kDBIDColumn:
{ // resource ID
if( itemID == kDataBrowserDataForkItem )
{
SetDataBrowserItemDataText( itemData, CFSTR("-") );
}
else
{
SInt16 id = resource->ID();
Str255 idPString;
NumToString( id, (StringPtr) &idPString );
CFStringRef idString = CFStringCreateWithPascalString( CFAllocatorGetDefault(), idPString, kCFStringEncodingMacRoman );
SetDataBrowserItemDataText( itemData, idString );
CFRelease( idString );
}
} break;
case kDBSizeColumn:
{ SInt32 size = resource->Size();
UInt8 power = 0, remainder = 0;
Str255 sizePString, frac;
while( size >= 1024 && power <= 30 )
{
power += 10; // 10 == KB, 20 == MB, 30 == GB
remainder = (UInt8) ((size % 1024) / 102.4); // 102.4 gives one dp, 10.24 would give two dps, 1.024 would give three dps
size /= 1024;
}
NumToString( (long) size, (StringPtr) &sizePString );
NumToString( remainder, (StringPtr) &frac );
if( power ) // some division has occoured
{
if( sizePString[0] < 3 && remainder > 0 )
{
AppendPString( (unsigned char *) &sizePString, "\p." ); // bug: should be a comma on european systems
AppendPString( (unsigned char *) &sizePString, (unsigned char *) &frac );
}
if( power == 10 ) AppendPString( (unsigned char *) &sizePString, "\p KB" );
else if( power == 20 ) AppendPString( (unsigned char *) &sizePString, "\p MB" );
else if( power == 30 ) AppendPString( (unsigned char *) &sizePString, "\p GB" ); // everything bigger will be given in GB
}
CFStringRef sizeString = CFStringCreateWithPascalString( CFAllocatorGetDefault(), sizePString, kCFStringEncodingMacRoman );
SetDataBrowserItemDataText( itemData, sizeString );
CFRelease( sizeString );
} break;
default:
result = errDataBrowserPropertyNotSupported;
break;
}
return result;
}
/*** SORT DATA BROWSER ***/
pascal Boolean SortDataBrowser( ControlRef browser, DataBrowserItemID itemOne, DataBrowserItemID itemTwo, DataBrowserPropertyID sortProperty )
{
short result;
Str255 typeOne, typeTwo;
StringPtr nameOne, nameTwo;
FileWindowPtr file = (FileWindowPtr) GetControlReference( browser );
// send data fork to top regardless of property
if( itemOne == kDataBrowserDataForkItem ) return true;
if( itemTwo == kDataBrowserDataForkItem ) return false;
// validate data browser item IDs
if( itemOne <= kDataBrowserNoItem || itemOne > file->GetResourceCount() )
{
DebugError( "\psort item one was invalid" );
return false;
}
if( itemTwo <= kDataBrowserNoItem || itemTwo > file->GetResourceCount() )
{
DebugError( "\psort item two was invalid" );
return false;
}
// get resource corrisponding to item ID
ResourceObjectPtr resourceOne = file->GetResource( itemOne );
ResourceObjectPtr resourceTwo = file->GetResource( itemTwo );
if( resourceOne == null || resourceTwo == null )
DebugError( "\pNull resource returned within SortDataBrowser()" );
// sort resources according to property user has selected
switch( sortProperty )
{
case kDBNameColumn:
nameOne = resourceOne->Name();
nameTwo = resourceTwo->Name();
result = CompareString( nameOne, nameTwo, null );
return result < 0;
case kDBTypeColumn:
TypeToPString( resourceOne->Type(), typeOne );
TypeToPString( resourceTwo->Type(), typeTwo );
result = CompareString( typeOne, typeTwo, null );
return result < 0;
case kDBIDColumn:
return resourceOne->ID() < resourceTwo->ID();
case kDBSizeColumn:
return resourceOne->Size() < resourceTwo->Size();
case kDataBrowserItemNoProperty: // this is valid when first constructing the data browser
// DebugError( "\pkDataBrowserItemNoProperty passed to sort function" );
return false;
default:
DebugError( "\pInvalid sort property given" );
return false;
}
return false;
}
/*** DATA BROWSER MESSAGE ***/
pascal void DataBrowserMessage( ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message/*, DataBrowserItemDataRef itemData*/ )
{
#pragma unused( itemID/*, itemData*/ )
FileWindowPtr file = (FileWindowPtr) GetControlReference( browser );
switch( message )
{
case kDataBrowserItemDoubleClicked:
{ KeyMap theKeys;
Boolean shiftKeyDown = false,
optionKeyDown = false,
controlKeyDown = false;
GetKeys( theKeys );
if( theKeys[1] & (shiftKey >> shiftKeyBit) ) shiftKeyDown = true;
if( theKeys[1] & (optionKey >> shiftKeyBit) ) optionKeyDown = true;
if( theKeys[1] & (controlKey >> shiftKeyBit) ) controlKeyDown = true;
if( optionKeyDown ) file->OpenResource( itemID, kMenuCommandOpenHex );
else if( controlKeyDown ) file->OpenResource( itemID, kMenuCommandOpenTemplate );
else file->OpenResource( itemID, kMenuCommandOpenDefault );
} break;
case kDataBrowserItemSelected:
case kDataBrowserItemDeselected:
case kDataBrowserSelectionSetChanged:
// file->SetHeaderText();
if( g.inspector )
g.inspector->Update();
break;
case kDataBrowserEditStarted:
case kDataBrowserEditStopped:
case kDataBrowserItemAdded:
case kDataBrowserItemRemoved:
case kDataBrowserContainerOpened:
case kDataBrowserContainerClosing:
case kDataBrowserContainerClosed:
case kDataBrowserContainerSorting:
case kDataBrowserContainerSorted:
case kDataBrowserTargetChanged:
case kDataBrowserUserStateChanged:
break;
}
}
/*** ADD DRAG ITEM ***/
pascal Boolean DataBrowserAddDragItem( ControlRef browser, DragRef drag, DataBrowserItemID item, DragItemRef *itemRef )
{
#pragma unused( item )
// if drag already has phfs flavour, don't add another
UInt16 numFlavours;
CountDragItemFlavors( drag, *itemRef, &numFlavours );
if( numFlavours > 0 ) return true;
// add 'create file' callback
if( itemRef ) *itemRef = ItemReference( item );
FlavorFlags flags = flavorNotSaved;
DragSendDataUPP sendData = NewDragSendDataUPP( SendPromisedFile );
SetDragSendProc( drag, sendData, browser );
// setup imaginary file
PromiseHFSFlavor promisedFile;
promisedFile.fileType = kResourceFileType;
promisedFile.fileCreator = kResKnifeCreator;
promisedFile.fdFlags = null; // finder flags
promisedFile.promisedFlavor = kResourceTransferType;
// add phfs and TEXT flavours
AddDragItemFlavor( drag, *itemRef, flavorTypePromiseHFS, &promisedFile, sizeof(PromiseHFSFlavor), flags );
return true;
/* OSErr error = noErr;
DragReference theDragRef;
ItemReference theItemRef = 1;
// create the drag reference
NewDrag( &theDragRef );
if( MemError() ) return;
SetDragSendProc( theDragRef, sendProc, this );
RgnHandle dragRgn = NewRgn(),
subtractRgn = NewRgn();
// get region of dragged items, using translucent dragging where possible
Point dragOffset;
GWorldPtr imageGWorld = nil;
resData = GetResourceData( ownerWindow );
while( resData )
{
if( r.selected )
UnionRgn( r.nameIconRgn, dragRgn, dragRgn ); // add new region to rest of drag region
resData = r.next;
}
if( g.translucentDrag )
{
short resCounter = 0;
SetPt( &dragOffset, 0, kFileHeaderHeight );
resData = GetResourceData( ownerWindow );
while( !r.selected )
{
resCounter++;
resData = r.next;
}
error = CreateDragImage( resData, &imageGWorld );
if( !error )
{
// init mask region
RgnHandle maskRgn = NewRgn();
CopyRgn( r.nameIconRgn, maskRgn );
OffsetRgn( maskRgn, 0, -kFileLineHeight * resCounter );
// init rects
Rect sourceRect, destRect;
SetRect( &sourceRect, 0, 0, g.nameColumnWidth, kFileLineHeight );
SetRect( &destRect, 0, 0, g.nameColumnWidth, kFileLineHeight );
OffsetRect( &destRect, 0, kFileHeaderHeight );
// init GWorld
PixMapHandle imagePixMap = GetGWorldPixMap( imageGWorld );
DragImageFlags imageFlags = kDragStandardTranslucency | kDragRegionAndImage;
error = SetDragImage( theDragRef, imagePixMap, maskRgn, dragOffset, imageFlags );
CopyBits( &GrafPtr( imageGWorld )->portBits, &GrafPtr( ownerWindow )->portBits, &sourceRect, &destRect, srcCopy, maskRgn );
if( error ) SysBeep(0);
DisposeGWorld( imageGWorld );
DisposeRgn( maskRgn );
}
}
// subtract middles from icons
MakeGlobal( ownerWindow, NewPoint(), &globalMouse );
CopyRgn( dragRgn, subtractRgn ); // duplicate region
InsetRgn( subtractRgn, 2, 2 ); // inset it by 2 pixels
DiffRgn( dragRgn, subtractRgn, dragRgn ); // subtract subRgn from addRgn, save in nameIconRgn
OffsetRgn( dragRgn, globalMouse.h, globalMouse.v ); // change drag region to global coords
// add flavour data to drag
error = AddDragItemFlavor( theDragRef, theItemRef, flavorTypePromiseHFS, &theFile, sizeof(PromiseHFSFlavor), theFlags );
error = AddDragItemFlavor( theDragRef, theItemRef, kResType, nil, 0, theFlags );
// track the drag, then clean up
error = TrackDrag( theDragRef, theEvent, dragRgn );
if( theDragRef ) DisposeDrag( theDragRef );
if( subtractRgn ) DisposeRgn( subtractRgn );
if( dragRgn ) DisposeRgn( dragRgn );
return error == noErr; */
}
/*** ACCEPT DRAG ***/
pascal Boolean DataBrowserAcceptDrag( ControlRef browser, DragRef drag, DataBrowserItemID item )
{
#pragma unused( browser, drag, item )
/* OSStatus error = noErr;
Size size = null;
DragItemRef dragItem = 1;
UInt16 index, totalItems;
CountDragItems( theDrag, &totalItems );
for( index = 1; index <= totalItems; index++ )
{
GetDragItemReferenceNumber( theDrag, index, &dragItem );
error = GetFlavourDataSize( theDrag, dragItem, kDragFlavourTypeResource, &size );
// if( error ) return false;
if( !error ) index = totalItems; // stop when valid item is reached
}
return size >= sizeof(ResTransferDesc);
*/ return true;
}
/*** RECEIVE DRAG ***/
pascal Boolean DataBrowserReceiveDrag( ControlRef browser, DragRef drag, DataBrowserItemID item )
{
#pragma unused( browser, drag, item )
return true;
}
/*** POSTÐPROCESS DRAG ***/
pascal void DataBrowserPostProcessDrag( ControlRef browser, DragRef drag, OSStatus trackDragResult )
{
#pragma unused( browser, drag, trackDragResult )
}
/*** SEND PROMISED FILE ***/
pascal OSErr SendPromisedFile( FlavorType type, void *dragSendRefCon, ItemReference item, DragReference drag )
{
OSErr error = noErr;
ControlRef browser = (ControlRef) dragSendRefCon;
FSSpec fileSpec;
Str255 fileName;
short vRefNum;
long dirID;
if( type != flavorTypePromiseHFS ) return badDragFlavorErr;
// create file
GetIndString( fileName, kFileNameStrings, kStringNewDragFileName );
FindFolder( kOnSystemDisk, /*kTemporaryFolderType*/kDesktopFolderType, kCreateFolder, &vRefNum, &dirID );
FSMakeFSSpec( vRefNum, dirID, fileName, &fileSpec );
FSpCreateResFile( &fileSpec, kResKnifeCreator, kResourceFileType, smSystemScript );
// save resources into file
DragData clientData; // waiting for jim to add a ControlRef to DataBrowserItemUPP; bug: jim no longer works at Apple
clientData.browser = browser;
clientData.fileSpec = &fileSpec;
DataBrowserItemUPP callback = NewDataBrowserItemUPP( AddResourceToDragFile );
/* control, container, recurse, state, callback, clientData */
ForEachDataBrowserItem( browser, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, callback, &clientData );
// save resources in file
/* ResourceObjectPtr resource = GetResourceData( file->window );
short refNum = FSpOpenResFile( &fileSpec, fsRdWrPerm );
UseResFile( refNum );
while( resData )
{
if( resource->Selected() )
AddResource( resource->Data(), resource->Type(), resource->ID(), resource->Name() );
resData = resource->Next();
}
CloseResFile( refNum );
UseResFile( g.appResFile );
*/
error = SetDragItemFlavorData( drag, item, type, &fileSpec, sizeof(FSSpec), 0 );
return error;
}
/*** ADD RESOURCE TO DRAG FILE ***/
pascal void AddResourceToDragFile( DataBrowserItemID item, DataBrowserItemState state, void *clientData )
{
#pragma unused( state )
// FSSpecPtr fileSpec = (FSSpecPtr) clientData;
WindowRef window = GetControlOwner( ((DragDataPtr) clientData)->browser );
FileWindowPtr file = (FileWindowPtr) GetWindowRefCon( window );
ResourceObjectPtr resource = file->GetResource( item );
// add resource to file
short oldFile = CurResFile();
short refNum = FSpOpenResFile( ((DragDataPtr) clientData)->fileSpec, fsRdWrPerm );
UseResFile( refNum );
AddResource( resource->Data(), resource->Type(), resource->ID(), resource->Name() );
if( ResError() == addResFailed )
{
DisplayError( "\pDrag Partially Failed", "\pCould not add a resource to file." );
}
else
{
SetResAttrs( resource->Data(), resource->Attributes() );
ChangedResource( resource->Data() );
// clean up & move on
DetachResource( resource->Data() );
}
CloseResFile( refNum );
UseResFile( oldFile );
}
#else
/*********************/
/* FAKE DATA BROWSER */
/*********************/
/*** CLEAR SELECTION ***/
OSStatus FileWindow::ClearSelection( void )
{
ResourceObjectPtr resource = resourceMap;
while( resource )
{
resource->Select( false );
resource = resource->Next();
}
return noErr;
}
#endif

View File

@ -1,87 +0,0 @@
#include "ResKnife.h"
#include "FileWindow.h"
#ifndef _ResKnife_DataBrowser_
#define _ResKnife_DataBrowser_
/*!
* @header DataBrowser
* @discussion Handles the databrowser control on post-CarbonLib systems, and mimics it on pre-CarbonLib machines.
*/
typedef struct
{
ControlRef browser;
FSSpecPtr fileSpec;
} DragData, *DragDataPtr;
/*!
* @enum DataBrowser Column IDs
* @discussion The data browser requires IDs for identifiying columns when adding data. These constants provide those IDs.
* @constant kDBNameColumn The name column, also include resource icon and disclosure triangle.
* @constant kDBTypeColumn The type column contains the four-byte resType of each resource.
* @constant kDBIDColumn The ID column contains 16-bit signed resource IDs
* @constant kDBSizeColumn The size column reports the size of each resource's data in bytes or multiples thereof.
*/
enum
{
kDBNameColumn = FOUR_CHAR_CODE('name'),
kDBTypeColumn = FOUR_CHAR_CODE('type'),
kDBIDColumn = FOUR_CHAR_CODE('id '),
kDBSizeColumn = FOUR_CHAR_CODE('size')
};
const DataBrowserItemID kDataBrowserDataForkItem = 0xFFFFFFFE; // bug in data browser preventts use of 0xFFFFFFFF
/*!
* @function AddDataBrowserColumn
* @discussion Adds columns to the data browser one at a time.
*/
void AddDataBrowserColumn( ControlRef browser, DataBrowserPropertyID column, UInt16 position );
/*!
* @function DataBrowserItemData
* @discussion DataBrowser callback.
*/
pascal OSStatus DataBrowserItemData( ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean changeValue );
/*!
* @function SortDataBrowser
* @discussion DataBrowser callback.
*/
pascal Boolean SortDataBrowser( ControlRef browser, DataBrowserItemID itemOne, DataBrowserItemID itemTwo, DataBrowserPropertyID sortProperty );
/*!
* @function DataBrowserMessage
* @discussion DataBrowser callback.
*/
pascal void DataBrowserMessage( ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message/*, DataBrowserItemDataRef itemData*/ );
/*!
* @function DataBrowserAddDragItem
* @discussion DataBrowser callback.
*/
pascal Boolean DataBrowserAddDragItem( ControlRef browser, DragRef drag, DataBrowserItemID item, DragItemRef *itemRef );
/*!
* @function DataBrowserAcceptDrag
* @discussion DataBrowser callback.
*/
pascal Boolean DataBrowserAcceptDrag( ControlRef browser, DragRef drag, DataBrowserItemID item );
/*!
* @function DataBrowserReceiveDrag
* @discussion DataBrowser callback.
*/
pascal Boolean DataBrowserReceiveDrag( ControlRef browser, DragRef drag, DataBrowserItemID item );
/*!
* @function DataBrowserPostProcessDrag
* @discussion DataBrowser callback.
*/
pascal void DataBrowserPostProcessDrag( ControlRef browser, DragRef drag, OSStatus trackDragResult );
/*!
* @function SendPromisedFile
* @discussion Creates the promised file and sends the FSSpec for it back.
*/
pascal OSErr SendPromisedFile( FlavorType theType, void *dragSendRefCon, ItemReference item, DragReference drag );
/*!
* @function AddResourceToDragFile
* @discussion Adds each resource to the file created by SendPromisedFile. Called once per resource.
*/
pascal void AddResourceToDragFile( DataBrowserItemID item, DataBrowserItemState state, void *clientData );
#endif

View File

@ -1,57 +0,0 @@
#include "EditorWindow.h"
#include "ResourceObject.h"
#include "Errors.h"
#include "Utility.h"
extern globals g;
/*** CREATOR ***/
EditorWindow::EditorWindow( FileWindowPtr ownerFile, ResourceObjectPtr targetResource, WindowRef inputWindow ) : PlugWindow( ownerFile )
{
// OSStatus error = noErr;
// set default variables
window = inputWindow;
resource = targetResource;
// set up default window title
Str255 windowTitle, resTypeStr, resIDStr;
FSSpec spec = *ownerFile->GetFileSpec();
CopyPString( spec.name, windowTitle );
TypeToPString( resource->Type(), resTypeStr );
NumToString( resource->ID(), resIDStr );
AppendPString( windowTitle, "\p: " );
AppendPString( windowTitle, resTypeStr );
AppendPString( windowTitle, "\p " );
AppendPString( windowTitle, resIDStr );
if( *resource->Name() != 0x00 ) // resource has name
{
AppendPString( windowTitle, "\p, Ò" );
AppendPString( windowTitle, resource->Name() );
AppendPString( windowTitle, "\" );
}
// save EditorWindow class in window's refcon
SetWindowRefCon( window, (UInt32) this );
SetWindowKind( window, kEditorWindowKind );
SetWindowTitle( window, windowTitle );
}
#if !TARGET_API_MAC_CARBON
/*** CLOSE ***/
OSStatus EditorWindow::Close( void )
{
// bug: need to tell plug it is about to die.
CloseWindow( window );
delete this;
return noErr;
}
#endif
/*** RESOURCE ACCESSOR ***/
ResourceObjectPtr EditorWindow::Resource( void )
{
return resource;
}

View File

@ -1,37 +0,0 @@
#include "ResKnife.h"
#include "PlugWindow.h"
#include "ResourceObject.h"
#ifndef _ResKnife_EditorWindow_
#define _ResKnife_EditorWindow_
/*!
* @header EditorWindow
* @discussion A class specifically designed to maintain an external editor window.
*/
/*!
* @class EditorWindow
* @discussion A class specifically designed to maintain an external editor window.
*/
class EditorWindow : PlugWindow
{
private:
ResourceObjectPtr resource;
Boolean modified; // flag the editor sets when it modifies a resource (ie. it needs to be saved)
public:
/*!
* @function EditorWindow
* @discussion Constructor function.
*/
EditorWindow( FileWindowPtr ownerFile, ResourceObjectPtr targetResource, WindowRef inputWindow );
/*!
* @function Close
* @discussion Sends a close message to the plug, then closes the window.
*/
OSStatus Close( void );
ResourceObjectPtr Resource( void );
};
#endif

View File

@ -1,89 +0,0 @@
#include "Errors.h"
#include "Application.h"
#include "Utility.h"
// import globals and prefs from Application.cpp
extern globals g;
extern prefs p;
/*** DISPLAY ANY ERROR ***/
OSStatus DisplayError( CFStringRef errorStr )
{
#pragma unused( errorStr )
return noErr;
}
/*** DISPLAY SIMPLE ERROR ***/
OSStatus DisplayError( ConstStr255Param errorStr )
{
return DisplayError( errorStr, "\p" );
}
/*** DISPLAY ERROR WITH EXPLANATION */
OSStatus DisplayError( UInt16 error, UInt16 explanation )
{
Str255 errorStr, explanationStr;
GetIndString( errorStr, kErrorStrings, error );
GetIndString( explanationStr, kErrorStrings, explanation );
return DisplayError( errorStr, explanationStr );
}
/*** DISPLAY ERROR WITH EXPLANATION */
OSStatus DisplayError( ConstStr255Param errorStr, ConstStr255Param explanationStr )
{
if( g.surpressErrors ) return noErr;
if( g.useAppearance )
{
SInt16 item;
AlertStdAlertParamRec params = {};
params.movable = true;
params.defaultButton = kAlertStdAlertOKButton;
params.position = kWindowDefaultPosition;
#if __profile__
ProfilerSetStatus( false );
#endif
SysBeep(0);
StandardAlert( kAlertStopAlert, errorStr, explanationStr, &params, &item );
#if __profile__
ProfilerSetStatus( true );
#endif
return item == kAlertStdAlertOKButton? noErr:paramErr;
}
else
{
ParamText( errorStr, explanationStr, "\p", "\p" );
ModalFilterUPP filter = null; // NewModalFilterUPP( ParseDialogEvents );
#if __profile__
ProfilerSetStatus( false );
#endif
SysBeep(0);
DialogItemIndex item = StopAlert( 128, filter );
#if __profile__
ProfilerSetStatus( true );
#endif
return item == kAlertStdAlertOKButton? noErr:paramErr;
}
}
/*** DISPLAY ERROR WITH EXPLANATION */
OSStatus DebugError( UInt16 error, OSStatus number )
{
Str255 errorStr;
GetIndString( errorStr, kDebugStrings, error );
return DebugError( errorStr, number );
}
/*** DISPLAY A DEBUGGING ERROR ***/
OSStatus DebugError( ConstStr255Param errorStr, OSStatus number )
{
OSStatus error = noErr;
if( g.debug )
{
Str255 message = "\pDebugging Error ID: ", numString = "\p";
NumToString( number, numString );
AppendPString( message, numString );
error = DisplayError( message, errorStr );
}
return error;
}

View File

@ -1,42 +0,0 @@
#include "ResKnife.h"
#ifndef _ResKnife_Errors_
#define _ResKnife_Errors_
/*!
@header Errors
@discussion Contains all error display code for both ResKnife and it's plug-ins.
*/
/*!
@function DisplayError
@discussion Pass a CFStringRef and ResKnife will do noting at all. (yet :)
*/
OSStatus DisplayError( CFStringRef error );
/*!
@function DisplayError
@discussion Pass one pascal string and ResKnife will display a simple error message.
*/
OSStatus DisplayError( ConstStr255Param error );
/*!
@function DisplayError
@discussion Pass two string indecies within kErrorStrings, and they will be displayed as an error message.
*/
OSStatus DisplayError( UInt16 error, UInt16 explanation );
/*!
@function DisplayError
@discussion Pass two pascal strings and ResKnife will display a more refined error message.
*/
OSStatus DisplayError( ConstStr255Param error, ConstStr255Param explanation );
/*!
@function DebugError
@discussion Pass an index of a string with kDebugStrings and if debugging mode is on, ResKnife will display the message.
*/
OSStatus DebugError( UInt16 error, OSStatus number = noErr );
/*!
@function DebugError
@discussion Pass a pascal string and if debugging mode is on, ResKnife will display the message.
*/
OSStatus DebugError( ConstStr255Param errorStr, OSStatus number = noErr );
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,179 +0,0 @@
#include "ResKnife.h"
#include "WindowObject.h"
#ifndef _ResKnife_FileWindow_
#define _ResKnife_FileWindow_
/*!
@header FileWindow
@discussion The bulk of the ResKnife code is concerned with the managment of this window. It is the essence of the program.
*/
/* Constants */
const UInt16 kDefaultHeaderHeight = 20;
const UInt16 kMinimumFileWindowWidth = 128;
const UInt16 kDefaultFileWindowWidth = 420;
const UInt16 kMinimumFileWindowHeight = 128 + kDefaultHeaderHeight;
const UInt16 kDefaultFileWindowHeight = 384 + kDefaultHeaderHeight;
const UInt16 kBevelButtonHeight = 20;
const UInt16 kFileWindowHeaderHeight = kDefaultHeaderHeight + kBevelButtonHeight;
const UInt16 kFileWindowRowHeight = 19;
const UInt16 kFileWindowTextHeight = kFileWindowRowHeight - 5;
const UInt16 kFileWindowMinimumNameColumnWidth = 150;
const UInt16 kFileWindowDefaultNameColumnWidth = 250;
const UInt16 kFileWindowTypeColumnWidth = 52;
const UInt16 kFileWindowIDColumnWidth = 52;
const UInt16 kFileWindowSizeColumnWidth = 52;
const UInt16 kFileWindowAttributesColumnWidth = 120;
const UInt16 kFileWindowSortColumnWidth = 16;
const UInt16 kFileWindowAllOtherColumnWidths = kFileWindowTypeColumnWidth + kFileWindowIDColumnWidth + kFileWindowSizeColumnWidth + kFileWindowAttributesColumnWidth +8; // excludes variable with name column
const UInt16 kFileWindowNameColumnTextOffset = 42; // start of text, actual column starts at zero
const UInt16 kFileWindowTypeColumnOffset = 0; // offset from end of name column
const UInt16 kFileWindowIDColumnOffset = kFileWindowTypeColumnOffset + kFileWindowTypeColumnWidth;
const UInt16 kFileWindowSizeColumnOffset = kFileWindowIDColumnOffset + kFileWindowIDColumnWidth;
const UInt16 kFileWindowAttributesColumnOffset = kFileWindowSizeColumnOffset + kFileWindowSizeColumnWidth;
const UInt32 kWindowPropertyDataBrowser = FOUR_CHAR_CODE('brow');
const UInt32 kHeaderSignature = FOUR_CHAR_CODE('head');
const UInt32 kLeftTextSignature = FOUR_CHAR_CODE('left');
const UInt32 kRightTextSignature = FOUR_CHAR_CODE('rght');
const UInt32 kDataBrowserSignature = FOUR_CHAR_CODE('brow');
const UInt32 kDataBrowserNameColumn = FOUR_CHAR_CODE('name');
const UInt32 kDataBrowserTypeColumn = FOUR_CHAR_CODE('type');
const UInt32 kDataBrowserIDColumn = FOUR_CHAR_CODE('id ');
const UInt32 kDataBrowserSizeColumn = FOUR_CHAR_CODE('size');
typedef enum
{
kSortName = 1,
kSortType,
kSortID,
kSortSize,
kSortAttrs
} SortOrder;
/*** FILE WINDOW CLASS ***/
class FileWindow : WindowObject
{
// file info
FSSpecPtr fileSpec; // user's copy
FSSpecPtr tempSpec; // my copy
Boolean fileExists; // existing file was opened or file has been saved at some point
Boolean fileDirty; // temp file ­ real file => save available
Boolean rfBased; // file's resource map came from it's resource fork
// resource info
UInt16 numTypes;
UInt32 numResources;
#if !TARGET_API_MAC_CARBON
UInt32 numSelected; // for fake data browser
#endif
Handle dataFork; // bug: what is this for?
ResourceObjectPtr resourceMap;
// controls
#if TARGET_API_MAC_CARBON
ControlRef dataBrowser; // header controls in WindowObject
#else // make a fake databrowser
SortOrder sortOrder; // the one which is actually selected
ControlRef sortName;
ControlRef sortType;
ControlRef sortID;
ControlRef sortSize;
ControlRef sortAttrs;
ControlRef sortDir;
SInt16 nameColumnWidth; // varies with window size, and needs to be signed
#endif
/* methods */
public:
FileWindow( FSSpecPtr spec = null );
virtual ~FileWindow( void );
// overridden inherited functions
/*!
* @function Window
* @discussion Accessor for the object&rsquo;s <tt>WindowRef</tt>.
*/
virtual WindowRef Window( void );
virtual OSStatus BoundsChanging( EventRef event );
virtual OSStatus BoundsChanged( EventRef event );
#if !TARGET_API_MAC_CARBON
virtual OSStatus Activate( Boolean active = true );
virtual OSStatus Update( RgnHandle region = null );
virtual OSStatus Click( Point mouse, EventModifiers modifiers );
// drawing
private:
virtual OSStatus UpdateScrollBars( void );
OSStatus DrawResourceIcon( ResourceObjectPtr resource, UInt16 line );
// fake data brwser
OSStatus ClearSelection( void );
#endif
// file manipulation
public:
OSStatus ReadResourceFork( void );
OSStatus ReadDataFork( OSStatus rfError );
OSStatus InitDataBrowser( void );
OSStatus SaveFile( FSSpecPtr saveSpec = null );
private:
/*!
@function ReadResourceMap
@discussion Requires the fork containing resources to be at the top of the resource chain
*/
OSStatus ReadResourceMap( void ); // fork-independent resource routines
OSStatus SaveResourceMap( void );
// carbon routines
public:
OSStatus Zoomed( EventRef event );
OSStatus SetIdealSize( EventRef event );
OSStatus DisplaySaveDialog( void );
OSStatus DisplayModelessAskSaveChangesDialog( void );
OSStatus DisplaySaveAsDialog( void );
OSStatus DisplayModelessPutFileDialog( void );
OSStatus DisplayRevertFileDialog( void );
OSStatus DisplayModelessAskDiscardChangesDialog( void );
OSStatus DisplayNewResourceDialog( void );
OSStatus DisplayNewResourceSheet( void );
// resource map processing
OSStatus CreateNewResource( ConstStr255Param name, ResType type, SInt16 resID, SInt16 attribs );
OSStatus OpenResource( DataBrowserItemID itemID, MenuCommand command );
private:
OSStatus DisposeResourceMap( void );
public:
// sound handlers
OSStatus PlaySound( DataBrowserItemID itemID );
// file accessors
FSSpecPtr GetFileSpec( void );
void SetFileSpec( FSSpecPtr spec );
Boolean IsFileDirty( void );
void SetFileDirty( Boolean dirty = true );
#if TARGET_API_MAC_CARBON
ControlRef GetDataBrowser( void );
#endif
// resource accessors
UInt32 GetResourceCount( ResType wanted = 0x00000000 );
ResourceObjectPtr GetResource( DataBrowserItemID itemID );
UInt8* GetResourceName( DataBrowserItemID itemID );
UInt32 GetResourceSize( DataBrowserItemID itemID );
ResType GetResourceType( DataBrowserItemID itemID );
SInt16 GetResourceID( DataBrowserItemID itemID );
SInt16 GetResourceAttributes( DataBrowserItemID itemID );
};
/* window event handler */
pascal void FileWindowScrollAction( ControlHandle control, SInt16 controlPart );
pascal OSStatus FileWindowEventHandler( EventHandlerCallRef callRef, EventRef event, void *userData );
pascal OSStatus FileWindowUpdateMenus( EventHandlerCallRef callRef, EventRef event, void *userData );
pascal OSStatus FileWindowParseMenuSelection( EventHandlerCallRef callRef, EventRef event, void *userData );
pascal OSStatus NewResourceEventHandler( EventHandlerCallRef callRef, EventRef event, void *userData );
#endif

View File

@ -1,865 +0,0 @@
#include "Files.h"
#include "Application.h"
#include "FileWindow.h"
#include "ResourceObject.h" // for saving inital resource data
#include "DataBrowser.h" // for kDataBrowserForkItem constant
#include "Utility.h"
#include "Errors.h"
extern globals g;
/* Convert an FSRef to an FSSpec:
FSGetCatalogInfo( &fsref, kFSCatInfoNone, null, null, &spec, null );
Get your application's FSSpec
FSSpec spec;
String name;
ProcessInfoRec info;
ProcessSerialNumber psn;
GetCurrentProcess( &psn );
info.processName = &name;
info.processAppSpec = &spec;
GetProcessInformation( psn, &info );
*/
/*** NAV OPEN FILE ***/
/*OSStatus NavOpenFile( void )
{
OSStatus error = noErr;
NavReplyRecord reply;
NavDialogOptions dialogOptions;
NavEventUPP eventProc = NewNavEventUPP( NavEventFilter );
NavPreviewUPP previewProc = NewNavPreviewUPP( NavPreviewFilter );
NavObjectFilterUPP filterProc = NewNavObjectFilterUPP( NavFileFilter );
// Initialize dialog options structure and set default values
NavGetDefaultDialogOptions( &dialogOptions );
dialogOptions.dialogOptionFlags = kNavNoTypePopup | kNavDontAutoTranslate | kNavDontAddTranslateItems | kNavAllowMultipleFiles | kNavAllowInvisibleFiles;
BlockMoveData( g.appName, dialogOptions.clientName, sizeof(Str255) );
// call the nav services routine
error = NavGetFile( null, &reply, &dialogOptions, eventProc, previewProc, filterProc, null, null );
DisposeNavEventUPP( eventProc );
DisposeNavPreviewUPP( previewProc );
DisposeNavObjectFilterUPP( filterProc );
if( reply.validRecord && error == noErr )
{
if( g.useAppleEvents )
error = AppleEventSendSelf( kCoreEventClass, kAEOpenDocuments, reply.selection );
#if !TARGET_API_MAC_CARBON
else
{
// open the list of item(s):
AEKeyword keyword;
DescType descType;
FSSpec fileSpec;
Size actualSize;
error = AEGetNthPtr( &(reply.selection), 1, typeFSS, &keyword, &descType, &fileSpec, sizeof(FSSpec), &actualSize );
if( !error ) // if sucessful, open & read the file
new FileWindow( &fileSpec );
*/ /* SInt32 count;
FSSpec fileSpec;
AEDesc resultDesc;
error = AECountItems( &(reply.selection), &count );
if( !error )
for( SInt32 n = 1; n <= count; n++ )
{
error = AEGetNthDesc( &(reply.selection), n, typeFSS, null, &resultDesc );
if( !error )
{
HLock( (Handle) resultDesc.dataHandle );
BlockMoveData( (void *) *resultDesc.dataHandle, &fileSpec, sizeof(FSSpec) );
new FileWindow( &fileSpec );
AEDisposeDesc( &resultDesc );
}
}
*/ /* }
#endif
// Always dispose of reply structure, resources, and descriptors
error = NavDisposeReply( &reply );
}
return error;
}
*/
#if !TARGET_API_MAC_CARBON
/*** OPEN FILE ***/
OSStatus OpenFile( short vRefNum, long dirID, ConstStr255Param fileName )
{
FSSpec fileSpec;
FSMakeFSSpec( vRefNum, dirID, fileName, &fileSpec );
new FileWindow( &fileSpec );
return noErr;
}
/*** DISPLAY STANDARD FILE OPEN DIALOG ***/
OSStatus DisplayStandardFileOpenDialog( void )
{
StandardFileReply theReply;
SFTypeList typeList = { 0x0L };
StandardGetFile( null, 0, typeList, &theReply );
if( theReply.sfGood ) new FileWindow( &theReply.sfFile );
return theReply.sfGood? noErr:userCanceledErr;
}
#endif
/*** OPEN A FILE DIALOG ***/
OSStatus DisplayOpenDialog( void )
{
OSStatus error = noErr;
NavReplyRecord reply;
NavDialogOptions dialogOptions;
NavEventUPP eventProc = NewNavEventUPP( NavEventFilter );
NavPreviewUPP previewProc = NewNavPreviewUPP( NavPreviewFilter );
NavObjectFilterUPP filterProc = NewNavObjectFilterUPP( NavFileFilter );
NavTypeListHandle typeList = null;
NavGetDefaultDialogOptions( &dialogOptions );
dialogOptions.dialogOptionFlags += kNavNoTypePopup;
GetIndString( dialogOptions.clientName, kFileNameStrings, kStringResKnifeName );
error = NavGetFile( null, &reply, &dialogOptions, eventProc, previewProc, filterProc, typeList, null);
if( reply.validRecord || !error )
{
AEKeyword keyword;
DescType descType;
FSSpec fileSpec;
Size actualSize;
error = AEGetNthPtr( &(reply.selection), 1, typeFSS, &keyword, &descType, &fileSpec, sizeof(FSSpec), &actualSize );
if( !error ) new FileWindow( &fileSpec ); // if sucessful, opens & reads the file
NavDisposeReply( &reply );
}
else error = userCanceledErr;
DisposeNavEventUPP( eventProc );
DisposeNavPreviewUPP( previewProc );
DisposeNavObjectFilterUPP( filterProc );
return error;
}
/*** DISPLAY MODELESS GET FILE DIALOG ***/
OSStatus DisplayModelessGetFileDialog( void )
{
OSStatus error;
NavEventUPP eventProc = NewNavEventUPP( ModelessGetFileHandler );
NavPreviewUPP previewProc = null;
NavObjectFilterUPP filterProc = null;
NavTypeListHandle typeList = null;
NavDialogCreationOptions options;
error = NavGetDefaultDialogCreationOptions( &options );
options.clientName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey( CFBundleGetMainBundle(), kCFBundleNameKey );
NavDialogRef dialog;
error = NavCreateGetFileDialog( &options, typeList, eventProc, previewProc, filterProc, null, &dialog );
error = NavDialogRun( dialog );
if( error ) NavDialogDispose( dialog );
return error;
}
/*** SAVE FILE DIALOG ***/
OSStatus FileWindow::DisplaySaveDialog( void )
{
OSStatus error = noErr;
NavDialogOptions options;
NavEventUPP eventProc = NewNavEventUPP( NavEventFilter );
NavAskSaveChangesAction action = g.quitting? kNavSaveChangesQuittingApplication : kNavSaveChangesClosingDocument;
NavAskSaveChangesResult result;
NavGetDefaultDialogOptions( &options );
GetWindowTitle( window, options.savedFileName );
// GetIndString( options.clientName, kFileNameStrings, kStringAppName );
NavAskSaveChanges( &options, action, &result, eventProc, null );
switch( result )
{
case kNavAskSaveChangesSave:
if( fileExists ) error = SaveFile( null );
else error = DisplaySaveAsDialog();
break;
case kNavAskSaveChangesDontSave:
break;
case kNavAskSaveChangesCancel:
g.cancelQuit = true;
g.quitting = false; // bug: why can't I check for userCanceledErr instead?
error = userCanceledErr;
break;
}
DisposeNavEventUPP( eventProc );
return error;
}
/*** DISPLAY MODELESS SAVE DIALOG ***/
OSStatus FileWindow::DisplayModelessAskSaveChangesDialog( void )
{
OSStatus error;
NavEventUPP eventProc = NewNavEventUPP( ModelessAskSaveChangesHandler );
/* NavPreviewUPP previewProc = null;
NavObjectFilterUPP filterProc = null;
NavTypeListHandle typeList = null;
*/ NavAskSaveChangesAction action = g.quitting? kNavSaveChangesQuittingApplication : kNavSaveChangesClosingDocument;
NavDialogCreationOptions options;
error = NavGetDefaultDialogCreationOptions( &options );
options.parentWindow = window;
options.modality = kWindowModalityWindowModal;
options.clientName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey( CFBundleGetMainBundle(), kCFBundleNameKey ); // bug: are these two strings CFReleased? Should they be?
options.saveFileName = CFStringCreateWithPascalString( null, fileSpec->name, CFStringGetSystemEncoding()); // bug: see above
NavDialogRef dialog;
error = NavCreateAskSaveChangesDialog( &options, action, eventProc, this, &dialog );
error = NavDialogRun( dialog );
return error;
}
/*** SAVE AS DIALOG ***/
OSStatus FileWindow::DisplaySaveAsDialog( void )
{
OSStatus error = noErr;
NavReplyRecord reply;
NavDialogOptions dialogOptions;
NavEventUPP eventProc = NewNavEventUPP( NavEventFilter );
NavGetDefaultDialogOptions( &dialogOptions );
GetWindowTitle( window, dialogOptions.savedFileName );
GetIndString( dialogOptions.clientName, kFileNameStrings, kStringResKnifeName );
error = NavPutFile( null, &reply, &dialogOptions, eventProc, kResourceFileType, kResKnifeCreator, null );
if( reply.validRecord || !error )
{
AEKeyword keyword;
DescType descType;
FSSpec savedSpec;
Size actualSize;
// bug: does the next line only get the first selected file?
error = AEGetNthPtr( &(reply.selection), 1, typeFSS, &keyword, &descType, &savedSpec, sizeof(FSSpec), &actualSize );
if( !error )
{
if( reply.replacing ) error = FSpDelete( &savedSpec );
if( !error )
{
error = SaveFile( &savedSpec );
if ( !error )
error = NavCompleteSave( &reply, kNavTranslateInPlace );
}
else if( error == fBsyErr )
{
DisplayError( kStringUnknownError, kExplanationUnknownError ); // read error
}
}
NavDisposeReply( &reply );
}
else if( !error ) error = userCanceledErr;
DisposeNavEventUPP( eventProc );
return error;
}
/*** DISPLAY MODELESS PUT FILE DIALOG ***/
OSStatus FileWindow::DisplayModelessPutFileDialog( void )
{
OSStatus error;
NavEventUPP eventProc = NewNavEventUPP( ModelessPutFileHandler );
NavDialogCreationOptions options;
error = NavGetDefaultDialogCreationOptions( &options );
options.parentWindow = window;
options.modality = kWindowModalityWindowModal;
options.clientName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey( CFBundleGetMainBundle(), kCFBundleNameKey );
options.saveFileName = CFStringCreateWithPascalString( null, fileSpec->name, CFStringGetSystemEncoding());
NavDialogRef dialog;
error = NavCreatePutFileDialog( &options, kResourceFileType, kResKnifeCreator, eventProc, this, &dialog );
error = NavDialogRun( dialog );
return error;
}
/*** DISPLAY REVERT FILE DIALOG ***/
OSStatus FileWindow::DisplayRevertFileDialog( void )
{
OSStatus error = noErr;
NavDialogOptions dialogOptions;
NavEventUPP eventProc = NewNavEventUPP( NavEventFilter );
NavAskDiscardChangesResult result;
NavGetDefaultDialogOptions( &dialogOptions );
GetWindowTitle( window, dialogOptions.savedFileName );
NavAskDiscardChanges( &dialogOptions, &result, eventProc, null );
switch( result )
{
case kNavAskDiscardChanges:
/* error = CloseFile();
if( error ) break;
error = OpenFile();
if( error ) break;
error = ReadFile();
*/ break;
case kNavAskDiscardChangesCancel:
break;
}
DisposeNavEventUPP( eventProc );
return error;
}
/*** DISPLAY MODELESS ASK DISCARD CHANGES DIALOG ***/
OSStatus FileWindow::DisplayModelessAskDiscardChangesDialog( void )
{
OSStatus error;
NavEventUPP eventProc = NewNavEventUPP( ModelessAskDiscardChangesHandler );
NavDialogCreationOptions options;
error = NavGetDefaultDialogCreationOptions( &options );
options.parentWindow = window;
options.modality = kWindowModalityWindowModal;
options.clientName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey( CFBundleGetMainBundle(), kCFBundleNameKey );
options.saveFileName = CFStringCreateWithPascalString( null, fileSpec->name, CFStringGetSystemEncoding());
NavDialogRef dialog;
error = NavCreateAskDiscardChangesDialog( &options, eventProc, this, &dialog );
error = NavDialogRun( dialog );
return error;
}
/*******************************/
/* NAV SERVICES EVENT HANDLERS */
/*******************************/
#pragma mark -
/*** NAV SERVICES EVENT FILTER ***/
pascal void NavEventFilter( NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD )
{
#pragma unused( callBackUD )
switch( callBackSelector )
{
case kNavCBEvent:
switch( cbRecord->eventData.eventDataParms.event->what )
{
default:
break;
}
break;
/* // Don't open file if it gets double-clicked (e.g. to add to an 'open' list instead)
case kNavCBOpenSelection:
NavCustomControl( callBackParms->context, (long) kNavCtlSetActionState, (void *) kNavDontOpenState );
break; */
}
}
/*** NAV SERVICES PREVIEW FILTER ***/
pascal Boolean NavPreviewFilter( NavCBRecPtr callBackParms, void *callBackUD )
{
#pragma unused( callBackParms, callBackUD )
return false;
}
/*** NAV SERVICES FILE FILTER ***/
pascal Boolean NavFileFilter( AEDescPtr theItem, void *info, void *callBackUD, NavFilterModes filterMode )
{
#pragma unused( theItem, info, callBackUD, filterMode )
/* do something useful here:
count rsources & types
give DF-based or RF-based info
maybe something else?
*/ return true;
}
#pragma mark -
/*** MODELESS GET FILE HANDLER ***/
pascal void ModelessGetFileHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD )
{
#pragma unused( callBackUD )
OSStatus error = noErr;
switch( callBackSelector )
{
case kNavCBAccept:
// case kNavCBUserAction:
{ // open first selected file
NavReplyRecord reply;
error = NavDialogGetReply( cbRecord->context, &reply );
if( reply.validRecord )
{
AEKeyword keyword;
DescType descType;
FSSpec fileSpec;
Size actualSize;
error = AEGetNthPtr( &(reply.selection), 1, typeFSS, &keyword, &descType, &fileSpec, sizeof(FSSpec), &actualSize );
if( !error ) new FileWindow( &fileSpec ); // if sucessful, opens & reads the file
}
else SysBeep(0);
NavDisposeReply( &reply );
} break;
case kNavCBTerminate:
{ // dispose of the dialog
NavDialogDispose( cbRecord->context );
} break;
}
}
/*** MODELESS ASK SAVE CHANGES HANDLER ***/
pascal void ModelessAskSaveChangesHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD )
{
OSStatus error = noErr;
FileWindowPtr file = (FileWindowPtr) callBackUD;
switch( callBackSelector )
{
case kNavCBUserAction:
{ // open first selected file
NavReplyRecord reply;
error = NavDialogGetReply( cbRecord->context, &reply );
if( reply.validRecord )
{
error = file->SaveFile( null );
}
else SysBeep(0);
NavDisposeReply( &reply );
} break;
case kNavCBTerminate:
{ // dispose of the dialog
NavDialogDispose( cbRecord->context );
} break;
}
}
/*** MODELESS PUT FILE HANDLER ***/
pascal void ModelessPutFileHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD )
{
OSStatus error = noErr;
// FileWindowPtr file = (FileWindowPtr) callBackUD;
switch( callBackSelector )
{
case kNavCBUserAction:
{ // open first selected file
NavReplyRecord reply;
error = NavDialogGetReply( cbRecord->context, &reply );
if( reply.validRecord )
{
;
}
else SysBeep(0);
NavDisposeReply( &reply );
} break;
case kNavCBTerminate:
{ // dispose of the dialog
NavDialogDispose( cbRecord->context );
} break;
}
}
/*** MODELESS ASK DISCARD CHANGES HANDLER ***/
pascal void ModelessAskDiscardChangesHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD )
{
OSStatus error = noErr;
// FileWindowPtr file = (FileWindowPtr) callBackUD;
switch( callBackSelector )
{
case kNavCBUserAction:
{ // open first selected file
NavReplyRecord reply;
error = NavDialogGetReply( cbRecord->context, &reply );
if( reply.validRecord )
{
;
}
else SysBeep(0);
NavDisposeReply( &reply );
} break;
case kNavCBTerminate:
{ // dispose of the dialog
NavDialogDispose( cbRecord->context );
} break;
}
}
/*********************/
/* READING & WRITING */
/*********************/
#pragma mark -
/*** READ RESOURCE FORK ***/
OSStatus FileWindow::ReadResourceFork( void )
{
// open file for reading
OSStatus error = noErr;
SInt16 oldResFile = CurResFile();
SetResLoad( false ); // don't load "preload" resources
SInt16 refNum = FSpOpenResFile( fileSpec, fsRdPerm );
SetResLoad( true );
if( !refNum ) return resFNotFound;
UseResFile( refNum );
error = ResError();
if( error ) // no resource map in resource fork, try in data fork before alerting user
DebugError( "\pResource map not present in resource fork", error );
// fork-independant resource reading routine
else error = ReadResourceMap();
rfBased = error? false:true;
// tidy up loose ends
UseResFile( oldResFile );
FSClose( refNum );
return error;
}
/*** READ DATA FORK ***/
OSStatus FileWindow::ReadDataFork( OSStatus rfError )
{
OSStatus error = rfError;
if( error ) // error occoured reading resource map from resource fork, try reading map from data fork instead
{
#if TARGET_API_MAC_CARBON
FSRef fileRef;
SInt16 refNum;
SInt16 oldResFile = CurResFile();
error = FSpMakeFSRef( fileSpec, &fileRef );
if( error )
{
DebugError( "\pFSpMakeFSRef error", error );
return error;
}
if( FSOpenResourceFile == (void *) kUnresolvedCFragSymbolAddress )
{
DisplayError( "\pCarbonLib version too old", "\pThe version of CarbonLib you have installed won't let you view files whose resources are stored in the data fork. Please update to version 1.3 GM of CarbonLib, available from http://www.apple.com/" );
error = paramErr;
return error;
}
SetResLoad( false ); // don't load "preload" resources
error = FSOpenResourceFile( &fileRef, 0, null, fsRdPerm, &refNum );
SetResLoad( true );
if( error || !refNum )
{
DisplayError( "\pThis file is corrupt", "\pSorry, but you will not be able to open it. You should replace it with a backÑup. FSOpenResourceFile()" );
return error? error:resFNotFound;
}
UseResFile( refNum );
// fork-independant resource reading routine
error = ReadResourceMap();
// tidy up loose ends
UseResFile( oldResFile );
FSClose( refNum );
#endif
return error;
}
else // no error occoured reading resource map from resource fork, read data fork as byte stream
{
// open file for reading
SInt16 refNum;
error = FSpOpenDF( fileSpec, fsRdPerm, &refNum );
if( error )
{
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." );
return error;
}
ResourceObjectPtr current = (ResourceObjectPtr) NewPtrClear( sizeof(ResourceObject) );
if( !current )
{
DisplayError( "\pNot enough memory to read data fork", "\pPlease quit other applications and try again." );
FSClose( refNum );
return error;
}
current->number = kDataBrowserDataForkItem; // ID of fork in dataBrowser
*current->name = 0x00;
current->type = 0x00000000;
current->resID = 0;
GetEOF( refNum, &current->size );
current->attribs = 0;
current->nameIconRgn = NewRgn();
current->file = this;
current->dataFork = true;
// get new handle
current->retainCount = 1;
current->data = NewHandleClear( current->size );
if( !current->data || MemError() )
{
DisplayError( "\pNot enough memory to read data fork", "\pPlease quit other applications and try again." );
FSClose( refNum );
return memFullErr;
}
// read data fork
HLock( current->data );
error = FSRead( refNum, &current->size, *current->data );
HUnlock( current->data );
if( error )
{
DisplayError( "\pFailed to read data fork.", "\pA mysterious error occured reading the data fork. The record saying how long the file is has probably been corrupted. You should run Disk First Aid to repair the dis." );
FSClose( refNum );
return error;
}
current->next = resourceMap;
resourceMap = current;
FSClose( refNum );
return error;
}
}
/*** READ RESOURCE MAP ***/
OSStatus FileWindow::ReadResourceMap( void )
{
OSStatus error = noErr;
// set up variables & first resource record
numResources = 0;
numTypes = Count1Types();
resourceMap = (ResourceObjectPtr) NewPtrClear( sizeof(ResourceObject) );
// resourceMap = new ResourceObject( this );
ResourceObjectPtr current = resourceMap;
for( unsigned short i = 1; i <= numTypes; i++ )
{
// read in each data type
ResType type;
Get1IndType( &type, i );
UInt16 n = Count1Resources( type );
for( UInt16 j = 1; j <= n; j++ )
{
// get resource info
// SetResLoad( false );
current->data = Get1IndResource( type, j );
error = ResError();
// SetResLoad( true );
if( MemError() )
{
DisplayError( "\pNot enough memory to read all resources", "\pPlease quit other applications and try again." );
DisposePtr( (Ptr) current );
return memFullErr;
}
if( !current->Data() || error != noErr )
{
DisplayError( "\pResources are damaged, proceed with extreme caution!" );
// bug: dialog should have "continue", "stop" and "quit" buttons, stop being default
DisposePtr( (Ptr) current );
// delete current;
return error; // bug: what should I be doing here?
}
current->number = numResources + j; // ID of resource in dataBrowser
GetResInfo( current->Data(), &current->resID, &current->type, current->name );
current->size = GetResourceSizeOnDisk( current->Data() );
current->attribs = GetResAttrs( current->Data() );
current->file = this;
current->dataFork = false;
DetachResource( current->Data() ); // bug: this needs to be here so calling AddResource() when saving will work, but if ResLoad() was off above, it will kill the only link between the Handle and the resource.
if( i != numTypes || j != n ) // if this isn't the last resourceÉ
{
// Émove on to the next one
current->next = (ResourceObjectPtr) NewPtrClear( sizeof(ResourceObject) );
// current->next = new ResourceObject( this );
current = current->next;
}
}
numResources += n;
}
return error;
}
/*** SAVE FILE ***/
OSStatus FileWindow::SaveFile( FSSpecPtr saveSpec )
{
OSStatus error;
if( saveSpec == null ) // we're straight saving the file, use a temp file, then switch
{
// set up file name
Str255 countStr; // bug: this is not initalised before being used
Str255 tempFileName = "\pResKnife Temporary File ";
NumToString( ++g.tempCount, (StringPtr) countStr );
AppendPString( tempFileName, countStr );
// create temporary file spec
SInt32 dirID;
SInt16 vRefNum; // Always create the temporary file on the same volume as the file we're saving, otherwise FSpExchangeFiles() won't work
OSStatus error = FindFolder( fileSpec->vRefNum, /*kTemporaryFolderType*/ kDesktopFolderType, kCreateFolder, &vRefNum, &dirID );
if( error ) DebugError( "\pFindFolder returned error.", error );
error = FSMakeFSSpec( vRefNum, dirID, tempFileName, tempSpec );
if( error == noErr )
{
DisplayError( "\pFile already exists", "\pThe temporary file used by ResKnife to protect your data already exists, try saving again. If the problem persists, flush your temporary items folder with a utility such as Eradicator." );
return error;
}
else if( error != fnfErr && error != dirNFErr )
{
DebugError( "\pError calling FSMakeFSSpec from FileWindow::SaveFile.", error );
return error;
}
}
else // we're doing a 'save as', no need for temp file
{ // if we created one, then FSpExchange wouldn't work
tempSpec = saveSpec;
}
// save plain DF if present
ResourceObjectPtr current = resourceMap;
if( rfBased && current->RepresentsDataFork() ) // requires data fork to be first item in list
{
// create data fork
FSpCreate( tempSpec, kResKnifeCreator, kResourceFileType, smSystemScript );
// open file for writing
SInt16 refNum;
error = FSpOpenDF( tempSpec, fsWrPerm, &refNum );
if( error )
{
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." );
return error;
}
// save byte stream
SInt8 state = HGetState( resourceMap->Data() );
HLock( current->Data() );
SInt32 size = current->Size();
SetEOF( refNum, size );
error = FSWrite( refNum, &size, (Ptr) *current->Data() );
HSetState( current->Data(), state );
FSClose( refNum );
}
else if( !rfBased && current->RepresentsDataFork() )
{
DisplayError( "\pData fork present with DF-based resource file." );
}
else if( rfBased )
{
DisplayError( "\pTried to save resource fork based file, but no data fork could be found" );
}
// save resource map in specified fork
if( rfBased )
{
SInt16 oldResFile = CurResFile();
FSpCreateResFile( tempSpec, kResKnifeCreator, kResourceFileType, smSystemScript );
SInt16 tempRef = FSpOpenResFile( tempSpec, fsWrPerm );
UseResFile( tempRef );
error = SaveResourceMap();
UseResFile( oldResFile );
CloseResFile( tempRef );
error = ResError();
if( error )
{
DebugError( "\pError calling CloseResFile.", error );
return error;
}
}
else
{
FSRef fileRef;
SInt16 refNum;
SInt16 oldResFile = CurResFile();
error = FSpMakeFSRef( tempSpec, &fileRef );
if( error )
{
DebugError( "\pFSpMakeFSRef error", error );
return error;
}
if( FSOpenResourceFile == (void *) kUnresolvedCFragSymbolAddress )
{
DisplayError( "\pCarbonLib version too old", "\pThe version of CarbonLib you have installed won't let you save resources into the data fork. Please update to version 1.3.1 of CarbonLib, available from http://www.apple.com/" );
error = paramErr;
return error;
}
/* error = FSCreateResourceFile( &fileRef, );
const FSRef * parentRef,
UniCharCount nameLength,
const UniChar * name,
FSCatalogInfoBitmap whichInfo,
const FSCatalogInfo * catalogInfo, // can be NULL
UniCharCount forkNameLength,
const UniChar * forkName, // can be NULL
FSRef * newRef, // can be NULL
FSSpec * newSpec); // can be NULL
if( error )
{
DisplayError( "\pFile could not be created", "\pThe file to save your resources into could not be created. FSCreateResourceFile()" );
return error? error:resFNotFound;
}
*/ error = FSOpenResourceFile( &fileRef, 0, null, fsRdPerm, &refNum );
if( error || !refNum )
{
DisplayError( "\pFile could not be created", "\pThe file to save your resources into could not be created. FSOpenResourceFile()" );
return error? error:resFNotFound;
}
UseResFile( refNum );
error = SaveResourceMap();
UseResFile( oldResFile );
CloseResFile( refNum );
error = ResError();
if( error )
{
DebugError( "\pError calling CloseResFile.", error );
return error;
}
}
// switch file for temp if we did a regular save
if( saveSpec == null )
{
// swap the temporary file for the real one
error = FSpExchangeFiles( tempSpec, fileSpec ); // bug: this will fail on non HFS/HFS+ file systems - therefore file will not save
if( error )
{
DebugError( "\pError calling FSpExchangeFiles.", error );
return error;
}
error = FSpDelete( tempSpec );
if( error )
{
DebugError( "\pError calling FSpDelete.", error );
}
// file is no longer dirty
fileDirty = false;
SetWindowModified( window, fileDirty );
}
return error;
}
/*** SAVE RESOURCE MAP ***/
OSStatus FileWindow::SaveResourceMap( void )
{
OSStatus error = noErr;
// save resources from memory to the temp file
ResourceObjectPtr current = resourceMap;
if( current->RepresentsDataFork() == true )
current = current->Next(); // skip data fork
while( current )
{
// save resource
AddResource( current->Data(), current->Type(), current->ID(), current->Name() );
if( ResError() == addResFailed )
{
DisplayError( "\pSaving Failed", "\pCould not add resources to file." );
current = null;
error = addResFailed;
}
else
{
SetResAttrs( current->Data(), current->Attributes() );
ChangedResource( current->Data() );
// clean up & move on
DetachResource( current->Data() );
current = current->Next();
}
}
return error;
}

View File

@ -1,62 +0,0 @@
#include "ResKnife.h"
#ifndef _ResKnife_Files_
#define _ResKnife_Files_
/*!
@header File Handling Code
@discussion All code that reads from and writes to a file resides in here. Also contains open, save and revert dialog code.
*/
/*!
@function DisplayOpenDialog
@discussion Calls the appropriate <tt>Open()</tt> function for the system we are running on.
*/
OSStatus DisplayOpenDialog( void );
/*!
@function DisplayModelessGetFileDialog
@discussion Requires CarbonLib 1.1 or OS X
*/
OSStatus DisplayModelessGetFileDialog( void );
/*!
@function OpenFile
*/
OSStatus OpenFile( short vRefNum, long dirID, ConstStr255Param fileName );
/*!
@function DisplayStandardFileOpenDialog
*/
OSStatus DisplayStandardFileOpenDialog( void );
/*!
@function ModelessGetFileHandler
@discussion Requires CarbonLib 1.1 or OS X
*/
pascal void ModelessGetFileHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD );
/*!
@function ModelessAskSaveChangesHandler
@discussion Requires CarbonLib 1.1 or OS X
*/
pascal void ModelessAskSaveChangesHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD );
/*!
@function ModelessPutFileHandler
@discussion Requires CarbonLib 1.1 or OS X
*/
pascal void ModelessPutFileHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD );
/*!
@function ModelessAskDiscardChangesHandler
@discussion Requires CarbonLib 1.1 or OS X
*/
pascal void ModelessAskDiscardChangesHandler( const NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD );
/*!
@function NavEventFilter
*/
pascal void NavEventFilter( NavEventCallbackMessage callBackSelector, NavCBRecPtr cbRecord, NavCallBackUserData callBackUD );
/*!
@function NavPreviewFilter
*/
pascal Boolean NavPreviewFilter( NavCBRecPtr callBackParms, void *callBackUD );
/*!
@function NavFileFilter
*/
pascal Boolean NavFileFilter( AEDescPtr theItem, void *info, void *callBackUD, NavFilterModes filterMode );
#endif

View File

@ -1,201 +0,0 @@
#define _ResKnife_Plug_ 0
#include "HostCallbacks.h"
#include "Application.h"
#include "WindowObject.h"
#include "EditorWindow.h"
#include "PlugObject.h"
#include "Errors.h"
extern globals g;
/* window management */
Plug_WindowRef Host_RegisterWindow( Plug_PlugInRef plug, Plug_ResourceRef resource, WindowRef window )
{
if( resource )
{
EditorWindowPtr plugWindow = new EditorWindow( ((ResourceObjectPtr) resource)->File(), (ResourceObjectPtr) resource, window );
((PlugObjectPtr) plug)->SetWindowObject( (WindowObjectPtr) plugWindow );
((PlugObjectPtr) plug)->SetResourceObject( (ResourceObjectPtr) resource );
return (Plug_WindowRef) plugWindow;
}
/* else
{
PickerWindowPtr plugWindow = new PickerWindow( window );
((PlugObjectPtr) plug)->SetWindowObject( plugWindow );
((PlugObjectPtr) plug)->SetResourceObject( (ResourceObjectPtr) resource );
return (Plug_WindowRef) plugWindow;
}
*/ else return null;
}
#if !TARGET_API_MAC_CARBON
void Host_InstallClassicWindowEventHandler( Plug_WindowRef plugWindow, RoutineDescriptor *handler )
{
((PlugWindowPtr) plugWindow)->InstallClassicEventHandler( (ClassicEventHandlerProcPtr) handler );
}
#endif
WindowRef Host_GetWindowRefFromPlugWindow( Plug_WindowRef plugWindow )
{
return ((WindowObjectPtr) plugWindow)->Window();
}
Plug_WindowRef Host_GetPlugWindowFromWindowRef( WindowRef window )
{
return (Plug_WindowRef) GetWindowRefCon(window);
}
Plug_PlugInRef Host_GetPlugRef( WindowRef window )
{
#pragma unused( window )
return null;
}
Plug_ResourceRef Host_GetResource( ResType type, SInt32 resID, Plug_ResourceRef sameFileAsResource )
{
// FileWindowPtr file;
if( sameFileAsResource != NULL )
{
// file = ((ResourceObjectPtr) sameFileAsResource)->file;
short oldResFile = CurResFile();
UseResFile( HomeResFile( ((ResourceObjectPtr) sameFileAsResource)->Data() ) );
Get1Resource( type, resID ); // bug: handle ignored at present
UseResFile( oldResFile );
}
else GetResource( type, resID ); // bug: handle ignored at present
return nil; // bug: handle ignored at present
}
Plug_ResourceRef Host_GetTargetResource( Plug_WindowRef plugWindow )
{
return (Plug_ResourceRef) ((EditorWindowPtr) plugWindow)->Resource();
}
/* accessors */
Handle Host_GetResourceData( Plug_ResourceRef resource )
{
((ResourceObjectPtr) resource)->Retain();
return ((ResourceObjectPtr) resource)->Data();
}
Handle Host_GetPartialResourceData( Plug_ResourceRef resource, UInt32 offset, UInt32 length )
{
#pragma unused( resource, offset, length )
return null;
}
void Host_ReleaseResourceData( Plug_ResourceRef resource )
{
#pragma unused( resource )
// ((ResourceObjectPtr) resource)->Release();
return;
}
void Host_ReleasePartialResourceData( Plug_ResourceRef resource, Handle data )
{
#pragma unused( resource, data )
return;
}
ResType Host_GetResourceType( Plug_ResourceRef resource )
{
return ((ResourceObjectPtr) resource)->Type();
}
SInt16 Host_GetResourceID( Plug_ResourceRef resource )
{
return ((ResourceObjectPtr) resource)->ID();
}
UInt32 Host_GetResourceSize( Plug_ResourceRef resource )
{
return ((ResourceObjectPtr) resource)->Size();
}
void Host_GetResourceName( Plug_ResourceRef resource, Str255 name )
{
#pragma unused( resource, name )
return;
}
UInt32 Host_GetWindowRefCon( Plug_WindowRef plugWindow )
{
return ((PlugWindowPtr) plugWindow)->GetRefCon();
}
void Host_SetWindowRefCon( Plug_WindowRef plugWindow, UInt32 value )
{
((PlugWindowPtr) plugWindow)->SetRefCon(value);
}
UInt32 Host_GetGlobalRefCon( Plug_PlugInRef plug )
{
return ((PlugObjectPtr) plug)->GetRefCon();
}
void Host_SetGlobalRefCon( Plug_PlugInRef plug, UInt32 value )
{
((PlugObjectPtr) plug)->SetRefCon(value);
}
Boolean Host_GetResourceDirty( Plug_ResourceRef resource )
{
return ((ResourceObjectPtr) resource)->Dirty();
}
void Host_SetResourceDirty( Plug_ResourceRef resource, Boolean dirty )
{
((ResourceObjectPtr) resource)->SetDirty( dirty );
}
/* utilities */
Handle Host_GetDefaultTemplate( ResType type )
{
short savedResFile = CurResFile();
UseResFile( g.appResFile );
Str255 name = "\pxxxx";
BlockMoveData( &type, name +1, sizeof(ResType) );
Handle tmpl = Get1NamedResource( 'TMPL', name );
OSStatus error = ResError();
UseResFile( savedResFile );
if( error ) return null;
else return tmpl;
}
void Host_AppendMenuToBar( Plug_PlugInRef plug, SInt16 resID )
{
#pragma unused( plug, resID )
return;
}
void Host_RemoveMenuFromBar( Plug_PlugInRef plug, SInt16 resID )
{
#pragma unused( plug, resID )
return;
}
void Host_UpdateMenus( Plug_ResourceRef resource )
{
OSStatus error = noErr;
#if TARGET_API_MAC_CARBON
error = CarbonEventUpdateMenus( null, null, null );
// if( error ) DebugError( "\pHost_UpdateMenus hit an error when calling CarbonEventUpdateMenus()" );
error = FileWindowUpdateMenus( null, null, ((ResourceObjectPtr) resource)->File() );
// if( error ) DebugError( "\pHost_UpdateMenus hit an error when calling FileWindowUpdateMenus()" );
#else
UpdateMenus( ((ResourceObjectPtr) resource)->File()->Window() );
#endif
}
void Host_DisplayError( ConstStr255Param errorStr, ConstStr255Param explanationStr, UInt8 severity )
{
#pragma unused( severity )
DisplayError( errorStr, explanationStr );
}
void Host_DebugError( ConstStr255Param errorStr, OSStatus number )
{
DebugError( errorStr, number );
}

View File

@ -1,254 +0,0 @@
#if !TARGET_API_MAC_OS8
#if !defined(__MWERKS__) // compiling with ProjectBuilder
#include <Carbon/Carbon.h>
#endif
#endif
#ifndef _ResKnife_HostCallbacks_
#define _ResKnife_HostCallbacks_
/*!
* @header Plug-in Import/Export
* @discussion The only file that both plug-ins and the host should include, this allows a one-to-one mapping between exported and imported functions.
*/
/*!
* @typedef Plug_PlugInRef
* @abstract A global reference to your plug-in.
* @discussion When you plug-in is first loded it is assigned a unique reference number. This allows you to maintain a global refcon into which you can save a pointer to your globals. Thus any change to preferences can be maintained across all of your open editors, even if they are editing resources in different files, and is persistant across the entire time the host remains running.
*/
typedef struct OpaquePlugInObject* Plug_PlugInRef;
/*!
* @typedef Plug_WindowRef
* @abstract A reference to one of your editor or picker windows.
* @discussion The <tt>Plug_WindowRef</tt> allows a host to track your window and send it events
*/
typedef struct OpaqueWindowObject* Plug_WindowRef;
/*!
* @typedef Plug_ResourceRef
* @abstract A reference to one particular resource.
* @discussion Allows a plug to obtain information about <i>any</i> resource, not necessarily the one it is editing. For example, a 'TEXT' editor will probably want 'styl' resource data as well.
*/
typedef struct OpaqueResourceObject* Plug_ResourceRef;
/*!
* @typedef Plug_MenuCommand
* @abstract Passed to your menu parser when the user selects something.
* @discussion Contains the four-byte menu command defined in your xmnu resources or that which you chose when creating the menu in InterfaceBuilder. Only used with the <tt>Plug_HandleMenuCommand()</tt> function.
*/
typedef UInt32 Plug_MenuCommand;
// idea taken from Starry Night (thanks Tom)
#if TARGET_API_MAC_OS8
#if _ResKnife_Plug_ // you should #define this to be 1É
#define ResCall __declspec(dllimport) // functions exported by the host
#define ResCallBack __declspec(dllexport) // functions exported by the plug-in
#else // Éthe host #defines 0
#define ResCall __declspec(dllexport)
#define ResCallBack __declspec(dllimport)
#endif
#else
#define ResCall
#define ResCallBack
#endif
/*!
* @enum EditorType
* @discussion Allows a plug-in to tell the host what it does in a consice and simple way.
*/
typedef enum
{
kPickerType = FOUR_CHAR_CODE('pick'),
kHexEditorType = FOUR_CHAR_CODE('hexa'), // returned ResTypes are ignored
kNormalEditorType = FOUR_CHAR_CODE('norm') // requires 'kind' to be set to the appropriate ResType
} EditorType;
/*!
* @enum OpenMode
* @discussion Lets the plug-in <i>influence</i> how sub-editors are chosen when the plug requests that a new editor be opened
* via <tt>Host_OpenEditor()</tt>. If it cannot be fulfilled, a lesser type of window will open.
*/
typedef enum
{
kOpenUsingEditor = 0,
kOpenUsingTemplate,
kOpenUsingHex
} OpenMode;
/*!
* @enum Plug-in WindowKinds
* @discussion ID numbers for generic plug windows.
*/
enum
{
kPlugWindowDocument = 1000, // your main window's windowkind is set to this by the host, do NOT change it.
kPlugWindowAboutBox, // windowkinds below 2000 are reserved
kPlugWindowPreferences
};
/*** IMPORTED FUNCTIONS ***/
extern "C" // functions beginning "Host_" are in ResKnife/Resurrection
{
/*!
* @function Host_RegisterWindow
* @abstract Registers plug-in windows with the host.
* @discussion Plug-ins should call this function immediatly after creating a window to swap their Mac OS <tt>WindowRef</tt>
* for a <tt>Plug_WindowRef</tt>, which allows the host to track the window, it's contents, and to send events there.
*/
ResCall Plug_WindowRef Host_RegisterWindow( Plug_PlugInRef plug, Plug_ResourceRef resource, WindowRef window );
/*!
* @function Host_InstallClassicWindowEventHandler
* @abstract Without this, non-carbon plugs will not receive events
* @discussion After regestering you window, and only if you do not have access to the Carbon routine <tt>InstallWindowEventHandler()</tt>,
* your plug should call this to receive events. Events sent are currently limited to:
*
* &bull; kEventWindowClickContentRgn
*/
ResCall void Host_InstallClassicWindowEventHandler( Plug_WindowRef plugWindow, RoutineDescriptor *handler );
/*!
* @function Host_GetWindowRefFromPlugWindow
* @abstract Allows plug-ins to obtain a Mac OS <tt>WindowRef</tt> from their <tt>Plug_WindowRef</tt>
* @discussion This call must not be made before the window has been registered using <tt>Host_RegisterWindow()</tt>
*/
ResCall WindowRef Host_GetWindowRefFromPlugWindow( Plug_WindowRef plugWindow );
/*!
* @function Host_GetPlugWindowFromWindowRef
* @abstract Allows plug-ins to obtain a <tt>Plug_WindowRef</tt> from their Mac OS <tt>WindowRef</tt>
* @discussion This call must not be made before the window has been registered using <tt>Host_RegisterWindow()</tt>
*/
ResCall Plug_WindowRef Host_GetPlugWindowFromWindowRef( WindowRef window );
/*!
* @function Host_GetPlugRef
* @discussion You will probably need to call this if the system calls one of your routines directly.
*/
ResCall Plug_PlugInRef Host_GetPlugRef( WindowRef window );
/*!
* @function Host_GetResource
* @discussion Returns a reference to any arbitrary resource.
* @param limitToDoc If true, the function will only search the same document that contains the resource returned by Host_GetTargetResource. If false, it will return any resource in the current resource chain.
*/
ResCall Plug_ResourceRef Host_GetResource( SInt32 type, SInt32 resID, Boolean limitToDoc );
/*!
* @function Host_GetTargetResource
* @discussion Returns the reference to the resource you're actually editing.
*/
ResCall Plug_ResourceRef Host_GetTargetResource( Plug_WindowRef plugWindow );
/*!
* @function Host_GetResourceData
* @discussion Dispose of with <tt>Host_ReleaseResourceData()</tt>
*/
ResCall Handle Host_GetResourceData( Plug_ResourceRef resource );
/*!
* @function Host_GetPartialResourceData
* @discussion Dispose of with <tt>Host_ReleasePartialResourceData()</tt>
*/
ResCall Handle Host_GetPartialResourceData( Plug_ResourceRef resource, UInt32 offset, UInt32 length );
/*!
* @function Host_ReleaseResourceData
*/
ResCall void Host_ReleaseResourceData( Plug_ResourceRef resource );
/*!
* @function Host_ReleasePartialResourceData
*/
ResCall void Host_ReleasePartialResourceData( Plug_ResourceRef resource, Handle data );
/*!
* @function Host_GetResourceType
*/
ResCall ResType Host_GetResourceType( Plug_ResourceRef resource );
/*!
* @function Host_GetResourceID
*/
ResCall SInt16 Host_GetResourceID( Plug_ResourceRef resource );
/*!
* @function Host_GetResourceSize
*/
ResCall UInt32 Host_GetResourceSize( Plug_ResourceRef resource );
/*!
* @function Host_GetResourceName
*/
ResCall void Host_GetResourceName( Plug_ResourceRef resource, Str255 name );
/* ResCall void Host_SetResourceName( Plug_ResourceRef resource, ConstStr255Param name ); */
/*!
* @function Host_GetResourceDirty
*/
ResCall Boolean Host_GetResourceDirty( Plug_ResourceRef resource );
/*!
* @function Host_SetResourceDirty
*/
ResCall void Host_SetResourceDirty( Plug_ResourceRef resource, Boolean dirty );
/* ResCall Boolean Host_GetResourceIsOnDisk( Plug_ResourceRef resource ); */ // name may change soon
/*!
* @function Host_GetWindowRefCon
*/
ResCall UInt32 Host_GetWindowRefCon( Plug_WindowRef plugWindow );
/*!
* @function Host_SetWindowRefCon
*/
ResCall void Host_SetWindowRefCon( Plug_WindowRef plugWindow, UInt32 value );
/*!
* @function Host_GetGlobalRefCon
*/
ResCall UInt32 Host_GetGlobalRefCon( Plug_PlugInRef plugRef );
/*!
* @function Host_SetGlobalRefCon
*/
ResCall void Host_SetGlobalRefCon( Plug_PlugInRef plugRef, UInt32 value );
/* ResCall OSStatus Host_OpenEditor( Plug_ResourceRef resource, ResOpenMode mode );
ResCall OSStatus Host_SaveResource( Plug_ResourceRef resource ); // VERY IMPORTANT CALL! - Make when closing window
ResCall void Host_SetCursor( Plug_PlugInRef plugRef, Cursor *cursor );
ResCall void Host_SetCursorToID( Plug_PlugInRef plugRef, SInt16 resID );
*/
/*!
* @function Host_GetDefaultTemplate
* @abstract Returns the default TMPL resource for the resource type passed in.
* @discussion Handle is <tt>NULL</tt> if no template exists. You must dispose of the handle yourself.
*/
ResCall Handle Host_GetDefaultTemplate( ResType type );
/*!
* @function Host_AppendMenuToBar
* @discussion The host will track your window, and hide the menu when you are not fromtmost.
*/
ResCall void Host_AppendMenuToBar( Plug_PlugInRef plug, SInt16 resID );
/*!
* @function Host_RemoveMenuFromBar
*/
ResCall void Host_RemoveMenuFromBar( Plug_PlugInRef plug, SInt16 resID );
/*!
* @function Host_UpdateMenus
*/
ResCall void Host_UpdateMenus( Plug_ResourceRef resource );
/*!
* @function Host_DisplayError
* @discussion Errors the user should see
*/
ResCall void Host_DisplayError( ConstStr255Param error, ConstStr255Param explanation, UInt8 severity );
/*!
* @function Host_DebugError
* @discussion Errors the user shouldn't see
*/
ResCall void Host_DebugError( ConstStr255Param error, OSStatus number );
}
/*** EXPORTED FUNCTIONS ***/
extern "C" // functions beginning "Plug_" should be in your plug-in editor
{
/* required functions - plug-in won't be loaded if all these symbols cannot be found */
/* ResCallBack OSStatus Plug_EditorType( Plug_PlugInRef plugRef, EditorType *type, ResType *kind, UInt8 *number ); // called to identify the number of different types of resources it can handle
*/
/*!
* @function Plug_InitInstance
* @abstract Allows a plug-in to initalise itself and prepare to edit the resource.
* @discussion This is a required call. You must export this for your plug-in to be loaded.
* @param plug A reference which has been assigned to this plug-in. It will not necessarily remain constant, so do not save it beyond this call returning.
* @param resource A reference to the resource whose editing session has been requested.
*/
ResCallBack OSStatus Plug_InitInstance( Plug_PlugInRef plug, Plug_ResourceRef resource );
/* ResCallBack OSStatus Plug_FlattenResource( Plug_PlugInRef plugRef, Plug_ResourceRef resource ); // update the handle provided by the host (see Host_GetResData)
ResCallBack OSStatus Plug_ResourceChanged( Plug_PlugInRef plugRef, Plug_ResourceRef resource ); // another editor has changed the resource your working on (normally responded to by calling Host_GetResData and a window update)
*/ /* optional functions - only called if they are requested & found */
/* ResCallBack OSStatus Plug_UpdateMenu( Plug_PlugInRef plugRef, Plug_WindowRef windowObject );
ResCallBack OSStatus Plug_HandleMenuCommand( Plug_PlugInRef plugRef, Plug_MenuCommand menuCmd, Boolean *handled );
ResCallBack OSStatus Plug_HandleMenuItem( Plug_PlugInRef plugRef, SInt16 menuID, SInt16 itemID, Boolean *handled ); // name change
ResCallBack OSStatus Plug_AboutBox( Plug_PlugInRef plugRef );
*/}
#endif

View File

@ -1,273 +0,0 @@
#include "InspectorWindow.h"
#include "FileWindow.h"
#include "ResourceObject.h"
#include "Utility.h"
extern globals g;
/*******************/
/* WINDOW & EVENTS */
/*******************/
/*** CONSTRUCTOR ***/
InspectorWindow::InspectorWindow( void )
{
// if inspector already exists, return
if( g.inspector )
{
SelectWindow( g.inspector->Window() );
return;
}
#if TARGET_API_MAC_CARBON
// create window
Str255 windowName;
Rect creationBounds;
SetRect( &creationBounds, 0, 0, kInspectorWindowWidth, kInspectorWindowHeight );
OffsetRect( &creationBounds, 520, 45 );
OSStatus error = CreateNewWindow( kFloatingWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute, &creationBounds, &window );
if( !error )
{
GetIndString( windowName, kWindowNameStrings, kStringInspectorWindowName );
SetWindowTitle( window, windowName );
SetWindowKind( window, kInspectorWindowKind );
SetThemeWindowBackground( window, kThemeBrushUtilityWindowBackgroundActive, false );
// install window event handler
EventHandlerRef ref = null;
EventHandlerUPP eventHandler = NewEventHandlerUPP( CloseInspectorWindow );
EventTypeSpec events[] = { { kEventClassWindow, kEventWindowClose } };
InstallWindowEventHandler( window, eventHandler, GetEventTypeCount(events), (EventTypeSpec *) &events, this, &ref );
// create root control
Rect bounds;
if( g.systemVersion < kMacOSX )
{
ControlRef root;
CreateRootControl( window, &root );
}
// create image well
ControlRef imageWell;
ControlButtonContentInfo content;
content.contentType = kControlNoContent;
SetRect( &bounds, 0, 0, 44, 44 );
OffsetRect( &bounds, 8, 8 );
CreateImageWellControl( window, &bounds, &content, &imageWell );
// create static text controls
Rect windowRect;
ControlRef name, type, id;
ControlFontStyleRec fontStyle;
fontStyle.flags = kControlUseFontMask + kControlUseJustMask;
fontStyle.font = kControlFontSmallSystemFont;
fontStyle.just = teJustLeft;
GetWindowPortBounds( window, &windowRect );
SetRect( &bounds, windowRect.left +60, windowRect.top +8, windowRect.right - windowRect.left -8, windowRect.top +36 );
CreateStaticTextControl( window, &bounds, CFSTR(""), &fontStyle, &name );
fontStyle.font = kControlFontSmallBoldSystemFont;
SetRect( &bounds, windowRect.left +60, windowRect.top +38, windowRect.right - windowRect.left -70, windowRect.top +52 );
CreateStaticTextControl( window, &bounds, CFSTR(""), &fontStyle, &type );
SetRect( &bounds, windowRect.right - windowRect.left -70, windowRect.top +38, windowRect.right - windowRect.left -8, windowRect.top +52 );
CreateStaticTextControl( window, &bounds, CFSTR(""), &fontStyle, &id );
// create group control
ControlRef group;
GetWindowPortBounds( window, &bounds );
InsetRect( &bounds, 8, 8 );
bounds.top += kInspectorHeaderHeight;
CreateGroupBoxControl( window, &bounds, CFSTR("Attributes"), true, &group );
// create checkboxes
ControlRef changedBox, preloadBox, protectedBox,
lockedBox, purgeableBox, sysHeapBox;
InsetRect( &bounds, 4, 4 );
bounds.top = bounds.bottom - kControlCheckBoxHeight;
CreateCheckBoxControl( window, &bounds, CFSTR("System Heap"), kControlCheckBoxUncheckedValue, true, &sysHeapBox );
bounds.top -= kControlCheckBoxHeight;
bounds.bottom -= kControlCheckBoxHeight;
CreateCheckBoxControl( window, &bounds, CFSTR("Purgeable"), kControlCheckBoxUncheckedValue, true, &purgeableBox );
bounds.top -= kControlCheckBoxHeight;
bounds.bottom -= kControlCheckBoxHeight;
CreateCheckBoxControl( window, &bounds, CFSTR("Locked"), kControlCheckBoxUncheckedValue, true, &lockedBox );
bounds.top -= kControlCheckBoxHeight;
bounds.bottom -= kControlCheckBoxHeight;
CreateCheckBoxControl( window, &bounds, CFSTR("Protected"), kControlCheckBoxUncheckedValue, true, &protectedBox );
bounds.top -= kControlCheckBoxHeight;
bounds.bottom -= kControlCheckBoxHeight;
CreateCheckBoxControl( window, &bounds, CFSTR("Preload"), kControlCheckBoxUncheckedValue, true, &preloadBox );
bounds.top -= kControlCheckBoxHeight;
bounds.bottom -= kControlCheckBoxHeight;
CreateCheckBoxControl( window, &bounds, CFSTR("Changed"), kControlCheckBoxUncheckedValue, true, &changedBox );
// embed controls
EmbedControl( changedBox, group );
EmbedControl( preloadBox, group );
EmbedControl( protectedBox, group );
EmbedControl( lockedBox, group );
EmbedControl( purgeableBox, group );
EmbedControl( sysHeapBox, group );
}
else window = NULL;
#else
if( g.useAppearance && g.systemVersion >= kMacOS8 )
window = GetNewCWindow( kFileWindow8, null, kFirstWindowOfClass );
else
window = GetNewCWindow( kFileWindow7, null, kFirstWindowOfClass );
#endif
if( window )
{
// update and show window
Update();
ShowWindow( window );
g.inspector = this;
}
else g.inspector = NULL;
}
/*** DESTRUCTOR ***/
InspectorWindow::~InspectorWindow( void )
{
g.inspector = null;
}
/*** CLOSW WINDOW EVENT HANDLER ***/
pascal OSStatus CloseInspectorWindow( EventHandlerCallRef callRef, EventRef event, void *userData )
{
#pragma unused( callRef, event, userData )
if( g.inspector ) delete g.inspector;
return eventNotHandledErr;
}
/*** UPDATE WINDOW ***/
OSStatus InspectorWindow::Update( RgnHandle region )
{
#pragma unused( region )
#if TARGET_API_MAC_CARBON
// get target file
FileWindowPtr file = null;
WindowRef fileWindow = GetFrontWindowOfClass( kDocumentWindowClass, true );
if( !fileWindow ) return noErr; // no window is open - BUG: items in window are not cleared
OSStatus error = noErr;
Boolean validWindow = false;
while( !validWindow || error )
{
WindowKind kind = (WindowKind) GetWindowKind( fileWindow );
if( kind != kFileWindowKind )
{
fileWindow = GetNextWindowOfClass( fileWindow, kDocumentWindowClass, true );
if( !window ) error = paramErr;
}
else
{
file = (FileWindowPtr) GetWindowRefCon( fileWindow );
if( file ) validWindow = true;
else error = paramErr;
}
}
if( error ) return error;
// get selection
UInt32 itemCount;
ControlRef browser = null;
GetWindowProperty( fileWindow, kResKnifeCreator, kDataBrowserSignature, sizeof(ControlRef), null, &browser );
GetDataBrowserItemCount( browser, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, &itemCount );
// get controls
ControlRef root, well, name, type, id, group;
ControlRef changedBox, preloadBox, protectedBox, lockedBox, purgeableBox, sysHeapBox;
ControlButtonContentInfo content;
GetRootControl( window, &root );
GetIndexedSubControl( root, 1, &well );
GetIndexedSubControl( root, 2, &name );
GetIndexedSubControl( root, 3, &type );
GetIndexedSubControl( root, 4, &id );
GetIndexedSubControl( root, 5, &group );
GetIndexedSubControl( group, 1, &changedBox );
GetIndexedSubControl( group, 2, &preloadBox );
GetIndexedSubControl( group, 3, &protectedBox );
GetIndexedSubControl( group, 4, &lockedBox );
GetIndexedSubControl( group, 5, &purgeableBox );
GetIndexedSubControl( group, 6, &sysHeapBox );
if( itemCount != 1 )
{
// set icon
content.contentType = kControlNoContent;
SetImageWellContentInfo( well, &content );
DrawOneControl( well ); // bug: work around for bug in ControlManager
// DisableControl( well );
// set name
StringPtr blank = (StringPtr) NewPtrClear( sizeof(Str255) );
CopyPascalStringToC( "\p", (char *) blank );
SetControlData( name, kControlLabelPart, kControlStaticTextTextTag, 1, blank );
SetControlTitle( name, "\p" );
// set type
SetControlData( type, kControlLabelPart, kControlStaticTextTextTag, 1, blank );
SetControlTitle( type, "\p" );
// set ID
SetControlData( id, kControlLabelPart, kControlStaticTextTextTag, 1, blank );
SetControlTitle( id, "\p" );
// set control values
SetControlValue( changedBox, kControlCheckBoxUncheckedValue );
SetControlValue( preloadBox, kControlCheckBoxUncheckedValue );
SetControlValue( protectedBox, kControlCheckBoxUncheckedValue );
SetControlValue( lockedBox, kControlCheckBoxUncheckedValue );
SetControlValue( purgeableBox, kControlCheckBoxUncheckedValue );
SetControlValue( sysHeapBox, kControlCheckBoxUncheckedValue );
// DisableControl( group );
}
else
{
// get selected resource
DataBrowserItemID first, last;
GetDataBrowserSelectionAnchor( browser, &first, &last ); // first must == last
ResourceObjectPtr resource = file->GetResource(first);
// set icon
content.contentType = kControlContentIconSuiteRes;
content.u.resID = kDefaultResourceIcon;
SetImageWellContentInfo( well, &content );
DrawOneControl( well ); // bug: work around for bug in ControlManager
// EnableControl( well );
// set name
StringPtr label = (StringPtr) NewPtrClear( sizeof(Str255) );
if( PStringLength( resource->Name()) == 0 ) GetIndString( label, kResourceNameStrings, kStringUntitledResource );
else CopyPascalStringToC( resource->Name(), (char *) label );
SetControlData( name, kControlLabelPart, kControlStaticTextTextTag, PStringLength(resource->Name()), label );
SetControlTitle( name, resource->Name() );
// set type
Str255 string;
TypeToPString( resource->Type(), string );
CopyPascalStringToC( string, (char *) label );
SetControlData( type, kControlLabelPart, kControlStaticTextTextTag, string[0], label );
SetControlTitle( type, string );
// set ID
NumToString( resource->ID(), string );
CopyPascalStringToC( string, (char *) label );
SetControlData( id, kControlLabelPart, kControlStaticTextTextTag, string[0], label );
SetControlTitle( id, string );
// set control values
SetControlValue( changedBox, (resource->Attributes() & resChanged)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue );
SetControlValue( preloadBox, (resource->Attributes() & resPreload)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue );
SetControlValue( protectedBox, (resource->Attributes() & resProtected)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue );
SetControlValue( lockedBox, (resource->Attributes() & resLocked)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue );
SetControlValue( purgeableBox, (resource->Attributes() & resPurgeable)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue );
SetControlValue( sysHeapBox, (resource->Attributes() & resSysHeap)? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue );
DeactivateControl( changedBox );
// EnableControl( group );
}
return error;
#else
return noErr;
#endif
}

View File

@ -1,26 +0,0 @@
#include "ResKnife.h"
#include "WindowObject.h"
/*!
@header InspectorWindow
@discussion Manages the little inspector that accompanies a File Window.
*/
/* INSPECTOR WINDOW CLASS */
class InspectorWindow : WindowObject
{
public:
InspectorWindow( void );
~InspectorWindow( void );
virtual OSStatus Update( RgnHandle region = null ); // unused parameter
};
pascal OSStatus CloseInspectorWindow( EventHandlerCallRef callRef, EventRef event, void *userData );
// inspector window dimentions
const UInt16 kInspectorHeaderHeight = 48 + 4; // 48 for huge icon
const UInt16 kInspectorWindowWidth = 183;
const UInt16 kInspectorWindowHeight = 183;
// non-window dimentions
const UInt16 kControlCheckBoxHeight = 16;

View File

@ -1,73 +0,0 @@
#include "PickerWindow.h"
#include "FileWindow.h"
#include "Errors.h"
#include "Utility.h"
extern globals g;
/*** CREATOR ***/
PickerWindow::PickerWindow( FileWindowPtr ownerFile, ResType resType ) : PlugWindow( ownerFile )
{
OSStatus error = noErr;
#if USE_NIBS
// create a nib reference (only searches the application bundle)
IBNibRef nibRef = null;
error = CreateNibReference( CFSTR("ResKnife"), &nibRef );
if( error != noErr || nibRef == null )
{
DisplayError( "\pThe nib file reference could not be obtained." );
return;
}
// create window
error = CreateWindowFromNib( nibRef, CFSTR("Picker Window"), &window );
if( error != noErr || window == null )
{
DisplayError( "\pA picker window could not be obtained from the nib file." );
return;
}
// dispose of nib ref
DisposeNibReference( nibRef );
#elif TARGET_API_MAC_CARBON
// create window
Rect creationBounds;
SetRect( &creationBounds, 9, 45, 256 +9, 256 +45 );
error = CreateNewWindow( kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute, &creationBounds, &window );
#else
if( g.useAppearance && g.systemVersion >= kMacOS8 )
{
window = GetNewCWindow( kFileWindow8, null, kFirstWindowOfClass );
themeSavvy = true;
}
else
{
window = GetNewCWindow( kFileWindow7, null, kFirstWindowOfClass );
themeSavvy = false;
}
#endif
// set up default window title
Str255 windowTitle, resTypeStr;
FSSpec spec = *ownerFile->GetFileSpec();
CopyPString( spec.name, windowTitle );
TypeToPString( resType, resTypeStr );
AppendPString( windowTitle, "\p: " );
AppendPString( windowTitle, resTypeStr );
AppendPString( windowTitle, "\p resources" );
// save PickerWindow class in window's refcon
SetWindowRefCon( window, (UInt32) this );
SetWindowKind( window, kPickerWindowKind );
SetWindowTitle( window, windowTitle );
// set window's background to default for theme
#if TARGET_API_MAC_CARBON
SetThemeWindowBackground( window, kThemeBrushDocumentWindowBackground, true );
#else
if( g.useAppearance )
SetThemeWindowBackground( window, kThemeBrushDocumentWindowBackground, false );
#endif
}

View File

@ -1,23 +0,0 @@
#include "ResKnife.h"
#include "PlugWindow.h"
#ifndef _ResKnife_PickerWindow_
#define _ResKnife_PickerWindow_
/*!
@header PickerWindow
@discussion A class specifically designed to maintain an external picker window.
*/
/*!
@class PickerWindow
@discussion A class specifically designed to maintain an external picker window.
*/
class PickerWindow : PlugWindow
{
public:
// methods
PickerWindow( FileWindowPtr ownerFile, ResType resType );
};
#endif

View File

@ -1,95 +0,0 @@
#include "PlugObject.h"
#include "Errors.h"
extern globals g;
/*** LOAD EDITOR ***/
OSStatus LoadEditor( ResourceObjectPtr resource, ConstStr63Param libName )
{
// create editor window structure and save resource to be edited into it
OSStatus error = noErr;
PlugObjectPtr plug = (PlugObjectPtr) NewPtrClear( sizeof(PlugObject) ); // bug: this function calls itself, so memory leak may exist here
if( !plug ) return memFullErr; // another bug: should check if plug already has associated PlugObject (ie it is loaded already) - globalRefCon won't work
// load editor's library into memory
CFragConnectionID connID = null;
Ptr mainAddr = null;
Str255 errMessage;
error = GetSharedLibrary( libName, kPowerPCCFragArch, kLoadCFrag, &connID, &mainAddr, errMessage );
DebugError( errMessage );
if( error )
{
if( EqualString( libName, "\pHex Editor", true, true ) )
{
DisposePtr( (Ptr) plug ); // only dispose if was created just now
DisplayError( "\pNo editors are available for this resource!", "\pI suggest you reinstall the program." );
return error;
}
else if( EqualString( libName, "\pTemplate Editor", true, true ) )
{
error = LoadEditor( resource, "\pHex Editor" );
return error;
}
else
{
error = LoadEditor( resource, "\pTemplate Editor" );
if( error )
error = LoadEditor( resource, "\pHex Editor" );
return error;
}
}
plug->SetConnectionID( connID );
// find and call InitInstance symbol
InitPlugProcPtr symAddr;
CFragSymbolClass symClass;
error = FindSymbol( connID, "\pPlug_InitInstance", (Ptr *) &symAddr, &symClass );
if( error )
{
DisposePtr( (Ptr) plug ); // only dispose if was created just now
if( g.debug ) DebugError( "\pPlug_InitInstance() could not be found." );
else DisplayError( "\pCannot load up requested editor.", "\pPlease obtain an update from the plug-in's author." );
return error;
}
error = (* symAddr)( plug, resource );
if( error )
{
DisposePtr( (Ptr) plug ); // only dispose if was created just now
DebugError( "\pPlug_InitInstance() returned an error. This is quite normal for the Template Editor, thus if no XXXX Editor exists, and no template is found, you will see this dialog, then a hex editor appear." );
}
return error;
}
/*** UNLOAD EDITOR ***/
OSStatus UnloadEditor( PlugObjectPtr plug )
{
#pragma unused( plug )
OSStatus error = noErr;
CFragConnectionID connID = plug->GetConnectionID();
// find and call DisposeEditor symbol
/* DisposePlugProcPtr symAddr;
CFragSymbolClass symClass;
error = FindSymbol( connID, "\pPlug_DisposeEditor", (Ptr *) &symAddr, &symClass );
if( error ) return error;
(* symAddr)( plug );
*/
// close connection to editor
error = CloseConnection( &connID );
plug->SetConnectionID( null );
return error;
}
/**************************/
/* CLASS ACCESSOR METHODS */
/**************************/
/*** ACCESSORS ***/
void PlugObject::SetRefCon( UInt32 value ) { refcon = value; }
UInt32 PlugObject::GetRefCon( void ) { return refcon; }
CFragConnectionID PlugObject::GetConnectionID( void ) { return connID; }
void PlugObject::SetConnectionID( CFragConnectionID newID ) { connID = newID; }
WindowObjectPtr PlugObject::GetWindowObject( void ) { return windowObj; }
void PlugObject::SetWindowObject( WindowObjectPtr newWindowObj ) { windowObj = newWindowObj; }
ResourceObjectPtr PlugObject::GetResourceObject( void ) { return resourceObj; }
void PlugObject::SetResourceObject( ResourceObjectPtr newResourceObj ) { resourceObj = newResourceObj; }

View File

@ -1,97 +0,0 @@
#include "ResKnife.h"
#include "WindowObject.h"
#include "ResourceObject.h"
#ifndef _ResKnife_PlugObject_
#define _ResKnife_PlugObject_
/*!
@header PlugObject
@discussion Keeps track of all loaded plug-ins.
*/
/*!
@class PlugObject
@abstract Contains the data required to know which plug-ins can edit what.
@discussion Created when a plug-in is loaded for the first time, and is never destoyed, this class maintains the connection between the host and a plug-in. Also tracks whether the plug is an Editor or a Picker.
*/
typedef class PlugObject
{
/*! @var connID A CFM connection ID to a plug-in. */
CFragConnectionID connID;
/*! @var windowObj The first window loaded for this plug-in. Either a PickerWindow or an EditorWindow. */
WindowObjectPtr windowObj;
/*! @var resourceObj What the first loaded window edits (if anything). */
ResourceObjectPtr resourceObj;
// EditorType editorType;
/*! @var ResType The type of resource this plug can handle. */
ResType whatIActuallyEdit;
// for the plug's use
/*! @var refcon A plug-global refcon for storing (say) it's preferences structure. */
UInt32 refcon;
public:
/*!
@function GetConnectionID
@discussion Accessor function.
*/
CFragConnectionID GetConnectionID( void );
/*!
@function SetConnectionID
@discussion Accessor function.
*/
void SetConnectionID( CFragConnectionID newID );
/*!
@function GetWindowObject
@discussion Accessor function.
*/
WindowObjectPtr GetWindowObject( void );
/*!
@function SetWindowObject
@discussion Accessor function.
*/
void SetWindowObject( WindowObjectPtr newWindowObj );
/*!
@function GetResourceObject
@discussion Accessor function.
*/
ResourceObjectPtr GetResourceObject( void );
/*!
@function SetResourceObject
@discussion Accessor function.
*/
void SetResourceObject( ResourceObjectPtr newResourceObj );
/*!
@function SetRefCon
@discussion Accessor function.
*/
void SetRefCon( UInt32 value );
/*!
@function GetRefCon
@discussion Accessor function.
*/
UInt32 GetRefCon( void );
} PlugObject, *PlugObjectPtr;
/*!
@function LoadEditor
@discussion Loads a CFrag by name, and passes it a resource to edit.
@param resource The resource to be edited.
@param libName A string containing the fragment name of the editor to be used, for example "icns Editor" or "PICT Picker".
*/
OSStatus LoadEditor( ResourceObjectPtr resource, ConstStr63Param libName );
/*!
@function UnloadEditor
@discussion Unloads the given plug.
@param plug The plug-in to be killed.
*/
OSStatus UnloadEditor( PlugObjectPtr plug );
/*!
@typedef InitPlugProcPtr
@discussion The pointer to Plug_InitInstance() that FindSymbol returns.
*/
typedef OSStatus (* InitPlugProcPtr)( PlugObjectPtr plug, ResourceObjectPtr resource );
#endif

View File

@ -1,91 +0,0 @@
#include "PlugWindow.h"
#include "Utility.h"
#include "string.h"
extern globals g;
/*********************/
/* PLUG WINDOW CLASS */
/*********************/
/*** CREATOR ***/
PlugWindow::PlugWindow( FileWindowPtr ownerFile )
{
memset( this, 0, sizeof(PlugWindow) );
file = ownerFile;
}
/*** GET FILE WINDOW ***/
FileWindowPtr PlugWindow::File( void )
{
return file;
}
#if !TARGET_API_MAC_CARBON
/*** INSTALL CLASSIC EVENT HANDLER ***/
void PlugWindow::InstallClassicEventHandler( ClassicEventHandlerProcPtr newHandler )
{
handler = newHandler;
}
/*** UPDATE WINDOW ***/
OSStatus PlugWindow::Update( RgnHandle region )
{
EventRecord event;
event.what = updateEvt;
event.message = (UInt32) window;
event.when = (UInt32) region; // note overload here
event.where = NewPoint();
event.modifiers = null;
OSStatus error = (* handler)( &event, kEventWindowUpdate, null );
return error;
}
/*** ACTIVATE WINDOW ***/
OSStatus PlugWindow::Activate( Boolean active )
{
EventRecord event;
event.what = activateEvt;
event.message = (UInt32) window;
event.when = TickCount();
event.where = NewPoint();
event.modifiers = null;
OSStatus error = (* handler)( &event, active? kEventWindowActivated:kEventWindowDeactivated, null );
return error;
}
/*** CLOSE WINDOW ***/
OSStatus PlugWindow::Close( void )
{
EventRecord event;
event.what = mouseUp;
event.message = (UInt32) window;
event.when = TickCount();
event.where = NewPoint();
event.modifiers = null;
OSStatus error = (* handler)( &event, kEventWindowClose, null );
return error;
}
/*** HANDLE CLICK IN WINDOW ***/
OSStatus PlugWindow::Click( Point mouse, EventModifiers modifiers )
{
EventRecord event;
event.what = mouseDown;
event.message = (UInt32) window;
event.when = TickCount();
event.where = mouse;
event.modifiers = modifiers;
OSStatus error = (* handler)( &event, kEventWindowClickContentRgn, null );
return error;
}
#endif
/*** ACCESSORS ***/
void PlugWindow::SetRefCon( UInt32 value ) { refcon = value; }
UInt32 PlugWindow::GetRefCon( void ) { return refcon; }

View File

@ -1,78 +0,0 @@
#include "ResKnife.h"
#include "WindowObject.h"
#ifndef _ResKnife_PlugWindow_
#define _ResKnife_PlugWindow_
/*!
* @header PlugWindow
* @discussion Declares the (very simple) PlugWindow subclass.
*/
#if !TARGET_API_MAC_CARBON
// classic event handler
typedef CALLBACK_API(OSStatus, ClassicEventHandlerProcPtr) (EventRecord *event, UInt32 eventKind, void *userData);
typedef STACK_UPP_TYPE(ClassicEventHandlerProcPtr) ClassicEventHandlerUPP;
enum { uppClassicEventHandlerProcInfo = 0x00000FF0 }; /* pascal 4_bytes Func(4_bytes, 4_bytes, 4_bytes) */
#ifdef __cplusplus
inline ClassicEventHandlerUPP NewClassicEventHandlerUPP(ClassicEventHandlerProcPtr userRoutine) { return (ClassicEventHandlerUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppClassicEventHandlerProcInfo, GetCurrentArchitecture()); }
#else
#define NewClassicEventHandlerUPP(userRoutine) (ClassicEventHandlerUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppClassicEventHandlerProcInfo, GetCurrentArchitecture())
#endif
#endif
/*!
* @class PlugWindow
* @abstract Base class for EditorWindow and PickerWindow.
* @discussion Declares the classic event handler &amp; a refcon, and overrides a few classic events.
*/
class PlugWindow : public WindowObject
{
protected:
/*! @var file The owning file of the window. */
FileWindowPtr file;
#if !TARGET_API_MAC_CARBON
/*! @var handler The classic event handler used for plug windows. */
ClassicEventHandlerProcPtr handler;
#endif
/*! @var refcon A refcon for the plug to use. */
UInt32 refcon;
public:
/*!
* @function PlugWindow
*/
PlugWindow( FileWindowPtr ownerFile );
/*!
* @function File
*/
FileWindowPtr File( void );
#if !TARGET_API_MAC_CARBON
/*!
* @function InstallClassicEventHandler
*/
void InstallClassicEventHandler( ClassicEventHandlerProcPtr newHandler );
/*!
* @function Close
*/
virtual OSStatus Close( void );
/*!
* @function Activate
*/
virtual OSStatus Activate( Boolean active = true );
/*!
* @function Update
*/
virtual OSStatus Update( RgnHandle region = null );
/*!
* @function Click
*/
virtual OSStatus Click( Point mouse, EventModifiers modifiers );
#endif
void SetRefCon( UInt32 value );
UInt32 GetRefCon( void );
};
#endif

View File

@ -1,100 +0,0 @@
#include "ResourceObject.h"
#include "Errors.h"
#include "string.h"
/*** CREATOR ***/
ResourceObject::ResourceObject( FileWindowPtr owner )
{
// set contents to zero
memset( this, 0, sizeof(ResourceObject) );
file = owner;
nameIconRgn = NewRgn();
}
/*** DESTRUCTOR ***/
ResourceObject::~ResourceObject( void )
{
if( nameIconRgn ) DisposeRgn( nameIconRgn );
if( data ) DisposeHandle( data );
}
/*** RETAIN ***/
OSStatus ResourceObject::Retain( void )
{
OSStatus error = noErr;
/* if( retainCount == 0 )
{
if( dataFork )
{
// open file for reading
SInt16 refNum;
error = FSpOpenDF( file->GetFileSpec(), fsRdPerm, &refNum );
if( error )
{
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." );
return error;
}
// get new handle
data = NewHandleClear( size );
if( !data || MemError() )
{
DisplayError( "\pNot enough memory to read data fork", "\pPlease quit other applications and try again." );
FSClose( refNum );
return memFullErr;
}
// read data fork
HLock( data );
error = FSRead( refNum, (long *) &size, *data );
HUnlock( data );
FSClose( refNum );
}
else
{
LoadResource( data );
}
}
*/ retainCount++;
return error;
}
/*** RELEASE ***/
void ResourceObject::Release( void )
{
if( retainCount > 0 )
{
/* if( retainCount == 1 )
DisposeHandle( data );
*/ retainCount--;
}
}
/*** SET RESOURCE DIRTY ***/
void ResourceObject::SetDirty( Boolean value )
{
dirty = value;
file->SetFileDirty( value );
// being here indicates the resource size parameter also needs updating
size = GetHandleSize( data );
// bug: should now tell all open copies of this resource to update themselves
}
/*** RES INFO RECORD ACCESSORS ***/
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; }
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; }

View File

@ -1,159 +0,0 @@
#include "ResKnife.h"
#include "FileWindow.h" // for friends
#ifndef _ResKnife_ResourceObject_
#define _ResKnife_ResourceObject_
/*!
@header ResourceObject
@discussion Contains all required information for a resource, including it's parent file and whether or not it has been edited since it was last saved (if ever).
*/
/*!
@class ResourceObject
@abstract Opaque
@discussion Mainly consisting of regular controls such as scroll bars and headers, this doesn't do much by it's self.
*/
class ResourceObject
{
/*! @var file The parent file into which this resource is to be saved. */
FileWindowPtr file;
/*! @var next the next resource. */
ResourceObjectPtr next;
// status of resource
// Boolean neverSaved; // resource has never been saved -- cleared on SaveFile()
/*! @var dirty Resource has been modified since the file was last saved if this flag is true. Cleared when SaveFile() is called. */
UInt16 retainCount; // counts the number of times this resource has been loaded minus the number it's been released
Boolean dirty;
// Boolean update; // resource is not synched with temporary file -- cleared on UpdateFile()
Boolean dataFork; // resource represents data fork, only true in files whose resource map is in the resource fork
/*! @var number Item number in the data browser. Deleted resources vacate their number, and it is not replaced if a new resource is created. New resources are appended to the end of the chain, and will always have the highest numbers. */
DataBrowserItemID number;
// classic display parameters
/*! @var nameIconRgn */
RgnHandle nameIconRgn;
/*! @var selected */
Boolean selected;
// resource
/*! @var type */
ResType type;
/*! @var size */
SInt32 size;
/*! @var resID */
SInt16 resID;
/*! @var attribs */
SInt16 attribs;
/*! @var data The actual resource byte stream. */
Handle data;
/*! @var name */
Str255 name;
/* methods */
public:
/*!
@function ResourceObject
@discussion Creator function.
*/
ResourceObject( FileWindowPtr owner = null );
/*!
@function ~ResourceObject
@discussion Destructor function.
*/
~ResourceObject( void );
/*!
@function Retain
@discussion Accessor function.
*/
OSStatus Retain( void );
/*!
@function Release
@discussion Accessor function.
*/
void Release( void );
/*!
@function File
@discussion Accessor function.
*/
FileWindowPtr File( void );
/*!
@function Next
@discussion Accessor function.
*/
ResourceObjectPtr Next( void );
/*!
@function SetDirty
@discussion Accessor function.
*/
void SetDirty( Boolean value );
/*!
@function Dirty
@discussion Accessor function.
*/
Boolean Dirty( void );
/*!
@function Select
@discussion Accessor function.
@param select Pass true to select, false to deselect this resource in the file window.
*/
void Select( Boolean select );
/*!
@function Selected
@discussion Accessor function.
*/
Boolean Selected( void );
/*!
@function Number
@discussion Accessor function.
*/
DataBrowserItemID Number( void );
/*!
@function RepresentsDataFork
@discussion Accessor function.
*/
Boolean RepresentsDataFork( void );
/*!
@function Data
@discussion Accessor function. Warning: This functions returns the ACTUAL data handle - do not dispose of it.
*/
Handle Data( void );
/*!
@function Name
@discussion Accessor function.
*/
UInt8* Name( void );
/*!
@function Size
@discussion Accessor function.
*/
UInt32 Size( void );
/*!
@function Type
@discussion Accessor function.
*/
ResType Type( void );
/*!
@function ID
@discussion Accessor function.
*/
SInt16 ID( void );
/*!
@function Attributes
@discussion Accessor function.
*/
SInt16 Attributes( void );
friend OSStatus FileWindow::ReadResourceMap( void );
friend OSStatus FileWindow::ReadDataFork( OSStatus RFError );
friend OSStatus FileWindow::InitDataBrowser( void );
#if !TARGET_API_MAC_CARBON
friend OSStatus FileWindow::Click( Point mouse, EventModifiers modifiers );
friend OSStatus FileWindow::DrawResourceIcon( ResourceObjectPtr resource, UInt16 line );
#endif
friend OSStatus FileWindow::CreateNewResource( ConstStr255Param name, ResType type, SInt16 resID, SInt16 attribs );
friend OSStatus FileWindow::DisposeResourceMap( void );
};
#endif

View File

@ -1,220 +0,0 @@
#include "Utility.h"
extern globals g;
/**********************/
/* QUICKDRAW ROUTINES */
/**********************/
/*** SET COLOUR ***/
void SetColour( RGBColor *colour, UInt16 red, UInt16 green, UInt16 blue )
{
colour->red = red;
colour->green = green;
colour->blue = blue;
}
/* investigate the call ShieldCursor() - it hides the mouse when it enters a certain rect */
/*******************/
/* STRING ROUTINES */
/*******************/
/*** C STRING LENGTH ***/
unsigned long CStringLength( char *string )
{
unsigned long length;
Boolean end = false;
for( length = 0; end == false; length++ )
if( *(string + length) == 0x00 ) end = true;
return length;
}
/*** PASCAL STRING LENGTH ***/
unsigned char PStringLength( unsigned char *string )
{
return *string;
}
/*** TYPE TO C STRING ***/
void TypeToCString( const OSType type, char *string )
{
BlockMoveData( &type, &string[0], sizeof(OSType) );
string[sizeof(OSType)] = 0x00;
}
/*** TYPE TO PASCAL STRING ***/
void TypeToPString( const OSType type, Str255 string )
{
string[0] = sizeof(OSType);
BlockMoveData( &type, &string[1], sizeof(OSType) );
}
/*** TYPE TO CORE FOUNDATION STRING ***/
void TypeToCFString( const OSType type, CFStringRef *string )
{
char cString[5];
TypeToCString( type, (char *) &cString );
*string = CFStringCreateWithCString( CFAllocatorGetDefault(), (char *) &cString, kCFStringEncodingMacRoman );
}
/*** COPY C STRING ***/
void CopyCString( const UInt8 *source, UInt8 *dest )
{
//#pragma warning off
while( *dest++ = *source++ );
//#pragma warning reset
}
/*** COPY PASCAL STRING ***/
void CopyPString( const UInt8 *source, UInt8 *dest )
{
UInt8 length = *source, count;
for( count = 0; count <= length; count++ )
*dest++ = *source++;
}
/*** EQUAL C STRINGS ***/
Boolean EqualCStrings( UInt8 *source, UInt8 *dest )
{
while( *source != 0x00 )
if( *source++ != *dest++ ) return false;
return true;
}
/*** EQUAL PASCAL STRINGS ***/
Boolean EqualPStrings( UInt8 *source, UInt8 *dest )
{
UInt8 length = *source, count;
for( count = 0; count <= length; count++ )
if( *source++ != *dest++ ) return false;
return true;
}
/*** APPEND ONE PASCAL STRING ONTO ANOTHER ***/
void AppendPString( Str255 original, ConstStr255Param added )
{
short numberBytes = added[0]; // length of string to be added
short totalLength = added[0] + original[0];
if( totalLength > 255 ) // too long, adjust number of bytes to add
{
totalLength = 255;
numberBytes = totalLength - original[0];
}
BlockMoveData( &added[1], &original[totalLength-numberBytes + 1], numberBytes );
original[0] = totalLength; // new length of original string
while( ++totalLength <= 255 )
original[totalLength] = 0x00; // set rest of string to zero
}
/*****************/
/* MENU ROUTINES */
/*****************/
/*** MENU ITEM ENABLE ***/
void MenuItemEnable( MenuRef menu, MenuItemIndex item, Boolean enable )
{
#if !TARGET_API_MAC_CARBON
if( g.systemVersion >= kMacOS85 )
{
#endif
if( enable ) EnableMenuItem( menu, item );
else DisableMenuItem( menu, item );
#if !TARGET_API_MAC_CARBON
}
else
{
if( enable ) EnableItem( menu, item );
else DisableItem( menu, item );
}
#endif
}
/*** ENABLE MENU COMMAND ***/
void EnableCommand( MenuRef menu, MenuCommand command, Boolean enable )
{
if( enable ) EnableMenuCommand( menu, command );
else DisableMenuCommand( menu, command );
}
/******************/
/* FILE UTILITIES */
/******************/
/* MakeRelativeAliasFile creates a new alias file located at
aliasDest referring to the targetFile. relative path
information is stored in the new file. */
/* MAKE RELATIVE ALIAS FILE */
OSErr MakeRelativeAliasFile(FSSpec *targetFile, FSSpec *aliasDest)
{
OSErr error;
FInfo fndrInfo;
AliasHandle theAlias = null;
Boolean fileCreated = false;
SInt16 rsrc = -1;
// set up our the alias' file information
error = FSpGetFInfo( targetFile, &fndrInfo );
if( error != noErr ) goto bail;
if( fndrInfo.fdType == 'APPL')
fndrInfo.fdType = kApplicationAliasType;
fndrInfo.fdFlags = kIsAlias; // implicitly clear the inited bit
// create the new file
FSpCreateResFile( aliasDest, 'TEMP', 'TEMP', smSystemScript );
if( (error = ResError() ) != noErr) goto bail;
fileCreated = true;
// set the file information or the new file
error = FSpSetFInfo( aliasDest, &fndrInfo );
if( error != noErr ) goto bail;
// create the alias record, relative to the new alias file
error = NewAlias( aliasDest, targetFile, &theAlias );
if( error != noErr ) goto bail;
// save the resource
rsrc = FSpOpenResFile( aliasDest, fsRdWrPerm );
if( rsrc == -1)
{
error = ResError();
goto bail;
}
UseResFile( rsrc );
AddResource( (Handle) theAlias, rAliasType, 0, aliasDest->name );
error = ResError();
if( error != noErr) goto bail;
theAlias = null;
CloseResFile( rsrc );
rsrc = -1;
error = ResError();
if( error != noErr) goto bail;
// done
return noErr;
bail:
if( rsrc != -1 ) CloseResFile( rsrc );
if( fileCreated ) FSpDelete( aliasDest );
if( theAlias != null ) DisposeHandle( (Handle) theAlias );
return error;
}
/**********************/
/* INTERNET UTILITIES */
/**********************/
/*** LAUNCH WEB BROWSER ***/
OSStatus LaunchURL( char *url )
{
OSStatus error = noErr;
ICInstance instance;
error = ICStart( &instance, kResKnifeCreator );
if( error != noErr ) return error;
SInt32 start = 0, length = CStringLength( url );
error = ICLaunchURL( instance, null, url, length, &start, &length );
ICStop( instance );
return error;
}

View File

@ -1,73 +0,0 @@
#include "ResKnife.h"
#ifndef _ResKnife_Utility_
#define _ResKnife_Utility_
/*!
@header Utility Routines
@discussion Supplies the application with generic oft-used functions such as string conversion and menu enabling.
*/
/*!
@function SetColour
*/
void SetColour( RGBColor *colour, UInt16 red, UInt16 green, UInt16 blue );
/*!
@function CStringLength
*/
unsigned long CStringLength( char *string );
/*!
@function PStringLength
*/
unsigned char PStringLength( unsigned char *string );
/*!
@function TypeToCString
*/
void TypeToCString( const OSType type, char *string );
/*!
@function TypeToPString
*/
void TypeToPString( const OSType type, Str255 string );
/*!
@function TypeToCFString
*/
void TypeToCFString( const OSType type, CFStringRef *string );
/*!
@function CopyCString
*/
void CopyCString( const UInt8 *source, UInt8 *dest );
/*!
@function CopyPString
*/
void CopyPString( const UInt8 *source, UInt8 *dest );
/*!
@function EqualCStrings
*/
Boolean EqualCStrings( UInt8 *source, UInt8 *dest );
/*!
@function EqualPStrings
*/
Boolean EqualPStrings( UInt8 *source, UInt8 *dest );
/*!
@function AppendPString
*/
void AppendPString( Str255 original, ConstStr255Param added );
/*!
@function MenuItemEnable
*/
void MenuItemEnable( MenuRef menu, MenuItemIndex item, Boolean enable );
/*!
@function EnableCommand
*/
void EnableCommand( MenuRef menu, MenuCommand command, Boolean enable );
/*!
@function MakeRelativeAliasFile
*/
OSErr MakeRelativeAliasFile(FSSpec *targetFile, FSSpec *aliasDest);
/*!
@function LaunchURL
@param url A C string containing the address to which you want the user to go. You must include 'http://' if necessary, and all addresses to a directory should have a trailing slash.
*/
OSStatus LaunchURL( char *url );
#endif

View File

@ -1,77 +0,0 @@
#include "WindowObject.h"
#include "string.h"
/*** CONSTRUCTOR ***/
WindowObject::WindowObject( void )
{
memset( this, 0, sizeof(WindowObject) );
}
/*** DESTRUCTOR ***/
WindowObject::~WindowObject( void )
{
if( window )
{
HideWindow( window );
DisposeWindow( window );
}
}
/*** WINDOW ACCESSOR ***/
WindowRef WindowObject::Window( void )
{
return window;
}
/*** WINDOW BOUNDS ARE CHANGING ***/
OSStatus WindowObject::BoundsChanging( EventRef event )
{
#pragma unused( event )
return eventNotHandledErr;
}
/*** WINDOW BOUNDS HAVE CHANGED ***/
OSStatus WindowObject::BoundsChanged( EventRef event )
{
#pragma unused( event )
return eventNotHandledErr;
}
#if !TARGET_API_MAC_CARBON
/*** CLOSE ***/
OSStatus WindowObject::Close( void )
{
delete this;
return noErr;
}
/*** ACTIVATE ***/
OSStatus WindowObject::Activate( Boolean active )
{
#pragma unused( active )
return eventNotHandledErr;
}
/*** UPDATE ***/
OSStatus WindowObject::Update( RgnHandle region )
{
#pragma unused( region )
return eventNotHandledErr;
}
/*** UPDATE SCROLL BARS ***/
OSStatus WindowObject::UpdateScrollBars( void )
{
return eventNotHandledErr;
}
/*** MOUSE CLICK ***/
OSStatus WindowObject::Click( Point mouse, EventModifiers modifiers )
{
#pragma unused( mouse, modifiers )
return eventNotHandledErr;
}
#endif

View File

@ -1,86 +0,0 @@
#include "ResKnife.h"
#ifndef _ResKnife_WindowObject_
#define _ResKnife_WindowObject_
/*!
* @header WindowObject
* @discussion The base class for all windows in the program. Also declares the (very simple) PlugWindow subclass.
*/
/*!
* @class WindowObject
* @abstract Base class for all windows in the program.
* @discussion Mainly consisting of regular controls such as scroll bars and headers, this doesn't do much by it's self.
*/
class WindowObject
{
// data
protected:
/*! @var window Stores the Mac OS <tt>WindowRef</tt> pertaining to this window. */
WindowRef window;
/*! @var header Header control (the grey bar at the top of most windows). */
ControlRef header;
/*! @var leftText Left hand side static text control (in the header). */
ControlRef left;
/*! @var rightText Right hand side static text control (in the header). */
ControlRef right;
#if !TARGET_API_MAC_CARBON
/*! @var horizScroll Horizontal scrollbar at the bottom of most windows */
ControlRef horizScroll;
/*! @var vertScroll Vetical scrollbar down the right side of most windows */
ControlRef vertScroll;
/*! @var themeSavvy True if this window is using an Appearance Manager WDEF. (Also used to determine if Appearance controls should be drawn if this window.) */
Boolean themeSavvy;
#endif
public:
// methods
/*!
* @function WindowObject
* @discussion Constructor function.
*/
WindowObject( void );
/*!
* @function WindowObject
* @discussion Desturctor function.
*/
virtual ~WindowObject( void );
/*!
* @function Window
* @discussion Accessor for the object&rsquo;s <tt>WindowRef</tt>.
*/
virtual WindowRef Window( void );
/*!
* @function BoundsChanging
*/
virtual OSStatus BoundsChanging( EventRef event );
/*!
* @function BoundsChanged
*/
virtual OSStatus BoundsChanged( EventRef event );
#if !TARGET_API_MAC_CARBON
/*!
* @function Close
*/
virtual OSStatus Close( void );
/*!
* @function Activate
*/
virtual OSStatus Activate( Boolean active = true );
/*!
* @function Update
*/
virtual OSStatus Update( RgnHandle region = null );
/*!
* @function UpdateScrollBars
*/
virtual OSStatus UpdateScrollBars( void );
/*!
* @function Click
*/
virtual OSStatus Click( Point mouse, EventModifiers modifiers );
#endif
};
#endif

View File

@ -1,27 +0,0 @@
// abbreviations
#define null NULL
#if TARGET_API_MAC_CARBON
#define qdb ScreenBounds()
inline Rect ScreenBounds()
{
Rect rect;
GetAvailableWindowPositioningBounds( GetMainDevice(), &rect );
return rect;
}
#else
#define qdb qd.screenBits.bounds
#endif
// Easier API call names
#define GetWindowRefCon( window ) (long) GetWRefCon( window )
#define SetWindowRefCon( window, refcon ) SetWRefCon( window, refcon )
#define GetWindowTitle( window, string ) GetWTitle( window, string )
#define SetWindowTitle( window, name ) SetWTitle( window, name )
#define InvalidateRect( bounds ) InvalRect( bounds )
#define InvalidateWindowRect( window, bounds ) (OSStatus) InvalWindowRect( window, bounds )
#define RectToRegion( region, rect ) RectRgn( region, rect )
#define NewPoint() (Point) { 0, 0 }
#define SetPoint( point, x, y ) SetPt( point, x, y )
#define HighlightColour( colour ) HiliteColor( colour )
#define GetPortHighlightColour( window, colour ) GetPortHiliteColor( window, colour )

View File

@ -1,315 +0,0 @@
/*
With thanks to: For:
Jim Luther MoreFiles
Bryan K. Ressler & Bradley D. Mohr Asynchronous SoundHelper
John Montbriand & Pete Gontier FinderDragPro
*/
// interesting function I found: CFBundleOpenBundleResourceMap()
#if defined(__MWERKS__) // compiling with CodeWarrior
#if __profile__
#include <Profiler.h>
#endif
#else // compiling with ProjectBuilder, use frameworks
#define NO_DATA_BROWSER_TWEAKS 0
#define USE_OLD_DATA_BROWSER_STRUCTS 0
#include <Carbon/Carbon.h>
#endif
#ifndef _ResKnife_
#define _ResKnife_
/*!
* @header ResKnife Global Header
* Imported by all ResKnife's C++ source files, this defines various structures and constants which have an application-wide domain.
*/
// compile options
#if TARGET_API_MAC_CARBON
#define USE_NIBS 1 // toggle this
#else
#define USE_NIBS 0 // leave this set to zero
#endif
// include my generic API abbreviations
#include "Generic.h"
/*** STRUCTURES ***/
// type definitions
typedef class ResourceObject ResourceObject, *ResourceObjectPtr;
typedef class PlugObject PlugObject, *PlugObjectPtr;
typedef class WindowObject WindowObject, *WindowObjectPtr;
typedef class FileWindow FileWindow, *FileWindowPtr;
typedef class PlugWindow PlugWindow, *PlugWindowPtr;
typedef class PickerWindow PickerWindow, *PickerWindowPtr;
typedef class EditorWindow EditorWindow, *EditorWindowPtr;
typedef class InspectorWindow InspectorWindow, *InspectorWindowPtr;
/* Global Variables */
struct globals
{
// application
Str255 appName;
Str255 prefsName;
Boolean quitting;
Boolean cancelQuit;
Boolean frontApp;
Boolean asyncSound; // async sound initalised
Boolean callSH; // call sound idle
short appResFile;
Handle emergencyMemory;
EventLoopTimerRef idleTimer; // for SHIdle()
// system info
SInt32 systemVersion;
SInt32 carbonVersion;
Boolean dragAvailable;
Boolean translucentDrag;
Boolean navAvailable;
Boolean appearanceAvailable;
Boolean windowMgrAvailable;
Boolean extendedWindowAttr;
// files
UInt16 tempCount; // number of temporary files opened, so names don't clash
// dialogs
DialogPtr prefsDialog;
Boolean protectPrefs; // if newer version of prefs file exists, will not overwrite
InspectorWindowPtr inspector;
// colours
RGBColor white; // 0xFFFF, 65535
RGBColor bgColour; // 0xEEEE, 61166
RGBColor sortColour; // 0xDDDD, 56797
RGBColor bevelColour; // 0xAAAA, 43690
RGBColor textColour; // 0x7777, 30583
RGBColor frameColour; // 0x5555, 21845
RGBColor black; // 0x0000, 0
// debugging
Boolean debug;
Boolean surpressErrors;
Boolean useAppleEvents;
Boolean useAppearance;
Boolean useNavServices;
Boolean useSheets; // OS X only
};
/*!
* @struct prefs
* @abstract Appplication-wide user preferences
* @discussion Stores all user preferences in memory to avoid needless disk access. This structure is simply written straight to disk when the preferences are saved.
* @field version Identifies which version of ResKnife saved the prefs file (allowing future versions to parse the data contained).
*/
struct prefs
{
UInt32 version; // == kResKnifeCurrentVersion, when saved to disk allows older prefs to be read in
Boolean quitIfNoWindowsAreOpen; // silly name! - perhaps grandmaMode ?
Boolean autoSave;
UInt32 autoSaveInterval; // should be in units of time
Boolean warnOnDelete; // "Are you sure?" dialog, © Microsoft 1986-2003
};
/*** CONSTANTS ***/
// Mac OS versions
const SInt32 kMacOS607 = 0x00000607;
const SInt32 kMacOS7 = 0x00000710;
const SInt32 kMacOS71 = 0x00000710;
const SInt32 kMacOS755 = 0x00000755;
const SInt32 kMacOS8 = 0x00000800;
const SInt32 kMacOS85 = 0x00000850;
const SInt32 kMacOS86 = 0x00000860;
const SInt32 kMacOS9 = 0x00000900;
const SInt32 kMacOS904 = 0x00000904;
const SInt32 kMacOS91 = 0x00000910;
const SInt32 kMacOS921 = 0x00000921;
const SInt32 kMacOS10 = 0x00001000;
const SInt32 kMacOS101 = 0x00001010;
const SInt32 kMacOS102 = 0x00001020;
const SInt32 kMacOSX = kMacOS10;
// CarbonLib versions
const SInt32 kCarbonLib104 = 0x00000104;
const SInt32 kCarbonLib11 = 0x00000110;
const SInt32 kCarbonLib12 = 0x00000120;
const SInt32 kCarbonLib125 = 0x00000125;
const SInt32 kCarbonLib131 = 0x00000131;
const SInt32 kCarbonLib14 = 0x00000140;
const SInt32 kCarbonLib145 = 0x00000145;
const SInt32 kCarbonLib15 = 0x00000150;
const SInt32 kCarbonLib16 = 0x00000160;
// ResKnife version & file types
const UInt32 kCurrentVersion = 0x00040001;
const UInt32 kResKnifeCreator = FOUR_CHAR_CODE('ResK');
const UInt32 kResourceFileType = FOUR_CHAR_CODE('rsrc');
const UInt32 kResourceTransferType = FOUR_CHAR_CODE('rsrc'); // for copy/paste and drags
// memory
const UInt16 kMinimumFreeMemory = 20 * 1024; // if we have over 20 KB we're alright
const UInt16 kEmergencyMemory = 40 * 1024; // 40 KB are put aside for emergencies
// window kinds
enum WindowKind
{
kFileWindowKind = 1,
kPickerWindowKind,
kEditorWindowKind,
kInspectorWindowKind
};
// control sizes
const UInt16 kScrollBarWidth = 16;
/* RESOURCES */
/*!
* @enum Menu Resources
* @discussion Contains all resource IDs for menu items and all ascociated item numbers.
*/
enum // menus
{
kClassicMenuBar = 128,
kAppleMenu = 128,
kAppleMenuAboutItem = 1,
kFileMenu = 129,
kFileMenuNewFileItem = 1,
kFileMenuOpenFileItem,
kFileMenuCloseWindowItem,
kFileMenuQuitItem = 12,
kEditMenu = 130,
kEditMenuClearItem = 7,
kEditMenuPreferencesItem = 13,
kResourceMenu = 131,
kResourceMenuNewResource = 1,
kWindowMenu = 132,
kDebugMenu = 200,
kDebugMenuDebugItem = 1,
kDebugMenuSurpressErrorsItem = 3,
kDebugMenuAppleEventsItem,
kDebugMenuAppearanceItem,
kDebugMenuNavServicesItem,
kDebugMenuSheetsItem
};
enum // application menu
{
kMenuCommandAbout = FOUR_CHAR_CODE('abou')
};
enum // file menu
{
kMenuCommandNewFile = FOUR_CHAR_CODE('new '),
kMenuCommandOpenFile = FOUR_CHAR_CODE('open'),
kMenuCommandCloseWindow = FOUR_CHAR_CODE('clos'),
kMenuCommandCloseFile = FOUR_CHAR_CODE('clsf'),
kMenuCommandSaveFile = FOUR_CHAR_CODE('save'),
kMenuCommandSaveFileAs = FOUR_CHAR_CODE('svas'),
kMenuCommandRevertFile = FOUR_CHAR_CODE('rvtf'),
kMenuCommandPageSetup = FOUR_CHAR_CODE('setu'),
kMenuCommandPrint = FOUR_CHAR_CODE('prin')
};
enum // edit menu
{
kMenuCommandFind = FOUR_CHAR_CODE('find'),
kMenuCommandFindAgain = FOUR_CHAR_CODE('agin')
};
enum // resource menu
{
kMenuCommandNewResource = FOUR_CHAR_CODE('newr'),
kMenuCommandOpenHex = FOUR_CHAR_CODE('hex '),
kMenuCommandOpenDefault = FOUR_CHAR_CODE('edit'),
kMenuCommandOpenTemplate = FOUR_CHAR_CODE('tmpl'),
kMenuCommandOpenSpecific = FOUR_CHAR_CODE('tmp '),
kMenuCommandRevertResource = FOUR_CHAR_CODE('rvtr'),
kMenuCommandPlaySound = FOUR_CHAR_CODE('play')
};
enum // debug menu
{
kMenuCommandDebug = FOUR_CHAR_CODE('dbug'),
kMenuCommandSurpressErrors = FOUR_CHAR_CODE('surp'),
kMenuCommandAppleEvents = FOUR_CHAR_CODE('appl'),
kMenuCommandAppearance = FOUR_CHAR_CODE('appr'),
kMenuCommandNavServices = FOUR_CHAR_CODE('nav '),
kMenuCommandSheets = FOUR_CHAR_CODE('shet')
};
enum // windows
{
kFileWindow7 = 128,
kFileWindow8 = 129
};
enum // dialogs
{
kErrorDialog = 128,
kNewResourceDialog = 129
};
enum // controls
{
kSystem7ScrollBarControl = 128,
kAppearanceScrollBarControl = 129,
kNormalHeaderControl = 130,
kFileHeaderControl = 131,
kEditTextControl = 132
};
enum // icons
{
kSortUpIcon = 921,
kSortDownIcon = 922,
kDefaultResourceIcon = 1000
};
enum // strings
{
kErrorStrings = 128,
kStringUnknownError = 1,
kExplanationUnknownError,
kStringOSNotGoodEnough,
kExplanationOSNotGoodEnough,
kStringMinimumCarbonLib,
kExplanationMinimumCarbonLib,
kStringRecommendedCarbonLib,
kExplanationRecommendedCarbonLib,
kDebugStrings = 129,
kStringRFNotFound = 1,
kExplanationRFNotFound,
kStringDFNotFound,
kExplanationDFNotFound,
kFileNameStrings = 130,
kStringResKnifeName = 1,
kStringPrefsFileName,
kStringNewDragFileName,
kWindowNameStrings = 131,
kStringNewFile = 1,
kStringPrefsWindowName,
kStringInspectorWindowName,
kStringNewResourceDialogName,
kResourceNameStrings = 132,
kStringDataFork = 1,
kStringUntitledResource,
kStringCustomIcon
};
#endif

Binary file not shown.

View File

@ -1,89 +0,0 @@
#if defined(__MWERKS__) // compiling with codewarrior
#include <Carbon.r>
#else // compiling with gcc (__APPLE_CC__)
#include <Carbon/Carbon.r>
#endif
/*
#if defined(__APPLE_CC__) // compiling with gcc
#include <Carbon/Carbon.r>
#else // compiling with CodeWarrior, __MWERKS__
#include <Carbon.r>
#endif
*/
/*** CARBON RESOURCES ***/
data 'carb' ( 0 )
{
$"00000000"
};
data 'plst' ( 0 )
{
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE plist SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\">\n"
"<plist version=\"0.9\">\n"
"<dict>\n"
" <key>CFBundleDevelopmentRegion</key>\n"
" <string>English</string>\n"
" <key>CFBundleDocumentTypes</key>\n"
" <array>\n"
" <dict>\n"
" <key>CFBundleTypeExtensions</key>\n"
" <array>\n"
" <string>rsrc</string>\n"
" </array>\n"
" <key>CFBundleTypeIconFile</key>\n"
" <string>129</string>\n"
" <key>CFBundleTypeName</key>\n"
" <string>Resource file</string>\n"
" <key>CFBundleTypeOSTypes</key>\n"
" <array>\n"
" <string>rsrc</string>\n"
" <string>RSRC</string>\n"
" </array>\n"
" <key>CFBundleTypeRole</key>\n"
" <string>Editor</string>\n"
" </dict>\n"
" <dict>\n"
" <key>CFBundleTypeExtensions</key>\n"
" <array>\n"
" <string>icns</string>\n"
" </array>\n"
" <key>CFBundleTypeIconFile</key>\n"
" <string>129</string>\n"
" <key>CFBundleTypeName</key>\n"
" <string>Icon file</string>\n"
" <key>CFBundleTypeOSTypes</key>\n"
" <array>\n"
" <string>icns</string>\n"
" </array>\n"
" <key>CFBundleTypeRole</key>\n"
" <string>Editor</string>\n"
" </dict>\n"
" </array>\n"
" <key>CFBundleExecutable</key>\n"
" <string>ResKnife (Carbon)</string>\n"
" <key>CFBundleGetInfoString</key>\n"
" <string>A resource editor for Mac OS X</string>\n"
" <key>CFBundleIconFile</key>\n"
" <string>128</string>\n"
" <key>CFBundleIdentifier</key>\n"
" <string>com.nickshanks.resknife</string>\n"
" <key>CFBundleInfoDictionaryVersion</key>\n"
" <string>6.0</string>\n"
" <key>CFBundleName</key>\n"
" <string>ResKnife</string>\n"
" <key>CFBundlePackageType</key>\n"
" <string>APPL</string>\n"
" <key>CFBundleShortVersionString</key>\n"
" <string>Development version 0.4d1</string>\n"
" <key>CFBundleSignature</key>\n"
" <string>ResK</string>\n"
" <key>CFBundleVersion</key>\n"
" <string>0.4d1</string>\n"
" <key>CSResourcesFileMapped</key>\n"
" <true/>\n"
"</dict>\n"
"</plist>"
};

View File

@ -1,4 +0,0 @@
{
IBClasses = ();
IBVersion = 1;
}

View File

@ -1,63 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>70 160 588 603 0 73 1152 775 </string>
<key>IBEditorPositions</key>
<dict>
<key>29</key>
<string>126 846 404 44 0 0 1600 1002 </string>
</dict>
<key>IBFramework Version</key>
<string>313.0</string>
<key>IBOpenObjects</key>
<array>
<integer>29</integer>
<integer>297</integer>
<integer>166</integer>
</array>
<key>IBSystem Version</key>
<string>6L60</string>
<key>IBUserGuides</key>
<dict>
<key>About Box</key>
<dict>
<key>guideLocations</key>
<array/>
<key>guidesLocked</key>
<string>NO</string>
</dict>
<key>File Window</key>
<dict>
<key>guideLocations</key>
<array/>
<key>guidesLocked</key>
<string>NO</string>
</dict>
<key>Inspector</key>
<dict>
<key>guideLocations</key>
<array/>
<key>guidesLocked</key>
<string>NO</string>
</dict>
<key>New Resource</key>
<dict>
<key>guideLocations</key>
<array/>
<key>guidesLocked</key>
<string>NO</string>
</dict>
<key>Preferences</key>
<dict>
<key>guideLocations</key>
<array/>
<key>guidesLocked</key>
<string>NO</string>
</dict>
</dict>
<key>targetFramework</key>
<string>IBCarbonFramework</string>
</dict>
</plist>

File diff suppressed because it is too large Load Diff

View File

@ -1,365 +0,0 @@
#if defined(__APPLE_CC__) // compiling with gcc
#include <Carbon/Carbon.r>
#else // compiling with CodeWarrior, __MWERKS__
#include <Carbon.r>
#endif
/*** APPLE MENU ***/
/*resource 'MENU' (128)
{
128,
textMenuProc,
0xFFFFFFFF,
enabled,
apple,
{
"About ResKnifeÉ", noIcon, "A", noMark, plain,
"PlugÑins", noIcon, 135, noMark, plain,
seperator
}
};*/
resource 'xmnu' (128, purgeable)
{
versionZero
{
{
dataItem { 'abou', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'plug', kMenuNoModifiers, currScript, 0, 0, 135, sysFont, naturalGlyph }
}
};
};
/*** FILE MENU ***/
resource 'MENU' (129)
{
129,
textMenuProc,
0xFFFFFFFF,
enabled,
"File",
{
"New File", noIcon, "N", noMark, plain,
"Open FileÉ", noIcon, "O", noMark, plain,
"Close Window", noIcon, "W", noMark, plain,
"Close File", noIcon, "W", noMark, plain,
"Save File", noIcon, "S", noMark, plain,
"Save File AsÉ", noIcon, "S", noMark, plain,
"RevertÉ", noIcon, noKey, noMark, plain,
"-", noIcon, noKey, noMark, plain,
"Page SetupÉ", noIcon, "P", noMark, plain,
"Print", noIcon, "P", noMark, plain,
"-", noIcon, noKey, noMark, plain,
"Quit", noIcon, "Q", noMark, plain
}
};
resource 'xmnu' (129, purgeable)
{
versionZero
{
{
dataItem { 'new ', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'open', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'clos', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'clsf', kMenuShiftModifier, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'save', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'svas', kMenuShiftModifier, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'rvtf', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
skipItem {},
dataItem { 'setu', kMenuShiftModifier, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'prin', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
skipItem {},
dataItem { 'quit', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph }
}
};
};
resource 'xmnu' (130, purgeable)
{
versionZero
{
{
dataItem { 'undo', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'redo', kMenuShiftModifier, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
skipItem {},
dataItem { 'cut ', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'copy', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'past', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'clea', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'sall', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
skipItem {},
dataItem { 'find', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'agin', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
skipItem {},
dataItem { 'pref', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
}
};
};
resource 'xmnu' (131, purgeable)
{
versionZero
{
{
dataItem { 'newr', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
skipItem {},
dataItem { 'edit', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'tmpl', kMenuShiftModifier, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'tmp ', kMenuShiftModifier | kMenuOptionModifier, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'hex ', kMenuOptionModifier, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
skipItem {},
dataItem { 'rvtr', kMenuShiftModifier, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'play', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
}
};
};
resource 'xmnu' (135, purgeable)
{
versionZero
{
{
dataItem { 'orgn', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
skipItem {},
dataItem { '!hex', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { '!tmp', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
}
};
};
resource 'xmnu' (200, purgeable)
{
versionZero
{
{
dataItem { 'dbug', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
skipItem {},
dataItem { 'surp', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'appl', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'appr', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'nav ', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
dataItem { 'shet', kMenuNoModifiers, currScript, 0, 0, noHierID, sysFont, naturalGlyph },
}
};
};
/*** APPLE EVENTS ***/
#if defined(__MWERKS__) // compiling with CodeWarrior
#include "AppleEvents.r"
#include "AEObjects.r"
#include "AERegistry.r"
#include "ASRegistry.r"
#include "AEUserTermTypes.r"
#endif
#define kAEResourceEditorSuite 'rsrc'
#define kAEResourceClass 'rsrc'
#define kAEResourceName 'name'
#define kAEResourceType 'type'
#define kAECompactResource 'cpct'
resource kAETerminologyExtension ( 0, "AppleScript Dictionary" )
{
1, // major version
0, // minor version
english,
roman, // should be same as resource ID
{
"Required Suite",
"Terms that every application supports",
kAERequiredSuite,
1, // level
1, // version
{ /* events */
/* 1 */ "run",
"Sent to the application when it is opened",
kCoreEventClass,
kAEOpenApplication,
/* reply */
noReply,
"",
replyOptional,
singleItem,
notEnumerated,
reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
/* direct parameter */
noParams,
"",
directParamOptional,
singleItem,
notEnumerated,
changesState,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
{ /* other parameters */ },
/* 2 */ "open",
"Open the specified object(s)",
kCoreEventClass,
kAEOpenDocuments,
/* reply */
noReply,
"",
replyOptional,
singleItem,
notEnumerated,
reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
/* direct parameter */
typeAlias,
"list of objects to open",
directParamRequired,
listOfItems,
notEnumerated,
changesState,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
{ /* other parameters */ },
/* 3 */ "print",
"Print the specified object(s)",
kCoreEventClass,
kAEPrintDocuments,
/* reply */
noReply,
"",
replyOptional,
singleItem,
notEnumerated,
reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
/* direct parameter */
typeAlias,
"list of objects to print",
directParamRequired,
listOfItems,
notEnumerated,
changesState,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
{ /* other parameters */ },
/* 4 */ "quit",
"Quit the application",
kCoreEventClass,
kAEQuitApplication,
/* reply */
noReply,
"",
replyOptional,
singleItem,
notEnumerated,
reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
/* direct parameter */
noParams,
"",
directParamOptional,
singleItem,
notEnumerated,
changesState,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
{ /* other parameters */ }
},
{ /* classes */ },
{ /* comparison operators */ },
{ /* enumerations */ },
"Resource Editor Suite",
"Terms that modern resource editors support",
kAEResourceEditorSuite,
1, // level
1, // version
{ /* array Events */
/* 1 */ "compact",
"Compact the specified resource(s)",
kAEResourceClass,
kAECompactResource,
/* reply */
noReply,
"",
replyOptional,
singleItem,
notEnumerated,
reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
/* direct parameter */
typeAlias,
"list of resources to compact",
directParamRequired,
listOfItems,
notEnumerated,
changesState,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
{ /* other parameters */ },
},
{ /* classes */
"resource",
kAEResourceClass,
"a resource of given type and ID",
{ /* class properties */
/* a */ "name",
kAEResourceName,
typeText,
"the name of the resource (up to 255 chars in length)",
reserved,
singleItem,
notEnumerated,
readWrite,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
noApostrophe,
notFeminine,
notMasculine,
singular,
/* b */ "type",
kAEResourceType,
typeUInt32,
"the type of the resource (four chars in length)",
reserved,
singleItem,
notEnumerated,
readWrite,
reserved, reserved, reserved, reserved,
reserved, reserved, reserved, reserved,
noApostrophe,
notFeminine,
notMasculine,
singular
},
{ /* elements */ }
},
{ /* comparison operators */ },
{ /* enumerations */ }
}
};

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 KiB

View File

@ -1,35 +0,0 @@
#ifndef _ResKnife_Transfer_
#define _ResKnife_Transfer_
/*!
@header Transfer
@discussion Declares the structure used for intra- and inter-application data transfer. All modern resource editors support this structure, and ResKnife handles both copy & paste and drag & drop transfer methods.
*/
/*!
@class ResTransferDesc
@discussion Useful for interaplication data transfer.
*/
typedef class
{
/*! @var version Should be kResTransferDescCurrentVersion. */
UInt16 version;
/*! @var resType Type of resource being copied/dragged. */
ResType resType;
/*! @var resID ID of resource being copied/dragged. */
SInt16 resID;
/*! @var resFlags Flags (attributes) of this resource. */
UInt16 resFlags;
/*! @var resName Name of this resource. */
Str255 resName;
/*! @var hostApp Creator of application that this copy/drag started from. */
OSType hostApp;
/*! @var hostData Data for private use by host. */
UInt32 hostData[4];
/*! @var dataSize Size of resource data. */
UInt32 dataSize;
/*! @var data Variably-sized array with resource data. */
UInt8 data[kVariableLengthArray]; // bug: zero-length resources do weird shit
} ResTransferDesc, *ResTransferPtr;
#endif