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

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... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.