1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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;
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;
107
108 Boolean anchored;
109 int pos;
110 int hAlign;
111 int vAlign;
112 int alignMode;
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;
122
123
124
125
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;
141
142
143 int cursorStyle;
144 Position marginWidth;
145
146 int xic_x;
147 int xic_y;
148 int nVisibleLines;
149 int nBufferLines;
150 textBuffer *buffer;
151 textBuffer *styleBuffer;
152
153 int firstChar, lastChar;
154
155
156
157 int continuousWrap;
158 int wrapMargin;
159
160 int *lineStarts;
161 int topLineNum;
162
163 int absTopLineNum;
164
165
166
167 int needAbsTopLineNum;
168
169
170 int horizOffset;
171 int visibility;
172 int nStyles;
173 styleTableEntry *styleTable;
174
175 char unfinishedStyle;
176
177 unfinishedStyleCBProc
178 unfinishedHighlightCB;
179 void *highlightCBArg;
180 NFont *font;
181 NFont *boldFont;
182 NFont *italicFont;
183 NFont *boldItalicFont;
184 int ascent, descent;
185
186 int fixedFontWidth;
187
188 Widget hScrollBar, vScrollBar;
189 GC gc;
190 GC cursorFGGC;
191
192 XftColor styleGC;
193 XftColor *bgClassPixel;
194
195 unsigned char *bgClass;
196
197 Boolean indentRainbow;
198
199
200
201 Boolean ansiColors;
202
203
204 ColorProfile *colorProfile;
205
206 Widget calltipW;
207 Widget calltipShell;
208 calltipStruct calltip;
209 Pixel calltipFGPixel;
210 Pixel calltipBGPixel;
211 int suppressResync;
212
213 int nLinesDeleted;
214
215
216
217 int modifyingTabDist;
218
219 Boolean mcursorOn;
220 Boolean pointerHidden;
221
222 Boolean disableRedisplay;
223 Boolean highlightCursorLine;
224 Boolean fixLeftClipAfterResize;
225
226 Boolean redrawCursorLine;
227
228
229 graphicExposeTranslationEntry *graphicsExposeQueue;
230
231 size_t cacheNoWrappingWidth;
232 Boolean cacheNoWrapping;
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
333