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

Latest Forum Discussions

See All

The secrets of Penacony might soon come...
Version 2.2 of Honkai: Star Rail is on the horizon and brings the culmination of the Penacony adventure after quite the escalation in the latest story quests. To help you through this new expansion is the introduction of two powerful new... | Read more »
The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »

Price Scanner via MacPrices.net

Apple’s 13-inch M2 MacBook Airs return to rec...
Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices currently... Read more
Best Buy is clearing out iPad Airs for up to...
In advance of next week’s probably release of new and updated iPad Airs, Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices for up to $200 off Apple’s MSRP, starting at $399. Sale prices... Read more
Every version of Apple Pencil is on sale toda...
Best Buy has all Apple Pencils on sale today for $79, ranging up to 39% off MSRP for some models. Sale prices for online orders only, in-store prices may vary. Order online and choose free shipping... Read more
Sunday Sale: Apple Studio Display with Standa...
Amazon has the standard-glass Apple Studio Display on sale for $300 off MSRP for a limited time. Shipping is free: – Studio Display (Standard glass): $1299.97 $300 off MSRP For the latest prices and... Read more
Apple is offering significant discounts on 16...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more
Apple HomePods on sale for $30-$50 off MSRP t...
Best Buy is offering a $30-$50 discount on Apple HomePods this weekend on their online store. The HomePod mini is on sale for $69.99, $30 off MSRP, while Best Buy has the full-size HomePod on sale... Read more
Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more

Jobs Board

Licensed Practical Nurse - Womens Imaging *A...
Licensed Practical Nurse - Womens Imaging Apple Hill - PRN Location: York Hospital, York, PA Schedule: PRN/Per Diem Sign-On Bonus Eligible Remote/Hybrid Regular Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Operating Room Assistant - *Apple* Hill Sur...
Operating Room Assistant - Apple Hill Surgical Center - Day Location: WellSpan Health, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.