TweetFollow Us on Twitter

IconEdit
Volume Number:8
Issue Number:5
Column Tag:C Workshop

IconEdit: A MacApplication in C++

Or, how I learned to stop worrying and love the GUI.

By Kaelin L. Colclasure, Scott AFB, Illinois

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

I’d heard of MacApp long before I bought my first volume of Inside Mac, but I wasn’t that impressed by the idea of an “extendable application.” For one thing, I was a self-taught, experienced programmer and I didn’t need anyone to show me how to write a simple application. And for another, using MacApp at that time meant using Object Pascal, and I prefer C over Pascal. I wrote my own file indexing routines back then, too. Yes, I was a pig-ignorant refugee from the dark ages of data processing.

Now, a few years older and a few volumes of Inside Mac wiser, I realize what a fool I was. These days I don’t write anything without checking to see if it’s already available first, and I acknowledge that the best programming language is the one that lets you complete the task at hand in the least possible time. I still use C(++), but I like to think I use it for the right reasons now.

Unfortunately, by the time I saw the object-oriented light coalesced about MacApp’s figurative head, I had already invested too much in C to switch over to Object Pascal. Thus, when Apple announced their intention to support C++ in MacApp 2.0, I was more than a little enthusiastic.

It took a bit longer than expected, but MPW C++ finally arrived last October. APDA received their initial inventory and shipped my copy (Federal Express, of course) on the same day - my birthday. It was a sign. But enough about me, you’re here to read about C++!

Apple’s Extensions

MPW C++ supports the usual extensions to Macintosh implementations of the underlying C language (i.e., the pascal type modifier, direct function calls, and pascal strings). In addition, some enhancements were added to the specification of C++ itself in the form of two new base classes: HandleObject and PascalObject.

Handle-based classes simplify the use of the Toolbox Memory Manager. They can be declared by subclassing the predefined base class HandleObject. For example:

class MyHandleObject : public HandleObject {

 // Field and member function definitions 
}

As implied by their name, handle-based objects are implemented using handles instead of pointers. Because of this, they are restricted in certain ways. Handle-based objects must be allocated by the new operator and referenced indirectly through a pointer (such a reference is actually doubly-indirect, but thanks to C++’s operator overloading the HandleObject class takes care of that particular detail for you). Also, multiple inheritance cannot be used in classes derived from HandleObject.

The PascalObject base class makes it possible to use Object Pascal classes (such as the MacApp class library) from C++, and vice versa. PascalObject, being a subclass of HandleObject, shares that class’ restrictions and adds a few of its own. A Pascal class can contain only virtual functions, and (naturally) all non-private functions must use Pascal’s calling conventions.

class MyPascalObject : public PascalObject {
public:
 virtual pascal void MyMethod (void);
}

Functions of Pascal classes cannot be overloaded (the message passing scheme does not support C++’s “mangled” name strategy). Also, Pascal classes should not use C++’s constructors or destructors, as these would not be automatically invoked by Object Pascal.

Conversion Pitfalls

Given the above, it’s obvious that the software wizards at Apple have gone out of their way to insure an easy transition from Object Pascal to C++. There are, however, still a few items to watch out for.

Veteran C programmers are no doubt already aware of the way Pascal passes structures- if it’s less than 4 bytes, by value, otherwise by reference (try explaining that one in an introductory programming course). A classic example of this is passing a Rect to one of the ROM routines:

VAR aRect : Rect;

FrameRect (aRect);

becomes in C:

Rect    aRect;

FrameRect (&aRect);

Thankfully, the compiler will catch these and similar errors thanks to C++’s type checking.

Another idiosyncrasy of Object Pascal lies in its mapping of object references. Despite the fact that Object Pascal objects must be allocated with New, they are declared as instances rather than as pointers. In keeping with that metaphor, references to fields and methods of objects do not require dereferences. For example:

/* 1 */

VAR gApplication : TIconApplication;

New (gApplication);
FailNIL (gApplication);
gApplication.IIconApplication (kFileType);

C++’s implementation is more straightforward- Pascal objects are declared and referenced using pointers.

/* 2 */

TIconApplication *gApplication;

gApplication = new TIconApplication;
FailNIL (gApplication);
gApplication->IIconApplication (kFileType);

A somewhat more formidable obstacle is presented by MacApp’s reliance upon Pascal’s nested procedures for certain methods. A nested procedure in Pascal has access to its enclosing procedure’s local variables. C++ (like C) doesn’t support nesting of functions, so this is a bit of a problem. The solution is to pass a “static link” pointer to the function that points to the would-be enclosing function’s local variables, like so:

/* 3 */

pascal void NestedFunction (short aParameter, 
 void *staticLink);

pascal void EnclosingFunction (void) {
 short  aLocal;

 NestedFunction (13, &aLocal);
}

Experimentation would seem to indicate that the static link parameters of functions to be called by MacApp must point within a valid stack frame, even if the function simply ignores the parameter. Setting it to nil has caused the Mac to generate addressing exceptions.

On to the Code

Programmers familiar with MacApp should find few surprises in the C++ version of IconEdit. Following Object Pascal’s convention, the source is broken up into three files: IconEdit.cp contains the main entry point, UIconEdit.h contains the class declarations, and UIconEdit.cp contains code for all of the class functions.

Six classes were needed to implement IconEdit, but only one (TIconBitMap) had to be written from the ground up. Objects of type TIconBitMap contain the actual bitmap of the icon being edited. The functions of the class perform low-level operations on the data, such as toggling individual bits on and off.

The TIconDocument class is a descendant of MacApp’s TDocument. This corresponds to a Finder document. The functions of this class handle document-oriented menu commands (such as Invert) and manage the document’s data in memory and on disk (although TIconDocument doesn’t handle disk I/O just yet).

TIconView is a TView that has been specialized to display a TIconDocument at various magnifications and to allow the user to edit the document by clicking with the mouse.

