TweetFollow Us on Twitter

MacApp and C++
Volume Number:6
Issue Number:8
Column Tag:Jörg's Folder

Using MacApp With C++

By Jörg Langowski, MacTutor Editorial Board

“C++ and MacApp”

Without Eric Carrasco this column couldn’t have been written. Eric is the president of MADA (MacApp Developer’s Association) Europe, and helped me at a crucial point (see below) when I was completely stuck with my example and very close to the “dead-dead-dead”line for this column. So first of all, I’d like to thank you, Eric, for your quick and efficient help.

It seems like using MacApp from C++ is not as trivial as it might have seemed at first sight. Although it has been several months since I got the first - very simple - MacApp ‘nothing’ example to run under C++, our introductions to C++ here have been based on a simpler application model, so that one could understand all the code from beginning to end, something that’s not so easy with MacApp.

So far, there have not been very many C++ examples using MacApp. nothing.cp, which came with the C++ header files, wasn’t too useful an example. Many of the things where object-oriented programming really shines, such as applying methods to lists of objects of unknown type, were just not included. The final version of MacApp 2.0 contains some non-trivial C++ examples, but as I write this, MacApp 2.0 has just been out for some weeks and hasn’t made its way to this side of the Atlantic yet.

Thus I thought it would be a good idea to construct a somewhat more interesting example of a MacApp program in C++. Browsing through examples from Apple’s MacApp developer class, I found one program that contains support for a TextEdit record, a simple drawing tool, a palette, and some color support. I translated the program - originally written in Object Pascal - into C++, with some modifications on the way. The complete program is printed in listings 1-4: 1 is the header file with the class definitions, 2 contains the implementation, 3 the resources and 4 is the MAMake file for building the application.

Since the example is quite long, I won’t explain it in all its details this month, but only point out some specifics that are important for going from Object Pascal to C++. A more detailed explanation of the MacApp part of the story will follow next month.

Translating Object Pascal to C++

At first, everything looks simple: just replace PROCEDURE by pascal void, and the dot by two colons, as in


PROCEDURE TApplication.MainEventLoop;

which becomes

/* 2 */

virtual pascal void TApplication::MainEventLoop(void);

replace FUNCTION (...):INTEGER; by pascal int (); etc furthermore, replace := by =, similarly for the other operators, and change the syntax of for loops, if and case statements.

From the Object Pascal interface file, create a C++ header file this way, and from the Pascal implementation, create the main program (extension .cp). Use an #include directive at the beginning of the program to include the header file. Compile and go.

Some lines from the ‘nothing’ example in Pascal and C++ illustrate this:



 TNothingApplication = OBJECT (TApplication)
 (itsMainFileType: OSType);
 { Initializes the application and globals. }
 TDefaultView    = OBJECT (TView)
 TDefaultView.Draw(area: Rect); OVERRIDE;
 { Draws the view seen in the window. Every
  nonblank view MUST override this method. }

// 4


class TNothingApplication : public TApplication {
public: virtual pascal void 
 INothingApplication(OSType itsMainFileType);  };
class TDefaultView : public TView {
public: virtual pascal void Draw(Rect *area);  };

Unfortunately, life is not that simple, as I could soon find out. Some problems occurred during the translation: a minor one was that C++ arrays (like in C) are always indexed starting at zero. You can’t declare, as in Pascal,


VAR gColorArray: ARRAY[cBlack..cWhite] OF INTEGER;

but have to write (see listing 2)



and later on do appropriate index calculation to access the array at the correct address.

Also, one thing to keep in mind is that a C++ int has no defined size; depending on the system, it can be either 16 or 32 bits long. On the Macintosh, it is 32 bits long, which doesn’t really matter if you are consistent within your own code, but matters a lot when you call Pascal procedures that expect a 16-bit integer. This, of course, is a C++ short. The nice thing about C++ is that the compiler will flag you errors about such type mismatches, and often when a program compiles, it will also execute at least in a semi-reasonable way.

The big problem was a true deficiency of C++: you cannot define procedures inside other procedures. A construction like


procedure a;
 var i,j,k: integer;
 procedure b;
 var a,b,c: real;
 i = k+j;

where b has access to the local variables of a without having passed them explicitly as parameters, is completely illegal in C++.

Second, although it is possible to pass procedure pointers as parameters to a C++ routine, and then execute them from within the routine, one can only pass the pointer, not any parameters with the procedure. That means while you can define in Pascal


procedure p(procedure q(x:real, var y:real));

and later call p(myproc(a,b)), thus defining the parameters that are passed with the procedure used in calling p, in C (or C++) you can only define e.g.

// 9

pascal void p(pascal void (*q)(float x, float *y));

and the type of the procedure pointer passed will be checked on the call; but there is no direct way to pass its parameters.

This means you cannot pass any information to a procedure that is passed as a variable to another procedure; you cannot define it inside another function and use that function’s local variables for parameter passing, neither can you pass parameters directly on the call. The only way would be to go through a global variable; which is very inconvenient.

MacApp makes extensive use of procedure parameters; one example is the method Each(), which applies a procedure to a list of objects of unspecified type. If that procedure expects parameters on its call, we run into the problem described.

This was the point where I was stuck and had to give Eric Carrasco a call. He explained to me that there was a standard way around the problem and that it was described in the MacApp 2.0 final documentation. Which I didn’t have yet, of course. But through network mail, the problem was solved quickly.

The method Each() expects one parameter in its Pascal interface:


procedure TList.Each
 (procedure DoToItem(item: TObject));

which is a procedure that takes any TObject as its parameter. The C++ interface expects two parameters:


virtual pascal void 
 Each(pascal void (*DoToItem) 
 (TObject *item, void *DoToItem_StaticLink), void *DoToItem_StaticLink);

The first parameter is a procedure that now also takes two parameters, one is the pointer to a TObject, and the other a void*, i.e., a generic pointer. The second parameter passed to Each is another void*. This second pointer - in the Each method and in the procedure passed to it as a parameter - is used to pass actual parameters to the procedure.

To illustrate this, look at listing 2 where the DoNeedDiskSpace method of class TTEDocument is implemented. Outside the method, we define a procedure CalcDiskSpace which takes two parameters:


