1 |
578 |
markom |
/*
|
2 |
|
|
* tixDiText.c --
|
3 |
|
|
*
|
4 |
|
|
* This file implements one of the "Display Items" in the Tix library :
|
5 |
|
|
* Text display items.
|
6 |
|
|
*
|
7 |
|
|
* Copyright (c) 1996, Expert Interface Technologies
|
8 |
|
|
*
|
9 |
|
|
* See the file "license.terms" for information on usage and redistribution
|
10 |
|
|
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
11 |
|
|
*
|
12 |
|
|
*/
|
13 |
|
|
|
14 |
|
|
#include <tixPort.h>
|
15 |
|
|
#include <tixInt.h>
|
16 |
|
|
#include <tixDef.h>
|
17 |
|
|
|
18 |
|
|
/*----------------------------------------------------------------------
|
19 |
|
|
*
|
20 |
|
|
* Configuration options for Text Items
|
21 |
|
|
*
|
22 |
|
|
*----------------------------------------------------------------------
|
23 |
|
|
*/
|
24 |
|
|
|
25 |
|
|
#define DEF_TEXTITEM_STYLE ""
|
26 |
|
|
#define DEF_TEXTITEM_TEXT ""
|
27 |
|
|
#define DEF_TEXTITEM_UNDERLINE "-1"
|
28 |
|
|
#define DEF_TEXTITEM_TYPE "text"
|
29 |
|
|
|
30 |
|
|
static Tk_ConfigSpec textItemConfigSpecs[] = {
|
31 |
|
|
{TK_CONFIG_CUSTOM, "-itemtype", "itemType", "ItemType",
|
32 |
|
|
DEF_TEXTITEM_TYPE, Tk_Offset(TixTextItem, diTypePtr),
|
33 |
|
|
0, &tixConfigItemType},
|
34 |
|
|
{TK_CONFIG_CUSTOM, "-style", "textStyle", "TextStyle",
|
35 |
|
|
DEF_TEXTITEM_STYLE, Tk_Offset(TixTextItem, stylePtr),
|
36 |
|
|
TK_CONFIG_NULL_OK, &tixConfigItemStyle},
|
37 |
|
|
{TK_CONFIG_STRING, "-text", "text", "Text",
|
38 |
|
|
DEF_TEXTITEM_TEXT, Tk_Offset(TixTextItem, text),
|
39 |
|
|
TK_CONFIG_NULL_OK},
|
40 |
|
|
{TK_CONFIG_INT, "-underline", "underline", "Underline",
|
41 |
|
|
DEF_TEXTITEM_UNDERLINE, Tk_Offset(TixTextItem, underline), 0},
|
42 |
|
|
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
|
43 |
|
|
(char *) NULL, 0, 0}
|
44 |
|
|
};
|
45 |
|
|
|
46 |
|
|
/*----------------------------------------------------------------------
|
47 |
|
|
*
|
48 |
|
|
* Configuration options for Text Styles
|
49 |
|
|
*
|
50 |
|
|
*----------------------------------------------------------------------
|
51 |
|
|
*/
|
52 |
|
|
|
53 |
|
|
#define SELECTED_BG SELECT_BG
|
54 |
|
|
#define DISABLED_BG DISABLED
|
55 |
|
|
|
56 |
|
|
#define DEF_TEXTSTYLE_NORMAL_FG_COLOR BLACK
|
57 |
|
|
#define DEF_TEXTSTYLE_NORMAL_FG_MONO BLACK
|
58 |
|
|
#define DEF_TEXTSTYLE_NORMAL_BG_COLOR NORMAL_BG
|
59 |
|
|
#define DEF_TEXTSTYLE_NORMAL_BG_MONO WHITE
|
60 |
|
|
|
61 |
|
|
#define DEF_TEXTSTYLE_ACTIVE_FG_COLOR BLACK
|
62 |
|
|
#define DEF_TEXTSTYLE_ACTIVE_FG_MONO WHITE
|
63 |
|
|
#define DEF_TEXTSTYLE_ACTIVE_BG_COLOR ACTIVE_BG
|
64 |
|
|
#define DEF_TEXTSTYLE_ACTIVE_BG_MONO BLACK
|
65 |
|
|
|
66 |
|
|
#define DEF_TEXTSTYLE_SELECTED_FG_COLOR BLACK
|
67 |
|
|
#define DEF_TEXTSTYLE_SELECTED_FG_MONO WHITE
|
68 |
|
|
#define DEF_TEXTSTYLE_SELECTED_BG_COLOR SELECTED_BG
|
69 |
|
|
#define DEF_TEXTSTYLE_SELECTED_BG_MONO BLACK
|
70 |
|
|
|
71 |
|
|
#define DEF_TEXTSTYLE_DISABLED_FG_COLOR BLACK
|
72 |
|
|
#define DEF_TEXTSTYLE_DISABLED_FG_MONO BLACK
|
73 |
|
|
#define DEF_TEXTSTYLE_DISABLED_BG_COLOR DISABLED_BG
|
74 |
|
|
#define DEF_TEXTSTYLE_DISABLED_BG_MONO WHITE
|
75 |
|
|
|
76 |
|
|
#define DEF_TEXTSTYLE_PADX "2"
|
77 |
|
|
#define DEF_TEXTSTYLE_PADY "2"
|
78 |
|
|
#define DEF_TEXTSTYLE_FONT CTL_FONT
|
79 |
|
|
#define DEF_TEXTSTYLE_JUSTIFY "left"
|
80 |
|
|
#define DEF_TEXTSTYLE_WLENGTH "0"
|
81 |
|
|
#define DEF_TEXTSTYLE_ANCHOR "w"
|
82 |
|
|
|
83 |
|
|
#if 0
|
84 |
|
|
/* %bordercolor not used */
|
85 |
|
|
#define DEF_TEXTSTYLE_BORDER_COLOR_COLOR BORDER_COLOR
|
86 |
|
|
#define DEF_TEXTSTYLE_BORDER_COLOR_MONO BLACK
|
87 |
|
|
#endif
|
88 |
|
|
|
89 |
|
|
static Tk_ConfigSpec textStyleConfigSpecs[] = {
|
90 |
|
|
{TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor",
|
91 |
|
|
DEF_TEXTSTYLE_ANCHOR, Tk_Offset(TixTextStyle, anchor), 0},
|
92 |
|
|
|
93 |
|
|
{TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL,
|
94 |
|
|
(char *) NULL, 0, 0},
|
95 |
|
|
|
96 |
|
|
#if 0
|
97 |
|
|
/* %bordercolor not used */
|
98 |
|
|
{TK_CONFIG_COLOR,"-bordercolor","borderColor","BorderColor",
|
99 |
|
|
DEF_TEXTSTYLE_BORDER_COLOR_COLOR, Tk_Offset(TixTextStyle, borderColor),
|
100 |
|
|
TK_CONFIG_COLOR_ONLY},
|
101 |
|
|
|
102 |
|
|
{TK_CONFIG_COLOR,"-bordercolor","borderColor","BorderColor",
|
103 |
|
|
DEF_TEXTSTYLE_BORDER_COLOR_MONO, Tk_Offset(TixTextStyle, borderColor),
|
104 |
|
|
TK_CONFIG_MONO_ONLY},
|
105 |
|
|
#endif
|
106 |
|
|
|
107 |
|
|
{TK_CONFIG_SYNONYM, "-fg", "foreground", (char *) NULL,
|
108 |
|
|
(char *) NULL, 0, 0},
|
109 |
|
|
|
110 |
|
|
{TK_CONFIG_FONT, "-font", "font", "Font",
|
111 |
|
|
DEF_TEXTSTYLE_FONT, Tk_Offset(TixTextStyle, font), 0},
|
112 |
|
|
|
113 |
|
|
{TK_CONFIG_JUSTIFY, "-justify", "justify", "Justyfy",
|
114 |
|
|
DEF_TEXTSTYLE_JUSTIFY, Tk_Offset(TixTextStyle, justify),
|
115 |
|
|
TK_CONFIG_NULL_OK},
|
116 |
|
|
|
117 |
|
|
{TK_CONFIG_PIXELS, "-padx", "padX", "Pad",
|
118 |
|
|
DEF_TEXTSTYLE_PADX, Tk_Offset(TixTextStyle, pad[0]), 0},
|
119 |
|
|
|
120 |
|
|
{TK_CONFIG_PIXELS, "-pady", "padY", "Pad",
|
121 |
|
|
DEF_TEXTSTYLE_PADY, Tk_Offset(TixTextStyle, pad[1]), 0},
|
122 |
|
|
|
123 |
|
|
{TK_CONFIG_PIXELS, "-wraplength", "wrapLength", "WrapLength",
|
124 |
|
|
DEF_TEXTSTYLE_WLENGTH, Tk_Offset(TixTextStyle, wrapLength), 0},
|
125 |
|
|
|
126 |
|
|
/* The following is automatically generated */
|
127 |
|
|
{TK_CONFIG_COLOR,"-background","background","Background",
|
128 |
|
|
DEF_TEXTSTYLE_NORMAL_BG_COLOR,
|
129 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_NORMAL].bg),
|
130 |
|
|
TK_CONFIG_COLOR_ONLY},
|
131 |
|
|
{TK_CONFIG_COLOR,"-background","background","Background",
|
132 |
|
|
DEF_TEXTSTYLE_NORMAL_BG_MONO,
|
133 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_NORMAL].bg),
|
134 |
|
|
TK_CONFIG_MONO_ONLY},
|
135 |
|
|
{TK_CONFIG_COLOR,"-foreground","foreground","Foreground",
|
136 |
|
|
DEF_TEXTSTYLE_NORMAL_FG_COLOR,
|
137 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_NORMAL].fg),
|
138 |
|
|
TK_CONFIG_COLOR_ONLY},
|
139 |
|
|
{TK_CONFIG_COLOR,"-foreground","foreground","Foreground",
|
140 |
|
|
DEF_TEXTSTYLE_NORMAL_FG_MONO,
|
141 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_NORMAL].fg),
|
142 |
|
|
TK_CONFIG_MONO_ONLY},
|
143 |
|
|
{TK_CONFIG_COLOR,"-activebackground","activeBackground","ActiveBackground",
|
144 |
|
|
DEF_TEXTSTYLE_ACTIVE_BG_COLOR,
|
145 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_ACTIVE].bg),
|
146 |
|
|
TK_CONFIG_COLOR_ONLY},
|
147 |
|
|
{TK_CONFIG_COLOR,"-activebackground","activeBackground","ActiveBackground",
|
148 |
|
|
DEF_TEXTSTYLE_ACTIVE_BG_MONO,
|
149 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_ACTIVE].bg),
|
150 |
|
|
TK_CONFIG_MONO_ONLY},
|
151 |
|
|
{TK_CONFIG_COLOR,"-activeforeground","activeForeground","ActiveForeground",
|
152 |
|
|
DEF_TEXTSTYLE_ACTIVE_FG_COLOR,
|
153 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_ACTIVE].fg),
|
154 |
|
|
TK_CONFIG_COLOR_ONLY},
|
155 |
|
|
{TK_CONFIG_COLOR,"-activeforeground","activeForeground","ActiveForeground",
|
156 |
|
|
DEF_TEXTSTYLE_ACTIVE_FG_MONO,
|
157 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_ACTIVE].fg),
|
158 |
|
|
TK_CONFIG_MONO_ONLY},
|
159 |
|
|
{TK_CONFIG_COLOR,"-selectbackground","selectBackground","SelectBackground",
|
160 |
|
|
DEF_TEXTSTYLE_SELECTED_BG_COLOR,
|
161 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_SELECTED].bg),
|
162 |
|
|
TK_CONFIG_COLOR_ONLY},
|
163 |
|
|
{TK_CONFIG_COLOR,"-selectbackground","selectBackground","SelectBackground",
|
164 |
|
|
DEF_TEXTSTYLE_SELECTED_BG_MONO,
|
165 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_SELECTED].bg),
|
166 |
|
|
TK_CONFIG_MONO_ONLY},
|
167 |
|
|
{TK_CONFIG_COLOR,"-selectforeground","selectForeground","SelectForeground",
|
168 |
|
|
DEF_TEXTSTYLE_SELECTED_FG_COLOR,
|
169 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_SELECTED].fg),
|
170 |
|
|
TK_CONFIG_COLOR_ONLY},
|
171 |
|
|
{TK_CONFIG_COLOR,"-selectforeground","selectForeground","SelectForeground",
|
172 |
|
|
DEF_TEXTSTYLE_SELECTED_FG_MONO,
|
173 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_SELECTED].fg),
|
174 |
|
|
TK_CONFIG_MONO_ONLY},
|
175 |
|
|
{TK_CONFIG_COLOR,"-disabledbackground","disabledBackground","DisabledBackground",
|
176 |
|
|
DEF_TEXTSTYLE_DISABLED_BG_COLOR,
|
177 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_DISABLED].bg),
|
178 |
|
|
TK_CONFIG_COLOR_ONLY},
|
179 |
|
|
{TK_CONFIG_COLOR,"-disabledbackground","disabledBackground","DisabledBackground",
|
180 |
|
|
DEF_TEXTSTYLE_DISABLED_BG_MONO,
|
181 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_DISABLED].bg),
|
182 |
|
|
TK_CONFIG_MONO_ONLY},
|
183 |
|
|
{TK_CONFIG_COLOR,"-disabledforeground","disabledForeground","DisabledForeground",
|
184 |
|
|
DEF_TEXTSTYLE_DISABLED_FG_COLOR,
|
185 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_DISABLED].fg),
|
186 |
|
|
TK_CONFIG_COLOR_ONLY},
|
187 |
|
|
{TK_CONFIG_COLOR,"-disabledforeground","disabledForeground","DisabledForeground",
|
188 |
|
|
DEF_TEXTSTYLE_DISABLED_FG_MONO,
|
189 |
|
|
Tk_Offset(TixTextStyle,colors[TIX_DITEM_DISABLED].fg),
|
190 |
|
|
TK_CONFIG_MONO_ONLY},
|
191 |
|
|
|
192 |
|
|
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
|
193 |
|
|
(char *) NULL, 0, 0}
|
194 |
|
|
};
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
/*----------------------------------------------------------------------
|
198 |
|
|
* Forward declarations for procedures defined later in this file:
|
199 |
|
|
*----------------------------------------------------------------------
|
200 |
|
|
*/
|
201 |
|
|
static void Tix_TextItemCalculateSize _ANSI_ARGS_((
|
202 |
|
|
Tix_DItem * iPtr));
|
203 |
|
|
static char * Tix_TextItemComponent _ANSI_ARGS_((
|
204 |
|
|
Tix_DItem * iPtr, int x, int y));
|
205 |
|
|
static int Tix_TextItemConfigure _ANSI_ARGS_((
|
206 |
|
|
Tix_DItem * iPtr, int argc, char ** argv,
|
207 |
|
|
int flags));
|
208 |
|
|
static Tix_DItem * Tix_TextItemCreate _ANSI_ARGS_((
|
209 |
|
|
Tix_DispData * ddPtr, Tix_DItemInfo * diTypePtr));
|
210 |
|
|
static void Tix_TextItemDisplay _ANSI_ARGS_((
|
211 |
|
|
Pixmap pixmap, GC gc, Tix_DItem * iPtr,
|
212 |
|
|
int x, int y, int width, int height, int flags));
|
213 |
|
|
static void Tix_TextItemFree _ANSI_ARGS_((
|
214 |
|
|
Tix_DItem * iPtr));
|
215 |
|
|
static void Tix_TextItemLostStyle _ANSI_ARGS_((
|
216 |
|
|
Tix_DItem * iPtr));
|
217 |
|
|
static void Tix_TextItemStyleChanged _ANSI_ARGS_((
|
218 |
|
|
Tix_DItem * iPtr));
|
219 |
|
|
static int Tix_TextStyleConfigure _ANSI_ARGS_((
|
220 |
|
|
Tix_DItemStyle* style, int argc, char ** argv,
|
221 |
|
|
int flags));
|
222 |
|
|
static Tix_DItemStyle * Tix_TextStyleCreate _ANSI_ARGS_((
|
223 |
|
|
Tcl_Interp *interp, Tk_Window tkwin,
|
224 |
|
|
Tix_DItemInfo * diTypePtr, char * name));
|
225 |
|
|
static void Tix_TextStyleFree _ANSI_ARGS_((
|
226 |
|
|
Tix_DItemStyle* style));
|
227 |
|
|
static void Tix_TextStyleSetTemplate _ANSI_ARGS_((
|
228 |
|
|
Tix_DItemStyle* style,
|
229 |
|
|
Tix_StyleTemplate * tmplPtr));
|
230 |
|
|
|
231 |
|
|
Tix_DItemInfo tix_TextItemType = {
|
232 |
|
|
"text", /* type */
|
233 |
|
|
TIX_DITEM_TEXT,
|
234 |
|
|
Tix_TextItemCreate, /* createProc */
|
235 |
|
|
Tix_TextItemConfigure,
|
236 |
|
|
Tix_TextItemCalculateSize,
|
237 |
|
|
Tix_TextItemComponent,
|
238 |
|
|
Tix_TextItemDisplay,
|
239 |
|
|
Tix_TextItemFree,
|
240 |
|
|
Tix_TextItemStyleChanged,
|
241 |
|
|
Tix_TextItemLostStyle,
|
242 |
|
|
|
243 |
|
|
Tix_TextStyleCreate,
|
244 |
|
|
Tix_TextStyleConfigure,
|
245 |
|
|
Tix_TextStyleFree,
|
246 |
|
|
Tix_TextStyleSetTemplate,
|
247 |
|
|
|
248 |
|
|
textItemConfigSpecs,
|
249 |
|
|
textStyleConfigSpecs,
|
250 |
|
|
NULL, /*next */
|
251 |
|
|
};
|
252 |
|
|
|
253 |
|
|
/*----------------------------------------------------------------------
|
254 |
|
|
* Tix_TextItemCreate --
|
255 |
|
|
*
|
256 |
|
|
*
|
257 |
|
|
*----------------------------------------------------------------------
|
258 |
|
|
*/
|
259 |
|
|
static Tix_DItem * Tix_TextItemCreate(ddPtr, diTypePtr)
|
260 |
|
|
Tix_DispData * ddPtr;
|
261 |
|
|
Tix_DItemInfo * diTypePtr;
|
262 |
|
|
{
|
263 |
|
|
TixTextItem * itPtr;
|
264 |
|
|
|
265 |
|
|
itPtr = (TixTextItem*) ckalloc(sizeof(TixTextItem));
|
266 |
|
|
|
267 |
|
|
itPtr->diTypePtr = &tix_TextItemType;
|
268 |
|
|
itPtr->ddPtr = ddPtr;
|
269 |
|
|
#if 1
|
270 |
|
|
itPtr->stylePtr = (TixTextStyle*)TixGetDefaultDItemStyle(
|
271 |
|
|
itPtr->ddPtr, &tix_TextItemType, (Tix_DItem*)itPtr, NULL);
|
272 |
|
|
#else
|
273 |
|
|
itPtr->stylePtr = NULL;
|
274 |
|
|
#endif
|
275 |
|
|
itPtr->clientData = 0;
|
276 |
|
|
itPtr->size[0] = 0;
|
277 |
|
|
itPtr->size[1] = 0;
|
278 |
|
|
|
279 |
|
|
itPtr->numChars = 0;
|
280 |
|
|
itPtr->text = NULL;
|
281 |
|
|
itPtr->textW = 0;
|
282 |
|
|
itPtr->textH = 0;
|
283 |
|
|
itPtr->underline = -1;
|
284 |
|
|
|
285 |
|
|
return (Tix_DItem *)itPtr;
|
286 |
|
|
}
|
287 |
|
|
|
288 |
|
|
static void Tix_TextItemFree(iPtr)
|
289 |
|
|
Tix_DItem * iPtr;
|
290 |
|
|
{
|
291 |
|
|
TixTextItem * itPtr = (TixTextItem *) iPtr;
|
292 |
|
|
|
293 |
|
|
if (itPtr->stylePtr) {
|
294 |
|
|
TixDItemStyleFree(iPtr, (Tix_DItemStyle*)itPtr->stylePtr);
|
295 |
|
|
}
|
296 |
|
|
|
297 |
|
|
Tk_FreeOptions(textItemConfigSpecs, (char *)itPtr,
|
298 |
|
|
itPtr->ddPtr->display, 0);
|
299 |
|
|
ckfree((char*)itPtr);
|
300 |
|
|
}
|
301 |
|
|
|
302 |
|
|
static int Tix_TextItemConfigure(iPtr, argc, argv, flags)
|
303 |
|
|
Tix_DItem * iPtr;
|
304 |
|
|
int argc;
|
305 |
|
|
char ** argv;
|
306 |
|
|
int flags;
|
307 |
|
|
{
|
308 |
|
|
TixTextItem * itPtr = (TixTextItem *) iPtr;
|
309 |
|
|
TixTextStyle * oldStyle = itPtr->stylePtr;
|
310 |
|
|
|
311 |
|
|
if (Tk_ConfigureWidget(itPtr->ddPtr->interp, itPtr->ddPtr->tkwin,
|
312 |
|
|
textItemConfigSpecs,
|
313 |
|
|
argc, argv, (char *)itPtr, flags) != TCL_OK) {
|
314 |
|
|
return TCL_ERROR;
|
315 |
|
|
}
|
316 |
|
|
|
317 |
|
|
if (itPtr->stylePtr == NULL) {
|
318 |
|
|
itPtr->stylePtr = (TixTextStyle*)TixGetDefaultDItemStyle(
|
319 |
|
|
itPtr->ddPtr, &tix_TextItemType, iPtr, NULL);
|
320 |
|
|
}
|
321 |
|
|
|
322 |
|
|
if (oldStyle != NULL && itPtr->stylePtr != oldStyle) {
|
323 |
|
|
Tix_TextItemStyleChanged(iPtr);
|
324 |
|
|
}
|
325 |
|
|
else {
|
326 |
|
|
Tix_TextItemCalculateSize((Tix_DItem*)itPtr);
|
327 |
|
|
}
|
328 |
|
|
|
329 |
|
|
return TCL_OK;
|
330 |
|
|
}
|
331 |
|
|
|
332 |
|
|
static void Tix_TextItemDisplay(pixmap, gc, iPtr, x, y, width, height, flags)
|
333 |
|
|
Pixmap pixmap;
|
334 |
|
|
GC gc;
|
335 |
|
|
Tix_DItem * iPtr;
|
336 |
|
|
int x;
|
337 |
|
|
int y;
|
338 |
|
|
int width;
|
339 |
|
|
int height;
|
340 |
|
|
int flags;
|
341 |
|
|
{
|
342 |
|
|
TixTextItem *itPtr = (TixTextItem *)iPtr;
|
343 |
|
|
GC foreGC, backGC;
|
344 |
|
|
TixpSubRegion subReg;
|
345 |
|
|
|
346 |
|
|
if ((width <= 0) || (height <= 0)) {
|
347 |
|
|
return;
|
348 |
|
|
}
|
349 |
|
|
|
350 |
|
|
TixGetColorDItemGC(iPtr, &backGC, &foreGC, flags);
|
351 |
|
|
|
352 |
|
|
TixpStartSubRegionDraw(itPtr->ddPtr->display, pixmap, foreGC,
|
353 |
|
|
&subReg, 0, 0, x, y, width, height,
|
354 |
|
|
itPtr->size[0], itPtr->size[1]);
|
355 |
|
|
|
356 |
|
|
if (backGC != None) {
|
357 |
|
|
TixpSubRegFillRectangle(itPtr->ddPtr->display, pixmap, backGC,
|
358 |
|
|
&subReg, x, y, width, height);
|
359 |
|
|
}
|
360 |
|
|
|
361 |
|
|
TixDItemGetAnchor(itPtr->stylePtr->anchor, x, y, width, height,
|
362 |
|
|
itPtr->size[0], itPtr->size[1], &x, &y);
|
363 |
|
|
|
364 |
|
|
if (foreGC != None && itPtr->text != NULL) {
|
365 |
|
|
x += itPtr->stylePtr->pad[0];
|
366 |
|
|
y += itPtr->stylePtr->pad[1];
|
367 |
|
|
|
368 |
|
|
TixpSubRegDisplayText(itPtr->ddPtr->display, pixmap, foreGC,
|
369 |
|
|
&subReg, itPtr->stylePtr->font, itPtr->text,
|
370 |
|
|
itPtr->numChars, x, y, itPtr->textW, itPtr->stylePtr->justify,
|
371 |
|
|
itPtr->underline);
|
372 |
|
|
}
|
373 |
|
|
|
374 |
|
|
TixpEndSubRegionDraw(itPtr->ddPtr->display, pixmap, foreGC,
|
375 |
|
|
&subReg);
|
376 |
|
|
}
|
377 |
|
|
|
378 |
|
|
static char * Tix_TextItemComponent(iPtr, x, y)
|
379 |
|
|
Tix_DItem * iPtr;
|
380 |
|
|
int x;
|
381 |
|
|
int y;
|
382 |
|
|
{
|
383 |
|
|
#if 0
|
384 |
|
|
TixTextItem *itPtr = (TixTextItem *)iPtr;
|
385 |
|
|
#endif
|
386 |
|
|
static char * body = "body";
|
387 |
|
|
|
388 |
|
|
return body;
|
389 |
|
|
}
|
390 |
|
|
|
391 |
|
|
|
392 |
|
|
static void Tix_TextItemCalculateSize(iPtr)
|
393 |
|
|
Tix_DItem * iPtr;
|
394 |
|
|
{
|
395 |
|
|
TixTextItem *itPtr = (TixTextItem *)iPtr;
|
396 |
|
|
|
397 |
|
|
|
398 |
|
|
if (itPtr->text) {
|
399 |
|
|
itPtr->numChars = strlen(itPtr->text);
|
400 |
|
|
TixComputeTextGeometry(itPtr->stylePtr->font, itPtr->text,
|
401 |
|
|
itPtr->numChars,
|
402 |
|
|
itPtr->stylePtr->wrapLength, &itPtr->textW, &itPtr->textH);
|
403 |
|
|
|
404 |
|
|
itPtr->size[0] = itPtr->textW;
|
405 |
|
|
itPtr->size[1] = itPtr->textH;
|
406 |
|
|
} else {
|
407 |
|
|
itPtr->size[0] = 0;
|
408 |
|
|
itPtr->size[1] = 0;
|
409 |
|
|
}
|
410 |
|
|
|
411 |
|
|
itPtr->size[0] += 2*itPtr->stylePtr->pad[0];
|
412 |
|
|
itPtr->size[1] += 2*itPtr->stylePtr->pad[1];
|
413 |
|
|
|
414 |
|
|
#if 0
|
415 |
|
|
/* %bordercolor not used */
|
416 |
|
|
if (itPtr->stylePtr->relief == TIX_RELIEF_SOLID) {
|
417 |
|
|
itPtr->size[0] += itPtr->stylePtr->borderWidth;
|
418 |
|
|
itPtr->size[1] += itPtr->stylePtr->borderWidth;
|
419 |
|
|
} else {
|
420 |
|
|
itPtr->size[0] += 2*itPtr->stylePtr->borderWidth;
|
421 |
|
|
itPtr->size[1] += 2*itPtr->stylePtr->borderWidth;
|
422 |
|
|
}
|
423 |
|
|
#endif
|
424 |
|
|
}
|
425 |
|
|
|
426 |
|
|
static void
|
427 |
|
|
Tix_TextItemStyleChanged(iPtr)
|
428 |
|
|
Tix_DItem * iPtr;
|
429 |
|
|
{
|
430 |
|
|
TixTextItem *itPtr = (TixTextItem *)iPtr;
|
431 |
|
|
|
432 |
|
|
if (itPtr->stylePtr == NULL) {
|
433 |
|
|
/* Maybe we haven't set the style to default style yet */
|
434 |
|
|
return;
|
435 |
|
|
}
|
436 |
|
|
Tix_TextItemCalculateSize(iPtr);
|
437 |
|
|
if (itPtr->ddPtr->sizeChangedProc != NULL) {
|
438 |
|
|
itPtr->ddPtr->sizeChangedProc(iPtr);
|
439 |
|
|
}
|
440 |
|
|
}
|
441 |
|
|
|
442 |
|
|
static void
|
443 |
|
|
Tix_TextItemLostStyle(iPtr)
|
444 |
|
|
Tix_DItem * iPtr;
|
445 |
|
|
{
|
446 |
|
|
TixTextItem *itPtr = (TixTextItem *)iPtr;
|
447 |
|
|
|
448 |
|
|
itPtr->stylePtr = (TixTextStyle*)TixGetDefaultDItemStyle(
|
449 |
|
|
itPtr->ddPtr, &tix_TextItemType, iPtr, NULL);
|
450 |
|
|
|
451 |
|
|
Tix_TextItemStyleChanged(iPtr);
|
452 |
|
|
}
|
453 |
|
|
/*----------------------------------------------------------------------
|
454 |
|
|
*
|
455 |
|
|
*
|
456 |
|
|
* Display styles
|
457 |
|
|
*
|
458 |
|
|
*
|
459 |
|
|
*----------------------------------------------------------------------
|
460 |
|
|
*/
|
461 |
|
|
static Tix_DItemStyle *
|
462 |
|
|
Tix_TextStyleCreate(interp, tkwin, diTypePtr, name)
|
463 |
|
|
Tcl_Interp * interp;
|
464 |
|
|
Tk_Window tkwin;
|
465 |
|
|
char * name;
|
466 |
|
|
Tix_DItemInfo * diTypePtr;
|
467 |
|
|
{
|
468 |
|
|
TixTextStyle * stylePtr = (TixTextStyle *)ckalloc(sizeof(TixTextStyle));
|
469 |
|
|
int i;
|
470 |
|
|
|
471 |
|
|
stylePtr->font = NULL;
|
472 |
|
|
stylePtr->justify = TK_JUSTIFY_LEFT;
|
473 |
|
|
stylePtr->wrapLength = 0;
|
474 |
|
|
stylePtr->pad[0] = 0;
|
475 |
|
|
stylePtr->pad[1] = 0;
|
476 |
|
|
stylePtr->anchor = TK_ANCHOR_CENTER;
|
477 |
|
|
|
478 |
|
|
for (i=0; i<4; i++) {
|
479 |
|
|
stylePtr->colors[i].bg = NULL;
|
480 |
|
|
stylePtr->colors[i].fg = NULL;
|
481 |
|
|
stylePtr->colors[i].backGC = None;
|
482 |
|
|
stylePtr->colors[i].foreGC = NULL;
|
483 |
|
|
}
|
484 |
|
|
#if 0
|
485 |
|
|
/* %bordercolor not used */
|
486 |
|
|
stylePtr->borderColor = NULL;
|
487 |
|
|
stylePtr->borderGC = None;
|
488 |
|
|
stylePtr->borderWidth = 0;
|
489 |
|
|
stylePtr->relief = TIX_RELIEF_NONE;
|
490 |
|
|
#endif
|
491 |
|
|
stylePtr->pad[0] = 0;
|
492 |
|
|
stylePtr->pad[1] = 0;
|
493 |
|
|
|
494 |
|
|
return (Tix_DItemStyle *)stylePtr;
|
495 |
|
|
}
|
496 |
|
|
|
497 |
|
|
static int
|
498 |
|
|
Tix_TextStyleConfigure(style, argc, argv, flags)
|
499 |
|
|
Tix_DItemStyle *style;
|
500 |
|
|
int argc;
|
501 |
|
|
char ** argv;
|
502 |
|
|
int flags;
|
503 |
|
|
{
|
504 |
|
|
TixTextStyle * stylePtr = (TixTextStyle *)style;
|
505 |
|
|
XGCValues gcValues;
|
506 |
|
|
GC newGC;
|
507 |
|
|
int i, isNew;
|
508 |
|
|
|
509 |
|
|
if (stylePtr->font == NULL) {
|
510 |
|
|
isNew = 1;
|
511 |
|
|
} else {
|
512 |
|
|
isNew = 0;
|
513 |
|
|
}
|
514 |
|
|
|
515 |
|
|
if (!(flags &TIX_DONT_CALL_CONFIG)) {
|
516 |
|
|
if (Tk_ConfigureWidget(stylePtr->interp, stylePtr->tkwin,
|
517 |
|
|
textStyleConfigSpecs,
|
518 |
|
|
argc, argv, (char *)stylePtr, flags) != TCL_OK) {
|
519 |
|
|
return TCL_ERROR;
|
520 |
|
|
}
|
521 |
|
|
}
|
522 |
|
|
|
523 |
|
|
gcValues.font = TixFontId(stylePtr->font);
|
524 |
|
|
gcValues.graphics_exposures = False;
|
525 |
|
|
|
526 |
|
|
for (i=0; i<4; i++) {
|
527 |
|
|
/* Foreground */
|
528 |
|
|
gcValues.background = stylePtr->colors[i].bg->pixel;
|
529 |
|
|
gcValues.foreground = stylePtr->colors[i].fg->pixel;
|
530 |
|
|
newGC = Tk_GetGC(stylePtr->tkwin,
|
531 |
|
|
GCFont|GCForeground|GCBackground|GCGraphicsExposures, &gcValues);
|
532 |
|
|
|
533 |
|
|
if (stylePtr->colors[i].foreGC != None) {
|
534 |
|
|
Tk_FreeGC(Tk_Display(stylePtr->tkwin),
|
535 |
|
|
stylePtr->colors[i].foreGC);
|
536 |
|
|
}
|
537 |
|
|
stylePtr->colors[i].foreGC = newGC;
|
538 |
|
|
|
539 |
|
|
/* Background */
|
540 |
|
|
gcValues.foreground = stylePtr->colors[i].bg->pixel;
|
541 |
|
|
newGC = Tk_GetGC(stylePtr->tkwin,
|
542 |
|
|
GCFont|GCForeground|GCGraphicsExposures, &gcValues);
|
543 |
|
|
|
544 |
|
|
if (stylePtr->colors[i].backGC != None) {
|
545 |
|
|
Tk_FreeGC(Tk_Display(stylePtr->tkwin),
|
546 |
|
|
stylePtr->colors[i].backGC);
|
547 |
|
|
}
|
548 |
|
|
stylePtr->colors[i].backGC = newGC;
|
549 |
|
|
}
|
550 |
|
|
|
551 |
|
|
#if 0
|
552 |
|
|
/* %bordercolor not used */
|
553 |
|
|
/* Border Color */
|
554 |
|
|
gcValues.foreground = stylePtr->borderColor->pixel;
|
555 |
|
|
newGC = Tk_GetGC(stylePtr->tkwin, GCForeground, &gcValues);
|
556 |
|
|
|
557 |
|
|
if (stylePtr->borderGC != None) {
|
558 |
|
|
Tk_FreeGC(Tk_Display(stylePtr->tkwin), stylePtr->borderGC);
|
559 |
|
|
}
|
560 |
|
|
stylePtr->borderGC = newGC;
|
561 |
|
|
#endif
|
562 |
|
|
|
563 |
|
|
if (!isNew) {
|
564 |
|
|
TixDItemStyleChanged(stylePtr->diTypePtr, (Tix_DItemStyle *)stylePtr);
|
565 |
|
|
}
|
566 |
|
|
|
567 |
|
|
return TCL_OK;
|
568 |
|
|
}
|
569 |
|
|
|
570 |
|
|
static void
|
571 |
|
|
Tix_TextStyleFree(style)
|
572 |
|
|
Tix_DItemStyle *style;
|
573 |
|
|
{
|
574 |
|
|
TixTextStyle * stylePtr = (TixTextStyle *)style;
|
575 |
|
|
int i;
|
576 |
|
|
|
577 |
|
|
for (i=0; i<4; i++) {
|
578 |
|
|
if (stylePtr->colors[i].backGC != None) {
|
579 |
|
|
Tk_FreeGC(Tk_Display(stylePtr->tkwin), stylePtr->colors[i].backGC);
|
580 |
|
|
}
|
581 |
|
|
if (stylePtr->colors[i].foreGC != None) {
|
582 |
|
|
Tk_FreeGC(Tk_Display(stylePtr->tkwin), stylePtr->colors[i].foreGC);
|
583 |
|
|
}
|
584 |
|
|
}
|
585 |
|
|
|
586 |
|
|
Tk_FreeOptions(textStyleConfigSpecs, (char *)stylePtr,
|
587 |
|
|
Tk_Display(stylePtr->tkwin), 0);
|
588 |
|
|
ckfree((char *)stylePtr);
|
589 |
|
|
}
|
590 |
|
|
|
591 |
|
|
static int bg_flags [4] = {
|
592 |
|
|
TIX_DITEM_NORMAL_BG,
|
593 |
|
|
TIX_DITEM_ACTIVE_BG,
|
594 |
|
|
TIX_DITEM_SELECTED_BG,
|
595 |
|
|
TIX_DITEM_DISABLED_BG
|
596 |
|
|
};
|
597 |
|
|
static int fg_flags [4] = {
|
598 |
|
|
TIX_DITEM_NORMAL_FG,
|
599 |
|
|
TIX_DITEM_ACTIVE_FG,
|
600 |
|
|
TIX_DITEM_SELECTED_FG,
|
601 |
|
|
TIX_DITEM_DISABLED_FG
|
602 |
|
|
};
|
603 |
|
|
|
604 |
|
|
|
605 |
|
|
static void
|
606 |
|
|
Tix_TextStyleSetTemplate(style, tmplPtr)
|
607 |
|
|
Tix_DItemStyle* style;
|
608 |
|
|
Tix_StyleTemplate * tmplPtr;
|
609 |
|
|
{
|
610 |
|
|
TixTextStyle * stylePtr = (TixTextStyle *)style;
|
611 |
|
|
int i;
|
612 |
|
|
|
613 |
|
|
if (tmplPtr->flags & TIX_DITEM_FONT) {
|
614 |
|
|
if (stylePtr->font != NULL) {
|
615 |
|
|
TixFreeFont(stylePtr->font);
|
616 |
|
|
}
|
617 |
|
|
stylePtr->font = TixGetFont(
|
618 |
|
|
stylePtr->interp, stylePtr->tkwin,
|
619 |
|
|
TixNameOfFont(tmplPtr->font));
|
620 |
|
|
}
|
621 |
|
|
if (tmplPtr->flags & TIX_DITEM_PADX) {
|
622 |
|
|
stylePtr->pad[0] = tmplPtr->pad[0];
|
623 |
|
|
}
|
624 |
|
|
if (tmplPtr->flags & TIX_DITEM_PADY) {
|
625 |
|
|
stylePtr->pad[1] = tmplPtr->pad[1];
|
626 |
|
|
}
|
627 |
|
|
|
628 |
|
|
for (i=0; i<4; i++) {
|
629 |
|
|
if (tmplPtr->flags & bg_flags[i]) {
|
630 |
|
|
if (stylePtr->colors[i].bg != NULL) {
|
631 |
|
|
Tk_FreeColor(stylePtr->colors[i].bg);
|
632 |
|
|
}
|
633 |
|
|
stylePtr->colors[i].bg = Tk_GetColor(
|
634 |
|
|
stylePtr->interp, stylePtr->tkwin,
|
635 |
|
|
Tk_NameOfColor(tmplPtr->colors[i].bg));
|
636 |
|
|
}
|
637 |
|
|
}
|
638 |
|
|
for (i=0; i<4; i++) {
|
639 |
|
|
if (tmplPtr->flags & fg_flags[i]) {
|
640 |
|
|
if (stylePtr->colors[i].fg != NULL) {
|
641 |
|
|
Tk_FreeColor(stylePtr->colors[i].fg);
|
642 |
|
|
}
|
643 |
|
|
stylePtr->colors[i].fg = Tk_GetColor(
|
644 |
|
|
stylePtr->interp, stylePtr->tkwin,
|
645 |
|
|
Tk_NameOfColor(tmplPtr->colors[i].fg));
|
646 |
|
|
}
|
647 |
|
|
}
|
648 |
|
|
#if 0
|
649 |
|
|
/* %bordercolor not used */
|
650 |
|
|
if (tmplPtr->flags & TIX_DITEM_BORDER_COLOR) {
|
651 |
|
|
if (stylePtr->borderColor != NULL) {
|
652 |
|
|
Tk_FreeColor(stylePtr->borderColor);
|
653 |
|
|
}
|
654 |
|
|
stylePtr->borderColor = Tk_GetColor(
|
655 |
|
|
stylePtr->interp, stylePtr->tkwin,
|
656 |
|
|
Tk_NameOfColor(tmplPtr->borderColor));
|
657 |
|
|
}
|
658 |
|
|
if (tmplPtr->flags & TIX_DITEM_BORDER_WIDTH) {
|
659 |
|
|
stylePtr->borderWidth = tmplPtr->borderWidth;
|
660 |
|
|
}
|
661 |
|
|
if (tmplPtr->flags & TIX_DITEM_RELIEF) {
|
662 |
|
|
stylePtr->relief = tmplPtr->relief;
|
663 |
|
|
}
|
664 |
|
|
#endif
|
665 |
|
|
|
666 |
|
|
Tix_TextStyleConfigure(style, 0, 0, TIX_DONT_CALL_CONFIG);
|
667 |
|
|
}
|