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

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 »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »
Explore some of BBCs' most iconic s...
Despite your personal opinion on the BBC at a managerial level, it is undeniable that it has overseen some fantastic British shows in the past, and now thanks to a partnership with Roblox, players will be able to interact with some of these... | Read more »

Price Scanner via MacPrices.net

You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer new Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more
Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several 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... Read more
Roundup of Verizon’s April Apple iPhone Promo...
Verizon is offering a number of iPhone deals for the month of April. Switch, and open a new of service, and you can qualify for a free iPhone 15 or heavy monthly discounts on other models: – 128GB... Read more

Jobs Board

Relationship Banker - *Apple* Valley Financ...
Relationship Banker - Apple Valley Financial Center APPLE VALLEY, Minnesota **Job Description:** At Bank of America, we are guided by a common purpose to help Read more
IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: Apr 9, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
Medical Assistant - Orthopedics *Apple* Hil...
Medical Assistant - Orthopedics Apple Hill York Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now 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
Liquor Stock Clerk - S. *Apple* St. - Idaho...
Liquor Stock Clerk - S. Apple St. Boise Posting Begin Date: 2023/10/10 Posting End Date: 2024/10/14 Category: Retail Sub Category: Customer Service Work Type: Part Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.