TweetFollow Us on Twitter

Linking Text
Volume Number:7
Issue Number:11
Column Tag:MacOOPs!

Related Info: TextEdit Edition Manager

Linking Text Objects

By Scott Steketee, Philadelphia, PA

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

TLinkItem: A MacApp class to link the content of text objects

“An injury to one is an injury to all.”

[Scott Steketee, a former teacher, has been programming the Apple II for many years, and is now adapting his popular GradeBook Deluxe program for the Macintosh.]

Introduction

This article presents a MacApp class which allows several TEditText or TStaticText objects to be linked, so that they always show the same contents, even while one is being edited. It also presents a subclass of TEditText which is capable of controlling such a link, and explains how to create subclasses of other objects so that they too can control and be controlled by the link. The objects which share the same text can be in the same or different windows, and there can be any number of such objects.

Macintosh applications frequently provide several different ways of viewing or changing some item of data. In a spreadsheet, for instance, the item may appear in a grid cell and in a separate formula bar where it can be edited. In a color program, the percentage of red may appear both in numeric form and as the position of a slider. In a database, the user may be entering data in a special record entry dialog, while the data appears in a second window as a row in a grid and in still another as an item in a report. In my own application (a teacher’s gradebook program), the teacher can enter information about a student in either a dialog window or a grade entry window; if both windows are open at the same time, changes in one should be immediately reflected in the other.

MacApp provides a good environment in which to construct this capability. The strength of MacApp, as an object programming system combined with a large Mac-specific class library, lies in the programmer’s ability to re-use the classes already provided, and to create new classes by modifying the existing ones. This strength shows up well here; the entire unit requires only one new class and relatively minor changes to three existing classes.

Publishers and Subscribers

For the remainder of this article, the objects that initiate the updating process by sending update information to the link are called publishers, and objects that accept and display update information from the link are called subscribers. The function of the link is to accept information from a publisher, and to forward the information to all the appropriate subscribers. Any object can function as a publisher by calling the appropriate method of the link. The present unit allows TStaticText, TEditText and TTEView objects to function as subscribers; other classes can be added by overriding the appropriate method.

A publisher which provides a visual representation of the data is usually also a subscriber, so that if any other publisher changes the data, the first publisher will get the updated information and be able to change its own visual representation of the data. On the other hand, a subscriber which only displays data and doesn’t change it will not be a publisher.

The unit ULinkItem provides the links between publishers and subscribers, and allows TEditText items to publish their data while the user is entering it. This unit allows all the subscribers to be updated each time the user changes the data, either by typing a character or by performing some other editing action. An application could provide several TEditText objects which can be used to enter data; as the data changes, the link updates the subscribing views in real time. The unit allows TEditText, TStaticText and TTEView objects to function as subscribers, with no limit to the number of subscribers which can be linked to the same item of data. (Of course, if you’re simultaneously updating a dozen objects on the screen with every character typed, things could get a little slow ) The classes that can function as subscribers can easily be extended to include your own custom classes. Such subscribers might be grids or lists showing text, or they could be objects capable of showing some other, non-text representation of the data.

Implementing the Links

One new class (TLinkItem) is defined to serve as the repository for one item of data and to keep track of the subscribers that display the data. Three other classes are modified (TEditText, TDialogView, and TDialogTEView) so that a TEditText object can function as a publisher while it is being edited. When the user edits such a TEditText object on the screen, the object publishes each change by forwarding it to the corresponding link item, which in turn forwards the change to all its subscribers.

The first object, TLinkItem, is fairly straight-forward. It requires three fields. The field fText stores the data, and fLinks is a list of all the subscribers. A third field, fUpdating, is set to TRUE whenever the item is in the process of informing its subscribers of a change. (This field is used to avoid the situation in which the link informs a subscriber of a change, and the subscriber, not knowing who sent the message, sends a message right back to inform the link that it has been changed, and the link then starts all over again informing subscribers )

There are five important methods of TLinkItem, in addition to the usual initialization, Free, and Fields methods. AddLink adds an object to the list of subscribers, and RemoveLink removes an object from the list. GetText supplies the current value of the link’s text data. SetText changes the text (usually but not necessarily as a result of the user’s typing) and initiates an update of all the subscribers. Finally, UpdatedLink sends the changed text to one single subscriber. This method knows how to update TEditText, TStaticText and TTEView objects; it must be overridden in order to allow updating of other kinds of objects.

Modifying TEditText

The rest of the unit is devoted to modifying TEditText objects so they can initiate and receive updates. It would be nice if we could modify only the TEditText class, but TEditText depends rather closely on three other classes for its behavior, and two of these three classes need to be modified.

(One of the principles of good object programming is to minimize the connections between different objects. To the extent possible, each object should stand on its own, with its methods and data as little as possible dependent on other objects. MacApp tries to meet this objective, but doesn’t succeed very well in the case of TEditText. It requires close and complex cooperation of four objects--the TEditText, a TDialogView, a TScroller, and a TDialogTEView--just to edit some text.)

The main change to TEditText itself is that SetText must check to see if it’s publishing to a TLinkItem, and if so pass the new text to the link.

