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

  1. /*
  2.     File:        RunObject.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 _RunObject_
  18. #define _RunObject_
  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 short    kInvalidAscent = -1;
  39.  
  40.  
  41. #ifdef txtnScal
  42. //CRunObject has 2 attrs
  43. const AttrId kHScaleAttr = 'hscl';
  44. const AttrId kVScaleAttr = 'vscl';
  45.  
  46. const kScaleRef = 100; //denom is always 100 for scale values (short input to SetAttributeValue)
  47. #endif
  48.  
  49.  
  50. //constants for SetDefaults
  51. const long kUpdateOnlyScriptInfo = 1 << 16;
  52. /*•weak point : some desendents may define other constants for their version of "SetDefaults".
  53. So, be careful when adding a new const.
  54. */
  55.  
  56. //***************************************************************************************************
  57.  
  58. #ifdef __SC__
  59. class __machdl CRunObject; //forward
  60. #else
  61. class CRunObject;
  62. #endif
  63.  
  64. struct TLineRun {//for TextensionObject routines that work on a line scope (Pixel2Char, Char2Pixel, ..)
  65.     CRunObject*    runObj;
  66.     short            runOffset; //offset from the start of the line
  67.     short            runLen;
  68.     Fixed            runWidth;
  69.     Fixed            runExtraWidth;
  70.     char            runCtrlChar;
  71. };
  72. typedef TLineRun* TLineRunPtr;
  73. //***************************************************************************************************
  74.  
  75. #ifdef txtnScal
  76. struct SetRunEnvPb {
  77.     Point numer; //input, zoom
  78.     Point denom; //input, zoom
  79.     
  80.     SetRunEnvPb() {numer.h = denom.h = numer.v = denom.v = 1;}
  81.     
  82.     SetRunEnvPb(short value) {numer.h = denom.h = numer.v = denom.v = value;} //used to pass value as 0 which means ignore all scaling stuff
  83.     
  84.     SetRunEnvPb(Point theNumer, Point theDenom) {
  85.         numer = theNumer;
  86.         denom = theDenom;
  87.     }
  88. };
  89. #endif
  90. //***************************************************************************************************
  91.  
  92. /*•••Pixel2CharPb, Char2PixelPb, DrawJustPb, FullJustPortionPb, MeasurePb start by a "RunDisplayPb"
  93. they may be type casted to it. The def of "Pixel2CharPb.." should be modified to have "RunDisplayPb"
  94. struct instead of its individual fields. Can't do this now for backward compatibility!
  95. */
  96. struct RunDisplayPb {
  97.     uPtr linePtr;
  98.     TLineRun* runInfo;
  99.     
  100.     JustStyleCode runPosition;
  101.     Point numer;
  102.     Point denom;
  103. };
  104. //***************************************************************************************************
  105.  
  106. struct Pixel2CharPb {
  107.     uPtr linePtr;
  108.     TLineRun* runInfo;
  109.     
  110.     JustStyleCode runPosition;
  111.     Point numer;
  112.     Point denom;
  113.  
  114.     Fixed    pixelWidth;
  115.     
  116.     char lineDirection;
  117.     
  118.     TOffsetRange* charRange; //output, offsets are wrt the run start
  119. };
  120. //***************************************************************************************************
  121.  
  122. struct Char2PixelPb {
  123.     uPtr     linePtr;
  124.     TLineRun* runInfo;
  125.     JustStyleCode runPosition;
  126.     Point numer;
  127.     Point denom;
  128.     
  129.     short    offset;
  130.     
  131.     char lineDirection;
  132. };
  133. //***************************************************************************************************
  134.  
  135. struct DrawJustPb {
  136.     uPtr linePtr;
  137.     TLineRun* runInfo;
  138.     
  139.     JustStyleCode runPosition;
  140.     Point numer;
  141.     Point denom;
  142.     
  143.     const Rect* lineRectPtr;
  144.     short lineAscent;
  145.     
  146.     Fixed runLeftEdge;
  147. };
  148. //***************************************************************************************************
  149.  
  150. struct FullJustPortionPb {
  151.     uPtr linePtr;
  152.     TLineRun* runInfo;
  153.     
  154.     JustStyleCode runPosition;
  155.     Point numer;
  156.     Point denom;
  157. };
  158. //***************************************************************************************************
  159.  
  160. struct MeasurePb {
  161.     uPtr linePtr;
  162.     TLineRun* runInfo;
  163.     JustStyleCode runPosition;
  164.     Point numer;
  165.     Point denom;
  166. };
  167. //***************************************************************************************************
  168.  
  169.  
  170. struct LineBreakPb {
  171.     uPtr         breakPtr;
  172.     long         breakLen;
  173.     long         breakStartOffset;
  174.     Fixed*    widthAvail;
  175.     long        breakOffset;
  176. };
  177. //***************************************************************************************************
  178.  
  179. struct RunPositionPB {
  180.     short runLineTop;
  181.     short runLineHite;
  182.     short runLeftEdge;
  183.     short runTotalWidth;
  184.     
  185.     Point numer;
  186.     Point denom;
  187. };
  188. //***************************************************************************************************
  189.  
  190. struct ClickPB {
  191.     RunPositionPB positionPB;
  192.     char countClicks;
  193.     Point clickPoint;
  194.     long modifiers;
  195. };
  196. //***************************************************************************************************
  197.  
  198. //constants for clickFlags
  199. const uchar kNoClickFlags = 0;
  200. const uchar kNeedsSaveClickFlag = 1; //indication that the clicked obj needs save
  201. const uchar kNeedsReformatClickFlag = 2;
  202.  
  203. //constants for "commandId" of TClickCommandInfo
  204. const uchar kNoClickCmd = 0;
  205.  
  206. struct TClickCommandInfo {//returned from DoClick
  207.     TClickCommandInfo() {
  208.         commandId = kNoClickCmd;
  209.         clickFlags = kNoClickFlags;
  210.     }
  211.     
  212.     uchar clickFlags;
  213.     
  214.     uchar commandId;
  215.     long commandParams[10];
  216. };
  217. //***************************************************************************************************
  218.  
  219.  
  220. void IndivisiblePixel2Char(Pixel2CharPb* paramPb);
  221. short IndivisibleChar2Pixel(Char2PixelPb* paramPb);
  222.  
  223.  
  224. class    CRunObject    :    public CAttrObject {
  225.     public:
  226. //-------
  227.     CRunObject();
  228.     
  229.     void    IRunObject();
  230.     
  231.     //•override
  232.     virtual ClassId GetClassId() const = 0;
  233.     
  234.     
  235.     virtual CAttrObject* CreateNew() const = 0;
  236.     
  237.     #ifdef txtnScal
  238.     virtual void GetAttrIDs(short* countAttr, AttrId* attrArray) const;
  239.  
  240.     virtual void SetDefaults(long message = 0);
  241.     //loWord of message = script no, hiWord = see contants for default flags 
  242.     #endif
  243.     
  244.     virtual void Assign(const CAttrObject* newVals);
  245.     
  246.     virtual void SetAttributeValue(AttrId theAttr, const void* attrBuffer);
  247.     
  248.     virtual void Invalid();
  249.     
  250.     //•own
  251.     virtual Boolean IsTextRun() const = 0;
  252.     
  253.     virtual void SaveRunEnv();
  254.     
  255.     #ifdef txtnScal
  256.     virtual void SetRunEnv(SetRunEnvPb*) const;
  257.     #else
  258.     virtual void SetRunEnv() const;
  259.     #endif
  260.     
  261.     virtual char GetRunDir() const;
  262.     virtual Boolean Is2Bytes() const;
  263.     virtual char GetRunScript() const;
  264.     virtual void SetKeyScript() const;
  265.     
  266.     void GetHiteInfo(short* ascent, short* descent, short* leading);
  267.     
  268.     virtual void DoPixel2Char(Pixel2CharPb*) = 0;
  269.     virtual short DoChar2Pixel(Char2PixelPb*) = 0;
  270.     virtual void DoDrawJust(DrawJustPb*) = 0;
  271.     
  272.     #ifdef txtnRulers
  273.     virtual Fixed DoFullJustifPortion(FullJustPortionPb*);
  274.     #endif
  275.     
  276.     virtual Fixed DoMeasure(MeasurePb*) = 0;
  277.     virtual StyledLineBreakCode DoBreak(LineBreakPb*) = 0;
  278.     
  279.     virtual void DoClick(ClickPB*, TClickCommandInfo*, Boolean* abortDrag);
  280.     //draging selection will be aborted if abortDrag is set to false (the default)
  281.     
  282.     virtual Boolean IsPointInside(Point, const RunPositionPB*);
  283.     /*called for active object when the point to test is outside the obj bounds
  284.     (added for MovieObj which may have extra componenets which overlap text when activ).
  285.     should return false in the normal case */
  286.     
  287.     virtual void SetCursor(Point, const RunPositionPB*) const; //does nothing by default
  288.     
  289.     virtual Boolean FilterControlChar(uchar theChar) const;
  290.     //true result ==> skip the char
  291.  
  292.     //folowing 2 messages are received by classes returning "kNeedsIdle" from "GetObjFlags".
  293.     virtual unsigned long GetIdleTime() const;
  294.     virtual void Idle(RunPositionPB*);
  295.  
  296.     virtual void SetHilite(char oldHilite, char newHilite, const RunPositionPB*, Boolean doDraw = true);
  297.     /*received by classes returning "kHasCustomHilite" from "GetObjFlags".
  298.     •paramPb is defined <==> doDraw == true
  299.     •oldHilite != newHilite always
  300.     */
  301.     
  302.     virtual void DrawSelection(char hiliteStat, const RunPositionPB* paramPb);
  303.     //received by classes returning "kHasCustomHilite" from "GetObjFlags".
  304.     
  305.     #ifdef txtnScal
  306.     virtual OSErr WriteToStream(CStream* outputStream);
  307.     virtual OSErr ReadFromStream(CStream* inputStream);
  308.     #endif
  309.         
  310.     protected:
  311. //----------
  312.     //•override
  313.     #ifdef txtnScal
  314.     virtual long GetAttrFlags(AttrId theAttr, void* attrBuffer, long updateMessage =0) const;
  315.     
  316.     virtual Boolean EqualAttribute(AttrId theAttr, const void* valToCheck) const;
  317.  
  318.     virtual void AttributeToBuffer(AttrId theAttr, void* attrBuffer) const;
  319.     
  320.     virtual void BufferToAttribute(AttrId theAttr, const void* attrBuffer);
  321.         
  322.     void AdjustScaleVals(Point* numer, Point* denom) const;
  323.     #endif
  324.     
  325.     //•own
  326.     virtual void CalcHiteInfo(short* ascent, short* descent, short* leading) = 0;
  327.     //returns NON scaled values
  328.     
  329.     inline void InvalidateHite() {fAscent = kInvalidAscent;}
  330.     
  331.     private:
  332. //--------
  333.     short    fAscent;
  334.     short    fDescent;
  335.     short    fLeading;
  336.  
  337. #ifdef txtnScal    
  338.     short fHScale;
  339.     short fVScale;
  340. #endif
  341. };
  342. //**************************************************************************************************
  343.  
  344. #endif
  345.