pascal void CalcDiskSpace(TBox *aBox, 
 CalcDiskSpaceStruct *aCalcDiskSpaceStruct)
 (&(aCalcDiskSpaceStruct->myDataForkBytes)); }

where CalcDiskSpaceStruct has been defined in the header file:


struct CalcDiskSpaceStruct {  long myDataForkBytes; };

Now, inside the method, we define


 CalcDiskSpaceStruct aCalcDiskSpaceStruct;

and later use this structure to pass the actual parameter:


 aCalcDiskSpaceStruct.myDataForkBytes = 

CalcDiskSpace must be typecast to the DoToObject type, defined as


typedef pascal void (*DoToObject) 
 (TObject *aObject, void *DoToObject_staticlink);

since otherwise the compiler would give a type mismatch error. ForEachShapeDo just calls the method Each for the object list associated with the document.

This is the way procedure parameters can be passed in C++; slightly more complicated than in Pascal, and I hope this has not confused you too much.

The last thing I’d like to note is that there are lots of debugging utilities built into MacApp; with Object Pascal, you can use writeln to write into the debugger window. I have not found an analogous procedure in C++, printf certainly didn’t work, but all this may be resolved when I receive the final docs. For the moment, the procedure I use is ProgramReport, which writes a string into the debugger window.

Objects should also be able to identify themselves and their instance variables; for this purpose, the methods Fields has been provided. For easy debugging, you should define this method for each class.

I’ll stop here, since this column with the example is getting very long; next month, we’ll look at some of the MacApp-specific details of the program, and also some OOPS Forth again. Till then.

Listing 1: TEDemo.h (header file)

class TTEApplication : public TApplication {
 virtual pascal void 
 ITEApplication(OSType itsMainFileType);
 virtual pascal struct TDocument 
 *DoMakeDocument(CmdNumber itsCmdNumber);
 virtual pascal struct TCommand 
 *DoMenuCommand(CmdNumber aCmdNumber);
 virtual pascal void PoseModalDialog();
#ifdef qDebug
 virtual pascal void IdentifySoftware();

class TTEDocument;

class TPaletteView : public TView {

 int    fIconSelected;
 virtual pascal void 
 IPaletteView(TTEDocument *itsTEDocument);
 virtual pascal struct TCommand 
 *DoMouseCommand(Point *theMouse,
 EventInfo *info, Point *hysteresis);
 pascal void DoHighlightSelection
 (HLState fromHL, HLState toHL);
 pascal void Draw(Rect *area);
#ifdef qDebug
 virtual pascal void Fields(pascal void (*DoToField)
  (StringPtr fieldName, Ptr fieldAddr, 
 short fieldType, void *link), void *link);

class TBox : public TObject {
 Rect fLocation;
 pascal void IBox(Rect *itsLocation);
 pascal void DrawShape();
 pascal void NeedDiskSpace(long *data);
 pascal void Read(short aRefNum);
 pascal void Write(short aRefNum);
#ifdef qDebug
 virtual pascal void Fields(pascal void (*DoToField)
  (StringPtr fieldName, Ptr fieldAddr, 
 short fieldType, void *link), void *link);

class TTextView : public TTEView {

 TPaletteView  *fPaletteView;
 pascal void 
 ITextView(TTEDocument *itsTEDocument);
 pascal Boolean DoIdle(IdlePhase phase);
 pascal struct TCommand  *DoKeyCommand(short ch, 
 short aKeyCode, EventInfo *info);
 pascal struct TCommand 
 *DoMenuCommand(CmdNumber aCmdNumber);
 pascal void DoSetupMenus ();
 pascal struct TCommand 
 *DoMouseCommand(Point *theMouse, 
 EventInfo *info, Point *hysteresis);
 pascal Boolean DoSetCursor
 (Point localPoint, RgnHandle cursorRgn);
 pascal void Draw(Rect *area);
#ifdef qDebug
 virtual pascal void Fields(pascal void (*DoToField)
  (StringPtr fieldName, Ptr fieldAddr, 
 short fieldType, void *link), void *link);

class TColorCmd : public TCommand {

 int  fOldColorCmd, fNewColorCmd;
 pascal void IColorCmd (int aCmdNumber, 
 TTEDocument *itsDocument,TTextView *itsView);
 pascal void DoIt();
 pascal void RedoIt();
 pascal void UndoIt();
#ifdef qDebug
 virtual pascal void Fields(pascal void (*DoToField)
  (StringPtr fieldName, Ptr fieldAddr, 
 short fieldType, void *link), void *link);

class TSketcher : public TCommand {

