home *** CD-ROM | disk | FTP | other *** search
- /*
- Text.h
- Application Kit, Release 2.1J
- Copyright (c) 1988, NeXT, Inc. All rights reserved.
- */
-
- #import "NSText.h"
- #import "NSView.h"
- #import "chunk.h"
- #import "NSColor.h"
- #import "NSFontManager.h"
- #import "NSSpellChecker.h"
- #import "NXRTFDErrors.h"
-
- #ifdef KANJI
- typedef wchar_t wchar; // Basic character type
- #else KANJI
- typedef unsigned char wchar; // Basic character type
- #endif KANJI
-
- #define NSTextBlockSize 512
-
- typedef struct _NXTextBlock {
- struct _NXTextBlock *next; /* next text block in link list */
- struct _NXTextBlock *prior; /* previous text block in link list */
- struct _tbFlags {
- unsigned int malloced:1; /* true if block was malloced */
- unsigned int PAD:15;
- } tbFlags;
- short chars; /* number of chars in this block */
- wchar *text; /* the text */
- } NSTextBlock;
-
- /*
- * NXRun represents a single run of text w/ a given format
- */
-
- typedef struct {
- unsigned int underline:1;
- unsigned int dummy:1; /* unused */
- unsigned int subclassWantsRTF:1;
- unsigned int graphic:1;
- unsigned int forcedSymbol:1; /* did alt-char force use to use symbol */
- unsigned int RESERVED:11;
- } NSRunFlags;
-
- typedef struct _NXRun {
- id font; /* Font id */
- int chars; /* number of chars in run */
- void *paraStyle; /* implementation dependent paraStyle
- * sheet info. */
- float textGray; /* text gray of current run */
- int textRGBColor; /* text color negative if not set */
- unsigned char superscript;/* superscript in points */
- unsigned char subscript; /* subscript in points */
- id info; /* available for subclasses of Text */
- NSRunFlags rFlags;
- } NSRun;
-
- /*
- * NXRunArray is a NXChunk that holds the set of formats for a Text object
- */
-
- typedef struct _NXRunArray {
- NSTextChunk chunk;
- NSRun runs[1];
- } NSRunArray;
-
- /*
- * NXBreakArray is a NXChunk that holds line break information for a Text
- * Object. it is mostly an array of line descriptors. each line
- * descriptor contains 3 fields:
- *
- * 1) line change bit (sign bit), set if this line defines a new height
- * 2) paragraph end bit (next to sign bit), set if the end of this
- * line ends the paragraph
- * 3) numbers of characters in the line (low order 14 bits)
- *
- * if the line change bit is set, the descriptor is the first field of a
- * NXHeightChange. since this record is bracketed by negative short
- * values, the breaks array can be sequentially accessed backwards and
- * forwards.
- */
-
- #if m68k
- typedef short NSLineDesc;
- #else
- typedef int NSLineDesc;
- #endif
-
- typedef struct _NXHeightInfo {
- float newHeight; /* line height from here forward */
- float oldHeight; /* height before change */
- NSLineDesc lineDesc; /* line descriptor */
- } NSHeightInfo;
-
- typedef struct _NXHeightChange {
- NSLineDesc lineDesc; /* line descriptor */
- NSHeightInfo heightInfo;
- } NSHeightChange;
-
- typedef struct _NXBreakArray {
- NSTextChunk chunk;
- NSLineDesc breaks[1];
- } NSBreakArray;
-
- /*
- * NXLay represents a single run of text in a line and records
- * everything needed to select or draw that piece.
- */
-
- typedef struct {
- unsigned int mustMove:1; /* unimplemented */
- unsigned int isMoveChar:1;
- unsigned int RESERVED:14;
- } NSLayFlags;
-
- typedef struct _NXLay {
- float x; /* x coordinate of moveto */
- float y; /* y coordinate of moveto */
- short offset; /* offset in line array for text */
- short chars; /* number of characters in lay */
- id font; /* font id */
- void *paraStyle; /* implementation dependent fontStyle
- * sheet info. */
- NSRun *run; /* run for lay */
- NSLayFlags lFlags;
- } NSLay;
-
- /*
- * NXLayArray is a NXChunk that holds the layout for the current line
- */
-
- typedef struct _NXLayArray {
- NSTextChunk chunk;
- NSLay lays[1];
- } NSLayArray;
-
- /*
- * NXWidthArray is a NXChunk that holds the widths for the current line
- */
-
- typedef struct _NXWidthArray {
- NSTextChunk chunk;
- float widths[1];
- } NSWidthArray;
-
- /*
- * NXCharArray is a NXChunk that holds the chars for the current line
- */
-
- typedef struct _NXCharArray {
- NSTextChunk chunk;
- wchar text[1];
- } NSCharArray;
-
- /*
- * Word definition Finite State Machine transition struct
- */
- typedef struct _NXFSM {
- const struct _NXFSM *next; /* state to go to, NULL implies final state */
- short delta; /* if final state, this undoes lookahead */
- short token; /* if final state, < 0 word is newline,
- * = is dark, > is white space */
- } NSFSM;
-
- /*
- * Represents one end of a selection
- */
-
- typedef struct _NXSelPt {
- int cp; /* character position */
- int line; /* offset of LineDesc in break table */
- float x; /* x coordinate */
- float y; /* y coordinate */
- int c1st; /* character position of first character
- * on the line */
- float ht; /* line height */
- } NSSelPt;
-
- /*
- * describes tabstop
- */
-
- typedef struct _NXTabStop {
- short kind; /* only NX_LEFTTAB implemented*/
- float x; /* x coordinate for stop */
- } NSTabStop;
-
- typedef struct _NXTextCache {
- int curPos; /* current position in text stream */
- NSRun *curRun; /* cache current block of text and */
- int runFirstPos; /* character pos that corresponds */
- NSTextBlock *curBlock; /* cache current block of text and */
- int blockFirstPos; /* character pos that corresponds */
- } NSTextCache;
-
- typedef struct _NXLayInfo {
- NSRect rect; /* bounds rect for current line. */
- float descent; /* descent for current line, can be reset
- * by scanFunc */
- float width; /* width of line */
- float left; /* left side visible coordinate */
- float right; /* right side visible coordinate */
- float rightIndent; /* how much white space is left at right
- * side of line */
- NSLayArray *lays; /* scanFunc fills with NXLay items */
- NSWidthArray *widths; /* scanFunc fills with character widths */
- NSCharArray *chars; /* scanFunc fills with characters */
- NSTextCache cache; /* cache of current block & run */
- NSRect *textClipRect; /* if non-nil, the current clip for drawing */
- struct _lFlags {
- unsigned int horizCanGrow:1;/* 1 if scanFunc should perform dynamic
- * growing of x margins */
- unsigned int vertCanGrow:1;/* 1 if scanFunc should perform dynamic
- * growing of y margins */
- unsigned int erase:1; /* used to tell drawFunc to erase before
- * drawing line */
- unsigned int ping:1; /* used to tell drawFunc to ping server */
- unsigned int endsParagraph:1;/* true if line ends the paragraph, eg
- * ends in newline */
- unsigned int resetCache:1;/* used in scanFunc to reset local caches */
- unsigned int RESERVED:10;
- } lFlags;
- } NSLayInfo;
-
- /*
- * Gives a paragraph fontStyle
- */
-
- typedef struct _NXTextStyle {
- float indent1st; /* how far first line in paragraph is
- * indented */
- float indent2nd; /* how far second line is indented */
- float lineHt; /* line height */
- float descentLine;/* distance to ascent line from bottom of
- * line */
- short alignment; /* justification */
- short numTabs; /* number of tab stops */
- NSTabStop *tabs; /* array of tab stops */
- } NSTextStyle;
-
-
- /* tab stop fontStyles */
-
- enum {
- NSLefttabKey = 0,
- NSBackspaceKey = 8,
- NSCarriageReturnKey = 13,
- NSDeleteKey = 0x7f,
- NSBacktabKey = 25
- };
-
- /* movement codes for movement between fields */
-
- enum {
- NSIllegalTextMovement = 0,
- NSReturnTextMovement = 0x10,
- NSTabTextMovement = 0x11,
- NSBacktabTextMovement = 0x12,
- NSLeftTextMovement = 0x13,
- NSRightTextMovement = 0x14,
- NSUpTextMovement = 0x15,
- NSDownTextMovement = 0x16
- };
-
- typedef enum {
- NSLeftAlignedParagraph = NSLeftTextAlignment,
- NSRightAlignedParagraph = NSRightTextAlignment,
- NSCenterAlignedParagraph = NSCenterTextAlignment,
- NSJustificationAlignedParagraph = NSJustifiedTextAlignment,
- NSFirstIndentParagraph,
- NSIndentParagraph,
- NSAddTabParagraph,
- NSRemoveTabParagraph,
- NSLeftMarginParagraph,
- NSRightMarginParagraph
- } NSParagraphProperty;
-
-
- /*
- Word tables for various languages. The SmartLeft and SmartRight arrays
- are suitable as arguments for the messages setPreSelSmartTable: and
- setPostSelSmartTable. When doing a paste, if the character to the left
- (right) of the new word is not in the left (right) table, an extra space
- is added on that side. The CharCats tables define the character classes
- used in the word wrap or click tables. The BreakTables are finite state
- machines that determine word wrapping. The ClickTables are finite state
- machines that determine which characters are selected when the user
- double clicks.
- */
-
- extern const unsigned char * const NSEnglishSmartLeftChars;
- extern const unsigned char * const NSEnglishSmartRightChars;
- extern const unsigned char * const NSEnglishCharCatTable;
- extern const NSFSM * const NSEnglishBreakTable;
- extern const int NSEnglishBreakTableSize;
- extern const NSFSM * const NSEnglishNoBreakTable;
- extern const int NSEnglishNoBreakTableSize;
- extern const NSFSM * const NSEnglishClickTable;
- extern const int NSEnglishClickTableSize;
-
- extern const unsigned char * const NSCSmartLeftChars;
- extern const unsigned char * const NSCSmartRightChars;
- extern const unsigned char * const NSCCharCatTable;
- extern const NSFSM * const NSCBreakTable;
- extern const int NSCBreakTableSize;
- extern const NSFSM * const NSCClickTable;
- extern const int NSCClickTableSize;
-
- typedef int (*NSTextFunc) (id self, NSLayInfo *layInfo);
- typedef unsigned short (*NSCharFilterFunc) (
- unsigned short charCode, int flags, unsigned short charSet);
- typedef char *(*NSTextFilterFunc) (
- id self, unsigned char * insertText, int *insertLength, int position);
- #ifdef KANJI
- typedef BOOL (*NXclickFunc) ( id self, int clickPos, NSSelPt * left, NSSelPt * right ) ;
- #endif
-
- @class NSText;
-
- @interface NSCStringText : NSText
- {
- const NSFSM *breakTable;
- const NSFSM *clickTable;
- const unsigned char *preSelSmartTable;
- const unsigned char *postSelSmartTable;
- const unsigned char *charCategoryTable;
- char delegateMethods;
- NSCharFilterFunc charFilterFunc;
- NSTextFilterFunc textFilterFunc;
- char *_compilerErrorSpacer;
- NSTextFunc scanFunc;
- NSTextFunc drawFunc;
- id delegate;
- int tag;
- void *cursorTE;
- NSTextBlock *firstTextBlock;
- NSTextBlock *lastTextBlock;
- NSRunArray *theRuns;
- NSRun typingRun;
- NSBreakArray *theBreaks;
- int growLine;
- int textLength;
- float maxY;
- float maxX;
- NSRect bodyRect;
- float borderWidth;
- char clickCount;
- NSSelPt sp0;
- NSSelPt spN;
- NSSelPt anchorL;
- NSSelPt anchorR;
- NSSize maxSize;
- NSSize minSize;
- struct _tFlags {
- #ifdef __BIG_ENDIAN__
- unsigned int _editMode:2;
- unsigned int _selectMode:2;
- unsigned int _caretState:2;
- unsigned int changeState:1;
- unsigned int charWrap:1;
- unsigned int haveDown:1;
- unsigned int anchorIs0:1;
- unsigned int horizResizable:1;
- unsigned int vertResizable:1;
- unsigned int overstrikeDiacriticals:1;
- unsigned int monoFont:1;
- unsigned int disableFontPanel:1;
- unsigned int inClipView:1;
- #else
- unsigned int inClipView:1;
- unsigned int disableFontPanel:1;
- unsigned int monoFont:1;
- unsigned int overstrikeDiacriticals:1;
- unsigned int vertResizable:1;
- unsigned int horizResizable:1;
- unsigned int anchorIs0:1;
- unsigned int haveDown:1;
- unsigned int charWrap:1;
- unsigned int changeState:1;
- unsigned int _caretState:2;
- unsigned int _selectMode:2;
- unsigned int _editMode:2;
- #endif
- } tFlags;
- void *_info;
- NXStream *textStream;
- NSString *_string;
- }
-
- + excludeFromServicesMenu:(BOOL)flag;
- + getDefaultFont;
- + setDefaultFont:anObject;
-
- - initFrame:(NSRect)frameRect text:(NSString *)theText alignment:(NSTextAlignment)mode;
-
- - renewRuns:(NSRunArray *)newRuns text:(NSString *)newText frame:(NSRect)newFrame tag:(int)newTag;
- - renewFont:newFontId text:(NSString *)newText frame:(NSRect)newFrame tag:(int)newTag;
- - renewFont:(NSString *)newFontName size:(float)newFontSize style:(int)newFontStyle text:(NSString *)newText frame:(NSRect)newFrame tag:(int)newTag;
- - adjustPageHeightNew:(float *)newBottom top:(float)oldTop bottom:(float)oldBottom limit:(float)bottomLimit;
-
- - (NSRect)paragraphRect:(int)prNumber start:(int *)startPos end:(int *)endPos;
- - setCharFilter:(NSCharFilterFunc)aFunc;
- - (NSCharFilterFunc)charFilter;
- - setTextFilter:(NSTextFilterFunc)aFunc;
- - (NSTextFilterFunc)textFilter;
- - (const unsigned char *)preSelSmartTable;
- - setPreSelSmartTable:(const unsigned char *)aTable;
- - (const unsigned char *)postSelSmartTable;
- - setPostSelSmartTable:(const unsigned char *)aTable;
- - (const unsigned char *)charCategoryTable;
- - setCharCategoryTable:(const unsigned char *)aTable;
- - (const NSFSM *)breakTable;
- - setBreakTable:(const NSFSM *)aTable;
- - (const NSFSM *)clickTable;
- - setClickTable:(const NSFSM *)aTable;
- - setTag:(int)anInt;
- - (int)tag;
- - (NSColor *)runColor: (NSRun *)run;
- - (NSColor *)selColor;
-
- - finishReadingRichText;
- - startReadingRichText;
- - setRetainedWhileDrawing:(BOOL)aFlag;
- - (BOOL) isRetainedWhileDrawing;
- - (NSTextBlock *)firstTextBlock;
- - setScanFunc:(NSTextFunc)aFunc;
- - (NSTextFunc)scanFunc;
- - setDrawFunc:(NSTextFunc)aFunc;
- - (NSTextFunc)drawFunc;
- @end
-
- @interface NSCStringText(NSFrameRect)
- - (void)resizeTextWithOldBounds:(NSRect)oldBounds maxRect:(NSRect)maxRect;
- @end
-
- @interface NSCStringText(Layout)
- - (int)calcLine;
- - (void *)paragraphStyleForFont:fontId alignment:(int)alignment;
- - (BOOL)charWrap;
- - (float)descentLine;
- - getMarginLeft:(float *)leftMargin right:(float *)rightMargin top:(float *)topMargin bottom:(float *)bottomMargin;
- - getMinWidth:(float *)width minHeight:(float *)height maxWidth:(float)widthMax maxHeight:(float)heightMax;
- - (void *)defaultParaStyle;
- - (float)lineHeight;
- - setCharWrap:(BOOL)flag;
- - setDescentLine:(float)value;
- - setLineHeight:(float)value;
- - setMarginLeft:(float)leftMargin right:(float)rightMargin top:(float)topMargin bottom:(float)bottomMargin;
- - setNoWrap;
- - setParaStyle:(void *)paraStyle;
- @end
-
- @interface NSCStringText(LinePosition)
- - (int)lineFromPosition:(int)position;
- - (int)positionFromLine:(int)line;
- @end
-
- @interface NSCStringText(Event)
- - clear:sender;
- - moveCaret:(unsigned short)theKey;
- - becomeKeyWindow;
- - selectText:sender;
- @end
-
- @interface NSCStringText(Selection)
- - setSel:(int)start :(int)end;
- - getSel:(NSSelPt *)start :(NSSelPt *)end;
- - hideCaret;
- - (BOOL)isSelectable;
- - replaceSel:(NSString *)aString;
- - replaceSel:(NSString *)aString length:(int)length;
- - replaceSel:(NSString *)aString length:(int)length runs:(NSRunArray *)insertRuns;
- - scrollSelToVisible;
- - selectError;
- - selectNull;
- - setSelColor:(NSColor *) color;
- - showCaret;
- - validRequestorForSendType:(NSString *)sendType andReturnType:(NSString *)returnType;
- - readSelectionFromPasteboard:pboard;
- - (BOOL)writeSelectionToPasteboard:pboard types:(NSArray *)types;
- @end
-
- @interface NSCStringText(NSFont)
- - setFont:fontObj paraStyle:(void *)paraStyle;
- - setSelFontFamily:(NSString *)fontName;
- - setSelFontSize:(float)size;
- - setSelFontStyle:(NSFontTraitMask)traits;
- - setSelFont:fontId;
- - setSelFont:fontId paraStyle:(void *)paraStyle;
- - changeTabStopAt:(float)oldX to:(float)newX;
- - setSelProp:(NSParagraphProperty)prop to:(float)val;
- @end
-
- @interface NSCStringText(Graphics)
- - replaceSelWithCell:cell;
- - (NSPoint)locationOfCell:cell;
- - setLocation:(NSPoint)origin ofCell:cell;
- + registerDirective:(NSString *)directive forClass:class;
- @end
-
- @interface NSCStringText(Find)
- - (BOOL)findText:(NSString *)textPattern ignoreCase:(BOOL) ignoreCase backwards:(BOOL) backwards wrap:(BOOL) wrap;
- @end
-
- @interface NSObject(TextDelegate)
- - textWillResize:textObject;
- - (NSRect)textDidResize:textObject oldBounds:(NSRect)oldBounds;
- - textWillSetSel:textObject toFont:font;
- - textWillConvert:textObject fromFont:from toFont:to;
- - textWillStartReadingRichText:textObject;
- - textWillFinishReadingRichText:textObject;
- - (NSSize)textWillWrite:textObject;
- - textDidRead:textObject paperSize:(NSSize)paperSize;
- @end
-
- @interface NSObject(TextCell)
- /*
- * Any object added to the Text object via replaceSelWithCell: must
- * respond to all of the following messages:
- */
- - highlight:(NSRect)cellFrame withFrame:controlView inView:(BOOL)flag;
- - drawWithFrame:(NSRect)cellFrame inView:controlView;
- - (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:controlView untilMouseUp:(BOOL)untilMouseUp;
- - (NSSize)cellSize;
- - readRichText:(NXStream *)stream forView:view;
- - (NSString *)richTextForView:view;
- @end
-
-
- extern void NSTextFontInfo(
- id fid, float *ascender, float *descender, float *lineHt);
- extern int NSScanALine(id self, NSLayInfo *layInfo);
- extern int NSDrawALine(id self, NSLayInfo *layInfo);
- extern unsigned short NSFieldFilter(
- unsigned short theChar, int flags, unsigned short charSet);
- extern unsigned short NSEditorFilter(
- unsigned short theChar, int flags, unsigned short charSet);
- extern void NSSetTextCache(id self, NSTextCache *cache, int pos);
- extern int NSAdjustTextCache(id self, NSTextCache *cache, int pos);
- extern void NSFlushTextCache(id self, NSTextCache *cache);
- extern NSData *NSDataWithWordTable(const unsigned char *smartLeft,
- const unsigned char *smartRight,
- const unsigned char *charClasses,
- const NSFSM *wrapBreaks, int wrapBreaksCount,
- const NSFSM *clickBreaks, int clickBreaksCount, BOOL charWrap);
- extern void NSReadWordTable(NSZone *zone, NSData *data,
- unsigned char **smartLeft, unsigned char **smartRight,
- unsigned char **charClasses,
- NSFSM **wrapBreaks, int *wrapBreaksCount,
- NSFSM **clickBreaks, int *clickBreaksCount,
- BOOL *charWrap);
- #ifdef KANJI
- extern BOOL NSClick ( id self, int clickPos, NSSelPt * left, NSSelPt * right );
- #endif
-
- typedef struct {
- unsigned char primary[256];
- unsigned char secondary[256];
- unsigned char primaryCI[256];
- unsigned char secondaryCI[256];
- } NXStringOrderTable;
-
- extern int NSOrderStrings(const unsigned char *s1, const unsigned char *s2, BOOL caseSensitive, int length, NXStringOrderTable *table);
- extern NXStringOrderTable *NSDefaultStringOrderTable(void);
-
- @interface NSCStringText(ObsoleteAfterColorConversion)
- - setSelGray:(float)value;
- - (float)runGray: (NSRun *)run;
- @end
-