TDialogTEView must also be sub-classed. This class is used in editing: when the TEditText is clicked on, a TDialogTEView is installed to handle the actual editing. Two of the methods must be overridden. First, InstallEditText is overridden so that when the view is installed in the TEditText, it is linked to the same item as the TEditText is. Second, all the changes to the text must be caught and relayed back to the TLinkItem. These changes include the typing of characters and the edit menu commands Cut, Paste and Clear. Fortunately, all these editing changes call SynchView to update the display, so SynchView is overridden so that it also updates the text in the TLinkItem.

Finally, TDialogView must also be subclassed, so that when it creates the TDialogTEView which later gets installed in the TEditText to handle editing, it creates our new-style TDialogTEView which knows how to handle links, instead of the old style that doesn’t.

The Source Code

The source code includes five files. Files ULinkItem.p and ULinkItem.inc1.p are the interface and implementation respectively for the classes described in the article. ULinkDemo.p, ULinkDemo.inc1.p, and MLinkDemo.p are the Pascal source files for a demonstration program which allows you to create a multitude of windows with linked EditText items. Finally, LinkDemo.r is the resource file for the demonstration program.

The program has been tested with MacApp 2.0 under both MPW Pascal and Think Pascal. (To run under Think Pascal, the interface and implementation of each unit must be combined into a single file using Think’s Source Converter.)

Extending the Unit

To extend this unit so that a link can forward data to other types of subscribers, you need only override the UpdatedLink procedure. This procedure checks to see if the subscriber currently being updated is one that it knows how to handle. If it is, the procedure takes whatever update action is appropriate and returns TRUE; otherwise it calls INHERITED UpdatedLink. Here is a template:

{1}

FUNCTION TMyLink.UpdatedLink
 (subscriber: TObject; theText: str255): BOOLEAN; OVERRIDE;
 { Update the subscribers we know how to do }
 { & return TRUE; Otherwise call inherited  }
 { UpdatedLink.                             }
 BEGIN
 IF Member (subscriber, TMyObject)
 THEN   { this is my type of subscriber }
 BEGIN
 { Set the text or take some other appropriate                 
 action---e.g., 
 TMyObject(subscriber).SetText (theText); }
 UpdatedLink := TRUE;
 END
 ELSE
 { this is not my type of subscriber, }
 { so find someone else to update it. }
 UpdatedLink := INHERITED UpdatedLink 
 (subscriber, theText);
 END;

If you are defining a class with the capability of subscribing to a link, it’s probably best to rely on the link to store the text data, and not to store a copy locally in the object. This finesses the problem of data integrity: the conflict in which the subscriber’s locally stored data doesn’t match the link’s data cannot arise. If there is a local copy of the data (as is the case with TEditText and TStaticText), it’s important to guarantee the integrity of the data. One approach is to make sure that any change to the local copy of the data is immediately sent to the link to be published. The other approach is to ensure that the link is the only object that ever sends new data to your object. If any other object wants to change your object’s data, it needs to do so by updating the link to which your object subscribes.

Besides being easy to extend this unit to allow it to automatically update other kinds of subscribers when the text in the TLinkItem changes, it would also be fairly easy to modify the unit so that the shared data is some other kind of information--numerical data, for instance. This would be a natural way to link a number in a text edit box with some other visual display--the position of a slider or dial, for instance.

Another possible extension to this capability of linking different items within an application is the capability of linking items from different applications. An interface between this unit and Apple’s IAC (Inter-Application Communications) facilities would be a natural. Attention, MacApp hackers! Who can give us some useful IAC capabilities?

Finally, if there’s interest, I’ll write a future column or two on a flexible approach to linking a two-dimensional view (i.e., a TGridView) with a two-dimensional data structure (a two-dimensional dynamic array based on TDynamicArray).

{2}

{=========== File ULinkItem.p ===========}
UNIT ULinkItem;
INTERFACE
USES
 UMacApp, UTEView, UDialog, UGridView,
 Fonts, ToolUtils;

