Handle refactor

This commit is contained in:
elasota
2019-12-29 23:14:37 -05:00
parent 9cf539eb52
commit fb105bd338
37 changed files with 365 additions and 240 deletions

View File

@@ -5,6 +5,7 @@
//============================================================================ //============================================================================
#include "PLKeyEncoding.h" #include "PLKeyEncoding.h"
#include "PLControlDefinitions.h"
#include "PLNumberFormatting.h" #include "PLNumberFormatting.h"
#include "PLResources.h" #include "PLResources.h"
#include "PLSound.h" #include "PLSound.h"
@@ -42,7 +43,7 @@ void DoAbout (void)
Str255 longVersion; Str255 longVersion;
StringPtr messagePtr; StringPtr messagePtr;
VersRecHndl version; VersRecHndl version;
Handle itemHandle; ControlHandle itemHandle;
short itemType, hit, wasResFile; short itemType, hit, wasResFile;
ModalFilterUPP aboutFilterUPP; ModalFilterUPP aboutFilterUPP;
@@ -55,7 +56,7 @@ void DoAbout (void)
// if (aboutDialog == nil) // if (aboutDialog == nil)
// RedAlert(kErrDialogDidntLoad); // RedAlert(kErrDialogDidntLoad);
version = (VersRecHndl)GetResource('vers', 1); version = GetResource('vers', 1).StaticCast<VersionRecord>();
if (version != nil) if (version != nil)
{ {
messagePtr = (**version).shortVersion + 1 + (**version).shortVersion[0]; messagePtr = (**version).shortVersion + 1 + (**version).shortVersion[0];
@@ -109,7 +110,7 @@ static void HiLiteOkayButton (void)
if (thePict != nil) if (thePict != nil)
{ {
DrawPicture(thePict, &okayButtonBounds); DrawPicture(thePict, &okayButtonBounds);
DisposeHandle((Handle)thePict); thePict.Dispose();
okayButtIsHiLit = true; okayButtIsHiLit = true;
} }
@@ -131,7 +132,7 @@ static void UnHiLiteOkayButton (void)
if (thePict != nil) if (thePict != nil)
{ {
DrawPicture(thePict, &okayButtonBounds); DrawPicture(thePict, &okayButtonBounds);
DisposeHandle((Handle)thePict); thePict.Dispose();
okayButtIsHiLit = false; okayButtIsHiLit = false;
} }

View File

@@ -25,15 +25,19 @@ typedef struct
BEInt16_t resID; BEInt16_t resID;
BEInt16_t reserved; BEInt16_t reserved;
} frame[1]; } frame[1];
} acurRec, *acurPtr, **acurHandle; } acurRec;
typedef THandle<acurRec> acurHandle;
typedef struct typedef struct
{ {
struct struct
{ {
Handle cursorHdl; THandle<CCursor> cursorHdl;
} frame[1]; } frame[1];
} compiledAcurRec, *compiledAcurPtr, **compiledAcurHandle; } compiledAcurRec;
typedef THandle<compiledAcurRec> compiledAcurHandle;
Boolean GetColorCursors (acurHandle, compiledAcurHandle); Boolean GetColorCursors (acurHandle, compiledAcurHandle);
@@ -73,7 +77,7 @@ Boolean GetColorCursors (acurHandle ballCursH, compiledAcurHandle compiledBallCu
} }
else // But, if the cursor loaded ok else // But, if the cursor loaded ok
{ // add it to our list or cursor handles { // add it to our list or cursor handles
(*compiledBallCursH)->frame[i].cursorHdl = (Handle)cursHdl; (*compiledBallCursH)->frame[i].cursorHdl = cursHdl;
SetCCursor((CCrsrHandle)(*compiledBallCursH)->frame[i].cursorHdl); SetCCursor((CCrsrHandle)(*compiledBallCursH)->frame[i].cursorHdl);
} }
} }
@@ -93,10 +97,10 @@ void InitAnimatedCursor (acurHandle ballCursH)
useColor = thisMac.hasColor; useColor = thisMac.hasColor;
if (ballCursH == nil) if (ballCursH == nil)
ballCursH = reinterpret_cast<acurHandle>(GetResource('acur', 128)); ballCursH = GetResource('acur', 128).StaticCast<acurRec>();
if (ballCursH && ballCursH != animCursorH) if (ballCursH && ballCursH != animCursorH)
{ {
compiledBallCursorH = (compiledAcurHandle)NewHandle(sizeof(compiledAcurRec) * (*ballCursH)->n); compiledBallCursorH = NewHandle(sizeof(compiledAcurRec) * (*ballCursH)->n).StaticCast<compiledAcurRec>();
if (!compiledBallCursorH) if (!compiledBallCursorH)
RedAlert(kErrFailedResourceLoad); RedAlert(kErrFailedResourceLoad);
@@ -120,7 +124,7 @@ void InitAnimatedCursor (acurHandle ballCursH)
void LoadCursors (void) void LoadCursors (void)
{ {
InitAnimatedCursor((acurHandle)GetResource('acur', rAcurID)); InitAnimatedCursor(GetResource('acur', rAcurID).StaticCast<acurRec>());
} }
//-------------------------------------------------------------- DisposCursors //-------------------------------------------------------------- DisposCursors
@@ -147,16 +151,16 @@ void DisposCursors (void)
for (i = 0; i < j; i++) for (i = 0; i < j; i++)
{ {
if ((*compiledAnimCursorH)->frame[i].cursorHdl != nil) if ((*compiledAnimCursorH)->frame[i].cursorHdl != nil)
DisposeHandle((Handle)(*compiledAnimCursorH)->frame[i].cursorHdl); (*compiledAnimCursorH)->frame[i].cursorHdl.Dispose();
} }
} }
DisposeHandle((Handle)compiledAnimCursorH); compiledAnimCursorH.Dispose();
compiledAnimCursorH = nil; compiledAnimCursorH = nil;
} }
if (animCursorH != nil) if (animCursorH != nil)
{ {
DisposeHandle((Handle)animCursorH); animCursorH.Dispose();
animCursorH = nil; animCursorH = nil;
} }
} }

View File

