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
 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Combo Quest (Games)
Combo Quest 1.0 Device: iOS Universal Category: Games Price: $.99, Version: 1.0 (iTunes) Description: Combo Quest is an epic, time tap role-playing adventure. In this unique masterpiece, you are a knight on a heroic quest to retrieve... | Read more »
Hero Emblems (Games)
Hero Emblems 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: ** 25% OFF for a limited time to celebrate the release ** ** Note for iPhone 6 user: If it doesn't run fullscreen on your device... | Read more »
Puzzle Blitz (Games)
Puzzle Blitz 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Puzzle Blitz is a frantic puzzle solving race against the clock! Solve as many puzzles as you can, before time runs out! You have... | Read more »
Sky Patrol (Games)
Sky Patrol 1.0.1 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0.1 (iTunes) Description: 'Strategic Twist On The Classic Shooter Genre' - Indie Game Mag... | Read more »
The Princess Bride - The Official Game...
The Princess Bride - The Official Game 1.1 Device: iOS Universal Category: Games Price: $3.99, Version: 1.1 (iTunes) Description: An epic game based on the beloved classic movie? Inconceivable! Play the world of The Princess Bride... | Read more »
Frozen Synapse (Games)
Frozen Synapse 1.0 Device: iOS iPhone Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Frozen Synapse is a multi-award-winning tactical game. (Full cross-play with desktop and tablet versions) 9/10 Edge 9/10 Eurogamer... | Read more »
Space Marshals (Games)
Space Marshals 1.0.1 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0.1 (iTunes) Description: ### IMPORTANT ### Please note that iPhone 4 is not supported. Space Marshals is a Sci-fi Wild West adventure taking place... | Read more »
Battle Slimes (Games)
Battle Slimes 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: BATTLE SLIMES is a fun local multiplayer game. Control speedy & bouncy slime blobs as you compete with friends and family.... | Read more »
Spectrum - 3D Avenue (Games)
Spectrum - 3D Avenue 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: "Spectrum is a pretty cool take on twitchy/reaction-based gameplay with enough complexity and style to stand out from the... | Read more »
Drop Wizard (Games)
Drop Wizard 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Bring back the joy of arcade games! Drop Wizard is an action arcade game where you play as Teo, a wizard on a quest to save his... | Read more »

Price Scanner via MacPrices.net

Apple’s M4 Mac minis on sale for record-low p...
B&H Photo has M4 and M4 Pro Mac minis in stock and on sale right now for up to $150 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses. Prices start at only $469: – M4... Read more
Deal Alert! Mac Studio with M4 Max CPU on sal...
B&H Photo has the standard-configuration Mac Studio model with Apple’s M4 Max CPU in stock today and on sale for $300 off MSRP, now $1699 (10-Core CPU and 32GB RAM/512GB SSD). B&H also... Read more

Jobs Board

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