The TInvertCommand and TDrawCommand classes are specialized TCommand subclasses. TInvertCommand objects handle doing, undoing, and redoing the Invert menu command. TDrawCommand objects handle tracking the mouse and updating the document when the user clicks in a TIconView. Drawing could be made “undoable” simply by adding a few more functions to this class.

Last and least (in lines of code, anyway), the TIconApplication class is an only slightly modified descendant of MacApp’s TApplication. Don’t let the brevity of the code fool you- this is the class that does most of the grunt work involved in implementing the Macintosh interface. Since we’re “true believers” and aren’t messing with the interface in any non-standard ways, we can let MacApp handle just about everything.

The driver in IconEdit.cp does a couple of initialization calls, allocates a TIconApplication object, and sets it on its way with a call to gIconApplication->Run(). And there you have it - a Macintosh application with a complete user interface, without half-a-million lines of code. Almost makes you want to heave that dog-eared copy of Inside Mac right out the window

Building IconEdit

The resource description file, IconEdit.r, contains the Rez input necessary to reconstruct all of IconEdit’s resources. You may find it more instructive, however, to create the view resource yourself using MacApp’s ViewEdit utility. The view hierarchy of IconEdit is illustrated in Figure 1.

Figure 1 - IconEdit’s View Hierarchy

The TScroller and TIconView are each 240 pixels wide by 240 pixels high- 32 bits in the icon times the initial magnification factor of 7, plus an 8 pixel border at each edge. The TWindow has an additional 15 pixels on each side to allow room for the two TSScrollbar views that the TScroller will create. If you wish to create the view resource yourself, you should delete its entry in IconEdit.r before building the application.

Before attempting to compile IconEdit, make sure you’ve followed Apple’s instructions for installing MacApp and C++ and increasing the MPW Shell’s memory partition and stack size. Once that’s been done MacApp’s MABuild utility takes care of most of the details of building your MacApplication for you. You need only insure that all of your source files have been collected into one folder. Make that folder MPW’s current directory, and type:

MABuild IconEdit

MABuild will construct a debugging version of your program and place it in a folder called .Debug Files.

You will receive several warnings from CFront during the compilation process. Some of them come from the header files supplied by Apple - these can be ignored for now. They’ll probably be fixed in the final release of C++. The remaining warnings all complain about unused parameters. I opted not to fix these because I may add some enhancements to IconEdit in a later article.

Afterword

While MacApp and C++ work well together, it’s obvious that they weren’t made for each other. Many of the unique features of C++ could be put to good use in MacApp. A couple that spring immediately to mind are constructors and destructors. Also, multiple inheritance and the ability to overload functions are valuable features - it’s a shame that they can’t be used with Pascal classes.

It is possible to mix “generic” C++ code into your MacApplication, but this is likely to become confusing rather quickly. Better to follow the conventions set forward by the engineers at Apple who wrote MacApp. An added advantage is that by doing so you’ll retain the ability to share code with other MacApp developers, the majority of whom still use Object Pascal. After all, the most valuable benefit of object-oriented programming is the ability to write reusable code - MacApp itself is ample evidence of that.

The Code

//---------------------------------------
// UIconEdit.h - Class declarations for UIconEdit.cp
//
// Written by K.L. Colclasure for MacTutor, Dec 3, 1989
// Copyright © 1989 MacTutor, all rights reserved.
//---------------------------------------

// This typedef makes it easier to declare Fields methods in
// MPW C++:
typedef pascal void (*FieldProcPtr) (StringPtr fieldName,
 Ptr fieldAddr, short fieldType, void *link);

const OSTypekFileType= ‘IDOC’;
const OSTypekSignature  = ‘ICED’;
const short kBorder = 8;
const short kDefaultMagnification = 7;

//---------------------------------------
class TIconBitMap : public TObject {
//---------------------------------------
public:
 Handle fDataHandle; // Handle to the icon’s
 // bitmap.
 
 // Initialize the IconBitMap object and allocate space for
 // its data. 
 virtual pascal void IIconBitMap (void);
 // Free the icon’s bit map.
 virtual pascal void Free (void);
 // Set the contents of the icon bit map to the new bit map.
 virtual pascal void SetIconBitMap (Handle theBitMap);
 // Clear the icon map by setting its bits to zero.
 virtual pascal void Clear (void);
 // Invert the icon’s bit map.
 virtual pascal void Invert (void);
 // Return the state of the given bit.
 virtual pascal Boolean GetBit (Point iconBit);
 // Set the state of the given bit as indicated.
 virtual pascal void SetBit (Point iconBit,
 Boolean turnBitOn);
 // Create a new icon object which is a copy of itself.
 virtual pascal TIconBitMap *Copy (void);
 // Copy icon data to an existing icon object.
 virtual pascal void CopyDataTo (TIconBitMap *anIcon);
 // Draw the icon’s bit map.
 virtual pascal void Draw (Rect *area);
#if qInspector
 virtual pascal void Fields (FieldProcPtr DTF, void *link);
#endif
};

//-----------------------------------
class TIconDocument : public TDocument {
//-----------------------------------
public:
 TIconBitMap*fIconBitMap; // The document’s icon
           // object.
 
 // Initialize the document.
 virtual pascal void IIconDocument (void);
 // Sets the document’s data to represent a “new” 
 // document.
 virtual pascal void DoInitialState (void);
 // Free allocated memory when the document is closed.
 virtual pascal void Free (void);
 // Create the window & view objects when a document’s
 // opened.
 virtual pascal void DoMakeViews (Boolean forPrinting);
 // Set the state of the menu items to which this class
 // responds.
 virtual pascal void DoSetupMenus (void);
 // Handle menu items specific to this class.
 virtual pascal TCommand *DoMenuCommand (
 CmdNumber whichCmd);
 // Invert the bits of this document’s icon and redraw its
 // views.
 virtual pascal void InvertIcon (void);
#if qInspector
 virtual pascal void Fields (FieldProcPtr DTF, void *link);
#endif
};