@@ -140,7 +140,7 @@ void GetDialogRect (Rect *bounds, short dialogID)
DialogTHndl dlogHandle; DialogTHndl dlogHandle;
Byte wasState; Byte wasState;
dlogHandle = (DialogTHndl)GetResource('DLOG', dialogID); dlogHandle = GetResource('DLOG', dialogID).StaticCast<DialogTemplate>();
if (dlogHandle != nil) if (dlogHandle != nil)
{ {
*bounds = (**dlogHandle).boundsRect; *bounds = (**dlogHandle).boundsRect;
@@ -332,14 +332,14 @@ void ZoomOutAlertRect (short alertID)
void FlashDialogButton (DialogPtr theDialog, short itemNumber) void FlashDialogButton (DialogPtr theDialog, short itemNumber)
{ {
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
UInt32 dummyLong; UInt32 dummyLong;
short itemType; short itemType;
GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, &itemRect);
HiliteControl((ControlHandle)itemHandle, kControlButtonPart); HiliteControl(itemHandle, kControlButtonPart);
Delay(8, &dummyLong); Delay(8, &dummyLong);
HiliteControl((ControlHandle)itemHandle, 0); HiliteControl(itemHandle, 0);
} }
//-------------------------------------------------------------- DrawDefaultButton //-------------------------------------------------------------- DrawDefaultButton
@@ -349,7 +349,7 @@ void FlashDialogButton (DialogPtr theDialog, short itemNumber)
void DrawDefaultButton (DialogPtr theDialog) void DrawDefaultButton (DialogPtr theDialog)
{ {
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, 1, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, 1, &itemType, &itemHandle, &itemRect);
@@ -365,7 +365,7 @@ void DrawDefaultButton (DialogPtr theDialog)
void GetDialogString (DialogPtr theDialog, short item, StringPtr theString) void GetDialogString (DialogPtr theDialog, short item, StringPtr theString)
{ {
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);
@@ -378,7 +378,7 @@ void GetDialogString (DialogPtr theDialog, short item, StringPtr theString)
void SetDialogString (DialogPtr theDialog, short item, const PLPasStr &theString) void SetDialogString (DialogPtr theDialog, short item, const PLPasStr &theString)
{ {
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);
@@ -392,7 +392,7 @@ short GetDialogStringLen (DialogPtr theDialog, short item)
{ {
Rect itemRect; Rect itemRect;
Str255 theString; Str255 theString;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);
@@ -407,11 +407,11 @@ short GetDialogStringLen (DialogPtr theDialog, short item)
void GetDialogItemValue (DialogPtr theDialog, short item, short *theState) void GetDialogItemValue (DialogPtr theDialog, short item, short *theState)
{ {
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);
*theState = GetControlValue((ControlHandle)itemHandle); *theState = GetControlValue(itemHandle);
} }
//-------------------------------------------------------------- SetDialogItemValue //-------------------------------------------------------------- SetDialogItemValue
@@ -421,11 +421,11 @@ void GetDialogItemValue (DialogPtr theDialog, short item, short *theState)
void SetDialogItemValue (DialogPtr theDialog, short item, short theState) void SetDialogItemValue (DialogPtr theDialog, short item, short theState)
{ {
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);
SetControlValue((ControlHandle)itemHandle, theState); SetControlValue(itemHandle, theState);
} }
//-------------------------------------------------------------- ToggleDialogItemValue //-------------------------------------------------------------- ToggleDialogItemValue
@@ -434,16 +434,16 @@ void SetDialogItemValue (DialogPtr theDialog, short item, short theState)
void ToggleDialogItemValue (DialogPtr theDialog, short item) void ToggleDialogItemValue (DialogPtr theDialog, short item)
{ {
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType, theState; short itemType, theState;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);
theState = GetControlValue((ControlHandle)itemHandle); theState = GetControlValue(itemHandle);
if (theState == 0) if (theState == 0)
theState = 1; theState = 1;
else else
theState = 0; theState = 0;
SetControlValue((ControlHandle)itemHandle, theState); SetControlValue(itemHandle, theState);
} }
//-------------------------------------------------------------- SetDialogNumToStr //-------------------------------------------------------------- SetDialogNumToStr
@@ -454,7 +454,7 @@ void SetDialogNumToStr (DialogPtr theDialog, short item, long theNumber)
{ {
Str255 theString; Str255 theString;
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
NumToString(theNumber, theString); NumToString(theNumber, theString);
@@ -470,7 +470,7 @@ void GetDialogNumFromStr (DialogPtr theDialog, short item, long *theNumber)
{ {
Str255 theString; Str255 theString;
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);
@@ -483,7 +483,7 @@ void GetDialogNumFromStr (DialogPtr theDialog, short item, long *theNumber)
void GetDialogItemRect (DialogPtr theDialog, short item, Rect *theRect) void GetDialogItemRect (DialogPtr theDialog, short item, Rect *theRect)
{ {
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, theRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, theRect);
@@ -496,7 +496,7 @@ void GetDialogItemRect (DialogPtr theDialog, short item, Rect *theRect)
void SetDialogItemRect (DialogPtr theDialog, short item, Rect *theRect) void SetDialogItemRect (DialogPtr theDialog, short item, Rect *theRect)
{ {
Rect oldRect; Rect oldRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &oldRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &oldRect);
@@ -510,7 +510,7 @@ void SetDialogItemRect (DialogPtr theDialog, short item, Rect *theRect)
void OffsetDialogItemRect (DialogPtr theDialog, short item, short h, short v) void OffsetDialogItemRect (DialogPtr theDialog, short item, short h, short v)
{ {
Rect oldRect; Rect oldRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &oldRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &oldRect);
@@ -526,17 +526,17 @@ void OffsetDialogItemRect (DialogPtr theDialog, short item, short h, short v)
void SelectFromRadioGroup (DialogPtr dial, short which, short first, short last) void SelectFromRadioGroup (DialogPtr dial, short which, short first, short last)
{ {
Rect iRect; Rect iRect;
Handle iHandle; ControlHandle iHandle;
short iType, i; short iType, i;
for (i = first; i <= last; i++) for (i = first; i <= last; i++)
{ {
GetDialogItem(dial, i, &iType, &iHandle, &iRect); GetDialogItem(dial, i, &iType, &iHandle, &iRect);
SetControlValue((ControlHandle)iHandle, (short)false); SetControlValue(iHandle, (short)false);
} }
GetDialogItem(dial, which, &iType, &iHandle, &iRect); GetDialogItem(dial, which, &iType, &iHandle, &iRect);
SetControlValue((ControlHandle)iHandle, (short)true); SetControlValue(iHandle, (short)true);
} }
//-------------------------------------------------------------- AddMenuToPopUp //-------------------------------------------------------------- AddMenuToPopUp
@@ -559,11 +559,11 @@ void AddMenuToPopUp (DialogPtr theDialog, short whichItem, MenuHandle theMenu)
void GetPopUpMenuValue (DialogPtr theDialog, short whichItem, short *value) void GetPopUpMenuValue (DialogPtr theDialog, short whichItem, short *value)
{ {
Rect iRect; Rect iRect;
Handle iHandle; ControlHandle iHandle;
short iType; short iType;
GetDialogItem(theDialog, whichItem, &iType, &iHandle, &iRect); GetDialogItem(theDialog, whichItem, &iType, &iHandle, &iRect);
*value = GetControlValue((ControlHandle)iHandle); *value = GetControlValue(iHandle);
} }
//-------------------------------------------------------------- SetPopUpMenuValue //-------------------------------------------------------------- SetPopUpMenuValue
@@ -572,11 +572,11 @@ void GetPopUpMenuValue (DialogPtr theDialog, short whichItem, short *value)
void SetPopUpMenuValue (DialogPtr theDialog, short whichItem, short value) void SetPopUpMenuValue (DialogPtr theDialog, short whichItem, short value)
{ {
Rect iRect; Rect iRect;
Handle iHandle; ControlHandle iHandle;
short iType; short iType;
GetDialogItem(theDialog, whichItem, &iType, &iHandle, &iRect); GetDialogItem(theDialog, whichItem, &iType, &iHandle, &iRect);
SetControlValue((ControlHandle)iHandle, value); SetControlValue(iHandle, value);
} }
//-------------------------------------------------------------- MyEnableControl //-------------------------------------------------------------- MyEnableControl
@@ -585,11 +585,11 @@ void SetPopUpMenuValue (DialogPtr theDialog, short whichItem, short value)
void MyEnableControl (DialogPtr theDialog, short whichItem) void MyEnableControl (DialogPtr theDialog, short whichItem)
{ {
Rect iRect; Rect iRect;
Handle iHandle; ControlHandle iHandle;
short iType; short iType;
GetDialogItem(theDialog, whichItem, &iType, &iHandle, &iRect); GetDialogItem(theDialog, whichItem, &iType, &iHandle, &iRect);
HiliteControl((ControlHandle)iHandle, kActive); HiliteControl(iHandle, kActive);
} }
//-------------------------------------------------------------- MyDisableControl //-------------------------------------------------------------- MyDisableControl
@@ -598,11 +598,11 @@ void MyEnableControl (DialogPtr theDialog, short whichItem)
void MyDisableControl (DialogPtr theDialog, short whichItem) void MyDisableControl (DialogPtr theDialog, short whichItem)
{ {
Rect iRect; Rect iRect;
Handle iHandle; ControlHandle iHandle;
short iType; short iType;
GetDialogItem(theDialog, whichItem, &iType, &iHandle, &iRect); GetDialogItem(theDialog, whichItem, &iType, &iHandle, &iRect);
HiliteControl((ControlHandle)iHandle, kInactive); HiliteControl(iHandle, kInactive);
} }
//-------------------------------------------------------------- DrawDialogUserText //-------------------------------------------------------------- DrawDialogUserText
@@ -613,7 +613,7 @@ void MyDisableControl (DialogPtr theDialog, short whichItem)
void DrawDialogUserText (DialogPtr dial, short item, StringPtr text, Boolean invert) void DrawDialogUserText (DialogPtr dial, short item, StringPtr text, Boolean invert)
{ {
Rect iRect; Rect iRect;
Handle iHandle; ControlHandle iHandle;
Str255 newString, stringCopy; Str255 newString, stringCopy;
short iType, textLong, i, inset; short iType, textLong, i, inset;
@@ -652,7 +652,7 @@ void DrawDialogUserText (DialogPtr dial, short item, StringPtr text, Boolean inv
void DrawDialogUserText2 (DialogPtr dial, short item, StringPtr text) void DrawDialogUserText2 (DialogPtr dial, short item, StringPtr text)
{ {
Rect iRect; Rect iRect;
Handle iHandle; ControlHandle iHandle;
Str255 stringCopy; Str255 stringCopy;
short iType; short iType;
@@ -674,7 +674,7 @@ void DrawDialogUserText2 (DialogPtr dial, short item, StringPtr text)
void LoadDialogPICT (DialogPtr theDialog, short item, short theID) void LoadDialogPICT (DialogPtr theDialog, short item, short theID)
{ {
Rect iRect; Rect iRect;
Handle iHandle; ControlHandle iHandle;
PicHandle thePict; PicHandle thePict;
short iType; short iType;
@@ -690,7 +690,7 @@ void LoadDialogPICT (DialogPtr theDialog, short item, short theID)
void FrameDialogItem (DialogPtr theDialog, short item) void FrameDialogItem (DialogPtr theDialog, short item)
{ {
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);
@@ -704,7 +704,7 @@ void FrameDialogItemC (DialogPtr theDialog, short item, long color)
{ {
RGBColor theRGBColor, wasColor; RGBColor theRGBColor, wasColor;
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);
@@ -721,7 +721,7 @@ void FrameDialogItemC (DialogPtr theDialog, short item, long color)
void FrameOvalDialogItem (DialogPtr theDialog, short item) void FrameOvalDialogItem (DialogPtr theDialog, short item)
{ {
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);
@@ -735,7 +735,7 @@ void FrameOvalDialogItem (DialogPtr theDialog, short item)
void BorderDialogItem (DialogPtr theDialog, short item, short sides) void BorderDialogItem (DialogPtr theDialog, short item, short sides)
{ {
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
// 1 = left // 1 = left
@@ -776,7 +776,7 @@ void BorderDialogItem (DialogPtr theDialog, short item, short sides)
void ShadowDialogItem (DialogPtr theDialog, short item, short thickness) void ShadowDialogItem (DialogPtr theDialog, short item, short thickness)
{ {
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);
@@ -794,7 +794,7 @@ void ShadowDialogItem (DialogPtr theDialog, short item, short thickness)
void EraseDialogItem (DialogPtr theDialog, short item) void EraseDialogItem (DialogPtr theDialog, short item)
{ {
Rect itemRect; Rect itemRect;
Handle itemHandle; ControlHandle itemHandle;
short itemType; short itemType;
GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect); GetDialogItem(theDialog, item, &itemType, &itemHandle, &itemRect);

View File

@@ -199,7 +199,9 @@ typedef struct
roomType rooms[1]; // 348 * nRooms roomType rooms[1]; // 348 * nRooms
static const size_t kBinaryDataSize = 866; static const size_t kBinaryDataSize = 866;
} houseType, *housePtr, **houseHand; // total = 866 + } houseType, *housePtr; // total = 866 +
typedef THandle<houseType> houseHand;
typedef struct typedef struct
{ {
@@ -277,7 +279,10 @@ typedef struct
Boolean top; Boolean top;
Boolean right; Boolean right;
Boolean bottom; Boolean bottom;
} boundsType, *boundsPtr, **boundsHand; } boundsType, *boundsPtr;
typedef THandle<boundsType> boundsHand;
typedef struct typedef struct
{ {

View File

@@ -120,9 +120,9 @@ Boolean InitializeEmptyHouse (void)
Str255 tempStr; Str255 tempStr;
if (thisHouse != nil) if (thisHouse != nil)
DisposeHandle((Handle)thisHouse); thisHouse.Dispose();
thisHouse = (houseHand)NewHandle(sizeof(houseType)); thisHouse = NewHandle(sizeof(houseType)).StaticCast<houseType>();
if (thisHouse == nil) if (thisHouse == nil)
{ {

View File

@@ -51,19 +51,19 @@ extern Boolean phoneBitSet, bannerStarCountOn;
void LoopMovie (void) void LoopMovie (void)
{ {
Handle theLoop; THandle<long> theLoop;
UserData theUserData; UserData theUserData;
short theCount; short theCount;
theLoop = NewHandle(sizeof(long)); theLoop = NewHandle(sizeof(long)).StaticCast<long>();
(** (long **) theLoop) = 0; (**theLoop) = 0;
theUserData = GetMovieUserData(theMovie); theUserData = GetMovieUserData(theMovie);
theCount = CountUserDataType(theUserData, 'LOOP'); theCount = CountUserDataType(theUserData, 'LOOP');
while (theCount--) while (theCount--)
{ {
RemoveUserData(theUserData, 'LOOP', 1); RemoveUserData(theUserData, 'LOOP', 1);
} }
AddUserData(theUserData, theLoop, 'LOOP'); AddUserData(theUserData, theLoop.StaticCast<void>(), 'LOOP');
} }
//-------------------------------------------------------------- OpenHouseMovie //-------------------------------------------------------------- OpenHouseMovie
@@ -119,11 +119,11 @@ void OpenHouseMovie (void)
if (theErr != PLErrors::kNone) if (theErr != PLErrors::kNone)
{ {
YellowAlert(kYellowQTMovieNotLoaded, theErr); YellowAlert(kYellowQTMovieNotLoaded, theErr);
DisposeHandle(spaceSaver); spaceSaver.Dispose();
CloseHouseMovie(); CloseHouseMovie();
return; return;
} }
DisposeHandle(spaceSaver); spaceSaver.Dispose();
theErr = PrerollMovie(theMovie, 0, 0x000F0000); theErr = PrerollMovie(theMovie, 0, 0x000F0000);
if (theErr != PLErrors::kNone) if (theErr != PLErrors::kNone)
@@ -642,12 +642,12 @@ Boolean ReadHouse (void)
#endif #endif
if (thisHouse != nil) if (thisHouse != nil)
DisposeHandle((Handle)thisHouse); thisHouse.Dispose();
// GP: Correct for padding // GP: Correct for padding
const size_t alignmentPadding = sizeof(houseType) - sizeof(roomType) - houseType::kBinaryDataSize; const size_t alignmentPadding = sizeof(houseType) - sizeof(roomType) - houseType::kBinaryDataSize;
thisHouse = (houseHand)NewHandle(byteCount + alignmentPadding); thisHouse = NewHandle(byteCount + alignmentPadding).StaticCast<houseType>();
if (thisHouse == nil) if (thisHouse == nil)
{ {
YellowAlert(kYellowNoMemory, 10); YellowAlert(kYellowNoMemory, 10);
@@ -767,7 +767,7 @@ Boolean WriteHouse (Boolean checkIt)
if (checkIt) if (checkIt)
CheckHouseForProblems(); CheckHouseForProblems();
byteCount = GetHandleSize((Handle)thisHouse); byteCount = GetHandleSize(thisHouse.StaticCast<void>());
if (fileDirty) if (fileDirty)
{ {

View File

@@ -616,7 +616,7 @@ void ValidateNumberOfRooms (void)
char wasState; char wasState;
reportsRooms = (long)(*thisHouse)->nRooms; reportsRooms = (long)(*thisHouse)->nRooms;
countedRooms = (GetHandleSize((Handle)thisHouse) - countedRooms = (GetHandleSize(thisHouse.StaticCast<void>()) -
sizeof(houseType)) / sizeof(roomType); sizeof(houseType)) / sizeof(roomType);
if (reportsRooms != countedRooms) if (reportsRooms != countedRooms)
{ {
@@ -737,7 +737,7 @@ void LopOffExtraRooms (void)
{ {
r = (*thisHouse)->nRooms - count; r = (*thisHouse)->nRooms - count;
newSize = sizeof(houseType) + (sizeof(roomType) * (long)r); newSize = sizeof(houseType) + (sizeof(roomType) * (long)r);
if (SetHandleSize((Handle)thisHouse, newSize) != PLErrors::kNone) // resize house handle (shrink) if (SetHandleSize(thisHouse.StaticCast<void>(), newSize) != PLErrors::kNone) // resize house handle (shrink)
{ {
ForeColor(redColor); ForeColor(redColor);
GetLocalizedString(16, message); GetLocalizedString(16, message);

View File

@@ -20,7 +20,7 @@
#define kDiagCursorID 131 #define kDiagCursorID 131
extern Rect **mirrorRects; extern THandle<Rect> mirrorRects;
extern WindowPtr mapWindow, toolsWindow, linkWindow; extern WindowPtr mapWindow, toolsWindow, linkWindow;
extern WindowPtr menuWindow; extern WindowPtr menuWindow;
extern Rect shieldRect, boardSrcRect, localRoomsDest[]; extern Rect shieldRect, boardSrcRect, localRoomsDest[];

View File

@@ -165,14 +165,14 @@ void LoadGraphicPlus (short resID, Rect *theRect)
thePicture = GetPicture(resID); thePicture = GetPicture(resID);
if (thePicture == nil) if (thePicture == nil)
{ {
thePicture = (PicHandle)GetResource('Date', resID); thePicture = GetResource('Date', resID).StaticCast<Picture>();
if (thePicture == nil) if (thePicture == nil)
{ {
return; return;
} }
} }
DrawPicture(thePicture, theRect); DrawPicture(thePicture, theRect);
DisposeHandle((Handle)thePicture); thePicture.Dispose();
} }
//-------------------------------------------------------------- RedrawMapContents //-------------------------------------------------------------- RedrawMapContents

View File

@@ -261,7 +261,7 @@ PLError_t LoadMusicSounds (void)
return PLErrors::kOutOfMemory; return PLErrors::kOutOfMemory;
BlockMove((Ptr)(static_cast<Byte*>(*theSound) + 20L), theMusicData[i], soundDataSize); BlockMove((Ptr)(static_cast<Byte*>(*theSound) + 20L), theMusicData[i], soundDataSize);
DisposeHandle(theSound); theSound.Dispose();
} }
return (theErr); return (theErr);
} }

View File

@@ -1158,7 +1158,7 @@ void DrawCalendar (Rect *theRect)
QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, -bounds.left, -bounds.top);
QOffsetRect(&bounds, theRect->left, theRect->top); QOffsetRect(&bounds, theRect->left, theRect->top);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);
DisposeHandle((Handle)thePicture); thePicture.Dispose();
SetPort((GrafPtr)backSrcMap); SetPort((GrafPtr)backSrcMap);
TextFace(bold); TextFace(bold);
@@ -1191,7 +1191,7 @@ void DrawBulletin (Rect *theRect)
QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, -bounds.left, -bounds.top);
QOffsetRect(&bounds, theRect->left, theRect->top); QOffsetRect(&bounds, theRect->left, theRect->top);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);
DisposeHandle((Handle)thePicture); thePicture.Dispose();
SetGraphicsPort(wasCPort); SetGraphicsPort(wasCPort);
} }
@@ -1246,7 +1246,7 @@ void DrawPictObject (short what, Rect *theRect)
bounds = srcRects[what]; bounds = srcRects[what];
QOffsetRect(&bounds, theRect->left, theRect->top); QOffsetRect(&bounds, theRect->left, theRect->top);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);
DisposeHandle((Handle)thePicture); thePicture.Dispose();
SetGraphicsPort(wasCPort); SetGraphicsPort(wasCPort);
} }

View File

@@ -526,7 +526,7 @@ void PlayGame (void)
QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, -bounds.left, -bounds.top);
QOffsetRect(&bounds, hOffset, 0); QOffsetRect(&bounds, hOffset, 0);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);
DisposeHandle((Handle)thePicture); thePicture.Dispose();
} }
#else #else
// ShowMenuBarOld(); // TEMP // ShowMenuBarOld(); // TEMP
@@ -576,7 +576,7 @@ void PlayGame (void)
QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, -bounds.left, -bounds.top);
QOffsetRect(&bounds, hOffset, 0); QOffsetRect(&bounds, hOffset, 0);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);
DisposeHandle((Handle)thePicture); thePicture.Dispose();
SetGraphicsPort(wasCPort); SetGraphicsPort(wasCPort);
} }

View File

@@ -29,13 +29,12 @@ void RenderStars (void);
void RenderBands (void); void RenderBands (void);
void RenderShreds (void); void RenderShreds (void);
void CopyRectsQD (void); void CopyRectsQD (void);
void CopyRectsAssm (void);
Rect work2MainRects[kMaxGarbageRects]; Rect work2MainRects[kMaxGarbageRects];
Rect back2WorkRects[kMaxGarbageRects]; Rect back2WorkRects[kMaxGarbageRects];
Rect shieldRect; Rect shieldRect;
Rect **mirrorRects; THandle<Rect> mirrorRects;
Point shieldPt; Point shieldPt;
long nextFrame; long nextFrame;
short numWork2Main, numBack2Work; short numWork2Main, numBack2Work;
@@ -151,7 +150,7 @@ void DrawReflection (gliderPtr thisGlider, Boolean oneOrTwo)
SetPort((GrafPtr)workSrcMap); SetPort((GrafPtr)workSrcMap);
long numMirrorRects = GetHandleSize(reinterpret_cast<Handle>(mirrorRects)) / sizeof(Rect); long numMirrorRects = GetHandleSize(mirrorRects.StaticCast<void>()) / sizeof(Rect);
for (long i = 0; i < numMirrorRects; i++) for (long i = 0; i < numMirrorRects; i++)
{ {
@@ -743,16 +742,16 @@ void AddToMirrorRegion (Rect *theRect)
{ {
if (mirrorRects == nil) if (mirrorRects == nil)
{ {
mirrorRects = reinterpret_cast<Rect**>(NewHandle(sizeof(Rect))); mirrorRects = NewHandle(sizeof(Rect)).StaticCast<Rect>();
if (mirrorRects != nil) if (mirrorRects != nil)
**mirrorRects = *theRect; **mirrorRects = *theRect;
} }
else else
{ {
const long oldSize = GetHandleSize(reinterpret_cast<Handle>(mirrorRects)); const long oldSize = GetHandleSize(mirrorRects.StaticCast<void>());
const long newSize = oldSize + sizeof(Rect); const long newSize = oldSize + sizeof(Rect);
if (SetHandleSize(reinterpret_cast<Handle>(mirrorRects), newSize) == PLErrors::kNone) if (SetHandleSize(mirrorRects.StaticCast<void>(), newSize) == PLErrors::kNone)
(*mirrorRects)[oldSize / sizeof(Rect)] = *theRect; (*mirrorRects)[oldSize / sizeof(Rect)] = *theRect;
} }
hasMirror = true; hasMirror = true;
@@ -763,7 +762,7 @@ void AddToMirrorRegion (Rect *theRect)
void ZeroMirrorRegion (void) void ZeroMirrorRegion (void)
{ {
if (mirrorRects != nil) if (mirrorRects != nil)
DisposeHandle(reinterpret_cast<Handle>(mirrorRects)); mirrorRects.Dispose();
mirrorRects = nil; mirrorRects = nil;
hasMirror = false; hasMirror = false;
} }

View File

@@ -194,7 +194,7 @@ Boolean CreateNewRoom (short h, short v)
if (availableRoom == -1) // found no available rooms if (availableRoom == -1) // found no available rooms
{ {
howMuch = sizeof(roomType); // add new room to end of house howMuch = sizeof(roomType); // add new room to end of house
theErr = PtrAndHand((Ptr)thisRoom, (Handle)thisHouse, howMuch); theErr = PtrAndHand((Ptr)thisRoom, thisHouse.StaticCast<void>(), howMuch);
if (theErr != PLErrors::kNone) if (theErr != PLErrors::kNone)
{ {
YellowAlert(kYellowUnaccounted, theErr); YellowAlert(kYellowUnaccounted, theErr);
@@ -260,7 +260,7 @@ void ReadyBackground (short theID, short *theTiles)
thePicture = GetPicture(theID); thePicture = GetPicture(theID);
if (thePicture == nil) if (thePicture == nil)
{ {
thePicture = (PicHandle)GetResource('Date', theID); thePicture = GetResource('Date', theID).StaticCast<Picture>();
if (thePicture == nil) if (thePicture == nil)
{ {
YellowAlert(kYellowNoBackground, 0); YellowAlert(kYellowNoBackground, 0);
@@ -271,7 +271,7 @@ void ReadyBackground (short theID, short *theTiles)
dest = (*thePicture)->picFrame.ToRect(); dest = (*thePicture)->picFrame.ToRect();
QOffsetRect(&dest, -dest.left, -dest.top); QOffsetRect(&dest, -dest.left, -dest.top);
DrawPicture(thePicture, &dest); DrawPicture(thePicture, &dest);
DisposeHandle((Handle)thePicture); thePicture.Dispose();
QSetRect(&src, 0, 0, kTileWide, kTileHigh); QSetRect(&src, 0, 0, kTileWide, kTileHigh);
QSetRect(&dest, 0, 0, kTileWide, kTileHigh); QSetRect(&dest, 0, 0, kTileWide, kTileHigh);
@@ -895,7 +895,7 @@ short GetOriginalBounding (short theID)
boundsHand boundsRes; boundsHand boundsRes;
short boundCode; short boundCode;
boundsRes = (boundsHand)GetResource('bnds', theID); boundsRes = GetResource('bnds', theID).StaticCast<boundsType>();
if (boundsRes == nil) if (boundsRes == nil)
{ {
if (PictIDExists(theID)) if (PictIDExists(theID))
@@ -913,7 +913,7 @@ short GetOriginalBounding (short theID)
boundCode += 4; boundCode += 4;
if ((*boundsRes)->bottom) if ((*boundsRes)->bottom)
boundCode += 8; boundCode += 8;
DisposeHandle((Handle)boundsRes); boundsRes.Dispose();
} }
return (boundCode); return (boundCode);

View File

@@ -134,7 +134,7 @@ void LoadGraphicSpecial (short resID)
thePicture = GetPicture(resID); thePicture = GetPicture(resID);
if (thePicture == nil) if (thePicture == nil)
{ {
thePicture = (PicHandle)GetResource('Date', resID); thePicture = GetResource('Date', resID).StaticCast<Picture>();
if (thePicture == nil) if (thePicture == nil)
{ {
thePicture = GetPicture(2000); thePicture = GetPicture(2000);
@@ -147,7 +147,7 @@ void LoadGraphicSpecial (short resID)
OffsetRect(&bounds, -bounds.left, -bounds.top); OffsetRect(&bounds, -bounds.left, -bounds.top);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);
DisposeHandle((Handle)thePicture); thePicture.Dispose();
} }
//-------------------------------------------------------------- DrawRoomBackground //-------------------------------------------------------------- DrawRoomBackground

View File

@@ -839,16 +839,16 @@ Boolean PictIDExists (short theID)
thePicture = GetPicture(theID); thePicture = GetPicture(theID);
if (thePicture == nil) if (thePicture == nil)
{ {
thePicture = (PicHandle)GetResource('Date', theID); thePicture = GetResource('Date', theID).StaticCast<Picture>();
if (thePicture == nil) if (thePicture == nil)
{ {
foundIt = false; foundIt = false;
} }
else else
DisposeHandle((Handle)thePicture); thePicture.Dispose();
} }
else else
DisposeHandle((Handle)thePicture); thePicture.Dispose();
// foundIt = false; // foundIt = false;
// numPicts = Count1Resources('PICT'); // numPicts = Count1Resources('PICT');
@@ -880,8 +880,8 @@ short GetFirstPICT (void)
resHandle = Get1IndResource('PICT', 1); resHandle = Get1IndResource('PICT', 1);
if (resHandle != nil) if (resHandle != nil)
{ {
const PortabilityLayer::ResourceCompiledRef *resRef = PortabilityLayer::ResourceManager::GetInstance()->ResourceForHandle(reinterpret_cast<PortabilityLayer::MMHandleBlock*>(resHandle)); const PortabilityLayer::ResourceCompiledRef *resRef = PortabilityLayer::ResourceManager::GetInstance()->ResourceForHandle(resHandle.MMBlock());
DisposeHandle(resHandle); resHandle.Dispose();
return resRef->m_resID; return resRef->m_resID;
} }
else else

View File

@@ -228,13 +228,13 @@ PLError_t LoadTriggerSound (short soundID)
theSoundData[kMaxSounds - 1] = NewPtr(soundDataSize); theSoundData[kMaxSounds - 1] = NewPtr(soundDataSize);
if (theSoundData[kMaxSounds - 1] == nil) if (theSoundData[kMaxSounds - 1] == nil)
{ {
DisposeHandle(theSound); theSound.Dispose();
theErr = PLErrors::kOutOfMemory; theErr = PLErrors::kOutOfMemory;
} }
else else
{ {
BlockMove((Ptr)((Byte*)(*theSound) + 20L), theSoundData[kMaxSounds - 1], soundDataSize); BlockMove((Ptr)((Byte*)(*theSound) + 20L), theSoundData[kMaxSounds - 1], soundDataSize);
DisposeHandle(theSound); theSound.Dispose();
} }
} }
} }
@@ -275,7 +275,7 @@ PLError_t LoadBufferSounds (void)
return (PLErrors::kOutOfMemory); return (PLErrors::kOutOfMemory);
BlockMove((Ptr)((Byte*)(*theSound) + 20L), theSoundData[i], soundDataSize); BlockMove((Ptr)((Byte*)(*theSound) + 20L), theSoundData[i], soundDataSize);
DisposeHandle(theSound); theSound.Dispose();
} }
theSoundData[kMaxSounds - 1] = nil; theSoundData[kMaxSounds - 1] = nil;

View File

@@ -84,7 +84,7 @@ void InitScoreboardMap (void)
QOffsetRect(&bounds, -bounds.left, -bounds.top); QOffsetRect(&bounds, -bounds.left, -bounds.top);
QOffsetRect(&bounds, hOffset, 0); QOffsetRect(&bounds, hOffset, 0);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);
DisposeHandle((Handle)thePicture); thePicture.Dispose();
QSetRect(&badgeSrcRect, 0, 0, 32, 66); // 2144 pixels QSetRect(&badgeSrcRect, 0, 0, 32, 66); // 2144 pixels
theErr = CreateOffScreenGWorld(&badgeSrcMap, &badgeSrcRect, kPreferredPixelFormat); theErr = CreateOffScreenGWorld(&badgeSrcMap, &badgeSrcRect, kPreferredPixelFormat);

View File

@@ -289,7 +289,7 @@ void CreatePointers (void)
else else
{ {
BlockMove(*tempHandle, demoData, kDemoLength); BlockMove(*tempHandle, demoData, kDemoLength);
DisposeHandle(tempHandle); tempHandle.Dispose();
} }
#endif #endif
} }

View File

@@ -288,7 +288,7 @@ void LoadGraphic (short resID)
OffsetRect(&bounds, -bounds.left, -bounds.top); OffsetRect(&bounds, -bounds.left, -bounds.top);
DrawPicture(thePicture, &bounds); DrawPicture(thePicture, &bounds);
DisposeHandle((Handle)thePicture); thePicture.Dispose();
} }
//-------------------------------------------------------------- LoadScaledGraphic //-------------------------------------------------------------- LoadScaledGraphic
@@ -304,7 +304,7 @@ void LoadScaledGraphic (short resID, Rect *theRect)
if (thePicture == nil) if (thePicture == nil)
RedAlert(kErrFailedGraphicLoad); RedAlert(kErrFailedGraphicLoad);
DrawPicture(thePicture, theRect); DrawPicture(thePicture, theRect);
DisposeHandle((Handle)thePicture); thePicture.Dispose();
} }
//-------------------------------------------------------------- LargeIconPlot //-------------------------------------------------------------- LargeIconPlot

View File

@@ -533,10 +533,10 @@ namespace PortabilityLayer
} }
if (icsHandle) if (icsHandle)
DisposeHandle(icsHandle); icsHandle.Dispose();
if (ics8Handle) if (ics8Handle)
DisposeHandle(ics8Handle); ics8Handle.Dispose();
m_haveIcon = true; m_haveIcon = true;
} }

View File

@@ -8,8 +8,7 @@ struct Control
{ {
}; };
typedef Control *ControlPtr; typedef THandle<Control> ControlHandle;
typedef ControlPtr *ControlHandle;
typedef void(*ControlActionProc)(ControlHandle control, short part); typedef void(*ControlActionProc)(ControlHandle control, short part);
typedef ControlActionProc ControlActionUPP; typedef ControlActionProc ControlActionUPP;

View File

@@ -222,7 +222,7 @@ Rect BERect::ToRect() const
CursHandle GetCursor(int cursorID) CursHandle GetCursor(int cursorID)
{ {
return reinterpret_cast<CursHandle>(GetResource('CURS', cursorID)); return GetResource('CURS', cursorID).ReinterpretCast<Cursor>();
} }
CCrsrHandle GetCCursor(int cursorID) CCrsrHandle GetCCursor(int cursorID)
@@ -271,7 +271,7 @@ void DisposeCCursor(CCrsrHandle handle)
{ {
(*handle)->hwCursor->Destroy(); (*handle)->hwCursor->Destroy();
PortabilityLayer::MemoryManager::GetInstance()->ReleaseHandle(reinterpret_cast<PortabilityLayer::MMHandleBlock*>(handle)); PortabilityLayer::MemoryManager::GetInstance()->ReleaseHandle(handle.MMBlock());
} }
void Delay(int ticks, UInt32 *endTickCount) void Delay(int ticks, UInt32 *endTickCount)
@@ -298,11 +298,7 @@ short Alert(int dialogID, void *unknown)
Handle GetResource(int32_t resType, int id) Handle GetResource(int32_t resType, int id)
{ {
PortabilityLayer::MMHandleBlock *block = PortabilityLayer::ResourceManager::GetInstance()->GetResource(PortabilityLayer::ResTypeID(resType), id); return PortabilityLayer::ResourceManager::GetInstance()->GetResource(PortabilityLayer::ResTypeID(resType), id);
if (!block)
return nullptr;
return &block->m_contents;
} }
Handle GetResource(const char(&resTypeLiteral)[5], int id) Handle GetResource(const char(&resTypeLiteral)[5], int id)
@@ -637,10 +633,10 @@ void GetIndString(unsigned char *str, int stringsID, int fnameIndex)
if (fnameIndex < 1) if (fnameIndex < 1)
return; return;
PortabilityLayer::MMHandleBlock *istrRes = PortabilityLayer::ResourceManager::GetInstance()->GetResource('STR#', stringsID); THandle<uint8_t> istrRes = PortabilityLayer::ResourceManager::GetInstance()->GetResource('STR#', stringsID).StaticCast<uint8_t>();
if (istrRes && istrRes->m_contents) if (istrRes && *istrRes)
{ {
const uint8_t *contentsBytes = static_cast<const uint8_t *>(istrRes->m_contents); const uint8_t *contentsBytes = *istrRes;
const BEUInt16_t *pArraySize = reinterpret_cast<const BEUInt16_t*>(contentsBytes); const BEUInt16_t *pArraySize = reinterpret_cast<const BEUInt16_t*>(contentsBytes);
const uint16_t arraySize = *pArraySize; const uint16_t arraySize = *pArraySize;
@@ -922,18 +918,12 @@ Handle NewHandle(Size size)
return &hBlock->m_contents; return &hBlock->m_contents;
} }
void DisposeHandle(Handle handle)
{
PortabilityLayer::MemoryManager::GetInstance()->ReleaseHandle(reinterpret_cast<PortabilityLayer::MMHandleBlock*>(handle));
}
long GetHandleSize(Handle handle) long GetHandleSize(Handle handle)
{ {
if (!handle) if (!handle)
return 0; return 0;
PortabilityLayer::MMHandleBlock *block = reinterpret_cast<PortabilityLayer::MMHandleBlock*>(handle); return handle.MMBlock()->m_size;
return static_cast<long>(block->m_size);
} }
PLError_t PtrAndHand(const void *data, Handle handle, Size size) PLError_t PtrAndHand(const void *data, Handle handle, Size size)
@@ -945,7 +935,7 @@ PLError_t PtrAndHand(const void *data, Handle handle, Size size)
PLError_t SetHandleSize(Handle hdl, Size newSize) PLError_t SetHandleSize(Handle hdl, Size newSize)
{ {
PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance(); PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance();
if (!mm->ResizeHandle(reinterpret_cast<PortabilityLayer::MMHandleBlock*>(hdl), newSize)) if (!mm->ResizeHandle(hdl.MMBlock(), newSize))
return PLErrors::kOutOfMemory; return PLErrors::kOutOfMemory;
return PLErrors::kNone; return PLErrors::kNone;

View File

@@ -1,6 +1,4 @@
#pragma once #pragma once
#ifndef __PL_CORE_H__
#define __PL_CORE_H__
#include "DataTypes.h" #include "DataTypes.h"
#include "PLErrorCodes.h" #include "PLErrorCodes.h"
@@ -9,6 +7,7 @@
#include "QDGraf.h" #include "QDGraf.h"
#include "ResTypeID.h" #include "ResTypeID.h"
#include "VirtualDirectory.h" #include "VirtualDirectory.h"
#include "PLHandle.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(error:4311) // Pointer truncation to int #pragma warning(error:4311) // Pointer truncation to int
@@ -44,7 +43,6 @@ struct CGraf;
struct Menu; struct Menu;
typedef void *Ptr; typedef void *Ptr;
typedef Ptr *Handle;
#define PL_DEAD(n) ((void)0) #define PL_DEAD(n) ((void)0)
@@ -172,10 +170,10 @@ typedef Menu *MenuPtr;
typedef CInfoPBRec *CInfoPBPtr; typedef CInfoPBRec *CInfoPBPtr;
typedef VersionRecord *VersRecPtr; typedef VersionRecord *VersRecPtr;
typedef CursPtr *CursHandle; typedef THandle<Cursor> CursHandle;
typedef CCrsrPtr *CCrsrHandle; typedef THandle<CCursor> CCrsrHandle;
typedef MenuPtr *MenuHandle; typedef THandle<Menu> MenuHandle;
typedef VersRecPtr *VersRecHndl; typedef THandle<VersionRecord> VersRecHndl;
typedef WindowPtr WindowRef; // wtf? typedef WindowPtr WindowRef; // wtf?
@@ -332,7 +330,6 @@ void ExitToShell();
void InvalWindowRect(WindowPtr window, const Rect *rect); void InvalWindowRect(WindowPtr window, const Rect *rect);
Handle NewHandle(Size size); Handle NewHandle(Size size);
void DisposeHandle(Handle handle);
long GetHandleSize(Handle handle); long GetHandleSize(Handle handle);
PLError_t PtrAndHand(const void *data, Handle handle, Size size); // Appends data to the end of a handle PLError_t PtrAndHand(const void *data, Handle handle, Size size); // Appends data to the end of a handle
@@ -362,6 +359,3 @@ void PL_NotYetImplemented();
void PL_NotYetImplemented_Minor(); void PL_NotYetImplemented_Minor();
void PL_NotYetImplemented_TODO(const char *category); void PL_NotYetImplemented_TODO(const char *category);
void PL_Init(); void PL_Init();
#endif

View File

@@ -23,22 +23,22 @@ CGrafPtr GetDialogPort(DialogPtr dialog)
return nullptr; return nullptr;
} }
void GetDialogItem(DialogPtr dialog, int index, short *itemType, Handle *itemHandle, Rect *itemRect) void GetDialogItem(DialogPtr dialog, int index, short *itemType, THandle<Control> *itemHandle, Rect *itemRect)
{ {
PL_NotYetImplemented(); PL_NotYetImplemented();
} }
void GetDialogItemText(Handle handle, StringPtr str) void GetDialogItemText(THandle<Control> handle, StringPtr str)
{ {
PL_NotYetImplemented(); PL_NotYetImplemented();
} }
void SetDialogItem(DialogPtr dialog, int index, short itemType, Handle itemHandle, const Rect *itemRect) void SetDialogItem(DialogPtr dialog, int index, short itemType, THandle<Control> itemHandle, const Rect *itemRect)
{ {
PL_NotYetImplemented(); PL_NotYetImplemented();
} }
void SetDialogItemText(Handle handle, const PLPasStr &str) void SetDialogItemText(THandle<Control> handle, const PLPasStr &str)
{ {
PL_NotYetImplemented(); PL_NotYetImplemented();
} }

View File

@@ -5,6 +5,7 @@
#include "PLCore.h" #include "PLCore.h"
class PLPasStr; class PLPasStr;
struct Control;
struct Dialog : public PortabilityLayer::QDPort struct Dialog : public PortabilityLayer::QDPort
{ {
@@ -23,8 +24,7 @@ enum TEMode
typedef Dialog *DialogPtr; typedef Dialog *DialogPtr;
typedef DialogTemplate *DialogTPtr; typedef THandle<DialogTemplate> DialogTHndl;
typedef DialogTPtr *DialogTHndl;
typedef Boolean(*ModalFilterUPP)(DialogPtr dial, EventRecord *event, short *item); typedef Boolean(*ModalFilterUPP)(DialogPtr dial, EventRecord *event, short *item);
@@ -34,11 +34,11 @@ WindowPtr GetDialogWindow(DialogPtr dialog);
DialogPtr GetNewDialog(int resID, void *unknown, WindowPtr behind); DialogPtr GetNewDialog(int resID, void *unknown, WindowPtr behind);
CGrafPtr GetDialogPort(DialogPtr dialog); CGrafPtr GetDialogPort(DialogPtr dialog);
void GetDialogItem(DialogPtr dialog, int index, short *itemType, Handle *itemHandle, Rect *itemRect); void GetDialogItem(DialogPtr dialog, int index, short *itemType, THandle<Control> *itemHandle, Rect *itemRect);
void GetDialogItemText(Handle handle, StringPtr str); void GetDialogItemText(THandle<Control> handle, StringPtr str);
void SetDialogItem(DialogPtr dialog, int index, short itemType, Handle itemHandle, const Rect *itemRect); void SetDialogItem(DialogPtr dialog, int index, short itemType, THandle<Control> itemHandle, const Rect *itemRect);
void SetDialogItemText(Handle handle, const PLPasStr &str); void SetDialogItemText(THandle<Control> handle, const PLPasStr &str);
void SelectDialogItemText(DialogPtr dialog, int item, int firstSelChar, int lastSelCharExclusive); void SelectDialogItemText(DialogPtr dialog, int item, int firstSelChar, int lastSelCharExclusive);

View File

@@ -0,0 +1,9 @@
#include "PLHandle.h"
#include "MemoryManager.h"
void THandleBase::Dispose()
{
if (m_hdl)
PortabilityLayer::MemoryManager::GetInstance()->ReleaseHandle(m_hdl);
}

133
PortabilityLayer/PLHandle.h Normal file
View File

@@ -0,0 +1,133 @@
#pragma once
namespace PortabilityLayer
{
struct MMHandleBlock;
}
class THandleBase
{
public:
explicit THandleBase(PortabilityLayer::MMHandleBlock *hdl);
THandleBase(const THandleBase &other);
PortabilityLayer::MMHandleBlock *MMBlock() const;
void Dispose();
protected:
PortabilityLayer::MMHandleBlock *m_hdl;
};
template<class T>
class THandle final : public THandleBase
{
public:
THandle();
THandle(T **hdl);
explicit THandle(PortabilityLayer::MMHandleBlock *hdl);
THandle(const THandle<T> &other);
operator T **() const;
template<class TOther>
THandle<TOther> StaticCast() const;
template<class TOther>
THandle<TOther> ReinterpretCast() const;
bool operator==(const THandle<T> &other) const;
bool operator!=(const THandle<T> &other) const;
bool operator==(T** other) const;
bool operator!=(T** other) const;
};
typedef THandle<void> Handle;
#include "MMHandleBlock.h"
inline THandleBase::THandleBase(PortabilityLayer::MMHandleBlock *hdl)
: m_hdl(hdl)
{
}
inline THandleBase::THandleBase(const THandleBase &other)
: m_hdl(other.m_hdl)
{
}
inline PortabilityLayer::MMHandleBlock *THandleBase::MMBlock() const
{
return m_hdl;
}
template<class T>
inline THandle<T>::THandle()
: THandleBase(nullptr)
{
}
template<class T>
inline THandle<T>::THandle(T **hdl)
: THandleBase(reinterpret_cast<PortabilityLayer::MMHandleBlock*>(hdl))
{
}
template<class T>
inline THandle<T>::THandle(PortabilityLayer::MMHandleBlock *hdl)
: THandleBase(hdl)
{
}
template<class T>
inline THandle<T>::THandle(const THandle<T> &other)
: THandleBase(other.m_hdl)
{
}
template<class T>
bool THandle<T>::operator==(const THandle<T> &other) const
{
return m_hdl == other.m_hdl;
}
template<class T>
bool THandle<T>::operator!=(const THandle<T> &other) const
{
return m_hdl != other.m_hdl;
}
template<class T>
bool THandle<T>::operator==(T** other) const
{
return static_cast<void*>(&m_hdl->m_contents) == static_cast<void*>(other);
}
template<class T>
bool THandle<T>::operator!=(T** other) const
{
return static_cast<void*>(&m_hdl->m_contents) != static_cast<void*>(other);
}
template<class T>
inline THandle<T>::operator T**() const
{
return reinterpret_cast<T**>(&m_hdl->m_contents);
}
template<class T>
template<class TOther>
THandle<TOther> THandle<T>::StaticCast() const
{
(void)(static_cast<TOther*>(static_cast<T*>(nullptr)));
return THandle<TOther>(m_hdl);
}
template<class T>
template<class TOther>
THandle<TOther> THandle<T>::ReinterpretCast() const
{
(void)(reinterpret_cast<TOther*>(static_cast<T*>(nullptr)));
return THandle<TOther>(m_hdl);
}

View File

@@ -27,7 +27,7 @@ MenuHandle GetMenu(int resID)
return nullptr; return nullptr;
const MenuHandle menu = PortabilityLayer::MenuManager::GetInstance()->DeserializeMenu(*menuRes); const MenuHandle menu = PortabilityLayer::MenuManager::GetInstance()->DeserializeMenu(*menuRes);
DisposeHandle(menuRes); menuRes.Dispose();
return menu; return menu;
} }

View File

@@ -252,7 +252,7 @@ PixMapHandle GetGWorldPixMap(GWorldPtr gworld)
PicHandle GetPicture(short resID) PicHandle GetPicture(short resID)
{ {
return reinterpret_cast<PicHandle>(PortabilityLayer::ResourceManager::GetInstance()->GetResource('PICT', resID)); return PortabilityLayer::ResourceManager::GetInstance()->GetResource('PICT', resID).StaticCast<Picture>();
} }
void OffsetRect(Rect *rect, int right, int down) void OffsetRect(Rect *rect, int right, int down)
@@ -290,7 +290,7 @@ void DrawPicture(PicHandle pict, Rect *bounds)
PortabilityLayer::PixMapImpl *pixMap = static_cast<PortabilityLayer::PixMapImpl*>(*port->GetPixMap()); PortabilityLayer::PixMapImpl *pixMap = static_cast<PortabilityLayer::PixMapImpl*>(*port->GetPixMap());
long handleSize = GetHandleSize(reinterpret_cast<Handle>(pict)); long handleSize = pict.MMBlock()->m_size;
PortabilityLayer::MemReaderStream stream(picPtr, handleSize); PortabilityLayer::MemReaderStream stream(picPtr, handleSize);
// Adjust draw origin // Adjust draw origin

View File

@@ -18,7 +18,7 @@ typedef PixMap *PixMapPtr;
typedef PixMapPtr *PixMapHandle; typedef PixMapPtr *PixMapHandle;
typedef Picture *PicPtr; typedef Picture *PicPtr;
typedef PicPtr *PicHandle; typedef THandle<Picture> PicHandle;
enum QDFlags enum QDFlags
{ {

View File

@@ -889,8 +889,8 @@ void GetIndPattern(Pattern *pattern, int patListID, int index)
if (index < 1) if (index < 1)
return; return;
PortabilityLayer::MMHandleBlock *patternList = PortabilityLayer::ResourceManager::GetInstance()->GetResource('PAT#', patListID); THandle<uint8_t> patternList = PortabilityLayer::ResourceManager::GetInstance()->GetResource('PAT#', patListID).StaticCast<uint8_t>();
const uint8_t *patternRes = static_cast<const uint8_t*>(patternList->m_contents); const uint8_t *patternRes = *patternList;
int numPatterns = (patternRes[0] << 8) | patternRes[1]; int numPatterns = (patternRes[0] << 8) | patternRes[1];
if (index > numPatterns) if (index > numPatterns)

View File

@@ -33,7 +33,7 @@ namespace PortabilityLayer
short OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) override; short OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) override;
void CloseResFile(short ref) override; void CloseResFile(short ref) override;
MMHandleBlock *GetResource(const ResTypeID &resType, int id) override; THandle<void> GetResource(const ResTypeID &resType, int id) override;
short GetCurrentResFile() const override; short GetCurrentResFile() const override;
void SetCurrentResFile(short ref) override; void SetCurrentResFile(short ref) override;
@@ -224,7 +224,7 @@ namespace PortabilityLayer
m_currentResFile = m_lastResFile; m_currentResFile = m_lastResFile;
} }
MMHandleBlock *ResourceManagerImpl::GetResource(const ResTypeID &resType, int id) THandle<void> ResourceManagerImpl::GetResource(const ResTypeID &resType, int id)
{ {
short searchIndex = m_currentResFile; short searchIndex = m_currentResFile;
while (searchIndex >= 0) while (searchIndex >= 0)
@@ -233,7 +233,7 @@ namespace PortabilityLayer
assert(slot.m_resourceFile); assert(slot.m_resourceFile);
if (MMHandleBlock *block = slot.m_resourceFile->GetResource(resType, id, m_load)) if (MMHandleBlock *block = slot.m_resourceFile->GetResource(resType, id, m_load))
return block; return THandle<void>(block);
searchIndex = slot.m_prevFile; searchIndex = slot.m_prevFile;
} }

View File

@@ -17,24 +17,6 @@ struct PLOpenedResFile
static const unsigned int kPLMaxOpenedResFiles = 64; static const unsigned int kPLMaxOpenedResFiles = 64;
static PLOpenedResFile gs_resFiles[kPLMaxOpenedResFiles]; static PLOpenedResFile gs_resFiles[kPLMaxOpenedResFiles];
void DetachResource(Handle hdl)
{
if (!hdl)
return;
PortabilityLayer::MMHandleBlock *block = reinterpret_cast<PortabilityLayer::MMHandleBlock*>(hdl);
assert(block->m_rmSelfRef);
assert(block->m_rmSelfRef->m_handle == block);
block->m_rmSelfRef->m_handle = nullptr;
block->m_rmSelfRef = nullptr;
}
void ReleaseResource(Handle hdl)
{
DetachResource(hdl);
DisposeHandle(hdl);
}
short CurResFile() short CurResFile()
{ {
return PortabilityLayer::ResourceManager::GetInstance()->GetCurrentResFile(); return PortabilityLayer::ResourceManager::GetInstance()->GetCurrentResFile();
@@ -76,7 +58,7 @@ void SetResLoad(Boolean load)
long GetMaxResourceSize(Handle res) long GetMaxResourceSize(Handle res)
{ {
const PortabilityLayer::MMHandleBlock *hBlock = reinterpret_cast<PortabilityLayer::MMHandleBlock*>(res); const PortabilityLayer::MMHandleBlock *hBlock = res.MMBlock();
const PortabilityLayer::ResourceCompiledRef *resRef = hBlock->m_rmSelfRef; const PortabilityLayer::ResourceCompiledRef *resRef = hBlock->m_rmSelfRef;
return resRef->GetSize(); return resRef->GetSize();
} }

View File

@@ -193,6 +193,7 @@
<ClInclude Include="PLEventQueue.h" /> <ClInclude Include="PLEventQueue.h" />
<ClInclude Include="PLFolders.h" /> <ClInclude Include="PLFolders.h" />
<ClInclude Include="PLHacks.h" /> <ClInclude Include="PLHacks.h" />
<ClInclude Include="PLHandle.h" />
<ClInclude Include="PLKeyEncoding.h" /> <ClInclude Include="PLKeyEncoding.h" />
<ClInclude Include="PLLowMem.h" /> <ClInclude Include="PLLowMem.h" />
<ClInclude Include="PLMacTypes.h" /> <ClInclude Include="PLMacTypes.h" />
@@ -317,6 +318,7 @@
<ClCompile Include="ResourceFile.cpp" /> <ClCompile Include="ResourceFile.cpp" />
<ClCompile Include="ScanlineMaskIterator.cpp" /> <ClCompile Include="ScanlineMaskIterator.cpp" />
<ClCompile Include="SimpleGraphic.cpp" /> <ClCompile Include="SimpleGraphic.cpp" />
<ClCompile Include="PLHandle.cpp" />
<ClCompile Include="WindowDef.cpp" /> <ClCompile Include="WindowDef.cpp" />
<ClCompile Include="WindowManager.cpp" /> <ClCompile Include="WindowManager.cpp" />
<ClCompile Include="XModemCRC.cpp" /> <ClCompile Include="XModemCRC.cpp" />

View File

@@ -390,6 +390,9 @@
<ClInclude Include="EllipsePlotter.h"> <ClInclude Include="EllipsePlotter.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="PLHandle.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="CFileStream.cpp"> <ClCompile Include="CFileStream.cpp">
@@ -590,5 +593,8 @@
<ClCompile Include="EllipsePlotter.cpp"> <ClCompile Include="EllipsePlotter.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="PLHandle.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "VirtualDirectory.h" #include "VirtualDirectory.h"
#include "PLHandle.h"
class PLPasStr; class PLPasStr;
@@ -21,7 +22,7 @@ namespace PortabilityLayer
virtual short OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) = 0; virtual short OpenResFork(VirtualDirectory_t virtualDir, const PLPasStr &filename) = 0;
virtual void CloseResFile(short ref) = 0; virtual void CloseResFile(short ref) = 0;
virtual MMHandleBlock *GetResource(const ResTypeID &resType, int id) = 0; virtual THandle<void> GetResource(const ResTypeID &resType, int id) = 0;
virtual short GetCurrentResFile() const = 0; virtual short GetCurrentResFile() const = 0;
virtual void SetCurrentResFile(short ref) = 0; virtual void SetCurrentResFile(short ref) = 0;