UNIXworkcode

1 /******************************************************************************* 2 * * 3 * textDisp.h -- Nirvana Editor Text Diplay Header File * 4 * * 5 * Copyright 2003 The NEdit Developers * 6 * * 7 * This is free software; you can redistribute it and/or modify it under the * 8 * terms of the GNU General Public License as published by the Free Software * 9 * Foundation; either version 2 of the License, or (at your option) any later * 10 * version. In addition, you may distribute versions of this program linked to * 11 * Motif or Open Motif. See README for details. * 12 * * 13 * This software is distributed in the hope that it will be useful, but WITHOUT * 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * 16 * more details. * 17 * * 18 * You should have received a copy of the GNU General Public License along with * 19 * software; if not, write to the Free Software Foundation, Inc., 59 Temple * 20 * Place, Suite 330, Boston, MA 02111-1307 USA * 21 * * 22 * Nirvana Text Editor * 23 * July 31, 2001 * 24 * * 25 *******************************************************************************/ 26 27 #ifndef NEDIT_TEXTDISP_H_INCLUDED 28 #define NEDIT_TEXTDISP_H_INCLUDED 29 30 #include "textBuf.h" 31 32 #include <X11/Intrinsic.h> 33 #include <X11/Xlib.h> 34 #include <Xm/Xm.h> 35 36 #include "colorprofile.h" 37 38 #include <X11/Xft/Xft.h> 39 40 enum cursorStyles {NORMAL_CURSOR, CARET_CURSOR, DIM_CURSOR, BLOCK_CURSOR, 41 HEAVY_CURSOR}; 42 43 #define NO_HINT -1 44 45 typedef struct _textDisp textDisp; 46 47 typedef struct NFont NFont; 48 typedef struct NFontList NFontList; 49 typedef struct NCharSetList NCharSetList; 50 struct NFontList { 51 XftFont *font; 52 NFontList *next; 53 }; 54 55 struct NCharSetList { 56 FcCharSet *charset; 57 NCharSetList *next; 58 }; 59 60 struct NFont { 61 NFontList *fonts; 62 NCharSetList *fail; 63 Display *display; 64 FcPattern *pattern; 65 double size; 66 int minWidth; 67 int maxWidth; 68 unsigned int ref; 69 }; 70 71 typedef struct { 72 char *highlightName; 73 char *styleName; 74 char *colorName; 75 char isBold; 76 char isItalic; 77 XftColor color; 78 Boolean underline; 79 NFont *font; 80 char *bgColorName; /* background style coloring (name may be NULL) */ 81 XftColor bgColor; 82 } styleTableEntry; 83 84 typedef struct graphicExposeTranslationEntry { 85 int horizontal; 86 int vertical; 87 struct graphicExposeTranslationEntry *next; 88 } graphicExposeTranslationEntry; 89 90 typedef struct ansiStyle { 91 short fg; 92 short bg; 93 short bold; 94 short italic; 95 short fg_r; 96 short fg_g; 97 short fg_b; 98 short bg_r; 99 short bg_g; 100 short bg_b; 101 } ansiStyle; 102 103 typedef void (*unfinishedStyleCBProc)(const textDisp *textD, int pos, const void *highlightCBArg); 104 105 typedef struct _calltipStruct { 106 int ID; /* ID of displayed calltip. Equals 107 zero if none is displayed. */ 108 Boolean anchored; /* Is it anchored to a position */ 109 int pos; /* Position tip is anchored to */ 110 int hAlign; /* horizontal alignment */ 111 int vAlign; /* vertical alignment */ 112 int alignMode; /* Strict or sloppy alignment */ 113 } calltipStruct; 114 115 typedef struct _textCursor { 116 int cursorPos; 117 int cursorPosCache; 118 int cursorPosCacheLeft; 119 int cursorPosCacheRight; 120 int cursorPreferredCol; 121 int x; /* X, Y pos. of last drawn cursor 122 Note: these are used for *drawing* 123 and are not generally reliable 124 for finding the insert position's 125 x/y coordinates! */ 126 int y; 127 } textCursor; 128 129 struct _textDisp { 130 Widget w; 131 XftDraw *d; 132 int top, left, width, height, lineNumLeft, lineNumWidth; 133 textCursor *cursor; 134 textCursor *newcursor; 135 textCursor *multicursor; 136 size_t mcursorAlloc; 137 size_t mcursorSize; 138 size_t mcursorSizeReal; 139 int cursorOn; 140 int cursorToHint; /* Tells the buffer modified callback 141 where to move the cursor, to reduce 142 the number of redraw calls */ 143 int cursorStyle; /* One of enum cursorStyles above */ 144 Position marginWidth; /* textWidget marginWidth */ 145 //int cursorPreferredCol; /* Column for vert. cursor movement */ 146 int xic_x; /* input method x */ 147 int xic_y; /* input method y */ 148 int nVisibleLines; /* # of visible (displayed) lines */ 149 int nBufferLines; /* # of newlines in the buffer */ 150 textBuffer *buffer; /* Contains text to be displayed */ 151 textBuffer *styleBuffer; /* Optional parallel buffer containing 152 color and font information */ 153 int firstChar, lastChar; /* Buffer positions of first and last 154 displayed character (lastChar points 155 either to a newline or one character 156 beyond the end of the buffer) */ 157 int continuousWrap; /* Wrap long lines when displaying */ 158 int wrapMargin; /* Margin in # of char positions for 159 wrapping in continuousWrap mode */ 160 int *lineStarts; 161 int topLineNum; /* Line number of top displayed line 162 of file (first line of file is 1) */ 163 int absTopLineNum; /* In continuous wrap mode, the line 164 number of the top line if the text 165 were not wrapped (note that this is 166 only maintained as needed). */ 167 int needAbsTopLineNum; /* Externally settable flag to continue 168 maintaining absTopLineNum even if 169 it isn't needed for line # display */ 170 int horizOffset; /* Horizontal scroll pos. in pixels */ 171 int visibility; /* Window visibility (see XVisibility event) */ 172 int nStyles; /* Number of entries in styleTable */ 173 styleTableEntry *styleTable; /* Table of fonts and colors for 174 coloring/syntax-highlighting */ 175 char unfinishedStyle; /* Style buffer entry which triggers 176 on-the-fly reparsing of region */ 177 unfinishedStyleCBProc /* Callback to parse "unfinished" */ 178 unfinishedHighlightCB; /* regions */ 179 void *highlightCBArg; /* Arg to unfinishedHighlightCB */ 180 NFont *font; /* primary font */ 181 NFont *boldFont; 182 NFont *italicFont; 183 NFont *boldItalicFont; 184 int ascent, descent; /* Composite ascent and descent for 185 primary font + all-highlight fonts */ 186 int fixedFontWidth; /* Font width if all current fonts are 187 fixed and match in width, else -1 */ 188 Widget hScrollBar, vScrollBar; 189 GC gc; 190 GC cursorFGGC; /* GC for drawing the cursor */ 191 192 XftColor styleGC; 193 XftColor *bgClassPixel; /* table of colors for each BG class */ 194 195 unsigned char *bgClass; /* obtains index into bgClassPixel[] */ 196 197 Boolean indentRainbow; 198 //XftColor *indentRainbowColors; 199 //int numRainbowColors; 200 201 Boolean ansiColors; 202 //XftColor *ansiColorList; 203 204 ColorProfile *colorProfile; 205 206 Widget calltipW; /* The Label widget for the calltip */ 207 Widget calltipShell; /* The Shell that holds the calltip */ 208 calltipStruct calltip; /* The info for the calltip itself */ 209 Pixel calltipFGPixel; 210 Pixel calltipBGPixel; 211 int suppressResync; /* Suppress resynchronization of line 212 starts during buffer updates */ 213 int nLinesDeleted; /* Number of lines deleted during 214 buffer modification (only used 215 when resynchronization is 216 suppressed) */ 217 int modifyingTabDist; /* Whether tab distance is being 218 modified */ 219 Boolean mcursorOn; /* Is there more than one cursor */ 220 Boolean pointerHidden; /* true if the mouse pointer is 221 hidden */ 222 Boolean disableRedisplay; 223 Boolean highlightCursorLine; 224 Boolean fixLeftClipAfterResize; /* after resize, left clip could be 225 in the middle of a glyph */ 226 Boolean redrawCursorLine; /* If true, redraw the complete in 227 line in some functions, when it 228 contains the cursor */ 229 graphicExposeTranslationEntry *graphicsExposeQueue; 230 231 size_t cacheNoWrappingWidth; /* Min width with no line wrapping */ 232 Boolean cacheNoWrapping; /* Currently no line wrapping */ 233 }; 234 235 textDisp *TextDCreate(Widget widget, Widget hScrollBar, Widget vScrollBar, 236 Position left, Position top, Position width, Position height, 237 Position lineNumLeft, Position lineNumWidth, Position marginWidth, 238 textBuffer *buffer, NFont *font, NFont *bold, NFont *italic, 239 NFont *boldItalic, ColorProfile *colorProfile, int continuousWrap, 240 int wrapMargin, XmString bgClassString, Pixel calltipFGPixel, 241 Pixel calltipBGPixel, Pixel lineHighlightBGPixel, Boolean indentRainbow, 242 Boolean highlightCursorLine, Boolean ansiColors); 243 void TextDInitXft(textDisp *textD); 244 void TextDFree(textDisp *textD); 245 void TextDSetBuffer(textDisp *textD, textBuffer *buffer); 246 void TextDAttachHighlightData(textDisp *textD, textBuffer *styleBuffer, 247 styleTableEntry *styleTable, int nStyles, char unfinishedStyle, 248 unfinishedStyleCBProc unfinishedHighlightCB, void *cbArg); 249 void TextDSetColorProfile(textDisp *textD, ColorProfile *profile); 250 void TextDSetFont(textDisp *textD, NFont *fontStruct); 251 void TextDSetBoldFont(textDisp *textD, NFont *boldFont); 252 void TextDSetItalicFont(textDisp *textD, NFont *boldFont); 253 void TextDSetBoldItalicFont(textDisp *textD, NFont *boldFont); 254 int TextDMinFontWidth(textDisp *textD, Boolean considerStyles); 255 int TextDMaxFontWidth(textDisp *textD, Boolean considerStyles); 256 void TextDResize(textDisp *textD, int width, int height); 257 void TextDRedisplayRect(textDisp *textD, int left, int top, int width, 258 int height); 259 void TextDSetScroll(textDisp *textD, int topLineNum, int horizOffset); 260 void TextDGetScroll(textDisp *textD, int *topLineNum, int *horizOffset); 261 void TextDInsert(textDisp *textD, char *text); 262 void TextDOverstrike(textDisp *textD, char *text); 263 void TextDSetInsertPosition(textDisp *textD, int newPos); 264 void TextDChangeCursors(textDisp *textD, int startPos, int diff); 265 int TextDAddCursor(textDisp *textD, int newMultiCursorPos); 266 void TextDRemoveCursor(textDisp *textD, int cursorIndex); 267 void TextDSetCursors(textDisp *textD, size_t *cursors, size_t ncursors); 268 int TextDClearMultiCursor(textDisp *textD); 269 void TextDCheckCursorDuplicates(textDisp *textD); 270 int TextDGetInsertPosition(textDisp *textD); 271 int TextDXYToPosition(textDisp *textD, int x, int y); 272 int TextDXYToCharPos(textDisp *textD, int x, int y); 273 void TextDXYToUnconstrainedPosition(textDisp *textD, int x, int y, int *row, 274 int *column); 275 int TextDLineAndColToPos(textDisp *textD, int lineNum, int column); 276 int TextDOffsetWrappedColumn(textDisp *textD, int row, int column); 277 int TextDOffsetWrappedRow(textDisp *textD, int row); 278 int TextDPositionToXY(textDisp *textD, int pos, int *x, int *y); 279 int TextDPosToLineAndCol(textDisp *textD, int pos, int *lineNum, int *column); 280 int TextDInSelection(textDisp *textD, int x, int y); 281 void TextDMakeInsertPosVisible(textDisp *textD); 282 int TextDMoveRight(textDisp *textD); 283 int TextDMoveLeft(textDisp *textD); 284 int TextDMoveUp(textDisp *textD, int absolute); 285 int TextDMoveDown(textDisp *textD, int absolute); 286 void TextDBlankCursor(textDisp *textD); 287 void TextDUnblankCursor(textDisp *textD); 288 void TextDSetCursorStyle(textDisp *textD, int style); 289 Boolean TextDPosHasCursor(textDisp *textD, int pos, int *index); 290 Boolean TextDRangeHasCursor(textDisp *textD, int start, int end); 291 void TextDSetWrapMode(textDisp *textD, int wrap, int wrapMargin); 292 int TextDEndOfLine(const textDisp* textD, int pos, 293 Boolean startPosIsLineStart); 294 int TextDStartOfLine(const textDisp* textD, int pos); 295 int TextDCountForwardNLines(const textDisp* textD, int startPos, 296 unsigned nLines, Boolean startPosIsLineStart); 297 int TextDCountBackwardNLines(textDisp *textD, int startPos, int nLines); 298 int TextDCountLines(textDisp *textD, int startPos, int endPos, 299 int startPosIsLineStart); 300 int TextDCountLinesW(textDisp *textD, int startPos, int endPos, 301 int startPosIsLineStart, Boolean *retWrapped); 302 void TextDSetupBGClasses(Widget w, XmString str, XftColor **pp_bgClassPixel, 303 unsigned char **pp_bgClass, XftColor bgPixelDefault); 304 void TextDSetLineNumberArea(textDisp *textD, int lineNumLeft, int lineNumWidth, 305 int textLeft); 306 void TextDMaintainAbsLineNum(textDisp *textD, int state); 307 int TextDPosOfPreferredCol(textDisp *textD, int column, int lineStartPos); 308 int TextDPreferredColumn(textDisp *textD, int *visLineNum, int *lineStartPos); 309 void TextDSetHighlightCursorLine(textDisp *textD, Boolean state); 310 void TextDSetIndentRainbow(textDisp *textD, Boolean indentRainbow); 311 void TextDCursorLR(textDisp *textD, int *left, int *right); 312 textCursor TextDPos2Cursor(textDisp *textD, int pos); 313 void TextDSetAnsiColors(textDisp *textD, Boolean ansiColors); 314 315 NFont *FontCreate(Display *dp, FcPattern *pattern); 316 NFont *FontFromName(Display *dp, const char *name); 317 XftFont *FontListAddFontForChar(NFont *f, FcChar32 c); 318 XftFont *FontDefault(NFont *f); 319 void FontAddFail(NFont *f, FcCharSet *c); 320 XftFont *FindFont(NFont *f, FcChar32 c); 321 void FontDestroy(NFont *f); 322 NFont *FontRef(NFont *font); 323 void FontUnref(NFont *font); 324 325 XftColor PixelToColor(Widget w, Pixel p); 326 XftColor RGBToColor(short r, short g, short b); 327 328 void TextDImposeGraphicsExposeTranslation(textDisp *textD, int *xOffset, int *yOffset); 329 Boolean TextDPopGraphicExposeQueueEntry(textDisp *textD); 330 void TextDTranlateGraphicExposeQueue(textDisp *textD, int xOffset, int yOffset, Boolean appendEntry); 331 332 #endif /* NEDIT_TEXTDISP_H_INCLUDED */ 333