//-----------------------------------
class TIconView : public TView {
//-----------------------------------
public:
 TIconDocument *fIconDocument;// View’s icon

          // document.
 short  fMagnification;   // Times to magnify
   // icon.
 
 // Initialize the view from a resource template.
 virtual pascal void IRes (TDocument *itsDocument,
 TView *itsSuperView, Ptr *itsParams);
 // Return the view’s minimum size.
 virtual pascal void CalcMinSize (VPoint *minSize);
 // Draw this view.
 virtual pascal void Draw (Rect *area);
 // Set the state of the menu items to which this class
 // responds.
 virtual pascal void DoSetupMenus (void);
 // Handle menu items specific to this class.
 virtual pascal TCommand *DoMenuCommand (
 CmdNumber whichCmd);
 // Set the view’s magnification.
 virtual pascal void SetMagnification (
 short newMagnification);
 // Handle mouse clicks in this view.
 virtual pascal TCommand *DoMouseCommand (
 Point *theMouse, EventInfo *info,
 Point *hysteresis);
 // Convert the given mouse point to an icon bit.
 virtual pascal Boolean PointToBit (Point thePoint,
 Point *iconBit);
 // Draw the given bit in the given state.
 virtual pascal void DrawBit (Point theBit,
 Boolean turnItOn);
#if qInspector
 virtual pascal void Fields (FieldProcPtr DTF, void *link);
#endif
};


//-----------------------------------
class TDrawCommand : public TCommand {
//-----------------------------------
public:
 TIconDocument *fIconDocument; // Document
          // affected.
 TIconView*fIconView;// View affected.
 TIconBitMap*fIconBitMap;  // Icon affected.
 BooleanfTurnBitsOn; // Turn bits on or off.
 
 // Initialize the command and associate it with a view.
 virtual pascal void IDrawCommand (
 TIconView *itsIconView);
 // Constrain the mouse to be within the icon in the edit
 // view.
 virtual pascal void TrackConstrain (VPoint *anchorPoint,
 VPoint *prevPoint, VPoint *nextPoint);
 // Overridden to avoid standard feedback.
 virtual pascal void TrackFeedback (VPoint *anchorPoint,
 VPoint *nextPoint, Boolean turnItOn,
 Boolean mouseMoved);
 // Track the mouse.
 virtual pascal TCommand *TrackMouse (
 TrackPhase aTrackPhase, VPoint *anchorPoint,
 VPoint *prevPoint, VPoint *nextPoint,
 Boolean mouseMoved);
#if qInspector
 virtual pascal void Fields (FieldProcPtr DTF, void *link);
#endif
};

//---------------------------------------
class TInvertCommand : public TCommand {
//---------------------------------------
public:
 TIconDocument *fIconDocument;// Document
 // affected.
 
 // Initialize the command and associate it with a
 // document.
 virtual pascal void IInvertCommand (
 TIconDocument *itsIconDocument);
 // Implement the command by calling the document’s
 // Invert method.
 virtual pascal void DoIt (void);
 // Implement undo by calling the document’s Invert
 // method again.
 virtual pascal void UndoIt (void);
 // Implement redo by calling the document’s Invert
 // method yet again.
 virtual pascal void RedoIt (void);
#if qInspector
 virtual pascal void Fields (FieldProcPtr DTF, void *link);
#endif
};

//---------------------------------------
class TIconApplication : public TApplication {
//---------------------------------------
public:
 // Initialize the application and globals.
 virtual pascal void IIconApplication (
 OSType iconFileType);
 // Create a document of type TIconDocument and return a 
 // reference to it.
 virtual pascal TDocument *DoMakeDocument (
 CmdNumber itsCmdNumber);
};

//---------------------------------------
// UIconEdit.cp - Class implementations for IconEdit
//
// Written by K.L. Colclasure for MacTutor, Dec 3, 1989
// Copyright © 1989 MacTutor, all rights reserved.
//---------------------------------------

// These standard types are missing from MPW 3.0 Types.h:
typedef signed charSignedByte;
typedef unsigned charByte;
typedef enum { v, h }VHSelect;

#include <UMacApp.h>
#include <UIconEdit.h>

#include <ToolUtils.h>

const short cZoomIn = 1000;
const short cZoomOut = 1001;
const short cInvert = 1002;
const short cDraw = 2000;

const short kSeedIconID = 1000;
const short kIconWindowID = 1000;

const short kIconHBits = 32, kIconVBits = 32;
const longkIconSizeInBytes =
 kIconHBits * kIconVBits / 8;
const longkIconSizeInLongs =
 kIconSizeInBytes / 4;
const short kMaxLong =
 (short) kIconSizeInLongs - 1;

typedef longLongArray[kIconSizeInLongs];
typedef LongArray**LongArrayHandle;

//---------------------------------------
pascal void TIconBitMap::IIconBitMap (void) {
//---------------------------------------
 fDataHandle = NewPermHandle (kIconSizeInBytes);
 FailNIL (fDataHandle);
}

//---------------------------------------
pascal void TIconBitMap::Free (void) {
//---------------------------------------
 DisposIfHandle (fDataHandle);
 TObject::Free ();
}

//---------------------------------------
pascal void TIconBitMap::SetIconBitMap (Handle theBitMap) {
//---------------------------------------
 BlockMove (*theBitMap,
 *fDataHandle, kIconSizeInBytes);
}

//---------------------------------------
pascal void TIconBitMap::Clear (void) {
//---------------------------------------
 LongArrayHandle iconData;
 
 iconData = (LongArrayHandle) fDataHandle;
 for (int i = 0; i <= kMaxLong; i++) {
 (**iconData)[i] = 0;
 }
}

//---------------------------------------
pascal void TIconBitMap::Invert (void) {
//---------------------------------------
 LongArrayHandle iconData;
 
 iconData = (LongArrayHandle) fDataHandle;
 for (int i = 0; i <= kMaxLong; i++) {
 (**iconData)[i] ^= 0xffffffff;
 }
}