 TTEDocument   *fTEDocument;
 TBox *fBox;// the object being sketched
 Rect fBoxLocation; // size of the Box being sketched
 pascal void ISketcher
 (TTEDocument *itsDocument, TTextView *itsView);
 pascal struct TCommand *TrackMouse
 (TrackPhase aTrackPhase, VPoint *anchorPoint, 
 VPoint *previousPoint, VPoint *nextPoint, 
 Boolean mouseDidMove);
 pascal void DoIt();
 pascal void RedoIt();
 pascal void UndoIt();
#ifdef qDebug
 virtual pascal void Fields(pascal void (*DoToField)
  (StringPtr fieldName, Ptr fieldAddr, 
 short fieldType, void *link), void *link);

class TTEDocument : public TDocument {
 TPaletteView  *fPaletteView;
 Handle fTextHdl;// text typed by user
 int  fTextColorCmd; // menu command number
 TList *fShapeList;// list of Shapes to be drawn
 pascal void ITEDocument();
 pascal void AddShape(TBox *aBox); 
 pascal void DeleteShape();
 pascal void DoMakeWindows();
 pascal void DoMakeViews(Boolean forPrinting);
 pascal void DoNeedDiskSpace
 (long *dataForkBytes, long *rsrcForkBytes);
 pascal void DoRead(short aRefNum, 
 Boolean rsrcExists, Boolean forPrinting);
 pascal void DoWrite(short aRefNum, 
 Boolean makingCopy);
 pascal void ForEachShapeDo
 (pascal void (*DoToItem) (TObject *item, void 
 *DoToItem_Staticlink),void *DoToItem_Staticlink);
 pascal void Free();
 pascal void SetTextColorCmd(int theColorCmd);
 pascal int  TextColorCmd();
#ifdef qDebug
 virtual pascal void Fields(pascal void (*DoToField)
  (StringPtr fieldName, Ptr fieldAddr, 
 short fieldType, void *link), void *link);

// -- global definitions --

typedef pascal void (*DoToObject) 
 (TObject *aObject, void *DoToObject_staticlink);
struct CalcDiskSpaceStruct {  long myDataForkBytes; };
struct DoToRectStruct {  int myRefNum; };

// -- end of declarations --
Listing 2: TEDemo.cp (implementation)

#include <UMacApp.h>
#include <UPrinting.h>
#include <UTEView.h>
#include <Fonts.h>
#include <ToolUtils.h>

#include “TEDemo.h”

const OSType kSignature   = ‘JLMT’;
const OSType kFileType  = ‘JL01’;
const int kWindID= 1001;  
const int kHelpID  = 1001;// Help DLOG ID 
const int kPaletteWidth = 640;
const int kPaletteHeight  = 32;
const int kIconWidth =  32;
const int kBoxIconID =  256;
const int kTextIconID=  257;
const int kBox   = 1;
const int kText  = 2;
const int kPaletteColor   = greenColor;
const int kBoxColor= redColor;

// commands
const int cHelp  = 1001;  // for color menu items
const int cDrawBox = 2001;
 // command number for Box sketcher object

const int cBlack = 5001;  // for TextColor menu
const int cBlue  = 5002;
const int cGreen = 5003;
const int cRed   = 5004;
const int cWhite = 5005;
Rect  gIconRect[kText-kBox+1];

pascal void TTEApplication::ITEApplication
 (OSType itsMainFileType)
{  gColorArray[cBlack-cBlack] = blackColor; 
 gColorArray[cBlue-cBlack]  = blueColor;
 gColorArray[cGreen-cBlack] = greenColor;
 gColorArray[cRed-cBlack] = redColor;
 gColorArray[cWhite-cBlack] = whiteColor;
 0, 0, kIconWidth, kIconWidth);
 SetRect(&gIconRect[kText-kBox], kIconWidth, 
 0, 2 * kIconWidth, kIconWidth);
 RegisterStdType(“\pTTextView”, ‘text’);
 if (gDeadStripSuppression)
 { TTextView *aTextView;
 aTextView = new TTextView; }

pascal struct TDocument 
 (CmdNumber itsCmdNumber)
{TTEDocument* aTEDocument;
 aTEDocument = new TTEDocument;
 return aTEDocument; }

pascal void TTEApplication::PoseModalDialog()
{DialogPtr dPtr;
 short  dItem;
 dPtr = GetNewDialog(kHelpID, nil, (WindowPtr) -1);
 ModalDialog(nil, &dItem);
 DisposDialog(dPtr); }

pascal struct TCommand 
 (CmdNumber aCmdNumber)
{switch (aCmdNumber) {
 case cHelp: 
 return gNoChanges;
 return inherited::DoMenuCommand(aCmdNumber); }

#ifdef qDebug
pascal void TTEApplication::IdentifySoftware()
(“\pTEDemo ©J.Langowski/MacTutor June 1990”,false);
 inherited::IdentifySoftware();  }

// ---- Document ----

pascal void TTEDocument::ITEDocument()
{TList  *aList;
 IDocument(kFileType, kSignature, kUsesDataFork,
 !kUsesRsrcFork, !kDataOpen, !kRsrcOpen);
 fSavePrintInfo = true; // save print info in data fork
 fTextHdl = NewPermHandle(0); // heap block for text
 fTextColorCmd = cBlack;
 aList = NewList();// make empty list of Boxs
 fShapeList = aList; }

pascal void TTEDocument::AddShape(TBox *aBox)
{fShapeList->InsertFirst(aBox);    }

pascal void TTEDocument::DeleteShape()
{fShapeList->Delete(fShapeList->First());  }

pascal void TTEDocument::DoMakeViews
 (Boolean forPrinting)
{const Boolean kSquareDots = true;
 const Boolean kFixedSize = true;
 TPaletteView    *aPaletteView;
 aPaletteView = new TPaletteView;
 fPaletteView = aPaletteView; 
 // save reference to palette in document
 aTextView = new TTextView;
 fTextView = aTextView; 
 // save reference to text view in document
 // so view uses the same characters
 aStdHandler = new TStdPrintHandler;
 // make text view printable
 aStdHandler->IStdPrintHandler (this, aTextView,
  !kSquareDots, kFixedSize, !kFixedSize); }

pascal void TTEDocument::DoMakeWindows()
 aWindow = NewPaletteWindow(kWindID, 
 kWantHScrollBar, kWantVScrollBar,  this, 
 fTextView, fPaletteView, kPaletteHeight, 
 // adjust for various size monitors
 kStdStaggerAmount, &gStdStaggerCount); }

pascal void CalcDiskSpace(TBox *aBox, 
 CalcDiskSpaceStruct *aCalcDiskSpaceStruct)
 (&(aCalcDiskSpaceStruct->myDataForkBytes)); }

pascal void TTEDocument::DoNeedDiskSpace
 (long *dataForkBytes, long *rsrcForkBytes)
{long textBytes, numberOfShapesBytes, 
 CalcDiskSpaceStruct aCalcDiskSpaceStruct;
/* file format:
 TextCmd Number (integer)
 # shapes (integer)
 data for shape #1
 data for shape #2
 text   */
 inherited::DoNeedDiskSpace (dataForkBytes, 
 aCalcDiskSpaceStruct.myDataForkBytes = 
 cmdNumberBytes = sizeof(int);
 numberOfShapesBytes = sizeof(fTextColorCmd);
 textBytes = GetHandleSize(fTextHdl);
 *dataForkBytes = cmdNumberBytes + 
 numberOfShapesBytes +  
 aCalcDiskSpaceStruct.myDataForkBytes + 
 textBytes;  }

pascal void TTEDocument::DoRead(short aRefNum,
 Boolean rsrcExists, Boolean forPrinting) 
{long   textColorCmdNumberBytes;
 int    textColorCmdNumber; 
 long   numberOfShapesBytes;
 int    numberOfShapes; 
 TBox *aBox;
 long eof, fPos, textBytes;
/* file format see above  */
 inherited::DoRead(aRefNum, rsrcExists, forPrinting);
 // print info from disk
 textColorCmdNumberBytes = 
 sizeof(textColorCmdNumber); // read text color
 FSRead(aRefNum, &textColorCmdNumberBytes, 
 (Ptr) &textColorCmdNumber));
 fTextColorCmd = textColorCmdNumber;
 numberOfShapesBytes = sizeof(numberOfShapes);
 // read # items
 FSRead(aRefNum, &numberOfShapesBytes, 
 (Ptr) &numberOfShapes));
 for (int i = 1; i <= numberOfShapes; i++)
 { aBox = new TBox; FailNIL(aBox); // make new Box
 aBox->Read(aRefNum); // read & initialize object
 AddShape(aBox); };  // add to list in doc
 FailOSErr(GetFPos(aRefNum, &fPos)); 
 // get size of text in file
 FailOSErr(GetEOF(aRefNum, &eof));
 // get size of data in file
 textBytes = eof - fPos;
 SetHandleSize(fTextHdl, textBytes);
 HLock (fTextHdl);
 FailOSErr(FSRead(aRefNum, &textBytes, *fTextHdl));
 HUnlock (fTextHdl); }

pascal void DoToRect
 (TBox *aBox, DoToRectStruct*aDoToRectStruct)
{aBox->Write(aDoToRectStruct->myRefNum);  }
pascal void TTEDocument::DoWrite
 (short aRefNum, Boolean makingCopy)
{long textColorCmdNumberBytes;
 int    textColorCmdNumber; 
 long numberOfShapesBytes;
 int    numberOfShapes;
 long textBytes;
 DoToRectStruct  aDoToRectStruct;
/* file format see above  */
 inherited::DoWrite(aRefNum, makingCopy);
 // print info to disk
 textColorCmdNumber = fTextColorCmd;
 // write text color to disk
 textColorCmdNumberBytes = 
 FSWrite(aRefNum, &textColorCmdNumberBytes, 
 (Ptr) &textColorCmdNumber));
 numberOfShapes = fShapeList->fSize;
 // write # items to disk
 numberOfShapesBytes = sizeof(numberOfShapes);
 FSWrite(aRefNum, &numberOfShapesBytes, 
 (Ptr) &numberOfShapes));
 aDoToRectStruct.myRefNum = aRefNum;
 &aDoToRectStruct);// write each rect to disk
 textBytes = GetHandleSize(fTextHdl);
 HLock (fTextHdl);
 FailOSErr(FSWrite(aRefNum, &textBytes, *fTextHdl));
 // write the text
 HUnlock (fTextHdl); }

pascal void TTEDocument::ForEachShapeDo
 (pascal void (*DoToItem)(TObject *item,
  void *DoToItem_Staticlink),void *DoToItem_Staticlink)
{  fShapeList->Each(DoToItem,DoToItem_Staticlink); }

pascal void DisposeRect(TBox *aBox, void *link)
{aBox->Free(); }

pascal void TTEDocument::Free()
{void *link;
 if (fTextHdl != nil) DisposHandle(fTextHdl);
 // dispose of ASCII characters
 // dispose of Box objects
 fShapeList->Free(); // dispose of List object
 inherited::Free();} // dispose of document object

#ifdef qDebug
pascal void TTEDocument::Fields
 (pascal void (*DoToField) (StringPtr fieldName,
  Ptr fieldAddr, short fieldType, void *link), void *link)
{DoToField(“\pTTEDocument”, nil, bClass, link);
 DoToField(“\pfPaletteView”, (Ptr) &fPaletteView, 
 bObject, link);
  DoToField(“\pfTextView”, (Ptr) &fTextView, bObject, link);
  DoToField(“\pfTextHdl”, (Ptr) &fTextHdl, bHandle, link);
 DoToField(“\pfTextColorCmd”, (Ptr) &fTextColorCmd, 
 bInteger, link);
 DoToField(“\pfShapeList”, (Ptr) &fShapeList, 
 bObject, link);
 inherited::Fields(DoToField, link); }

pascal void 
 TTEDocument::SetTextColorCmd(int theColorCmd)
{fTextColorCmd = theColorCmd; }

pascal int  TTEDocument::TextColorCmd()
{return fTextColorCmd;    }

// ---- TPaletteView ----

pascal void TPaletteView::IPaletteView
 (TTEDocument *itsTEDocument)
{VPoint itsSize;
 SetVPt(&itsSize, kPaletteWidth, kPaletteHeight);
 IView(itsTEDocument, nil, &gZeroVPt, &itsSize,
  sizeFixed, sizeFixed);
 fIconSelected = kText-kBox;  }

pascal void TPaletteView::Draw(Rect *area)
{Rect aFrame;  Point aPenSize;
 Handle aHandle;
 aHandle = GetIcon(kBoxIconID);
 PlotIcon(&gIconRect[kBox-kBox], aHandle);
 aHandle = GetIcon(kTextIconID);
 PlotIcon(&gIconRect[kText-kBox], aHandle);
 SetPt(&aPenSize, 1, 1);
 Adorn(&aFrame, aPenSize, adnLineBottom); }

pascal void TPaletteView::DoHighlightSelection
 (HLState fromHL, HLState toHL)
{Rect aRect;
 aRect = gIconRect[fIconSelected];
 InsetRect(&aRect, 1, 1);
 SetHLPenState(fromHL, toHL);

pascal struct TCommand 
 *TPaletteView::DoMouseCommand(Point *theMouse,
 EventInfo *info, Point *hysteresis)
{int  index;
 index = int(theMouse->h / kIconWidth);

 if ((index < 2) && (index != fIconSelected)) 
 { if (Focus()) { DoHighlightSelection(hlOn, hlOff); };
 fIconSelected = index;
 if (Focus()) { DoHighlightSelection(hlOff, hlOn); };
 return gNoChanges; }

#ifdef qDebug
pascal void TPaletteView::Fields
 (pascal void (*DoToField) (StringPtr fieldName,
 Ptr fieldAddr, short fieldType, void *link), void *link)
{DoToField(“\pTPaletteView”, nil, bClass, link);
 DoToField(“\pfIconSelected”, (Ptr) &fIconSelected, 
 bInteger, link);
 inherited::Fields(DoToField, link); }

pascal void 
TTextView::ITextView(TTEDocument *itsTEDocument)
{VPoint itsSize; Rect   itsInset;
 SetVPt(&itsSize, 100, 100);
 SetRect(&itsInset, 10, 8, 10, 0);
 (&aStyle, applFont, bold, 12, &gRGBBlack);
 ITEView(itsTEDocument, nil, &gZeroVPt, &itsSize, 
 sizePage, sizeFillPages, &itsInset, &aStyle, 
 teJustLeft, !kWithStyle, true); 
 fTEDocument = itsTEDocument;
 fPaletteView = itsTEDocument->fPaletteView;
 fUpdated = true; }

pascal Boolean TTextView::DoIdle(IdlePhase phase)
{if (!fUpdated)
 { if (Focus()) { DrawContents(); fUpdated = true; };
 return inherited::DoIdle(phase); }

pascal struct TCommand *TTextView::DoKeyCommand
 (short ch, short aKeyCode, EventInfo *info)
{int aQDColor;
 aQDColor = 
 fUpdated = false;
 inherited::DoKeyCommand(ch, aKeyCode, info); }

pascal void TTextView::DoSetupMenus()
{  int colorIndex, aColorCmd;
 aColorCmd = fTEDocument->TextColorCmd();
 for (colorIndex = cBlack; 
 colorIndex <= cWhite; colorIndex++)
 EnableCheck(colorIndex, TRUE, 
 (colorIndex == aColorCmd));  }

pascal struct TCommand *TTextView::DoMenuCommand
 (CmdNumber aCmdNumber)
{TColorCmd *aColorCmd;
 switch (aCmdNumber)
 { case cBlack:  case cBlue:  case cGreen: 
 case cRed: case cWhite: 
 aColorCmd = new TColorCmd;
 (aCmdNumber, fTEDocument, this);
 return aColorCmd;
 default: return inherited::DoMenuCommand
 (aCmdNumber); }

pascal struct TCommand *TTextView::DoMouseCommand
 (Point *theMouse,  EventInfo *info, Point *hysteresis)
{  TSketcher *aSketcher;
 if (fPaletteView->fIconSelected == kBox-kBox) 
 { aSketcher = new TSketcher;
 aSketcher->ISketcher(fTEDocument, this);
 return aSketcher; }
 else   return inherited::DoMouseCommand
 (theMouse,info,hysteresis); }

pascal Boolean TTextView::DoSetCursor
 (Point localPoint, RgnHandle cursorRgn)
{Rect qdExtent;
 RectRgn(cursorRgn, &qdExtent);
 if (fPaletteView->fIconSelected == kText-kBox)
 return inherited::DoSetCursor(localPoint, cursorRgn);
 else   SetCursor(*GetCursor(crossCursor));  return true;      }

pascal void DrawYourself(TBox *aBox, void *link)

pascal void TTextView::Draw(Rect *area)
{int aQDColor; void *link;
 aQDColor = 
 ForeColor(aQDColor);// set text color
 inherited::Draw(area); // let TTEView draw the text
 ForeColor(kBoxColor);  // set box color
 ForeColor(blackColor); }

#ifdef qDebug
pascal void TTextView::Fields
 (pascal void (*DoToField) (StringPtr fieldName,
  Ptr fieldAddr, short fieldType, void *link), void *link)
{DoToField(“\pTTextView”, nil, bClass, link);
 DoToField(“\pfTEDocument”, (Ptr) &fTEDocument, 
 bObject, link);
 DoToField(“\pfPaletteView”, (Ptr) &fPaletteView, 
 bObject, link);
  DoToField(“\pfUpdated”, (Ptr) &fUpdated, bBoolean, link);
 inherited::Fields(DoToField, link); }

pascal void TColorCmd::IColorCmd (int aCmdNumber, 
 TTEDocument *itsDocument, TTextView *itsView)
{TScroller *aScroller;  int oldColorCmd;
 fTextView = itsView;
 fTEDocument = itsDocument;
 aScroller = itsView->GetScroller(true);
 (aCmdNumber, itsDocument, itsView, aScroller);
 oldColorCmd = itsDocument->TextColorCmd(); 
 fOldColorCmd = oldColorCmd;
 fNewColorCmd = aCmdNumber;  }

pascal void TColorCmd::DoIt()

pascal void TColorCmd::RedoIt()  { UndoIt();  }

pascal void TColorCmd::UndoIt()
{fNewColorCmd = fOldColorCmd;
 fOldColorCmd = fTEDocument->TextColorCmd();

#ifdef qDebug
pascal void TColorCmd::Fields
 (pascal void (*DoToField) (StringPtr fieldName,
  Ptr fieldAddr, short fieldType, void *link), void *link)
{DoToField(“\pTColorCmd”, nil, bClass, link);
 DoToField(“\pfTEDocument”, (Ptr) &fTEDocument, 
 bObject, link);
  DoToField(“\pfTextView”, (Ptr) &fTextView, bObject, link);
 DoToField(“\pfOldColorCmd”, (Ptr) &fOldColorCmd, 
 bInteger, link);
 DoToField(“\pfNewColorCmd”, (Ptr) &fNewColorCmd, 
 bInteger, link);
 inherited::Fields(DoToField, link);  }

pascal void TSketcher::ISketcher
 (TTEDocument *itsDocument, TTextView *itsView)
{TScroller *aScroller;
 aScroller = itsView->GetScroller(true);
 (cDrawBox, itsDocument, itsView, aScroller);
 fTEDocument = itsDocument; fTextView = itsView;  }

pascal struct TCommand  *TSketcher::TrackMouse
 (TrackPhase aTrackPhase, VPoint *anchorPoint, 
 VPoint *previousPoint,  VPoint *nextPoint, 
 Boolean mouseDidMove)
{Rect newRect; TBox*aBox;
 if (aTrackPhase == trackRelease)
 { Pt2Rect(fTextView->ViewToQDPt(anchorPoint), 
 fTextView->ViewToQDPt(nextPoint), &newRect);
 aBox = new TBox; FailNIL(aBox);
 aBox->IBox(&newRect); fBox = aBox;
 fBoxLocation = newRect;  }
 return this;  }

pascal void TSketcher::DoIt()
 fTextView->InvalidRect(&fBoxLocation);  }

pascal void TSketcher::RedoIt()  {  DoIt();  }

pascal void TSketcher::UndoIt()
 fTextView->InvalidRect(&fBoxLocation);  }

#ifdef qDebug
pascal void TSketcher::Fields
 (pascal void (*DoToField) (StringPtr fieldName,
  Ptr fieldAddr, short fieldType, void *link), void *link)
{DoToField(“\pTSketcher”, nil, bClass, link);
 DoToField(“\pfTEDocument”, (Ptr) &fTEDocument, 
 bObject, link);
  DoToField(“\pfTextView”, (Ptr) &fTextView, bObject, link);
 DoToField(“\pfBox”, (Ptr) &fBox, bObject, link);
 DoToField(“\pfBoxLocation”, (Ptr) &fBoxLocation, 
 bRect, link);
 inherited::Fields(DoToField, link);  }

pascal void TBox::IBox(Rect *itsLocation)
 {  fLocation = *itsLocation;  }

pascal void TBox::DrawShape()
 FrameRoundRect(&fLocation, 20,20); }

pascal void TBox::NeedDiskSpace(long *data)
{data = data + sizeof(fLocation);  }

pascal void TBox::Read(short aRefNum)
{long bytes;
 bytes = sizeof(fLocation);
 FSRead(aRefNum, &bytes, (Ptr) &fLocation));  }

pascal void TBox::Write(short aRefNum)
{long bytes;
 bytes = sizeof(fLocation);
 FSWrite(aRefNum, &bytes, (Ptr) &fLocation));}

#ifdef qDebug
pascal void TBox::Fields
 (pascal void (*DoToField) (StringPtr fieldName,
  Ptr fieldAddr, short fieldType, void *link), void *link)
{DoToField(“\pTBox”, nil, bClass, link);
 DoToField(“\pfLocation”, (Ptr) &fLocation, bRect, link);
 inherited::Fields(DoToField, link); }

TTEApplication *gTEApplication;
int main()
 if (ValidateConfiguration(&gConfiguration))
 { InitUMacApp(8); InitUPrinting(); InitUTEView();
 gTEApplication = new TTEApplication;
 gTEApplication->Run();  }
 else StdAlert(phUnsupportedConfiguration);
 return 0;  }