TYPE
 TLinkItem = OBJECT (TObject)
 fText: StringHandle;{ the data itself }
 fLinks:TList;     { list of subscribers }
 fUpdating: BOOLEAN;
 { don’t respond to call-backs while }
 { I’m sending update messages to my }
 { subscribers.                      }
 PROCEDURE TLinkItem.ILinkItem
 (theText: str255);
 PROCEDURE TLinkItem.Free; OVERRIDE;
 FUNCTION  TLinkItem.UpdatedLink 
 (theSubscriber: TObject;
 theText: str255): BOOLEAN;
 PROCEDURE TLinkItem.SetText (theText: str255;
 thePublisher: TObject);
 PROCEDURE TLinkItem.GetText
 (VAR theText: str255);
 PROCEDURE TLinkItem.AddLink
 (theSubscriber: TObject);
 PROCEDURE TLinkItem.RemoveLink 
 (theSubscriber: TObject);
 PROCEDURE TLinkItem.Fields (
 PROCEDURE DoToField(fieldName: Str255;
 fieldAddr: Ptr;
 fieldType: INTEGER));
 OVERRIDE;
 END;
 
 TLinkEditText = OBJECT (TEditText)
 fLink: TLinkItem;
 PROCEDURE TLinkEditText.ILinkEditText
 (itsSuperView: TView;
 itsLocation, itsSize: VPoint;
 itsMaxChars: INTEGER;
 itsLink: TLinkItem);
 PROCEDURE TLinkEditText.Free; OVERRIDE;
 PROCEDURE TLinkEditText.SetText
 (theText: Str255; redraw: BOOLEAN); 
 OVERRIDE;
 PROCEDURE TLinkEditText.Fields (
 PROCEDURE DoToField(fieldName: Str255;
 fieldAddr: Ptr;
 fieldType: INTEGER));
 OVERRIDE;
 END;
 
 TLinkDialogTEView = OBJECT (TDialogTEView)
 fLink: TLinkItem;
 { the item, if any, the TEView }
 { is linked to                 }
 PROCEDURE TLinkDialogTEView.IDialogTEView 
 (itsDocument: TDocument;
 itsSuperView: TView;
 itsLocation,  itsSize: VPoint; 
 itsHDeterminer,
 itsVDeterminer: SizeDeterminer;
 itsInset: Rect;
 itsTextStyle: TextStyle; 
 itsJustification: INTEGER;
 itsStyleType, itsAutoWrap: BOOLEAN);  OVERRIDE;
 PROCEDURE TLinkDialogTEView.SynchView
 (redraw: BOOLEAN); OVERRIDE;
 PROCEDURE TLinkDialogTEView.InstallEditText 
 (theEditText: TEditText;
 selectChars: BOOLEAN); OVERRIDE;
 PROCEDURE TLinkDialogTEView.Fields(
 PROCEDURE DoToField(fieldName: Str255;
 fieldAddr: Ptr;
 fieldType: INTEGER));
 OVERRIDE;
 END;

 TLinkDialogView = OBJECT (TDialogView)
 FUNCTION TLinkDialogView.MakeTEView:
 TDialogTEView; OVERRIDE;
 PROCEDURE TLinkDialogView.Fields(
 PROCEDURE DoToField(fieldName: Str255;
 fieldAddr: Ptr;
 fieldType: INTEGER));
 OVERRIDE;
 END;
 
IMPLEMENTATION
 {$I ULinkItem.inc1.p}
END { UNIT ULinkItem }.

{======== File ULinkItem.inc1.p =========}
CONST kSizeJump = 8;
 { don’t resize the handle every time }
 { a char is added!                   }

{------------  T L i n k I t e m  ------------}
{$S LnkItmOpen}
PROCEDURE TLinkItem.ILinkItem (theText: str255);
 BEGIN
 fText := NewString (theText);
 fLinks := NewList;
 fUpdating := FALSE;
 END { TLinkItem.ILinkItem };
 
{$S LnkItmClose}
PROCEDURE TLinkItem.Free; OVERRIDE;
 BEGIN
 DisposIfHandle (fText);   { free the text }
 fLinks.Free;      { free the list items }
 INHERITED Free; { and free the object itself }
 END { TLinkItem.Free };
 
{$S LnkItmRes}
FUNCTION TLinkItem.UpdatedLink
 (theSubscriber: TObject; theText: str255):              BOOLEAN;
 { Updates the links it can & returns TRUE.    }
 { Ignores those it can’t & returns FALSE.     }
 { Override this method to provide the ability }
 { to update other types of objects.           }
 BEGIN
 UpdatedLink := TRUE;
 IF Member (theSubscriber, TStaticText) THEN
 { I know how to do static & edit texts }
 TStaticText(theSubscriber).SetText
 (theText, kRedraw)
 ELSE IF Member (theSubscriber, TTEView) THEN
 { I can also do TTEViews }
 WITH TTEView (theSubscriber) DO
 BEGIN
 SetText (theText);
 ForceRedraw;
 END
 ELSE { I don’t know how to do this object }
 UpdatedLink := FALSE;
 END { TLinkItem.UpdatedLink };

{$S LnkItmRes}
PROCEDURE TLinkItem.SetText
 (theText: str255; thePublisher: TObject);
 { Sets the text for the item and for each of }
 { the linked objects. thePublisher is the    }
 { object which originated the change; it’s   }
 { assumed to have updated itself.            }
 VAR  newSize: INTEGER;
 
 PROCEDURE FixText (theSubscriber: TObject);
 BEGIN
 IF theSubscriber <> thePublisher THEN
 IF NOT UpdatedLink (theSubscriber, theText) 
 THEN
 {$IFC qDebug}
 Writeln (‘Nobody handled link update for ‘, 
 theText);
 {$ENDC}
 END { FixText };
 
 BEGIN { TLinkItem.SetText }
 IF NOT fUpdating & (theText <> fText^^) THEN
 BEGIN
 fUpdating := TRUE;
 newSize := Length (theText) + 1;
 { need 1 extra byte for the length }
 IF Odd (newSize)
 THEN newSize := newSize + 1;
 IF GetHandleSize (Handle (fText)) < newSize
 THEN SetHandleSize (Handle (fText),
 newSize + kSizeJump);
 FailMemError;
 BlockMove (@theText, Ptr (fText^), newSize);
 fLinks.Each (FixText);
 fUpdating := FALSE;
 END;
 END { TLinkItem.SetText };
 
{$S LnkItmRes}
PROCEDURE TLinkItem.GetText (VAR theText: str255);
 BEGIN
 theText := fText^^;
 END { TLinkItem.AddLink };
 