//---------------------------------------
pascal Boolean TIconBitMap::GetBit (Point iconBit) {
//---------------------------------------
 long   bit;
 
 bit = iconBit.v * kIconVBits + iconBit.h;
 return (BitTst (*fDataHandle, bit));
}

//---------------------------------------
pascal void TIconBitMap::SetBit (Point iconBit,
 Boolean turnBitOn) {
//---------------------------------------
 long   bit;
 
 bit = iconBit.v * kIconVBits + iconBit.h;
 if (turnBitOn) BitSet (*fDataHandle, bit);
 else BitClr (*fDataHandle, bit);
}

//---------------------------------------
pascal TIconBitMap *TIconBitMap::Copy (void) {
//---------------------------------------
 TIconBitMap*copyOfIcon;
 
 copyOfIcon = new TIconBitMap;
 FailNIL (copyOfIcon);
 copyOfIcon->IIconBitMap ();
 copyOfIcon->SetIconBitMap (fDataHandle);
 return (copyOfIcon);
}

//---------------------------------------
pascal void TIconBitMap::CopyDataTo (
 TIconBitMap *anIcon) {
//---------------------------------------
 anIcon->SetIconBitMap (fDataHandle);
}

//---------------------------------------
pascal void TIconBitMap::Draw (Rect *area) {
//---------------------------------------
 PlotIcon (area, fDataHandle);
}

#if qInspector
//---------------------------------------
pascal void TIconBitMap::Fields (
 FieldProcPtr DTF, void *link) {
//---------------------------------------
 (*DTF) (“\pTIconBitMap”, nil, bClass, link);
 (*DTF) (“\pfDataHandle”, (Ptr) &fDataHandle, bHandle,
 link);
 inherited::Fields (DTF, link);
}
#endif

//---------------------------------------
pascal void TIconView::IRes (TDocument *itsDocument,
 TView *itsSuperView, Ptr *itsParams) {
//---------------------------------------
 TView::IRes (itsDocument, itsSuperView, itsParams);
 fIconDocument = (TIconDocument *) itsDocument;
 fMagnification = kDefaultMagnification;
}

//---------------------------------------
pascal void TIconView::CalcMinSize (VPoint *minSize) {
//---------------------------------------
 minSize->h = (32 * fMagnification) + (2 * kBorder);
 minSize->v = minSize->h;
}

//---------------------------------------
pascal void TIconView::Draw (Rect *area) {
//---------------------------------------
 Rect   destRect;
 
 SetRect (&destRect, kBorder, kBorder,
 kBorder + (32 * fMagnification),
 kBorder + (32 * fMagnification));
 fIconDocument->fIconBitMap->Draw (&destRect);
}

//---------------------------------------
pascal void TIconView::DoSetupMenus (void) {
//---------------------------------------
 inherited::DoSetupMenus ();
 Enable (cZoomIn, fMagnification < 32);
 Enable (cZoomOut, fMagnification > 1);
}

//---------------------------------------
pascal TCommand *TIconView::DoMenuCommand (
 CmdNumber whichCmd) {
//---------------------------------------
 switch (whichCmd) {
 case cZoomIn:
 SetMagnification (fMagnification + 1);
 return (gNoChanges);
 case cZoomOut:
 SetMagnification (fMagnification - 1);
 return (gNoChanges);
 default:
 return (inherited::DoMenuCommand (
 whichCmd));
 }
}

//---------------------------------------
pascal void TIconView::SetMagnification (
 short newMagnification) {
//---------------------------------------
 fMagnification = newMagnification;
 AdjustSize ();
 ForceRedraw ();
}
//---------------------------------------
pascal TCommand *TIconView::DoMouseCommand (
 Point *theMouse, EventInfo *info, Point *hysteresis) {
//---------------------------------------
 TDrawCommand  *theCommand;
 Point  unusedPoint;
 
 if (PointToBit (*theMouse, &unusedPoint)) {
 theCommand = new TDrawCommand;
 FailNIL (theCommand);
 theCommand->IDrawCommand (this);
 return (theCommand);
 } else return (gNoChanges);
}

//---------------------------------------
pascal Boolean TIconView::PointToBit (Point thePoint,
 Point *iconBit) {
//---------------------------------------
 thePoint.h -= kBorder;
 thePoint.v -= kBorder;
 if ((thePoint.h >= 0) &&
 (thePoint.h < 32 * fMagnification) &&
 (thePoint.v >= 0) &&
 (thePoint.v < 32 * fMagnification)) {
 iconBit->h = thePoint.h / fMagnification;
 iconBit->v = thePoint.v / fMagnification;
 return (true);
 } else return (false);
}

//---------------------------------------
pascal void TIconView::DrawBit (Point theBit,
 Boolean turnItOn) {
//---------------------------------------
 Rect   bitRect;
 
 bitRect.top = theBit.v * fMagnification + kBorder;
 bitRect.left = theBit.h * fMagnification + kBorder;
 bitRect.bottom = (theBit.v + 1) * fMagnification + kBorder;
 bitRect.right = (theBit.h + 1) * fMagnification + kBorder;
 FillRect (&bitRect, turnItOn ? qd.black : qd.white);
}

#if qInspector
//---------------------------------------
pascal void TIconView::Fields (FieldProcPtr DTF, void *link) {
//---------------------------------------
 (*DTF) (“\pTIconView”, nil, bClass, link);
 (*DTF) (“\pfIconDocument”, (Ptr) &fIconDocument,
 bObject, link);
 (*DTF) (“\pfMagnification”, (Ptr) &fMagnification,
 bInteger, link);
 inherited::Fields (DTF, link);
}
#endif

//---------------------------------------
pascal void TDrawCommand::IDrawCommand (
 TIconView *itsIconView) {
//---------------------------------------
 ICommand (cDraw, itsIconView->fIconDocument,
 itsIconView, itsIconView->GetScroller (true));
 fIconDocument = itsIconView->fIconDocument;
 fIconView = itsIconView;
 fIconBitMap = fIconDocument->fIconBitMap;
 fConstrainsMouse = true;
 fCanUndo = false;
}

