fix nc -do ""
[nedit-bw.git] / UnderlineStyle.diff
blobcb8c644d1ac7bcefc6cc93f33552b576ac18fe37
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.
15 ---
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 @@ -772,6 +772,7 @@ static windowHighlightData *createHighli
28 p->styleName = pat->style; \
29 p->colorName = ColorOfNamedStyle(pat->style); \
30 p->bgColorName = BgColorOfNamedStyle(pat->style); \
31 + p->underline = UnderlineOfNamedStyle(pat->style); \
32 p->isBold = FontOfNamedStyleIsBold(pat->style); \
33 p->isItalic = FontOfNamedStyleIsItalic(pat->style); \
34 /* And now for the more physical stuff */ \
35 diff --quilt old/source/highlightData.c new/source/highlightData.c
36 --- old/source/highlightData.c
37 +++ new/source/highlightData.c
38 @@ -89,6 +89,7 @@ typedef struct {
39 char *color;
40 char *bgColor;
41 int font;
42 + Boolean underline;
43 } highlightStyleRec;
45 static int styleError(const char *stringStart, const char *stoppedAt,
46 @@ -168,10 +169,12 @@ static struct {
47 Widget colorW;
48 Widget bgColorW;
49 Widget plainW, boldW, italicW, boldItalicW;
50 + Widget underlineW;
51 Widget managedListW;
52 highlightStyleRec **highlightStyleList;
53 int nHighlightStyles;
54 -} HSDialog = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0};
55 +} HSDialog = {NULL, NULL, NULL, NULL, NULL, NULL,
56 + NULL, NULL, NULL, NULL, NULL, 0};
58 /* Highlight dialog information */
59 static struct {
60 @@ -1070,6 +1073,17 @@ int LoadStylesString(char *inString)
62 XtFree(fontStr);
64 + hs->underline = False;
65 + while (SkipOptSeparator(':', &inPtr)) {
66 + char *wordStr = ReadSymbolicField(&inPtr);
67 + if (wordStr == NULL)
68 + break;
69 + if (strcmp(wordStr, "underline") == 0) {
70 + hs->underline = True;
71 + }
72 + /* else if any other optional flags ... */
73 + XtFree(wordStr);
74 + }
75 /* pattern set was read correctly, add/change it in the list */
76 for (i=0; i<NHighlightStyles; i++) {
77 if (!strcmp(HighlightStyles[i]->name, hs->name)) {
78 @@ -1117,6 +1131,9 @@ char *WriteStylesString(void)
80 BufInsert(outBuf, outBuf->length, ":");
81 BufInsert(outBuf, outBuf->length, FontTypeNames[style->font]);
82 + if (style->underline) {
83 + BufInsert(outBuf, outBuf->length, ":underline");
84 + }
85 BufInsert(outBuf, outBuf->length, "\\n\\\n");
88 @@ -1339,6 +1356,18 @@ char *BgColorOfNamedStyle(const char *st
92 +** Find whether a named style is underlined.
93 +*/
94 +Boolean UnderlineOfNamedStyle(const char *styleName)
96 + int styleNo=lookupNamedStyle(styleName);
98 + if (styleNo<0)
99 + return False;
100 + return HighlightStyles[styleNo]->underline;
104 ** Determine whether a named style exists
106 int NamedStyleExists(const char *styleName)
107 @@ -1868,7 +1897,18 @@ from the list on the left. Select \"New
108 XmNlabelString, s1=XmStringCreateSimple("Bold Italic"),
109 XmNmnemonic, 'o', NULL);
110 XmStringFree(s1);
113 + HSDialog.underlineW = XtVaCreateManagedWidget("underline",
114 + xmToggleButtonWidgetClass, form,
115 + XmNleftAttachment, XmATTACH_POSITION,
116 + XmNleftPosition, HS_LIST_RIGHT,
117 + XmNtopAttachment, XmATTACH_WIDGET,
118 + XmNtopOffset, HS_H_MARGIN,
119 + XmNtopWidget, fontBox,
120 + XmNlabelString, s1=XmStringCreateSimple("Underlined"),
121 + XmNmnemonic, 'U', NULL);
122 + XmStringFree(s1);
124 okBtn = XtVaCreateManagedWidget("ok",xmPushButtonWidgetClass,form,
125 XmNlabelString, s1=XmStringCreateSimple("OK"),
126 XmNmarginWidth, BUTTON_WIDTH_MARGIN,
127 @@ -1909,7 +1949,7 @@ from the list on the left. Select \"New
128 sep1 = XtVaCreateManagedWidget("sep1", xmSeparatorGadgetClass, form,
129 XmNleftAttachment, XmATTACH_FORM,
130 XmNtopAttachment, XmATTACH_WIDGET,
131 - XmNtopWidget, fontBox,
132 + XmNtopWidget, /* fontBox, */ HSDialog.underlineW,
133 XmNtopOffset, HS_H_MARGIN,
134 XmNrightAttachment, XmATTACH_FORM,
135 XmNbottomAttachment, XmATTACH_WIDGET,
136 @@ -2026,6 +2066,7 @@ static void hsSetDisplayedCB(void *item,
137 RadioButtonChangeState(HSDialog.boldW, False, False);
138 RadioButtonChangeState(HSDialog.italicW, False, False);
139 RadioButtonChangeState(HSDialog.boldItalicW, False, False);
140 + RadioButtonChangeState(HSDialog.underlineW, False, False);
141 } else {
142 if (strcmp(hs->name, "Plain") == 0) {
143 /* you should not be able to delete the reserved style "Plain" */
144 @@ -2056,6 +2097,7 @@ static void hsSetDisplayedCB(void *item,
145 RadioButtonChangeState(HSDialog.italicW, hs->font==ITALIC_FONT, False);
146 RadioButtonChangeState(HSDialog.boldItalicW, hs->font==BOLD_ITALIC_FONT,
147 False);
148 + RadioButtonChangeState(HSDialog.underlineW, hs->underline, False);
152 @@ -2171,6 +2213,8 @@ static highlightStyleRec *readHSDialogFi
153 else
154 hs->font = PLAIN_FONT;
156 + /* and finally, do we underline? */
157 + hs->underline = XmToggleButtonGetState(HSDialog.underlineW);
158 return hs;
161 @@ -2198,6 +2242,7 @@ static highlightStyleRec *copyHighlightS
162 strcpy(newHS->bgColor, hs->bgColor);
164 newHS->font = hs->font;
165 + newHS->underline = hs->underline;
166 return newHS;
169 @@ -2235,7 +2280,8 @@ static int hsDialogEmpty(void)
171 return TextWidgetIsBlank(HSDialog.nameW) &&
172 TextWidgetIsBlank(HSDialog.colorW) &&
173 - XmToggleButtonGetState(HSDialog.plainW);
174 + XmToggleButtonGetState(HSDialog.plainW) &&
175 + !XmToggleButtonGetState(HSDialog.underlineW);
179 diff --quilt old/source/highlightData.h new/source/highlightData.h
180 --- old/source/highlightData.h
181 +++ new/source/highlightData.h
182 @@ -48,6 +48,7 @@ int FontOfNamedStyleIsBold(char *styleNa
183 int FontOfNamedStyleIsItalic(char *styleName);
184 char *ColorOfNamedStyle(const char *styleName);
185 char *BgColorOfNamedStyle(const char *styleName);
186 +Boolean UnderlineOfNamedStyle(const char *styleName);
187 int IndexOfNamedStyle(const char *styleName);
188 int NamedStyleExists(const char *styleName);
189 void RenameHighlightPattern(const char *oldName, const char *newName);
190 diff --quilt old/source/macro.c new/source/macro.c
191 --- old/source/macro.c
192 +++ new/source/macro.c
193 @@ -5658,7 +5658,8 @@ static int rangesetSetModeMS(WindowInfo
194 ** ["color"] Foreground color name of style
195 ** ["background"] Background color name of style if specified
196 ** ["bold"] '1' if style is bold, '0' otherwise
197 -** ["italic"] '1' if style is italic, '0' otherwise
198 +** ["italic"] '1' if style is italic, '0' otherwise
199 +** ["underline"] '1' if style is underlined, '0' otherwise
200 ** Given position and pattern code we obtain:
201 ** ["rgb"] RGB representation of foreground color of style
202 ** ["back_rgb"] RGB representation of background color of style
203 @@ -5752,6 +5753,12 @@ static int fillStyleResult(DataValue *re
204 M_ARRAY_INSERT_FAILURE();
207 + /* Put underlining value in array */
208 + DV.val.n = UnderlineOfNamedStyle(styleName);
209 + if (!ArrayInsert(result, PERM_ALLOC_STR("underline"), &DV)) {
210 + M_ARRAY_INSERT_FAILURE();
213 if (bufferPos >= 0) {
214 /* insert extent */
215 const char *styleNameNotUsed = NULL;
216 diff --quilt old/source/textDisp.c new/source/textDisp.c
217 --- old/source/textDisp.c
218 +++ new/source/textDisp.c
219 @@ -2308,16 +2308,20 @@ static void drawString(textDisp *textD,
220 y + textD->ascent, string, nChars);
222 /* Underline if style is secondary selection */
223 - if (style & SECONDARY_MASK || underlineStyle)
224 + if (style & SECONDARY_MASK)
226 - /* restore foreground in GC (was set to background by clearRect()) */
227 - gcValues.foreground = fground;
228 - XChangeGC(XtDisplay(textD->w), gc,
229 - GCForeground, &gcValues);
230 /* draw underline */
231 XDrawLine(XtDisplay(textD->w), XtWindow(textD->w), gc, x,
232 y + textD->ascent, toX - 1, y + textD->ascent);
234 + /* Underline if style is underlined */
235 + if (underlineStyle)
237 + int bottom = textD->ascent + textD->descent - 1;
238 + /* draw underline - use textD->gc for the non-highlighted text color */
239 + XDrawLine(XtDisplay(textD->w), XtWindow(textD->w), gc, x,
240 + y + bottom, toX - 1, y + bottom);