{$S LnkItmRes}
PROCEDURE TLinkItem.AddLink(theSubscriber: TObject);
 { adds the subscriber to the list, }
 { and sends the current data back. }
 VAR theIndex: ArrayIndex;
 theText: str255;
 BEGIN
 theIndex := fLinks.GetSameItemNo 
 (theSubscriber);
 { add it only if it’s not already there! }
 IF theIndex = kEmptyIndex THEN
 BEGIN
 fLinks.InsertLast (theSubscriber);
 GetText (theText);
 IF NOT UpdatedLink (theSubscriber, theText) 
 THEN
 {$IFC qDebug}
 Writeln (
 ‘Nobody handled link update in AddLink for ‘,                 
 theText);
 {$ENDC}
 END;
 END { TLinkItem.AddLink };
 
{$S LnkItmRes}
PROCEDURE TLinkItem.RemoveLink
 (theSubscriber: TObject);
 VAR theIndex: ArrayIndex;
 BEGIN
 theIndex := fLinks.GetSameItemNo 
 (theSubscriber);
 If theIndex > kEmptyIndex
 THEN fLinks.AtDelete (theIndex);
 END { TLinkItem.RemoveLink };
 
{$S LnkItmFields}
PROCEDURE TLinkItem.Fields (
 PROCEDURE DoToField(fieldName: Str255;
 fieldAddr: Ptr;
 fieldType: INTEGER)); 
 OVERRIDE;
 BEGIN
 DoToField(‘TLinkItem’, NIL, bClass);
 DoToField(‘fText’, @fText, bString);
 DoToField(‘fLinks’, @fLinks, bObject);
 INHERITED Fields(DoToField);
 END { TLinkItem.Fields };

{------------ TLinkEditText ------------------}
{$S LnkItmOpen}
PROCEDURE TLinkEditText.ILinkEditText
 (itsSuperView: TView;
 itsLocation, itsSize: VPoint; 
 itsMaxChars: INTEGER; 
 itsLink: TLinkItem);
 VAR theText: str255;
 BEGIN
 IEditText (itsSuperView, itsLocation, itsSize, 
 itsMaxChars);
 fLink := itsLink;
 IF fLink <> NIL THEN
 fLink.AddLink (SELF);
 END { TLinkEditText.ILinkEditText };

{$S LnkItmClose}
PROCEDURE TLinkEditText.Free; OVERRIDE;
 BEGIN
 { If I’m a publisher, I may also be a   }
 { subscriber. Try to remove myself from }
 { the list of subscribers.              }
 IF fLink <> NIL THEN
 fLink.RemoveLink (SELF);
 INHERITED Free;
 END { TLinkEditText.Free };
 
{$S LnkItmRes}
PROCEDURE TLinkEditText.SetText 
 (theText: Str255;
 redraw: BOOLEAN);
 OVERRIDE;
 VAR  currentText: Str255;
 area: Rect;
 BEGIN
 IF fLink <> NIL THEN
 fLink.SetText (theText, SELF);
 INHERITED SetText(theText, redraw);
 END { TLinkEditText.SetText };

{$S LnkItmFields}
PROCEDURE TLinkEditText.Fields(
 PROCEDURE DoToField(fieldName: Str255;
 fieldAddr: Ptr;
 fieldType: INTEGER)); 
 OVERRIDE;
 BEGIN
 DoToField(‘TLinkEditText’, NIL, bClass);
 DoToField(‘fLink’, @fLink, bObject);
 INHERITED Fields(DoToField);
 END { TLinkEditText.Fields };

{------------ TLinkDialogTEView ----------------}
{$S LnkItmOpen}
PROCEDURE TLinkDialogTEView.IDialogTEView
 (itsDocument: TDocument;
 itsSuperView: TView;
 itsLocation, itsSize: VPoint;
 itsHDeterminer, 
 itsVDeterminer: SizeDeterminer;
 itsInset: Rect;
 itsTextStyle: TextStyle;
 itsJustification: INTEGER;
 itsStyleType, itsAutoWrap: BOOLEAN);  OVERRIDE;
 BEGIN
 fLink := NIL;
 INHERITED IDialogTEView (itsDocument, 
 itsSuperView, itsLocation, itsSize, 
 itsHDeterminer, itsVDeterminer, 
 itsInset, itsTextStyle, 
 itsJustification,  itsStyleType, 
 itsAutoWrap)
 END { TLinkDialogTEView.IDialogTEView };

{$S LnkItmRes}
PROCEDURE TLinkDialogTEView.SynchView
 (redraw: BOOLEAN); OVERRIDE;
 { If I’m a publisher, get & publish my text, }
 { so the link can update the other displays. }
 VAR theText:    str255;
 theTextHdl:Handle;
 nChars:INTEGER;
 BEGIN
 INHERITED SynchView (redraw);
 IF fLink <> NIL THEN
 BEGIN
 theTextHdl := ExtractText;
 nChars := Min(GetHandleSize (theTextHdl), 255);
 {$Push} {$R-}
 theText[0] := Chr (nChars);
 {$Pop}
 BlockMove (Ptr (theTextHdl^), @theText [1], 
 nChars);
 fLink.SetText (theText, SELF);
 END;
 END { TLinkDialogTEView.SynchView };
 
