home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Examples / Text / Textension / Include / Formatter.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  5.3 KB  |  207 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Formatter.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Essam Zaky
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>      1/4/94    EZ        clean up
  13.          <1>      1/4/94    EZ        first checked in
  14.  
  15. */
  16.  
  17. #ifndef _Formatter_
  18. #define _Formatter_
  19.  
  20. #ifndef _ToolBoxDump_
  21. #include "ToolBoxDump.h"
  22. #endif
  23.  
  24. #ifndef _Array_
  25. #include "Array.h"
  26. #endif
  27.  
  28. #ifndef _RunsRanges_
  29. #include "RunsRanges.h"
  30. #endif
  31.  
  32. #ifndef _Frames_
  33. #include "Frames.h"
  34. #endif
  35.  
  36. #ifdef txtnRulers
  37. #ifndef _RulersRanges_
  38. #include "RulersRanges.h"
  39. #endif
  40.  
  41. #ifndef _RulerObject_
  42. #include "RulerObject.h"
  43. #endif
  44. #endif
  45.  
  46. #ifndef _ObjectsRanges_
  47. #include "ObjectsRanges.h"//for CRanges
  48. #endif
  49.  
  50. #ifndef _StyledText_
  51. #include "StyledText.h"
  52. #endif
  53.  
  54. //***************************************************************************************************
  55.  
  56. struct TLineInfo{
  57.     long    lineEnd;
  58.     TLineHiteInfo lineHiteInfo;
  59. };
  60. typedef    TLineInfo*    TLineInfoPtr;
  61.  
  62.  
  63. struct TFormattingInfo {
  64.     long lineIndex; //input/output
  65.     long nextLineStart; //output
  66.     long lastFormatChar; //input/output
  67. };
  68.  
  69. //***************************************************************************************************
  70.  
  71. class    CFormatter    : public HandleObject {
  72. public:
  73.     CFormatter();
  74.     
  75.     void IFormatter();
  76.     
  77.     //•should be called once after IFormatter and before any call to other member of CFormatter
  78.     #ifdef txtnRulers
  79.     void SetHandlers(CStyledText* itsStyledText, CFrames* theFrames, CRulersRanges* rulersRanges, TSize sizeInfo);
  80.     #else
  81.     void SetHandlers(CStyledText* itsStyledText, CFrames* theFrames, TSize sizeInfo);
  82.     #endif
  83.     
  84.     void Free();
  85.     void FreeData(Boolean emptyLine =true);
  86.     
  87.     #ifdef txtnNever
  88.     virtual CFormatter* CreateEmptyClone();
  89.     #endif
  90.  
  91.     OSErr ReserveLines(long extraLines);
  92.     
  93.     void Compact();
  94.     
  95.     inline void DisableFormatting()  {--fFormatLevel;}
  96.     inline void EnableFormatting() {++fFormatLevel;}
  97.     
  98.     inline long CountLines() const {return fLastLineIndex+1;}
  99.  
  100.     virtual    OSErr Format(long startChar = 0, long endChar = -1, long* firstLine = nil, long* lastLine = nil); 
  101.     virtual OSErr ReplaceRange(long offset, long oldLen, long newLen
  102.                                                     , long* firstLine, long* lastLine);
  103.     
  104.     //void RecalcLinesHite(long firstLine, long lastLine);
  105.     
  106.     inline void SetCRFlag(Boolean newFlag) {fCR = newFlag;}
  107.     //"Format" has to be called after calling this meth, crOnly flag overrides the format width.
  108.     inline Boolean GetCRFlag() {return fCR;}
  109.     
  110.     Boolean IsLineFeed(long offset) const;
  111.     
  112.     //••inlines to public some fLineEnds services
  113.     inline long Offset2Line(TOffset lineOffset) const
  114.         {return fLineEnds->Offset2RangeIndex(lineOffset);}
  115.  
  116.     inline long    GetLineStart(long lineNo) const {return fLineEnds->GetRangeStart(lineNo);}
  117.     inline long    GetLineEnd(long lineNo) const {return fLineEnds->GetRangeEnd(lineNo);}
  118.     void GetLineRange(long lineNo, TOffsetRange* range);
  119.     
  120.     inline Boolean IsLineStart(long offset, long lineNo = -1) const
  121.         {return fLineEnds->IsRangeStart(offset, lineNo);}
  122.     inline Boolean IsLineEmpty(long lineNo) const {return fLineEnds->IsRangeEmpty(lineNo);}
  123.     
  124.     #ifdef txtnDebug
  125.     void CheckCoherence(long count);
  126.     #endif
  127.     
  128. protected :
  129.     CStyledText* fStyledText;
  130.     
  131.     #ifdef txtnRulers
  132.     CRulersRanges*    fRulersRanges;
  133.     #endif
  134.     
  135.     CFrames* fFrames;
  136.     CFrameFormatter* fFrameFormatter;
  137.     
  138.     CRanges* fLineEnds;
  139.     
  140.     CRunsRanges*  fRunsRanges;
  141.     
  142.     Boolean fCR;
  143.  
  144.     //note that newLineInfo is not constant, it returns the actual values (which may be modified by a descendent)
  145.     #ifdef txtnMultiFrames
  146.     virtual void SetLineInfo(TLineInfo* newLineInfo, TFormattingInfo* formatInfo, Boolean allowReflow = true);
  147.     #else
  148.     virtual void SetLineInfo(TLineInfo* newLineInfo, TFormattingInfo* formatInfo);
  149.     #endif
  150.     
  151.     virtual OSErr    InsertLine(TLineInfo* newLineInfo, TFormattingInfo* formatInfo);
  152.  
  153.     virtual void BreakLine(long startBreak, short formattingWidth, TLineInfo* lineInfo);
  154.     
  155.     virtual short BreakVisibleChars(long lineStart, long runStart, short runLen, Fixed* widthAvail
  156.                                                                 , CRunObject* runObj);
  157.  
  158.     virtual short BreakRun(long lineStart, long runStart, short runLen, Fixed* widthAvail
  159.                                                     , CRunObject* runObj);
  160.     
  161.     virtual short BreakCtrlChar(long offset, Fixed* widthAvail);
  162.     
  163. private:
  164.     short fFormatLevel; //to disable formatting
  165.     
  166.     #ifdef txtnRulers
  167.     CRulerObject* fParagraphRuler;
  168.     #endif
  169.     
  170.     Fixed    fLineFormattingWidth;
  171.     
  172.     long fLastLineIndex;
  173.     
  174.     #ifdef txtnAdvRulers
  175.     TPendingTab    fPendingTab;
  176.     Fixed    fTabMungedWidth;
  177.     #endif
  178.     
  179.     #ifdef txtnMultiFrames
  180.     void CheckFramesReflow(const CFormatReflowLines* reflowInfo
  181.                                                     , TFormattingInfo* formatInfo, long* nextFormatOffset);
  182.     #endif
  183.     
  184.     Boolean AppendEmptyLine();
  185.     OSErr    FormatRange(long startChar, long endChar, long* firstLine, long* lastLine);
  186.     OSErr    FormatAll();
  187.     
  188.     #ifdef txtnMultiFrames
  189.     void    RemoveLines(long firstLine, long count, CFormatReflowLines* reflowInfo);
  190.     long    RemoveFormattedLines(long lastFormattedLine, CFormatReflowLines* reflowInfo);
  191.     #else
  192.     void    RemoveLines(long firstLine, long count);
  193.     long    RemoveFormattedLines(long lastFormattedLine);
  194.     #endif
  195.  
  196.     #ifdef txtnAdvRulers
  197.     short BreakAlignTabChars(long lineStart, long runStart, short runLen, Fixed* widthAvail
  198.                                                         , CRunObject* runObj);
  199.     #endif
  200.     
  201.     void     CalcCharsHite(long charsOffset, short charsCount, TLineHiteInfo* lineHiteInfo) const;
  202. };
  203. //***************************************************************************************************
  204.  
  205.  
  206. #endif
  207.