1 From: Tony Balinski <ajbj@free.fr>
2 Subject: Allows styles to specify the underlining of text.
4 This patch adds an "Underline" check box to the Text Drawing Styles dialog.
5 If selected, it causes text of the corresponding style to be underlined.
7 The position of the underline for underlining is determined differently from
8 the underline used for secondary selection, so you can distinguish between
9 the two. The text-style underline is at the bottom of the glyphs' descenders
10 whereas the secondary select underline is just below their baseline.
12 The underline flag is stored as the word "underline" in the nedit.rc saved
13 preferences file. If missing, no underline attribute is registered.
17 source/highlight.c | 1
18 source/highlightData.c | 54 +++++++++++++++++++++++++++++++++++++++++++++----
19 source/highlightData.h | 1
20 source/macro.c | 9 +++++++-
21 source/textDisp.c | 14 ++++++++----
22 5 files changed, 69 insertions(+), 10 deletions(-)
24 diff --quilt old/source/highlight.c new/source/highlight.c
25 --- old/source/highlight.c
26 +++ new/source/highlight.c
27 @@ -770,10 +770,11 @@ static windowHighlightData *createHighli
29 p->highlightName = pat->name; \
30 p->styleName = pat->style; \
31 p->colorName = ColorOfNamedStyle(pat->style); \
32 p->bgColorName = BgColorOfNamedStyle(pat->style); \
33 + p->underline = UnderlineOfNamedStyle(pat->style); \
34 p->isBold = FontOfNamedStyleIsBold(pat->style); \
35 p->isItalic = FontOfNamedStyleIsItalic(pat->style); \
36 /* And now for the more physical stuff */ \
37 p->color = AllocColor(window->textArea, p->colorName, &r, &g, &b); \
39 diff --quilt old/source/highlightData.c new/source/highlightData.c
40 --- old/source/highlightData.c
41 +++ new/source/highlightData.c
42 @@ -87,10 +87,11 @@ static const char *FontTypeNames[N_FONT_
51 static int styleError(const char *stringStart, const char *stoppedAt,
54 @@ -166,14 +167,16 @@ static struct {
59 Widget plainW, boldW, italicW, boldItalicW;
62 highlightStyleRec **highlightStyleList;
64 -} HSDialog = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0};
65 +} HSDialog = {NULL, NULL, NULL, NULL, NULL, NULL,
66 + NULL, NULL, NULL, NULL, NULL, 0};
68 /* Highlight dialog information */
72 @@ -1068,10 +1071,21 @@ int LoadStylesString(char *inString)
73 freeHighlightStyleRec(hs);
74 return styleError(inString, inPtr, "unrecognized font type");
78 + hs->underline = False;
79 + while (SkipOptSeparator(':', &inPtr)) {
80 + char *wordStr = ReadSymbolicField(&inPtr);
81 + if (wordStr == NULL)
83 + if (strcmp(wordStr, "underline") == 0) {
84 + hs->underline = True;
86 + /* else if any other optional flags ... */
89 /* pattern set was read correctly, add/change it in the list */
90 for (i=0; i<NHighlightStyles; i++) {
91 if (!strcmp(HighlightStyles[i]->name, hs->name)) {
92 freeHighlightStyleRec(HighlightStyles[i]);
93 HighlightStyles[i] = hs;
94 @@ -1115,10 +1129,13 @@ char *WriteStylesString(void)
95 BufInsert(outBuf, outBuf->length, "/");
96 BufInsert(outBuf, outBuf->length, style->bgColor);
98 BufInsert(outBuf, outBuf->length, ":");
99 BufInsert(outBuf, outBuf->length, FontTypeNames[style->font]);
100 + if (style->underline) {
101 + BufInsert(outBuf, outBuf->length, ":underline");
103 BufInsert(outBuf, outBuf->length, "\\n\\\n");
106 /* Get the output, and lop off the trailing newlines */
107 outStr = BufGetRange(outBuf, 0, outBuf->length - (i==1?0:4));
108 @@ -1337,10 +1354,22 @@ char *BgColorOfNamedStyle(const char *st
110 return HighlightStyles[styleNo]->bgColor;
114 +** Find whether a named style is underlined.
116 +Boolean UnderlineOfNamedStyle(const char *styleName)
118 + int styleNo=lookupNamedStyle(styleName);
122 + return HighlightStyles[styleNo]->underline;
126 ** Determine whether a named style exists
128 int NamedStyleExists(const char *styleName)
130 return lookupNamedStyle(styleName) != -1;
131 @@ -1866,11 +1895,22 @@ from the list on the left. Select \"New
132 HSDialog.boldItalicW = XtVaCreateManagedWidget("boldItalic",
133 xmToggleButtonWidgetClass, fontBox,
134 XmNlabelString, s1=XmStringCreateSimple("Bold Italic"),
135 XmNmnemonic, 'o', NULL);
139 + HSDialog.underlineW = XtVaCreateManagedWidget("underline",
140 + xmToggleButtonWidgetClass, form,
141 + XmNleftAttachment, XmATTACH_POSITION,
142 + XmNleftPosition, HS_LIST_RIGHT,
143 + XmNtopAttachment, XmATTACH_WIDGET,
144 + XmNtopOffset, HS_H_MARGIN,
145 + XmNtopWidget, fontBox,
146 + XmNlabelString, s1=XmStringCreateSimple("Underlined"),
147 + XmNmnemonic, 'U', NULL);
150 okBtn = XtVaCreateManagedWidget("ok",xmPushButtonWidgetClass,form,
151 XmNlabelString, s1=XmStringCreateSimple("OK"),
152 XmNmarginWidth, BUTTON_WIDTH_MARGIN,
153 XmNleftAttachment, XmATTACH_POSITION,
155 @@ -1907,11 +1947,11 @@ from the list on the left. Select \"New
158 sep1 = XtVaCreateManagedWidget("sep1", xmSeparatorGadgetClass, form,
159 XmNleftAttachment, XmATTACH_FORM,
160 XmNtopAttachment, XmATTACH_WIDGET,
161 - XmNtopWidget, fontBox,
162 + XmNtopWidget, /* fontBox, */ HSDialog.underlineW,
163 XmNtopOffset, HS_H_MARGIN,
164 XmNrightAttachment, XmATTACH_FORM,
165 XmNbottomAttachment, XmATTACH_WIDGET,
166 XmNbottomWidget, closeBtn, 0,
167 XmNbottomOffset, HS_H_MARGIN, NULL);
168 @@ -2024,10 +2064,11 @@ static void hsSetDisplayedCB(void *item,
169 XmTextSetString(HSDialog.bgColorW, "");
170 RadioButtonChangeState(HSDialog.plainW, True, False);
171 RadioButtonChangeState(HSDialog.boldW, False, False);
172 RadioButtonChangeState(HSDialog.italicW, False, False);
173 RadioButtonChangeState(HSDialog.boldItalicW, False, False);
174 + RadioButtonChangeState(HSDialog.underlineW, False, False);
176 if (strcmp(hs->name, "Plain") == 0) {
177 /* you should not be able to delete the reserved style "Plain" */
179 int nList = HSDialog.nHighlightStyles;
180 @@ -2054,10 +2095,11 @@ static void hsSetDisplayedCB(void *item,
181 RadioButtonChangeState(HSDialog.plainW, hs->font==PLAIN_FONT, False);
182 RadioButtonChangeState(HSDialog.boldW, hs->font==BOLD_FONT, False);
183 RadioButtonChangeState(HSDialog.italicW, hs->font==ITALIC_FONT, False);
184 RadioButtonChangeState(HSDialog.boldItalicW, hs->font==BOLD_ITALIC_FONT,
186 + RadioButtonChangeState(HSDialog.underlineW, hs->underline, False);
190 static void hsFreeItemCB(void *item)
192 @@ -2169,10 +2211,12 @@ static highlightStyleRec *readHSDialogFi
193 else if (XmToggleButtonGetState(HSDialog.boldItalicW))
194 hs->font = BOLD_ITALIC_FONT;
196 hs->font = PLAIN_FONT;
198 + /* and finally, do we underline? */
199 + hs->underline = XmToggleButtonGetState(HSDialog.underlineW);
204 ** Copy a highlightStyleRec data structure, and all of the allocated memory
205 @@ -2196,10 +2240,11 @@ static highlightStyleRec *copyHighlightS
207 newHS->bgColor = XtMalloc(strlen(hs->bgColor)+1);
208 strcpy(newHS->bgColor, hs->bgColor);
210 newHS->font = hs->font;
211 + newHS->underline = hs->underline;
216 ** Free all of the allocated data in a highlightStyleRec, including the
217 @@ -2233,11 +2278,12 @@ static void setStyleByName(const char *s
219 static int hsDialogEmpty(void)
221 return TextWidgetIsBlank(HSDialog.nameW) &&
222 TextWidgetIsBlank(HSDialog.colorW) &&
223 - XmToggleButtonGetState(HSDialog.plainW);
224 + XmToggleButtonGetState(HSDialog.plainW) &&
225 + !XmToggleButtonGetState(HSDialog.underlineW);
229 ** Apply the changes made in the highlight styles dialog to the stored
230 ** highlight style information in HighlightStyles
231 diff --quilt old/source/highlightData.h new/source/highlightData.h
232 --- old/source/highlightData.h
233 +++ new/source/highlightData.h
234 @@ -46,10 +46,11 @@ int LMHasHighlightPatterns(const char *l
235 XFontStruct *FontOfNamedStyle(WindowInfo *window, const char *styleName);
236 int FontOfNamedStyleIsBold(char *styleName);
237 int FontOfNamedStyleIsItalic(char *styleName);
238 char *ColorOfNamedStyle(const char *styleName);
239 char *BgColorOfNamedStyle(const char *styleName);
240 +Boolean UnderlineOfNamedStyle(const char *styleName);
241 int IndexOfNamedStyle(const char *styleName);
242 int NamedStyleExists(const char *styleName);
243 void RenameHighlightPattern(const char *oldName, const char *newName);
245 #endif /* NEDIT_HIGHLIGHTDATA_H_INCLUDED */
246 diff --quilt old/source/macro.c new/source/macro.c
247 --- old/source/macro.c
248 +++ new/source/macro.c
249 @@ -5952,11 +5952,12 @@ static int rangesetSetModeMS(WindowInfo
251 ** From the name we obtain:
252 ** ["color"] Foreground color name of style
253 ** ["background"] Background color name of style if specified
254 ** ["bold"] '1' if style is bold, '0' otherwise
255 -** ["italic"] '1' if style is italic, '0' otherwise
256 +** ["italic"] '1' if style is italic, '0' otherwise
257 +** ["underline"] '1' if style is underlined, '0' otherwise
258 ** Given position and pattern code we obtain:
259 ** ["rgb"] RGB representation of foreground color of style
260 ** ["back_rgb"] RGB representation of background color of style
261 ** ["extent"] Forward distance from position over which style applies
262 ** We only supply the style name if the includeName parameter is set:
263 @@ -6046,10 +6047,16 @@ static int fillStyleResult(DataValue *re
264 DV.val.n = FontOfNamedStyleIsItalic(styleName);
265 if (!ArrayInsert(result, PERM_ALLOC_STR("italic"), &DV)) {
266 M_ARRAY_INSERT_FAILURE();
269 + /* Put underlining value in array */
270 + DV.val.n = UnderlineOfNamedStyle(styleName);
271 + if (!ArrayInsert(result, PERM_ALLOC_STR("underline"), &DV)) {
272 + M_ARRAY_INSERT_FAILURE();
275 if (bufferPos >= 0) {
277 const char *styleNameNotUsed = NULL;
278 DV.val.n = StyleLengthOfCodeFromPos(window, bufferPos, &styleNameNotUsed);
279 if (!ArrayInsert(result, PERM_ALLOC_STR("extent"), &DV)) {
280 diff --quilt old/source/textDisp.c new/source/textDisp.c
281 --- old/source/textDisp.c
282 +++ new/source/textDisp.c
283 @@ -2306,20 +2306,24 @@ static void drawString(textDisp *textD,
284 /* Draw the string using gc and font set above */
285 XDrawImageString(XtDisplay(textD->w), XtWindow(textD->w), gc, x,
286 y + textD->ascent, string, nChars);
288 /* Underline if style is secondary selection */
289 - if (style & SECONDARY_MASK || underlineStyle)
290 + if (style & SECONDARY_MASK)
292 - /* restore foreground in GC (was set to background by clearRect()) */
293 - gcValues.foreground = fground;
294 - XChangeGC(XtDisplay(textD->w), gc,
295 - GCForeground, &gcValues);
297 XDrawLine(XtDisplay(textD->w), XtWindow(textD->w), gc, x,
298 y + textD->ascent, toX - 1, y + textD->ascent);
300 + /* Underline if style is underlined */
301 + if (underlineStyle)
303 + int bottom = textD->ascent + textD->descent - 1;
304 + /* draw underline - use textD->gc for the non-highlighted text color */
305 + XDrawLine(XtDisplay(textD->w), XtWindow(textD->w), gc, x,
306 + y + bottom, toX - 1, y + bottom);
311 ** Clear a rectangle with the appropriate background color for "style"