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

  1. /*
  2.     File:        AttrObject.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 _AttrObject_
  18. #define _AttrObject_
  19.  
  20. #ifndef _ToolBoxDump_
  21. #include "ToolBoxDump.h"
  22. #endif
  23.  
  24. #ifndef _Array_
  25. #include "Array.h"
  26. #endif
  27.  
  28. #ifndef _Streams_
  29. #include "Streams.h"
  30. #endif
  31. //***************************************************************************************************
  32.  
  33. const long kNoAttr    =    0;
  34. //***************************************************************************************************
  35.  
  36. typedef unsigned long TObjFlags;
  37. //constants for TObjFlags (returned from GetObjFlags)
  38.  
  39. const TObjFlags kNoFlags = 0;
  40.  
  41. const TObjFlags kHasCustomHilite = 1;
  42.  
  43. const TObjFlags kNeedsIdle = 2;
  44.  
  45. const TObjFlags kIndivisibleRun = 4;
  46. /*
  47.     -always selected as block (clicking or shift arrow keys)
  48.     -cleared as block (back space)
  49. */
  50.  
  51. const TObjFlags kFixedRangeRun = 8;
  52. /*
  53.     -once defined, the obj range can not be modified: other chars can not be added to or deleted from
  54.         the same range (graphics, foot notes, TSM runs..)
  55. */
  56. //***************************************************************************************************
  57.  
  58.  
  59.  
  60. /*constants for values returned as a feed back flags from certain object routines
  61. (GetAttrFlags, eventually mouseDown, ..) */
  62. const long kReformat = 1;
  63. const long kVReformat = 2;
  64.  
  65. typedef unsigned long ClassId;
  66.  
  67. typedef unsigned long AttrId;
  68.  
  69. const short kMaxCountAttr = 32;
  70.  
  71. const short kMaxAttrSize = 16;
  72.  
  73. //***************************************************************************************************
  74.  
  75. OSErr InitObjects();
  76. void EndObjects();
  77. //***************************************************************************************************
  78.  
  79.  
  80. struct TAttrObjModifier; //forward
  81.  
  82. class    CAttrObject : public HandleObject {
  83. public:
  84.     CAttrObject();
  85.     
  86.     void    IAttrObject();
  87.     void Free();
  88.     
  89.     virtual void FreeData();
  90.     
  91.     virtual CAttrObject* CreateNew() const = 0;
  92.     //Just do new of your class type and initialize it
  93.     
  94.     virtual CAttrObject* Reference();
  95.     
  96.     inline long GetCountReferences() {return fCountRefs;}
  97.     
  98.     virtual ClassId GetClassId() const = 0;
  99.     //should be unique for each CAttrObject descendent (i.e CQDTextRun and all descendents from it have different one)
  100.     
  101.     virtual void GetAttrIDs(short* countAttr, AttrId* attrArray) const;
  102.     //attrArray is allocated by the caller, just fill it
  103.     
  104.     virtual TObjFlags GetObjFlags();
  105.     
  106.     Boolean HasAttribute(AttrId theAttr) const;
  107.     
  108.     virtual void Assign(const CAttrObject* newVals);
  109.  
  110.     virtual void SetDefaults(long message = 0);
  111.     
  112.     long Update(const TAttrObjModifier* modifier, const CAttrObject* continuousObj =nil);
  113.     
  114.     long Update(const CAttrObject* srcObj, long updateMessage = 0, const CAttrObject* continuousObj =nil);
  115.     long Update(AttrId theAttr, const void* attrBuffer, long updateMessage
  116.                             , const CAttrObject* continuousObj =nil);
  117.     /*updateMessage, continuousObj to be passed to UpdateAttribute. The returned value is a feedBack
  118.     flags. for each updated attribute "GetAttrFlags" is called, the ORed result is returned
  119.     to the caller. the CAttrObject value is 0 (means no flags), descendents can override 
  120.     GetAttrFlags to return useful info like "widthChanged"(reformat), "needRedraw", ...
  121.     */
  122.     
  123.     //void Complete(const CAttrObject* srcObj);
  124.     
  125.     Boolean Common(const CAttrObject* anObj);
  126.     Boolean IsEqual(const CAttrObject* objectToCheck) const;
  127.     
  128.     inline Boolean IsInvalid() const {return (fAttr == kNoAttr);}
  129.     virtual void Invalid();
  130.     
  131.     #ifdef txtnDebug
  132.     Boolean HasAllAttributes();
  133.     #endif
  134.     
  135.     Boolean GetAttributeValue(AttrId theAttr, void* attrBuffer) const;
  136.     virtual void SetAttributeValue(AttrId theAttr, const void* attrBuffer);
  137.     
  138.     Boolean IsAttributeON(AttrId theAttr) const;
  139.     
  140.     //input/output methods
  141.     virtual OSErr WriteToStream(CStream* outputStream);
  142.     virtual OSErr ReadFromStream(CStream* inputStream);
  143.  
  144.     virtual ResType GetScrapType() const; // 0 means no data to put in the scrap
  145.     //override if your object has a type which can be in the scrap and understood by other apps (like 'PICT' and 'snd ')
  146.     
  147.     virtual OSErr WriteToScrap();
  148.     //called if GetScrapType returns != 0, may assume that ZeroScrap is called and should call PutScrap. 
  149.     
  150.     virtual OSErr ReadFromScrap(long scrapSize);
  151.     //called if GetScrapType returns != 0 and the type exist in the scrap, may assume that LoadScrap is already called  
  152.         
  153.         
  154. protected:
  155.     void SetAttributeON(AttrId theAttr);
  156.     
  157.     virtual Boolean EqualAttribute(AttrId theAttr, const void* valToCheck) const;
  158.     //false by default
  159.     
  160.     virtual Boolean SetCommonAttribute(AttrId theAttr, const void* val2Check);
  161.     
  162.     virtual long GetAttrFlags(AttrId theAttr, const void* attrBuffer, long updateMessage =0) const;
  163.     /*see comment after "Update", and note that attrBuffer may be nil, in this case descendents should return a value based only
  164.     on the AttrId.
  165.     */
  166.     
  167.     virtual void UpdateAttribute(AttrId theAttr, const void* srcAttr, long updateMessage
  168.                                                             , const void* continuousAttr = nil);
  169.  
  170.     virtual void AttributeToBuffer(AttrId theAttr, void* attrBuffer) const;
  171.     
  172.     virtual void BufferToAttribute(AttrId theAttr, const void* attrBuffer);
  173.         
  174. private:
  175.     ulong    fAttr;
  176.     short fAttrRef;
  177.     long fCountRefs;
  178.     
  179.     virtual void CopyAttribute(AttrId theAttr, const CAttrObject* srcObj);
  180. };
  181. //**************************************************************************************************
  182.  
  183.  
  184. struct TAttrObjModifier {
  185.     long fMessage;
  186.     
  187.     CAttrObject* fObj;
  188.     
  189.     AttrId fAttr;
  190.     char fAttrValue[kMaxAttrSize];
  191.  
  192.     TAttrObjModifier(CAttrObject* obj, long message = 0);
  193.     
  194.     TAttrObjModifier(AttrId attr, const void* buffer, long message = 0);
  195.  
  196.     TAttrObjModifier();
  197.     
  198.     void Set(CAttrObject* obj, long message = 0);
  199.     
  200.     void Set(AttrId attr, const void* buffer, long message = 0);
  201. };
  202. //***************************************************************************************************
  203.  
  204.  
  205.  
  206. #endif
  207.