home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 8 / IOPROG_8.ISO / soft / sdkplnet / mac / macnpsdk.sit / PluginSDK / Examples / PPViewText / Source / CFastTextEdit.cp next >
Encoding:
Text File  |  1996-07-09  |  4.1 KB  |  174 lines

  1. // ===========================================================================
  2. //    CFastTextEdit.cp                    ⌐1993 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    ### Still under moderate construction
  6. //            * Doesn't autoscroll while typing or selecting
  7. //            * Doesn't adjust to display whole lines
  8. //            * Doesn't undo
  9.  
  10. #ifdef PowerPlant_PCH
  11. #include PowerPlant_PCH
  12. #endif
  13.  
  14. #include "CFastTextEdit.h"
  15.  
  16. #include <LStream.h>
  17. #include <UTextTraits.h>
  18. #include <UDrawingState.h>
  19. #include <UMemoryMgr.h>
  20. #include <UKeyFilters.h>
  21. #include <PP_KeyCodes.h>
  22. #include <PP_Messages.h>
  23.  
  24. #ifndef __SCRAP__
  25. #include <Scrap.h>
  26. #endif
  27.  
  28. #ifndef __SCRIPT__
  29. #include <Script.h>
  30. #endif
  31.  
  32. #ifndef __TOOLUTILS__
  33. #include <ToolUtils.h>
  34. #endif
  35.  
  36.  
  37. // ---------------------------------------------------------------------------
  38. //        Ñ CreateTextEditStream
  39. // ---------------------------------------------------------------------------
  40. //    Create a new TextEdit object from the data in a Stream
  41.  
  42. CFastTextEdit*
  43. CFastTextEdit::CreateFastTextEditStream(
  44.     LStream    *inStream)
  45. {
  46.     return (new CFastTextEdit(inStream));
  47. }
  48.  
  49.  
  50. // ---------------------------------------------------------------------------
  51. //        Ñ CFastTextEdit
  52. // ---------------------------------------------------------------------------
  53. //    Default Contructor
  54.  
  55. CFastTextEdit::CFastTextEdit()
  56. :    LTextEdit()
  57. {
  58. }
  59.  
  60.  
  61. // ---------------------------------------------------------------------------
  62. //        Ñ CFastTextEdit
  63. // ---------------------------------------------------------------------------
  64. //    Construct from input parameters
  65.  
  66. CFastTextEdit::CFastTextEdit(
  67.     const SPaneInfo    &inPaneInfo,
  68.     const SViewInfo    &inViewInfo,
  69.     Uint16            inTextAttributes,
  70.     ResIDT            inTextTraitsID)
  71.         : LTextEdit( inPaneInfo, inViewInfo, inTextAttributes, inTextTraitsID )
  72. {
  73. }
  74.  
  75.  
  76. // ---------------------------------------------------------------------------
  77. //        Ñ CFastTextEdit(LStream*)
  78. // ---------------------------------------------------------------------------
  79. //    Contruct an TextEdit from the data in a Stream
  80.  
  81. CFastTextEdit::CFastTextEdit(
  82.     LStream    *inStream)
  83.         : LTextEdit(inStream)
  84. {
  85. }
  86.  
  87.  
  88. // ---------------------------------------------------------------------------
  89. //        Ñ ~CFastTextEdit
  90. // ---------------------------------------------------------------------------
  91. //    Destructor
  92.  
  93. CFastTextEdit::~CFastTextEdit()
  94. {
  95. }
  96.  
  97.  
  98. Boolean
  99. CFastTextEdit::FocusDraw()
  100. {
  101.     Boolean    focused = LView::FocusDraw();
  102.     if (focused) {
  103.         StColorPenState::Normalize();
  104.         UTextTraits::SetPortTextTraits(mTextTraitsID);
  105.     }
  106.     
  107.     return focused;
  108. }
  109.  
  110.  
  111. // ---------------------------------------------------------------------------
  112. //        Ñ DrawSelf
  113. // ---------------------------------------------------------------------------
  114. //    Draw a TextEdit
  115.  
  116. void
  117. CFastTextEdit::DrawSelf()
  118. {
  119.     Rect    frame;
  120.     CalcLocalFrameRect(frame);
  121.     
  122.         // A Mac TERec stores a pointer to its owner port  We have to
  123.         // change it to the current port in case we are drawing into
  124.         // a port that is not the owner port. This happens when we are
  125.         // printing or drawing into an offscreen port.
  126.         
  127.     GrafPtr    savePort = (**mTextEditH).inPort;
  128.     (**mTextEditH).inPort = UQDGlobals::GetCurrentPort();
  129.  
  130.     ::TEUpdate(&frame, mTextEditH);
  131.     
  132.     (**mTextEditH).inPort = savePort;
  133. }
  134.  
  135.  
  136.  
  137.  
  138. // ---------------------------------------------------------------------------
  139. //        Ñ ScrollImageBy
  140. // ---------------------------------------------------------------------------
  141. //    Scroll the Text
  142.  
  143. void
  144. CFastTextEdit::ScrollImageBy(
  145.     Int32        inLeftDelta,        // Pixels to scroll horizontally
  146.     Int32        inTopDelta,            // Pixels to scroll vertically
  147.     Boolean        inRefresh)
  148. {
  149.     OffsetRect(&(**mTextEditH).viewRect, inLeftDelta, inTopDelta);
  150.  
  151.     LView::ScrollImageBy(inLeftDelta, inTopDelta, false);
  152.     
  153.     if( inRefresh )
  154.         Draw(nil);
  155. }
  156.  
  157.  
  158.  
  159.  
  160. // ---------------------------------------------------------------------------
  161. //        Ñ SpendTime
  162. // ---------------------------------------------------------------------------
  163. //    Idle time: Flash the insertion cursor
  164.  
  165. void
  166. CFastTextEdit::SpendTime(
  167.     const EventRecord&    /* inMacEvent */)
  168. {
  169.     if (FocusDraw() && IsVisible() && HasAttribute(textAttr_Selectable)) {
  170.         ::TEIdle(mTextEditH);
  171.     }
  172. }
  173.  
  174.