{$S ARes}
PROCEDURE TLinkDialogTEView.InstallEditText 
 (theEditText: TEditText;
 selectChars: BOOLEAN); OVERRIDE;
 { When I install myself in an EditText, I }
 { must use the EditText’s LinkItem as my own. }
 VAR theText: Str255;
 BEGIN
 IF fLink <> NIL THEN
 BEGIN
 fLink.RemoveLink (SELF);
 fLink := NIL;
 END;
 IF (theEditText <> NIL)
 & Member (theEditText, TLinkEditText) 
 THEN fLink := TLinkEditText 
 (theEditText).fLink;
 IF fLink <> NIL THEN
 fLink.AddLink (SELF);
 INHERITED InstallEditText
 (theEditText, selectChars);
 END { TLinkDialogTEView.InstallEditText };

{$S LnkItmFields}
PROCEDURE TLinkDialogTEView.Fields(
 PROCEDURE DoToField(fieldName: Str255;
 fieldAddr: Ptr;
 fieldType: INTEGER)); 
 OVERRIDE;
 BEGIN
 DoToField(‘TLinkDialogTEView’, NIL, bClass);
 DoToField(‘fLink’, @fLink, bObject);
 INHERITED Fields(DoToField);
 END { TLinkDialogTEView.Fields };

{------------ TLinkDialogView ----------------}
{$S LnkItmOpen}
FUNCTION TLinkDialogView.MakeTEView: TDialogTEView; OVERRIDE;
 VAR aDialogTEView:TLinkDialogTEView;
 BEGIN
 New(aDialogTEView);
 FailNIL(aDialogTEView);
 aDialogTEView.IDialogTEView (NIL, NIL,
 gZeroVPt, gZeroVPt,
 sizeRelSuperView, sizeVariable, 
 gZeroRect, gSystemStyle, teJustSystem, 
 kWithoutStyle, False);
 aDialogTEView.fMinAhead := 1;
 MakeTEView := aDialogTEView;
 END { TLinkDialogView.MakeTEView };

{$S LnkItmFields}
PROCEDURE TLinkDialogView.Fields(  
 PROCEDURE DoToField(fieldName: Str255;
 fieldAddr: Ptr;
 fieldType: INTEGER)); 
 OVERRIDE;
 BEGIN
 DoToField(‘TLinkDialogView’, NIL, bClass);
 INHERITED Fields(DoToField);
 END { TLinkDialogView.Fields };


{========== File ULinkDemo.p ============}
UNIT ULinkDemo;
INTERFACE
USES
 UMacApp, UTEView, UDialog,
 Fonts, ToolUtils, 
 ULinkItem;
TYPE
 TLinkApplication= OBJECT (TApplication)
 fItem1, fItem2: TLinkItem;
 PROCEDURE TLinkApplication.ILinkApplication
 (itsMainFileType: OSType);
 { Initializes the application and globals. }
 FUNCTION TLinkApplication.DoMenuCommand
 (aCmdNumber: CmdNumber): TCommand; 
 OVERRIDE;
 PROCEDURE TLinkApplication.DoSetupMenus; 
 OVERRIDE;
 PROCEDURE TLinkApplication.Fields(
 PROCEDURE DoToField(fieldName: Str255;
 fieldAddr: Ptr;
 fieldType: INTEGER));
 OVERRIDE;
 END;
IMPLEMENTATION
 {$I ULinkDemo.inc1.p}
END.

{======= File ULinkDemo.inc1.p ==========}
CONST
 cMakeWindow   = 1001;
{-------------- TLinkApplication ----------------}
{$S AInit}
PROCEDURE TLinkApplication.ILinkApplication 
 (itsMainFileType: OSType);
 VAR anItem: TLinkItem;
 BEGIN
 gAlwaysTrackCursor := TRUE;
 IApplication(itsMainFileType);
 { Suppress creation of new document at launch }
 fLaunchWithNewDocument := FALSE;
 NEW (anItem);
 FailNIL (anItem);
 fItem1 := anItem;
 fItem1.ILinkItem (‘an Item’);
 NEW (anItem);
 FailNIL (anItem);
 fItem2 := anItem;
 fItem2.ILinkItem (‘another Item’);
 END;

