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

  1. /*
  2.     File:        AdvancedRuler.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 _AdvancedRuler_
  18. #define _AdvancedRuler_
  19.  
  20. #ifndef _ToolBoxDump_
  21. #include "ToolBoxDump.h"
  22. #endif
  23.  
  24. #ifndef _RulerObject_
  25. #include "RulerObject.h"
  26. #endif
  27.  
  28. //***************************************************************************************************
  29.  
  30. const ClassId kAdvancedRulerClassId = 'rulr';
  31.  
  32. const AttrId    kIndentAttr = 'ndnt';
  33. const AttrId    kLeftMarginAttr = 'lMrg';
  34. const AttrId    kRightMarginAttr = 'rMrg';
  35. const AttrId    kLineSpacingAttr = 'lspc';
  36.  
  37.  
  38. const  kMaxTabCount = 20;
  39.  
  40.  
  41. //***************************************************************************************************
  42.  
  43. typedef Ttab TtabTable[kMaxTabCount];
  44. //***************************************************************************************************
  45.  
  46. //constants for TLineSpacing.spacingUnit
  47. const ushort kFixedPixelsUnit = 0;
  48. const ushort kLinesUnit = 1;
  49.  
  50. class CLineSpacing : private SingleObject {
  51.     public:
  52.         CLineSpacing() {}
  53.         
  54.         Boolean IsEqual(CLineSpacing aSpacing) const;
  55.         
  56.         void GetParams(short* unit, short* value, Boolean* halfLine) const;
  57.         
  58.         void SetParams(short newUnit, short newVal, Boolean halfLine = false);
  59.         
  60.         inline void SetUnit(short newUnit) {fUnit = ushort(newUnit);}
  61.         inline void IncrementValue() {++fValue;} //increment lines by 1/2
  62.         inline void DecrementValue() {--fValue;} //derement lines by 1/2
  63.         
  64.         void AdjustLineHite(TLineHiteInfo* lineHiteInfo) const;
  65.     
  66.     private:
  67.         ushort    fUnit  : 1;
  68.         ushort    fValue  : 15; //if fUnit is kLinesUnit ==> bit 0 is 1 ==> half line
  69. };
  70. typedef CLineSpacing* CLineSpacingPtr;
  71.  
  72. //***************************************************************************************************
  73.  
  74.  
  75. //•CTabs should not allocate in any of its member fns, since it may be a record in a Handle object
  76.  
  77. class CTabs : private SingleObject {
  78.     public:
  79.         CTabs() {fCount = 0;}
  80.         
  81.         inline short GetCountTabs() const {return fCount;}
  82.         void GetTabsTable(TtabTable theTable) const;
  83.         
  84.         Ttab GetTab(short tabIndex) const;
  85.         
  86.         void InsertTab(Ttab theTab);
  87.         void RemoveTab(short tabIndex);
  88.         
  89.         Boolean SearchTab(short width, short* index) const; //caller should pass "width" scaled properly
  90.         short SearchNearestTab(short width) const;
  91.         
  92.         Fixed CalcPendingTabWidth(const TPendingTab* pendingTab, Fixed tabTrailWidth
  93.                                                         , Fixed remainingWidth) const;
  94.         
  95.         #ifdef txtnScal
  96.         Fixed GetTabWidth(Fixed tabPixStart, TPendingTab* pendingTab, short numer =1, short denom=1) const;
  97.         #else
  98.         Fixed GetTabWidth(Fixed tabPixStart, TPendingTab* pendingTab) const;
  99.         #endif
  100.         
  101.         Boolean IsEqual(const CTabs* tabsToCheck) const;
  102.         
  103.     private:
  104.         char fCount;
  105.         TtabTable    fTable;
  106.         
  107.         #ifdef txtnScal
  108.         Ttab Width2Tab(Fixed width, short numer, short denom,) const;
  109.         #else
  110.         Ttab Width2Tab(Fixed width) const;
  111.         #endif
  112. };
  113. //***************************************************************************************************
  114.  
  115.  
  116.  
  117. class    CAdvancedRuler    :    public CBasicRuler {
  118.     public:
  119.         CAdvancedRuler();
  120.         
  121.         inline void    IAdvancedRuler() {this->IBasicRuler();}
  122.         
  123.         //•override
  124.         virtual ClassId GetClassId() const;
  125.         
  126.         virtual void GetAttrIDs(short* countAttr, AttrId* attrArray) const;
  127.         
  128.         virtual CAttrObject* CreateNew() const;
  129.  
  130.         virtual void SetDefaults(long message = 0);
  131.  
  132.         #ifdef txtnScal
  133.         virtual Fixed GetEffectiveLineWidth(Fixed width, Boolean paragStart, short numer=1, short denom =1) const;
  134.         virtual Fixed GetLineLeftEdge(char direction, Boolean paragStart, short numer=1, short denom =1) const;
  135.         virtual Fixed GetTabWidth(Fixed tabPixStart, TPendingTab* pendingTab, short numer =1
  136.                                                         , short denom=1) const;
  137.         #else
  138.         virtual Fixed GetEffectiveLineWidth(Fixed width, Boolean paragStart) const;
  139.         virtual Fixed GetLineLeftEdge(char direction, Boolean paragStart) const;
  140.         virtual Fixed GetTabWidth(Fixed tabPixStart, TPendingTab* pendingTab) const;
  141.         #endif
  142.         
  143.         virtual void AdjustLineHite(TLineHiteInfo* lineHiteInfo) const;
  144.         virtual Fixed CalcPendingTabWidth(const TPendingTab* pendingTab, Fixed tabTrailWidth
  145.                                                                         , Fixed remainingWidth) const;
  146.         
  147.  
  148.         //input/output methods
  149.         virtual OSErr WriteToStream(CStream* outputStream);
  150.         virtual OSErr ReadFromStream(CStream* inputStream);
  151.                 
  152.     protected:
  153.         //•override
  154.         virtual long GetAttrFlags(AttrId theAttr, const void* attrBuffer, long updateMessage =0) const;
  155.         
  156.         virtual Boolean EqualAttribute(AttrId theAttr, const void* valToCheck) const; 
  157.         
  158.         virtual void AttributeToBuffer(AttrId theAttr, void* attrBuffer) const;
  159.         
  160.         virtual void BufferToAttribute(AttrId theAttr, const void* attrBuffer);
  161.  
  162.         virtual void UpdateAttribute(AttrId theAttr, const void* srcAttr, long updateMessage
  163.                                                                     , const void* continuousAttr = nil);
  164.         /*if updateMessage == kRemoveTab ==> srcAttr is a ptr to the tabValue(short), note that tabValue is chosen instead of the 
  165.         tabIndex since UpdateAttribute is normally called for a selection of rulers, and the tabValue is what identify
  166.         a tab over different rulers.
  167.         kInsertTab ==> srcAttr is a ptr to the tab to be inserted
  168.         if updateMessage is 0 ==> srcAttr is a ptr to a CTabs object and *srcAttr will become the new tabs
  169.         */
  170.         
  171.     private:
  172.         CTabs    fTabs;
  173.         CLineSpacing fLineSpacing;
  174.  
  175.         short    fIndent; //is measured to the left margin (to the right margin if direction is rl), can be -ive(out) or +ive(in)
  176.         short fLeftMarg;
  177.         short fRightMarg;
  178. };
  179. //**************************************************************************************************
  180.     
  181. #endif
  182.