home *** CD-ROM | disk | FTP | other *** search
- /*
- File: RunObject.h
-
- Contains: xxx put contents here xxx
-
- Written by: Essam Zaky
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 1/4/94 EZ clean up
- <1> 1/4/94 EZ first checked in
-
- */
-
- #ifndef _RunObject_
- #define _RunObject_
-
- #ifndef _ToolBoxDump_
- #include "ToolBoxDump.h"
- #endif
-
- #ifndef _Array_
- #include "Array.h"
- #endif
-
- #ifndef _AttrObject_
- #include "AttrObject.h"
- #endif
-
- #ifndef _Streams_
- #include "Streams.h"
- #endif
-
- //***************************************************************************************************
-
- const short kInvalidAscent = -1;
-
-
- #ifdef txtnScal
- //CRunObject has 2 attrs
- const AttrId kHScaleAttr = 'hscl';
- const AttrId kVScaleAttr = 'vscl';
-
- const kScaleRef = 100; //denom is always 100 for scale values (short input to SetAttributeValue)
- #endif
-
-
- //constants for SetDefaults
- const long kUpdateOnlyScriptInfo = 1 << 16;
- /*•weak point : some desendents may define other constants for their version of "SetDefaults".
- So, be careful when adding a new const.
- */
-
- //***************************************************************************************************
-
- #ifdef __SC__
- class __machdl CRunObject; //forward
- #else
- class CRunObject;
- #endif
-
- struct TLineRun {//for TextensionObject routines that work on a line scope (Pixel2Char, Char2Pixel, ..)
- CRunObject* runObj;
- short runOffset; //offset from the start of the line
- short runLen;
- Fixed runWidth;
- Fixed runExtraWidth;
- char runCtrlChar;
- };
- typedef TLineRun* TLineRunPtr;
- //***************************************************************************************************
-
- #ifdef txtnScal
- struct SetRunEnvPb {
- Point numer; //input, zoom
- Point denom; //input, zoom
-
- SetRunEnvPb() {numer.h = denom.h = numer.v = denom.v = 1;}
-
- SetRunEnvPb(short value) {numer.h = denom.h = numer.v = denom.v = value;} //used to pass value as 0 which means ignore all scaling stuff
-
- SetRunEnvPb(Point theNumer, Point theDenom) {
- numer = theNumer;
- denom = theDenom;
- }
- };
- #endif
- //***************************************************************************************************
-
- /*•••Pixel2CharPb, Char2PixelPb, DrawJustPb, FullJustPortionPb, MeasurePb start by a "RunDisplayPb"
- they may be type casted to it. The def of "Pixel2CharPb.." should be modified to have "RunDisplayPb"
- struct instead of its individual fields. Can't do this now for backward compatibility!
- */
- struct RunDisplayPb {
- uPtr linePtr;
- TLineRun* runInfo;
-
- JustStyleCode runPosition;
- Point numer;
- Point denom;
- };
- //***************************************************************************************************
-
- struct Pixel2CharPb {
- uPtr linePtr;
- TLineRun* runInfo;
-
- JustStyleCode runPosition;
- Point numer;
- Point denom;
-
- Fixed pixelWidth;
-
- char lineDirection;
-
- TOffsetRange* charRange; //output, offsets are wrt the run start
- };
- //***************************************************************************************************
-
- struct Char2PixelPb {
- uPtr linePtr;
- TLineRun* runInfo;
- JustStyleCode runPosition;
- Point numer;
- Point denom;
-
- short offset;
-
- char lineDirection;
- };
- //***************************************************************************************************
-
- struct DrawJustPb {
- uPtr linePtr;
- TLineRun* runInfo;
-
- JustStyleCode runPosition;
- Point numer;
- Point denom;
-
- const Rect* lineRectPtr;
- short lineAscent;
-
- Fixed runLeftEdge;
- };
- //***************************************************************************************************
-
- struct FullJustPortionPb {
- uPtr linePtr;
- TLineRun* runInfo;
-
- JustStyleCode runPosition;
- Point numer;
- Point denom;
- };
- //***************************************************************************************************
-
- struct MeasurePb {
- uPtr linePtr;
- TLineRun* runInfo;
- JustStyleCode runPosition;
- Point numer;
- Point denom;
- };
- //***************************************************************************************************
-
-
- struct LineBreakPb {
- uPtr breakPtr;
- long breakLen;
- long breakStartOffset;
- Fixed* widthAvail;
- long breakOffset;
- };
- //***************************************************************************************************
-
- struct RunPositionPB {
- short runLineTop;
- short runLineHite;
- short runLeftEdge;
- short runTotalWidth;
-
- Point numer;
- Point denom;
- };
- //***************************************************************************************************
-
- struct ClickPB {
- RunPositionPB positionPB;
- char countClicks;
- Point clickPoint;
- long modifiers;
- };
- //***************************************************************************************************
-
- //constants for clickFlags
- const uchar kNoClickFlags = 0;
- const uchar kNeedsSaveClickFlag = 1; //indication that the clicked obj needs save
- const uchar kNeedsReformatClickFlag = 2;
-
- //constants for "commandId" of TClickCommandInfo
- const uchar kNoClickCmd = 0;
-
- struct TClickCommandInfo {//returned from DoClick
- TClickCommandInfo() {
- commandId = kNoClickCmd;
- clickFlags = kNoClickFlags;
- }
-
- uchar clickFlags;
-
- uchar commandId;
- long commandParams[10];
- };
- //***************************************************************************************************
-
-
- void IndivisiblePixel2Char(Pixel2CharPb* paramPb);
- short IndivisibleChar2Pixel(Char2PixelPb* paramPb);
-
-
- class CRunObject : public CAttrObject {
- public:
- //-------
- CRunObject();
-
- void IRunObject();
-
- //•override
- virtual ClassId GetClassId() const = 0;
-
-
- virtual CAttrObject* CreateNew() const = 0;
-
- #ifdef txtnScal
- virtual void GetAttrIDs(short* countAttr, AttrId* attrArray) const;
-
- virtual void SetDefaults(long message = 0);
- //loWord of message = script no, hiWord = see contants for default flags
- #endif
-
- virtual void Assign(const CAttrObject* newVals);
-
- virtual void SetAttributeValue(AttrId theAttr, const void* attrBuffer);
-
- virtual void Invalid();
-
- //•own
- virtual Boolean IsTextRun() const = 0;
-
- virtual void SaveRunEnv();
-
- #ifdef txtnScal
- virtual void SetRunEnv(SetRunEnvPb*) const;
- #else
- virtual void SetRunEnv() const;
- #endif
-
- virtual char GetRunDir() const;
- virtual Boolean Is2Bytes() const;
- virtual char GetRunScript() const;
- virtual void SetKeyScript() const;
-
- void GetHiteInfo(short* ascent, short* descent, short* leading);
-
- virtual void DoPixel2Char(Pixel2CharPb*) = 0;
- virtual short DoChar2Pixel(Char2PixelPb*) = 0;
- virtual void DoDrawJust(DrawJustPb*) = 0;
-
- #ifdef txtnRulers
- virtual Fixed DoFullJustifPortion(FullJustPortionPb*);
- #endif
-
- virtual Fixed DoMeasure(MeasurePb*) = 0;
- virtual StyledLineBreakCode DoBreak(LineBreakPb*) = 0;
-
- virtual void DoClick(ClickPB*, TClickCommandInfo*, Boolean* abortDrag);
- //draging selection will be aborted if abortDrag is set to false (the default)
-
- virtual Boolean IsPointInside(Point, const RunPositionPB*);
- /*called for active object when the point to test is outside the obj bounds
- (added for MovieObj which may have extra componenets which overlap text when activ).
- should return false in the normal case */
-
- virtual void SetCursor(Point, const RunPositionPB*) const; //does nothing by default
-
- virtual Boolean FilterControlChar(uchar theChar) const;
- //true result ==> skip the char
-
- //folowing 2 messages are received by classes returning "kNeedsIdle" from "GetObjFlags".
- virtual unsigned long GetIdleTime() const;
- virtual void Idle(RunPositionPB*);
-
- virtual void SetHilite(char oldHilite, char newHilite, const RunPositionPB*, Boolean doDraw = true);
- /*received by classes returning "kHasCustomHilite" from "GetObjFlags".
- •paramPb is defined <==> doDraw == true
- •oldHilite != newHilite always
- */
-
- virtual void DrawSelection(char hiliteStat, const RunPositionPB* paramPb);
- //received by classes returning "kHasCustomHilite" from "GetObjFlags".
-
- #ifdef txtnScal
- virtual OSErr WriteToStream(CStream* outputStream);
- virtual OSErr ReadFromStream(CStream* inputStream);
- #endif
-
- protected:
- //----------
- //•override
- #ifdef txtnScal
- virtual long GetAttrFlags(AttrId theAttr, void* attrBuffer, long updateMessage =0) const;
-
- virtual Boolean EqualAttribute(AttrId theAttr, const void* valToCheck) const;
-
- virtual void AttributeToBuffer(AttrId theAttr, void* attrBuffer) const;
-
- virtual void BufferToAttribute(AttrId theAttr, const void* attrBuffer);
-
- void AdjustScaleVals(Point* numer, Point* denom) const;
- #endif
-
- //•own
- virtual void CalcHiteInfo(short* ascent, short* descent, short* leading) = 0;
- //returns NON scaled values
-
- inline void InvalidateHite() {fAscent = kInvalidAscent;}
-
- private:
- //--------
- short fAscent;
- short fDescent;
- short fLeading;
-
- #ifdef txtnScal
- short fHScale;
- short fVScale;
- #endif
- };
- //**************************************************************************************************
-
- #endif
-