{$S ASelCommand}
FUNCTION TLinkApplication.DoMenuCommand
 (aCmdNumber: CmdNumber): TCommand;

 PROCEDURE MakeWindow;
 VAR  itsLocation: VPoint;
 itsSize: VPoint;
 ts: TextStyle;
 aWindow: TWindow;
 aDialogView: TLinkDialogView;
 anEditView: TLinkEditText;
 BEGIN
 NEW(aDialogView);
 FailNIL(aDialogView);
 SetVPt(itsSize, 250, 130);
 aDialogView.IDialogView(NIL, NIL, gZeroVPt, 
 itsSize, SizeFixed, SizeFixed,
 kNoIdentifier, kNoIdentifier);

 aWindow := NewSimpleWindow (aCmdNumber, 
 TRUE, TRUE, NIL, aDialogView);
 aWindow.fFreeOnClosing := TRUE;
 aWindow.SimpleStagger(kStdStaggerAmount, 
 kStdStaggerAmount, gStdStaggerCount);

 { make two edit texts linked to item1 }
 NEW(anEditView);
 FailNIL(anEditView);
 SetVPt(itsLocation, 10, 20);
 SetVPt(itsSize, 100, 22);
 anEditView.ILinkEditText(aDialogView, 
 itsLocation, itsSize, 255, fItem1);
 SetTextStyle(ts, applFont, [], 12, gRGBBlack);
 anEditView.InstallTextStyle(ts, kDontRedraw);
 anEditView.SetJustification(teJustSystem, 
 kDontRedraw);

 NEW(anEditView);
 FailNIL(anEditView);
 SetVPt(itsLocation, 120, 20);
 SetVPt(itsSize, 100, 22);
 anEditView.ILinkEditText(aDialogView, 
 itsLocation, itsSize, 255, fItem1);
 SetTextStyle(ts, applFont, [], 12, gRGBBlack);
 anEditView.InstallTextStyle(ts, kDontRedraw);
 anEditView.SetJustification(teJustRight, kDontRedraw);

 { make an edit text linked to item2 }
 NEW(anEditView);
 FailNIL(anEditView);
 SetVPt(itsLocation, 120, 60);
 SetVPt(itsSize, 100, 22);
 anEditView.ILinkEditText(aDialogView, 
 itsLocation, itsSize, 255, fItem2);
 SetTextStyle(ts, applFont, [], 12, gRGBBlack);
 anEditView.InstallTextStyle(ts, kDontRedraw);
 anEditView.SetJustification(teJustSystem, 
 kDontRedraw);
 
 { make a fourth, unlinked EditText }
 NEW(anEditView);
 FailNIL(anEditView);
 SetVPt(itsLocation, 120, 100);
 SetVPt(itsSize, 100, 22);
 anEditView.ILinkEditText(aDialogView, 
 itsLocation, itsSize, 255, NIL);
 SetTextStyle(ts, applFont, [], 12, gRGBBlack);
 anEditView.InstallTextStyle(ts, kDontRedraw);
 anEditView.SetJustification(teJustRight, 
 kDontRedraw);
 anEditView.SetText(‘unlinked’, kDontRedraw);
 
 aWindow.Open;
 END { MakeWindow };

 BEGIN { DoMenuCommand }
 DoMenuCommand := NIL;
 CASE aCmdNumber OF
 cMakeWindow:  MakeWindow;
 OTHERWISEDoMenuCommand := 
 INHERITED DoMenuCommand(aCmdNumber);
 END { CASE };
 END { DoMenuCommand };


{$S ARes}
PROCEDURE TLinkApplication.DoSetupMenus; 
 OVERRIDE;
 BEGIN
 INHERITED DoSetupMenus;
 Enable(cMakeWindow, TRUE);
 END;

{$S AFields}
PROCEDURE TLinkApplication.Fields( 
 PROCEDURE DoToField(fieldName: Str255;
 fieldAddr: Ptr;
 fieldType: INTEGER)); 
 OVERRIDE;
 BEGIN
 DoToField(‘TLinkApplication’, NIL, bClass);
 INHERITED Fields(DoToField);
 END { TLinkApplication.Fields };

{========== File MLinkDemo.p ============}
PROGRAM LinkDemo;
  {$MC68020-}  
  {$MC68881-}
 { The main program must be universal code }
 USES
 UMacApp, UTEView, UDialog,
 ULinkItem, ULinkDemo;
 VAR
 gLinkApplication: TLinkApplication; BEGIN
 InitToolBox;
 IF ValidateConfiguration(gConfiguration) THEN     
 { Make sure we can run }
 BEGIN
 { Continue with remainder of initialization }
 InitUMacApp(8);
 InitUTEView;
 InitUDialog;

 New(gLinkApplication);
 FailNil(gLinkApplication);
 gLinkApplication.ILinkApplication (‘????’);       gLinkApplication.Run;
 END
 ELSE
 StdAlert(phUnsupportedConfiguration);
 END.

{========== File LinkDemo.r ============}
/* Note: .rsrc files have been changed to .r.o, */
/* as per Tech Note #280. */
#ifndef __TYPES.R__
#include “Types.r”
#endif

#ifndef __MacAppTypes__
#include “MacAppTypes.r”
#endif

#if qTemplateViews
#ifndef __ViewTypes__
#include “ViewTypes.r”
#endif
#endif

#if qDebug
include “Debug.r.o”;
#endif
include “MacApp.r.o”;
include “Dialog.r.o”;

include $$Shell(“ObjApp”)”LinkDemo” ‘CODE’;

/* Command numbers */
#define cNewWindow 1001

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

resource ‘SIZE’ (-1) {
 dontSaveScreen,
 acceptSuspendResumeEvents,
 enableOptionSwitch,
 canBackground,
 MultiFinderAware,
 backgroundAndForeground,
 dontGetFrontClicks,
 ignoreChildDiedEvents,
 is32BitCompatible,
 reserved, reserved, reserved, reserved, 
 reserved, reserved, reserved,
#if qDebug
 500 * 1024, 400 * 1024
#else
 290 * 1024, 218 * 1024
#endif
};

resource ‘DITL’ (phAboutApp, purgeable) {
  {
/* [1] */ {160, 182, 180, 262}, Button { enabled, “OK” };
/* [2] */ {8, 70, 152, 316}, StaticText { disabled, 
 “This program demonstrates simultaneous updating of several TextEdits.” 

 “\n\nThis program was written for MacTutor by Scott Steketee “
 “with MacApp® © 1985-1990 Apple Computer, Inc.”};
/* [3] */ {10, 20, 42, 52}, Icon { disabled, 1 }
 }
};