Listing 3: TEDemo.r (Resource definitions)

#ifndef __TYPES.R__
#include “Types.r”

#ifndef __SYSTYPES.R__
#include “SysTypes.r”

#ifndef __MacAppTypes__
#include “MacAppTypes.r”

#ifndef __ViewTypes__
#include “ViewTypes.r”

#if qDebug
include “Debug.rsrc”;

include “MacApp.rsrc”;
include “Printing.rsrc”;
include “TEOther.rsrc”; 
 /* DLOG & DITL 1001; ICON 256,257; ICN# 128,129 */
include “TEDemo” ‘CODE’;

#define cHelp    1001
#define cDrawBox 2001
#define cBlack   5001
#define cBlue    5002
#define cGreen   5003
#define cRed     5004
#define cWhite   5005

#define kSignature ‘JLMT’
#define kDocFileType ‘JL01’
#define getInfoString
“©1990 J.Langowski/MacTutor. Translated from MacApp® Pascal.”

resource ‘WIND’ (1001, purgeable) {
 {50, 20, 250, 450}, zoomDocProc, invisible, goAway,
 0x0, “<<<>>>”  };

resource ‘DITL’ (201, purgeable) {
 /* About box */
  {   /* [1] */
 {130, 182, 150, 262},
 Button { enabled, “OK” };
 /* [2] */
 {10, 80, 110, 270},
 StaticText { disabled,
 “Displays text and boxes”
 “\n\nThis program was written “
 “with MacApp® © 1985-1989 Apple Computer, Inc.” };
 /* [3] */
 {10, 20, 42, 52},
 Icon { disabled, 1 }}  };

