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.inc1.p < prev    next >
Encoding:
Text File  |  1990-10-25  |  22.0 KB  |  770 lines  |  [TEXT/MPS ]

  1. {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
  2. { Copyright © 1986-1990 Apple Computer, Inc.  All rights reserved. }
  3.  
  4. VAR
  5.  
  6.     {$J+}                                                { These have storage allocated elsewhere }
  7.     HookedCQDProcsPtrOffset: integer;                    { offset in object to the QDProcs record }
  8.     OldTEHooksRecOffset: integer;                        { offset in object to the OldHooks record }
  9.  
  10.     curTabTEView:        TTabTEView;                     { accessed synchronously by the QD
  11.                                                          replacement procs to get context }
  12.     {$J-}
  13.  
  14.     pLastTheLength, pLastTheWidthBefore: integer;
  15.     pLastSelf:            TTabTEView;
  16.     pLastTETxMeas:        integer;
  17.     pLastTheCharOffset, pLastTheLine: integer;
  18.  
  19. PROCEDURE myTEDrawHook;
  20.     EXTERNAL;
  21.  
  22. PROCEDURE myTEWidthHook;
  23.     EXTERNAL;
  24.  
  25. PROCEDURE myTEHitTestHook;
  26.     EXTERNAL;
  27.  
  28. PROCEDURE myTEEOLHook;
  29.     EXTERNAL;
  30.  
  31. FUNCTION CallOriginalTxMeas(byteCount: integer;
  32.                             textAddr: Ptr;
  33.                             VAR numer: Point;
  34.                             VAR denom: Point;
  35.                             VAR info: FontInfo;
  36.                             actionProc: ProcPtr): integer;
  37.     INLINE $205F, $4E90;
  38. {  MOVE.L  (A7)+,A0
  39. JSR (A0)
  40. }
  41.  
  42. PROCEDURE CallOriginalText(theLength: integer;
  43.                            theText: Ptr;
  44.                            numer: Point;
  45.                            denom: Point;
  46.                            actionProc: ProcPtr);
  47.     INLINE $205F, $4E90;
  48. {  MOVE.L  (A7)+,A0
  49. JSR (A0)
  50. }
  51.  
  52. {--------------------------------------------------------------------------------------------------}
  53. {$S TEInit}
  54.  
  55. PROCEDURE InitUTabTEView;
  56.  
  57.     BEGIN
  58.     IF NOT gUTEViewInitialized THEN
  59.         InitUTEView;
  60.     
  61.     IF qTemplateViews THEN
  62.         BEGIN
  63.         { So linker doesn't strip TTabTEView class }
  64.         IF gDeadStripSuppression THEN
  65.             IF Member(TObject(NIL), TTabTEView) THEN;
  66.         END;
  67.     END;
  68.  
  69. { Follows are the bottleneck procs for QuickDraw to perform tabs }
  70.  
  71. {--------------------------------------------------------------------------------------------------}
  72. {$S TERes}
  73. {$Push} {$ifc qTrace} {$D+} {$endc}                     { we don't really need these guys traced! }
  74.  
  75. FUNCTION myTxMeas(theLength: integer;
  76.                   theText: Ptr;
  77.                   VAR numer: Point;
  78.                   VAR denom: Point;
  79.                   VAR info: FontInfo): integer;
  80.  
  81.     BEGIN
  82.     IF curTabTEView <> NIL THEN
  83.         myTxMeas := curTabTEView.TETxMeas(theLength, theText, numer, denom, info)
  84.     ELSE
  85.     {$IFC false}
  86.         myTxMeas := CallOriginalTxMeas(theLength, theText, numer, denom, info,
  87.                                        curTabTEView.fOldCQDProcs.txMeasProc)
  88.         {$EndC}
  89.                     DebugStr('whoops!');
  90.     END;
  91. {$Pop}
  92.  
  93. {--------------------------------------------------------------------------------------------------}
  94. {$S TERes}
  95. {$Push} {$ifc qTrace} {$D+} {$endc}                     { we don't really need these guys traced! }
  96.  
  97. PROCEDURE myDrawText(theLength: integer;
  98.                      theText: Ptr;
  99.                      numer: Point;
  100.                      denom: Point);
  101.  
  102.     BEGIN
  103.     IF curTabTEView <> NIL THEN
  104.         curTabTEView.TEDrawText(theLength, theText, numer, denom)
  105.     ELSE
  106.     {$IFC false}
  107.         CallOriginalText(theLength, theText, numer, denom, curTabTEView.fOldCQDProcs.textProc)
  108.         {$EndC}
  109.           DebugStr('whoops!');
  110.     END;
  111. {$Pop}
  112.  
  113. {--------------------------------------------------------------------------------------------------}
  114. {$S TERes}
  115. {$Push} {$ifc qTrace} {$D+} {$endc}                     { we don't really need these guys traced! }
  116.  
  117. PROCEDURE TTabTEView.TEDrawText(theLength: integer;
  118.                                 theText: Ptr;
  119.                                 numer: Point;
  120.                                 denom: Point);
  121.  
  122.     VAR
  123.         i:                    integer;
  124.         margin:             integer;
  125.         currentPoint:        Point;
  126.         beginChar:            integer;
  127.  
  128.     BEGIN
  129.  
  130.     WITH fHTE^^, currentPoint DO
  131.         BEGIN
  132.         beginChar := 0;
  133.         margin := destRect.left;
  134.         FOR i := 0 TO theLength - 1 DO
  135.             BEGIN
  136.             CASE char(Ptr(ORD(theText) + i)^) OF
  137.                 chTab:
  138.                     BEGIN
  139.                     CallOriginalText(i - beginChar, Ptr(ORD(theText) + beginChar), numer, denom,
  140.                                      fOldCQDProcs.textProc);
  141.                     beginChar := i + 1;
  142.  
  143.                     GetPen(currentPoint);
  144.  
  145.                     IF fShowInvisibles THEN
  146.                         DrawChar(kVisibleTAB);
  147.  
  148.                     h := h - margin + fTabSize;
  149.                     h := (h DIV fTabSize) * fTabSize + margin + 1;
  150.  
  151.                     MoveTo(h, v);
  152.                     END;
  153.                 chReturn:
  154.                     IF fShowInvisibles THEN
  155.                         BEGIN
  156.                         CallOriginalText(i - beginChar, Ptr(ORD(theText) + beginChar), numer, denom,
  157.                                          fOldCQDProcs.textProc);
  158.                         beginChar := i + 1;
  159.  
  160.                         DrawChar(kVisibleCR);
  161.                         END;
  162.                 chSpace:
  163.                     IF fShowInvisibles THEN
  164.                         BEGIN
  165.                         CallOriginalText(i - beginChar, Ptr(ORD(theText) + beginChar), numer, denom,
  166.                                          fOldCQDProcs.textProc);
  167.                         beginChar := i + 1;
  168.  
  169.                         DrawChar(kVisibleSpace);
  170.                         END;
  171.             END;
  172.             END;
  173.         END;
  174.  
  175.     CallOriginalText(theLength - beginChar, Ptr(ORD(theText) + beginChar), numer, denom,
  176.                      fOldCQDProcs.textProc);
  177.     END;
  178. {$Pop}
  179.  
  180. {--------------------------------------------------------------------------------------------------}
  181. {$S TERes}
  182. {$Push} {$ifc qTrace} {$D+} {$endc}                     { we don't really need these guys traced! }
  183.  
  184. FUNCTION TTabTEView.TETextLength(theText: Ptr;
  185.                                  theLength: integer;
  186.                                  theWidthBefore: integer;
  187.                                  VAR numer: Point;
  188.                                  VAR denom: Point;
  189.                                  VAR info: FontInfo): integer;
  190.  
  191.     VAR
  192.         beginChar:            integer;
  193.         theWidth:            integer;
  194.         i:                    integer;
  195.         aByte:                QDByte;
  196.  
  197.     BEGIN
  198.  
  199.     theWidth := 0;
  200.     beginChar := 0;
  201.     FOR i := 0 TO theLength - 1 DO
  202.         BEGIN
  203.         CASE char(Ptr(ORD(theText) + i)^) OF
  204.             chTab:
  205.                 BEGIN
  206.                 theWidth := theWidth + CallOriginalTxMeas(i - beginChar, Ptr(ORD(theText) +
  207.                                                           beginChar), numer, denom, info,
  208.                                                           fOldCQDProcs.txMeasProc);
  209.                 beginChar := i + 1;
  210.                 theWidth := ((theWidth + fTabSize + theWidthBefore) DIV fTabSize) *
  211.                             fTabSize - theWidthBefore;
  212.                 END;
  213.             chSpace:
  214.                 IF fShowInvisibles THEN
  215.                     BEGIN
  216.                     theWidth := theWidth + CallOriginalTxMeas(i - beginChar, Ptr(ORD(theText) +
  217.                                                               beginChar), numer, denom, info,
  218.                                                               fOldCQDProcs.txMeasProc);
  219.                     beginChar := i + 1;
  220.                     {$Push} {$R-}
  221.                     aByte := QDByte(kVisibleSpace);
  222.                     {$Pop}
  223.                     theWidth := theWidth + CallOriginalTxMeas(1, @aByte, numer, denom, info,
  224.                                                               fOldCQDProcs.txMeasProc);
  225.                     END;
  226.             chReturn:
  227.                 IF fShowInvisibles THEN
  228.                     BEGIN
  229.                     theWidth := theWidth + CallOriginalTxMeas(i - beginChar, Ptr(ORD(theText) +
  230.                                                               beginChar), numer, denom, info,
  231.                                                               fOldCQDProcs.txMeasProc);
  232.                     beginChar := i + 1;
  233.                     {$Push} {$R-}
  234.                     aByte := QDByte(kVisibleCR);
  235.                     {$Pop}
  236.                     theWidth := theWidth + CallOriginalTxMeas(1, @aByte, numer, denom, info,
  237.                                                               fOldCQDProcs.txMeasProc);
  238.                     END;
  239.         END;
  240.         END;
  241.  
  242.     TETextLength := theWidth + CallOriginalTxMeas(theLength - beginChar, Ptr(ORD(theText) +
  243.                                                   beginChar), numer, denom, info,
  244.                                                   fOldCQDProcs.txMeasProc);
  245.     END;
  246. {$Pop}
  247.  
  248. {--------------------------------------------------------------------------------------------------}
  249. {$S TERes}
  250. {$Push} {$ifc qTrace} {$D+} {$endc}                     { we don't really need these guys traced! }
  251.  
  252. FUNCTION TTabTEView.TETxMeas(theLength: integer;
  253.                              theText: Ptr;
  254.                              VAR numer: Point;
  255.                              VAR denom: Point;
  256.                              VAR info: FontInfo): integer;
  257.  
  258.     VAR
  259.         TheCharOffset:        integer;
  260.         theline:            integer;
  261.         theWidthBefore:     integer;
  262.  
  263.     BEGIN
  264.     {
  265.     Find which line in the TE the text pointed to by theText starts on and measure the
  266.     distance between the start of the line and the position in theline pointed to by theText.
  267.     This whole scheme depends on textedit passing us a pointer to the actual hText^.
  268.     }
  269.  
  270.     WITH fHTE^^ DO
  271.         BEGIN
  272.         { find out what line we're currently on }
  273.         TheCharOffset := ORD(StripLong(theText)) - ORD(StripLong(hText^));
  274.  
  275.         IF (self = pLastSelf) & (TheCharOffset = pLastTheCharOffset) THEN
  276.             BEGIN
  277.             theline := pLastTheLine;
  278.             END
  279.         ELSE                                            { Scan backward thru the line starts array
  280.                                                          for a linestart less than TheCharOffset }
  281.             BEGIN
  282.             FOR theline := max(nLines - 1, 0) DOWNTO 0 DO
  283.                 IF lineStarts[theline] <= TheCharOffset THEN
  284.                     LEAVE
  285.             END;
  286.  
  287.         { if the line is the same we may be able to save some calculation by caching }
  288.  
  289.         {$IFC FALSE}
  290.         {### NOT NOW }
  291.         IF (self = pLastSelf) & (theline = pLastTheLine) THEN
  292.             BEGIN
  293.             IF (TheCharOffset < pLastTheCharOffset) THEN { starts sooner on line. saved
  294.                                                           theWidthBefore info is useless }
  295.                 BEGIN
  296.                 IF (lineStarts[theline] = TheCharOffset) | (lineStarts[theline] < 0) THEN { the
  297.                        beginning of a line or end of text }
  298.                     theWidthBefore := 0
  299.                 ELSE
  300.                     theWidthBefore := TETextLength(Ptr(ORD(hText^) + lineStarts[theline]),
  301.                                                    TheCharOffset - lineStarts[theline], 0, numer,
  302.                                                    denom, info);
  303.                 pLastTETxMeas := TETextLength(theText, theLength, theWidthBefore, numer, denom,
  304.                                               info);
  305.                 END
  306.             ELSE IF (TheCharOffset > pLastTheCharOffset) THEN { starts later on line. Attempt to
  307.                                                                re-use some width before info }
  308.                 BEGIN
  309.                 IF (TheCharOffset < (pLastTheCharOffset + pLastTheLength)) THEN { starts sooner than
  310.                        end of last run pLastTETxMeas is useless }
  311.                     BEGIN
  312.                     theWidthBefore := TETextLength(Ptr(ORD(hText^) + pLastTheCharOffset),
  313.                                                    TheCharOffset - pLastTheCharOffset,
  314.                                                    theWidthBefore, numer, denom, info);
  315.                     pLastTETxMeas := TETextLength(theText, theLength, theWidthBefore, numer, denom,
  316.                                                   info);
  317.                     END
  318.                 ELSE IF (TheCharOffset > (pLastTheCharOffset + pLastTheLength)) THEN
  319.                     BEGIN
  320.                     theWidthBefore := pLastTheWidthBefore + pLastTETxMeas;
  321.                     theWidthBefore := TETextLength(Ptr(ORD(hText^) + pLastTheCharOffset +
  322.                                                        pLastTheLength), TheCharOffset -
  323.                                                    (pLastTheCharOffset + pLastTheLength),
  324.                                                    theWidthBefore, numer, denom, info);
  325.                     pLastTETxMeas := TETextLength(theText, theLength, theWidthBefore, numer, denom,
  326.                                                   info);
  327.                     END
  328.                 ELSE                                    { must be equal }
  329.                     BEGIN
  330.                     theWidthBefore := pLastTheWidthBefore + pLastTETxMeas;
  331.                     pLastTETxMeas := TETextLength(theText, theLength, theWidthBefore, numer, denom,
  332.                                                   info)
  333.                     END
  334.                 END
  335.             ELSE                                        { must be equal starting position }
  336.                 BEGIN
  337.                 IF (theLength < pLastTheLength) THEN
  338.                     BEGIN
  339.                     IF (lineStarts[theline] = TheCharOffset) | (lineStarts[theline] < 0) THEN { the
  340.                            beginning of a line or end of text }
  341.                         theWidthBefore := 0
  342.                     ELSE
  343.                         theWidthBefore := TETextLength(Ptr(ORD(hText^) + lineStarts[theline]),
  344.                                                        TheCharOffset - lineStarts[theline], 0,
  345.                                                        numer, denom, info);
  346.                     pLastTETxMeas := TETextLength(theText, theLength, theWidthBefore, numer, denom,
  347.                                                   info);
  348.                     END
  349.                 ELSE IF (theLength > pLastTheLength) THEN
  350.                     BEGIN
  351.                     pLastTETxMeas := pLastTETxMeas + TETextLength(Ptr(ORD(theText) +
  352.                                                                   pLastTheLength), theLength -
  353.                                                                   pLastTheLength,
  354.                                                                   pLastTheWidthBefore +
  355.                                                                   pLastTETxMeas, numer, denom, info)
  356.                     END
  357.                 ELSE                                    { must be equal }
  358.                     BEGIN
  359.                     pLastTETxMeas := pLastTETxMeas;
  360.                     END;
  361.  
  362.                 END;
  363.             END
  364.         ELSE                                            { line not the same. no caching available }
  365.         {$EndC}
  366.             BEGIN
  367.             IF (lineStarts[theline] = TheCharOffset) | (lineStarts[theline] < 0) THEN { the
  368.                    beginning of a line or end of text }
  369.                 theWidthBefore := 0
  370.             ELSE
  371.                 theWidthBefore := TETextLength(Ptr(ORD(hText^) + lineStarts[theline]),
  372.                                                TheCharOffset - lineStarts[theline], 0, numer,
  373.                                                denom, info);
  374.             pLastTETxMeas := TETextLength(theText, theLength, theWidthBefore, numer, denom, info);
  375.             END
  376.  
  377.         END;
  378.  
  379.     pLastTheWidthBefore := theWidthBefore;
  380.     pLastTheCharOffset := TheCharOffset;
  381.     pLastTheLine := theline;
  382.     pLastTheLength := theLength;
  383.     pLastSelf := self;
  384.     TETxMeas := pLastTETxMeas;
  385.     END;
  386. {$Pop}
  387.  
  388. {--------------------------------------------------------------------------------------------------}
  389. {$S TERes}
  390.  
  391. PROCEDURE TTabTEView.WithHookedGrafProcsDo(PROCEDURE whatToDo);
  392.  
  393.     VAR
  394.         oldGrafPort:        GrafPtr;                    { the GrafPort found in the TE }
  395.         oldGrafProcs:        QDProcsPtr;                 { the grafprocs pointer found in the TE's
  396.                                                          grafport }
  397.         oldCurTEView:        TTabTEView;                 { the saved setting of the curTEView }
  398.  
  399.     BEGIN
  400.  
  401. { Make SELF available to the hooked grafprocs that will be invoked later
  402.  save the old curTabTEView first }
  403.     oldCurTEView := curTabTEView;
  404.     curTabTEView := self;
  405.  
  406.     { save its old grafprocs pointer }
  407.     oldGrafProcs := fHTE^^.inPort^.grafProcs;
  408.     fHTE^^.inPort^.grafProcs := QDProcsPtr(fHookedCQDProcsPtr);
  409.  
  410.     { Do what we were called for }
  411.     whatToDo;
  412.  
  413.     { restore the old curTabTEView, grafprocs and that showed we were hooked in }
  414.  
  415.     curTabTEView := oldCurTEView;
  416.     fHTE^^.inPort^.grafProcs := oldGrafProcs;
  417.     END;
  418.  
  419. {--------------------------------------------------------------------------------------------------}
  420. {$S TERes}
  421.  
  422. FUNCTION TTabTEView.DoMouseCommand(VAR theMouse: Point;
  423.                                    VAR info: EventInfo;
  424.                                    VAR hysteresis: Point): TCommand; OVERRIDE;
  425.  
  426.     PROCEDURE whatToDo;
  427.  
  428.         BEGIN
  429.         DoMouseCommand := INHERITED DoMouseCommand(theMouse, info, hysteresis);
  430.         END;
  431.  
  432.     BEGIN
  433.     { lousy TE (6.0) doesn't always respect TECustomHook! }
  434.     WithHookedGrafProcsDo(whatToDo)
  435.     END;
  436.  
  437. {--------------------------------------------------------------------------------------------------}
  438. {$S ARes}
  439.  
  440. PROCEDURE TTabTEView.DoSetupMenus; OVERRIDE;
  441.     BEGIN
  442.     INHERITED DoSetupMenus;
  443.     Enable(cIncTabs, TRUE);
  444.     Enable(cDecTabs, TRUE);
  445.     EnableCheck(cShowInvs, TRUE, fShowInvisibles);            {}
  446.     END;
  447.  
  448. {--------------------------------------------------------------------------------------------------}
  449. {$S ASelCommand}
  450.  
  451. FUNCTION TTabTEView.DoMenuCommand(aCmdNumber: CmdNumber): TCommand; OVERRIDE;
  452.     VAR
  453.         aSetTabCmd:TSetTabCommand;
  454.         aShowInvsCmd:TShowInvsCommand;
  455.     BEGIN
  456.     DoMenuCommand := NIL;
  457.     CASE aCmdNumber OF
  458.         cIncTabs:
  459.             BEGIN
  460.             New(aSetTabCmd);
  461.             FailNIL(aSetTabCmd);
  462.             aSetTabCmd.ISetTabCommand(SELF, aCmdNumber, fTabSize + 1);
  463.             PostCommand(aSetTabCmd);
  464.             END;
  465.         cDecTabs:
  466.             BEGIN
  467.             New(aSetTabCmd);
  468.             FailNIL(aSetTabCmd);
  469.             aSetTabCmd.ISetTabCommand(SELF, aCmdNumber, fTabSize - 1);
  470.             PostCommand(aSetTabCmd);
  471.             END;
  472.         cShowInvs:
  473.             BEGIN
  474.             New(aShowInvsCmd);
  475.             FailNIL(aShowInvsCmd);
  476.             aShowInvsCmd.IShowInvsCommand(SELF, aCmdNumber, fShowInvisibles);
  477.             PostCommand(aShowInvsCmd);
  478.             END;
  479.         OTHERWISE
  480.             DoMenuCommand := INHERITED DoMenuCommand(aCmdNumber);
  481.     END;
  482.     END;
  483.  
  484. {--------------------------------------------------------------------------------------------------}
  485. {$S TEOpen}
  486.  
  487. PROCEDURE TTabTEView.IRes(itsDocument: TDocument;
  488.                           itsSuperView: TView;
  489.                           VAR itsParams: Ptr); OVERRIDE;
  490.  
  491.     VAR
  492.         aProcPtr:            ProcPtr;
  493.  
  494.     BEGIN
  495.     fHookedCQDProcsPtr := NIL;
  496.  
  497.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  498.  
  499.     fHookedCQDProcsPtr := CQDProcsPtr(NewPermPtr(sizeof(CQDProcs)));
  500.     fTabSize := kDefaultTabSize;
  501.     fShowInvisibles := FALSE;
  502.     fControlChars := fControlChars + [chTab];            { tell TTE to accept tabs }
  503.  
  504.     IF fStyleType THEN                                    { only for style right now… sorry! }
  505.         BEGIN
  506.         IF fHTE <> NIL THEN
  507.             BEGIN
  508.             { Storing SELF in the refcon should be in MacApp }
  509.             GetStylHandle(fHTE)^^.teRefCon := longint(self);
  510.  
  511.             { let the ASM code know the offset of some of our structures }
  512.             HookedCQDProcsPtrOffset := StripLong(@fHookedCQDProcsPtr) - StripLong(Handle(self)^);
  513.             OldTEHooksRecOffset := StripLong(@fOldTEHooksRec) - StripLong(Handle(self)^);
  514.  
  515.             {  set up custom hooks into my TE to handle tabs }
  516.             aProcPtr := @myTEDrawHook;
  517.             TECustomHook(intDrawHook, aProcPtr, fHTE);
  518.             fOldTEHooksRec.DrawHook := aProcPtr;
  519.  
  520.             aProcPtr := @myTEWidthHook;
  521.             TECustomHook(intWidthHook, aProcPtr, fHTE);
  522.             fOldTEHooksRec.WidthHook := aProcPtr;
  523.  
  524.             aProcPtr := @myTEHitTestHook;
  525.             TECustomHook(intHitTestHook, aProcPtr, fHTE);
  526.             fOldTEHooksRec.HitTestHook := aProcPtr;
  527.  
  528.             END;
  529.         END;
  530.     BeInPort(GetGrafPort);
  531.     END;
  532.  
  533. {--------------------------------------------------------------------------------------------------}
  534. {$S TENonRes}
  535.  
  536. PROCEDURE TTabTEView.BeInPort(itsPort: GrafPtr); OVERRIDE;
  537. { save a copy of the currently effective GrafProcs and create a new version of the hooked procs }
  538.  
  539.     VAR
  540.         theCProcs:            CQDProcs;
  541.         theProcs:            QDProcs;
  542.         aQDProcsPtr:        QDProcsPtr;
  543.         isColor:            Boolean;
  544.         itsCPort:            CGrafPtr;
  545.  
  546.     BEGIN
  547.     INHERITED BeInPort(itsPort);
  548.  
  549.     IF (fHTE <> NIL) & (fHookedCQDProcsPtr <> NIL) THEN
  550.         BEGIN
  551.         itsCPort := CGrafPtr(itsPort);
  552.         isColor := itsCPort^.portversion = $C000;
  553.  
  554.         IF isColor THEN
  555.             BEGIN
  556.             IF itsCPort^.grafProcs = NIL THEN
  557.                 BEGIN
  558.                 SetStdCProcs(theCProcs);
  559.                 fOldCQDProcs := theCProcs;
  560.                 END
  561.             ELSE
  562.                 fOldCQDProcs := CQDProcsPtr(itsCPort^.grafProcs)^;
  563.             END
  564.         ELSE
  565.             BEGIN
  566.             IF itsPort^.grafProcs = NIL THEN
  567.                 BEGIN
  568.                 SetStdProcs(theProcs);
  569.                 aQDProcsPtr := QDProcsPtr(@fOldCQDProcs);
  570.                 aQDProcsPtr^ := theProcs;
  571.                 END
  572.             ELSE
  573.                 BEGIN
  574.                 aQDProcsPtr := QDProcsPtr(@fOldCQDProcs);
  575.                 aQDProcsPtr^ := itsPort^.grafProcs^;
  576.                 END;
  577.             END;
  578.  
  579.         { stuff my replacements into the hooked grafprocs }
  580.         fHookedCQDProcsPtr^ := fOldCQDProcs;
  581.         fHookedCQDProcsPtr^.textProc := @myDrawText;
  582.         fHookedCQDProcsPtr^.txMeasProc := @myTxMeas;
  583.         END
  584.     END;
  585.  
  586. {--------------------------------------------------------------------------------------------------}
  587. {$S TEOpen}
  588.  
  589. PROCEDURE TTabTEView.SetTabSize(newSize: integer; redraw: BOOLEAN);
  590.  
  591.     BEGIN
  592.     fTabSize := newSize;
  593.     fSpecsChanged := TRUE;
  594.     SynchView(FALSE);
  595.     IF redraw THEN
  596.         ForceRedraw;
  597.     END;
  598.  
  599. {--------------------------------------------------------------------------------------------------}
  600. {$S TERes}
  601.  
  602. PROCEDURE TTabTEView.ShowInvisibles(showEm: Boolean; redraw: BOOLEAN);
  603.  
  604.     BEGIN
  605.     fShowInvisibles := showEm;
  606.     IF redraw THEN
  607.         ForceRedraw;
  608.     END;
  609.  
  610. {--------------------------------------------------------------------------------------------------}
  611. {$S TEFields}
  612.  
  613. PROCEDURE TTabTEView.Fields(PROCEDURE DoToField(fieldName: Str255;
  614.                                                 fieldAddr: Ptr;
  615.                                                 fieldType: integer)); OVERRIDE;
  616.  
  617.     PROCEDURE QDProcsFields(theTitle: Str255;
  618.                             VAR theProcs: CQDProcs;
  619.                             PROCEDURE DoToField(fieldName: Str255;
  620.                                                 fieldAddr: Ptr;
  621.                                                 fieldType: integer));
  622.  
  623.         BEGIN
  624.         DoToField(theTitle, NIL, bTitle);
  625.         DoToField(' textProc', @theProcs.textProc, bPointer);
  626.         DoToField(' lineProc', @theProcs.lineProc, bPointer);
  627.         DoToField(' rectProc', @theProcs.rectProc, bPointer);
  628.         DoToField(' rRectProc', @theProcs.rRectProc, bPointer);
  629.         DoToField(' ovalProc', @theProcs.ovalProc, bPointer);
  630.         DoToField(' arcProc', @theProcs.arcProc, bPointer);
  631.         DoToField(' polyProc', @theProcs.polyProc, bPointer);
  632.         DoToField(' rgnProc', @theProcs.rgnProc, bPointer);
  633.         DoToField(' bitsProc', @theProcs.bitsProc, bPointer);
  634.         DoToField(' commentProc', @theProcs.commentProc, bPointer);
  635.         DoToField(' txMeasProc', @theProcs.txMeasProc, bPointer);
  636.         DoToField(' getPicProc', @theProcs.getPicProc, bPointer);
  637.         DoToField(' putPicProc', @theProcs.putPicProc, bPointer);
  638.         END;
  639.  
  640.     BEGIN
  641.     DoToField('TTabTEView', NIL, bClass);
  642.     DoToField('fTabSize', @fTabSize, bInteger);
  643.     DoToField('fShowInvisibles', @ShowInvisibles, bBoolean);
  644.     {$Push} {$H-}
  645.     QDProcsFields('fOldCQDProcs', fOldCQDProcs, DoToField);
  646.     QDProcsFields('fHookedCQDProcsPtr', fHookedCQDProcsPtr^, DoToField);
  647.     {$Pop}
  648.  
  649.     INHERITED Fields(DoToField);
  650.     END;
  651.  
  652. {--------------------------------------------------------------------------------------------------}
  653. {$S TESelCommand}
  654.  
  655. PROCEDURE TSetTabCommand.ISetTabCommand(itsView: TView;
  656.                                 itsCmdNumber: CmdNumber;
  657.                                 tabSetting: INTEGER);
  658.     BEGIN
  659.     ICommand(itsCmdNumber, itsView.fDocument, itsView, NIL);
  660.     IF Member(itsView, TTabTEView) THEN
  661.         fOldTabSetting := TTabTEView(itsView).fTabSize
  662.     ELSE
  663.         fOldTabSetting := 0;
  664.     fNewTabSetting := tabSetting;
  665.     END;
  666.  
  667. {--------------------------------------------------------------------------------------------------}
  668. {$S TEDoCommand}
  669.  
  670. PROCEDURE TSetTabCommand.DoIt; OVERRIDE;
  671. { sets new tabs, then calls ForceRedraw }
  672.     BEGIN
  673.     IF fView.Focus THEN;                                {??? What if Focus fails}
  674.     IF Member(fView,TTabTEView) THEN
  675.         TTabTEView(fView).SetTabSize(fNewTabSetting, kRedraw);
  676.     END;
  677.  
  678. {--------------------------------------------------------------------------------------------------}
  679. {$S TEDoCommand}
  680.  
  681. PROCEDURE TSetTabCommand.RedoIt; OVERRIDE;
  682. { calls DoIt }
  683.     BEGIN
  684.     DoIt;
  685.     END;
  686.  
  687. {--------------------------------------------------------------------------------------------------}
  688. {$S TEDoCommand}
  689.  
  690. PROCEDURE TSetTabCommand.UndoIt; OVERRIDE;
  691. { restores previous tab setting }
  692.     BEGIN
  693.     IF fView.Focus THEN;                                {??? What if Focus fails}
  694.     IF Member(fView,TTabTEView) THEN
  695.         TTabTEView(fView).SetTabSize(fOldTabSetting, kRedraw);
  696.     END;
  697.  
  698. {--------------------------------------------------------------------------------------------------}
  699. {$S TEFields}
  700.  
  701. { Debugging }
  702.  
  703. PROCEDURE TSetTabCommand.Fields(PROCEDURE
  704.                             DoToField(fieldName: Str255;
  705.                                       fieldAddr: Ptr;
  706.                                       fieldType: INTEGER)); OVERRIDE;
  707.     BEGIN
  708.     DoToField('TSetTabCommand', NIL, bClass);
  709.     DoToField('fOldTabSetting', @fOldTabSetting, bInteger);
  710.     DoToField('fNewTabSetting', @fNewTabSetting, bInteger);
  711.     INHERITED Fields(DoToField);
  712.     END;
  713.  
  714. {--------------------------------------------------------------------------------------------------}
  715. {$S TESelCommand}
  716.  
  717. PROCEDURE TShowInvsCommand.IShowInvsCommand(itsView: TView;
  718.                                 itsCmdNumber: CmdNumber;
  719.                                 invsWereShown: BOOLEAN);
  720.     BEGIN
  721.     ICommand(itsCmdNumber, itsView.fDocument, itsView, NIL);
  722.     fInvsWereShown := invsWereShown;
  723.     END;
  724.  
  725. {--------------------------------------------------------------------------------------------------}
  726. {$S TEDoCommand}
  727.  
  728. PROCEDURE TShowInvsCommand.DoIt; OVERRIDE;
  729. { sets new tabs, then calls ForceRedraw }
  730.     BEGIN
  731.     IF fView.Focus THEN;                                {??? What if Focus fails}
  732.     IF Member(fView,TTabTEView) THEN
  733.         TTabTEView(fView).ShowInvisibles(NOT fInvsWereShown, kRedraw);
  734.     END;
  735.  
  736. {--------------------------------------------------------------------------------------------------}
  737. {$S TEDoCommand}
  738.  
  739. PROCEDURE TShowInvsCommand.RedoIt; OVERRIDE;
  740. { calls DoIt }
  741.     BEGIN
  742.     DoIt;
  743.     END;
  744.  
  745. {--------------------------------------------------------------------------------------------------}
  746. {$S TEDoCommand}
  747.  
  748. PROCEDURE TShowInvsCommand.UndoIt; OVERRIDE;
  749. { restores previous tab setting }
  750.     BEGIN
  751.     IF fView.Focus THEN;                                {??? What if Focus fails}
  752.     IF Member(fView,TTabTEView) THEN
  753.         TTabTEView(fView).ShowInvisibles(fInvsWereShown, kRedraw);
  754.     END;
  755.  
  756. {--------------------------------------------------------------------------------------------------}
  757. {$S TEFields}
  758.  
  759. { Debugging }
  760.  
  761. PROCEDURE TShowInvsCommand.Fields(PROCEDURE
  762.                             DoToField(fieldName: Str255;
  763.                                       fieldAddr: Ptr;
  764.                                       fieldType: INTEGER)); OVERRIDE;
  765.     BEGIN
  766.     DoToField('TShowInvsCommand', NIL, bClass);
  767.     DoToField('fInvsWereShown', @fInvsWereShown, bBoolean);
  768.     INHERITED Fields(DoToField);
  769.     END;
  770.