home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MacApp / MacApp 3.0a2 / Libraries / UTabTEView.cp < prev    next >
Encoding:
Text File  |  1991-05-01  |  22.2 KB  |  823 lines  |  [TEXT/MPS ]

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