home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 5.6 KB | 183 lines | [TEXT/MPS ] |
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-,d-]}
- { Copyright © 1986-1990 Apple Computer, Inc. All rights reserved. }
- (*=============================================================================
- | Tabs for TE Views.
- | by Steve Friedrich
- | Adapted from code generously supplied by Tom Dowdy @ Apple
- |
- | KNOWN LIMITATIONS
- | • only works for styled text but not with styles
- | • slow on full recalcs when linewrap is true
- | • won't print
- | • !!! STILL _VERY_ EXPERIMENTAL AND UNSUPPORTED !!!
- | • tabs only work for left justified text
- |
- | T H E O R Y O F O P E R A T I O N
- | This UNIT supports Tabs in TextEdit by providing a mechanism for the TE proc's
- | to call back into the object. This mechanism operates as follows - the refCon
- | field of the TERec is stuffed with the handle to the object (ie SELF). When
- | the TE proc's get control, they use this handle to access the object and thus
- | call back into the object.
- |
- | TO USE THIS UNIT WITH DemoText sample, make the following changes:
-
- 1) DemoText.MAMake - modify these settings accordingly:
- BuildingBlockIntf = ∂
- "{MAPInterfaces}UPrinting.p" ∂
- "{MAPInterfaces}UTEView.p" ∂
- "{SrcApp}UTabTEView.p"
- OtherInterfaces = ∂
- "{SrcApp}UTEDocument.p" ∂
- "{SrcApp}UTabTEView.p"
- OtherLinkFiles = ∂
- "{ObjApp}UTEDocument.p.o" ∂
- "{ObjApp}UTabTEView.p.o" ∂
- "{ObjApp}UTabTEView.a.o"
- "{ObjApp}UTabTEView.p.o" ƒ ∂
- "{SrcApp}UTabTEView.inc1.p" ∂
- {MacAppIntf} ∂
- {BuildingBlocksIntf}
-
- 2) MDemoText.p
- a) add UTabTEView to the USES clause, after UTEView,
- b) call InitUTabTEView instead of InitUTEView.
-
- 3) DemoText.r
- in 'view' resource kViewRsrcID, specify the class for the TEView
- as "TTabTEView" (it is set to "" in DemoText).
-
- *)
-
- UNIT UTabTEView;
-
- INTERFACE
-
- USES
- { • MacApp }
- UMacApp, UTEView,
-
- { • Implementation use }
- ToolUtils, Fonts, FixMath, Script, Errors;
-
- CONST
- { pretty pictures for "ShowInvisibles" }
- kVisibleTAB = 'Δ';
- kVisibleSpace = '◊';
- kVisibleCR = '¬';
-
- kDefaultTabSize = 24; { the default tab size in pixels }
-
- cIncTabs = 1410;
- cDecTabs = 1411;
- cShowInvs = 1412;
-
- TYPE
- OldTEHooksRec = RECORD { routines that can be hooked in TE }
- DrawHook: ProcPtr;
- WidthHook: ProcPtr;
- HitTestHook: ProcPtr;
- EOLHook: ProcPtr;
- END;
-
- TTabTEView = OBJECT (TTEView)
- fTabSize: integer;
- fShowInvisibles: Boolean;
- fOldCQDProcs: CQDProcs; { currently effective grafprocs }
- fHookedCQDProcsPtr: CQDProcsPtr; { Points to a hooked version of currently
- effective grafprocs. }
-
- fOldTEHooksRec: OldTEHooksRec; { previous hooks returned by TECustomHook }
-
- PROCEDURE TTabTEView.IRes(itsDocument: TDocument;
- itsSuperView: TView;
- VAR itsParams: Ptr); OVERRIDE;
- PROCEDURE TTabTEView.BeInPort(itsPort: GrafPtr); OVERRIDE;
-
- PROCEDURE TTabTEView.SetTabSize(newSize: integer;
- redraw: Boolean);
- PROCEDURE TTabTEView.ShowInvisibles(showEm: Boolean;
- redraw: Boolean);
- FUNCTION TTabTEView.TETextLength(theText: Ptr;
- theLength: integer;
- theWidthBefore: integer;
- VAR numer: Point;
- VAR denom: Point;
- VAR info: FontInfo): integer;
- FUNCTION TTabTEView.DoMouseCommand(VAR theMouse: Point;
- VAR info: EventInfo;
- VAR hysteresis: Point): TCommand; OVERRIDE;
- PROCEDURE TTabTEView.DoSetupMenus; OVERRIDE;
- FUNCTION TTabTEView.DoMenuCommand(aCmdNumber: CmdNumber): TCommand; OVERRIDE;
- PROCEDURE TTabTEView.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: integer)); OVERRIDE;
- FUNCTION TTabTEView.TETxMeas(theLength: integer;
- theText: Ptr;
- VAR numer: Point;
- VAR denom: Point;
- VAR info: FontInfo): integer;
- PROCEDURE TTabTEView.TEDrawText(theLength: integer;
- theText: Ptr;
- numer: Point;
- denom: Point);
- PROCEDURE TTabTEView.WithHookedGrafProcsDo(PROCEDURE whatToDo);
- END;
-
- TSetTabCommand = OBJECT (TCommand)
- fOldTabSetting, fNewTabSetting: integer;
- PROCEDURE TSetTabCommand.ISetTabCommand(itsView: TView;
- itsCmdNumber: CmdNumber;
- tabSetting: integer);
- PROCEDURE TSetTabCommand.DoIt; OVERRIDE;
- { sets new tabs, then calls ForceRedraw }
-
- PROCEDURE TSetTabCommand.RedoIt; OVERRIDE;
- { calls DoIt }
-
- PROCEDURE TSetTabCommand.UndoIt; OVERRIDE;
- { restores previous tab setting }
-
- { Debugging }
-
- PROCEDURE TSetTabCommand.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: integer)); OVERRIDE;
- { Used by the Inspector and the Debugger to display the contents of this class's
- fields. }
- END;
-
- TShowInvsCommand = OBJECT (TCommand)
- fInvsWereShown: Boolean;
- PROCEDURE TShowInvsCommand.IShowInvsCommand(itsView: TView;
- itsCmdNumber: CmdNumber;
- invsWereShown: Boolean);
- PROCEDURE TShowInvsCommand.DoIt; OVERRIDE;
- { sets new tabs, then calls ForceRedraw }
-
- PROCEDURE TShowInvsCommand.RedoIt; OVERRIDE;
- { calls DoIt }
-
- PROCEDURE TShowInvsCommand.UndoIt; OVERRIDE;
- { restores previous tab setting }
-
- { Debugging }
-
- PROCEDURE TShowInvsCommand.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: integer)); OVERRIDE;
- { Used by the Inspector and the Debugger to display the contents of this class's
- fields. }
- END;
-
- PROCEDURE InitUTabTEView;
- { Initialize TabTEView unit. }
-
- IMPLEMENTATION
-
- {$I UTabTEView.inc1.p}
-
- END.
-