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” 
};

 
AAPL
$116.61
Apple Inc.
+1.94
MSFT
$48.52
Microsoft Corpora
+0.30
GOOG
$534.82
Google Inc.
-2.17

MacTech Search:
Community Search:

Software Updates via MacUpdate

SuperDuper! 2.7.3 - Advanced disk clonin...
SuperDuper! is an advanced, yet easy to use disk copying program. It can, of course, make a straight copy, or "clone" -- useful when you want to move all your data from one machine to another, or do... Read more
MacJournal 6.1.5 - Create, maintain, and...
MacJournal is the world's most popular journaling software for the Mac. MacJournal 6 adds a calendar mode that show entries from any journal, geolocation, word count, and progress tracking, as well... Read more
Skim 1.4.10 - PDF Reader and note-taker...
Skim is a PDF reader and note-taker for OS X. It is designed to help you read and annotate scientific papers in PDF, but is also great for viewing any PDF file. Skim includes many features and has a... Read more
FontExplorer X Pro 4.2.2 - Font manageme...
FontExplorer X Pro is optimized for professional use; it's the solution that gives you the power you need to manage all your fonts. Now you can more easily manage, activate and organize your... Read more
SoftRAID 5.0.5 - High-quality RAID manag...
SoftRAID allows you to create and manage disk arrays to increase performance and reliability. SoftRAID's intuitive interface and powerful feature set makes this utility a must have for any Mac OS X... Read more
DEVONthink Pro 2.8.2 - Knowledge base, i...
Save 10% with our exclusive coupon code: MACUPDATE10 DEVONthink Pro is your essential assistant for today's world, where almost everything is digital. From shopping receipts to important research... Read more
Airmail 2.0.1 - Powerful, minimal email...
Airmail 2 is a new mail client designed for OS X 10.10 Yosemite with fast performance and intuitive interaction. Support for iCloud, MS Exchange, Gmail, Google Apps, IMAP, POP3, Yahoo!, AOL, Outlook.... Read more
Together 3.3.3 - Store and organize all...
Together helps you organize your Mac, giving you the ability to store, edit and preview your files in a single clean, uncluttered interface. Smart storage. With simple drag-and-drop functionality,... Read more
OsiriX 6.0.1 - 3D medical image processi...
OsiriX is an image processing software dedicated to DICOM images (".dcm" / ".DCM" extension) produced by medical equipment (MRI, CT, PET, PET-CT, ...) and confocal microscopy (LSM and BioRAD-PIC... Read more
Acorn 4.5.2 - Bitmap image editor. (Demo...
Acorn is a new image editor built with one goal in mind - simplicity. Fast, easy, and fluid, Acorn provides the options you'll need without any overhead. Acorn feels right, and won't drain your bank... Read more

Latest Forum Discussions

See All

Tapventures Review
Tapventures Review By Jennifer Allen on November 20th, 2014 Our Rating: :: ODDLY COMPELLINGUniversal App - Designed for iPhone and iPad Tapventures is an increasingly hands-off one-tap RPG, but expect it to hook you despite your... | Read more »
Who Wore it Best? The Hunger Games: Girl...
With The Hunger Games: Mockingjay Part 1 out this weekend, Who Wore it Best? pits two Hunger Games tie-ins, Girl on Fire and Panem Run, against each other in a brutal and pointless fight to the death. I wonder where we got that idea from? | Read more »
Ironkill Review
Ironkill Review By Jennifer Allen on November 20th, 2014 Our Rating: :: LACKLUSTER PUNCHINGUniversal App - Designed for iPhone and iPad Ironkill is a freemium focused fighting game that doesn’t offer particularly thrilling fights... | Read more »
Real-Time Multiplayer Match-3 RPG Crusad...
Real-Time Multiplayer Match-3 RPG Crusaders Quest Set to Launch Next Month Posted by Ellis Spice on November 20th, 2014 [ permalink ] | Read more »
Checkpoint Champion Review
Checkpoint Champion Review By Jennifer Allen on November 20th, 2014 Our Rating: :: SPEEDY DRIFTINGUniversal App - Designed for iPhone and iPad Checkpoint Champion is a drift-focused racing game that’s ideal for short but fun gaming... | Read more »
MediaFire iOS 8 Native Update Brings New...
MediaFire iOS 8 Native Update Brings New “Power Upload” Feature to iPad and iPhone Posted by Jessica Fisher on November 20th, 2014 [ | Read more »
Mark of the Dragon Review
Mark of the Dragon Review By Nadia Oxford on November 20th, 2014 Our Rating: :: TRAIN YOUR DRAGON FOR WARUniversal App - Designed for iPhone and iPad Mark of the Dragon is a bit rough and scaly, but flying into battle on the backs... | Read more »
My PlayHome School (Entertainment)
My PlayHome School 1.0.1 Device: iOS Universal Category: Entertainment Price: $2.99, Version: 1.0.1 (iTunes) Description: New from the creators of the award winning "My PlayHome"! "My PlayHome School" expands the PlayHome world into... | Read more »
Strap On Your Nope Hat – Five Nights at...
Strap On Your Nope Hat – Five Nights at Freddy’s 2 is Now Available for iOS. Posted by Jessica Fisher on November 20th, 2014 [ permalink ] | Read more »
My PomPom
My PomPom By Nadia Oxford on November 20th, 2014 Our Rating: :: SEND IT BACKUniversal App - Designed for iPhone and iPad My PomPom probably won’t hold your interest long enough to truly become your PomPom.   | Read more »

Price Scanner via MacPrices.net

64GB iPod touch on sale for $249, save $50
Best Buy has the 64GB iPod touch on sale for $249 on their online store for a limited time. Their price is $50 off MSRP. Choose free shipping or free local store pickup (if available). Sale price for... Read more
15″ 2.2GHz Retina MacBook Pro on sale for $17...
 B&H Photo has the 2014 15″ 2.2GHz Retina MacBook Pro on sale for $1799.99 for a limited time. Shipping is free, and B&H charges NY sales tax only. B&H will also include free copies of... Read more
New Logitech AnyAngle Case/Stand Brings Flexi...
Logitec has announced the newest addition to its suite of tablet products — the Logitech AnyAngle. A protective case with an any-angle stand for iPad Air 2 and all iPad mini models, AnyAngle is the... Read more
2013 15-inch 2.0GHz Retina MacBook Pro availa...
B&H Photo has leftover previous-generation 15″ 2.0GHz Retina MacBook Pros available for $1499 including free shipping plus NY sales tax only. Their price is $500 off original MSRP. B&H will... Read more
16GB Retina iPad mini on sale today for $199,...
 Staples has 2nd generation 16GB Retina iPad minis on sale for $199 on their online store for a limited time. Their price is $100 off MSRP. Choose free shipping or free local store pickup (if... Read more
Developers Start Designing Apps for Apple Wat...
Apple has announced the availability of WatchKit, software that gives developers a set of tools to easily create experiences designed specifically for Apple Watch. Apple’s developer community can now... Read more
C Spire Launches iPad Air 2 and iPad Mini 3 o...
C Spire has announced that iPad Air 2 with Wi-Fi + Cellular and iPad mini 3 with Wi-Fi + Cellular are now available on its 4G LTE network. C Spire offers both new iPads with a range of data plans... Read more
Are You On Your Last PC? – The ‘Book Mystique
Will your current PC be your last? Quite possibly so if you define “personal computer” as a traditional desktop or laptop form factor machine according to some commentators. So then, the upshot that... Read more
Save up to $180 on MacBook Airs with Apple re...
The Apple Store has Apple Certified Refurbished 2014 MacBook Airs available for up to $180 off the cost of new models. An Apple one-year warranty is included with each MacBook, and shipping is free.... Read more
16GB iPad mini available for $219, save $30
Walmart has 16GB iPad minis (1st generation) available for $219 on their online store. Their price is $30 off MSRP. Choose free shipping or free store pickup (if available). Price for online orders... Read more

Jobs Board

*Apple* Store Leader Program - College Gradu...
Job Description: Job Summary As an Apple Store Leader Program agent, you can continue your education as you major in the art of leadership at the Apple Store. You'll Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.