resource ‘ALRT’ (201, purgeable) {
 {90, 100, 250, 412},
 { OK, visible, silent; OK, visible, silent;
 OK, visible, silent;OK, visible, silent  }   };

resource ‘cmnu’ (1) {
 1, textMenuProc, 0x7FFFFFFB, enabled, apple,
  {   “About TEDemo ”, 
 noIcon, noKey, noMark, plain, cAboutApp;
 “Help ”, noIcon, “H”, noMark, plain, cHelp;
 “-”, noIcon, noKey, noMark, plain, nocommand } };

resource ‘cmnu’ (2) {
 2, textMenuProc, allEnabled, enabled, “File”,
  {   “New”, noIcon, “N”, noMark, plain, 10;
 “Open ”, noIcon, “O”, noMark, plain, 20;
 “-”, noIcon, noKey, noMark, plain, nocommand;
 “Close”, noIcon, noKey, noMark, plain, 31;
 “Save”, noIcon, “S”, noMark, plain, 30;
 “Save As ”, noIcon, noKey, noMark, plain, 32;
 “Save a Copy In ”, 
 noIcon, noKey, noMark, plain, 33;
 “-”, noIcon, noKey, noMark, plain, nocommand;
 “Page Setup ”, 
 noIcon, noKey, noMark, plain, 176;
 “Print One”, noIcon, “P”, noMark, plain, 177;
 “Print ”, noIcon, noKey, noMark, plain, 178;
 “-”, noIcon, noKey, noMark, plain, nocommand;
 “Quit”, noIcon, “Q”, noMark, plain, 36  }   };