//---------------------------------------
pascal void TDrawCommand::TrackConstrain (
 VPoint *anchorPoint, VPoint *prevPoint,
 VPoint *nextPoint) {
//---------------------------------------
 nextPoint->h = Max (kBorder, Min (nextPoint->h,
 fIconView->fSize.h - kBorder - 1));
 nextPoint->v = Max (kBorder, Min (nextPoint->v,
 fIconView->fSize.v - kBorder - 1));
}

//---------------------------------------
pascal void TDrawCommand::TrackFeedback (
 VPoint *anchorPoint, VPoint *nextPoint,
 Boolean turnItOn, Boolean mouseMoved) {
//---------------------------------------
}

//---------------------------------------
pascal TCommand *TDrawCommand::TrackMouse (
 TrackPhase aTrackPhase, VPoint *anchorPoint,
 VPoint *prevPoint, VPoint *nextPoint,
 Boolean mouseMoved) {
//---------------------------------------
 Point  mousePoint;
 Point  iconBit;
 BooleannotUsed;
 
 if (mouseMoved) {
 mousePoint = fIconView->ViewToQDPt (nextPoint);
 notUsed = fIconView->PointToBit (mousePoint,
 &iconBit);
 if (aTrackPhase == trackPress) {
 fTurnBitsOn = !fIconBitMap->GetBit (iconBit);
 }
 fIconBitMap->SetBit (iconBit, fTurnBitsOn);
 fIconView->DrawBit (iconBit, fTurnBitsOn);
 }
 return (this);
}

#if qInspector
//---------------------------------------
pascal void TDrawCommand::Fields (FieldProcPtr DTF,
 void *link) {
//---------------------------------------
 (*DTF) (“\pTDrawCommand”, nil, bClass, link);
 (*DTF) (“\pfIconDocument”, (Ptr) &fIconDocument,
 bObject, link);
 (*DTF) (“\pfIconView”, (Ptr) &fIconView, bObject, link);
 (*DTF) (“\pfIconBitMap”, (Ptr) &fIconBitMap, bObject,
 link);
 (*DTF) (“\pfTurnBitsOn”, (Ptr) &fTurnBitsOn, bBoolean,
 link);
 inherited::Fields (DTF, link);
}
#endif

//---------------------------------------
pascal void TInvertCommand::IInvertCommand (
 TIconDocument *itsIconDocument) {
//---------------------------------------
 ICommand (cInvert, itsIconDocument, nil, nil);
 fIconDocument = itsIconDocument;
}

//---------------------------------------
pascal void TInvertCommand::DoIt (void) {
//---------------------------------------
 fIconDocument->InvertIcon ();
}

//---------------------------------------
pascal void TInvertCommand::UndoIt (void) {
//---------------------------------------
 fIconDocument->InvertIcon ();
}

//---------------------------------------
pascal void TInvertCommand::RedoIt (void) {
//---------------------------------------
 fIconDocument->InvertIcon ();
}

#if qInspector
//---------------------------------------
pascal void TInvertCommand::Fields (FieldProcPtr DTF,
 void *link) {
//---------------------------------------
 (*DTF) (“\pTInvertCommand”, nil, bClass, link);
 (*DTF) (“\pfIconDocument”, (Ptr) &fIconDocument,
 bObject, link);
 inherited::Fields (DTF, link);
}
#endif

//---------------------------------------
pascal void TIconDocument::IIconDocument (void) {
//---------------------------------------
 IDocument (kFileType, kSignature, kUsesDataFork,
 !kUsesRsrcFork, !kDataOpen, !kRsrcOpen);
 
 fIconBitMap = new TIconBitMap;
 FailNIL (fIconBitMap);
 fIconBitMap->IIconBitMap ();
}

//---------------------------------------
pascal void TIconDocument::DoInitialState (void) {
//---------------------------------------
 Handle seedIcon;
 
 seedIcon = GetIcon (kSeedIconID);
 FailNILResource (seedIcon);
 fIconBitMap->SetIconBitMap (seedIcon);
}

//---------------------------------------
pascal void TIconDocument::Free (void) {
//---------------------------------------



 FreeIfObject (fIconBitMap);
 TDocument::Free ();
}

//---------------------------------------
pascal void TIconDocument::DoMakeViews (
 Boolean forPrinting) {
//---------------------------------------
 TWindow*aWindow;
 
 aWindow = NewTemplateWindow (kIconWindowID, this);
}

//---------------------------------------
pascal void TIconDocument::DoSetupMenus (void) {
//---------------------------------------
 inherited::DoSetupMenus ();
 Enable (cInvert, true);
}

//---------------------------------------
pascal TCommand *TIconDocument::DoMenuCommand (
 CmdNumber whichCmd) {
//---------------------------------------
 TInvertCommand  *theCommand;
 
 switch (whichCmd) {
 case cInvert:
 theCommand = new TInvertCommand;
 FailNIL (theCommand);
 theCommand->IInvertCommand (this);
 return (theCommand);
 default:
 return (inherited::DoMenuCommand (
 whichCmd));
 }
}

//---------------------------------------
pascal void RedrawView (TView *aView, void *link) {
//---------------------------------------
 aView->ForceRedraw ();
}

//---------------------------------------
pascal void TIconDocument::InvertIcon (void) {
//---------------------------------------
 short  notUsed;
 
 fIconBitMap->Invert ();
 ForAllViewsDo (RedrawView, &notUsed);
}

#if qInspector
//---------------------------------------
pascal void TIconDocument::Fields (FieldProcPtr DTF,
 void *link) {
//---------------------------------------
 (*DTF) (“\pTIconDocument”, nil, bClass, link);
 (*DTF) (“\pfIconBitMap”, (Ptr) &fIconBitMap, bObject,
 link);
 inherited::Fields (DTF, link);
}
#endif

