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

  1. /*
  2.     File:        LinkedFrames.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.          <4>      1/5/94    EZ        fix compilation problems, this file didn't compile for long time
  13.          <3>      1/5/94    EZ        don't compile if txtnMultiFrames compilation var is not defined
  14.          <2>      1/4/94    EZ        clean up
  15.          <1>      1/4/94    EZ        first checked in
  16.  
  17. */
  18.  
  19. #ifdef txtnMultiFrames
  20.  
  21. #ifndef _LinkedFrames_
  22. #define _LinkedFrames_
  23.  
  24. #ifndef _ToolBoxDump_
  25. #include "ToolBoxDump.h"
  26. #endif
  27.  
  28. #ifndef _TextensionCommon_
  29. #include "TextensionCommon.h"
  30. #endif
  31.  
  32. #ifndef _Array_
  33. #include "Array.h"
  34. #endif
  35.  
  36. #ifndef _Pages_
  37. #include "Pages.h"
  38. #endif
  39.  
  40. #ifndef _TextensionCommand_
  41. #include "TextensionCommand.h"
  42. #endif
  43. //***************************************************************************************************
  44.  
  45.  
  46. struct TLinkedFrameInfo {
  47.     long top;
  48.     long left;
  49. };
  50. typedef TLinkedFrameInfo* TLinkedFrameInfoPtr;
  51. //*************************************************************************************************
  52.  
  53.  
  54. //••constants for CLinkedFramesCommand command ids
  55.  
  56. const short kNewFrameCommand = 5001; //works on 1 frame
  57. const short kDeleteFramesCommand = 5002; //works on list of frames
  58. const short kModifyFrameCommand = 5003; //works on 1 frame
  59. const short kOffsetFramesCommand = 5004; //works on list of frames
  60. //*************************************************************************************************
  61.  
  62.  
  63. //frameHite and frameWidth are not scaled
  64. struct TFrameFormatInfo {
  65.     short frameHite;
  66.     short frameWidth;
  67. };
  68. typedef TFrameFormatInfo* TFrameFormatInfoPtr;
  69.  
  70. //*************************************************************************************************
  71.  
  72. class    CLongArray    :    public    CLongTagArray {
  73. //Array of "long" elements
  74.     public:
  75.         CLongArray();
  76.         
  77.         inline void ILongArray(short moreElementsCount = 0)
  78.             {this->IArray(sizeof(long), moreElementsCount);}
  79.         
  80.         OSErr AppendValue(long theValue);
  81.             
  82.         long GetValue(long index) const;
  83.  
  84.         void Sort(); //ascending order
  85.         
  86.     private:
  87.  
  88. };
  89. //***************************************************************************************************
  90.  
  91.  
  92. class CVariableSizeFrameFormatter : public CMultiFrameFormatter {
  93.     public:
  94.         CVariableSizeFrameFormatter();
  95.         
  96.         void IVariableSizeFrameFormatter();
  97.         
  98.         //•override
  99.         virtual void Free();
  100.         virtual void FreeData();
  101.         
  102.         virtual void SetFrameHite(long frameNo, short newHite);
  103.             
  104.         virtual short GetFrameHite(long frameNo) const;
  105.  
  106.         virtual long GetCountFrames() const;
  107.         
  108.         virtual Boolean GetFrameLineRange(long frameNo, TOffsetPair* frameLines) const;
  109.                     
  110.         virtual Boolean VariableSizeFrames() const;
  111.  
  112.         //•own members
  113.         inline long GetCountFilledFrames() const {return CMultiFrameFormatter::GetCountFrames();}
  114.         //frames containing some text
  115.         
  116.         short GetFrameWidth(long frameNo) const;
  117.  
  118.         OSErr AddUserFrame(long frameNo, short width, short hite, TOffsetPair* lines2Format =nil);
  119.         //add at the "frameNo", returns in lines2Format the lines needing formating, -1 in lines2Format->firstOffset if none
  120.         
  121.         void DeleteUserFrame(long frameNo, TOffsetPair* lines2Format);
  122.         //returns in lines2Format the lines needing formating, -1 in lines2Format->firstOffset if none
  123.         
  124.         void SetFrameSize(long frameNo, short width, short hite, TOffsetPair* lines2Format =nil);
  125.         
  126.         void DeleteAllUserFrames();
  127.  
  128.     protected:
  129.         //•override
  130.         virtual Boolean BreakFrame(long frameNo, short* pixReflow, TOffsetPair* linesReflow
  131.                                                             , CFormatReflowLines* formatReflowLines);
  132.         virtual OSErr AppendFrame(short framePix, long lastLine =-1);
  133.         
  134.         //•own members
  135.         
  136.     private:
  137.         CArray* fFrames; //array of TFrameFormatInfo
  138.         
  139.         void FrameChangedSize(long frameNo, TOffsetPair* lines2Format);
  140. };
  141. //*************************************************************************************************
  142.  
  143.  
  144. /*CVariableSizeFrames manages frames of variable size and with no rule of position of a frame wrt to another
  145. , primarily done for Linked frames in CW.
  146. will create a frame formatter of type "CVariableSizeFrameFormatter". CVariableSizeFrameFormatter will keep
  147. the non scaled width and hite for each frame which are necessary for vertical formatting of variable size frames.
  148. CVariableSizeFrames will keep "TLinkedFrameInfo" for each frame.
  149. */
  150.  
  151. class CVariableSizeFrames : public CFrames {
  152.     public:
  153.         CVariableSizeFrames();
  154.         
  155.         void IVariableSizeFrames();
  156.         
  157.         //•override
  158.         virtual void Free();
  159.         virtual void FreeData();
  160.         
  161.         #ifdef txtnScal
  162.         virtual void GetAbsFrameRect(long frameNo, TxtnLongRect* absRect, Boolean scaled = true) const;
  163.         #else
  164.         virtual void GetAbsFrameRect(long frameNo, TxtnLongRect* absRect) const;
  165.         #endif
  166.         
  167.         virtual void SetTextFrameSize(const LongPoint* newSize, CDisplayChanges* changes = nil, long frameNo = 0);
  168.         
  169.         #ifdef txtnScal
  170.         virtual void GetTextFrameSize(LongPoint* theSize, Boolean scaled = true, long frameNo = 0) const;
  171.         #else
  172.         virtual void GetTextFrameSize(LongPoint* theSize, long frameNo = 0) const;
  173.         #endif
  174.         
  175.         virtual long GetTotalHite() const;
  176.         virtual long GetTotalWidth() const;
  177.  
  178.         virtual short GetLineFormatWidth(long lineNo) const;
  179.         virtual short GetLineMaxWidth(long lineNo) const;
  180.         
  181.         virtual long Point2Frame(const LongPoint* thePt) const; //thePt is in abs coord
  182.         //•returns a value < 0 if the point is not in any frame
  183.  
  184.         virtual void SectFrames(const Rect* theRect, CSectFrames* sectedFrames) const;
  185.         //theRect is in draw coord
  186.         
  187.         //•own members
  188.         
  189.         OSErr AddUserFrame(long frameNo, TxtnLongRect* absRect, CDisplayChanges* changes = nil);
  190.         //add at the "frameNo", absRect is the abs text bounds
  191.         
  192.         void DeleteUserFrame(long frameNo, CDisplayChanges* changes);
  193.         //delete at the "frameNo"
  194.  
  195.         void SetAbsTextFrame(long frameNo, const TxtnLongRect* absRect, CDisplayChanges* changes = nil);
  196.         //•absRect is not scaled
  197.         
  198.         Boolean IsLastFrameOverflow() const;
  199.         
  200.         void DeleteAllUserFrames();
  201.         
  202.     protected:
  203.  
  204.         //•override
  205.         virtual void CreateFrameFormatter();
  206.         
  207.     private:
  208.         CVariableSizeFrameFormatter* fVSFrameFormatter; //a ref is kept to avoid type casting
  209.         CArray* fFrames; //array of TLinkedFrameInfo
  210. };
  211. //*************************************************************************************************
  212.  
  213.  
  214.  
  215.  
  216.  
  217. struct TFrameCmdData {
  218.     long frameNo;
  219.     TxtnLongRect textBounds;
  220. };
  221. typedef TFrameCmdData* TFrameCmdDataPtr;
  222. //*************************************************************************************************
  223.  
  224. class CLinkedFramesCommand : public CTextensionCommand {
  225.     public:
  226.         CLinkedFramesCommand();
  227.         
  228.         void ILinkedFramesCommand(CTextension* textension, short theCmd
  229.                                                             , short countFrames, Boolean framesExists);
  230.         
  231.         //•own
  232.         inline short GetCmdCountFrames() const {return fCountFrames;}
  233.         inline Boolean FramesExist() const {return fFramesExist;}
  234.  
  235.         virtual void GetIndFrameCmdData(short frameIndex, TFrameCmdData* frameData) const = 0;
  236.         
  237.     protected:
  238.         CVariableSizeFrames* fFramesHandler;
  239.         short fCountFrames;
  240.  
  241.         //•override
  242.         virtual OSErr DoIt(short* userAction);
  243.         virtual OSErr UndoIt(short* userAction);
  244.         virtual OSErr RedoIt(short* userAction);
  245.         
  246.         //•own
  247.         virtual OSErr DoMainAction(const TFrameCmdData* frameData, short frameIndex
  248.                                                             , Boolean isUndo, CDisplayChanges* displayChanges) = 0;
  249.         
  250.         virtual char GetFlags() const;
  251.                                         
  252.     private:
  253.         Boolean fFramesExist;
  254.         char fFlags;
  255.         
  256.         OSErr CommonAction(short* userAction);
  257. };
  258. //**************************************************************************************************
  259.  
  260.  
  261. class CMonoFrameCommand : public CLinkedFramesCommand {
  262.     public:
  263.         CMonoFrameCommand();
  264.         
  265.         void IMonoFrameCommand(CTextension* textension, short theCmd, const TFrameCmdData* frameData
  266.                                                         , Boolean framesExist);
  267.         
  268.         //•override
  269.         virtual void GetIndFrameCmdData(short frameIndex, TFrameCmdData* frameData) const;
  270.  
  271.     protected:
  272.         //•override
  273.         virtual OSErr DoMainAction(const TFrameCmdData* frameData, short frameIndex
  274.                                                         , Boolean isUndo, CDisplayChanges* displayChanges) = 0;
  275.         
  276.     private:
  277.         TFrameCmdData fFrameCmdData;
  278. };
  279. //**************************************************************************************************
  280.  
  281.  
  282. class CMultiFrameCommand : public CLinkedFramesCommand {
  283.     public:
  284.         CMultiFrameCommand();
  285.         
  286.         OSErr IMultiFrameCommand(CTextension* textension, short theCmd
  287.                                                     , CLongArray* cmdFrames, Boolean framesExist);
  288.         
  289.         //•override
  290.         virtual void Free();
  291.     
  292.         virtual void GetIndFrameCmdData(short frameIndex, TFrameCmdData* frameData) const;
  293.  
  294.     protected:
  295.         //•override
  296.         virtual OSErr DoMainAction(const TFrameCmdData* frameData, short frameIndex
  297.                                                         , Boolean isUndo, CDisplayChanges* displayChanges) = 0;
  298.         
  299.     private:
  300.         CLongArray* fFrames;
  301. };
  302. //**************************************************************************************************
  303.  
  304.  
  305. class CNewFrameCommand : public CMonoFrameCommand {
  306.     public:
  307.         CNewFrameCommand();
  308.         
  309.         void INewFrameCommand(CTextension* textension, long frameNo, TxtnLongRect* absTextRect);
  310.         //absTextRect is not scaled
  311.         
  312.     protected:
  313.         //•override
  314.         virtual OSErr DoMainAction(const TFrameCmdData* frameData, short frameIndex
  315.                                                         , Boolean isUndo, CDisplayChanges* displayChanges);
  316.         
  317.         virtual char GetFlags() const;
  318.         
  319.     private:
  320. };
  321. //**************************************************************************************************
  322.  
  323.  
  324. class CModifyFrameCommand : public CMonoFrameCommand {
  325.     public:
  326.         CModifyFrameCommand();
  327.         
  328.         void IModifyFrameCommand(CTextension* itsView, long frameNo, TxtnLongRect* newTextBounds);
  329.         //newTextBounds is not scaled
  330.         
  331.     protected:
  332.         //•override
  333.         virtual OSErr DoMainAction(const TFrameCmdData* frameData, short frameIndex
  334.                                                         , Boolean isUndo, CDisplayChanges* displayChanges);
  335.         
  336.     private:
  337.         TxtnLongRect fNewTextBounds;
  338. };
  339. //**************************************************************************************************
  340.  
  341.  
  342. class CDeleteFramesCommand : public CMultiFrameCommand {
  343.     public:
  344.         CDeleteFramesCommand();
  345.         
  346.         OSErr IDeleteFramesCommand(CTextension* textension, CLongArray* cmdFrames);
  347.         
  348.     protected:
  349.         //•override
  350.         virtual OSErr DoMainAction(const TFrameCmdData* frameData, short frameIndex
  351.                                                         , Boolean isUndo, CDisplayChanges* displayChanges);
  352.         
  353.         virtual char GetFlags() const;
  354.         
  355.     private:
  356. };
  357. //**************************************************************************************************
  358.  
  359.  
  360. class COffsetFramesCommand : public CMultiFrameCommand {
  361.     public:
  362.         COffsetFramesCommand();
  363.         
  364.         OSErr IOffsetFramesCommand(CTextension* textension, CLongArray* cmdFrames
  365.                                                                 , long hOffset, long vOffset);
  366.         
  367.         //•own
  368.         void SetOffsets(long hOffset, long vOffset);
  369.         
  370.     protected:
  371.         //•override
  372.         virtual OSErr DoMainAction(const TFrameCmdData* frameData, short frameIndex
  373.                                                         , Boolean isUndo, CDisplayChanges* displayChanges);
  374.         
  375.     private:
  376.         long fHOffset;
  377.         long fVOffset;
  378. };
  379. //**************************************************************************************************
  380.  
  381.  
  382.  
  383. #endif //_LinkedFrames_
  384.  
  385. #endif //txtnMultiFrames