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 enum cursorStyles {NORMAL_CURSOR, CARET_CURSOR, DIM_CURSOR, BLOCK_CURSOR, 37 HEAVY_CURSOR}; 38 39 #define NO_HINT -1 40 41 typedef struct { 42 char *highlightName; 43 char *styleName; 44 char *colorName; 45 char isBold; 46 char isItalic; 47 unsigned short red; 48 unsigned short green; 49 unsigned short blue; 50 Pixel color; 51 Boolean underline; 52 XFontStruct *font; 53 char *bgColorName; /* background style coloring (name may be NULL) */ 54 unsigned short bgRed; 55 unsigned short bgGreen; 56 unsigned short bgBlue; 57 Pixel bgColor; 58 } styleTableEntry; 59 60 typedef struct graphicExposeTranslationEntry { 61 int horizontal; 62 int vertical; 63 struct graphicExposeTranslationEntry *next; 64 } graphicExposeTranslationEntry; 65 66 typedef void (*unfinishedStyleCBProc)(); 67 68 typedef struct _calltipStruct { 69 int ID; /* ID of displayed calltip. Equals 70 zero if none is displayed. */ 71 Boolean anchored; /* Is it anchored to a position */ 72 int pos; /* Position tip is anchored to */ 73 int hAlign; /* horizontal alignment */ 74 int vAlign; /* vertical alignment */ 75 int alignMode; /* Strict or sloppy alignment */ 76 } calltipStruct; 77 78 typedef struct _textDisp { 79 Widget w; 80 int top, left, width, height, lineNumLeft, lineNumWidth; 81 int cursorPos; 82 int cursorOn; 83 int cursorX, cursorY; /* X, Y pos. of last drawn cursor 84 Note: these are used for *drawing* 85 and are not generally reliable 86 for finding the insert position's 87 x/y coordinates! */ 88 int cursorToHint; /* Tells the buffer modified callback 89 where to move the cursor, to reduce 90 the number of redraw calls */ 91 int cursorStyle; /* One of enum cursorStyles above */ 92 int cursorPreferredCol; /* Column for vert. cursor movement */ 93 int nVisibleLines; /* # of visible (displayed) lines */ 94 int nBufferLines; /* # of newlines in the buffer */ 95 textBuffer *buffer; /* Contains text to be displayed */ 96 textBuffer *styleBuffer; /* Optional parallel buffer containing 97 color and font information */ 98 int firstChar, lastChar; /* Buffer positions of first and last 99 displayed character (lastChar points 100 either to a newline or one character 101 beyond the end of the buffer) */ 102 int continuousWrap; /* Wrap long lines when displaying */ 103 int wrapMargin; /* Margin in # of char positions for 104 wrapping in continuousWrap mode */ 105 int *lineStarts; 106 int topLineNum; /* Line number of top displayed line 107 of file (first line of file is 1) */ 108 int absTopLineNum; /* In continuous wrap mode, the line 109 number of the top line if the text 110 were not wrapped (note that this is 111 only maintained as needed). */ 112 int needAbsTopLineNum; /* Externally settable flag to continue 113 maintaining absTopLineNum even if 114 it isn't needed for line # display */ 115 int horizOffset; /* Horizontal scroll pos. in pixels */ 116 int visibility; /* Window visibility (see XVisibility event) */ 117 int nStyles; /* Number of entries in styleTable */ 118 styleTableEntry *styleTable; /* Table of fonts and colors for 119 coloring/syntax-highlighting */ 120 char unfinishedStyle; /* Style buffer entry which triggers 121 on-the-fly reparsing of region */ 122 unfinishedStyleCBProc /* Callback to parse "unfinished" */ 123 unfinishedHighlightCB; /* regions */ 124 void *highlightCBArg; /* Arg to unfinishedHighlightCB */ 125 XFontStruct *fontStruct; /* Font structure for primary font */ 126 int ascent, descent; /* Composite ascent and descent for 127 primary font + all-highlight fonts */ 128 int fixedFontWidth; /* Font width if all current fonts are 129 fixed and match in width, else -1 */ 130 Widget hScrollBar, vScrollBar; 131 GC gc, selectGC, highlightGC; /* GCs for drawing text */ 132 GC selectBGGC, highlightBGGC; /* GCs for erasing text */ 133 GC cursorFGGC; /* GC for drawing the cursor */ 134 GC lineNumGC; /* GC for drawing line numbers */ 135 GC styleGC; /* GC with color and font unspecified 136 for drawing colored/styled text */ 137 Pixel fgPixel, bgPixel; /* Foreground/Background colors */ 138 Pixel selectFGPixel, /* Foreground select color */ 139 selectBGPixel; /* Background select color */ 140 Pixel highlightFGPixel, /* Highlight colors are used when */ 141 highlightBGPixel; /* flashing matching parens */ 142 Pixel lineNumFGPixel; /* Color for drawing line numbers */ 143 Pixel cursorFGPixel; 144 Pixel *bgClassPixel; /* table of colors for each BG class */ 145 unsigned char *bgClass; /* obtains index into bgClassPixel[] */ 146 147 Widget calltipW; /* The Label widget for the calltip */ 148 Widget calltipShell; /* The Shell that holds the calltip */ 149 calltipStruct calltip; /* The info for the calltip itself */ 150 Pixel calltipFGPixel; 151 Pixel calltipBGPixel; 152 int suppressResync; /* Suppress resynchronization of line 153 starts during buffer updates */ 154 int nLinesDeleted; /* Number of lines deleted during 155 buffer modification (only used 156 when resynchronization is 157 suppressed) */ 158 int modifyingTabDist; /* Whether tab distance is being 159 modified */ 160 Boolean pointerHidden; /* true if the mouse pointer is 161 hidden */ 162 graphicExposeTranslationEntry *graphicsExposeQueue; 163 } textDisp; 164 165 textDisp *TextDCreate(Widget widget, Widget hScrollBar, Widget vScrollBar, 166 Position left, Position top, Position width, Position height, 167 Position lineNumLeft, Position lineNumWidth, textBuffer *buffer, 168 XFontStruct *fontStruct, Pixel bgPixel, Pixel fgPixel, 169 Pixel selectFGPixel, Pixel selectBGPixel, Pixel highlightFGPixel, 170 Pixel highlightBGPixel, Pixel cursorFGPixel, Pixel lineNumFGPixel, 171 int continuousWrap, int wrapMargin, XmString bgClassString, 172 Pixel calltipFGPixel, Pixel calltipBGPixel); 173 void TextDFree(textDisp *textD); 174 void TextDSetBuffer(textDisp *textD, textBuffer *buffer); 175 void TextDAttachHighlightData(textDisp *textD, textBuffer *styleBuffer, 176 styleTableEntry *styleTable, int nStyles, char unfinishedStyle, 177 unfinishedStyleCBProc unfinishedHighlightCB, void *cbArg); 178 void TextDSetColors(textDisp *textD, Pixel textFgP, Pixel textBgP, 179 Pixel selectFgP, Pixel selectBgP, Pixel hiliteFgP, Pixel hiliteBgP, 180 Pixel lineNoFgP, Pixel cursorFgP); 181 void TextDSetFont(textDisp *textD, XFontStruct *fontStruct); 182 int TextDMinFontWidth(textDisp *textD, Boolean considerStyles); 183 int TextDMaxFontWidth(textDisp *textD, Boolean considerStyles); 184 void TextDResize(textDisp *textD, int width, int height); 185 void TextDRedisplayRect(textDisp *textD, int left, int top, int width, 186 int height); 187 void TextDSetScroll(textDisp *textD, int topLineNum, int horizOffset); 188 void TextDGetScroll(textDisp *textD, int *topLineNum, int *horizOffset); 189 void TextDInsert(textDisp *textD, char *text); 190 void TextDOverstrike(textDisp *textD, char *text); 191 void TextDSetInsertPosition(textDisp *textD, int newPos); 192 int TextDGetInsertPosition(textDisp *textD); 193 int TextDXYToPosition(textDisp *textD, int x, int y); 194 int TextDXYToCharPos(textDisp *textD, int x, int y); 195 void TextDXYToUnconstrainedPosition(textDisp *textD, int x, int y, int *row, 196 int *column); 197 int TextDLineAndColToPos(textDisp *textD, int lineNum, int column); 198 int TextDOffsetWrappedColumn(textDisp *textD, int row, int column); 199 int TextDOffsetWrappedRow(textDisp *textD, int row); 200 int TextDPositionToXY(textDisp *textD, int pos, int *x, int *y); 201 int TextDPosToLineAndCol(textDisp *textD, int pos, int *lineNum, int *column); 202 int TextDInSelection(textDisp *textD, int x, int y); 203 void TextDMakeInsertPosVisible(textDisp *textD); 204 int TextDMoveRight(textDisp *textD); 205 int TextDMoveLeft(textDisp *textD); 206 int TextDMoveUp(textDisp *textD, int absolute); 207 int TextDMoveDown(textDisp *textD, int absolute); 208 void TextDBlankCursor(textDisp *textD); 209 void TextDUnblankCursor(textDisp *textD); 210 void TextDSetCursorStyle(textDisp *textD, int style); 211 void TextDSetWrapMode(textDisp *textD, int wrap, int wrapMargin); 212 int TextDEndOfLine(const textDisp* textD, int pos, 213 Boolean startPosIsLineStart); 214 int TextDStartOfLine(const textDisp* textD, int pos); 215 int TextDCountForwardNLines(const textDisp* textD, int startPos, 216 unsigned nLines, Boolean startPosIsLineStart); 217 int TextDCountBackwardNLines(textDisp *textD, int startPos, int nLines); 218 int TextDCountLines(textDisp *textD, int startPos, int endPos, 219 int startPosIsLineStart); 220 void TextDSetupBGClasses(Widget w, XmString str, Pixel **pp_bgClassPixel, 221 unsigned char **pp_bgClass, Pixel bgPixelDefault); 222 void TextDSetLineNumberArea(textDisp *textD, int lineNumLeft, int lineNumWidth, 223 int textLeft); 224 void TextDMaintainAbsLineNum(textDisp *textD, int state); 225 int TextDPosOfPreferredCol(textDisp *textD, int column, int lineStartPos); 226 int TextDPreferredColumn(textDisp *textD, int *visLineNum, int *lineStartPos); 227 228 #ifdef VMS /* VMS linker doesn't like long names (>31 chars) */ 229 #define TextDImposeGraphicsExposeTranslation TextDGraphicsExposeTranslation 230 #endif /* VMS */ 231 232 void TextDImposeGraphicsExposeTranslation(textDisp *textD, int *xOffset, int *yOffset); 233 Boolean TextDPopGraphicExposeQueueEntry(textDisp *textD); 234 void TextDTranlateGraphicExposeQueue(textDisp *textD, int xOffset, int yOffset, Boolean appendEntry); 235 236 #endif /* NEDIT_TEXTDISP_H_INCLUDED */ 237