home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Examples / DemoText / UTabTEView.p < prev    next >
Encoding:
Text File  |  1990-10-25  |  5.6 KB  |  183 lines  |  [TEXT/MPS ]

  1. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-,d-]}
  2. { Copyright © 1986-1990 Apple Computer, Inc.  All rights reserved. }
  3. (*=============================================================================
  4. | Tabs for TE Views.
  5. | by Steve Friedrich
  6. | Adapted from code generously supplied by Tom Dowdy @ Apple
  7. |
  8. | KNOWN LIMITATIONS
  9. | • only works for styled text but not with styles
  10. | • slow on full recalcs when linewrap is true
  11. | • won't print
  12. | • !!! STILL _VERY_ EXPERIMENTAL AND UNSUPPORTED !!!
  13. | • tabs only work for left justified text
  14. |
  15. | T H E O R Y  O F    O P E R A T I O N
  16. | This UNIT supports Tabs in TextEdit by providing a mechanism for the TE proc's
  17. | to call back into the object. This mechanism operates as follows - the refCon
  18. | field of the TERec is stuffed with the handle to the object (ie SELF). When
  19. | the TE proc's get control, they use this handle to access the object and thus
  20. | call back into the object.
  21. |
  22. | TO USE THIS UNIT WITH DemoText sample, make the following changes:
  23.  
  24.   1) DemoText.MAMake - modify these settings accordingly:
  25.     BuildingBlockIntf =  ∂
  26.         "{MAPInterfaces}UPrinting.p" ∂
  27.         "{MAPInterfaces}UTEView.p" ∂
  28.         "{SrcApp}UTabTEView.p"
  29.     OtherInterfaces =  ∂
  30.         "{SrcApp}UTEDocument.p" ∂
  31.         "{SrcApp}UTabTEView.p"
  32.     OtherLinkFiles = ∂
  33.         "{ObjApp}UTEDocument.p.o" ∂
  34.         "{ObjApp}UTabTEView.p.o" ∂
  35.         "{ObjApp}UTabTEView.a.o"
  36.     "{ObjApp}UTabTEView.p.o"    ƒ ∂
  37.                             "{SrcApp}UTabTEView.inc1.p" ∂
  38.                             {MacAppIntf} ∂
  39.                             {BuildingBlocksIntf}
  40.  
  41.   2) MDemoText.p
  42.     a) add UTabTEView to the USES clause, after UTEView,
  43.     b) call InitUTabTEView instead of InitUTEView.
  44.  
  45.   3) DemoText.r
  46.     in 'view' resource kViewRsrcID, specify the class for the TEView
  47.     as "TTabTEView" (it is set to "" in DemoText).
  48.  
  49. *)
  50.  
  51. UNIT UTabTEView;
  52.  
  53.     INTERFACE
  54.  
  55.         USES
  56.             { • MacApp }
  57.             UMacApp, UTEView,
  58.  
  59.             { • Implementation use }
  60.             ToolUtils, Fonts, FixMath, Script, Errors;
  61.  
  62.         CONST
  63.             { pretty pictures for "ShowInvisibles" }
  64.             kVisibleTAB         = 'Δ';
  65.             kVisibleSpace        = '◊';
  66.             kVisibleCR            = '¬';
  67.  
  68.             kDefaultTabSize     = 24;                    { the default tab size in pixels }
  69.  
  70.             cIncTabs            = 1410;
  71.             cDecTabs            = 1411;
  72.             cShowInvs            = 1412;
  73.  
  74.         TYPE
  75.             OldTEHooksRec        = RECORD                { routines that can be hooked in TE }
  76.                 DrawHook:            ProcPtr;
  77.                 WidthHook:            ProcPtr;
  78.                 HitTestHook:        ProcPtr;
  79.                 EOLHook:            ProcPtr;
  80.                 END;
  81.  
  82.             TTabTEView            = OBJECT (TTEView)
  83.                 fTabSize:            integer;
  84.                 fShowInvisibles:    Boolean;
  85.                 fOldCQDProcs:        CQDProcs;            { currently effective grafprocs }
  86.                 fHookedCQDProcsPtr: CQDProcsPtr;        { Points to a hooked version of currently
  87.                                                          effective grafprocs. }
  88.  
  89.                 fOldTEHooksRec:     OldTEHooksRec;        { previous hooks returned by TECustomHook }
  90.  
  91.                 PROCEDURE TTabTEView.IRes(itsDocument: TDocument;
  92.                                           itsSuperView: TView;
  93.                                           VAR itsParams: Ptr); OVERRIDE;
  94.                 PROCEDURE TTabTEView.BeInPort(itsPort: GrafPtr); OVERRIDE;
  95.  
  96.                 PROCEDURE TTabTEView.SetTabSize(newSize: integer;
  97.                                                 redraw: Boolean);
  98.                 PROCEDURE TTabTEView.ShowInvisibles(showEm: Boolean;
  99.                                                     redraw: Boolean);
  100.                 FUNCTION TTabTEView.TETextLength(theText: Ptr;
  101.                                                  theLength: integer;
  102.                                                  theWidthBefore: integer;
  103.                                                  VAR numer: Point;
  104.                                                  VAR denom: Point;
  105.                                                  VAR info: FontInfo): integer;
  106.                 FUNCTION TTabTEView.DoMouseCommand(VAR theMouse: Point;
  107.                                                    VAR info: EventInfo;
  108.                                                    VAR hysteresis: Point): TCommand; OVERRIDE;
  109.                 PROCEDURE TTabTEView.DoSetupMenus; OVERRIDE;
  110.                 FUNCTION TTabTEView.DoMenuCommand(aCmdNumber: CmdNumber): TCommand; OVERRIDE;
  111.                 PROCEDURE TTabTEView.Fields(PROCEDURE
  112.                                             DoToField(fieldName: Str255;
  113.                                                       fieldAddr: Ptr;
  114.                                                       fieldType: integer)); OVERRIDE;
  115.                 FUNCTION TTabTEView.TETxMeas(theLength: integer;
  116.                                              theText: Ptr;
  117.                                              VAR numer: Point;
  118.                                              VAR denom: Point;
  119.                                              VAR info: FontInfo): integer;
  120.                 PROCEDURE TTabTEView.TEDrawText(theLength: integer;
  121.                                                 theText: Ptr;
  122.                                                 numer: Point;
  123.                                                 denom: Point);
  124.                 PROCEDURE TTabTEView.WithHookedGrafProcsDo(PROCEDURE whatToDo);
  125.                 END;
  126.  
  127.             TSetTabCommand        = OBJECT (TCommand)
  128.                 fOldTabSetting, fNewTabSetting: integer;
  129.                 PROCEDURE TSetTabCommand.ISetTabCommand(itsView: TView;
  130.                                                         itsCmdNumber: CmdNumber;
  131.                                                         tabSetting: integer);
  132.                 PROCEDURE TSetTabCommand.DoIt; OVERRIDE;
  133.                 { sets new tabs, then calls ForceRedraw }
  134.  
  135.                 PROCEDURE TSetTabCommand.RedoIt; OVERRIDE;
  136.                 { calls DoIt }
  137.  
  138.                 PROCEDURE TSetTabCommand.UndoIt; OVERRIDE;
  139.                 { restores previous tab setting }
  140.  
  141.                 { Debugging }
  142.  
  143.                 PROCEDURE TSetTabCommand.Fields(PROCEDURE
  144.                                                 DoToField(fieldName: Str255;
  145.                                                           fieldAddr: Ptr;
  146.                                                           fieldType: integer)); OVERRIDE;
  147.                 { Used by the Inspector and the Debugger to display the contents of this class's
  148.                 fields. }
  149.                 END;
  150.  
  151.             TShowInvsCommand    = OBJECT (TCommand)
  152.                 fInvsWereShown:     Boolean;
  153.                 PROCEDURE TShowInvsCommand.IShowInvsCommand(itsView: TView;
  154.                                                             itsCmdNumber: CmdNumber;
  155.                                                             invsWereShown: Boolean);
  156.                 PROCEDURE TShowInvsCommand.DoIt; OVERRIDE;
  157.                 { sets new tabs, then calls ForceRedraw }
  158.  
  159.                 PROCEDURE TShowInvsCommand.RedoIt; OVERRIDE;
  160.                 { calls DoIt }
  161.  
  162.                 PROCEDURE TShowInvsCommand.UndoIt; OVERRIDE;
  163.                 { restores previous tab setting }
  164.  
  165.                 { Debugging }
  166.  
  167.                 PROCEDURE TShowInvsCommand.Fields(PROCEDURE
  168.                                                   DoToField(fieldName: Str255;
  169.                                                             fieldAddr: Ptr;
  170.                                                             fieldType: integer)); OVERRIDE;
  171.                 { Used by the Inspector and the Debugger to display the contents of this class's
  172.                 fields. }
  173.                 END;
  174.  
  175.         PROCEDURE InitUTabTEView;
  176.         { Initialize TabTEView unit. }
  177.  
  178.     IMPLEMENTATION
  179.  
  180.         {$I UTabTEView.inc1.p}
  181.  
  182. END.
  183.