home *** CD-ROM | disk | FTP | other *** search
- /*
- // { WASTE PROJECT: }
- // { Internal interface: constants, types and inline code }
-
- // { Copyright © 1993-1994 Marco Piovanelli }
- // { All Rights Reserved }
- */
-
- /* useful macros for testing, setting and clearing bits */
-
- #include <TextServices.h>
- #include <AERegistry.h>
-
- #define BTST( FLAGS, BIT ) (((FLAGS) & (1L << (BIT)))!=0)
- #define BSET( FLAGS, BIT ) ((FLAGS) |= (1L << (BIT)))
- #define BCLR( FLAGS, BIT ) ((FLAGS) &= (~(1L << (BIT))))
-
- #define ABS(A) ((A) > 0 ? (A) : -(A))
-
- #define BSL(A, B) (((long)A) << (B))
- #define BSR(A, B) (((long)A) >> (B))
-
- #include "LongCoords.h"
- #include <limits.h>
-
- /* alignment styles */
-
- enum {
- weFlushLeft = -2, /* flush left */
- weFlushRight = -1, /* flush right */
- weFlushDefault = 0, /* flush according to system direction */
- weCenter = 1, /* centered */
- weJustify = 2 /* fully justified */
- };
-
- // { values for the edge parameter }
-
- enum {
- kLeadingEdge = -1,
- kTrailingEdge = 0
- };
-
- // { control character codes }
-
- enum {
- kBackspace = 8,
- kEOL = 13,
- kArrowLeft = 28,
- kArrowRight = 29,
- kArrowUp = 30,
- kArrowDown = 31
- };
-
- // { bit equates for QuickDraw styles }
-
- enum {
- tsBold = 0,
- tsItalic = 1,
- tsUnderline = 2,
- tsOutline = 3,
- tsShadow = 4,
- tsCondense = 5,
- tsExtend = 6
- };
-
- // { bit equates for the tsFlags field of the WETextStyle record }
- enum {
- tsTSMHilite = 4, // { set if style run is part of active input area }
- tsTSMSelected = 5, // { set for selected raw/converted text }
- tsTSMConverted = 6, // { set for converted text, clear for raw text }
- tsRightToLeft = 7 // { reserved for future use }
- };
-
- // { bit equates for the mode parameter in WESetStyle and WEContinuousStyle }
- enum {
- kModeFont = 0,
- kModeFace = 1,
- kModeSize = 2,
- kModeColor = 3,
- kModeAddSize = 4,
- kModeToggleFace = 5,
- kModeReplaceFace = 6,
- kModeFlags = 15
- };
-
- // { values for the mode parameter in WESetStyle and WEContinuousStyle }
- enum {
- weDoFont = 0x0001,
- weDoFace = 0x0002,
- weDoSize = 0x0004,
- weDoColor = 0x0008,
- weDoAll = weDoFont + weDoFace + weDoSize + weDoColor,
- weDoAddSize = 0x0010,
- weDoToggleFace = 0x0020,
- weDoReplaceFace = 0x0040,
- weDoFlags = 0x8000
- };
-
- // { values for WEFeatureFlag action parameter }
- enum {
- weBitClear = 0, // { disables the specified feature }
- weBitSet = 1, // { enables the specified feature }
- weBitTest = -1 // { returns the current setting of the specified feature }
- };
-
- // { bit equates for the flags field in the WE record }
- // { bits 0..15 can be used to turn on and off specific features with WEFeatureFlag }
- // { bits 16..31 are used internally and should not be modified }
-
- // { private flags }
- enum {
- weFHasColorQD = 31, // { Color QuickDraw is available }
- weFHasTextServices = 30, // { Text Services Manager is available }
- weFNonRoman = 29, // { at least one non-Roman script is enabled }
- weFDoubleByte = 28, // { a double-byte script is installed }
- weFBidirectional = 27, // { reserved for future use }
- weFUseDualCaret = 26, // { reserved for future use }
- weFCaretVisible = 24, // { the caret is currently visible }
- weFMouseTracking = 23, // { set internally during mouse tracking }
- weFAnchorIsEnd = 22, // { anchor offset is selEnd }
- weFUseNullStyle = 21, // { a null style is associated with the empty selection }
- weFActive = 20 // { we're active }
- };
-
- // { public flags }
- enum {
- weFDrawOffscreen = 11, // { draw text offscreen for smoother visual results }
- weFUseTempMem = 10, // { use temporary memory for main data structures }
- weFInhibitRecal = 9, // { if set, recals and redraws are inhibited }
- weFDragAndDrop = 8, // { reserved for future use }
- weFIntCutAndPaste = 7, // { reserved for future use }
- weFOutlineHilite = 2, // { frame selection range when text pane is inactive }
- weFAutoScroll = 0 // { automatically scroll text when cursor is outside pane }
- };
-
- // { masks for setting the feature bits }
- enum {
- weDoAutoScroll = 1 << weFAutoScroll,
- weDoOutlineHilite = 1 << weFOutlineHilite,
- weDoIntCutAndPaste = 1 << weFIntCutAndPaste,
- weDoDragAndDrop = 1 << weFDragAndDrop,
- weDoInhibitRecal = 1 << weFInhibitRecal,
- weDoUseTempMem = 1 << weFUseTempMem,
- weDoDrawOffscreen = 1 << weFDrawOffscreen
- };
-
- // { scrap types }
- enum {
- kTypeText = 'TEXT',
- kTypeStyles = 'styl'
- };
-
- // { selectors for WEGetInfo/WESetInfo }
- enum {
- weClickLoop = 'clik',
- weLineArray = 'line',
- wePort = 'port',
- weRefCon = 'refc',
- weRunArray = 'runa',
- weScrollProc = 'scrl',
- weStyleTable = 'styl',
- weText = 'text',
- weTSMDocumentID = 'tsmd',
- weTSMPostUpdate = 'post',
- weTSMPreUpdate = 'pre '
- };
-
- // { values for WEAllocate allocFlags parameter }
- enum {
- kAllocClear = 0x0001, // { clear handle after allocation }
- kAllocTemp = 0x0002 // { use temporary memory if available }
- };
-
- // { other miscellaneous constants }
- enum {
- kMinFontSize = 1, // { minimum valid font size }
- kMaxFontSize = SHRT_MAX, // { maximum valid font size }
- kInvalidOffset = -1 // { used to flag an invalid or nonexistent offset }
- };
-
- static long kOneToOneScaling = 0x00010001; // { 1:1 scaling ratio }
-
- // { WETextStyle is just a familiar TextStyle record as defined by TextEdit, where }
- // { tsFace is redefined as SignedByte (rather than Style) so that the filler byte }
- // { becomes "visible" from Pascal and can be used to store internal flags }
-
- #if defined(powerc) || defined (__powerc)
- #pragma options align=mac68k
- #endif
-
- typedef struct WETextStyle {
- short tsFont; /* font family number */
- char tsFace; /* set of QuickDraw styles */
- char tsFlags; /* flags (FOR INTERNAL USE ONLY) */
- short tsSize; /* font size, in integer points */
- RGBColor tsColor; /* absolute red-green-blue color */
- } WETextStyle, *WETextStylePtr, **WETextStyleHandle;
-
- typedef struct WERunAttributes {
- short runHeight; /* style run height (ascent + descent + leading) */
- short runAscent; /* font ascent */
- WETextStyle runStyle; /* text style */
- } WERunAttributes, *WERunAttributesPtr, **WERunAttributesHandle;
-
- typedef struct WERunInfo {
- long runStart; /* byte offset to first character of this style run */
- long runEnd; /* byte offset to first character of next style run */
- WERunAttributes runAttrs; /* run attributes */
- } WERunInfo, *WERunInfoPtr, **WERunInfoHandle;
-
- typedef struct WEStyleScrapElement {
- long scrpStartChar;
- WERunAttributes scrpAttrs;
- } WEStyleScrapElement, *WEStyleScrapElementPtr, **WEStyleScrapElementHandle;
-
- // { another "view" for the familiar TextEdit 'styl' Clipboard type }
-
- typedef struct WEStyleScrap {
- short scrpNStyles;
- WEStyleScrapElement scrpStyleTab[1];
- } WEStyleScrap, *WEStyleScrapPtr, **WEStyleScrapHandle;
-
- // { the purpose of the GrafPort1 declaration is to redefine the txFace field as SignedByte, }
- // { rather than Style ( = set of StyleItem), to avoid using THINK Pascal runtime routines }
- // { for set manipulation }
-
- typedef struct GrafPort1
- {
- short device;
- BitMap portBits;
- Rect portRect;
- RgnHandle visRgn;
- RgnHandle clipRgn;
- Pattern bkPat;
- Pattern fillPat;
- Point pnLoc;
- Point pnSize;
- short pnMode;
- Pattern pnPat;
- short pnVis;
- short txFont;
- char txFace;
- char filler;
- short txMode;
- short txSize;
- Fixed spExtra;
- long fgColor;
- long bkColor;
- short colrBit;
- short patStretch;
- Handle picSave;
- Handle rgnSave;
- Handle polySave;
- QDProcsPtr grafProcs;
- } GrafPort1, *GrafPtr1;
-
- typedef struct QDEnvironment {
- GrafPtr envPort;
- PenState envPen;
- WETextStyle envStyle;
- short envMode;
- } QDEnvironment;
-
- typedef struct WEStyleScrapPair {
- WEStyleScrapElement first;
- WEStyleScrapElement second;
- } WEStyleScrapPair, *WEStyleScrapPeek;
-
- typedef struct RunArrayElement {
- long runStart; // { offset to first character in style run }
- long styleIndex; // { index into style table (high word currently unused) }
- } RunArrayElement, *RunArrayElementPtr, **RunArrayElementHandle;
-
- typedef struct RunArrayPair {
- RunArrayElement first;
- RunArrayElement second;
- } RunArrayPair, *RunArrayPeek;
-
- // const kRunArrayMaxIndex = (maxLong / sizeOf(RunArrayElement)) - 1;
-
- typedef RunArrayElement *RunArrayPtr;
- typedef RunArrayPtr *RunArrayHandle;
-
- typedef struct StyleTableElement {
- long refCount; // { reference count }
- WERunAttributes info; // { style information }
- } StyleTableElement, *StyleTableElementPtr, **StyleTableElementHandle;
-
- // kStyleTableMaxIndex = (maxint div SizeOf(StyleTableElement)) - 1;
-
- typedef StyleTableElement *StyleTablePtr;
- typedef StyleTablePtr *StyleTableHandle;
-
- typedef struct LineRec {
- long lineStart; /* byte offset to first character in line */
- long lineOrigin; /* pixel offset from destRect.top */
- short lineAscent; /* maximum font ascent for this line */
- short lineSlop; /* extra pixels needed to fill up the line */
- Fixed lineJustAmount; /* normalized slop value, used for justification */
- } LineRec, *LinePtr, **LineHandle;
-
-
- typedef struct LinePair {
- LineRec first;
- LineRec second;
- } LinePair, *LinePeek;
-
- // kLineArrayMaxIndex = (maxLongInt div SizeOf(LineRec)) - 1;
-
- typedef LineRec *LineArrayPtr;
- typedef LineArrayPtr *LineArrayHandle;
-
- typedef struct WERec {
- GrafPtr port; /* graphics port text is drawn into */
- Handle hText; /* handle to the text */
- LineArrayHandle hLines; /* handle to the line array */
- StyleTableHandle hStyles; /* handle to the style table */
- RunArrayHandle hRuns; /* handle to the style run array */
- long textLength; /* length of text */
- long nLines; /* number of lines */
- long nStyles; /* number of unique styles in the style table */
- long nRuns; /* number of style runs */
- LongRect viewRect; /* view rectangle, all drawing is clipped to this */
- LongRect destRect; /* destination rectangle */
- long selStart; /* start of selection range */
- long selEnd; /* end of selection range */
- long flags; /* 32 bits of miscellaneous flags */
- long caretTime; /* time of most recent caret drawing, in ticks */
- long clickTime; /* time of most recent click, in ticks */
- long clickLoc; /* byte offset of most recent click */
- long anchorStart; /* start offset of anchor word/line */
- long anchorEnd; /* end offset of anchor word/line */
- ProcPtr clickLoop; /* click loop callback */
- char unused1; /* unused */
- char clickEdge; /* edge of character hit by most recent click */
- char unused2; /* unused */
- char firstByte; /* first byte of a double-byte character */
- GrafPtr offscreenPort; /* offscreen graphics world */
- RgnHandle viewRgn; /* handle to the view region */
- ProcPtr scrollProc; /* scroll callback */
- short clickCount; /* multiple click count */
- char alignment; /* alignment style */
- long refCon; /* reference value for client use */
- TSMDocumentID tsmReference; /* reference value for the text services manager */
- long tsmAreaStart; /* start of active input area (for TSM) */
- long tsmAreaEnd; /* end of active input area */
- ProcPtr tsmPreUpdate; /* TSM pre-update callback */
- ProcPtr tsmPostUpdate; /* TSM post-update callback */
- WERunAttributes nullStyle; /* style for null selection */
- } WERec, *WEPtr, **WEHandle;
-
- #if defined(powerc) || defined (__powerc)
- #pragma options align=reset
- #endif
-
- /* callback prototypes */
-
- typedef pascal Boolean (*WEClickLoopProcPtr)(WEHandle hWE);
- typedef pascal void (*WEScrollProcPtr)(WEHandle hWE);
- typedef pascal void (*WETSMPreUpdateProcPtr)(WEHandle hWE);
- typedef pascal void (*WETSMPostUpdateProcPtr)(WEHandle hWE,
- long fixLength, long inputAreaStart, long inputAreaEnd,
- long pinRangeStart, long pinRangeEnd);
-
- typedef Boolean (*SegmentLoopProcPtr)
- (LinePtr pLine,
- WERunAttributesPtr pAttrs,
- Ptr pSegment,
- long segmentStart,
- long segmentLength,
- JustStyleCode styleRunPosition,
- void *callbackData);
-
- struct SLDrawData {
- WEPtr pWE;
- Rect bounds; /* same rectangle, but in global coords */
- Boolean usingColor; /* true if drawing in color */
- Boolean usingOffscreen; /* true if an offscreen graphics world has been set up */
- Boolean drawingOffscreen; /* true if actually drawing to an offscreen buffer */
- Boolean doErase;
- };
-
- struct SLCalcSlopData {
- WEPtr pWE;
- short lineWidth;
- short totalSlop;
- Fixed totalProportion;
- };
-
- struct SLPixelToCharData {
- WEPtr pWE;
- Fixed pixelWidth;
- long offset;
- char *edge;
- };
-
- struct SLCharToPixelData {
- WEPtr pWE;
- long offset;
- LongPt *thePoint;
- };
-
- // { ****** ASSEMBLY ROUTINES DEFINED IN WASTEUTILS.LIB ****** }
-
- void _WEForgetHandle(Handle *h);
- Boolean _WESetHandleLock(Handle h, Boolean lock);
- void _WEBlockClr(Ptr block, long blockSize);
- Boolean _WEBlockCmp(Ptr block1, Ptr block2, long blockSize);
- OSErr _WEInsertSlot(Handle h, Ptr element, long insertAt, long slotSize);
- OSErr _WERemoveSlot(Handle h, long removeAt, long slotSize);
- void _WEReorder(long *a, long *b);
-
- /*** in TSMSupport.c ***/
- OSErr _WEHiliteRangeArray(TextRangeArrayHandle hTray, WEHandle hWE);
- pascal OSErr _WEHandleUpdateActiveInputArea(AppleEvent *ae, AppleEvent *reply,
- long handlerRefCon);
- pascal OSErr _WEHandlePositionToOffset(AppleEvent *ae, AppleEvent *reply,
- long handlerRefCon);
- pascal OSErr _WEHandleOffsetToPosition(AppleEvent *ae, AppleEvent *reply, long handlerRefCon);
- pascal OSErr WEInstallTSMHandlers(void);
-
- /*** in LongCoords.c ***/
- long _WEPinInRange(long value, long rangeStart, long rangeEnd);
- pascal void WELongPointToPoint(const LongPt *lp, Point *p);
- pascal void WEPointToLongPoint(Point p, LongPt *lp);
- pascal void WESetLongRect(LongRect *lr, long left, long top, long right, long bottom);
- pascal void WELongRectToRect(const LongRect *lr, Rect *r);
- pascal void WERectToLongRect(const Rect *r, LongRect *lr);
- pascal void WEOffsetLongRect(LongRect *lr, long hOffset, long vOffset);
- pascal Boolean WELongPointInLongRect(const LongPt *lp, const LongRect *lr);
-
- /*** in WASTE1.c ***/
- long _WEOffsetToLine (long offset, WEHandle hWE);
- long _WEPixelToLine(long vOffset, WEHandle hWE);
- long _WEOffsetToRun (long offset, WEHandle hWE);
- void _WEGetIndStyle(long runIndex, WERunInfo *info, WEHandle hWE);
- pascal void WEGetRunInfo(long offset, WERunInfo *info, WEHandle hWE);
- void _WEContinuousStyleRange(long rangeStart, long rangeEnd, short *mode,
- WETextStyle *ts, WEHandle hWE);
- void _WESynchNullStyle(WEHandle hWE);
- pascal Boolean WEContinuousStyle (short *mode, WETextStyle *ts, WEHandle hWE);
- void _WESegmentLoop(long firstLine, long lastLine, SegmentLoopProcPtr callback, void *callbackData,
- WEHandle hWE);
- void _WEDrawTSMHilite(Rect *segmentRect, short tsFlags);
- void _WEDrawLines (long firstLine, long lastLine, Boolean doErase, WEHandle hWE);
- OSErr _WEAllocate (Size blockSize, short allocFlags, Handle *h);
- short _WECalcPenIndent(short slop, short alignment);
- void _WESaveQDEnvironment(GrafPtr port, Boolean saveColor, QDEnvironment *theEnvironment);
- void _WERestoreQDEnvironment(QDEnvironment *theEnvironment);
- void _WEFillFontInfo (GrafPtr port, WERunAttributes *targetStyle);
- void _WECopyStyle (WETextStyle *sourceStyle, WETextStyle *targetStyle, short offStyles,
- short mode);
- Boolean _WEOffsetInRange(long offset, char edge, long rangeStart, long rangeEnd);
-
- /*** in WASTE2.c ***/
- OSErr _WERegisterWithTSM(WEHandle hWE);
- pascal void WEStopInlineSession(WEHandle hWE);
- pascal OSErr WENew(LongRect *destRect, LongRect *viewRect, short flags, WEHandle *hWE);
- pascal void WEDispose(WEHandle hWE);
- OSErr _WERemoveLine(long lineIndex, WEPtr pWE);
- OSErr InsertLine(long lineIndex, LineRec *theLine, WEPtr pWE);
- void _WEBumpOrigin(long lineIndex, long deltaOrigin, WEPtr pWE);
- long _WEFindLineBreak(long lineStart, WEHandle hWE);
- void _WECalcHeights(long rangeStart, long rangeEnd, short *lineAscent, short *lineDescent,
- WEHandle hWE);
- OSErr _WERecalBreaks(long *startLine, long *endLine, WEHandle hWE);
- void _WERecalSlops(long firstLine, long lastLine, WEHandle hWE);
- pascal OSErr WECalText(WEHandle hWE);
- pascal OSErr WEUseText(Handle text, WEHandle hWE);
- pascal char WEGetAlignment(WEHandle hWE);
- pascal void WEGetSelection(long *selStart, long *selEnd, WEHandle hWE);
- pascal void WESetDestRect(LongRect *destRect, WEHandle hWE);
- pascal void WEGetDestRect(LongRect *destRect, WEHandle hWE);
- pascal void WESetViewRect(LongRect *viewRect, WEHandle hWE);
- pascal void WEGetViewRect(LongRect *viewRect, WEHandle hWE);
- pascal long WEGetTextLength(WEHandle hWE);
- pascal long WECountLines(WEHandle hWE);
- pascal long WEGetHeight(long startLine, long endLine, WEHandle hWE);
- pascal Handle WEGetText(WEHandle hWE);
- pascal char WEGetChar(long offset, WEHandle hWE);
- pascal short WECharByte(long offset, WEHandle hWE);
- pascal short WECharType(long offset, WEHandle hWE);
- pascal OSErr WECopyRange(long rangeStart, long rangeEnd, Handle hText, WEStyleScrapHandle
- hStyles, WEHandle hWE);
- pascal OSErr WECopy(WEHandle hWE);
- pascal short WEFeatureFlag(short feature, short action, WEHandle hWE);
- pascal OSErr WEGetInfo(OSType selector, Ptr info, WEHandle hWE);
- pascal OSErr WESetInfo(OSType selector, Ptr info, WEHandle hWE);
-
- /*** in WASTE3.c ***/
- void ClearHiliteBit(void);
- pascal long WEGetOffset(LongPt *thePoint, char *edge, WEHandle hWE);
- pascal void WEGetPoint(long offset, LongPt *thePoint, short *lineHeight, WEHandle hWE);
- pascal void WEFindLine(long offset, char edge, long *lineStart, long *lineEnd, WEHandle hWE);
- pascal short WEFindScriptRun(long offset, char edge, long *scriptRunStart, long *scriptRunEnd,
- WEHandle hWE);
- pascal void WEFindWord(long offset, char edge, long *wordStart, long *wordEnd, WEHandle hWE);
- void _WEDrawCaret(WEHandle hWE);
- pascal RgnHandle WEGetHiliteRgn(long rangeStart, long rangeEnd, WEHandle hWE);
- void _WEHiliteRange(long rangeStart, long rangeEnd, WEHandle hWE);
- pascal void WESetSelection(long selStart, long selEnd, WEHandle hWE);
- pascal void WEClick(Point mouseLoc, short modifiers, long clickTime, WEHandle hWE);
- pascal void WESetAlignment(char alignment, WEHandle hWE);
- long _WEArrowOffset(short action, long offset, WEHandle hWE);
- void _WEDoArrowKey (short arrow, short modifiers, WEHandle hWE);
- pascal Boolean WEAdjustCursor(Point mouseLoc, RgnHandle mouseRgn, WEHandle hWE);
- pascal void WEIdle(long *maxSleep, WEHandle hWE);
- pascal void WEUpdate(RgnHandle updateRgn, WEHandle hWE);
- pascal void WEDeactivate(WEHandle hWE);
- pascal void WEActivate(WEHandle hWE);
- pascal Boolean WEIsActive(WEHandle hWE);
- pascal void WEScroll(long hOffset, long vOffset, WEHandle hWE);
- Boolean _WEScrollIntoView (long offset, WEHandle hWE);
- pascal void WESelView(WEHandle hWE);
-
- /*** in WASTE4.c ***/
- OSErr _WEInsertRun(long runIndex, long offset, long styleIndex, WEPtr pWE);
- OSErr _WERemoveRun(long runIndex, WEPtr pWE);
- void _WEChangeRun(long runIndex, long newStyleIndex, WEPtr pWE);
- OSErr _WENewStyle(WERunAttributes *ts, long *styleIndex, WEPtr pWE);
- OSErr _WERedraw(long rangeStart, long rangeEnd, WEHandle hWE);
- OSErr _WESetStyleRange(long rangeStart, long rangeEnd, short mode, WETextStyle *ts, WEHandle hWE);
- OSErr _WEApplyStyleScrap(long rangeStart, long rangeEnd, WEStyleScrapHandle styleScrap, WEHandle hWE);
- void _WEBumpRunStart(long runIndex, long deltaRunStart, WEPtr pWE);
- OSErr _WERemoveRunRange(long rangeStart, long rangeEnd, WEHandle hWE);
- void _WEBumpLineStart(long lineIndex, long deltaLineStart, WEPtr pWE);
- OSErr _WERemoveLineRange(long rangeStart, long rangeEnd, WEHandle hWE);
- OSErr _WEDeleteRange(long rangeStart, long rangeEnd, WEHandle hWE);
- OSErr _WEInsertText(long offset, Ptr textPtr, long textLength, WEHandle hWE);
- pascal OSErr WEDelete(WEHandle hWE);
- pascal OSErr WEInsert(Ptr textPtr, long textLength, WEStyleScrapHandle styleScrap, WEHandle hWE);
- void _WEInsertByte(char theByte, WEHandle hWE);
- void _WEBackspace(WEHandle hWE);
- pascal void WEKey(short key, short modifiers, WEHandle hWE);
- pascal OSErr WECut(WEHandle hWE);
- pascal OSErr WESetStyle(short mode, WETextStyle *ts, WEHandle hWE);
- pascal OSErr WEUseStyleScrap(WEStyleScrapHandle styleScrap, WEHandle hWE);
- pascal OSErr WEPaste(WEHandle hWE);
-
-
-
-
-