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
$96.93
Apple Inc.
-0.26
MSFT
$44.54
Microsoft Corpora
-0.33
GOOG
$595.42
Google Inc.
-0.56

MacTech Search:
Community Search:

Software Updates via MacUpdate

Airfoil 4.8.7 - 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
Microsoft Remote Desktop 8.0.8 - Connect...
With Microsoft Remote Desktop, you can connect to a remote PC and your work resources from almost anywhere. Experience the power of Windows with RemoteFX in a Remote Desktop client designed to help... Read more
xACT 2.30 - Audio compression toolkit. (...
xACT stands for X Aaudio Compression Toolkit, an application that encodes and decodes FLAC, SHN, Monkey’s Audio, TTA, Wavpack, and Apple Lossless files. It also can encode these formats to MP3, AAC... Read more
Firefox 31.0 - Fast, safe Web browser. (...
Firefox for Mac offers a fast, safe Web browsing experience. Browse quickly, securely, and effortlessly. With its industry-leading features, Firefox is the choice of Web development professionals... Read more
Little Snitch 3.3.3 - Alerts you to outg...
Little Snitch gives you control over your private outgoing data. Track background activityAs soon as your computer connects to the Internet, applications often have permission to send any... Read more
Thunderbird 31.0 - Email client from Moz...
As of July 2012, Thunderbird has transitioned to a new governance model, with new features being developed by the broader free software and open source community, and security fixes and improvements... Read more
Together 3.2 - Store and organize all of...
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
Cyberduck 4.5 - FTP and SFTP browser. (F...
Cyberduck is a robust FTP/FTP-TLS/SFTP browser for the Mac whose lack of visual clutter and cleverly intuitive features make it easy to use. Support for external editors and system technologies such... Read more
iExplorer 3.4 - View and transfer all th...
iExplorer is an iPhone browser for Mac lets you view the files on your iOS device. By using a drag and drop interface, you can quickly copy files and folders between your Mac and your iPhone or... Read more
Airmail 1.4 - Powerful, minimal email cl...
Airmail is a powerful, minimal mail client.It was designed to retain the same experience with a single or multiple accounts and provide a quick, modern and easy-to-use user experience. Airmail... Read more

Latest Forum Discussions

See All

More Paintings Have Been Added to Paint...
More Paintings Have Been Added to Paint it Back! Posted by Jessica Fisher on July 24th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
The Order of Souls Review
The Order of Souls Review By Campbell Bird on July 24th, 2014 Our Rating: :: STORY GRINDUniversal App - Designed for iPhone and iPad The Order of Souls is a free-to-play, turn-based RPG with a genre-mixing art style, interesting... | Read more »
Revolution 60 Review
Revolution 60 Review By Jordan Minor on July 24th, 2014 Our Rating: :: LASS EFFECTUniversal App - Designed for iPhone and iPad Revolution 60 is a bold, cinematic action game with ambition to spare.   | Read more »
Matter (Photography)
Matter 1.0.1 Device: iOS Universal Category: Photography Price: $1.99, Version: 1.0.1 (iTunes) Description: Add stunning 3D effects to your photos with real-time shadows and reflections. Export your creations as photos or video loops... | Read more »
Fanatic Earth Review
Fanatic Earth Review By Brittany Vincent on July 24th, 2014 Our Rating: :: BY-THE-NUMBERSUniversal App - Designed for iPhone and iPad Kemco’s stable of mobile RPGs grows, but in Fanatic Earth’s situation it’s a case of quantity... | Read more »
Together for iOS (Productivity)
Together for iOS 1.0 Device: iOS Universal Category: Productivity Price: $9.99, Version: 1.0 (iTunes) Description: Together is an app for keeping things in one place. Notes, documents, images, movies, sounds, web pages and bookmarks... | Read more »
The Phantom PI Mission Apparition (Game...
The Phantom PI Mission Apparition 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: ** Release sale! 50% off for a limited time! ** The Phantom PI Mission Apparition is a spooky, puzzly, rock’... | Read more »
The Great Prank War (Games)
The Great Prank War 1.0.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0.0 (iTunes) Description: Help Mordecai, Rigby, Muscle Man and Skips take the park back from Gene and his goons with a plethora of prank-related... | Read more »
Teenage Mutant Ninja Turtles (Games)
Teenage Mutant Ninja Turtles 1.0.0 Device: iOS Universal Category: Games Price: $3.99, Version: 1.0.0 (iTunes) Description: Download the all new Teenage Mutant Ninja Turtles Official Movie Game! | Read more »
Dream Revenant (Games)
Dream Revenant 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: EXCLUSIVE LAUNCH PRICE ! Dream Revenant is at $1.99 for a limited time ! | Read more »

Price Scanner via MacPrices.net

What Should Apple’s Next MacBook Priority Be;...
Stabley Times’ Phil Moore says that after expanding its iMac lineup with a new low end model, Apple’s next Mac hardware decision will be how it wants to approach expanding its MacBook lineup as well... Read more
ArtRage For iPhone Painting App Free During C...
ArtRage for iPhone is currently being offered for free (regularly $1.99) during Comic-Con San Diego #SDCC, July 24-27, in celebration of the upcoming ArtRage 4.5 and other 64-bit versions of the... Read more
With The Apple/IBM Alliance, Is The iPad Now...
Almost since the iPad was rolled out in 2010, and especially after Apple made a 128 GB storage configuration available in 2012, there’s been debate over whether the iPad is a serious tool for... Read more
MacBook Airs on sale starting at $799, free s...
B&H Photo has the new 2014 MacBook Airs on sale for up to $100 off MSRP for a limited time. Shipping is free, and B&H charges NY sales tax only. They also include free copies of Parallels... Read more
Apple 27″ Thunderbolt Display (refurbished) a...
The Apple Store has Apple Certified Refurbished 27″ Thunderbolt Displays available for $799 including free shipping. That’s $200 off the cost of new models. Read more
WaterField Designs Unveils Cycling Ride Pouch...
High end computer case and bag maker WaterField Designs of San Francisco now enters the cycling market with the introduction of the Cycling Ride Pouch – an upscale toolkit with a scratch-free iPhone... Read more
Kingston Digital Ships Large Capacity Near 1T...
Kingston Digital, Inc., the Flash memory affiliate of Kingston Technology Company, Inc.,has announced its latest addition to the SSDNow V300 series, the V310. The Kingston SSDNow V310 solid-state... Read more
Apple’s Fiscal Third Quarter Results; Record...
Apple has announced financial results for its fiscal 2014 third quarter ended June 28, 2014, racking up quarterly revenue of $37.4 billion and quarterly net profit of $7.7 billion, or $1.28 per... Read more
15-inch 2.0GHz MacBook Pro Retina on sale for...
B&H Photo has the 15″ 2.0GHz Retina MacBook Pro on sale for $1829 including free shipping plus NY sales tax only. Their price is $170 off MSRP. B&H will also include free copies of Parallels... Read more
Apple restocks refurbished Mac minis for up t...
The Apple Store has restocked Apple Certified Refurbished Mac minis for up to $150 off the cost of new models. Apple’s one-year warranty is included with each mini, and shipping is free: - 2.5GHz Mac... Read more

Jobs Board

Sr Software Lead Engineer, *Apple* Online S...
Sr Software Lead Engineer, Apple Online Store Publishing Systems Keywords: Company: Apple Job Code: E3PCAK8MgYYkw Location (City or ZIP): Santa Clara Status: Full Read more
Senior Interaction Designer, *Apple* Online...
**Job Summary** Apple is looking for a hands on Senior…will be a key player in designing for the Apple Online Store. The ideal designer will have a Read more
*Apple* Sales Chat Rep - Apple (United State...
…is looking for motivated, outgoing, and tech savvy individuals who want to offer Apple Customers an unparalleled customer experience over chat. At Apple , we believe Read more
Mac Expert - *Apple* Online Store Mexico -...
…MUST be fluent in English and Spanish to be considered for this position At Apple , we believe that hard work, a fun environment, creativity and innovation fuel the Read more
*Apple* Industrial Design CAD Sculptor - App...
**Job Summary** The Apple Industrial Design team is looking for a CAD sculptor/Digital 3D modeler to create high quality CAD models used in the industrial design process Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.