//---------------------------------------
pascal void TIconApplication::IIconApplication (
 OSType iconFileType) {
//---------------------------------------
 IApplication (iconFileType);
 
 if (gDeadStripSuppression) {
 TIconView *anIconView = new TIconView;
 }
}

//---------------------------------------
pascal TDocument *TIconApplication::DoMakeDocument (
 CmdNumber itsCmdNumber) {
//---------------------------------------
 TIconDocument *anIconDocument;
 
 anIconDocument = new TIconDocument;
 FailNIL (anIconDocument);
 anIconDocument->IIconDocument ();
 return (anIconDocument);
}

//---------------------------------------
// IconEdit.cp - A sample MacApplication in MPW C++.
//
// Written by K.L. Colclasure for MacTutor, Dec 3, 1989
// Copyright © 1989 MacTutor, all rights reserved.
//
// Based upon the Object Pascal IconEdit application from
// the MacApp® 2.0 Tutorial.
//---------------------------------------

// These standard types are missing from MPW 3.0 Types.h:
typedef signed charSignedByte;
typedef unsigned charByte;
typedef enum { v, h }VHSelect;

#include <UMacApp.h>
#include <UIconEdit.h>

// Global holds a reference to the TIconApplication object.
TIconApplication *gIconApplication;

short main () {
 // Initialize the Mac Toolbox 
 InitToolBox ();
 //   and MacApp, eight calls to MoreMasters.
 InitUMacApp (8);
 
 // Create the TIconApplication object.
 gIconApplication = new TIconApplication;
 FailNIL (gIconApplication);
 // Initialize it.
 gIconApplication->IIconApplication (kFileType);
 // Run the application.
 gIconApplication->Run ();
}

//---------------------------------------
// IconEdit.r - Resources for IconEdit
//
// Written by K.L. Colclasure for MacTutor, Dec 3, 1989
// Copyright © 1989 MacTutor, all rights reserved.
//---------------------------------------

#ifndef _TYPES.R_
#include “Types.r”
#endif

#ifndef _MacAppTypes_
#include “MacAppTypes.r”
#endif

#ifndef __ViewTypes__
#include “ViewTypes.r”
#endif

#ifdef Debugging
include “Debug.rsrc”;
#endif
include “MacApp.rsrc”;

include “IconEdit” ‘CODE’;

//---------------------------------------
// Constants
//---------------------------------------
#define cZoomIn  1000
#define cZoomOut 1001
#define cInvert  1002

//---------------------------------------
// Menus
//---------------------------------------
resource ‘cmnu’ (mApple) {
 1,
 textMenuProc,
 0x7FFFFFFD,
 enabled,
 apple,
  {
 /* [1] */“About IconEdit ”, noIcon, noKey, noMark,
 plain, cAboutApp;
 /* [2] */“-”, noIcon, noKey, noMark, plain, nocommand
 }
};

resource ‘cmnu’ (mFile) {
 2,
 textMenuProc,
 allEnabled,
 enabled,
 “File”,
  {
 /* [1] */“New”, noIcon, “N”, noMark, plain, cNew;
 /* [2] */“Open ”, noIcon, “O”, noMark, plain, cOpen;
 /* [3] */“-”, noIcon, noKey, noMark, plain, nocommand;
 /* [4] */“Close”, noIcon, noKey, noMark, plain, cClose;
 /* [5] */“Save”, noIcon, noKey, noMark, plain, cSave;
 /* [6] */“Save As ”, noIcon, noKey, noMark, plain,
 cSaveAs;
 /* [7] */“Revert to Saved”, noIcon, noKey, noMark,
 plain, cRevert;
 /* [8] */“-”, noIcon, noKey, noMark, plain, nocommand;
 /* [9] */“Page Setup ”, noIcon, noKey, noMark, plain,
 cPageSetup;
 /* [10] */ “Print ”, noIcon, noKey, noMark, plain, cPrint;
 /* [11] */ “-”, noIcon, noKey, noMark, plain, nocommand;
 /* [12] */ “Quit”, noIcon, “Q”, noMark, plain, cQuit
 }
};

resource ‘cmnu’ (mEdit) {
 3,
 textMenuProc,
 allEnabled,
 enabled,
 “Edit”,
  {
 /* [1] */“Undo”, noIcon, “Z”, noMark, plain, cUndo;
 /* [2] */“-”, noIcon, noKey, noMark, plain, nocommand;
 /* [3] */“Cut”, noIcon, “X”, noMark, plain, cCut;
 /* [4] */“Copy”, noIcon, “C”, noMark, plain, cCopy;
 /* [5] */“Paste”, noIcon, “V”, noMark, plain, cPaste;
 /* [6] */“Clear”, noIcon, noKey, noMark, plain, cClear;
 /* [7] */“-”, noIcon, noKey, noMark, plain, nocommand;
 /* [8] */“Show Clipboard”, noIcon, noKey, noMark,
 plain, cShowClipboard
 }
};

resource ‘cmnu’ (4) {
 4,
 textMenuProc,
 allEnabled,
 enabled,
 “Icon”,
  {
 /* [1] */“Zoom In”,  noIcon, “M”, noMark, plain,
 cZoomIn;
 /* [2] */“Zoom Out”,  noIcon, “L”, noMark, plain,
 cZoomOut;
 /* [3] */“-”, noIcon, noKey, noMark, plain, nocommand;
 /* [4] */“Invert”, noIcon, “I”, noMark, plain, cInvert
 }
};

resource ‘cmnu’ (128) {
 128,
 textMenuProc,
 allEnabled,
 enabled,
 “Buzzwords”,
  {
 /* [1] */“Page Setup Change”, noIcon, noKey, noMark,
 plain, cChangePrinterStyle
 }
};

resource ‘MBAR’ (128) { {mApple; mFile; mEdit; 4} };

