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 / Frames.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  10.2 KB  |  389 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Frames.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 _Frames_
  18. #define _Frames_
  19.  
  20. #ifndef _ToolBoxDump_
  21. #include "ToolBoxDump.h"
  22. #endif
  23.  
  24. #ifndef _TextensionCommon_
  25. #include "TextensionCommon.h"
  26. #endif
  27.  
  28. #ifndef _Array_
  29. #include "Array.h"
  30. #endif
  31.  
  32. #ifndef _FrameFormatter_
  33. #include "FrameFormatter.h"
  34. #endif
  35.  
  36. //***************************************************************************************************
  37.  
  38. /*TSectLines is the element type of the array filled by CFrames::SectLines.
  39. an element with countLines == 0 ===> firstLineRect is a rect with no lines
  40. (probably should be erased by the caller), in this case firstLine and lineAscent are undefined.
  41. */
  42. struct TSectLines {
  43.     long    firstLine;
  44.     Rect    firstLineRect; //rect hite = lineHite
  45.     short    countLines;
  46.     short lineAscent;
  47. };
  48. typedef TSectLines* TSectLinesPtr;
  49. //*************************************************************************************************
  50.  
  51.  
  52. #ifdef txtnMultiFrames
  53. struct TUniformSectFrames {
  54.         long fFirstFrame;
  55.         short fCountAcross;
  56.         long fLastFrame;
  57.         short fRowFrames;
  58.  
  59.         short fCurrentAcross;
  60. };
  61.  
  62. const short kMaxSectedFrames = 64;
  63. struct TMultiformFrames {
  64.     short fCountSected;
  65.     long fSectedFrames[kMaxSectedFrames];
  66. };
  67.  
  68. /*CSectFrames is returned from CFrames::SectFrames, the caller will loop on each frame by calling
  69. CSectFrames::GetNextFrame , GetNextFrame returns a val < 0 if no next.*/
  70.  
  71. class CSectFrames : private SingleObject {
  72.     public:
  73.         TUniformSectFrames fUniformFrames;
  74.         
  75.         CSectFrames() {
  76.             fCurrentFrame = -2;
  77.             fMultiformFrames.fCountSected = 0;
  78.         }
  79.         
  80.         void SetUniform(long firstFrame, short countAcross, long lastFrame, short rowFrames);
  81.         void AppendMultiform(long frameNo);
  82.         
  83.         inline Boolean IsEmpty() const {return fCurrentFrame == -2;}
  84.         
  85.         long GetFirstFrame() const;
  86.         long GetLastFrame() const;
  87.         
  88.         long GetNextFrame(); //returns < 0 if no next
  89.     
  90.     private:
  91.         TMultiformFrames    fMultiformFrames;
  92.  
  93.         long fCurrentFrame;
  94.         
  95.         inline IsUniform() const {return fMultiformFrames.fCountSected < 0;}
  96. };
  97. //*************************************************************************************************
  98. #endif
  99.  
  100.  
  101. //constants for CDisplayChanges::fKind
  102. const short kNoChanges = 0;
  103.  
  104. const short kNeedHReformat = 1;
  105. const short kNeedVReformat = 2;
  106. const short kNeedPartialReformat = 4;
  107.  
  108. const short kRedrawAll = 8;
  109. const short kCheckSize = 16;
  110.  
  111. const short kCheckUpdate = 32;
  112.  
  113. const short kScrollSelection = 64;
  114.  
  115. //*************************************************************************************************
  116.  
  117. class CDisplayChanges : private SingleObject {
  118.     public :
  119.         CDisplayChanges();
  120.         
  121.         inline void SetChangesKind(short result) {fKind |= result;}
  122.         inline short GetChangesKind() const {return fKind;}
  123.         
  124.         void SetFormatRange(const TOffsetPair* formatRange);
  125.         void GetFormatRange(TOffsetPair* formatRange) const;
  126.     
  127.     private:
  128.         short fKind;
  129.         
  130.         TOffsetPair fFormatRange;
  131. };
  132. //*************************************************************************************************
  133.  
  134. struct TCell {
  135.     long row;
  136.     short column;
  137. };
  138. //*************************************************************************************************
  139.  
  140. #ifdef txtnNever
  141. //constants for SyncTextFrameHite
  142. const short kNoShrink = 1;
  143. const short kNoExpand = 2;
  144. #endif
  145. //*************************************************************************************************
  146.  
  147.  
  148.  
  149. inline void InitFrames() {} //should be called atr the start
  150. inline void EndFrames() {} //should be called atr the end
  151.  
  152. //*************************************************************************************************
  153.  
  154.  
  155. class    CFrames    : public HandleObject {
  156. public:
  157.     CFrames();
  158.     
  159.     void IFrames();
  160.  
  161.     virtual void Free();
  162.     virtual void FreeData();
  163.     
  164.     inline CFrameFormatter* GetFrameFormatter() {return fFrameFormatter;}
  165.     
  166.     inline long GetCountFrames() const {return fFrameFormatter->GetCountFrames();}
  167.             
  168.     #ifdef txtnScal
  169.     virtual void SetScale(Point numer, Point denom);
  170.     void GetScale(Point* numer, Point* denom) const;
  171.     #endif
  172.     
  173.     inline void SetDirection(char newDirection) {fDirection = newDirection;}
  174.     
  175.     #ifdef txtnScal
  176.     virtual void GetTextFrameSize(LongPoint* theSize, Boolean scaled = true, long frameNo = 0) const = 0;
  177.     #else
  178.     virtual void GetTextFrameSize(LongPoint* theSize, long frameNo = 0) const = 0;
  179.     #endif
  180.     
  181.     virtual void SetTextFrameSize(const LongPoint* newSize, CDisplayChanges* changes = nil, long frameNo = 0) = 0;
  182.     //•newSize is not scaled
  183.     
  184.     #ifdef txtnNever
  185.     virtual Boolean SyncTextFrameHite(Rect* rect2Update = nil, short flags = 0, long frameNo = 0);
  186.     #endif
  187.     
  188.     #ifdef txtnScal
  189.     virtual void GetAbsFrameRect(long frameNo, TxtnLongRect* absRect, Boolean scaled = true) const;
  190.  
  191.     virtual void GetAbsTextFrame(long frameNo, TxtnLongRect* absRect, Boolean scaled = true) const;
  192.     
  193.     void GetTextFrame(long frameNo, Rect* theRect, Boolean scaled = true) const;
  194.     //in draw coord
  195.     
  196.     void GetFrameRect(long frameNo, Rect* theRect, Boolean scaled = true) const;
  197.     //in draw coord
  198.  
  199.     #else
  200.     virtual void GetAbsFrameRect(long frameNo, TxtnLongRect* absRect) const;
  201.  
  202.     virtual void GetAbsTextFrame(long frameNo, TxtnLongRect* absRect) const;
  203.     
  204.     void GetTextFrame(long frameNo, Rect* theRect) const;
  205.     //in draw coord
  206.     
  207.     void GetFrameRect(long frameNo, Rect* theRect) const;
  208.     //in draw coord
  209.     #endif
  210.     
  211.     virtual void SetMargins(const Rect* newMargins, CDisplayChanges* changes = nil); //newMargins not scaled
  212.     
  213.     #ifdef txtnScal
  214.     virtual void GetMargins(Rect* margins, Boolean scaled = true) const;
  215.     #else
  216.     virtual void GetMargins(Rect* margins) const;
  217.     #endif
  218.  
  219.     virtual long GetTotalHite() const = 0;
  220.     virtual long GetTotalWidth() const = 0;
  221.     
  222.     #ifdef txtnMultiFrames
  223.     virtual void InvalFramePart(long frameNo, TFrameEditFlags invalFlags, long invalMessage = 0
  224.                                                         , RgnHandle theClip = nil);
  225.     #endif
  226.     
  227.     //••• formatter can optimize for non variable size Frames
  228.     virtual short GetLineFormatWidth(long lineNo) const = 0;
  229.     virtual short GetLineMaxWidth(long lineNo) const = 0;
  230.  
  231.     long HDraw2Abs(long hCoord) const;
  232.     long VDraw2Abs(long vCoord) const;
  233.     short HAbs2Draw(long hCoord) const;
  234.     short VAbs2Draw(long vCoord) const;
  235.     void Abs2Draw(const TxtnLongRect* absRect, Rect* drawRect) const;
  236.     void Draw2Abs(const Rect* drawRect, TxtnLongRect* absRect) const;
  237.     Point Abs2Draw(const LongPoint* absPoint) const;
  238.     void Draw2Abs(Point thePoint, LongPoint* absPoint) const;
  239.     
  240.     void FramesScrolled(long hPix, long vPix);
  241.     inline long GetVScrolledPix()  const {return fVScrolledPix;}
  242.     inline long GetHScrolledPix()  const {return fHScrolledPix;}
  243.     
  244.     void SetDrawOrigin(long h, long v);
  245.     void GetDrawOrigin(long* h, long* v) const;
  246.     
  247.     void SetFramesOrigin(long h, long v);
  248.     void GetFramesOrigin(long* h, long* v) const;
  249.     
  250.     long Point2Line(Point* thePt, Boolean* outside, Boolean* vOverflow) const;
  251.     /* -•returns a val < 0 if thePt is not in any frame
  252.         -thePt (in and out) is in draw coord
  253.         -in output thePt is set to the topLeft of the line in Draw coord (except if outside is true).
  254.         -outside is true if thePt is outside the text frame
  255.         -vOverflow is true if thePt->v is > frame last line (in this case the fn result is the last line in the frame)
  256.     */
  257.     
  258.     void Line2Point(long lineNo, LongPoint* absPt) const;
  259.     Point Line2Point(long lineNo) const;
  260.     
  261.     virtual long Point2Frame(const LongPoint* thePt) const = 0; //thePt is in abs coord
  262.     //•returns a value < 0 if the point is not in any frame
  263.     
  264.     long Point2Frame(Point thePt) const;
  265.     //thePt is in draw coord
  266.     
  267.     #ifdef txtnMultiFrames
  268.     virtual void SectFrames(const Rect* theRect, CSectFrames* sectedFrames) const = 0;
  269.     //theRect is in draw coord
  270.     #endif
  271.     
  272.     Boolean SectLines(Rect* theRect, long frameNo, short* countLines, CArray* sectedLines) const;
  273.     
  274. protected:
  275.     CFrameFormatter* fFrameFormatter;
  276.  
  277.     #ifdef txtnScal
  278.     Point fNumer;
  279.     Point fDenom;
  280.     #endif
  281.     
  282.     char    fDirection;
  283.     
  284.     long    fVScrolledPix;
  285.     long    fHScrolledPix;
  286.     
  287.     LongPoint fDrawOrigin;
  288.     LongPoint fFramesOrigin;
  289.     
  290.     virtual void CreateFrameFormatter() = 0;
  291.     
  292. private:
  293.     Rect    fMargins;
  294.     
  295.     #ifdef txtnScal
  296.     Rect    fScaledMargins;
  297.     #endif
  298.  
  299.     #ifdef txtnScal
  300.     void RecalcScaledMargins();
  301.     #endif
  302. };
  303. //*************************************************************************************************
  304.  
  305. class CMonoSizeFrames : public CFrames {
  306. public:
  307.     CMonoSizeFrames();
  308.     
  309.     void IMonoSizeFrames();
  310.     
  311.     //•override
  312.     
  313.     #ifdef txtnScal
  314.     virtual void SetScale(Point numer, Point denom);
  315.     #endif
  316.     
  317.     virtual void SetTextFrameSize(const LongPoint* newSize, CDisplayChanges* changes = nil, long frameNo = 0);
  318.     
  319.     #ifdef txtnScal
  320.     virtual void GetTextFrameSize(LongPoint* theSize, Boolean scaled = true, long frameNo = 0) const;
  321.     #else
  322.     virtual void GetTextFrameSize(LongPoint* theSize, long frameNo = 0) const;
  323.     #endif
  324.  
  325.     virtual long GetTotalHite() const = 0;
  326.     virtual long GetTotalWidth() const = 0;
  327.  
  328.     virtual short GetLineFormatWidth(long lineNo) const;
  329.     virtual short GetLineMaxWidth(long lineNo) const;
  330.     
  331.     virtual long Point2Frame(const LongPoint* thePt) const = 0; //thePt is in abs coord
  332.     
  333.     #ifdef txtnMultiFrames
  334.     virtual void SectFrames(const Rect* theRect, CSectFrames* sectedFrames) const = 0;
  335.     //theRect is in draw coord
  336.     #endif
  337.     
  338. protected:
  339.     LongPoint fTextFrameSize;
  340.     
  341.     #ifdef txtnScal
  342.     LongPoint fScaledTextFrameSize;
  343.     #endif
  344.     
  345.     //•override
  346.     virtual void CreateFrameFormatter() = 0;
  347.     
  348. private:
  349.     #ifdef txtnScal
  350.     void RecalcScaledSize();
  351.     #endif
  352. };
  353. //*************************************************************************************************
  354.  
  355. /*
  356. -CMonoFrameFrames may be called with 0 vertical in SetTextFrameSize ==> unlimited hite
  357. */
  358. class CMonoFrame : public CMonoSizeFrames {
  359. public:
  360.     CMonoFrame();
  361.     
  362.     inline void IMonoFrame() {this->IMonoSizeFrames();}
  363.     
  364.     //•override
  365.  
  366.     virtual void SetTextFrameSize(const LongPoint* newSize, CDisplayChanges* changes = nil, long frameNo = 0);
  367.  
  368.     virtual long GetTotalHite() const;
  369.     virtual long GetTotalWidth() const;
  370.  
  371.     #ifdef txtnMultiFrames
  372.     virtual void SectFrames(const Rect* theRect, CSectFrames* sectedFrames) const;
  373.     #endif
  374.     
  375.     virtual long Point2Frame(const LongPoint* thePt) const;
  376.     //•returns a value < 0 if the point is not in the frame
  377.     
  378.     //•own members
  379.  
  380. protected:
  381.     virtual void CreateFrameFormatter();
  382.  
  383. private:
  384. };
  385. //*************************************************************************************************
  386.  
  387.  
  388. #endif
  389.