resource ‘ALRT’ (1000, purgeable) {
 {44, 48, 130, 358},
 1000,
 { OK, visible, sound1,
 OK, visible, sound1,
 OK, visible, sound1,
 OK, visible, sound1
 }
};

include “Defaults.r.o”  ‘ALRT’ (phAboutApp); // Grab the default about 
box

include “Defaults.r.o” ‘cmnu’ (mApple);// Grab the default Apple menu

resource ‘cmnu’ (mFile) {
 mFile,
 textMenuProc,
 0x7FFFFBBB,
 enabled,
 “File”,
  { “Quit”, noIcon, “Q”,  noMark, plain, cQuit }
};

include “Defaults.r.o” ‘cmnu’ (mEdit); // Grab the default Edit menus

resource ‘cmnu’ (4) {
 4,
 textMenuProc,
 0x7FFFFFBD,
 enabled,
 “LinkDemo”,
  {“New Window”, noIcon, noKey, noMark, plain, cNewWindow;}
};

include “Defaults.r.o” ‘cmnu’ (mBuzzwords);  // Get the default buzzwords 
menu


resource ‘MBAR’ (kMBarDisplayed) { 
 {mApple; mFile; mEdit; 4} };

/***********************************/
/* Views by procedure      */
/***********************************/
resource ‘WIND’ (cNewWindow, purgeable) {
 {50, 20, 200, 300}, zoomDocProc, invisible, goAway, 0x0, “Window”
};

type ‘SS11’ as ‘STR ‘;
resource ‘SS11’ (0,
#if qNames
“Signature”,
#endif
 purgeable) {
 “Application created by MacApp®”
};

resource ‘BNDL’ (128,
#if qNames
“Bundle”,
#endif
 purgeable) {
 ‘SS11’,
 0,
 { ‘ICN#’,
 { 0, 128, },
 ‘FREF’,
 { 0, 128, }
 }
};

include “Defaults.r.o”  ‘STR#’ (kDefaultCredits);        // Grab the 
default credits

// Get the default MacApp® application icon and necessary bundling rsrcs
include “Defaults.r.o”  ‘FREF’ (128);
include “Defaults.r.o”  ‘ICN#’ (128);

// Get the default Version resources
include “Defaults.r.o”  ‘vers’ (1);
 // Application or file specific
include “Defaults.r.o”  ‘vers’ (2);
 // Overall package
 
AAPL
$100.96
Apple Inc.
-0.83
MSFT
$47.52
Microsoft Corpora
+0.84
GOOG
$596.08
Google Inc.
+6.81

MacTech Search:
Community Search:

Software Updates via MacUpdate

Audio Hijack Pro 2.11.3 - Record and enh...
Audio Hijack Pro drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio with Audio Hijack... Read more
Airfoil 4.8.9 - Send audio from any app...
Airfoil allows you to send any audio to AirPort Express units, Apple TVs, and even other Macs and PCs, all in sync! It's your audio - everywhere. With Airfoil you can take audio from any... Read more
WhatRoute 1.13.0 - Geographically trace...
WhatRoute is designed to find the names of all the routers an IP packet passes through on its way from your Mac to a destination host. It also measures the round-trip time from your Mac to the... Read more
Chromium 37.0.2062.122 - Fast and stable...
Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all Internet users to experience the web. FreeSMUG-Free OpenSource Mac User Group build is... Read more
Attachment Tamer 3.1.14b9 - Take control...
Attachment Tamer gives you control over attachment handling in Apple Mail. It fixes the most annoying Apple Mail flaws, ensures compatibility with other email software, and allows you to set up how... Read more
Duplicate Annihilator 5.0 - Find and del...
Duplicate Annihilator takes on the time-consuming task of comparing the images in your iPhoto library using effective algorithms to make sure that no duplicate escapes. Duplicate Annihilator detects... Read more
jAlbum Pro 12.2 - Organize your digital...
jAlbum Pro has all the features you love in jAlbum, but comes with a commercial license. With jAlbum, you can create gorgeous custom photo galleries for the Web without writing a line of code!... Read more
jAlbum 12.2 - Create custom photo galler...
With jAlbum, you can create gorgeous custom photo galleries for the Web without writing a line of code! Beginner-friendly, with pro results Simply drag and drop photos into groups, choose a design... Read more
Quicken 2015 2.0.4 - Complete personal f...
Quicken 2015 helps you manage all your personal finances in one place, so you can see where you're spending and where you can save. Quicken automatically categorizes your financial transactions,... Read more
iMazing 1.0 - Complete iOS device manage...
iMazing (formerly DiskAid) is the ultimate iOS device manager with capabilities far beyond what iTunes offers. With iMazing and your iOS device (iPhone, iPad, or iPod), you can: Copy music to and... Read more

Latest Forum Discussions

See All