//---------------------------------------
// Alert for default About Box
//---------------------------------------
resource ‘DITL’ (phAboutApp,
#if qNames
“phAboutApp”,
#endif
 purgeable) {
  {/* array DITLarray: 3 elements */
 /* [1] */
 {160, 182, 180, 262},
 Button {
 enabled,
 “OK”
 };
 /* [2] */
 {10, 75, 150, 306},
 StaticText {
 disabled,
 “^0” // The ^0 will be dynamically replaced with
 // CurApName
 “\n\nMPW C++ version for MacTutor “
 “by K.L. Colclasure”
 “\n\nThis program was written “
 “with MacApp® © 1985-1989 Apple Computer, “
 “Inc.”
 };
 /* [3] */
 {10, 20, 42, 52},
 Icon {
 disabled,
 1000
 }
 }
};

resource ‘ALRT’ (phAboutApp,
#if qNames
“phAboutApp”,
#endif
 purgeable) {
 {90, 100, 280, 412},
 phAboutApp,
 {
 OK, visible, silent;
 OK, visible, silent;
 OK, visible, silent;
 OK, visible, silent
 }
};

//---------------------------------------
// Views
//---------------------------------------
resource ‘view’ (1000, “IconEdit”, purgeable) {
 { /* array viewArray: 3 elements */
 /* [1] */
 root, ‘wind’,
 { /* array: 1 elements */
 /* [1] */
 50, 40
 },
 { /* array: 1 elements */
 /* [1] */
 255, 255
 }, sizeVariable, sizeVariable, shown, enabled,
 Window {
 “TWindow”,
 zoomDocProc, goAwayBox, resizable,
 modeless, ignoreFirstClick, freeOnClosing,
 disposeOnFree, closesDocument,
 openWithDocument, dontAdaptToScreen,
 stagger, forceOnScreen, dontCenter,
 ‘VW01’,
 “<<<>>>”
 },
 /* [2] */
 ‘wind’, ‘VW02’,
 { /* array: 1 elements */
 /* [1] */
 0, 0
 },
 { /* array: 1 elements */
 /* [1] */
 240, 240
 }, sizeRelSuperView, sizeRelSuperView, shown,
 enabled,
 Scroller {
 “TScroller”,
 VertScrollBar, HorzScrollBar,
 256, 256, 16, 16,
 noVertConstrain, noHorzConstrain,
 {0, 0, 0, 0}
 },
 /* [3] */
 ‘VW02’, ‘VW01’,
 { /* array: 1 elements */
 /* [1] */
 0, 0
 },
 { /* array: 1 elements */
 /* [1] */
 240, 240
 }, sizeVariable, sizeVariable, shown, enabled,
 View {
 “TIconView”
 }
 }
};

//---------------------------------------
// Seed Icon
//---------------------------------------
data ‘ICON’ (1000, purgeable) {
 $”00 00 00 00 00 02 7E 00 00 04 81 00 00 09 00 80”  
 $”00 12 60 40 00 23 90 20 00 7C FF 1E 00 C4 60 0E” 
 $”01 82 00 0E 03 01 00 0E 06 00 C0 0E 0C 00 3F CE” 
 $”18 00 00 3E 30 00 00 0E 60 00 00 00 C0 00 15 02” 
 $”60 00 40 81 30 00 00 42 18 00 10 24 0C 01 40 10” 
 $”06 0A 2A 8A 03 00 10 05 01 81 00 02 00 C0 80 05” 
 $”00 60 21 02 00 30 0A A5 00 18 00 0A 00 0C 08 05” 
 $”00 06 10 00 00 03 20 00 00 01 C0 00 00 00 80 00” 
};

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

coconutBattery 3.9.14 - Displays info ab...
With coconutBattery you're always aware of your current battery health. It shows you live information about your battery such as how often it was charged and how is the current maximum capacity in... Read more
Keynote 13.2 - Apple's presentation...
Easily create gorgeous presentations with the all-new Keynote, featuring powerful yet easy-to-use tools and dazzling effects that will make you a very hard act to follow. The Theme Chooser lets you... Read more
Apple Pages 13.2 - Apple's word pro...
Apple Pages is a powerful word processor that gives you everything you need to create documents that look beautiful. And read beautifully. It lets you work seamlessly between Mac and iOS devices, and... Read more
Numbers 13.2 - Apple's spreadsheet...
With Apple Numbers, sophisticated spreadsheets are just the start. The whole sheet is your canvas. Just add dramatic interactive charts, tables, and images that paint a revealing picture of your data... Read more
Ableton Live 11.3.11 - Record music usin...
Ableton Live lets you create and record music on your Mac. Use digital instruments, pre-recorded sounds, and sampled loops to arrange, produce, and perform your music like never before. Ableton Live... Read more
Affinity Photo 2.2.0 - Digital editing f...
Affinity Photo - redefines the boundaries for professional photo editing software for the Mac. With a meticulous focus on workflow it offers sophisticated tools for enhancing, editing and retouching... Read more
SpamSieve 3.0 - Robust spam filter for m...
SpamSieve is a robust spam filter for major email clients that uses powerful Bayesian spam filtering. SpamSieve understands what your spam looks like in order to block it all, but also learns what... Read more
WhatsApp 2.2338.12 - Desktop client for...
WhatsApp is the desktop client for WhatsApp Messenger, a cross-platform mobile messaging app which allows you to exchange messages without having to pay for SMS. WhatsApp Messenger is available for... Read more
Fantastical 3.8.2 - Create calendar even...
Fantastical is the Mac calendar you'll actually enjoy using. Creating an event with Fantastical is quick, easy, and fun: Open Fantastical with a single click or keystroke Type in your event details... Read more
iShowU Instant 1.4.14 - Full-featured sc...
iShowU Instant gives you real-time screen recording like you've never seen before! It is the fastest, most feature-filled real-time screen capture tool from shinywhitebox yet. All of the features you... Read more

Latest Forum Discussions

See All

