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

  1. /*
  2.     File:        RulerObject.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 _RulerObject_
  18. #define _RulerObject_
  19.  
  20. #ifndef _ToolBoxDump_
  21. #include "ToolBoxDump.h"
  22. #endif
  23.  
  24. #ifndef _Array_
  25. #include "Array.h"
  26. #endif
  27.  
  28. #ifndef _AttrObject_
  29. #include "AttrObject.h"
  30. #endif
  31.  
  32. #ifndef _Streams_
  33. #include "Streams.h"
  34. #endif
  35.  
  36. //***************************************************************************************************
  37.  
  38. const ClassId kBasicRulerClassId = 'brlr';
  39.  
  40. const AttrId     kJustAttr = 'just'; //defined in CBasicRuler and CAdvancedRuler
  41.  
  42. const AttrId     kTabAttr = 'tabb';
  43. //defined only in CAdvancedRuler, declared here for CTextensionCommand
  44.  
  45.  
  46. //kJustAttr constants
  47. const char kLeftJust = 1;
  48. const char kRightJust = 2;
  49. const char kCenterJust = 4;
  50. const char kFullJust = 8;
  51. const char kForceFullJust = 16;
  52.  
  53. //tab kind const, CBasicRuler supports only "kRepulsivTab", others are handled by "CAdvancedRuler"
  54. const char kRepulsivTab = 0;
  55. const char kCenterTab = 1;
  56. const char kAttractivTab = 2;
  57. const char kAlignTab = 3; //align on a uchar
  58.  
  59. const short kDefaultTabVal = 30; //pixels
  60.  
  61. //constants for updateMessage when kTabAttr
  62. //defined only in CAdvancedRuler, declared here for CTextensionCommand
  63. const long kRemoveTab = 1;
  64. const long kInsertTab = 2;
  65.  
  66. //***************************************************************************************************
  67.  
  68. struct Ttab {
  69.     void Set(short tabValue, char tabKind, uchar tabAlign = 0);
  70.     
  71.     short value;
  72.     char kind; //kRepulsivTab..kAlignTab
  73.     uchar alignChar;
  74. };
  75. typedef Ttab* TtabPtr;
  76.  
  77.  
  78.  
  79. struct TPendingTab {
  80.     Boolean valid; //true if the "theTab" is pending tab
  81.     Ttab theTab;
  82.     Fixed tabWidth;
  83. };
  84. //***************************************************************************************************
  85.  
  86.  
  87. class CRulerObject : public CAttrObject { //abstract class for ruler objects
  88.     public:
  89.         CRulerObject();
  90.         
  91.         //•override
  92.         virtual ClassId GetClassId() const = 0;
  93.         
  94.         virtual CAttrObject* CreateNew() const = 0;
  95.         
  96.         virtual void GetAttrIDs(short* countAttr, AttrId* attrArray) const = 0;
  97.         
  98.         //•own
  99.         #ifdef txtnScal
  100.         virtual Fixed GetEffectiveLineWidth(Fixed width, Boolean paragStart
  101.                                                                     , short numer=1, short denom =1) const = 0;
  102.  
  103.         virtual Fixed GetLineLeftEdge(char direction, Boolean paragStart
  104.                                                                     , short numer=1, short denom =1) const = 0;
  105.  
  106.         virtual Fixed GetTabWidth(Fixed tabPixStart, TPendingTab* pendingTab
  107.                                                             , short numer =1, short denom=1) const = 0;
  108.         #else
  109.         virtual Fixed GetEffectiveLineWidth(Fixed width, Boolean paragStart) const = 0;
  110.  
  111.         virtual Fixed GetLineLeftEdge(char direction, Boolean paragStart) const = 0;
  112.  
  113.         virtual Fixed GetTabWidth(Fixed tabPixStart, TPendingTab* pendingTab) const = 0;
  114.         #endif
  115.         
  116.         
  117.         virtual void AdjustLineHite(TLineHiteInfo* lineHiteInfo) const = 0;
  118.         virtual Fixed CalcPendingTabWidth(const TPendingTab* pendingTab, Fixed tabTrailWidth
  119.                                                                             , Fixed remainingWidth) const = 0;
  120.                                                                             
  121.  
  122.     protected:
  123.         //•override
  124.         virtual Boolean EqualAttribute(AttrId theAttr, const void* valToCheck) const = 0;
  125.  
  126.         virtual void AttributeToBuffer(AttrId theAttr, void* attrBuffer) const = 0;
  127.         
  128.         virtual void BufferToAttribute(AttrId theAttr, const void* attrBuffer) = 0;
  129. };
  130. //***************************************************************************************************
  131.  
  132. class CBasicRuler : public CRulerObject {
  133.     public:
  134.         CBasicRuler();
  135.         
  136.         inline void    IBasicRuler() {this->IAttrObject();}
  137.         
  138.         //•override
  139.         virtual ClassId GetClassId() const;
  140.         
  141.         virtual void GetAttrIDs(short* countAttr, AttrId* attrArray) const;
  142.  
  143.         virtual CAttrObject* CreateNew() const;
  144.  
  145.         virtual void SetDefaults(long message = 0);
  146.  
  147.         #ifdef txtnScal
  148.         virtual Fixed GetEffectiveLineWidth(Fixed width, Boolean paragStart, short numer=1, short denom =1) const;
  149.         virtual Fixed GetLineLeftEdge(char direction, Boolean paragStart, short numer=1, short denom =1) const;
  150.         virtual Fixed GetTabWidth(Fixed tabPixStart, TPendingTab* pendingTab, short numer =1
  151.                                                         , short denom=1) const;
  152.         #else
  153.         virtual Fixed GetEffectiveLineWidth(Fixed width, Boolean paragStart) const;
  154.         virtual Fixed GetLineLeftEdge(char direction, Boolean paragStart) const;
  155.         virtual Fixed GetTabWidth(Fixed tabPixStart, TPendingTab* pendingTab) const;
  156.         #endif
  157.         
  158.         virtual void AdjustLineHite(TLineHiteInfo* lineHiteInfo) const;
  159.         virtual Fixed CalcPendingTabWidth(const TPendingTab* pendingTab, Fixed tabTrailWidth
  160.                                                                         , Fixed remainingWidth) const;
  161.  
  162.  
  163.         //input/output methods
  164.         virtual OSErr WriteToStream(CStream* outputStream);
  165.         virtual OSErr ReadFromStream(CStream* inputStream);
  166.  
  167.     protected:        
  168.         char     fJust;
  169.  
  170.         //•override
  171.         virtual Boolean EqualAttribute(AttrId theAttr, const void* valToCheck) const;
  172.         
  173.         virtual void AttributeToBuffer(AttrId theAttr, void* attrBuffer) const;
  174.         virtual void BufferToAttribute(AttrId theAttr, const void* attrBuffer);
  175. };
  176. //***************************************************************************************************
  177.  
  178. #endif
  179.