View Source – HTML, JavaScript and CSS...
View Source – HTML, JavaScript and CSS 1.0 Device: iOS Universal Category: Utilities Price: $.99, Version: 1.0 (iTunes) Description: View Source is an app plus an iOS 8 Safari extension that makes it easy to do one key web developer... | Read more »
Avenged Sevenfold’s Hail To The King: De...
Avenged Sevenfold’s Hail To The King: Deathbat is Coming to iOS on October 16th Posted by Jessica Fisher on September 19th, 2014 [ permalink ] Just in time for Halloween, on October 16 Avenged Sevenfold will be launching | Read more »
Talisman Has Gone Universal – Can Now be...
Talisman Has Gone Universal – Can Now be Played on the iPhone Posted by Jessica Fisher on September 19th, 2014 [ permalink ] | Read more »
Tap Army Review
Tap Army Review By Jennifer Allen on September 19th, 2014 Our Rating: :: SHOOT EM ALLUniversal App - Designed for iPhone and iPad Mindless but fun, Tap Army is a lane-based shooter that should help you relieve some stress.   | Read more »
Monsters! Volcanoes! Loot! Epic Island f...
Monsters! Volcanoes! Loot! | Read more »
Plunder Pirates: Tips, Tricks, Strategie...
Ahoy There, Seadogs: Interested in knowing our thoughts on all this plundering and pirating? Check out our Plunder Pirates Review! Have you just downloaded the rather enjoyable pirate-em-up Plunder Pirates and are in need of some assistance? Never... | Read more »
Goat Simulator Review
Goat Simulator Review By Lee Hamlet on September 19th, 2014 Our Rating: :: THE GRUFFEST OF BILLY GOATSUniversal App - Designed for iPhone and iPad Unleash chaos as a grumpy goat in this humorous but short-lived casual game.   | Read more »
A New and Improved Wunderlist is Here fo...
A New and Improved Wunderlist is Here for iOS 8 Posted by Jessica Fisher on September 19th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Evernote Update for iOS 8 Adds Web Clipp...
Evernote Update for iOS 8 Adds Web Clipping, Quick Notes, and More Posted by Ellis Spice on September 19th, 2014 [ permalink ] | Read more »
Apple Names Ultimate Productivity Bundl...
Apple Names Ultimate Productivity Bundle by Readdle as the Essential Bundle on the App Store Posted by Jessica Fisher on September 19th, 2014 [ permalink | Read more »

Price Scanner via MacPrices.net

iFixIt Tears Down iPhone 6; Awards Respectabl...
iFixit notes that even the smaller 4.7″ iPhone 6 is a giant among iPhones; so big that Apple couldn’t fit it into the familiar iPhone form factor. In a welcome reversal of a recent trend to more or... Read more
Phone 6 Guide – Tips Book For Both iPhone 6...
iOS Guides has announced its latest eBook: iPhone 6 Guide. Brought to you by the expert team at iOS Guides, and written by best-selling technology author Tom Rudderham, iPhone 6 Guide is packed with... Read more
How to Upgrade iPhone iPad to iOS 8 without D...
PhoneClean, a iPhone cleaner utility offered by iMobie Inc., reveals a solution for upgrading iPhone and iPad to iOS 8 without deleting photos, apps, the new U2 album or anything. Thanks to more than... Read more
Updated Price Trackers
We’ve updated our Mac Price Trackers with the latest information on prices, bundles, and availability on systems from Apple’s authorized internet/catalog resellers: - 15″ MacBook Pros - 13″ MacBook... Read more
Mac Pros available for up to $260 off MSRP
Adorama has Mac Pros on sale for up to $260 off MSRP. Shipping is free, and Adorama charges sales tax in NY & NJ only: - 4-core Mac Pro: $2839.99, $160 off MSRP - 6-core Mac Pro: $3739.99, $260... Read more
13-inch 2.6GHz/256GB Retina MacBook Pros avai...
B&H Photo has the 13″ 2.6GHz/256GB Retina MacBook Pro on sale for $1379 including free shipping plus NY sales tax only. Their price is $120 off MSRP. Read more
Previous-generation 15-inch 2.0GHz Retina Mac...
B&H Photo has leftover previous-generation 15″ 2.0GHz Retina MacBook Pros now available for $1599 including free shipping plus NY sales tax only. Their price is $400 off original MSRP. B&H... Read more
21″ 2.7GHz iMac available for $1179, save $12...
Adorama has 21″ 2.7GHz Hawell iMacs on sale for $1179.99 including free shipping. Their price is $120 off MSRP. NY and NJ sales tax only. Read more
iOS 8 Adoption Rate Slower than iOS 7, 6, Hit...
Apple began pushing out iOS 8 updates to eligible devices around 1pm ET on September 17, 2014. However, unlike with iOS 7, which boasted a wide variety of differences from its predecessor iOS 6, in... Read more
LIkely Final Definitive OS X 10.9.5 Mavericks...
Apple has released what will almost certainly be the last incremental version number update of OS X 10.9 Mavericks (save for futire security updates) before OS X 10.10 Yosemite is released next month... Read more

Jobs Board

Position Opening at *Apple* - Apple (United...
**Job Summary** The Apple Store is a retail environment like no other - uniquely focused on delivering amazing customer experiences. As an Expert, you introduce people Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** As businesses discover the power of Apple computers and mobile devices, it's your job - as a Solutions Engineer - to show them how to introduce these Read more
Position Opening at *Apple* - Apple (United...
…Summary** As a Specialist, you help create the energy and excitement around Apple products, providing the right solutions and getting products into customers' hands. You 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, *Apple* Financial Services...
**Job Summary** Apple Financial Services (AFS) offers consumers, businesses and educational institutions ways to finance Apple purchases. We work with national and Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.