Square Enix commemorates one of its grea...
One of the most criminally underused properties in the Square Enix roster is undoubtedly Parasite Eve, a fantastic fusion of Resident Evil and Final Fantasy that deserved far more than two PlayStation One Games and a PSP follow-up. Now, however,... | Read more »
Resident Evil Village for iPhone 15 Pro...
During its TGS 2023 stream, Capcom showcased the Following upcoming ports revealed during the Apple iPhone 15 event. Capcom also announced pricing for the mobile (and macOS in the case of the former) ports of Resident Evil 4 Remake and Resident Evil... | Read more »
The iPhone 15 Episode – The TouchArcade...
After a 3 week hiatus The TouchArcade Show returns with another action-packed episode! Well, maybe not so much “action-packed" as it is “packed with talk about the iPhone 15 Pro". Eli, being in a time zone 3 hours ahead of me, as well as being smart... | Read more »
TouchArcade Game of the Week: ‘DERE Veng...
Developer Appsir Games have been putting out genre-defying titles on mobile (and other platforms) for a number of years now, and this week marks the release of their magnum opus DERE Vengeance which has been many years in the making. In fact, if the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for September 22nd, 2023. I’ve had a good night’s sleep, and though my body aches down to the last bit of sinew and meat, I’m at least thinking straight again. We’ve got a lot to look at... | Read more »
TGS 2023: Level-5 Celebrates 25 Years Wi...
Back when I first started covering the Tokyo Game Show for TouchArcade, prolific RPG producer Level-5 could always be counted on for a fairly big booth with a blend of mobile and console games on offer. At recent shows, the company’s presence has... | Read more »
TGS 2023: ‘Final Fantasy’ & ‘Dragon...
Square Enix usually has one of the bigger, more attention-grabbing booths at the Tokyo Game Show, and this year was no different in that sense. The line-ups to play pretty much anything there were among the lengthiest of the show, and there were... | Read more »
Valve Says To Not Expect a Faster Steam...
With the big 20% off discount for the Steam Deck available to celebrate Steam’s 20th anniversary, Valve had a good presence at TGS 2023 with interviews and more. | Read more »
‘Honkai Impact 3rd Part 2’ Revealed at T...
At TGS 2023, HoYoverse had a big presence with new trailers for the usual suspects, but I didn’t expect a big announcement for Honkai Impact 3rd (Free). | Read more »
‘Junkworld’ Is Out Now As This Week’s Ne...
Epic post-apocalyptic tower-defense experience Junkworld () from Ironhide Games is out now on Apple Arcade worldwide. We’ve been covering it for a while now, and even through its soft launches before, but it has returned as an Apple Arcade... | Read more »

Price Scanner via MacPrices.net

New low price: 13″ M2 MacBook Pro for $1049,...
Amazon has the Space Gray 13″ MacBook Pro with an Apple M2 CPU and 256GB of storage in stock and on sale today for $250 off MSRP. Their price is the lowest we’ve seen for this configuration from any... Read more
Apple AirPods 2 with USB-C now in stock and o...
Amazon has Apple’s 2023 AirPods Pro with USB-C now in stock and on sale for $199.99 including free shipping. Their price is $50 off MSRP, and it’s currently the lowest price available for new AirPods... Read more
New low prices: Apple’s 15″ M2 MacBook Airs w...
Amazon has 15″ MacBook Airs with M2 CPUs and 512GB of storage in stock and on sale for $1249 shipped. That’s $250 off Apple’s MSRP, and it’s the lowest price available for these M2-powered MacBook... Read more
New low price: Clearance 16″ Apple MacBook Pr...
B&H Photo has clearance 16″ M1 Max MacBook Pros, 10-core CPU/32-core GPU/1TB SSD/Space Gray or Silver, in stock today for $2399 including free 1-2 day delivery to most US addresses. Their price... Read more
Switch to Red Pocket Mobile and get a new iPh...
Red Pocket Mobile has new Apple iPhone 15 and 15 Pro models on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide service using all the major... Read more
Apple continues to offer a $350 discount on 2...
Apple has Studio Display models available in their Certified Refurbished store for up to $350 off MSRP. Each display comes with Apple’s one-year warranty, with new glass and a case, and ships free.... Read more
Apple’s 16-inch MacBook Pros with M2 Pro CPUs...
Amazon is offering a $250 discount on new Apple 16-inch M2 Pro MacBook Pros for a limited time. Their prices are currently the lowest available for these models from any Apple retailer: – 16″ MacBook... Read more
Closeout Sale: Apple Watch Ultra with Green A...
Adorama haș the Apple Watch Ultra with a Green Alpine Loop on clearance sale for $699 including free shipping. Their price is $100 off original MSRP, and it’s the lowest price we’ve seen for an Apple... Read more
Use this promo code at Verizon to take $150 o...
Verizon is offering a $150 discount on cellular-capable Apple Watch Series 9 and Ultra 2 models for a limited time. Use code WATCH150 at checkout to take advantage of this offer. The fine print: “Up... Read more
New low price: Apple’s 10th generation iPads...
B&H Photo has the 10th generation 64GB WiFi iPad (Blue and Silver colors) in stock and on sale for $379 for a limited time. B&H’s price is $70 off Apple’s MSRP, and it’s the lowest price... Read more

Jobs Board

Housekeeper, *Apple* Valley Villa - Cassia...
Apple Valley Villa, part of a 4-star senior living community, is hiring entry-level Full-Time Housekeepers to join our team! We will train you for this position and Read more
Housekeeper, *Apple* Valley Village - Cassi...
Apple Valley Village Health Care Center, a 4-star rated senior care campus, is hiring a Part-Time Housekeeper to join our team! We will train you for this position! Read more
Optometrist- *Apple* Valley, CA- Target Opt...
Optometrist- Apple Valley, CA- Target Optical Date: Sep 23, 2023 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 796045 At Target Read more
Senior *Apple* iOS CNO Developer (Onsite) -...
…Offense and Defense Experts (CODEX) is in need of smart, motivated and self-driven Apple iOS CNO Developers to join our team to solve real-time cyber challenges. Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.