Important: The information in this document is obsolete and should not be used for new development.
Summary of TextEdit
Pascal Summary
Constants
CONST {Gestalt returned values} gestaltUndefSelectorErr {Systems before 6.0.4, multistyled TextEdit } { on all hardware} gestaltTE1 = 1; {System 6.0.4 Roman script system on } { IIci-family hardware} gestaltTE2 = 2; {Script Manager-compatible. System 6.0.4 } { non-Roman script systems on all } { IIci family hardware.New measuring hook } { nWIDTHHook.} gestaltTE3 = 3; {Script Manager-compatible. System 6.0.4 } { non-Roman script systems on all non-IIci } { family hardware.} gestaltTE4 = 4; {Script Manager-compatible. System 6.0.5 on } { all hardware. New TEFeatureFlag function.} gestaltTE5 = 5; {Script Manager-compatible. System 7.0 on all } {hardware} {alignment styles: new constant names for the align parameter } { of TESetAlignment and TETextBox} teFlushDefault = 0; {flush according to system direction } teCenter = 1; {centered for all scripts } teFlushRight = -1; {flush right for all scripts} teFlushLeft = -2; {flush left for all scripts} {alignment styles; old constant names supported for } { backward-compatibility} teJustLeft = 0; teJustCenter = 1; teJustRight = -1; teForceLeft = -2; {values for TEFeatureFlag feature parameter} teFAutoScroll = 0; {automatic scrolling teFAutoScr = 0; {old constant for automatic scrolling} teFTextBuffering = 1; {text buffering} teFOutlineHilite = 2; {outline highlighting} teFInlineInput = 3; {inline input} teFUseTextServices = 4; {use inline input service} {values for TEFeatureFlag action parameter} teBitClear = 0; {clear TEFeatureFlag features} teBitSet = 1; {set TEFeatureFlag features} teBitTest = -1; {test TEFeatureFlag features: return } { the current setting} {selectors for identifying the routine that called TEFindWord } teWordSelect = 4; {called for determining new } { line breaks} teWordDrag = 8; {called for extending word selection} teFromFind = 12; {called for word selection} teFromRecal = 16; {called for word breaking in line } { recalculation} {values for TESetStyle/TEContinuousStyle/TEReplaceStyle modes} doFont = 1; {set font family number} doFace = 2; {set character style} doSize = 4; {set type size} doColor = 8; {set color} doAll = 15; {set all attributes} addSize = 16; {adjust type size } doToggle = 32; {toggle mode for TESetStyle} {selectors for TECustomHook} intEOLHook = 0; {end-of-line hook} intDrawHook = 1; {drawing hook} intWidthHook = 2; {width measurement hook} intHitTestHook = 3; {hit-test hook} intNWidthHook = 6; {nWIDTHHook measurement hook} intTextWidthHook = 7; {TextWidth measurement hook}Data Types
TYPE TERec = RECORD destRect: Rect; {destination rectangle} viewRect: Rect; {view rectangle} selRect: Rect; {the selection rectangle} lineHeight: Integer; {used for vertical spacing of lines} fontAscent: Integer; {used for caret/highlighting position} selPoint: Point; {point selected with the mouse} selStart: Integer; {start of selection range} selEnd: Integer; {end of selection range} active: Integer; {set when record is } { activated/deactivated} wordBreak: ProcPtr; {word break hook} clikLoop: ProcPtr; {click loop hook} clickTime: LongInt; {used internally} clickLoc: Integer; {used internally} caretTime: LongInt; {used internally} caretState: Integer; {used internally} just: Integer; {alignment of text} teLength: Integer; {length of text} hText: Handle; {handle to text to be edited} hDispatchRec: LongInt; {handle to TextEdit } { dispatch record} clikStuff: Integer; {used internally} crOnly: Integer; {if <0, new line at Return only} txFont: Integer; {text font} txFace: Style; {character style; unpacked byte} txMode: Integer; {pen mode} txSize: Integer; {value indicates either a multistyled } { edit record or a font size} inPort: GrafPtr; {a pointer to the grafPort for this TERec} highHook: ProcPtr; {used for text highlighting } caretHook: ProcPtr; {used for the caret appearance} nLines: Integer; {number of lines} lineStarts: ARRAY[0..16000] OF Integer; {positions of line starts} END; TEPtr = ^TERec; TEHandle = ^TEPtr; Chars= PACKED ARRAY[0..32000] OF CHAR; CharsHandle = ^CharsPtr; CharsPtr = ^Chars; TEStyleRec = RECORD nRuns: Integer; {number of style runs} nStyles: Integer; {size of style table} styleTab: STHandle; {handle to style table} lhTab: LHHandle; {handle to line-height table} teRefCon: LongInt; {reserved for application use} nullStyle: NullStHandle; {handle to style set at } { null selection} runs: ARRAY [0..8000] OF StyleRun; {ARRAY [0..8000] OF StyleRun} END; TEStylePtr = ^TEStyleRec; TEStyleHandle = ^TEStylePtr; StyleRun = RECORD startChar: Integer; {starting character position} styleIndex: Integer; {index in style table} END; STElement = RECORD stCount: Integer; {number of runs in this style} stHeight: Integer; {line height} stAscent: Integer; {font ascent} stFont: Integer; {font (family) number} stFace: Style; {character style} stSize: Integer; {size in points} stColor: RGBColor; {absolute RGB color} END; STPtr = ^TEStyleTable; STHandle = ^STPtr; TEStyleTable = ARRAY [0..1776] OF STElement; LHElement = RECORD lhHeight: Integer; {maximum height in line} lhAscent: Integer; {maximum ascent in line} END; LHPtr = ^LHTable; LHHandle = ^LHPtr; LHTable = ARRAY [0..8000] OF LHElement; ScrpSTElement = RECORD scrpStartChar: LongInt; {offset to start of style} scrpHeight: Integer; {line height} scrpAscent: Integer; {font ascent} scrpFont: Integer; {font (family) number} scrpFace: Style; {character style} scrpSize: Integer; {size in points} scrpColor: RGBColor; {absolute (RGB) color} END; ScrpStyl2Tab = ARRAY[0..1600] OF ScrpSTElement; StScrpRec = RECORD scrpNStyles: Integer; {number of styles in scrap} scrpStyleTab: ScrpSTTable; {table of styles for scrap} END; StScrpPtr = ^StScrpRec; StScrpHandle = ^StScrpPtr; NullStRec = RECORD teReserved: LongInt; {reserved for future expansion} nullScrap: StScrpHandle; {handle to scrap style table} END; NullStPtr = ^NullStRec; NullStHandle = ^NullStPtr; TextStyle = RECORD tsFont: Integer; {font (family) number} tsFace: Style; {character Style} tsSize: Integer; {size in points} tsColor: RGBColor; {absolute (RGB) color} END; TextStylePtr = ^TextStyle; TextStyleHandle = ^TextStylePtr; TEIntHook = Integer;Routines
Initializing TextEdit, Creating an Edit Record, and Disposing of an Edit Record
PROCEDURE TEInit; FUNCTION TEStyleNew (destRect: Rect; viewRect: Rect): TEHandle; FUNCTION TENew (destRect, viewRect: Rect): TEHandle; PROCEDURE TEDispose (hTE: TEHandle);Activating and Deactivating an Edit Record
PROCEDURE TEActivate (hTE: TEHandle); PROCEDURE TEDeactivate (hTE: TEHandle);Setting and Getting an Edit Record's Text and Character Attribute Information
PROCEDURE TEKey (key: Char; hTE: TEHandle); PROCEDURE TESetText (text: Ptr; length: LongInt; hTE: TEHandle); FUNCTION TEGetText (hTE: TEHandle): CharsHandle; PROCEDURE TESetStyleHandle (theHandle: TEStyleHandle; hTE: TEHandle); FUNCTION TEGetStyleHandle (hTE: TEHandle): TEStyleHandle;Setting the Caret and Selection Range
PROCEDURE TEIdle (hTE: TEHandle); PROCEDURE TEClick (pt: Point; extend: Boolean; hTE: TEHandle); PROCEDURE TESetSelect (selStart, selEnd: LongInt; hTE: TEHandle);Displaying and Scrolling Text
PROCEDURE TESetAlignment (align: Integer; hTE: TEHandle); PROCEDURE TEUpdate (rUpdate: Rect; hTE: TEHandle); PROCEDURE TETextBox (text: Ptr; length: LongInt; box: Rect; just: Integer); PROCEDURE TECalText (hTE: TEHandle); FUNCTION TEGetHeight (endLine, startLine:LONGINT; hTE: TEHandle): INTEGER; PROCEDURE TEScroll (dh,dv: Integer; hTE: TEHandle); PROCEDURE TEPinScroll (dh: INTEGER; dv: INTEGER; hTE: TEHandle); PROCEDURE TEAutoView (fAuto: Boolean; hTE: TEHandle); PROCEDURE TESelView (hTE: TEHandle);Modifying the Text of an Edit Record
PROCEDURE TEDelete (hTE: TEHandle); PROCEDURE TEInsert (text: Ptr; length: LongInt; hTE: TEHandle); PROCEDURE TECut (hTE: TEHandle); PROCEDURE TECopy (hTE: TEHandle); PROCEDURE TEPaste (hTE: TEHandle); PROCEDURE TEStylePaste (hTE: TEHandle); FUNCTION TEToScrap: OSErr; FUNCTION TEFromScrap: OSErr;Managing the TextEdit Private Scrap
FUNCTION TEScrapHandle: Handle; FUNCTION TEGetScrapLength: LongInt; PROCEDURE TESetScrapLength (length: LongInt);Checking, Setting, and Replacing Styles
PROCEDURE TESetStyle (mode: Integer; newStyle: TextStyle; redraw: Boolean; hTE: TEHandle); PROCEDURE TEReplaceStyle (mode: INTEGER; oldStyle, newStyle: TextStyle; redraw: BOOLEAN; hTE: TEHandle); FUNCTION TEContinuousStyle (VAR mode: Integer; VAR aStyle: TextStyle; hTE: TEHandle) : Boolean; PROCEDURE TEStyleInsert (text: Ptr; length: LongInt; hST: STScrpHandle; hTE: TEHandle); FUNCTION TEGetStyleScrapHandle (hTE: TEHandle): StyleScrpHandle; PROCEDURE TEUseStyleScrap (rangeStart: LongInt; rangeEnd: LongInt; newStyles: STScrpHandle; redraw: Boolean; hTE: TEHandle); FUNCTION TENumStyles (rangeStart: LongInt; rangeEnd: LongInt; hTE: TEHandle): LongInt;Using Byte Offsets and Corresponding Points
FUNCTION TEGetOffset (pt: Point; hTE: TEHandle): Integer; FUNCTION TEGetPoint (offset: Integer; hTE: TEHandle): Point;Additional TextEdit Features
FUNCTION TEFeatureFlag (feature: Integer; action: Integer; hTE: TEHandle) : Integer;Customizing TextEdit
PROCEDURE TECustomHook (which: TEIntHook; VAR addr: ProcPtr; hTE: TEHandle); PROCEDURE TESetWordBreak (wBrkProc: ProcPtr; hTE: TEHandle); PROCEDURE TESetClickLoop (clickProc: ProcPtr; hTE: TEHandle);C Summary
Constants
enum { /*alignment styles of TESetAlignment and TETextBox*/ teFlushDefault = 0, /*flush according to system direction*/ teCenter = 1, /*centered for all scripts*/ teFlushRight = -1, /*flush right for all scripts*/ teFlushLeft = -2, /*flush left for all script*/ /*alignment styles; old names supported for backward-compatibility*/ teJustLeft = 0, teJustCenter = 1, teJustRight = -1, teForceLeft = -2, /*feature or bit definitions for TEFeatureFlag feature parameter*/ teFAutoScroll = 0, /*automatic scrolling*/ teFAutoScr = 0, /*old constant for automatic scrolling*/ teFTextBuffering = 1, /*text buffering*/ teFOutlineHilite = 2, /*outline highlighting*/ teFInlineInput = 3, /*inline input*/ teFUseTextServices = 4, /*use inline input service*/ /* action for the new bit (un)set interface,TEFeatureFlag */ teBitClear = 0, /*set the selector bit*/ teBitSet = 1, }; enum { teBitTest = -1, /*no change; just return the current setting*/ teBitClear = 0, teBitSet = 1, /*set the selector bit*/ teBitTest = -1, /*no change; just return the current setting*/ /*constants for identifying the routine that called TEFindWord */ teWordSelect = 4, /*clickExpand to select word*/ teWordDrag = 8, /*clickExpand for extending word selection*/ teFromFind = 12, /*FindLine called it ($0C)*/ teFromRecal = 16, /*called for word breaking in line recalculation*/ /*values for TESetStyle/TEContinuousStyle/TEReplaceStyle modes*/ doFont = 1, /*set font family number*/ doFace = 2, /*set character style*/ doSize = 4, /*set type size*/ doColor = 8, /*set color*/ doAll = 15, /*set all attributes*/ addSize = 16, /*adjust type size*/ }; enum { doToggle = 32, /*toggle mode for TESetStyle*/ /*selectors for TECustomHook*/ intEOLHook = 0, /*end-of-line hook*/ intDrawHook = 1, /*drawing hook*/ intWidthHook = 2, /*width measurement hook*/ intHitTestHook = 3, /*hit-test hook*/ intNWidthHook = 6, /*nWIDTHHook measurement hook*/ intTextWidthHook = 7, /*TextWidth measurement hook*/ };Types
typedef pascal Boolean (*WordBreakProcPtr)(Ptr text, short charPos); typedef pascal Boolean (*ClikLoopProcPtr)(void); struct TERec { Rect destRect; /*destination rectangle*/ Rect viewRect; /*view rectangle*/ Rect selRect; /*the selection rectangle*/ short lineHeight; /*used for vertical spacing of lines*/ short fontAscent; /*used for caret/highlighting position*/ Point selPoint; /*point selected with the mouse*/ short selStart; /*start of selection range*/ short selEnd; /*end of selection range*/ short active; /*set when record is activated/deactivated*/ WordBreakProcPtr wordBreak; /*word break hook*/ ClikLoopProcPtr clikLoop; /*click loop hook*/ long clickTime; /*used internally*/ short clickLoc; /*used internally*/ long caretTime; /*used internally*/ short caretState; /*used internally*/ short just; /*alignment of text*/ short teLength; /*length of text*/ Handle hText; /*handle to text to be edited*/ long hDispatchRec; /*handle to TextEdit dispatch record*/ short clikStuff; /*used internally*/ short crOnly; /*if <0, new line at Return only*/ short txFont; /*text font*/ Style txFace; /*character style; unpacked byte*/ char filler; short txMode; /*pen mode*/ short txSize; /*value indicates either a multistyled edit record or a font size*/ GrafPtr inPort; /*a pointer to the grafPort for this TERec*/ ProcPtr highHook; /*used for text highlighting and the caret appearance*/ ProcPts caretHook; /*used from assembly language*/ short nLines; /*number of lines*/ short lineStarts[16000];/*positions of line starts*/ }; typedef struct TERec TERec; typedef TERec *TEPtr, **TEHandle; typedef char Chars[32001]; typedef char *CharsPtr, **CharsHandle; struct StyleRun { short startChar; /*starting character position*/ short styleIndex; /*index in style table*/ }; typedef struct StyleRun StyleRun; struct STElement { short stCount; /*number of runs in this style*/ short stHeight; /*line height*/ short stAscent; /*font ascent*/ short stFont; /*font family number*/ Style stFace; /*character style*/ char filler; /*stFace is unpacked byte*/ short stSize; /*size in points*/ RGBColor stColor; /*absolute Red Green Blue color*/ }; typedef struct STElement STElement; typedef STElement TEStyleTable[1777], *STPtr, **STHandle; struct LHElement { short lhHeight; /*maximum height in line*/ short lhAscent; /*maximum ascent in line*/ }; typedef struct LHElement LHElement; typedef LHElement LHTable[8001], *LHPtr, **LHHandle; /* ARRAY [0..8000] OF LHElement */ struct ScrpSTElement { long scrpStartChar; /*starting character position*/ short scrpHeight; /*line height*/ short scrpAscent; short scrpFont; Style scrpFace; /*unpacked byte*/ char filler; /*scrpFace is unpacked byte*/ short scrpSize; RGBColor scrpColor; }; typedef struct ScrpSTElement ScrpSTElement; typedef ScrpSTElement ScrpSTTable[1601]; /*ARRAY [0..1600] OF ScrpSTElement*/ struct STScrpRec { short scrpNStyle; /*number of styles in scrap*/ ScrpSTTable scrpStyleTab; /*table of style for scrap*/ }; typedef struct StScrpRec StScrpRec; typedef StScrpRec *StScrpPtr, **StScrpHandle; struct NullSTRec { long teReserved; /*reserved for future expansion*/ StScrpHandle nullScrap; /*handle to scrap style table*/ }; typedef struct NullStRec NullSTRec; typedef NullStRec *NullStPtr, **NullStHandle; struct TEStyleRec { short nRuns; /*number of style runs*/ short nStyles; /*size of style table*/ STHandle styleTab; /*handle to style table*/ LHHandle lhTab; /*handle to line-height table*/ long teRefCon; /*reserved for application use*/ NullSTHandle nullStyle; /*handle to style set at null selection*/ StyleRun runs [8001]; /*ARRAY [0..8000] OF StyleRun*/ }; typedef struct TEStyleRec TEStyleRec; typedef TEStyleRec *TEStylePtr, **TEStyleHandle; struct TextStyle { short tsFont; /*font family number*/ Style tsFace; /*character Style*/ char filler; /*tsFace is unpacked byte*/ short tsSize; /*size in points*/ RGBColor tsColor; /*absolute red, green, and blue color*/ }; typedef struct TextStyle TextStyle; typedef TextStyle *TextStylePtr, **TextStyleHandle; typedef short TEIntHook;Routines
Initializing TextEdit, Creating an Edit Record, and Disposing of an Edit Record
pascal void TEInit (void); pascal TEHandle TEStyleNew (const Rect *destRect,const Rect *viewRect); pascal TEHandle TENew (const Rect *destRect, const Rect *viewRect); pascal void TEDispose (TEHandle hTE);Activating and Deactivating an Edit Record
pascal void TEActivate (TEHandle hTE); pascal void TEDeactivate (TEHandle hTE);Setting and Getting an Edit Record's Text and Character Attribute Information
pascal void TEKey (short key, TEHandle hTE); pascal void TESetText (const void *text, long length, TEHandle hTE); pascal CharsHandle TEGetText (TEHandle hTE); pascal void TESetStyleHandle (TEStyleHandle theHandle, TEHandle hTE); pascal TEStyleHandle TEGetStyleHandle (TEHandle hTE);Setting the Caret and Selection Range
pascal void TEIdle (TEHandle hTE); pascal void TEClick (Point pt, Boolean fExtend, TEHandle hTE); pascal void TESetSelect (long selStart, long selEnd, TEHandle hTE);Displaying and Scrolling Text
pascal void TESetAlignment (short just, TEHandle hTE); pascal void TEUpdate (const Rect *rUpdate, TEHandle hTE); pascal void TETextBox (const void *text, long length, const Rect *box, short just); pascal void TECalText (TEHandle hTE); pascal long TEGetHeight (long endLine, long startLine, TEHandle hTE); pascal void TEScroll (short dh, short dv, TEHandle hTE); pascal void TEPinScroll (short dh, short dv, TEHandle hTE); pascal void TEAutoView (Boolean fAuto, TEHandle hTE); pascal void TESelView (TEHandle hTE);Modifying the Text of an Edit Record
pascal void TEDelete (TEHandle hTE); pascal void TEInsert (const void *text, long length, TEHandle hTE); pascal void TECut (TEHandle hTE); pascal void TECopy (TEHandle hTE); pascal void TEPaste (TEHandle hTE); pascal void TEStylePaste (TEHandle hTE); pascal OSErr TEToScrap (void); pascal OSErr TEFromScrap (void);Managing the TextEdit Private Scrap
#define TEScrapHandle() (* (Handle*) 0xAB4) #define TEGetScrapLength() ((long) * (unsigned short *) 0x0AB0) pascal void TESetScrapLength (long length);Checking, Setting, and Replacing Styles
pascal void TESetStyle (short mode, const TextStyle *newStyle, Boolean fRedraw, TEHandle hTE); pascal void TEReplaceStyle (short mode, onst TextStyle *oldStyle, const TextStyle *newStyle, Boolean fRedraw, TEHandle hTE); pascal Boolean TEContinuousStyle (short *mode, TextStyle *aStyle, TEHandle hTE); pascal void TEStyleInsert (const void *text, long length, STScrpHandle hSt, TEHandle hTE); pascal StScrpHandle TEGetStyleScrapHandle (TEHandle hTE); pascal void TEUseStyleScrap (long rangeStart, long rangeEnd, StScrpHandle newStyles, Boolean fRedraw, TEHandle hTE); pascal long TENumStyles (long rangeStart, long rangeEnd, TEHandle hTE);Using Byte Offsets and Corresponding Points
pascal short TEGetOffset (Point pt, TEHandle hTE); pascal Point TEGetPoint (short offset, TEHandle hTE);Additional TextEdit Features
pascal short TEFeatureFlag (short feature, short action, TEHandle hTE);Customizing TextEdit
pascal void TECustomHook (TEIntHook which, ProcPtr *addr, TEHandle hTE); pascal void TESetWordBreak (WordBreakProcPtr wBrkProc, TEHandle hTE); pascal void TESetClickLoop (ClikLoopProcPtr clickProc, TEHandle hTE);Assembly-Language Summary
Trap Macros
Trap Macro Names
Pascal name Trap macro name TEContinuousStyle _TEContinuousStyle TEUseStyleScrap _TEUseStyleScrap TECustomHook _TECustomHook TENumStyles _TENumStyles TEFeatureFlag _TEFeatureFlag TEStylePaste _TEStylePaste TEReplaceStyle _TEReplaceStyle TEGetStyleHandle _TEGetStyleHandle TESetStyleHandle _TESetStyleHandle TEReplaceStyle _TEReplaceStyle TEGetStyleScrap _TEGetStyleScrap TEGetStyleHandle _TEGetStyleHandle TEGetStyleScrapHandle _TEGetStyleScrapHandle TEStyleInsert _TEStyleInsert TEGetPoint _TEGetPoint TEGetHeight _TEGetHeight Global Variables
WordRedraw Used for line calculations to determine how much of a line must be redrawn after a character is entered. TEFindWord TextEdit's word selection and line breaking routine. TERecal The address of the routine called by TECalText
to recalculate the line starts
and set the first and last characters that need to be redrawn.TEDoText The address of a multi-purpose text editing routine used to display, highlight,
and hit-test characters, and position the pen to draw the caret.TEScrpHandle A handle to the TextEdit private scrap. TEScrapLength The size of the TextEdit scrap in bytes.