home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 October / Macformat17.cdr / Shareware City / Developers / WASTETCL / WASTE TCL / CWASTEText.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-02  |  23.2 KB  |  996 lines  |  [TEXT/ttxt]

  1. /********************************************************\
  2.  CWASTEText.cpp
  3.  
  4. \********************************************************/
  5.  
  6. #ifdef TCL_PCH
  7. #include <TCLHeaders>
  8. #endif
  9.  
  10. #include "CWASTEText.h"
  11. #ifndef __ERRORS__
  12. #include <Errors.h>
  13. #endif
  14. #ifndef __SCRAP__
  15. #include <Scrap.h>
  16. #endif
  17. #ifndef __FONTS__
  18. #include <Fonts.h>
  19. #endif
  20.  
  21. #include <Script.h>
  22.  
  23. // Global Variables
  24.  
  25. extern CClipboard    *gClipboard;    // Copies and Pastes data
  26. extern EventRecord  gLastMouseUp;
  27. extern CBureaucrat    *gGopher;
  28.  
  29. extern long            gSleepTime;
  30. extern short        gUsingTSM;
  31.  
  32. static pascal Boolean WEClickLoop(WEHandle hWE);
  33.  
  34. CWASTEText    *gWASTEText=NULL;                /* Current WASTEText object */
  35.  
  36. // undocumented WASTE routine
  37. extern pascal long _WEOffsetToLine(long offset, WEHandle hWE);
  38.  
  39. TCL_DEFINE_CLASS_D1(CWASTEText, CAbstractText);
  40.  
  41. /********************************************************\
  42.  CWASTEText() - default constructor
  43.      You must call IWASTEText if you use this
  44. \********************************************************/
  45.  
  46. CWASTEText::CWASTEText()
  47. {
  48.     macWE = NULL;
  49.     spacingCmd = cmdSingleSpace;
  50.     alignCmd = cmdAlignLeft;
  51.  
  52.     wholeLines = false;
  53.     
  54.     fixedLineHeights = false;
  55.     
  56.     TCL_END_CONSTRUCTOR
  57. }
  58.  
  59. /********************************************************\
  60.  CWASTEText - constructor
  61.      You cannot call IWASTEText if you use this
  62. \********************************************************/
  63.  
  64. CWASTEText::CWASTEText(
  65.     CView            *anEnclosure,
  66.     CBureaucrat        *aSupervisor,
  67.     short            aWidth,
  68.     short            aHeight,
  69.     short            aHEncl,
  70.     short            aVEncl,
  71.     SizingOption    aHSizing,
  72.     SizingOption    aVSizing,
  73.     short            aLineWidth,
  74.     Boolean            aScrollHoriz)
  75.  
  76.     :    CAbstractText(anEnclosure, aSupervisor,
  77.                      aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing,
  78.                      aLineWidth, aScrollHoriz)
  79. {
  80.     macWE = NULL;
  81.     spacingCmd = cmdSingleSpace;
  82.     alignCmd = cmdAlignLeft;
  83.  
  84.     wholeLines = false;
  85.     fixedLineHeights = false;
  86.     
  87.     IWASTETextX();
  88.     TCL_END_CONSTRUCTOR
  89. }
  90.  
  91. /********************************************************\
  92.  ~CWASTEText - destructor
  93. \********************************************************/
  94.  
  95. CWASTEText::~CWASTEText()
  96. {
  97.     TCL_START_DESTRUCTOR
  98.     if (macWE)
  99.     {
  100.         WEDispose(macWE);
  101.         macWE = NULL;
  102.     }
  103. }
  104.  
  105. /********************************************************\
  106.  IWASTEText - initialize CWASTEText
  107.      Use this only if you use the default constructor
  108. \********************************************************/
  109.  
  110. void CWASTEText::IWASTEText(
  111.     CView            *anEnclosure,
  112.     CBureaucrat        *aSupervisor,
  113.     short            aWidth,
  114.     short            aHeight,
  115.     short            aHEncl,
  116.     short            aVEncl,
  117.     SizingOption    aHSizing,
  118.     SizingOption    aVSizing,
  119.     short            aLineWidth)
  120. {
  121.  
  122.     CAbstractText::IAbstractText(anEnclosure, aSupervisor,
  123.                      aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing,
  124.                      aLineWidth);
  125.  
  126.     IWASTETextX();
  127. }
  128.  
  129. /********************************************************\
  130.  IViewTemp - initialize from View resource
  131. \********************************************************/
  132.  
  133. void CWASTEText::IViewTemp(CView *anEnclosure, CBureaucrat *aSupervisor,
  134.                         Ptr viewData)
  135. {
  136.     CAbstractText::IViewTemp(anEnclosure, aSupervisor, viewData);
  137.  
  138.     macWE = NULL;
  139.     spacingCmd = cmdSingleSpace;
  140.     alignCmd = cmdAlignLeft;
  141.     fixedLineHeights = FALSE;
  142.  
  143.     IWASTETextX();
  144. }
  145.  
  146. /********************************************************\
  147.  IWASTETextX - initialization common to above routines
  148. \********************************************************/
  149.  
  150. void CWASTEText::IWASTETextX()
  151. {
  152.     Str255                itemStr;
  153.     FontInfo            macFontInfo;
  154.     LongRect            longInterior;
  155.     Rect                tFrame;
  156.     Boolean                savedAlloc;
  157.     LongRect            tLongFrame;
  158.     WEClickLoopProcPtr    clickLoop;
  159.  
  160.     ForceNextPrepare();
  161.     //SetPort(macPort);
  162.     TextFont(GetScriptVariable(smJapanese, smScriptAppFond));
  163.  
  164.  
  165.     // Figure out size of of rectangle
  166.     GetInterior(&longInterior);
  167.     LongToQDRect(&longInterior, &tFrame);
  168.  
  169.     // create WEHandle
  170.     SetLongRect(&tLongFrame, tFrame.left, tFrame.top, tFrame.right, tFrame.bottom);
  171.     FailOSErr(WENew(&tLongFrame, &tLongFrame, weDoOutlineHilite + weDoDrawOffscreen,
  172.          &macWE));
  173.  
  174.     SetWholeLines(wholeLines);
  175.  
  176.     AdjustBounds();
  177.  
  178.     autoRefresh = lineWidth <= 0;
  179.  
  180.     clickLoop = &WEClickLoop;
  181.     WESetInfo(weClickLoop, (void *)&clickLoop, macWE);
  182.     CalcWERects();
  183. }
  184.  
  185. /********************************************************\
  186.  DoClick - handle mouse clicks
  187. \********************************************************/
  188.  
  189. void CWASTEText::DoClick(Point hitPt, short modifierKeys, long when)
  190. {
  191.     WEClick(hitPt, modifierKeys, when, macWE);
  192.     
  193.         // CSwitchboard will never see the mouse up that ended
  194.         // the drag, so we stuff gLastMouseUp here to allow
  195.         // multi-click counting to work.
  196.         
  197.     gLastMouseUp.what = mouseUp;
  198.     gLastMouseUp.when = TickCount();
  199.     gLastMouseUp.where = hitPt;
  200.     LocalToGlobal( &gLastMouseUp.where);
  201.     gLastMouseUp.modifiers = modifierKeys;
  202.  
  203.     SelectionChanged();
  204.     
  205.     if (!editable && (gGopher == this))
  206.     {
  207.         long selStart, selEnd;
  208.         
  209.         GetSelection( &selStart, &selEnd);    
  210.         if (selStart == selEnd)
  211.             itsSupervisor->BecomeGopher( TRUE);
  212.     }
  213. }
  214.  
  215. /********************************************************\
  216.  PerformEditCommand - handle cut, copy, paste, and clear
  217. \********************************************************/
  218.  
  219. void CWASTEText::PerformEditCommand(long theCommand)
  220. {
  221.     Prepare();
  222.  
  223.     switch( theCommand)
  224.     {        
  225.         case cmdCut:
  226.             gClipboard->EmptyGlobalScrap();            
  227.             WECut(macWE);
  228.             gClipboard->UpdateDisplay();
  229.             break;
  230.             
  231.         case cmdCopy:
  232.             gClipboard->EmptyGlobalScrap();
  233.             WECopy(macWE);
  234.             gClipboard->UpdateDisplay();
  235.             break;
  236.             
  237.         case cmdPaste:
  238.             WEPaste(macWE);
  239.             break;
  240.             
  241.         case cmdClear:
  242.             WEDelete(macWE);
  243.             break;
  244.             
  245.     }
  246.     AdjustBounds();
  247.     ScrollToSelection();
  248. }
  249.  
  250. /********************************************************\
  251.  Draw - draw the text
  252. \********************************************************/
  253.  
  254. void CWASTEText::Draw(Rect *area)
  255. {
  256.     RgnHandle updateRgn;
  257.     OSErr err;
  258.     
  259.     updateRgn = NewRgn();
  260.     RectRgn(updateRgn, area);
  261.     
  262.     err = WESetInfo(wePort, &qd.thePort, macWE);
  263.     WEUpdate(updateRgn, macWE);
  264.     err = WESetInfo(wePort, &macPort, macWE);
  265.     DisposeRgn(updateRgn);
  266. }
  267.  
  268. /********************************************************\
  269.  Scroll - scroll the text within pane
  270. \********************************************************/
  271.  
  272. void CWASTEText::Scroll(long hDelta, long vDelta, Boolean redraw)
  273. {
  274.     short        hPixels;
  275.     short        vPixels;
  276.     LongRect     viewRect;
  277.     
  278.     hPixels = hDelta * hScale;
  279.     vPixels = vDelta * vScale;
  280.  
  281.     WEGetViewRect(&viewRect, macWE);
  282.     OffsetLongRect(&viewRect, hPixels, vPixels);
  283.     WESetViewRect(&viewRect, macWE);
  284.         
  285.     CAbstractText::Scroll(hDelta, vDelta, redraw);
  286.  
  287. }
  288.  
  289. /********************************************************\
  290.  Activate - activate the pane
  291. \********************************************************/
  292.  
  293. void CWASTEText::Activate()
  294. {
  295.     TSMDocumentID aTSMDocument;
  296.     
  297.     if (gWASTEText==this) // already active
  298.     {
  299.         return;
  300.     }
  301.     
  302.     CAbstractText::Activate();
  303.     
  304.     // deactivate old WASTEText
  305.     if (gWASTEText!=NULL) gWASTEText->Deactivate();
  306.     Prepare();
  307.     WEActivate(macWE);
  308.     gWASTEText = this;
  309.     if (!editable)
  310.     {
  311.         // if not editable, deactivate TSM so inline input won't work
  312.         if (gUsingTSM)
  313.         {
  314.             if (WEGetInfo(weTSMDocumentID, &aTSMDocument, macWE) == noErr)
  315.             {
  316.                 if (aTSMDocument != NULL)
  317.                     DeactivateTSMDocument(aTSMDocument);
  318.             }
  319.         }
  320.     }
  321. }
  322.  
  323. /********************************************************\
  324.  Deactivate - deactivate the pane
  325. \********************************************************/
  326.  
  327. void CWASTEText::Deactivate()
  328. {
  329.     CAbstractText::Deactivate();
  330.  
  331.     WEStopInlineSession(macWE);
  332.     Prepare();
  333.     if (macWE) WEDeactivate(macWE);
  334.     gWASTEText = NULL;
  335. }
  336.  
  337. /********************************************************\
  338.  SetSelection - set what text is selected
  339. \********************************************************/
  340.  
  341. void CWASTEText::SetSelection(long selStart, long selEnd, Boolean fRedraw)
  342. {
  343.     Prepare();    
  344.     WESetSelection(selStart, selEnd, macWE);
  345. }
  346.  
  347. /********************************************************\
  348.  Clear - clear the text
  349.     Deactivates text before clearing to prevent
  350.     highlighting from showing up
  351. \********************************************************/
  352.  
  353. void CWASTEText::Clear(void)
  354. {
  355.     Handle h;
  356.     Boolean wasActive;
  357.     
  358.     wasActive = active;
  359.     
  360.     if (wasActive) Deactivate();
  361.     SetSelection(0, 0x7FFFFFF, false);
  362.     WEDelete(macWE);
  363.     
  364.     if (wasActive) Activate();
  365. }
  366.  
  367. /********************************************************\
  368.  SetTextPtr - set the text to a block of memory
  369. \********************************************************/
  370.  
  371. void CWASTEText::SetTextPtr(Ptr textPtr, long numChars)
  372. {
  373.     Handle newHand;
  374.  
  375.     // put text into a handle    
  376.     PtrToHand(textPtr, &newHand, numChars);
  377.     FailMemError();
  378.     WEUseText(newHand, macWE);
  379.     WECalText(macWE);
  380.  
  381.     AdjustBounds();
  382.     Refresh();
  383. }
  384.  
  385. /********************************************************\
  386.  StopInlineSession - stop inline session, confirm text
  387. \********************************************************/
  388. void CWASTEText::StopInlineSession(void)
  389. {
  390.     WEStopInlineSession(macWE);
  391. }
  392.  
  393. /********************************************************\
  394.  GetTextHandle - get a handle to the text
  395.      This is not a copy of the handle, but the real thing
  396. \********************************************************/
  397.  
  398. Handle CWASTEText::GetTextHandle()
  399. {
  400.     return( (Handle) WEGetText(macWE));
  401. }
  402.  
  403. /********************************************************\
  404.  CopyTextRange - return a handle to a copy of the
  405.      indicated range of text
  406. \********************************************************/
  407.  
  408. Handle CWASTEText::CopyTextRange(long start, long end)
  409. {
  410.     Handle    h;
  411.     long    len;
  412.     
  413.     end = Min(end, WEGetTextLength(macWE));
  414.     
  415.     len = Max(end - start, 0);
  416.     h = NewHandleCanFail(len);
  417.     FailNIL(h);
  418.     if (len > 0)
  419.         BlockMove( (char*)*(WEGetText(macWE)) + start, *h, len);
  420.     
  421.     return h;
  422. }
  423.  
  424. /********************************************************\
  425.  CopyRangeWithStyle - return a handle to the text and
  426.      styles in a range.  Handles must be previously
  427.      created with NewHandle();
  428. \********************************************************/
  429.  
  430. void CWASTEText::CopyRangeWithStyle(long start, long end, Handle hText,
  431.     StScrpHandle hStyles)
  432. {
  433.     FailOSErr(WECopyRange(start, end, hText, hStyles, macWE));
  434. }
  435.  
  436. /********************************************************\
  437.  InsertTextPtr - insert a block of text
  438. \********************************************************/
  439.  
  440. void CWASTEText::InsertTextPtr(Ptr text, long length, Boolean fRedraw)
  441. {
  442.     Prepare();
  443.     WEInsert(text, length, NULL, macWE);
  444.     AdjustBounds();
  445.     if (fRedraw) Refresh();
  446. }
  447.  
  448. /********************************************************\
  449.  InsertTextPtr - insert a block of text
  450. \********************************************************/
  451.  
  452. void CWASTEText::InsertWithStyle(Ptr text, long length, StScrpHandle hStyles,
  453.         Boolean fRedraw)
  454. {
  455.     Prepare();
  456.     WEInsert(text, length, hStyles, macWE);
  457.     AdjustBounds();
  458.     if (fRedraw) Refresh();
  459. }
  460.  
  461. /********************************************************\
  462.  TypeChar - type a character
  463. \********************************************************/
  464.  
  465. void CWASTEText::TypeChar(char theChar, short theModifers)
  466. {
  467.     Prepare();
  468.     WEKey(theChar, theModifers, macWE);
  469.     AdjustBounds();
  470.     ScrollToSelection();
  471. }
  472.  
  473. /********************************************************\
  474.  CalcWERects - Sets the DestRect and ViewRect fields
  475.      used by WASTE
  476. \********************************************************/
  477.  
  478. void CWASTEText::CalcWERects()
  479. {
  480.     LongRect    interior;    
  481.     short        hDelta;
  482.     short        vDelta;
  483.     LongRect    destRect, viewRect;
  484.     Rect         vRect;
  485.     
  486.     WEGetDestRect(&destRect, macWE);
  487.     
  488.     GetInterior( &interior);
  489.  
  490.     hDelta = position.h * hScale - interior.left + destRect.left;
  491.     vDelta = position.v * vScale - interior.top + destRect.top;
  492.     
  493.     frame.left += hDelta;
  494.     frame.right += hDelta;
  495.     frame.top += vDelta;
  496.         
  497.     hOrigin += hDelta;
  498.     vOrigin += vDelta;
  499.  
  500.  
  501.     destRect.right = (lineWidth > 0) ?
  502.                                     destRect.left + lineWidth :
  503.                                     interior.right;
  504.     WESetDestRect(&destRect, macWE);
  505.     
  506.     LongToQDRect( &interior, &vRect);
  507.     SetLongRect(&viewRect, vRect.left, vRect.top, vRect.right, vRect.bottom);
  508.     WESetViewRect(&viewRect, macWE);
  509.  
  510.     WECalText( macWE);
  511. }
  512.  
  513. /********************************************************\
  514.  ResizeFrame - resize the frame when the size of the
  515.      pane changes
  516. \********************************************************/
  517.  
  518. void CWASTEText::ResizeFrame(Rect *delta)
  519. {
  520.     LongRect    destRect, viewRect;
  521.  
  522.     CAbstractText::ResizeFrame(delta);
  523.  
  524.     WEGetDestRect(&destRect, macWE);
  525.     
  526.     destRect.left += delta->left;
  527.     destRect.top += delta->top;
  528.  
  529.     WESetDestRect(&destRect, macWE);
  530.  
  531.     CalcWERects();    
  532.     AdjustBounds();
  533. }
  534.  
  535. /********************************************************\
  536.  AdjustBounds - change the size of the CWASTEText to
  537.      match that in the WASTE record
  538. \********************************************************/
  539.  
  540. void CWASTEText::AdjustBounds()
  541. {
  542.  
  543.     long          newHeight;
  544.     LongRect     viewRect;
  545.  
  546.     newHeight = GetHeight( 1, MAXLONG);
  547.     WEGetViewRect(&viewRect, macWE);
  548.     
  549.     bounds.left = bounds.top = 0;
  550.     bounds.bottom = newHeight;
  551.  
  552.     if (lineWidth > 0) 
  553.     {
  554.         bounds.right = lineWidth;
  555.     } else {
  556.         bounds.right = viewRect.right - viewRect.left;
  557.     }
  558.         
  559.     bounds.right = (bounds.right - 1) / hScale + 1;
  560.  
  561.     if (itsScrollPane != NULL) {
  562.         itsScrollPane->AdjustScrollMax();
  563.     }
  564. }
  565.  
  566. /********************************************************\
  567.  FindLine - return the line on which the character
  568.      at charPos is on.
  569. \********************************************************/
  570.  
  571. long CWASTEText::FindLine(long charPos)
  572. {
  573.     return _WEOffsetToLine(charPos, macWE);
  574. }
  575.  
  576. /********************************************************\
  577.  GetLength - return the length of the text
  578. \********************************************************/
  579.  
  580. long CWASTEText::GetLength()
  581. {
  582.     return WEGetTextLength(macWE);
  583. }
  584.  
  585. /********************************************************\
  586.  SetFontNumber - set the font of the selection
  587. \********************************************************/
  588.  
  589. void CWASTEText::SetFontNumber(short aFontNumber)
  590. {
  591.     TextStyle    style;
  592.     
  593.     style.tsFont = aFontNumber;
  594.     SetStyle( doFont, &style, TRUE);
  595. }
  596.  
  597. /********************************************************\
  598.  SetFontStyle - set the font style of the selection
  599. \********************************************************/
  600.  
  601. void CWASTEText::SetFontStyle(short aStyle)
  602. {
  603.     TextStyle    style;
  604.     short        mode = doFace;
  605.     
  606.     style.tsFace = aStyle;
  607.     if (aStyle != NOTHING)
  608.         mode += doToggle;
  609.     SetStyle( mode, &style, TRUE);
  610. }
  611.  
  612. /********************************************************\
  613.  SetFontSize - set the font size of the selection
  614. \********************************************************/
  615.  
  616. void CWASTEText::SetFontSize(short aSize)
  617. {
  618.     TextStyle    style;
  619.     
  620.     style.tsSize = aSize;
  621.     SetStyle( doSize, &style, TRUE);
  622. }
  623.  
  624. /********************************************************\
  625.  SetTextMode - currently not implemented
  626. \********************************************************/
  627.  
  628. void CWASTEText::SetTextMode(short aMode)
  629. {
  630.     return;
  631. }
  632.  
  633. /********************************************************\
  634.  SetAlignment - set the alignment
  635. \********************************************************/
  636.  
  637. void CWASTEText::SetAlignment(short anAlignment)
  638. {
  639.     WESetAlignment(anAlignment, macWE);
  640.     Refresh();
  641. }
  642.  
  643. /********************************************************\
  644.  SetAlignCmd - set the alignment
  645. \********************************************************/
  646.  
  647. void CWASTEText::SetAlignCmd(long anAlignCmd)
  648. {
  649.     short teAlign;
  650.     
  651.     alignCmd = anAlignCmd;
  652.     switch( alignCmd)
  653.     {
  654.         case cmdAlignLeft:
  655.             teAlign = weFlushDefault;
  656.             break;
  657.         case cmdAlignCenter:
  658.             teAlign = weCenter;
  659.             break;
  660.         case cmdAlignRight:
  661.             teAlign = weFlushRight;
  662.             break;
  663.         default:
  664.             teAlign = weFlushDefault;
  665.     }
  666.     SetAlignment( teAlign);
  667. }
  668.  
  669. /********************************************************\
  670.  SetSpacingCmd - not really supported
  671. \********************************************************/
  672.  
  673. void CWASTEText::SetSpacingCmd(long aSpacingCmd)
  674. {
  675.     spacingCmd = cmdSingleSpace;
  676.     
  677.     // only single-spaced text is supported.
  678.     
  679.   SetWholeLines(wholeLines);
  680.   CalcAperture();
  681.   AdjustBounds();
  682.  
  683. }
  684.  
  685. /********************************************************\
  686.  SetTheStyleScrap - set the style of a given range
  687.      caller disposes handle
  688. \********************************************************/
  689.  
  690. void CWASTEText::SetTheStyleScrap(long rangeStart, long rangeEnd,
  691.             StScrpHandle styleScrap, Boolean redraw)
  692. {
  693.     long selStart, selEnd;
  694.     
  695.     Prepare();
  696.     WEGetSelection(&selStart, &selEnd, macWE);
  697.     WESetSelection(rangeStart, rangeEnd, macWE);
  698.     WEUseStyleScrap(styleScrap, macWE);
  699.     WESetSelection(selStart, selEnd, macWE);
  700.     WECalText( macWE);
  701.     AdjustBounds();
  702. }
  703.  
  704. /********************************************************\
  705.  SetStyle - set the style of the current selection
  706. \********************************************************/
  707.  
  708. void CWASTEText::SetStyle(short mode, TextStyle *newStyle, Boolean redraw)
  709. {
  710.     Prepare();
  711.     WESetStyle( mode, newStyle, macWE);
  712.     WECalText( macWE);
  713.     SetSpacingCmd( spacingCmd);
  714.     SetWholeLines( wholeLines);
  715.     AdjustBounds();
  716. }
  717.  
  718. /********************************************************\
  719.  GetHeight - get the height of the indicated lines
  720. \********************************************************/
  721.  
  722. long CWASTEText::GetHeight(long startLine, long endLine)
  723. {
  724.     long height;
  725.     long nLines;
  726.     
  727.     nLines = GetNumLines();
  728.     if (endLine>nLines) endLine = nLines;
  729.     height = WEGetHeight( startLine - 1, endLine, macWE);
  730.  
  731.     return height;
  732. }
  733.  
  734. /********************************************************\
  735.  GetCharOffset - return offset of character at point in
  736.      frame coords
  737. \********************************************************/
  738.  
  739. long CWASTEText::GetCharOffset(LongPt *aPt)
  740. {
  741.     Point    qdPt;
  742.     LongPt lPt;
  743.     char edge;
  744.     
  745.     Prepare();
  746.     FrameToQD( aPt, &qdPt);
  747.     lPt.v = qdPt.v;
  748.     lPt.h = qdPt.h;
  749.     
  750.     return WEGetOffset( &lPt, &edge, macWE);
  751.     
  752. }
  753.  
  754. /********************************************************\
  755.  GetCharPoint - return the position of the character in
  756.      Frame coordinates
  757. \********************************************************/
  758.  
  759. void CWASTEText::GetCharPoint( long offset, LongPt *aPt)
  760. {
  761.     Point    qdPt;
  762.     LongPt lPt;
  763.     short lineHeight;
  764.     
  765.     ASSERT( offset <= MAXLONG);
  766.     
  767.     Prepare();
  768.     WEGetPoint(offset, &lPt, &lineHeight, macWE);
  769.     qdPt.h = lPt.h;
  770.     qdPt.v = lPt.v;
  771.     QDToFrame( qdPt, aPt);
  772. }
  773.  
  774. /********************************************************\
  775.  GetTextStyle - return style of selection
  776. \********************************************************/
  777.  
  778. void CWASTEText::GetTextStyle(short *whichAttributes, TextStyle *aStyle)
  779. {
  780.     WEContinuousStyle( whichAttributes, aStyle, macWE);
  781. }
  782.  
  783. /********************************************************\
  784.  GetCharStyle - return style of one character
  785. \********************************************************/
  786.  
  787. void CWASTEText::GetCharStyle(long charOffset, TextStyle *theStyle)
  788. {
  789.     long selStart, selEnd;
  790.     short mode = doAll;
  791.  
  792.     WEGetSelection(&selStart, &selEnd, macWE);
  793.     WESetSelection(charOffset, charOffset+1, macWE);
  794.     WEContinuousStyle(&mode, theStyle, macWE);
  795.     WESetSelection(selStart, selEnd, macWE);
  796. }
  797.  
  798. /********************************************************\
  799.  GetSpacingCmd - not really supported
  800. \********************************************************/
  801.  
  802. long CWASTEText::GetSpacingCmd(void)
  803. {
  804.     return spacingCmd;
  805. }
  806.  
  807. /********************************************************\
  808.  GetAlignCmd - not really supported
  809. \********************************************************/
  810.  
  811. long CWASTEText::GetAlignCmd(void)
  812. {
  813.     return alignCmd;
  814. }
  815.  
  816. /********************************************************\
  817.  GetTheStyleScrap -- get a scrap handle of the styles
  818.      of the selection
  819. \********************************************************/
  820.  
  821. StScrpHandle CWASTEText::GetTheStyleScrap(void)
  822. {
  823.     long selStart, selEnd;
  824.     StScrpHandle h;
  825.  
  826.     WEGetSelection(&selStart, &selEnd, macWE);
  827.  
  828.     h=(StScrpHandle)NewHandle(1);
  829.     WECopyRange(selStart, selEnd, NULL, h, macWE);
  830.     FailNIL(h); // shouldn't happen
  831.     
  832.     return h;
  833. }
  834.  
  835. /********************************************************\
  836.  GetNumLines - return the number of lines
  837. \********************************************************/
  838.  
  839. long CWASTEText::GetNumLines(void)
  840. {
  841.     long nLines = WECountLines(macWE);
  842.  
  843.     if (!GetLength()) return 0;
  844.     if (((char*)(*GetTextHandle()))[GetLength()-1] == 13)
  845.         nLines++;
  846.     return nLines;
  847. }
  848.  
  849. /********************************************************\
  850.  GetSelection - get the position of the start and end
  851.      of the selection
  852. \********************************************************/
  853.  
  854. void CWASTEText::GetSelection(long *selStart, long *selEnd)
  855. {
  856.     WEGetSelection(selStart, selEnd, macWE);
  857. }
  858.  
  859. /********************************************************\
  860.  HideSelection - not implemented
  861. \********************************************************/
  862.  
  863. void CWASTEText::HideSelection(Boolean hide, Boolean redraw)
  864. {
  865.     return;
  866. }
  867.  
  868. /********************************************************\
  869.  GetSteps - get the size of the scrolling steps
  870.      Step sizes hard coded in
  871. \********************************************************/
  872.  
  873. void CWASTEText::GetSteps(short *hStep, short *vStep)
  874. {
  875.     short        phStep, pvStep;
  876.  
  877.     CPanorama::GetSteps(&phStep, &pvStep);
  878.  
  879.     if (phStep == 1 && pvStep == 1 && hScale == 1 && vScale == 1)
  880.     {
  881.         *hStep = 4;
  882.         *vStep = 12;
  883.     }
  884.     else
  885.     {
  886.         *hStep = phStep;
  887.         *vStep = pvStep;
  888.     }
  889. }
  890.  
  891. /********************************************************\
  892.  AboutToPrint -- called right before printing
  893. \********************************************************/
  894.  
  895. void CWASTEText::AboutToPrint(short *firstPage, short *lastPage)
  896. {
  897.     CAbstractText::AboutToPrint(firstPage, lastPage);
  898. }
  899.  
  900. /********************************************************\
  901.  PrintPage -- called to print page
  902. \********************************************************/
  903.  
  904. void CWASTEText::PrintPage(short pageNum, short pageWidth, short pageHeight,
  905.             CPrinter *aPrinter)
  906. {
  907.     LongRect viewRect;    
  908.     OSErr err;
  909.     short oldFeature;
  910.  
  911.     err = WESetInfo(wePort, &qd.thePort, macWE);
  912.     // temporarily turn off off screen drawing
  913.     oldFeature = WEFeatureFlag(weFDrawOffscreen, weBitClear, macWE);
  914.  
  915.     if (printClip == clipPAGE) {        /* Expand viewRect to the size of a    */
  916.                                         /*   page. It will be restored by    */
  917.                                         /*   the DonePrinting() method.        */
  918.         WEGetViewRect(&viewRect, macWE);
  919.         viewRect.right = viewRect.left + pageWidth;
  920.         
  921.         if (wholeLines) {
  922.             viewRect.bottom = viewRect.top +
  923.                                             vScale * (pageHeight / vScale);
  924.         } else {
  925.             viewRect.bottom = viewRect.top + pageHeight;
  926.         }
  927.         WESetViewRect(&viewRect, macWE);
  928.     }
  929.  
  930.     CAbstractText::PrintPage(pageNum, pageWidth, pageHeight, aPrinter);
  931.  
  932.     err = WESetInfo(wePort, &macPort, macWE);
  933.     WEFeatureFlag(weFDrawOffscreen, oldFeature, macWE);
  934. }
  935.  
  936. /********************************************************\
  937.  DonePrinting - called when printing is finished
  938. \********************************************************/
  939.  
  940. void CWASTEText::DonePrinting()
  941. {
  942.     CAbstractText::DonePrinting();
  943.  
  944.     CalcWERects();
  945. }
  946.  
  947. /********************************************************\
  948.  Dawdle - do idle stuff
  949. \********************************************************/
  950.  
  951. void CWASTEText::Dawdle(long *maxSleep)
  952. {
  953.     if (editable && visible)
  954.     {
  955.         Prepare();
  956.         WEIdle(NULL, macWE);
  957.         *maxSleep = GetCaretTime();
  958.     }
  959. }
  960.  
  961. /********************************************************\
  962.  PutTo - not implemented
  963. \********************************************************/
  964.  
  965. void CWASTEText::PutTo(CStream& stream)
  966. {
  967.     return;
  968. }
  969.  
  970. /********************************************************\
  971.  GetFrom - not implemented
  972. \********************************************************/
  973.  
  974. void CWASTEText::GetFrom(CStream& stream)
  975. {
  976.     return;
  977. }
  978.  
  979. /********************************************************\
  980.  WEClickLoop - click loop routine
  981. \********************************************************/
  982.  
  983. static pascal Boolean    WEClickLoop(WEHandle hWE)
  984. {
  985.     Point        mouseLoc;
  986.     LongPt        longMouse;
  987.  
  988.     if (gWASTEText != NULL) {
  989.         GetMouse(&mouseLoc);
  990.         QDToLongPt( mouseLoc, &longMouse);
  991.         gWASTEText->AutoScroll( &longMouse);
  992.     }
  993.     return(TRUE);
  994. }
  995.  
  996.