resource ‘cmnu’ (3) {
 3, textMenuProc, allEnabled, enabled, “Edit”,
  {   “Undo”, noIcon, “Z”, noMark, plain, 101;
 “-”, noIcon, noKey, noMark, plain, nocommand;
 “Cut”, noIcon, “X”, noMark, plain, 103;
 “Copy”, noIcon, “C”, noMark, plain, 104;
 “Paste”, noIcon, “V”, noMark, plain, 105;
 “Clear”, noIcon, noKey, noMark, plain, 106;
 “-”, noIcon, noKey, noMark, plain, nocommand;
 “Show Clipboard”, 
 noIcon, noKey, noMark, plain, 35  }  };

resource ‘cmnu’ (4) {
 4, textMenuProc, allEnabled, enabled, “TextColor”,
  {   “Black”, noIcon, noKey, noMark, plain, cBlack;
 “Blue”, noIcon, “B”, noMark, plain, cBlue;
 “Green”, noIcon, “G”, noMark, plain, cGreen;
 “Red”, noIcon, “R”, noMark, plain, cRed;
 “White”, noIcon, noKey, noMark, outline, cWhite }

resource ‘cmnu’ (128) {
  {“Page Setup Change”, 
 noIcon, noKey, noMark, plain, cChangePrinterStyle;
 “Typing”, noIcon, noKey, noMark, plain, cTyping;
 noIcon, noKey, noMark, plain, cDrawBox }  };

resource ‘MBAR’ (128) { {1; 2; 3; 4} };

resource ‘mctb’ (128) {
 { /* Blue */
 4, 2,
 { 0x0000, 0x0000, 0xFFFF;
 0x0000, 0x0000, 0xFFFF;
 0x0000, 0x0000, 0xFFFF;
 0xFFFF, 0xFFFF, 0xFFFF };
 /* Green */
 4, 3,
 { 0x0000, 0xDB00, 0x0000;0x0000, 0xDB00, 0x0000;              
 0x0000, 0xDB00, 0x0000;  0xFFFF, 0xFFFF, 0xFFFF   };
 /* Red */
 4, 4,
 { 0xDB00, 0x0000, 0x0000;0xDB00, 0x0000, 0x0000;              
 0xDB00, 0x0000, 0x0000;  0xFFFF, 0xFFFF, 0xFFFF   }   }   };

resource ‘SIZE’ (-1) {
 saveScreen, acceptSuspendResumeEvents,
 enableOptionSwitch, canBackground,
 MultiFinderAware, backgroundAndForeground,
 dontGetFrontClicks, ignoreChildDiedEvents,
 is32BitCompatible, reserved, reserved, reserved,
 reserved, reserved, reserved, reserved,
#if qDebug
 640 * 1024, 512 * 1024
 240 * 1024, 220 * 1024

resource ‘seg!’ (256, purgeable) {
 { “GClose”; “GDoCommand”; “GNonRes”;
 “GFile”; “GOpen”; “GSelCommand”; }  };

resource ‘mem!’ (256, purgeable) {
 30 * 1024, /* Add to temporary reserve */
 0,/* Add to permanent reserve */
 0 /* Add to stack space */

/* Bundle */

type kSignature as ‘STR ‘;

resource kSignature (0) { getInfoString; };
resource ‘FREF’ (128) { ‘APPL’, 0, “TEDemo };
resource ‘FREF’ (129) { kDocFileType, 1, “TEDemo” };
resource ‘BNDL’ (128) { kSignature, 0,
 { ‘ICN#’,{ 0, 128; 1, 129 };
 ‘FREF’,{ 0, 128; 1, 129 } }   };

RESOURCE ‘vers’ (2,
#if qNames
“Package Version”,
 purgeable) { 0x02, 0x00, beta, 0x06, verUs, “2.0ß9”,
 “MacApp® 2.0ß9, ©Apple Computer, Inc. 1989” };
RESOURCE ‘vers’ (1,
#if qNames
“File Version”,
 purgeable) { 0x01,0x00,beta,0x05,verUs,”TEDemo”,
 “v 0.0, ©JL/MacTutor 1990”  };

/* debug window */
resource ‘dbug’ (kDebugParamsID,
#if qNames
 purgeable) {
 {350, 4, 474, 636}, /* Bounds rect */
 1,     /* font rsrc ID (normal = monaco) */
 9,/* font size (normal = 9) */
 100, /* Number of lines */
 100, /* Width of lines in characters */
 true,  /* open initially */
 “Jörg’s Debug Window”  /* Window title */   };
Listing 4: TEDemo.MAMake (MacApp Make file)

= TEDemo
 List resource files that the Rez file includes
OtherRsrcFiles = 
 “{MAObj}Printing.rsrc” 


Community Search:
MacTech Search:

Software Updates via MacUpdate

Posterino 3.3.6 - Create posters, collag...
Posterino offers enhanced customization and flexibility including a variety of new, stylish templates featuring grids of identical or odd-sized image boxes. You can customize the size and shape of... Read more
Together 3.8.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. Features Smart storage. With simple drag-and-drop... Read more
iClock Pro 3.4.9 - Customize your menuba...
iClock Pro is a menu bar replacement clock for Apple's default clock. iClock Pro is an update, total rewrite and improvement to the popular iClock. Have the day, date and time in different fonts and... Read more
Things 2.8.12 - Elegant personal task ma...
Things is a task management solution that helps to organize your tasks in an elegant and intuitive way. Things combines powerful features with simplicity through the use of tags and its intelligent... Read more
Typinator 7.2 - Speedy and reliable text...
Typinator turbo-charges your typing productivity. Type a little. Typinator does the rest. We've all faced projects that require repetitive typing tasks. With Typinator, you can store commonly used... Read more
Spotify - Stream music, crea...
Spotify is a streaming music service that gives you on-demand access to millions of songs. Whether you like driving rock, silky R&B, or grandiose classical music, Spotify's massive catalogue puts... Read more
beaTunes 4.6.14 - Organize your music co...
beaTunes is a full-featured music player and organizational tool for music collections. How well organized is your music library? Are your artists always spelled the same way? Any R.E.M. vs REM?... Read more
Vienna 3.1.10 :d05d7a5d: - RSS and Atom...
Vienna is a freeware and Open-Source RSS/Atom newsreader with article storage and management via a SQLite database, written in Objective-C and Cocoa, for the OS X operating system. It provides... Read more
Day One 2.1.8 - Maintain a daily journal...
Day One is the easiest and best-looking way to use a journal / diary / text-logging application for the Mac. Day One is well designed and extremely focused to encourage you to write more through... Read more
iDefrag 5.1.8 - Disk defragmentation and...
iDefrag helps defragment and optimize your disk for improved performance. Features include: Supports HFS and HFS+ (Mac OS Extended). Supports case sensitive and journaled filesystems. Supports... Read more

Latest Forum Discussions

See All

Fantasy MMORPG MU Origin adds new modes,...
MU Origin, Webzen’s highly popular fantasy MMORPG is getting ready to shake things up for the second time this year, as a new update makes its way to the Google Play and App Store from today. Introducing new systems, modes, and events, the land of... | Read more »
Blizzard is looking to hire a mobile dev...
A new thread on the popular video game rumor forum, NeoGAF, uncovered an interesting job listing over at Blizzard Entertainment. It appears the studio behindStarCraft, World of WarCraft, Hearthstone,andOverwatch is looking to bring on a new hire... | Read more »
Legend of Zelda meets Cooking Mama in ne...
Dungeon Chef is what happens when you mix the RPG elements (and style) of a Legend of Zelda game, with cooking elements. Although, now that The Legend of Zelda: Breath of the Wild also has cookingelements, so maybe the gameplay is not so novel.... | Read more »
ChordFlow (Music)
ChordFlow 1.0.0 Device: iOS Universal Category: Music Price: $6.99, Version: 1.0.0 (iTunes) Description: ChordFlow is a chord sequencer with a unique 4-track polyphonic arpeggiator, extensive chord library, MIDI out and Ableton Link... | Read more »
The Walking Dead: A New Frontier is out...
The newest season of Telltale Games'The Walking Dead is well underway. After the release of the third episode, "Above the Law" about a month ago, episode four, "Thicker Than Water" is hot and ready for more zombies and gut-wrenching emotional... | Read more »
Best games we played this week
Another week, another new wave of mobile games do dive into. We've dug through the list of apps that came out this week to tell you which apps are worth your sweet time. And while there weren't too many games this week, there were some big ones.... | Read more »
Vignettes (Games)
Vignettes 1.0.1 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0.1 (iTunes) Description: Vignettes is a casual but unique exploration game without text or characters, where objects shapeshift as you spin them around... | Read more »
Get Me Outta Here is an 80s retro shoote...
Are you ready to fight some aliens? Because Crescent Moon Games has released the retro shooter Get Me Outta Here on iOS devices today. [Read more] | Read more »
Get a bunch of Apple productivity apps f...
If you're an Apple Mac owner, you're probably aware of the host of Apple productivity apps the company includes in all new Mac purchases. Apps like iMovie, Keynote, and of course, GarageBand. While you used to be able to also buy these apps... | Read more »
Terra Mystica (Games)
Terra Mystica 1.03 Device: iOS Universal Category: Games Price: $9.99, Version: 1.03 (iTunes) Description: Short Summary:≈≈≈≈≈≈≈≈≈≈≈≈≈ | Read more »

Price Scanner via

HyperX Ships Pulsefire FPS Gaming Mouse, Winn...
Your reporter is a longtime fan of gaming mice for general purpose coomnputing use, finding them typically superior in comfort and performance. HyperX, a division of Kingston Technology Company, Inc... Read more
Penske Truck Leasing Unveils “Penske Fleet” M...
Penske Truck Leasing has introduced a free mobile app called “Penske Fleet” to benefit its full-service truck leasing and contract maintenance customers. The mobile app enables Penske’s customers to... Read more
DEVONthink To Go 2.1.3 For iOS Adds New Declu...
DEVONtechnologies has updated DEVONthink To Go, its iOS companion to DEVONthink for Mac. Enhancements and bug fixes in Version 2.1.3 include DEVONtechnologies’ new decluttering service for clipping... Read more
Use Apple’s Education discount to save up to...
Purchase a new Mac or iPad using Apple’s Education Store and take up to $300 off MSRP. All teachers, students, and staff of any educational institution qualify for the discount. Shipping is free: -... Read more
Apple refurbished Apple Watches available sta...
Apple is now offering Certified Refurbished Series 1 and Series 2 Apple Watches for 14-16% off MSRP, starting at $229. An Apple one-year warranty is included with each watch. Shipping is free: Series... Read more
15-inch Touch Bar MacBook Pros, Apple refurbi...
Apple is offering Certified Refurbished 2016 15″ Touch Bar MacBook Pros for $360 to $420 off original MSRP. An Apple one-year warranty is included with each model, and shipping is free: - 15″ 2.6GHz... Read more
13-inch MacBook Airs on sale for up to $150 o... has 13″ MacBook Airs on sale for up to $150 off MSRP including free shipping: - 13″ 1.6GHz/128GB MacBook Air (sku MMGF2LL/A): $869.99 $130 off MSRP - 13″ 1.6GHz/256GB MacBook Air (sku... Read more
15-inch Touch Bar MacBook Pros on sale for $1...
B&H Photo has the new 2016 15″ Apple Touch Bar MacBook Pros in stock today and on sale for up to $200 off MSRP. Shipping is free, and B&H charges NY sales tax only: - 15″ 2.7GHz Touch Bar... Read more
15-inch 2.7GHz Touch Bar MacBook Pros on sale...
Amazon has 2016 15″ 2.7GHz Apple Touch Bar MacBook Pros in stock today and on sale for $150-$200 off MSRP. Shipping is free: - 15″ 2.7GHz Touch Bar MacBook Pro Space Gray (sku MLH42LL/A): $2599 $200... Read more
Apple now offering Certified Refurbished 13-i...
Apple is now offering Certified Refurbished 2016 13″ Touch Bar MacBook Pros for $270-$300 off original MSRP. An Apple one-year warranty is included with each model, and shipping is free: - 13″ 2.9GHz... Read more

Jobs Board

Music Marketing Lead, iTunes & *Apple*...
# Music Marketing Lead, iTunes & Apple Music Job Number: 56868140 Culver City, California, United States Posted: Apr. 17, 2017 Weekly Hours: 40.00 **Job Summary** Read more
Best Buy *Apple* Computing Master - Best Bu...
**498001BR** **Job Title:** Best Buy Apple Computing Master **Location Number:** 000356-Manassas-Store **Job Description:** **What does a Best Buy Apple Read more
*Apple* Mac Computer Technician - GeekHampto...
…complex computer issues over the phone and in person? GeekHampton, Long Island's Apple Premium Service Provider, is looking for you! Come work with our crew Read more
*Apple* Retail - Multiple Positions - Apple,...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
Music Marketing Lead, iTunes & *Apple*...
# Music Marketing Lead, iTunes & Apple Music Job Number: 56868140 Culver City, California, United States Posted: Apr. 17, 2017 Weekly Hours: 40.00 **Job Summary** Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.