push up calltip_ignore_arg.patch
[nedit-bw.git] / UnderlineStyle.diff
blob8ffa065358020da81005dde6f09034fbdfa2baa8
1 Allows styles to specify the underlining of text.
3 This patch adds an "Underline" check box to the Text Drawing Styles dialog.
4 If selected, it causes text of the corresponding style to be underlined.
6 The position of the underline for underlining is determined differently from
7 the underline used for secondary selection, so you can distinguish between
8 the two. The text-style underline is at the bottom of the glyphs' descenders
9 whereas the secondary select underline is just below their baseline.
11 The underline flag is stored as the word "underline" in the nedit.rc saved
12 preferences file. If missing, no underline attribute is registered.
14 ---
16 source/highlight.c | 1
17 source/highlightData.c | 54 +++++++++++++++++++++++++++++++++++++++++++++----
18 source/highlightData.h | 1
19 source/macro.c | 9 +++++++-
20 source/textDisp.c | 14 ++++++++----
21 5 files changed, 69 insertions(+), 10 deletions(-)
23 diff --quilt old/source/highlight.c new/source/highlight.c
24 --- old/source/highlight.c
25 +++ new/source/highlight.c
26 @@ -770,10 +770,11 @@ static windowHighlightData *createHighli
28 p->highlightName = pat->name; \
29 p->styleName = pat->style; \
30 p->colorName = ColorOfNamedStyle(pat->style); \
31 p->bgColorName = BgColorOfNamedStyle(pat->style); \
32 + p->underline = UnderlineOfNamedStyle(pat->style); \
33 p->isBold = FontOfNamedStyleIsBold(pat->style); \
34 p->isItalic = FontOfNamedStyleIsItalic(pat->style); \
35 /* And now for the more physical stuff */ \
36 p->color = AllocColor(window->textArea, p->colorName, &r, &g, &b); \
37 p->red = r; \
38 diff --quilt old/source/highlightData.c new/source/highlightData.c
39 --- old/source/highlightData.c
40 +++ new/source/highlightData.c
41 @@ -87,10 +87,11 @@ static const char *FontTypeNames[N_FONT_
42 typedef struct {
43 char *name;
44 char *color;
45 char *bgColor;
46 int font;
47 + Boolean underline;
48 } highlightStyleRec;
50 static int styleError(const char *stringStart, const char *stoppedAt,
51 const char *message);
52 #if 0
53 @@ -166,14 +167,16 @@ static struct {
54 Widget shell;
55 Widget nameW;
56 Widget colorW;
57 Widget bgColorW;
58 Widget plainW, boldW, italicW, boldItalicW;
59 + Widget underlineW;
60 Widget managedListW;
61 highlightStyleRec **highlightStyleList;
62 int nHighlightStyles;
63 -} HSDialog = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0};
64 +} HSDialog = {NULL, NULL, NULL, NULL, NULL, NULL,
65 + NULL, NULL, NULL, NULL, NULL, 0};
67 /* Highlight dialog information */
68 static struct {
69 Widget shell;
70 Widget lmOptMenu;
71 @@ -1066,10 +1069,21 @@ int LoadStylesString(char *inString)
72 freeHighlightStyleRec(hs);
73 return styleError(inString, inPtr, "unrecognized font type");
75 XtFree(fontStr);
77 + hs->underline = False;
78 + while (SkipOptSeparator(':', &inPtr)) {
79 + char *wordStr = ReadSymbolicField(&inPtr);
80 + if (wordStr == NULL)
81 + break;
82 + if (strcmp(wordStr, "underline") == 0) {
83 + hs->underline = True;
84 + }
85 + /* else if any other optional flags ... */
86 + XtFree(wordStr);
87 + }
88 /* pattern set was read correctly, add/change it in the list */
89 for (i=0; i<NHighlightStyles; i++) {
90 if (!strcmp(HighlightStyles[i]->name, hs->name)) {
91 freeHighlightStyleRec(HighlightStyles[i]);
92 HighlightStyles[i] = hs;
93 @@ -1113,10 +1127,13 @@ char *WriteStylesString(void)
94 BufInsert(outBuf, outBuf->length, "/");
95 BufInsert(outBuf, outBuf->length, style->bgColor);
97 BufInsert(outBuf, outBuf->length, ":");
98 BufInsert(outBuf, outBuf->length, FontTypeNames[style->font]);
99 + if (style->underline) {
100 + BufInsert(outBuf, outBuf->length, ":underline");
102 BufInsert(outBuf, outBuf->length, "\\n\\\n");
105 /* Get the output, and lop off the trailing newlines */
106 outStr = BufGetRange(outBuf, 0, outBuf->length - (i==1?0:4));
107 @@ -1335,10 +1352,22 @@ char *BgColorOfNamedStyle(const char *st
108 return "";
109 return HighlightStyles[styleNo]->bgColor;
113 +** Find whether a named style is underlined.
115 +Boolean UnderlineOfNamedStyle(const char *styleName)
117 + int styleNo=lookupNamedStyle(styleName);
119 + if (styleNo<0)
120 + return False;
121 + return HighlightStyles[styleNo]->underline;
125 ** Determine whether a named style exists
127 int NamedStyleExists(const char *styleName)
129 return lookupNamedStyle(styleName) != -1;
130 @@ -1864,11 +1893,22 @@ from the list on the left. Select \"New
131 HSDialog.boldItalicW = XtVaCreateManagedWidget("boldItalic",
132 xmToggleButtonWidgetClass, fontBox,
133 XmNlabelString, s1=XmStringCreateSimple("Bold Italic"),
134 XmNmnemonic, 'o', NULL);
135 XmStringFree(s1);
138 + HSDialog.underlineW = XtVaCreateManagedWidget("underline",
139 + xmToggleButtonWidgetClass, form,
140 + XmNleftAttachment, XmATTACH_POSITION,
141 + XmNleftPosition, HS_LIST_RIGHT,
142 + XmNtopAttachment, XmATTACH_WIDGET,
143 + XmNtopOffset, HS_H_MARGIN,
144 + XmNtopWidget, fontBox,
145 + XmNlabelString, s1=XmStringCreateSimple("Underlined"),
146 + XmNmnemonic, 'U', NULL);
147 + XmStringFree(s1);
149 okBtn = XtVaCreateManagedWidget("ok",xmPushButtonWidgetClass,form,
150 XmNlabelString, s1=XmStringCreateSimple("OK"),
151 XmNmarginWidth, BUTTON_WIDTH_MARGIN,
152 XmNleftAttachment, XmATTACH_POSITION,
153 XmNleftPosition, 10,
154 @@ -1905,11 +1945,11 @@ from the list on the left. Select \"New
155 XmStringFree(s1);
157 sep1 = XtVaCreateManagedWidget("sep1", xmSeparatorGadgetClass, form,
158 XmNleftAttachment, XmATTACH_FORM,
159 XmNtopAttachment, XmATTACH_WIDGET,
160 - XmNtopWidget, fontBox,
161 + XmNtopWidget, /* fontBox, */ HSDialog.underlineW,
162 XmNtopOffset, HS_H_MARGIN,
163 XmNrightAttachment, XmATTACH_FORM,
164 XmNbottomAttachment, XmATTACH_WIDGET,
165 XmNbottomWidget, closeBtn, 0,
166 XmNbottomOffset, HS_H_MARGIN, NULL);
167 @@ -2022,10 +2062,11 @@ static void hsSetDisplayedCB(void *item,
168 XmTextSetString(HSDialog.bgColorW, "");
169 RadioButtonChangeState(HSDialog.plainW, True, False);
170 RadioButtonChangeState(HSDialog.boldW, False, False);
171 RadioButtonChangeState(HSDialog.italicW, False, False);
172 RadioButtonChangeState(HSDialog.boldItalicW, False, False);
173 + RadioButtonChangeState(HSDialog.underlineW, False, False);
174 } else {
175 if (strcmp(hs->name, "Plain") == 0) {
176 /* you should not be able to delete the reserved style "Plain" */
177 int i, others = 0;
178 int nList = HSDialog.nHighlightStyles;
179 @@ -2052,10 +2093,11 @@ static void hsSetDisplayedCB(void *item,
180 RadioButtonChangeState(HSDialog.plainW, hs->font==PLAIN_FONT, False);
181 RadioButtonChangeState(HSDialog.boldW, hs->font==BOLD_FONT, False);
182 RadioButtonChangeState(HSDialog.italicW, hs->font==ITALIC_FONT, False);
183 RadioButtonChangeState(HSDialog.boldItalicW, hs->font==BOLD_ITALIC_FONT,
184 False);
185 + RadioButtonChangeState(HSDialog.underlineW, hs->underline, False);
189 static void hsFreeItemCB(void *item)
191 @@ -2167,10 +2209,12 @@ static highlightStyleRec *readHSDialogFi
192 else if (XmToggleButtonGetState(HSDialog.boldItalicW))
193 hs->font = BOLD_ITALIC_FONT;
194 else
195 hs->font = PLAIN_FONT;
197 + /* and finally, do we underline? */
198 + hs->underline = XmToggleButtonGetState(HSDialog.underlineW);
199 return hs;
203 ** Copy a highlightStyleRec data structure, and all of the allocated memory
204 @@ -2194,10 +2238,11 @@ static highlightStyleRec *copyHighlightS
205 else {
206 newHS->bgColor = XtMalloc(strlen(hs->bgColor)+1);
207 strcpy(newHS->bgColor, hs->bgColor);
209 newHS->font = hs->font;
210 + newHS->underline = hs->underline;
211 return newHS;
215 ** Free all of the allocated data in a highlightStyleRec, including the
216 @@ -2231,11 +2276,12 @@ static void setStyleByName(const char *s
218 static int hsDialogEmpty(void)
220 return TextWidgetIsBlank(HSDialog.nameW) &&
221 TextWidgetIsBlank(HSDialog.colorW) &&
222 - XmToggleButtonGetState(HSDialog.plainW);
223 + XmToggleButtonGetState(HSDialog.plainW) &&
224 + !XmToggleButtonGetState(HSDialog.underlineW);
228 ** Apply the changes made in the highlight styles dialog to the stored
229 ** highlight style information in HighlightStyles
230 diff --quilt old/source/highlightData.h new/source/highlightData.h
231 --- old/source/highlightData.h
232 +++ new/source/highlightData.h
233 @@ -46,10 +46,11 @@ int LMHasHighlightPatterns(const char *l
234 XFontStruct *FontOfNamedStyle(WindowInfo *window, const char *styleName);
235 int FontOfNamedStyleIsBold(char *styleName);
236 int FontOfNamedStyleIsItalic(char *styleName);
237 char *ColorOfNamedStyle(const char *styleName);
238 char *BgColorOfNamedStyle(const char *styleName);
239 +Boolean UnderlineOfNamedStyle(const char *styleName);
240 int IndexOfNamedStyle(const char *styleName);
241 int NamedStyleExists(const char *styleName);
242 void RenameHighlightPattern(const char *oldName, const char *newName);
244 #endif /* NEDIT_HIGHLIGHTDATA_H_INCLUDED */
245 diff --quilt old/source/macro.c new/source/macro.c
246 --- old/source/macro.c
247 +++ new/source/macro.c
248 @@ -5950,11 +5950,12 @@ static int rangesetSetModeMS(WindowInfo
249 ** (patCode >= 0).
250 ** From the name we obtain:
251 ** ["color"] Foreground color name of style
252 ** ["background"] Background color name of style if specified
253 ** ["bold"] '1' if style is bold, '0' otherwise
254 -** ["italic"] '1' if style is italic, '0' otherwise
255 +** ["italic"] '1' if style is italic, '0' otherwise
256 +** ["underline"] '1' if style is underlined, '0' otherwise
257 ** Given position and pattern code we obtain:
258 ** ["rgb"] RGB representation of foreground color of style
259 ** ["back_rgb"] RGB representation of background color of style
260 ** ["extent"] Forward distance from position over which style applies
261 ** We only supply the style name if the includeName parameter is set:
262 @@ -6044,10 +6045,16 @@ static int fillStyleResult(DataValue *re
263 DV.val.n = FontOfNamedStyleIsItalic(styleName);
264 if (!ArrayInsert(result, PERM_ALLOC_STR("italic"), &DV)) {
265 M_ARRAY_INSERT_FAILURE();
268 + /* Put underlining value in array */
269 + DV.val.n = UnderlineOfNamedStyle(styleName);
270 + if (!ArrayInsert(result, PERM_ALLOC_STR("underline"), &DV)) {
271 + M_ARRAY_INSERT_FAILURE();
274 if (bufferPos >= 0) {
275 /* insert extent */
276 const char *styleNameNotUsed = NULL;
277 DV.val.n = StyleLengthOfCodeFromPos(window, bufferPos, &styleNameNotUsed);
278 if (!ArrayInsert(result, PERM_ALLOC_STR("extent"), &DV)) {
279 diff --quilt old/source/textDisp.c new/source/textDisp.c
280 --- old/source/textDisp.c
281 +++ new/source/textDisp.c
282 @@ -2313,20 +2313,24 @@ static void drawString(textDisp *textD,
283 /* Draw the string using gc and font set above */
284 XDrawImageString(XtDisplay(textD->w), XtWindow(textD->w), gc, x,
285 y + textD->ascent, string, nChars);
287 /* Underline if style is secondary selection */
288 - if (style & SECONDARY_MASK || underlineStyle)
289 + if (style & SECONDARY_MASK)
291 - /* restore foreground in GC (was set to background by clearRect()) */
292 - gcValues.foreground = fground;
293 - XChangeGC(XtDisplay(textD->w), gc,
294 - GCForeground, &gcValues);
295 /* draw underline */
296 XDrawLine(XtDisplay(textD->w), XtWindow(textD->w), gc, x,
297 y + textD->ascent, toX - 1, y + textD->ascent);
299 + /* Underline if style is underlined */
300 + if (underlineStyle)
302 + int bottom = textD->ascent + textD->descent - 1;
303 + /* draw underline - use textD->gc for the non-highlighted text color */
304 + XDrawLine(XtDisplay(textD->w), XtWindow(textD->w), gc, x,
305 + y + bottom, toX - 1, y + bottom);
310 ** Clear a rectangle with the appropriate background color for "style"