Debian Codegraph @

generic/bltTreeViewStyle.c

raw symbols ◀ ▶
Source reconstructed at patch state 1 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1
2 /*
3 * bltTreeViewStyle.c --
4 *
5 * This module implements styles for treeview widget cells.
6 *
7 * Copyright 1998-1999 Lucent Technologies, Inc.
8 *
9 * Permission to use, copy, modify, and distribute this software and
10 * its documentation for any purpose and without fee is hereby
11 * granted, provided that the above copyright notice appear in all
12 * copies and that both that the copyright notice and warranty
13 * disclaimer appear in supporting documentation, and that the names
14 * of Lucent Technologies or any of their entities not be used in
15 * advertising or publicity pertaining to distribution of the software
16 * without specific, written prior permission.
17 *
18 * Lucent Technologies disclaims all warranties with regard to this
19 * software, including all implied warranties of merchantability and
20 * fitness. In no event shall Lucent Technologies be liable for any
21 * special, indirect or consequential damages or any damages
22 * whatsoever resulting from loss of use, data or profits, whether in
23 * an action of contract, negligence or other tortuous action, arising
24 * out of or in connection with the use or performance of this
25 * software.
26 *
27 * The "treeview" widget was created by George A. Howlett.
28 * Extensive cleanups and enhancements by Peter MacDonald.
29 */
30
31 #include "bltInt.h"
32
33 #ifndef NO_TREEVIEW
34
35 #include "bltTreeView.h"
36 #include "bltList.h"
37 #include <X11/Xutil.h>
38 #include <X11/Xatom.h>
39
40 #define STYLE_GAP 2
41
42 static Blt_OptionParseProc ObjToSticky;
43 static Blt_OptionPrintProc StickyToObj;
44
45 static Blt_OptionParseProc ObjToIcon;
46 static Blt_OptionPrintProc IconToObj;
47 static Blt_OptionFreeProc FreeIcon;
48 Blt_CustomOption bltTreeViewIconOption =
49 {
50 /* Contains a pointer to the widget that's currently being
51 * configured. This is used in the custom configuration parse
52 * routine for icons. */
53 ObjToIcon, IconToObj, FreeIcon, NULL,
54 };
55 extern Blt_CustomOption bltTreeViewIconsOption;
56
57
58 #define DEF_STYLE_HIGHLIGHT_BACKGROUND STD_NORMAL_BACKGROUND
59 #define DEF_STYLE_HIGHLIGHT_FOREGROUND STD_NORMAL_FOREGROUND
60 #ifdef WIN32
61 #define DEF_STYLE_ACTIVE_BACKGROUND RGB_GREY85
62 #else
63 #define DEF_STYLE_ACTIVE_BACKGROUND RGB_GREY95
64 #endif
65 #define DEF_STYLE_ACTIVE_FOREGROUND STD_ACTIVE_FOREGROUND
66 #define DEF_STYLE_GAP "2"
67
68 typedef struct {
69 TREEVIEW_STYLE_COMMON
70
71 /* TextBox-specific fields */
72 Tcl_Obj *formatCmd;
73
74 int iconside; /* Position of the text in relation to
75 * the icon. */
76 int side; /* Side to anchor cell. */
77
78 } TreeViewTextBox;
79
80 #ifdef WIN32
81 #define DEF_TEXTBOX_CURSOR "arrow"
82 #else
83 #define DEF_TEXTBOX_CURSOR "hand2"
84 #endif /*WIN32*/
85 #define DEF_TEXTBOX_SIDE "left"
86
87 #define CONF_STYLES \
88 {BLT_CONFIG_BORDER, "-activebackground", "activeBackground", \
89 "ActiveBackground", DEF_STYLE_ACTIVE_BACKGROUND, \
90 Blt_Offset(TreeViewStyle, activeBorder), BLT_CONFIG_NULL_OK}, \
91 {BLT_CONFIG_SYNONYM, "-activebg", (char *)NULL, \
92 (char *)NULL, (char *)NULL, 0, 0, (ClientData)"-activebackground"}, \
93 {BLT_CONFIG_SYNONYM, "-activefg", (char *)NULL, \
94 (char *)NULL, (char *)NULL, 0, 0, (ClientData)"-activeforeground"}, \
95 {BLT_CONFIG_COLOR, "-activeforeground", "activeForeground", \
96 "ActiveForeground", DEF_STYLE_ACTIVE_FOREGROUND, \
97 Blt_Offset(TreeViewStyle, activeFgColor), 0}, \
98 {BLT_CONFIG_BORDER, "-background", (char *)NULL, (char *)NULL, \
99 (char *)NULL, Blt_Offset(TreeViewStyle, border), \
100 BLT_CONFIG_NULL_OK|BLT_CONFIG_DONT_SET_DEFAULT}, \
101 {BLT_CONFIG_SYNONYM, "-bg", (char *)NULL, (char *)NULL, (char *)NULL, \
102 0, 0, (ClientData)"-background"}, \
103 {BLT_CONFIG_CURSOR, "-cursor", "cursor", "Cursor", \
104 DEF_TEXTBOX_CURSOR, Blt_Offset(TreeViewStyle, cursor), 0}, \
105 {BLT_CONFIG_BOOLEAN, "-readonly", "readOnly", "ReadOnly", \
106 "False", Blt_Offset(TreeViewStyle, noteditable), \
107 BLT_CONFIG_DONT_SET_DEFAULT},\
108 {BLT_CONFIG_STRING, "-editopts", "editOpts", "EditOpts", \
109 (char *)NULL, Blt_Offset(TreeViewStyle, editOpts), \
110 BLT_CONFIG_NULL_OK}, \
111 {BLT_CONFIG_SYNONYM, "-fg", (char *)NULL, (char *)NULL, (char *)NULL, \
112 0, 0, (ClientData)"-foreground"}, \
113 {BLT_CONFIG_FONT, "-font", (char *)NULL, (char *)NULL, \
114 (char *)NULL, Blt_Offset(TreeViewStyle, font), \
115 BLT_CONFIG_NULL_OK|BLT_CONFIG_DONT_SET_DEFAULT}, \
116 {BLT_CONFIG_COLOR, "-foreground", (char *)NULL, (char *)NULL, \
117 (char *)NULL, Blt_Offset(TreeViewStyle, fgColor), \
118 BLT_CONFIG_NULL_OK|BLT_CONFIG_DONT_SET_DEFAULT }, \
119 {BLT_CONFIG_DISTANCE, "-gap", "gap", "Gap", \
120 DEF_STYLE_GAP, Blt_Offset(TreeViewStyle, gap), \
121 BLT_CONFIG_DONT_SET_DEFAULT}, \
122 {BLT_CONFIG_BOOLEAN, "-hide", (char *)NULL, (char *)NULL, \
123 "False", Blt_Offset(TreeViewStyle, hidden), 0}, \
124 {BLT_CONFIG_BORDER, "-highlightbackground", "highlightBackground", \
125 "HighlightBackground", DEF_STYLE_HIGHLIGHT_BACKGROUND, \
126 Blt_Offset(TreeViewStyle, highlightBorder), \
127 BLT_CONFIG_COLOR_ONLY|BLT_CONFIG_NULL_OK}, \
128 {BLT_CONFIG_COLOR, "-highlightforeground", "highlightForeground", \
129 "HighlightForeground", DEF_STYLE_HIGHLIGHT_FOREGROUND, \
130 Blt_Offset(TreeViewStyle, highlightFgColor), BLT_CONFIG_NULL_OK}, \
131 {BLT_CONFIG_SYNONYM, "-highlightbg",(char *)NULL, \
132 (char *)NULL, (char *)NULL, 0, 0, (ClientData)"-highlightbackground"}, \
133 {BLT_CONFIG_SYNONYM, "-highlightfg", (char *)NULL, \
134 (char *)NULL, (char *)NULL, 0, 0, (ClientData)"-highlightforeground"}, \
135 {BLT_CONFIG_CUSTOM, "-icon", (char *)NULL, (char *)NULL, \
136 (char *)NULL, Blt_Offset(TreeViewStyle, icon), \
137 BLT_CONFIG_NULL_OK, &bltTreeViewIconOption}, \
138 {BLT_CONFIG_INT, "-priority", (char *)NULL, (char *)NULL, \
139 "0", Blt_Offset(TreeViewStyle, priority), 0}, \
140 {BLT_CONFIG_SHADOW, "-shadow", "Shadow", "Shadow", \
141 (char *)NULL, Blt_Offset(TreeViewStyle, shadow), 0}, \
142 {BLT_CONFIG_TILE, "-tile", (char *)NULL, (char *)NULL, \
143 (char *)NULL, Tk_Offset(TreeViewStyle, tile), BLT_CONFIG_NULL_OK, },
144
145 static Blt_ConfigSpec textBoxSpecs[] =
146 {
147 CONF_STYLES
148 {BLT_CONFIG_OBJCMD, "-formatcmd", "formatCmd", "FormatCmd",
149 NULL, Blt_Offset(TreeViewTextBox, formatCmd),
150 BLT_CONFIG_NULL_OK},
151 {BLT_CONFIG_SIDE, "-side", (char *)NULL, (char *)NULL,
152 DEF_TEXTBOX_SIDE, Tk_Offset(TreeViewTextBox, side),
153 BLT_CONFIG_DONT_SET_DEFAULT},
154 {BLT_CONFIG_SIDE, "-iconside", (char *)NULL, (char *)NULL,
155 DEF_TEXTBOX_SIDE, Tk_Offset(TreeViewTextBox, iconside),
156 BLT_CONFIG_DONT_SET_DEFAULT},
157 {BLT_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL,
158 (char *)NULL, 0, 0}
159 };
160
161 typedef struct {
162 TREEVIEW_STYLE_COMMON
163
164 /* Checkbox specific fields. */
165 int size; /* Size of the checkbox. */
166 int showValue; /* If non-zero, display the on/off value. */
167 char *onValue;
168 char *offValue;
169 int lineWidth; /* Linewidth of the surrounding box. */
170 GC bgGC;
171 Tk_3DBorder checkBg; /* Normal background color of cell. */ \
172
173 XColor *boxColor; /* Rectangle (box) color (grey). */
174 XColor *fillColor; /* Fill color (white) */
175 XColor *checkColor; /* Check color (red). */
176
177 GC boxGC;
178 GC fillGC; /* Box fill GC */
179 GC checkGC;
180
181 TextLayout *onPtr, *offPtr;
182 TreeViewIcon *icons; /* Tk images */
183 int boxX, boxW, boxH;
184 int halo;
185
186 } TreeViewCheckBox;
187
188 #define DEF_CHECKBOX_BOX_COLOR "black"
189 #define DEF_CHECKBOX_CHECK_COLOR "darkblue"
190 #define DEF_CHECKBOX_FILL_COLOR "white"
191 #define DEF_CHECKBOX_OFFVALUE "0"
192 #define DEF_CHECKBOX_ONVALUE "1"
193 #define DEF_CHECKBOX_SHOWVALUE "yes"
194 #define DEF_CHECKBOX_HALO "0"
195 #define DEF_CHECKBOX_SIZE "11"
196 #define DEF_CHECKBOX_LINEWIDTH "1"
197 #define DEF_CHECKBOX_GAP "4"
198 #ifdef WIN32
199 #define DEF_CHECKBOX_CURSOR "arrow"
200 #else
201 #define DEF_CHECKBOX_CURSOR "hand2"
202 #endif /*WIN32*/
203
204 static Blt_ConfigSpec checkBoxSpecs[] =
205 {
206 CONF_STYLES
207 {BLT_CONFIG_COLOR, "-boxcolor", "boxColor", "BoxColor",
208 DEF_CHECKBOX_BOX_COLOR, Blt_Offset(TreeViewCheckBox, boxColor), 0},
209 {BLT_CONFIG_DISTANCE, "-boxsize", "boxSize", "BoxSize",
210 DEF_CHECKBOX_SIZE, Blt_Offset(TreeViewCheckBox, size),
211 BLT_CONFIG_DONT_SET_DEFAULT},
212 {BLT_CONFIG_BORDER, "-checkbg", "checkBg", "checkBg",
213 (char *)NULL, Blt_Offset(TreeViewCheckBox, checkBg), BLT_CONFIG_NULL_OK},
214 {BLT_CONFIG_COLOR, "-checkcolor", "checkColor", "CheckColor",
215 DEF_CHECKBOX_CHECK_COLOR, Blt_Offset(TreeViewCheckBox, checkColor), 0},
216 {BLT_CONFIG_CUSTOM, "-checkicons", "checkIcons", "CheckIcons",
217 (char *)NULL, Blt_Offset(TreeViewCheckBox, icons),
218 BLT_CONFIG_NULL_OK, &bltTreeViewIconsOption},
219 {BLT_CONFIG_COLOR, "-fillcolor", "fillColor", "FillColor",
220 DEF_CHECKBOX_FILL_COLOR, Blt_Offset(TreeViewCheckBox, fillColor), 0},
221 {BLT_CONFIG_TILE, "-filltile", "fillTile", "FillTile",
222 (char *)NULL, Blt_Offset(TreeViewCheckBox, fillTile), BLT_CONFIG_NULL_OK, },
223 {BLT_CONFIG_INT, "-halo", "halo", "Halo",
224 DEF_CHECKBOX_HALO, Blt_Offset(TreeViewCheckBox, halo),
225 0},
226 {BLT_CONFIG_DISTANCE, "-linewidth", "lineWidth", "LineWidth",
227 DEF_CHECKBOX_LINEWIDTH,
228 Blt_Offset(TreeViewCheckBox, lineWidth),
229 BLT_CONFIG_DONT_SET_DEFAULT},
230 {BLT_CONFIG_STRING, "-offvalue", "offValue", "OffValue",
231 DEF_CHECKBOX_OFFVALUE, Blt_Offset(TreeViewCheckBox, offValue),
232 BLT_CONFIG_NULL_OK},
233 {BLT_CONFIG_STRING, "-onvalue", "onValue", "OnValue",
234 DEF_CHECKBOX_ONVALUE, Blt_Offset(TreeViewCheckBox, onValue),
235 BLT_CONFIG_NULL_OK},
236 {BLT_CONFIG_BOOLEAN, "-showvalue", "showValue", "ShowValue",
237 DEF_CHECKBOX_SHOWVALUE, Blt_Offset(TreeViewCheckBox, showValue),
238 BLT_CONFIG_DONT_SET_DEFAULT},
239 {BLT_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL,
240 (char *)NULL, 0, 0}
241 };
242
243 typedef struct {
244 TREEVIEW_STYLE_COMMON
245
246 /* ComboBox-specific fields */
247
248 int borderWidth; /* Width of outer border surrounding
249 * the entire box. */
250 char *choiceCmd; /* Command to get list of available choices. */
251 char *choices; /* List of available choices. */
252 char *choiceKey; /* Key to get list of available choices. */
253 int scrollWidth;
254 int button;
255 int buttonWidth;
256 int buttonBorderWidth; /* Border width of button. */
257 int buttonRelief; /* Normal relief of button. */
258 TreeViewIcon *buttonIcons;
259
260 } TreeViewComboBox;
261
262 #define DEF_COMBOBOX_BORDERWIDTH "1"
263 #define DEF_COMBOBOX_BUTTON_BORDERWIDTH "1"
264 #define DEF_COMBOBOX_BUTTON_RELIEF "raised"
265 #define DEF_COMBOBOX_RELIEF "flat"
266 #ifdef WIN32
267 #define DEF_COMBOBOX_CURSOR "arrow"
268 #else
269 #define DEF_COMBOBOX_CURSOR "hand2"
270 #endif /*WIN32*/
271
272
273 static Blt_ConfigSpec comboBoxSpecs[] =
274 {
275 CONF_STYLES
276 {BLT_CONFIG_SYNONYM, "-bd", (char *)NULL, (char *)NULL, (char *)NULL, 0,
277 0, (ClientData)"-borderwidth"},
278 {BLT_CONFIG_DISTANCE, "-borderwidth", (char *)NULL, (char *)NULL,
279 DEF_COMBOBOX_BORDERWIDTH, Blt_Offset(TreeViewComboBox, borderWidth),
280 BLT_CONFIG_DONT_SET_DEFAULT},
281 {BLT_CONFIG_DISTANCE, "-buttonborderwidth", "buttonBorderWidth",
282 "ButtonBorderWidth", DEF_COMBOBOX_BUTTON_BORDERWIDTH,
283 Blt_Offset(TreeViewComboBox, buttonBorderWidth),
284 BLT_CONFIG_DONT_SET_DEFAULT},
285 {BLT_CONFIG_CUSTOM, "-buttonicons", "buttonIcons", "ButtonIcons",
286 (char *)NULL, Blt_Offset(TreeViewComboBox, buttonIcons),
287 BLT_CONFIG_NULL_OK, &bltTreeViewIconsOption},
288 {BLT_CONFIG_RELIEF, "-buttonrelief", "buttonRelief", "ButtonRelief",
289 DEF_COMBOBOX_BUTTON_RELIEF, Blt_Offset(TreeViewComboBox, buttonRelief),
290 BLT_CONFIG_DONT_SET_DEFAULT},
291 {BLT_CONFIG_STRING, "-choicecmd", "choiceCmd", "ChoiceCmd",
292 (char *)NULL, Blt_Offset(TreeViewComboBox, choiceCmd),
293 BLT_CONFIG_NULL_OK, 0},
294 {BLT_CONFIG_STRING, "-choicekey", "choiceKey", "ChoiceKey",
295 (char *)NULL, Blt_Offset(TreeViewComboBox, choiceKey),
296 BLT_CONFIG_NULL_OK, 0},
297 {BLT_CONFIG_STRING, "-choices", "choices", "Choices",
298 (char *)NULL, Blt_Offset(TreeViewComboBox, choices),
299 BLT_CONFIG_NULL_OK, 0},
300 {BLT_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL,
301 (char *)NULL, 0, 0}
302 };
303
304 typedef struct {
305 TREEVIEW_STYLE_COMMON
306
307 int windowHeight;
308 int windowWidth;
309 char *windowCmd;
310 int sticky;
311
312 } TreeViewWindowBox;
313
314 #define STICK_NORTH (1<<0)
315 #define STICK_EAST (1<<1)
316 #define STICK_SOUTH (1<<2)
317 #define STICK_WEST (1<<3)
318
319 static Blt_CustomOption bltStickyOption = {
320 ObjToSticky, StickyToObj, NULL, NULL,
321 };
322
323 #define DEF_COMBOBOX_BORDERWIDTH "1"
324 #define DEF_COMBOBOX_BUTTON_BORDERWIDTH "1"
325 #define DEF_COMBOBOX_BUTTON_RELIEF "raised"
326 #define DEF_COMBOBOX_RELIEF "flat"
327 #ifdef WIN32
328 #define DEF_COMBOBOX_CURSOR "arrow"
329 #else
330 #define DEF_COMBOBOX_CURSOR "hand2"
331 #endif /*WIN32*/
332
333 static Blt_ConfigSpec windowBoxSpecs[] =
334 {
335 {BLT_CONFIG_STRING, "-windowcmd", "windowCmd", "windowCmd",
336 (char *)NULL, Blt_Offset(TreeViewWindowBox, windowCmd),
337 BLT_CONFIG_NULL_OK, 0},
338 {BLT_CONFIG_INT, "-minwidth", "WindowWidth", "WindowWidth",
339 "0", Blt_Offset(TreeViewWindowBox, windowWidth), 0},
340 {BLT_CONFIG_INT, "-minheight", "WindowHeight", "WindowHeight",
341 "0", Blt_Offset(TreeViewWindowBox, windowHeight), 0},
342 {BLT_CONFIG_CUSTOM, "-sticky", "sticky", "Sticky",
343 "w", Tk_Offset(TreeViewWindowBox, sticky),
344 0, &bltStickyOption},
345
346 {BLT_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL,
347 (char *)NULL, 0, 0}
348 };
349
350 typedef struct {
351 TREEVIEW_STYLE_COMMON
352
353 /* Barbox specific fields. */
354 GC bgGC;
355 Tk_3DBorder barBg; /* Normal background color of cell. */ \
356
357 int showValue; /* If non-zero, display the on/off value. */
358 double minValue;
359 double maxValue;
360 int lineWidth; /* Linewidth of the surrounding box. */
361 Tcl_Obj *formatCmd;
362
363 XColor *boxColor; /* Rectangle (box) color (grey). */
364 XColor *fillColor; /* Fill color (white) */
365
366 GC boxGC;
367 GC fillGC; /* Box fill GC */
368
369 int barWidth;
370 int barHeight;
371
372 } TreeViewBarBox;
373
374 #define DEF_BARBOX_BOX_COLOR "black"
375 #define DEF_BARBOX_FILL_COLOR "darkgreen"
376 #define DEF_BARBOX_MINVALUE "0.0"
377 #define DEF_BARBOX_MAXVALUE "100.0"
378 #define DEF_BARBOX_WIDTH "80"
379 #define DEF_BARBOX_HEIGHT "10"
380 #define DEF_BARBOX_SHOWVALUE "yes"
381 #define DEF_BARBOX_LINEWIDTH "1"
382 #define DEF_BARBOX_GAP "4"
383 #ifdef WIN32
384 #define DEF_BARBOX_CURSOR "arrow"
385 #else
386 #define DEF_BARBOX_CURSOR "hand2"
387 #endif /*WIN32*/
388
389 static Blt_ConfigSpec barBoxSpecs[] =
390 {
391 CONF_STYLES
392 {BLT_CONFIG_BORDER, "-barbg", "barBg", "BarBg",
393 (char *)NULL, Blt_Offset(TreeViewBarBox, barBg), BLT_CONFIG_NULL_OK},
394 {BLT_CONFIG_COLOR, "-barfg", "barFg", "BarFg",
395 DEF_BARBOX_FILL_COLOR, Blt_Offset(TreeViewBarBox, fillColor), 0},
396 {BLT_CONFIG_COLOR, "-boxcolor", "boxColor", "BoxColor",
397 DEF_BARBOX_BOX_COLOR, Blt_Offset(TreeViewBarBox, boxColor), 0},
398 {BLT_CONFIG_INT, "-barwidth", "barWidth", "BarWidth",
399 DEF_BARBOX_WIDTH, Blt_Offset(TreeViewBarBox, barWidth), 0},
400 {BLT_CONFIG_INT, "-barheight", "BarHeight", "BarHeight",
401 DEF_BARBOX_HEIGHT, Blt_Offset(TreeViewBarBox, barHeight), 0},
402 {BLT_CONFIG_TILE, "-filltile", "fillTile", "FillTile",
403 (char *)NULL, Tk_Offset(TreeViewBarBox, fillTile), BLT_CONFIG_NULL_OK, },
404 {BLT_CONFIG_OBJCMD, "-formatcmd", "formatCmd", "FormatCmd",
405 NULL, Blt_Offset(TreeViewBarBox, formatCmd),
406 BLT_CONFIG_NULL_OK},
407 {BLT_CONFIG_DISTANCE, "-linewidth", "lineWidth", "LineWidth",
408 DEF_BARBOX_LINEWIDTH,
409 Blt_Offset(TreeViewBarBox, lineWidth),
410 BLT_CONFIG_DONT_SET_DEFAULT},
411 {BLT_CONFIG_DOUBLE, "-maxvalue", "maxValue", "MaxValue",
412 DEF_BARBOX_MAXVALUE, Blt_Offset(TreeViewBarBox, maxValue), 0},
413 {BLT_CONFIG_DOUBLE, "-minvalue", "minValue", "MinValue",
414 DEF_BARBOX_MINVALUE, Blt_Offset(TreeViewBarBox, minValue), 0},
415 {BLT_CONFIG_BOOLEAN, "-showvalue", "showValue", "ShowValue",
416 DEF_BARBOX_SHOWVALUE, Blt_Offset(TreeViewBarBox, showValue),
417 BLT_CONFIG_DONT_SET_DEFAULT},
418 {BLT_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL,
419 (char *)NULL, 0, 0}
420 };
421
422 typedef union {
423 TreeViewTextBox tb;
424 TreeViewCheckBox cb;
425 TreeViewComboBox cob;
426 TreeViewBarBox bb;
427 TreeViewWindowBox wb;
428 } TreeViewAllStyles;
429
430 typedef TreeViewStyle *(StyleCreateProc) _ANSI_ARGS_((TreeView *tvPtr,
431 Blt_HashEntry *hPtr));
432
433 static StyleConfigProc ConfigureTextBox, ConfigureCheckBox, ConfigureComboBox, ConfigureWindowBox, ConfigureBarBox;
434 static StyleCreateProc CreateTextBox, CreateCheckBox, CreateComboBox, CreateWindowBox, CreateBarBox;
435 static StyleDrawProc DrawTextBox, DrawCheckBox, DrawComboBox, DrawWindowBox, DrawBarBox;
436 static StyleEditProc EditTextBox, EditCheckBox, EditComboBox, EditWindowBox, EditBarBox;
437 static StyleFreeProc FreeTextBox, FreeCheckBox, FreeComboBox, FreeWindowBox, FreeBarBox;
438 static StyleMeasureProc MeasureTextBox, MeasureCheckBox, MeasureComboBox, MeasureWindowBox, MeasureBarBox;
439 static StylePickProc PickComboBox;
440
441
442 static Tcl_Obj *
443 StickyToObj(clientData, interp, tkwin, widgRec, offset)
444 ClientData clientData; /* Not used. */
445 Tcl_Interp *interp;
446 Tk_Window tkwin; /* Not used. */
447 char *widgRec;
448 int offset;
449 {
450 int flags = *(int *)(widgRec + offset);
451
452 int count = 0;
453 char result[10];
454
455 if (flags&STICK_NORTH) result[count++] = 'n';
456 if (flags&STICK_EAST) result[count++] = 'e';
457 if (flags&STICK_SOUTH) result[count++] = 's';
458 if (flags&STICK_WEST) result[count++] = 'w';
459
460 result[count] = '\0';
461 return Tcl_NewStringObj(result, -1);
462 }
463
464 static int
465 ObjToSticky(clientData, interp, tkwin, objPtr, widgRec, offset)
466 ClientData clientData; /* Not used. */
467 Tcl_Interp *interp; /* Interpreter to send results back to */
468 Tk_Window tkwin; /* Not used. */
469 Tcl_Obj *objPtr; /* Tcl_Obj representing the new value. */
470 char *widgRec;
471 int offset;
472 {
473 /* TreeView *tvPtr = clientData; */
474 int *stickyPtr = (int *)(widgRec + offset);
475 int sticky = 0;
476 char c;
477 char *value;
478
479 value = Tcl_GetString(objPtr);
480
481 while ((c = *value++) != '\0') {
482 switch (c) {
483 case 'n': case 'N': sticky |= STICK_NORTH; break;
484 case 'e': case 'E': sticky |= STICK_EAST; break;
485 case 's': case 'S': sticky |= STICK_SOUTH; break;
486 case 'w': case 'W': sticky |= STICK_WEST; break;
487 case ' ': case ',': case '\t': case '\r': case '\n': break;
488 default:
489 Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
490 "bad sticky value \"", --value,
491 "\": must contain n, s, e or w",
492 (char *) NULL);
493 return TCL_ERROR;
494 }
495 }
496 *stickyPtr = sticky;
497 return TCL_OK;
498 }
499
500
501 /*
502 *----------------------------------------------------------------------
503 *
504 * ObjToIcon --
505 *
506 * Convert the name of an icon into a Tk image.
507 *
508 * Results:
509 * If the string is successfully converted, TCL_OK is returned.
510 * Otherwise, TCL_ERROR is returned and an error message is left in
511 * interpreter's result field.
512 *
513 *----------------------------------------------------------------------
514 */
515 /*ARGSUSED*/
516 static int
517 ObjToIcon(clientData, interp, tkwin, objPtr, widgRec, offset)
518 ClientData clientData; /* Not used. */
519 Tcl_Interp *interp; /* Interpreter to send results back to */
520 Tk_Window tkwin; /* Not used. */
521 Tcl_Obj *objPtr; /* Tcl_Obj representing the new value. */
522 char *widgRec;
523 int offset;
524 {
525 TreeView *tvPtr = clientData;
526 TreeViewIcon *iconPtr = (TreeViewIcon *)(widgRec + offset);
527 TreeViewIcon icon;
528
529 icon = Blt_TreeViewGetIcon(tvPtr, Tcl_GetString(objPtr));
530 if (icon == NULL) {
531 return TCL_ERROR;
532 }
533 *iconPtr = icon;
534 return TCL_OK;
535 }
536 /*
537 *----------------------------------------------------------------------
538 *
539 * IconToObj --
540 *
541 * Converts the icon into its string representation (its name).
542 *
543 * Results:
544 * The name of the icon is returned.
545 *
546 *----------------------------------------------------------------------
547 */
548 /*ARGSUSED*/
549 static Tcl_Obj *
550 IconToObj(clientData, interp, tkwin, widgRec, offset)
551 ClientData clientData; /* Not used. */
552 Tcl_Interp *interp;
553 Tk_Window tkwin; /* Not used. */
554 char *widgRec;
555 int offset;
556 {
557 TreeViewIcon icon = *(TreeViewIcon *)(widgRec + offset);
558
559 return Tcl_NewStringObj(icon?Blt_NameOfImage((icon)->tkImage):"", -1);
560 }
561
562 /*ARGSUSED*/
563
564 int
565 Blt_TreeViewTextbox(TreeView *tvPtr,
566 TreeViewEntry *entryPtr,
567 TreeViewColumn *columnPtr);
568 static int
569 FreeIcon(clientData, display, widgRec, offset, oldPtr)
570 ClientData clientData;
571 Display *display; /* Not used. */
572 char *widgRec;
573 int offset;
574 char *oldPtr;
575 {
576 TreeViewIcon icon = (TreeViewIcon)(oldPtr);
577 TreeView *tvPtr = clientData;
578
579 Blt_TreeViewFreeIcon(tvPtr, icon);
580 return TCL_OK;
581 }
582
583 static TreeViewStyleClass textBoxClass = {
584 "TextBoxStyle",
585 textBoxSpecs,
586 ConfigureTextBox,
587 MeasureTextBox,
588 DrawTextBox,
589 NULL,
590 EditTextBox,
591 FreeTextBox,
592 };
593
594 static TreeViewStyleClass checkBoxClass = {
595 "CheckBoxStyle",
596 checkBoxSpecs,
597 ConfigureCheckBox,
598 MeasureCheckBox,
599 DrawCheckBox,
600 NULL,
601 EditCheckBox,
602 FreeCheckBox,
603 };
604
605 static TreeViewStyleClass comboBoxClass = {
606 "ComboBoxStyle",
607 comboBoxSpecs,
608 ConfigureComboBox,
609 MeasureComboBox,
610 DrawComboBox,
611 PickComboBox,
612 EditComboBox,
613 FreeComboBox,
614 };
615
616 static TreeViewStyleClass windowBoxClass = {
617 "WindowBoxStyle",
618 windowBoxSpecs,
619 ConfigureWindowBox,
620 MeasureWindowBox,
621 DrawWindowBox,
622 NULL,
623 EditWindowBox,
624 FreeWindowBox,
625 };
626
627 static TreeViewStyleClass barBoxClass = {
628 "BarBoxStyle",
629 barBoxSpecs,
630 ConfigureBarBox,
631 MeasureBarBox,
632 DrawBarBox,
633 NULL,
634 EditBarBox,
635 FreeBarBox,
636 };
637
638 int Blt_TreeViewStyleIsFmt (TreeView *tvPtr,
639 TreeViewStyle *stylePtr)
640 {
641 if (stylePtr->classPtr == &textBoxClass) {
642 TreeViewTextBox *tbPtr;
643 tbPtr = (TreeViewTextBox *)stylePtr;
644 if (tbPtr->formatCmd != NULL && strlen(Tcl_GetString(tbPtr->formatCmd))) {
645 return 1;
646 }
647 return 0;
648 }
649 if (stylePtr->classPtr == &barBoxClass) {
650 TreeViewBarBox *bbPtr;
651 bbPtr = (TreeViewBarBox *)stylePtr;
652 if (bbPtr->formatCmd != NULL && strlen(Tcl_GetString(bbPtr->formatCmd))) {
653 return 1;
654 }
655 return 0;
656 }
657 return 0;
658 }
659
660 /* Allocate a new style. */
661 static TreeViewStyle *newStyle(TreeView *tvPtr, Blt_HashEntry *hPtr, int size) {
662 TreeViewStyle *stylePtr;
663 stylePtr = Blt_Calloc(1, sizeof(TreeViewAllStyles));
664 /*stylePtr = Blt_Calloc(1, size); */
665 assert(stylePtr);
666 stylePtr->gap = STYLE_GAP;
667 stylePtr->name = Blt_Strdup(Blt_GetHashKey(&tvPtr->styleTable, hPtr));
668 stylePtr->hashPtr = hPtr;
669 stylePtr->refCount = 1;
670 Blt_SetHashValue(hPtr, stylePtr);
671 return stylePtr;
672 }
673 /*
674 *----------------------------------------------------------------------
675 *
676 * CreateTextBox --
677 *
678 * Creates a "textbox" style.
679 *
680 * Results:
681 * A pointer to the new style structure.
682 *
683 *----------------------------------------------------------------------
684 */
685 static TreeViewStyle *
686 CreateTextBox(tvPtr, hPtr)
687 TreeView *tvPtr;
688 Blt_HashEntry *hPtr;
689 {
690 TreeViewTextBox *tbPtr;
691
692 tbPtr = (TreeViewTextBox *)newStyle(tvPtr, hPtr, sizeof(TreeViewTextBox));
693 tbPtr->classPtr = &textBoxClass;
694 tbPtr->iconside = SIDE_LEFT;
695 tbPtr->side = SIDE_TOP;
696 tbPtr->flags = STYLE_TEXTBOX;
697 return (TreeViewStyle *)tbPtr;
698 }
699
700 /*
701 *----------------------------------------------------------------------
702 *
703 * ConfigureTextBox --
704 *
705 * Configures a "textbox" style. This routine performs
706 * generates the GCs required for a textbox style.
707 *
708 * Results:
709 * None.
710 *
711 * Side Effects:
712 * GCs are created for the style.
713 *
714 *----------------------------------------------------------------------
715 */
716 static void
717 ConfigureTextBox(tvPtr, stylePtr)
718 TreeView *tvPtr;
719 TreeViewStyle *stylePtr;
720 {
721 GC newGC;
722 XColor *bgColor;
723 XGCValues gcValues;
724 unsigned long gcMask;
725
726 gcMask = GCForeground | GCBackground | GCFont;
727 gcValues.font = Tk_FontId(CHOOSE(tvPtr->font, stylePtr->font));
728 bgColor = Tk_3DBorderColor(CHOOSE(tvPtr->border, stylePtr->border));
729
730 gcValues.background = bgColor->pixel;
731 gcValues.foreground = CHOOSE(tvPtr->fgColor, stylePtr->fgColor)->pixel;
732 newGC = Tk_GetGC(tvPtr->tkwin, gcMask, &gcValues);
733 if (stylePtr->gc != NULL) {
734 Tk_FreeGC(tvPtr->display, stylePtr->gc);
735 }
736 stylePtr->gc = newGC;
737 if (stylePtr->highlightBorder) {
738 gcValues.background = Tk_3DBorderColor(stylePtr->highlightBorder)->pixel;
739 } else {
740 gcValues.background = bgColor->pixel;
741 }
742 if (stylePtr->highlightFgColor) {
743 gcValues.foreground = stylePtr->highlightFgColor->pixel;
744 } else {
745 gcValues.foreground = CHOOSE(tvPtr->fgColor, stylePtr->fgColor)->pixel;
746 }
747 newGC = Tk_GetGC(tvPtr->tkwin, gcMask, &gcValues);
748 if (stylePtr->highlightGC != NULL) {
749 Tk_FreeGC(tvPtr->display, stylePtr->highlightGC);
750 }
751 stylePtr->highlightGC = newGC;
752
753 if (stylePtr->activeBorder) {
754 gcValues.background = Tk_3DBorderColor(stylePtr->activeBorder)->pixel;
755 } else {
756 gcValues.background = bgColor->pixel;
757 }
758 if (stylePtr->activeFgColor) {
759 gcValues.foreground = stylePtr->activeFgColor->pixel;
760 } else {
761 gcValues.foreground = CHOOSE(tvPtr->fgColor, stylePtr->fgColor)->pixel;
762 }
763 newGC = Tk_GetGC(tvPtr->tkwin, gcMask, &gcValues);
764 if (stylePtr->activeGC != NULL) {
765 Tk_FreeGC(tvPtr->display, stylePtr->activeGC);
766 }
767 stylePtr->activeGC = newGC;
768 stylePtr->flags |= STYLE_DIRTY;
769 }
770
771 /*
772 *----------------------------------------------------------------------
773 *
774 * MeasureTextBox --
775 *
776 * Determines the space requirements for the "textbox" given
777 * the value to be displayed. Depending upon whether an icon
778 * or text is displayed and their relative placements, this
779 * routine computes the space needed for the text entry.
780 *
781 * Results:
782 * None.
783 *
784 * Side Effects:
785 * The width and height fields of *valuePtr* are set with the
786 * computed dimensions.
787 *
788 *----------------------------------------------------------------------
789 */
790 static void
791 MeasureTextBox(tvPtr, stylePtr, valuePtr)
792 TreeView *tvPtr;
793 TreeViewStyle *stylePtr;
794 TreeViewValue *valuePtr;
795 {
796 TreeViewTextBox *tbPtr = (TreeViewTextBox *)stylePtr;
797 TreeViewColumn *columnPtr = valuePtr->columnPtr;
798 int iconWidth, iconHeight;
799 int textWidth, textHeight;
800 int gap;
801 TreeViewIcon icon;
802 int rel = 0;
803
804 textWidth = textHeight = 0;
805 iconWidth = iconHeight = 0;
806 valuePtr->width = valuePtr->height = 0;
807 icon = (stylePtr->icon?stylePtr->icon:(columnPtr->stylePtr?columnPtr->stylePtr->icon:NULL));
808 if (icon != NULL && tvPtr->hideStyleIcons == 0) {
809 iconWidth = TreeViewIconWidth(icon);
810 iconHeight = TreeViewIconHeight(icon);
811 }
812 if (valuePtr->textPtr != NULL) {
813 Blt_Free(valuePtr->textPtr);
814 valuePtr->textPtr = NULL;
815 }
816 #define NotNullObj(p) ((p != NULL && strlen(Tcl_GetString(p))) ? p : NULL)
817
818 if (valuePtr->string != NULL) {
819 /* New string defined. */
820 TextStyle ts;
821 Tcl_Obj *fmtObj;
822
823 fmtObj = NotNullObj(tbPtr->formatCmd);
824 if (fmtObj == NULL) {
825 fmtObj = NotNullObj(columnPtr->formatCmd);
826 }
827 if (fmtObj == NULL) {
828 fmtObj = NotNullObj(tvPtr->formatCmd);
829 }
830
831 Blt_InitTextStyle(&ts);
832 ts.font = CHOOSE3(tvPtr->font, columnPtr->font , stylePtr->font);
833 ts.anchor = TK_ANCHOR_NW;
834 ts.justify = columnPtr->justify;
835 if (fmtObj != NULL) {
836 Tcl_DString cmdString;
837 char *string;
838 int result;
839 Tcl_Interp *interp = tvPtr->interp;
840
841 Tcl_Preserve(valuePtr->entryPtr);
842 rel = 1;
843 Blt_TreeViewPercentSubst(tvPtr, valuePtr->entryPtr, columnPtr, Tcl_GetString(fmtObj), valuePtr->string, &cmdString);
844 result = Tcl_GlobalEval(interp, Tcl_DStringValue(&cmdString));
845 Blt_TreeViewOptsInit(tvPtr);
846 Tcl_DStringFree(&cmdString);
847 if (result == TCL_OK) {
848 string = Tcl_GetStringResult(interp);
849 valuePtr->textPtr = Blt_GetTextLayoutStr(string, &ts);
850 }
851 }
852 if (valuePtr->textPtr == NULL) {
853 valuePtr->textPtr = Blt_GetTextLayoutStr(valuePtr->string, &ts);
854 }
855 }
856 gap = 0;
857 if (valuePtr->textPtr != NULL && tvPtr->hideStyleText == 0) {
858 textWidth = valuePtr->textPtr->width;
859 textHeight = valuePtr->textPtr->height;
860 if (stylePtr->icon != NULL) {
861 gap = stylePtr->gap;
862 }
863 }
864 if (SIDE_VERTICAL(tbPtr->iconside)) {
865 valuePtr->height = iconHeight + gap + textHeight;
866 valuePtr->width = MAX(textWidth, iconWidth);
867 } else {
868 valuePtr->width = iconWidth + gap + textWidth;
869 valuePtr->height = MAX(textHeight, iconHeight);
870 }
871 if (rel) {
872 Tcl_Release(valuePtr->entryPtr);
873 }
874 }
875
876 /*
877 * Fill in the bg, fg, font from styles from value, entry, column and tvjj. */
878 static void
879 GetPriorityStyle(
880 TreeView *tvPtr,
881 TreeViewEntry *entryPtr,
882 TreeViewValue *valuePtr,
883 TreeViewStyle *inStylePtr,
884 TreeViewStyle *stylePtr
885 ) {
886 TreeViewStyle *s[4];
887 int i = -1, bgprio = -1, fgprio = -1, fntprio = -1;
888 int disabled = (entryPtr->state == STATE_DISABLED);
889
890 s[0] = valuePtr?valuePtr->stylePtr:NULL;
891 s[1] = entryPtr?entryPtr->stylePtr:NULL;
892 s[2] = valuePtr?valuePtr->columnPtr->stylePtr:NULL;
893 s[3] = tvPtr->stylePtr;
894 /*stylePtr->font = CHOOSE3(tvPtr->font, inStylePtr->font, entryPtr->font); */
895 stylePtr->font = tvPtr->font;
896 if (valuePtr != NULL && valuePtr->columnPtr->font) {
897 stylePtr->font = valuePtr->columnPtr->font;
898 stylePtr->gc = valuePtr->columnPtr->textGC;
899 } else if (inStylePtr->font) {
900 stylePtr->font = inStylePtr->font;
901 stylePtr->gc = stylePtr->gc;
902 }
903 stylePtr->border = CHOOSE3(tvPtr->border, inStylePtr->border, entryPtr->border);
904 if (disabled) {
905 stylePtr->fgColor = tvPtr->disabledColor;
906 } else if (valuePtr != NULL) {
907 stylePtr->fgColor = CHOOSE4(tvPtr->fgColor, valuePtr->columnPtr->fgColor, inStylePtr->fgColor, entryPtr->color);
908 } else {
909 stylePtr->fgColor = CHOOSE3(tvPtr->fgColor, inStylePtr->fgColor, entryPtr->color);
910 }
911 while (++i<4) {
912 if (s[i]) {
913 if (s[i]->border && (s[i]->priority>bgprio||stylePtr->border==NULL)) {
914 stylePtr->border = s[i]->border;
915 bgprio = s[i]->priority;
916 }
917 if (disabled == 0 && s[i]->fgColor && (s[i]->priority>fgprio||stylePtr->fgColor==NULL)) {
918 stylePtr->fgColor = s[i]->fgColor;
919 fgprio = s[i]->priority;
920 }
921 if (s[i]->font && (s[i]->priority>fntprio||stylePtr->font==NULL)) {
922 stylePtr->font = s[i]->font;
923 stylePtr->gc = s[i]->gc;
924 fntprio = s[i]->priority;
925 }
926 }
927 }
928 }
929
930 /* Fill in stylePtr with font, border, fgColor, etc. UNUSED */
931 void
932 Blt_GetPriorityStyle(
933 TreeViewStyle *stylePtr, /* Style to fillin. */
934 TreeView *tvPtr,
935 TreeViewColumn *columnPtr,
936 TreeViewEntry *entryPtr,
937 TreeViewValue *valuePtr,
938 TreeViewStyle *inStylePtr,
939 int flags
940 ) {
941 TreeViewStyle *s[20];
942 int n = 0, i = -1;
943 int bgprio = -1, fgprio = -1, fntprio = -1, shadprio = -1, tileprio = -1;
944 int iconprio = -1;
945 int disabled = (entryPtr->state == STATE_DISABLED);
946
947 if ((flags&STYLEFLAG_NOCLEAR) == 0) {
948 memset(stylePtr, 0, sizeof(*stylePtr));
949 }
950 /* Is a sub label */
951 if ((flags&STYLEFLAG_SUBSTYLE) && tvPtr->subStylePtr) {
952 s[n++] = tvPtr->subStylePtr;
953 }
954 /* Is an empty value. */
955 if ((flags&STYLEFLAG_EMPTYSTYLE) && tvPtr->emptyStylePtr) {
956 s[n++] = tvPtr->emptyStylePtr;
957 }
958 /* Is an alt row. */
959 if ((flags&STYLEFLAG_ALTSTYLE) && tvPtr->altStylePtr) {
960 s[n++] = tvPtr->altStylePtr;
961 }
962 /* Is a title. */
963 if ((flags&STYLEFLAG_TITLESTYLE) && columnPtr && columnPtr->titleStylePtr) {
964 s[n++] = columnPtr->titleStylePtr;
965 }
966 if (inStylePtr) s[n++] = inStylePtr;
967 if (valuePtr && valuePtr->stylePtr) s[n++] = valuePtr->stylePtr;
968 if (entryPtr && entryPtr->stylePtr) s[n++] = entryPtr->stylePtr;
969 if (columnPtr && columnPtr->stylePtr) s[n++] = columnPtr->stylePtr;
970 if (tvPtr->stylePtr) s[n++] = tvPtr->stylePtr;
971 if (inStylePtr == NULL) inStylePtr = tvPtr->stylePtr;
972 /*stylePtr->font = CHOOSE(tvPtr->font, entryPtr->font); */
973 /*stylePtr->font = tvPtr->font;
974 stylePtr->border = tvPtr->border;
975 stylePtr->fgColor = tvPtr->fgColor;
976 stylePtr->shadow.color = NULL;
977 stylePtr->tile = NULL;
978 stylePtr->icon = NULL;*/
979 stylePtr->gc = (entryPtr?entryPtr->gc:NULL);
980 /* stylePtr->font = tvPtr->font; */
981 if (valuePtr != NULL && valuePtr->columnPtr->font) {
982 stylePtr->font = valuePtr->columnPtr->font;
983 stylePtr->gc = valuePtr->columnPtr->textGC;
984 } else if (inStylePtr->font) {
985 stylePtr->font = inStylePtr->font;
986 stylePtr->gc = stylePtr->gc;
987 } else if (columnPtr && columnPtr->font) {
988 stylePtr->font = columnPtr->font;
989 stylePtr->gc = columnPtr->textGC;
990 }
991 stylePtr->border = CHOOSE3(tvPtr->border, inStylePtr->border, entryPtr->border);
992 if (disabled) {
993 stylePtr->fgColor = tvPtr->disabledColor;
994 } else if (valuePtr != NULL) {
995 stylePtr->fgColor = CHOOSE4(tvPtr->fgColor, valuePtr->columnPtr->fgColor, inStylePtr->fgColor, entryPtr->color);
996 } else {
997 stylePtr->fgColor = CHOOSE3(tvPtr->fgColor, inStylePtr->fgColor, entryPtr->color);
998 }
999 i = -1;
1000 while (++i<n) {
1001 if (s[i]->border && (s[i]->priority>bgprio||stylePtr->border==NULL)) {
1002 stylePtr->border = s[i]->border;
1003 bgprio = s[i]->priority;
1004 }
1005 if (disabled == 0 && s[i]->fgColor && (s[i]->priority>fgprio||stylePtr->fgColor==NULL)) {
1006 stylePtr->fgColor = s[i]->fgColor;
1007 fgprio = s[i]->priority;
1008 }
1009 if (s[i]->font && (s[i]->priority>fntprio||stylePtr->font==NULL)) {
1010 stylePtr->font = s[i]->font;
1011 fntprio = s[i]->priority;
1012 stylePtr->gc = s[i]->gc;
1013 }
1014 if (s[i]->shadow.color && (s[i]->priority>shadprio||stylePtr->shadow.color==NULL)) {
1015 stylePtr->shadow = s[i]->shadow;
1016 shadprio = s[i]->priority;
1017 }
1018 if (s[i]->icon && (s[i]->priority>iconprio||stylePtr->icon==NULL)) {
1019 stylePtr->icon = s[i]->icon;
1020 iconprio = s[i]->priority;
1021 }
1022 if (s[i]->tile && (s[i]->priority>tileprio||stylePtr->tile==NULL)) {
1023 stylePtr->tile = s[i]->tile;
1024 tileprio = s[i]->priority;
1025 }
1026 }
1027 if (entryPtr == NULL) {
1028 if (stylePtr->font==NULL) stylePtr->font = tvPtr->font;
1029 if (stylePtr->border==NULL) stylePtr->border = tvPtr->border;
1030 if (stylePtr->fgColor==NULL) stylePtr->fgColor = tvPtr->fgColor;
1031 } else {
1032 if (stylePtr->font==NULL) stylePtr->font = CHOOSE3(tvPtr->font,(columnPtr?columnPtr->font:NULL),entryPtr->font);
1033 if (stylePtr->border==NULL) stylePtr->border = CHOOSE(tvPtr->border,entryPtr->border);
1034 if (stylePtr->fgColor==NULL) stylePtr->fgColor = CHOOSE(tvPtr->fgColor,entryPtr->color);
1035 if (stylePtr->shadow.color==NULL) stylePtr->shadow = entryPtr->shadow;
1036 }
1037 if (stylePtr->tile==NULL) stylePtr->tile = tvPtr->tile;
1038 }
1039
1040 #define IFSET(var,val) var = (val?val:var)
1041
1042 /* Fill background. */
1043 /* TODO: return GC for element/style that sets the font!!!! */
1044 /* TODO: lookup font from style for Measure routines. */
1045 void
1046 drawTextBox(tvPtr, drawable, entryPtr, valuePtr, stylePtr, icon, x, y, sRec)
1047 TreeView *tvPtr;
1048 Drawable drawable;
1049 TreeViewEntry *entryPtr;
1050 TreeViewValue *valuePtr;
1051 TreeViewStyle *stylePtr;
1052 TreeViewIcon icon;
1053 int x, y;
1054 TreeViewStyle *sRec;
1055 {
1056 TreeViewColumn *columnPtr;
1057 int altRow = (entryPtr->flags&ENTRY_ALTROW);
1058
1059 columnPtr = valuePtr->columnPtr;
1060 sRec->font = CHOOSE(tvPtr->font, columnPtr->font);
1061 sRec->fgColor = CHOOSE(tvPtr->fgColor, columnPtr->fgColor);
1062 sRec->border = tvPtr->border;
1063 sRec->gc = tvPtr->stylePtr->gc;
1064 GetPriorityStyle(tvPtr, entryPtr, valuePtr, stylePtr, sRec);
1065 /* TODO: fix font/gc bug where altStyle has tile and bg */
1066 if ((tvPtr->activeColumnPtr == valuePtr->columnPtr && tvPtr->actCol) ||
1067 (valuePtr == tvPtr->activeValuePtr) ||
1068 (tvPtr->activeButtonPtr == entryPtr && tvPtr->actEntry) ||
1069 (stylePtr->flags & STYLE_HIGHLIGHT)) {
1070 IFSET(sRec->border, stylePtr->highlightBorder);
1071 IFSET(sRec->fgColor, stylePtr->highlightFgColor);
1072 } else if (valuePtr->stylePtr && valuePtr->stylePtr->border) {
1073 sRec->border = valuePtr->stylePtr->border;
1074 } else if (columnPtr->hasbg) {
1075 sRec->border = columnPtr->border;
1076 /*((tvPtr->tile != NULL || columnPtr->tile != NULL) && stylePtr->tile==NULL)*/
1077 } else if ((Blt_HasTile(tvPtr->tile) || Blt_HasTile(columnPtr->tile)) && Blt_HasTile(stylePtr->tile)==0) {
1078 sRec->border = NULL;
1079 } else if (altRow && tvPtr->altStylePtr && Blt_HasTile(tvPtr->altStylePtr->tile)) {
1080 stylePtr = tvPtr->altStylePtr;
1081 }
1082 if (!Blt_TreeViewEntryIsSelected(tvPtr, entryPtr, columnPtr)) {
1083 /*
1084 * Draw the active or normal background color over the entire
1085 * label area. This includes both the tab's text and image.
1086 * The rectangle should be 2 pixels wider/taller than this
1087 * area. So if the label consists of just an image, we get an
1088 * halo around the image when the tab is active.
1089 */
1090 if (sRec->border != NULL && (altRow==0 ||
1091 (altRow && stylePtr->tile && stylePtr == tvPtr->altStylePtr))) {
1092 Blt_TreeViewFill3DTile(tvPtr, drawable, sRec->border,
1093 x - columnPtr->pad.side1, y - tvPtr->leader/2,
1094 columnPtr->width, entryPtr->height,
1095 0, TK_RELIEF_FLAT, entryPtr->gc?NULL:stylePtr->tile, tvPtr->scrollTile, 1);
1096 }
1097 }
1098 }
1099
1100 /*
1101 * Set fg color based on string pattern match
1102 */
1103 static void
1104 GetColorPats(tvPtr, entryPtr, valuePtr, stylePtr, fgPtr)
1105 TreeView *tvPtr;
1106 TreeViewEntry *entryPtr;
1107 TreeViewValue *valuePtr;
1108 TreeViewStyle *stylePtr;
1109 XColor **fgPtr;
1110 {
1111 XColor *color = NULL;
1112 Tcl_Interp *interp = tvPtr->interp;
1113 int objc, i;
1114 Tcl_Obj **objv, *objPtr = NULL;
1115 TreeViewColumn *columnPtr = valuePtr->columnPtr;
1116
1117 if (columnPtr->colorPats != NULL && strlen(Tcl_GetString(columnPtr->colorPats))) {
1118 if (Tcl_ListObjGetElements(NULL, columnPtr->colorPats, &objc, &objv) != TCL_OK) return;
1119 if (objc%2) return;
1120 for (i = 0; i < objc; i += 2) {
1121 if (Tcl_StringMatch(valuePtr->string, Tcl_GetString(objv[i]))) {
1122 color = Tk_AllocColorFromObj(interp, tvPtr->tkwin, objv[i+1]);
1123 if (color != NULL) {
1124 *fgPtr = color;
1125 return;
1126 }
1127 }
1128 }
1129 }
1130 if (columnPtr->colorRegex != NULL && strlen(Tcl_GetString(columnPtr->colorRegex))) {
1131 if (Tcl_ListObjGetElements(NULL, columnPtr->colorRegex, &objc, &objv) != TCL_OK) return;
1132 if (objc%2) return;
1133 for (i = 0; i < objc; i += 2) {
1134 if (objPtr == NULL) {
1135 objPtr = Tcl_NewStringObj(valuePtr->string,-1);
1136 Tcl_IncrRefCount(objPtr);
1137 }
1138 if (Tcl_RegExpMatchObj(NULL, objPtr, objv[i]) == 1) {
1139 color = Tk_AllocColorFromObj(interp, tvPtr->tkwin, objv[i+1]);
1140 if (color != NULL) {
1141 *fgPtr = color;
1142 break;
1143 }
1144 }
1145 }
1146 if (objPtr != NULL) {
1147 Tcl_DecrRefCount(objPtr);
1148 }
1149 }
1150 }
1151
1152 /*
1153 *----------------------------------------------------------------------
1154 *
1155 * DrawTextBox --
1156 *
1157 * Draws the "textbox" given the screen coordinates and the
1158 * value to be displayed.
1159 *
1160 * Results:
1161 * None.
1162 *
1163 * Side Effects:
1164 * The textbox value is drawn.
1165 *
1166 *----------------------------------------------------------------------
1167 */
1168 static void
1169 DrawTextBox(tvPtr, drawable, entryPtr, valuePtr, stylePtr, icon, x, y)
1170 TreeView *tvPtr;
1171 Drawable drawable;
1172 TreeViewEntry *entryPtr;
1173 TreeViewValue *valuePtr;
1174 TreeViewStyle *stylePtr;
1175 TreeViewIcon icon;
1176 int x, y;
1177 {
1178 GC gc;
1179 TreeViewColumn *columnPtr;
1180 TreeViewTextBox *tbPtr = (TreeViewTextBox *)stylePtr;
1181 int iconX, iconY, iconWidth, iconHeight;
1182 int textX, textY, textWidth, textHeight;
1183 int gap, columnWidth, ix = x;
1184 TreeViewStyle sRec = *stylePtr;
1185 int valWidth;
1186 TextLayout *layPtr;
1187
1188 layPtr = (tvPtr->hideStyleText?NULL:valuePtr->textPtr);
1189 columnPtr = valuePtr->columnPtr;
1190 valWidth = (layPtr?valuePtr->width:(icon?TreeViewIconWidth(icon):0));
1191 if (!stylePtr) return;
1192 drawTextBox(tvPtr, drawable, entryPtr, valuePtr, stylePtr, icon, x, y, &sRec);
1193 gc = sRec.gc;
1194 columnWidth = columnPtr->width -
1195 (2 * columnPtr->borderWidth + PADDING(columnPtr->pad));
1196
1197 textX = textY = iconX = iconY = 0; /* Suppress compiler warning. */
1198
1199 iconWidth = iconHeight = 0;
1200 if (icon != NULL) {
1201 iconWidth = TreeViewIconWidth(icon);
1202 iconHeight = TreeViewIconHeight(icon);
1203 }
1204 textWidth = textHeight = 0;
1205 if (layPtr != NULL) {
1206 textWidth = layPtr->width;
1207 textHeight = layPtr->height;
1208 }
1209 gap = 0;
1210 if ((icon != NULL) && (layPtr != NULL)) {
1211 gap = stylePtr->gap;
1212 }
1213 if (columnWidth >= valWidth) {
1214 switch(columnPtr->justify) {
1215 case TK_JUSTIFY_RIGHT:
1216 ix = x + columnWidth - iconWidth;
1217 x += (columnWidth - valWidth);
1218 break;
1219 case TK_JUSTIFY_CENTER:
1220 ix = x + (columnWidth - iconWidth)/2;
1221 x += (columnWidth - valWidth) / 2;
1222 break;
1223 case TK_JUSTIFY_LEFT:
1224 break;
1225 }
1226 }
1227
1228 switch (tbPtr->iconside) {
1229 case SIDE_RIGHT:
1230 textX = x;
1231 textY = y + (entryPtr->height - textHeight) / 2;
1232 iconX = textX + textWidth + gap;
1233 iconY = y + (entryPtr->height - iconHeight) / 2;
1234 break;
1235 case SIDE_LEFT:
1236 iconX = x;
1237 iconY = y + (entryPtr->height - iconHeight) / 2;
1238 textX = iconX + iconWidth + gap;
1239 textY = y + (entryPtr->height - textHeight) / 2;
1240 break;
1241 case SIDE_TOP:
1242 iconY = y;
1243 if (tbPtr->side == SIDE_BOTTOM) {
1244 iconY = y + (entryPtr->height - textHeight - iconHeight - gap*2);
1245 }
1246 iconX = ix;
1247 textY = iconY + iconHeight + gap;
1248 textX = x;
1249 if (iconWidth>textWidth) {
1250 textX = x + (iconWidth-textWidth)/2;
1251 }
1252 break;
1253 case SIDE_BOTTOM:
1254 textX = x;
1255 textY = y;
1256 if (tbPtr->side == SIDE_BOTTOM) {
1257 textY = y + (entryPtr->height - textHeight - iconHeight - gap*2);
1258 }
1259 if (iconWidth>textWidth) {
1260 textX = x + (iconWidth-textWidth)/2;
1261 }
1262 iconY = textY + textHeight + gap;
1263 iconX = ix;
1264 break;
1265 }
1266 valuePtr->iX = iconX;
1267 valuePtr->iY = iconY;
1268 valuePtr->iW = iconWidth;
1269 valuePtr->iH = iconHeight;
1270 valuePtr->tX = textX;
1271 valuePtr->tY = textY;
1272 valuePtr->tW = textWidth;
1273 valuePtr->tH = textHeight;
1274 if (icon != NULL) {
1275 if (Blt_TreeViewRedrawIcon(tvPtr, entryPtr, columnPtr, icon, 0, 0, iconWidth,
1276 iconHeight, drawable, iconX, iconY) != TCL_OK) return;
1277 }
1278 if (layPtr != NULL) {
1279 TextStyle ts;
1280 XColor *color;
1281 int disabled = (entryPtr->state == STATE_DISABLED);
1282
1283 if (disabled) {
1284 color = tvPtr->disabledColor;
1285 } else if (Blt_TreeViewEntryIsSelected(tvPtr, entryPtr, columnPtr)) {
1286 color = SELECT_FG(tvPtr);
1287 } else if (entryPtr->color != NULL) {
1288 color = entryPtr->color;
1289 } else {
1290 color = sRec.fgColor;
1291 GetColorPats(tvPtr, entryPtr, valuePtr, stylePtr, &color );
1292 }
1293 XSetForeground(tvPtr->display, gc, color->pixel);
1294 Blt_SetDrawTextStyle(&ts, sRec.font, gc, color, sRec.fgColor,
1295 stylePtr->shadow.color, 0.0,
1296 TK_ANCHOR_NW, columnPtr->justify, 0, stylePtr->shadow.offset);
1297 Blt_DrawTextLayout(tvPtr->tkwin, drawable, layPtr,
1298 &ts, textX, textY);
1299 if (color != sRec.fgColor) {
1300 XSetForeground(tvPtr->display, gc, sRec.fgColor->pixel);
1301 }
1302 } else {
1303 valuePtr->tW = 0;
1304 }
1305 stylePtr->flags &= ~STYLE_DIRTY;
1306 }
1307
1308 /*
1309 *----------------------------------------------------------------------
1310 *
1311 * EditTextbox --
1312 *
1313 * Edits the "textbox".
1314 *
1315 * Results:
1316 * None.
1317 *
1318 * Side Effects:
1319 * The checkbox value is drawn.
1320 *
1321 *----------------------------------------------------------------------
1322 */
1323 /*ARGSUSED*/
1324 static int
1325 EditTextBox(tvPtr, entryPtr, valuePtr, stylePtr, x, y, retVal)
1326 TreeView *tvPtr;
1327 TreeViewEntry *entryPtr;
1328 TreeViewValue *valuePtr;
1329 TreeViewStyle *stylePtr; /* Not used. */
1330 int x;
1331 int y;
1332 int *retVal;
1333 {
1334 int isTest = *retVal;
1335 *retVal = 0;
1336 if (isTest) {
1337 return TCL_OK;
1338 }
1339 return Blt_TreeViewTextbox(tvPtr, entryPtr, valuePtr->columnPtr);
1340 }
1341
1342
1343 /*
1344 *----------------------------------------------------------------------
1345 *
1346 * FreeTextBox --
1347 *
1348 * Releases resources allocated for the textbox. The resources
1349 * freed by this routine are specific only to the "textbox".
1350 * Other resources (common to all styles) are freed in the
1351 * Blt_TreeViewFreeStyle routine.
1352 *
1353 * Results:
1354 * None.
1355 *
1356 * Side Effects:
1357 * GCs allocated for the textbox are freed.
1358 *
1359 *----------------------------------------------------------------------
1360 */
1361 static void
1362 FreeTextBox(tvPtr, stylePtr)
1363 TreeView *tvPtr;
1364 TreeViewStyle *stylePtr;
1365 {
1366 if (!stylePtr) return;
1367 if (stylePtr->highlightGC != NULL) {
1368 Tk_FreeGC(tvPtr->display, stylePtr->highlightGC);
1369 }
1370 if (stylePtr->activeGC != NULL) {
1371 Tk_FreeGC(tvPtr->display, stylePtr->activeGC);
1372 }
1373 if (stylePtr->gc != NULL) {
1374 Tk_FreeGC(tvPtr->display, stylePtr->gc);
1375 }
1376 if (stylePtr->icon != NULL) {
1377 Blt_TreeViewFreeIcon(tvPtr, stylePtr->icon);
1378 }
1379
1380 }
1381
1382
1383 /*
1384 *----------------------------------------------------------------------
1385 *
1386 * CreateCheckbox --
1387 *
1388 * Creates a "checkbox" style.
1389 *
1390 * Results:
1391 * A pointer to the new style structure.
1392 *
1393 *----------------------------------------------------------------------
1394 */
1395 static TreeViewStyle *
1396 CreateCheckBox(tvPtr, hPtr)
1397 TreeView *tvPtr;
1398 Blt_HashEntry *hPtr;
1399 {
1400 TreeViewCheckBox *cbPtr;
1401
1402 cbPtr = (TreeViewCheckBox *)newStyle(tvPtr, hPtr, sizeof(TreeViewCheckBox));
1403 cbPtr->classPtr = &checkBoxClass;
1404 cbPtr->gap = 4;
1405 cbPtr->size = 11;
1406 cbPtr->lineWidth = 1;
1407 cbPtr->showValue = TRUE;
1408 cbPtr->flags = STYLE_CHECKBOX;
1409 return (TreeViewStyle *)cbPtr;
1410 }
1411
1412 /*
1413 *----------------------------------------------------------------------
1414 *
1415 * ConfigureCheckbox --
1416 *
1417 * Configures a "checkbox" style. This routine performs
1418 * generates the GCs required for a checkbox style.
1419 *
1420 * Results:
1421 * None.
1422 *
1423 * Side Effects:
1424 * GCs are created for the style.
1425 *
1426 *----------------------------------------------------------------------
1427 */
1428 static void
1429 ConfigureCheckBox(tvPtr, stylePtr)
1430 TreeView *tvPtr;
1431 TreeViewStyle *stylePtr;
1432 {
1433 GC newGC;
1434 TreeViewCheckBox *cbPtr = (TreeViewCheckBox *)stylePtr;
1435 XColor *bgColor;
1436 XGCValues gcValues;
1437 unsigned long gcMask;
1438
1439 bgColor = Tk_3DBorderColor(CHOOSE(tvPtr->border, stylePtr->border));
1440
1441 gcValues.background = bgColor->pixel;
1442 gcValues.foreground = CHOOSE(tvPtr->fgColor, stylePtr->fgColor)->pixel;
1443 ConfigureTextBox(tvPtr, stylePtr);
1444 gcMask = GCForeground;
1445 gcValues.foreground = cbPtr->fillColor->pixel;
1446 newGC = Tk_GetGC(tvPtr->tkwin, gcMask, &gcValues);
1447 if (cbPtr->fillGC != NULL) {
1448 Tk_FreeGC(tvPtr->display, cbPtr->fillGC);
1449 }
1450 cbPtr->fillGC = newGC;
1451
1452 gcMask = GCForeground | GCLineWidth;
1453 gcValues.line_width = cbPtr->lineWidth;
1454 gcValues.foreground = cbPtr->boxColor->pixel;
1455 newGC = Tk_GetGC(tvPtr->tkwin, gcMask, &gcValues);
1456 if (cbPtr->boxGC != NULL) {
1457 Tk_FreeGC(tvPtr->display, cbPtr->boxGC);
1458 }
1459 cbPtr->boxGC = newGC;
1460
1461 gcMask = GCForeground | GCLineWidth;
1462 gcValues.line_width = 1;
1463 gcValues.foreground = cbPtr->checkColor->pixel;
1464 newGC = Tk_GetGC(tvPtr->tkwin, gcMask, &gcValues);
1465 if (cbPtr->checkGC != NULL) {
1466 Tk_FreeGC(tvPtr->display, cbPtr->checkGC);
1467 }
1468 cbPtr->checkGC = newGC;
1469 if (cbPtr->checkBg) {
1470 bgColor = Tk_3DBorderColor(cbPtr->checkBg);
1471 gcValues.background = bgColor->pixel;
1472 gcValues.foreground = bgColor->pixel;
1473 newGC = Tk_GetGC(tvPtr->tkwin, gcMask, &gcValues);
1474 if (cbPtr->bgGC != NULL) {
1475 Tk_FreeGC(tvPtr->display, cbPtr->bgGC);
1476 }
1477 cbPtr->bgGC = newGC;
1478 }
1479 stylePtr->flags |= STYLE_DIRTY;
1480 }
1481
1482 /*
1483 *----------------------------------------------------------------------
1484 *
1485 * MeasureCheckbox --
1486 *
1487 * Determines the space requirements for the "checkbox" given
1488 * the value to be displayed. Depending upon whether an icon
1489 * or text is displayed and their relative placements, this
1490 * routine computes the space needed for the text entry.
1491 *
1492 * Results:
1493 * None.
1494 *
1495 * Side Effects:
1496 * The width and height fields of *valuePtr* are set with the
1497 * computed dimensions.
1498 *
1499 *----------------------------------------------------------------------
1500 */
1501 static void
1502 MeasureCheckBox(tvPtr, stylePtr, valuePtr)
1503 TreeView *tvPtr;
1504 TreeViewStyle *stylePtr;
1505 TreeViewValue *valuePtr;
1506 {
1507 TreeViewCheckBox *cbPtr = (TreeViewCheckBox *)stylePtr;
1508 TreeViewColumn *columnPtr = valuePtr->columnPtr;
1509 int iconWidth, iconHeight;
1510 int textWidth, textHeight;
1511 int gap;
1512 int boxWidth, boxHeight;
1513 TreeViewIcon icon;
1514
1515 boxWidth = boxHeight = ODD(cbPtr->size);
1516
1517 if (cbPtr->icons) {
1518 TreeViewIcon mIcon;
1519 int i;
1520
1521 for (i=0; i<2; i++) {
1522 mIcon = cbPtr->icons[i];
1523 if (mIcon) {
1524 int mwid = TreeViewIconWidth(mIcon);
1525 int mhig = TreeViewIconHeight(mIcon);
1526 if (mwid>boxWidth) { boxWidth = mwid; }
1527 if (mhig>boxHeight) { boxHeight = mhig; }
1528 }
1529 }
1530 }
1531 textWidth = textHeight = iconWidth = iconHeight = 0;
1532 valuePtr->width = valuePtr->height = 0;
1533 icon = (stylePtr->icon?stylePtr->icon:(columnPtr->stylePtr?columnPtr->stylePtr->icon:NULL));
1534 if (icon != NULL && tvPtr->hideStyleIcons == 0) {
1535 iconWidth = TreeViewIconWidth(icon);
1536 iconHeight = TreeViewIconHeight(icon);
1537 }
1538 if (cbPtr->onPtr != NULL) {
1539 Blt_Free(cbPtr->onPtr);
1540 cbPtr->onPtr = NULL;
1541 }
1542 if (cbPtr->offPtr != NULL) {
1543 Blt_Free(cbPtr->offPtr);
1544 cbPtr->offPtr = NULL;
1545 }
1546 gap = 0;
1547 if (cbPtr->showValue && tvPtr->hideStyleText == 0) {
1548 TextStyle ts;
1549 char *string;
1550
1551 Blt_InitTextStyle(&ts);
1552 ts.font = CHOOSE3(tvPtr->font, columnPtr->font, stylePtr->font);
1553 ts.anchor = TK_ANCHOR_NW;
1554 ts.justify = columnPtr->justify;
1555 string = (cbPtr->onValue != NULL) ? cbPtr->onValue : valuePtr->string;
1556 cbPtr->onPtr = Blt_GetTextLayout(string, &ts);
1557 string = (cbPtr->offValue != NULL) ? cbPtr->offValue : valuePtr->string;
1558 cbPtr->offPtr = Blt_GetTextLayout(string, &ts);
1559 textWidth = MAX(cbPtr->offPtr->width, cbPtr->onPtr->width);
1560 textHeight = MAX(cbPtr->offPtr->height, cbPtr->onPtr->height);
1561 if (stylePtr->icon != NULL) {
1562 gap = stylePtr->gap;
1563 }
1564 }
1565 valuePtr->width = stylePtr->gap * 2 + boxWidth + iconWidth + gap + textWidth;
1566 valuePtr->height = MAX3(boxHeight, textHeight, iconHeight);
1567 }
1568
1569 /*
1570 *----------------------------------------------------------------------
1571 *
1572 *
1573 box --
1574 *
1575 * Draws the "checkbox" given the screen coordinates and the
1576 * value to be displayed.
1577 *
1578 * Results:
1579 * None.
1580 *
1581 * Side Effects:
1582 * The checkbox value is drawn.
1583 *
1584 *----------------------------------------------------------------------
1585 */
1586 static void
1587 DrawCheckBox(tvPtr, drawable, entryPtr, valuePtr, stylePtr, icon, x, y)
1588 TreeView *tvPtr;
1589 Drawable drawable;
1590 TreeViewEntry *entryPtr;
1591 TreeViewValue *valuePtr;
1592 TreeViewStyle *stylePtr;
1593 TreeViewIcon icon;
1594 int x, y;
1595 {
1596 GC gc;
1597 TreeViewColumn *columnPtr;
1598 TreeViewCheckBox *cbPtr = (TreeViewCheckBox *)stylePtr;
1599 int iconX, iconY, iconWidth, iconHeight;
1600 int textX, textY, textHeight;
1601 int gap, columnWidth, ttlWidth;
1602 int bool;
1603 int borderWidth, relief;
1604 TextLayout *textPtr;
1605 int boxX, boxY, boxWidth, boxHeight;
1606 TreeViewStyle *csPtr, sRec = *stylePtr;
1607 int valWidth = (valuePtr->textPtr?valuePtr->width:(icon?TreeViewIconWidth(icon):0));
1608 TextLayout *layPtr;
1609 int showValue;
1610
1611 layPtr = (tvPtr->hideStyleText?NULL:valuePtr->textPtr);
1612 showValue = (tvPtr->hideStyleText ? 0 : cbPtr->showValue);
1613
1614 columnPtr = valuePtr->columnPtr;
1615 csPtr = columnPtr->stylePtr;
1616
1617 drawTextBox(tvPtr, drawable, entryPtr, valuePtr, stylePtr, icon, x, y, &sRec);
1618 gc = sRec.gc;
1619
1620 if (gc != stylePtr->activeGC) {
1621 borderWidth = 0;
1622 relief = TK_RELIEF_FLAT;
1623 } else {
1624 borderWidth = 1;
1625 relief = TK_RELIEF_RAISED;
1626 }
1627
1628 columnWidth = columnPtr->width - PADDING(columnPtr->pad);
1629 if (!valuePtr->string) {
1630 return;
1631 }
1632
1633 if (cbPtr->size) {
1634 boxWidth = boxHeight = ODD(cbPtr->size);
1635 } else {
1636 boxWidth = boxHeight = 0;
1637 }
1638 ttlWidth = ( boxWidth + stylePtr->gap * 2);
1639 if (showValue) {
1640 ttlWidth += (valWidth + stylePtr->gap);
1641 }
1642 if (icon != NULL) {
1643 iconWidth = TreeViewIconWidth(icon);
1644 iconHeight = TreeViewIconHeight(icon);
1645 ttlWidth += iconWidth + stylePtr->gap;
1646 }
1647
1648 if (columnWidth > ttlWidth) {
1649 switch(columnPtr->justify) {
1650 case TK_JUSTIFY_RIGHT:
1651 x += (columnWidth - ttlWidth - stylePtr->gap*2);
1652 break;
1653 case TK_JUSTIFY_CENTER:
1654 x += (columnWidth - ttlWidth) / 2;
1655 break;
1656 case TK_JUSTIFY_LEFT:
1657 break;
1658 }
1659 }
1660
1661 bool = (strcmp(valuePtr->string, cbPtr->onValue) == 0);
1662 textPtr = (bool) ? cbPtr->onPtr : cbPtr->offPtr;
1663
1664 cbPtr->boxW = cbPtr->boxH = 0;
1665 cbPtr->boxX = boxX = x + stylePtr->gap;
1666 boxY = y + (entryPtr->height - boxHeight) / 2;
1667
1668 if (cbPtr->icons != NULL) {
1669 TreeViewIcon mIcon;
1670 mIcon = cbPtr->icons[bool];
1671 if (mIcon) {
1672 int mwid = TreeViewIconWidth(mIcon);
1673 int mhig = TreeViewIconHeight(mIcon);
1674 cbPtr->boxW = mwid;
1675 cbPtr->boxH = mhig;
1676 boxY = y + (entryPtr->height - mhig) / 2;
1677 if (Blt_TreeViewRedrawIcon(tvPtr, entryPtr, columnPtr, mIcon, 0, 0, mwid,
1678 mhig, drawable, boxX, boxY) != TCL_OK) return;
1679 }
1680
1681 } else {
1682 /*
1683 * Draw the box and check.
1684 *
1685 * +-----------+
1686 * | |
1687 * | * |
1688 * | * |
1689 * | * * |
1690 * | * * |
1691 * | * * |
1692 * | * |
1693 * +-----------+
1694 */
1695 if (boxWidth) {
1696 if (cbPtr->checkBg) {
1697 XFillRectangle(tvPtr->display, drawable, cbPtr->bgGC, boxX, boxY,
1698 boxWidth, boxHeight);
1699 } else {
1700 if (Blt_HasTile(stylePtr->fillTile)) {
1701 Blt_SetTileOrigin(tvPtr->tkwin, stylePtr->fillTile, -boxX, -boxY);
1702 Blt_TileRectangle(tvPtr->tkwin, drawable, stylePtr->fillTile,
1703 boxX, boxY, boxWidth, boxHeight );
1704 } else if (csPtr != NULL && Blt_HasTile(csPtr->fillTile)) {
1705 Blt_SetTileOrigin(tvPtr->tkwin, csPtr->fillTile, -boxX, -boxY);
1706 Blt_TileRectangle(tvPtr->tkwin, drawable, csPtr->fillTile,
1707 boxX, boxY, boxWidth, boxHeight );
1708 } else {
1709 XFillRectangle(tvPtr->display, drawable, cbPtr->fillGC, boxX, boxY, boxWidth, boxHeight);
1710
1711 }
1712 }
1713 cbPtr->boxW = boxWidth;
1714 cbPtr->boxH = boxHeight;
1715 XDrawRectangle(tvPtr->display, drawable, cbPtr->boxGC, boxX, boxY,
1716 boxWidth, boxHeight);
1717
1718 if (bool) {
1719 int midX, midY;
1720 int i;
1721
1722 for (i = 0; i < 3; i++) {
1723 midX = boxX + 2 * boxWidth / 5;
1724 midY = boxY + boxHeight - 5 + i;
1725 XDrawLine(tvPtr->display, drawable, cbPtr->checkGC,
1726 boxX + 2, boxY + boxHeight / 3 + 1 + i, midX, midY);
1727 XDrawLine(tvPtr->display, drawable, cbPtr->checkGC,
1728 midX, midY, boxX + boxWidth - 2, boxY + i + 1);
1729 }
1730 }
1731 }
1732 }
1733 #ifdef notdef
1734 textX = textY = iconX = iconY = 0; /* Suppress compiler warning. */
1735 #endif
1736 iconWidth = iconHeight = 0;
1737 if (icon != NULL) {
1738 iconWidth = TreeViewIconWidth(icon);
1739 iconHeight = TreeViewIconHeight(icon);
1740 }
1741 textHeight = 0;
1742 gap = 0;
1743 if (showValue) {
1744 textHeight = textPtr->height;
1745 if (icon != NULL) {
1746 gap = stylePtr->gap;
1747 }
1748 }
1749 x = boxX + boxWidth + stylePtr->gap;
1750
1751 /* The icon sits to the left of the text. */
1752 iconX = x;
1753 iconY = y + (entryPtr->height - iconHeight) / 2;
1754 textX = iconX + iconWidth + gap;
1755 textY = y + (entryPtr->height - textHeight) / 2;
1756
1757 valuePtr->iX = iconX;
1758 valuePtr->iY = iconY;
1759 valuePtr->iW = iconWidth;
1760 valuePtr->iH = iconHeight;
1761 valuePtr->tX = textX;
1762 valuePtr->tY = textY;
1763 valuePtr->tW = (textPtr?textPtr->width:0);
1764 valuePtr->tH = textHeight;
1765
1766 if (icon != NULL) {
1767 if (Blt_TreeViewRedrawIcon(tvPtr, entryPtr, columnPtr, icon, 0, 0, iconWidth,
1768 iconHeight, drawable, iconX, iconY) != TCL_OK) return;
1769 } else {
1770 valuePtr->iW = 0;
1771 }
1772 if ((showValue) && (textPtr != NULL)) {
1773 TextStyle ts;
1774 XColor *color;
1775
1776 int disabled = (entryPtr->state == STATE_DISABLED);
1777
1778 if (disabled) {
1779 color = tvPtr->disabledColor;
1780 } else if (Blt_TreeViewEntryIsSelected(tvPtr, entryPtr, columnPtr)) {
1781 color = SELECT_FG(tvPtr);
1782 } else if (entryPtr->color != NULL) {
1783 color = entryPtr->color;
1784 } else {
1785 color = sRec.fgColor;
1786 GetColorPats(tvPtr, entryPtr, valuePtr, stylePtr, &color );
1787 }
1788 XSetForeground(tvPtr->display, gc, color->pixel);
1789 Blt_SetDrawTextStyle(&ts, sRec.font, gc, color, sRec.fgColor,
1790 stylePtr->shadow.color, 0.0,
1791 TK_ANCHOR_NW, columnPtr->justify, 0, stylePtr->shadow.offset);
1792 Blt_DrawTextLayout(tvPtr->tkwin, drawable, textPtr, &ts, textX, textY);
1793 if (color != sRec.fgColor) {
1794 XSetForeground(tvPtr->display, gc, sRec.fgColor->pixel);
1795 }
1796 } else {
1797 valuePtr->tW = 0;
1798 }
1799 stylePtr->flags &= ~STYLE_DIRTY;
1800 }
1801
1802 #if 0
1803 /*
1804 *----------------------------------------------------------------------
1805 *
1806 * PickCheckbox --
1807 *
1808 * Draws the "checkbox" given the screen coordinates and the
1809 * value to be displayed.
1810 *
1811 * Results:
1812 * None.
1813 *
1814 * Side Effects:
1815 * The checkbox value is drawn.
1816 *
1817 *----------------------------------------------------------------------
1818 */
1819 static int
1820 PickCheckBox(entryPtr, valuePtr, stylePtr, worldX, worldY)
1821 TreeViewEntry *entryPtr;
1822 TreeViewValue *valuePtr;
1823 TreeViewStyle *stylePtr;
1824 int worldX, worldY;
1825 {
1826 TreeViewColumn *columnPtr;
1827 TreeViewCheckBox *cbPtr = (TreeViewCheckBox *)stylePtr;
1828 int columnWidth;
1829 int x, y, width, height;
1830
1831 columnPtr = valuePtr->columnPtr;
1832 columnWidth = columnPtr->width -
1833 (2 * columnPtr->borderWidth + PADDING(columnPtr->pad));
1834 if (columnWidth > valuePtr->width) {
1835 switch(columnPtr->justify) {
1836 case TK_JUSTIFY_RIGHT:
1837 worldX += (columnWidth - valuePtr->width);
1838 break;
1839 case TK_JUSTIFY_CENTER:
1840 worldX += (columnWidth - valuePtr->width) / 2;
1841 break;
1842 case TK_JUSTIFY_LEFT:
1843 break;
1844 }
1845 }
1846 width = height = ODD(cbPtr->size) + 2 * cbPtr->lineWidth;
1847 x = columnPtr->worldX + columnPtr->pad.side1 + stylePtr->gap -
1848 cbPtr->lineWidth;
1849 y = entryPtr->worldY + (entryPtr->height - height) / 2;
1850 if ((worldX >= x) && (worldX < (x + width)) &&
1851 (worldY >= y) && (worldY < (y + height))) {
1852 return TRUE;
1853 }
1854 return FALSE;
1855 }
1856 #endif
1857 /*
1858 *----------------------------------------------------------------------
1859 *
1860 * EditCheckbox --
1861 *
1862 * Edits the "checkbox".
1863 *
1864 * Results:
1865 * None.
1866 *
1867 * Side Effects:
1868 * The checkbox value is drawn.
1869 *
1870 *----------------------------------------------------------------------
1871 */
1872 static int
1873 EditCheckBox(tvPtr, entryPtr, valuePtr, stylePtr, x, y, retVal)
1874 TreeView *tvPtr;
1875 TreeViewEntry *entryPtr;
1876 TreeViewValue *valuePtr;
1877 TreeViewStyle *stylePtr;
1878 int x;
1879 int y;
1880 int *retVal;
1881 {
1882 TreeViewColumn *columnPtr;
1883 TreeViewCheckBox *cbPtr = (TreeViewCheckBox *)stylePtr;
1884 Tcl_Obj *objPtr;
1885 int boxY, isTest = *retVal;
1886 TreeViewStyle *vsPtr;
1887
1888 *retVal = 1;
1889 columnPtr = valuePtr->columnPtr;
1890 if (Blt_TreeGetValueByKey(tvPtr->interp, tvPtr->tree,
1891 entryPtr->node, columnPtr->key, &objPtr) != TCL_OK) {
1892 return TCL_ERROR;
1893 }
1894 vsPtr = valuePtr->stylePtr;
1895 if (vsPtr && vsPtr->noteditable) {
1896 *retVal = 0;
1897 return TCL_OK;
1898 }
1899 boxY = SCREENY(tvPtr, entryPtr->worldY) + (entryPtr->height -cbPtr->boxH) / 2;
1900 if (cbPtr->halo>=0) {
1901 int h = cbPtr->halo;
1902
1903 if (x < (cbPtr->boxX - h) || x > (cbPtr->boxX + cbPtr->boxW + h) ||
1904 y < (boxY - h) || y > (boxY + cbPtr->boxH + h)) {
1905 *retVal = 0;
1906 return TCL_OK;
1907 }
1908 }
1909 if (isTest) {
1910 return TCL_OK;
1911 }
1912 if (strcmp(Tcl_GetString(objPtr), cbPtr->onValue) == 0) {
1913 objPtr = Tcl_NewStringObj(cbPtr->offValue, -1);
1914 } else {
1915 objPtr = Tcl_NewStringObj(cbPtr->onValue, -1);
1916 }
1917 entryPtr->flags |= ENTRY_DIRTY;
1918 tvPtr->flags |= (TV_DIRTY | TV_LAYOUT | TV_SCROLL | TV_RESORT);
1919 if (Blt_TreeSetValueByKey(tvPtr->interp, tvPtr->tree,
1920 entryPtr->node, columnPtr->key, objPtr) != TCL_OK) {
1921 return TCL_ERROR;
1922 }
1923 return TCL_OK;
1924 }
1925
1926 /*
1927 *----------------------------------------------------------------------
1928 *
1929 * FreeCheckbox --
1930 *
1931 * Releases resources allocated for the checkbox. The resources
1932 * freed by this routine are specific only to the "checkbox".
1933 * Other resources (common to all styles) are freed in the
1934 * Blt_TreeViewFreeStyle routine.
1935 *
1936 * Results:
1937 * None.
1938 *
1939 * Side Effects:
1940 * GCs allocated for the checkbox are freed.
1941 *
1942 *----------------------------------------------------------------------
1943 */
1944 static void
1945 FreeCheckBox(tvPtr, stylePtr)
1946 TreeView *tvPtr;
1947 TreeViewStyle *stylePtr;
1948 {
1949 TreeViewCheckBox *cbPtr = (TreeViewCheckBox *)stylePtr;
1950
1951 FreeTextBox(tvPtr, stylePtr);
1952 if (cbPtr->fillGC != NULL) {
1953 Tk_FreeGC(tvPtr->display, cbPtr->fillGC);
1954 }
1955 if (cbPtr->boxGC != NULL) {
1956 Tk_FreeGC(tvPtr->display, cbPtr->boxGC);
1957 }
1958 if (cbPtr->checkGC != NULL) {
1959 Tk_FreeGC(tvPtr->display, cbPtr->checkGC);
1960 }
1961 if (cbPtr->offPtr != NULL) {
1962 Blt_Free(cbPtr->offPtr);
1963 }
1964 if (cbPtr->onPtr != NULL) {
1965 Blt_Free(cbPtr->onPtr);
1966 }
1967 if (cbPtr->bgGC != NULL) {
1968 Tk_FreeGC(tvPtr->display, cbPtr->bgGC);
1969 }
1970 }
1971
1972 /*
1973 *----------------------------------------------------------------------
1974 *
1975 * CreateComboBox --
1976 *
1977 * Creates a "combobox" style.
1978 *
1979 * Results:
1980 * A pointer to the new style structure.
1981 *
1982 *----------------------------------------------------------------------
1983 */
1984 static TreeViewStyle *
1985 CreateComboBox(tvPtr, hPtr)
1986 TreeView *tvPtr;
1987 Blt_HashEntry *hPtr;
1988 {
1989 TreeViewComboBox *cbPtr;
1990
1991 cbPtr = (TreeViewComboBox *)newStyle(tvPtr, hPtr, sizeof(TreeViewComboBox));
1992 cbPtr->classPtr = &comboBoxClass;
1993 cbPtr->buttonRelief = TK_RELIEF_RAISED;
1994 cbPtr->buttonBorderWidth = 1;
1995 cbPtr->borderWidth = 1;
1996 cbPtr->flags = STYLE_COMBOBOX;
1997 return (TreeViewStyle *)cbPtr;
1998 }
1999
2000 /*
2001 *----------------------------------------------------------------------
2002 *
2003 * ConfigureComboBox --
2004 *
2005 * Configures a "combobox" style. This routine performs
2006 * generates the GCs required for a combobox style.
2007 *
2008 * Results:
2009 * None.
2010 *
2011 * Side Effects:
2012 * GCs are created for the style.
2013 *
2014 *----------------------------------------------------------------------
2015 */
2016 static void
2017 ConfigureComboBox(tvPtr, stylePtr)
2018 TreeView *tvPtr;
2019 TreeViewStyle *stylePtr;
2020 {
2021 ConfigureTextBox(tvPtr, stylePtr);
2022 }
2023
2024 /*
2025 *----------------------------------------------------------------------
2026 *
2027 * MeasureComboBox --
2028 *
2029 * Determines the space requirements for the "combobox" given
2030 * the value to be displayed. Depending upon whether an icon
2031 * or text is displayed and their relative placements, this
2032 * routine computes the space needed for the text entry.
2033 *
2034 * Results:
2035 * None.
2036 *
2037 * Side Effects:
2038 * The width and height fields of *valuePtr* are set with the
2039 * computed dimensions.
2040 *
2041 *----------------------------------------------------------------------
2042 */
2043 static void
2044 MeasureComboBox(tvPtr, stylePtr, valuePtr)
2045 TreeView *tvPtr;
2046 TreeViewStyle *stylePtr;
2047 TreeViewValue *valuePtr;
2048 {
2049 TreeViewComboBox *cbPtr = (TreeViewComboBox *)stylePtr;
2050 TreeViewColumn *columnPtr = valuePtr->columnPtr;
2051 int iconWidth, iconHeight, biconWidth, biconHeight;
2052 int textWidth, textHeight;
2053 int gap;
2054 Tk_Font font;
2055 TreeViewIcon icon, *butIcons;
2056
2057 textWidth = textHeight = 0;
2058 iconWidth = iconHeight = 0;
2059 valuePtr->width = valuePtr->height = 0;
2060
2061 butIcons = cbPtr->buttonIcons;
2062 icon = (stylePtr->icon?stylePtr->icon:(columnPtr->stylePtr?columnPtr->stylePtr->icon:NULL));
2063 if (icon != NULL && tvPtr->hideStyleIcons == 0) {
2064 iconWidth = TreeViewIconWidth(icon);
2065 iconHeight = TreeViewIconHeight(icon);
2066 }
2067 if (valuePtr->textPtr != NULL) {
2068 Blt_Free(valuePtr->textPtr);
2069 valuePtr->textPtr = NULL;
2070 }
2071 font = CHOOSE3(tvPtr->font, columnPtr->font, stylePtr->font);
2072 if (valuePtr->string != NULL) { /* New string defined. */
2073 TextStyle ts;
2074
2075 Blt_InitTextStyle(&ts);
2076 ts.font = font;
2077 ts.anchor = TK_ANCHOR_NW;
2078 ts.justify = valuePtr->columnPtr->justify;
2079 valuePtr->textPtr = Blt_GetTextLayoutStr(valuePtr->string, &ts);
2080 }
2081 gap = 0;
2082 if (valuePtr->textPtr != NULL && tvPtr->hideStyleText == 0) {
2083 textWidth = valuePtr->textPtr->width;
2084 textHeight = valuePtr->textPtr->height;
2085 if (stylePtr->icon != NULL) {
2086 gap = stylePtr->gap;
2087 }
2088 }
2089 if (butIcons != NULL) {
2090 TreeViewIcon mIcon;
2091 int i;
2092
2093 biconWidth = 0;
2094 biconHeight = 0;
2095 for (i=0; i<2; i++) {
2096 mIcon = butIcons[i];
2097 if (!mIcon) continue;
2098 biconWidth = MAX(biconWidth,TreeViewIconWidth(mIcon));
2099 biconHeight = MAX(biconHeight,TreeViewIconHeight(mIcon));
2100 }
2101 biconHeight = MAX(iconHeight,biconHeight);
2102 } else {
2103 biconWidth = STD_ARROW_WIDTH + 6;
2104 biconHeight = iconHeight;
2105 }
2106 cbPtr->buttonWidth = biconWidth + 2 * cbPtr->buttonBorderWidth;
2107 valuePtr->width = 2 * cbPtr->borderWidth + iconWidth + 4 * gap +
2108 cbPtr->buttonWidth + textWidth;
2109 valuePtr->height = MAX(textHeight, biconHeight) + 2 * cbPtr->borderWidth;
2110 }
2111
2112 /*
2113 *----------------------------------------------------------------------
2114 *
2115 * DrawComboBox --
2116 *
2117 * Draws the "combobox" given the screen coordinates and the
2118 * value to be displayed.
2119 *
2120 * Results:
2121 * None.
2122 *
2123 * Side Effects:
2124 * The combobox value is drawn.
2125 *
2126 *----------------------------------------------------------------------
2127 */
2128 static void
2129 DrawComboBox(tvPtr, drawable, entryPtr, valuePtr, stylePtr, icon, x, y)
2130 TreeView *tvPtr;
2131 Drawable drawable;
2132 TreeViewEntry *entryPtr;
2133 TreeViewValue *valuePtr;
2134 TreeViewStyle *stylePtr;
2135 TreeViewIcon icon;
2136 int x, y;
2137 {
2138 GC gc;
2139 TreeViewColumn *columnPtr;
2140 TreeViewComboBox *cbPtr = (TreeViewComboBox *)stylePtr;
2141 int iconX, iconY, iconWidth, iconHeight;
2142 int textX, textY, textHeight;
2143 int buttonX, buttonY;
2144 int gap, columnWidth;
2145 TreeViewStyle sRec;
2146 int valWidth = (valuePtr->textPtr?valuePtr->width:(icon?TreeViewIconWidth(icon):0));
2147 TextLayout *layPtr;
2148
2149 layPtr = (tvPtr->hideStyleText?NULL:valuePtr->textPtr);
2150
2151 columnPtr = valuePtr->columnPtr;
2152 drawTextBox(tvPtr, drawable, entryPtr, valuePtr, stylePtr, icon, x, y, &sRec);
2153 gc = sRec.gc;
2154
2155 if (!valuePtr->string) {
2156 return;
2157 }
2158 buttonX = x + columnPtr->width;
2159 buttonX -= columnPtr->pad.side2 + cbPtr->borderWidth +
2160 cbPtr->buttonWidth + stylePtr->gap;
2161 buttonY = y;
2162
2163 columnWidth = columnPtr->width -
2164 (2 * columnPtr->borderWidth + PADDING(columnPtr->pad));
2165 if (columnWidth > valWidth) {
2166 switch(columnPtr->justify) {
2167 case TK_JUSTIFY_RIGHT:
2168 x += (columnWidth - valWidth);
2169 break;
2170 case TK_JUSTIFY_CENTER:
2171 x += (columnWidth - valWidth) / 2;
2172 break;
2173 case TK_JUSTIFY_LEFT:
2174 break;
2175 }
2176 }
2177
2178 #ifdef notdef
2179 textX = textY = iconX = iconY = 0; /* Suppress compiler warning. */
2180 #endif
2181
2182 iconWidth = iconHeight = 0;
2183 if (icon != NULL) {
2184 iconWidth = TreeViewIconWidth(icon);
2185 iconHeight = TreeViewIconHeight(icon);
2186 }
2187 textHeight = 0;
2188 if (layPtr != NULL) {
2189 textHeight = layPtr->height;
2190 }
2191 gap = 0;
2192 if ((icon != NULL) && (layPtr != NULL)) {
2193 gap = stylePtr->gap;
2194 }
2195
2196 iconX = x + gap;
2197 iconY = y + (entryPtr->height - iconHeight) / 2;
2198 textX = iconX + iconWidth + gap;
2199 textY = y + (entryPtr->height - textHeight) / 2;
2200
2201 valuePtr->iX = iconX;
2202 valuePtr->iY = iconY;
2203 valuePtr->iW = iconWidth;
2204 valuePtr->iH = iconHeight;
2205 valuePtr->tX = textX;
2206 valuePtr->tY = textY;
2207 valuePtr->tW = valuePtr->textPtr->width;
2208 valuePtr->tH = textHeight;
2209 if (icon != NULL) {
2210 if (Blt_TreeViewRedrawIcon(tvPtr, entryPtr, columnPtr, icon, 0, 0, iconWidth,
2211 iconHeight, drawable, iconX, iconY) != TCL_OK) return;
2212 } else {
2213 valuePtr->iW = 0;
2214 }
2215 if (layPtr != NULL) {
2216 TextStyle ts;
2217 XColor *color;
2218
2219 int disabled = (entryPtr->state == STATE_DISABLED);
2220
2221 if (disabled) {
2222 color = tvPtr->disabledColor;
2223 } else if (Blt_TreeViewEntryIsSelected(tvPtr, entryPtr, columnPtr)) {
2224 color = SELECT_FG(tvPtr);
2225 } else if (entryPtr->color != NULL) {
2226 color = entryPtr->color;
2227 } else {
2228 color = sRec.fgColor;
2229 GetColorPats(tvPtr, entryPtr, valuePtr, stylePtr, &color );
2230 }
2231 XSetForeground(tvPtr->display, gc, color->pixel);
2232 Blt_SetDrawTextStyle(&ts, sRec.font, gc, color, sRec.fgColor,
2233 stylePtr->shadow.color, 0.0,
2234 TK_ANCHOR_NW, columnPtr->justify, 0, stylePtr->shadow.offset);
2235 Blt_DrawTextLayout(tvPtr->tkwin, drawable, valuePtr->textPtr,
2236 &ts, textX, textY);
2237 if (color != sRec.fgColor) {
2238 XSetForeground(tvPtr->display, gc, sRec.fgColor->pixel);
2239 }
2240 } else {
2241 valuePtr->tW = 0;
2242 }
2243 if (cbPtr->buttonIcons == NULL) {
2244 if (valuePtr == tvPtr->activeValuePtr) {
2245 Blt_Fill3DRectangle(tvPtr->tkwin, drawable, stylePtr->activeBorder,
2246 buttonX, buttonY + cbPtr->borderWidth, cbPtr->buttonWidth,
2247 entryPtr->height - 2 * cbPtr->borderWidth,
2248 cbPtr->buttonBorderWidth, cbPtr->buttonRelief);
2249 } else {
2250 Blt_Fill3DRectangle(tvPtr->tkwin, drawable, columnPtr->titleBorder,
2251 buttonX, buttonY + cbPtr->borderWidth, cbPtr->buttonWidth,
2252 entryPtr->height - 2 * cbPtr->borderWidth,
2253 cbPtr->buttonBorderWidth, cbPtr->buttonRelief);
2254 }
2255 buttonX += cbPtr->buttonWidth / 2;
2256 buttonY += entryPtr->height / 2;
2257 Blt_DrawArrow(tvPtr->display, drawable, gc, buttonX, buttonY,
2258 STD_ARROW_HEIGHT, ARROW_DOWN);
2259 stylePtr->flags &= ~STYLE_DIRTY;
2260 } else {
2261 TreeViewIcon butIcon;
2262 int biconWidth;
2263 int biconHeight;
2264 if (valuePtr == tvPtr->activeValuePtr && cbPtr->buttonIcons[1]) {
2265 butIcon = cbPtr->buttonIcons[1];
2266 } else {
2267 butIcon = cbPtr->buttonIcons[0];
2268 }
2269 biconWidth = TreeViewIconWidth(butIcon);
2270 biconHeight = MAX(iconHeight,TreeViewIconHeight(butIcon));
2271
2272 buttonY += (entryPtr->height-biconHeight)/2;
2273 Blt_TreeViewRedrawIcon(tvPtr, entryPtr, columnPtr, butIcon, 0, 0, biconWidth,
2274 biconHeight, drawable, buttonX, buttonY);
2275 }
2276 }
2277
2278 /*
2279 *----------------------------------------------------------------------
2280 *
2281 * PickCombobox --
2282 *
2283 * Draws the "checkbox" given the screen coordinates and the
2284 * value to be displayed.
2285 *
2286 * Results:
2287 * None.
2288 *
2289 * Side Effects:
2290 * The checkbox value is drawn.
2291 *
2292 *----------------------------------------------------------------------
2293 */
2294 static int
2295 PickComboBox(entryPtr, valuePtr, stylePtr, worldX, worldY)
2296 TreeViewEntry *entryPtr;
2297 TreeViewValue *valuePtr;
2298 TreeViewStyle *stylePtr;
2299 int worldX, worldY;
2300 {
2301 TreeViewColumn *columnPtr;
2302 TreeViewComboBox *cbPtr = (TreeViewComboBox *)stylePtr;
2303 int x, y, width, height;
2304
2305 columnPtr = valuePtr->columnPtr;
2306 width = cbPtr->buttonWidth;
2307 height = entryPtr->height - 4;
2308 x = columnPtr->worldX + columnPtr->width - columnPtr->pad.side2 -
2309 cbPtr->borderWidth - columnPtr->borderWidth - width;
2310 y = entryPtr->worldY + cbPtr->borderWidth;
2311 if ((worldX >= x) && (worldX < (x + width)) &&
2312 (worldY >= y) && (worldY < (y + height))) {
2313 return TRUE;
2314 }
2315 return FALSE;
2316 }
2317
2318 /*
2319 *----------------------------------------------------------------------
2320 *
2321 * EditCombobox --
2322 *
2323 * Edits the "combobox".
2324 *
2325 * Results:
2326 * None.
2327 *
2328 * Side Effects:
2329 * The checkbox value is drawn.
2330 *
2331 *----------------------------------------------------------------------
2332 */
2333 /*ARGSUSED*/
2334 static int
2335 EditComboBox(tvPtr, entryPtr, valuePtr, stylePtr, x, y, retVal)
2336 TreeView *tvPtr;
2337 TreeViewEntry *entryPtr;
2338 TreeViewValue *valuePtr;
2339 TreeViewStyle *stylePtr; /* Not used. */
2340 int x;
2341 int y;
2342 int *retVal;
2343 {
2344 int isTest = *retVal;
2345 *retVal = 1;
2346 if (isTest) {
2347 return TCL_OK;
2348 }
2349 return Blt_TreeViewTextbox(tvPtr, entryPtr, valuePtr->columnPtr);
2350 }
2351
2352 /*
2353 *----------------------------------------------------------------------
2354 *
2355 * FreeComboBox --
2356 *
2357 * Releases resources allocated for the combobox. The resources
2358 * freed by this routine are specific only to the "combobox".
2359 * Other resources (common to all styles) are freed in the
2360 * Blt_TreeViewFreeStyle routine.
2361 *
2362 * Results:
2363 * None.
2364 *
2365 * Side Effects:
2366 * GCs allocated for the combobox are freed.
2367 *
2368 *----------------------------------------------------------------------
2369 */
2370 static void
2371 FreeComboBox(tvPtr, stylePtr)
2372 TreeView *tvPtr;
2373 TreeViewStyle *stylePtr;
2374 {
2375 FreeTextBox(tvPtr, stylePtr);
2376 }
2377
2378 /*
2379 *----------------------------------------------------------------------
2380 *
2381 * CreateBarbox --
2382 *
2383 * Creates a "checkbox" style.
2384 *
2385 * Results:
2386 * A pointer to the new style structure.
2387 *
2388 *----------------------------------------------------------------------
2389 */
2390 static TreeViewStyle *
2391 CreateBarBox(tvPtr, hPtr)
2392 TreeView *tvPtr;
2393 Blt_HashEntry *hPtr;
2394 {
2395 TreeViewBarBox *cbPtr;
2396
2397 cbPtr = (TreeViewBarBox *)newStyle(tvPtr, hPtr, sizeof(TreeViewBarBox));
2398 cbPtr->classPtr = &barBoxClass;
2399 cbPtr->gap = 4;
2400 cbPtr->lineWidth = 1;
2401 cbPtr->showValue = TRUE;
2402 cbPtr->flags = STYLE_BARBOX;
2403 return (TreeViewStyle *)cbPtr;
2404 }
2405
2406 /*
2407 *----------------------------------------------------------------------
2408 *
2409 * ConfigureBarbox --
2410 *
2411 * Configures a "checkbox" style. This routine performs
2412 * generates the GCs required for a checkbox style.
2413 *
2414 * Results:
2415 * None.
2416 *
2417 * Side Effects:
2418 * GCs are created for the style.
2419 *
2420 *----------------------------------------------------------------------
2421 */
2422 static void
2423 ConfigureBarBox(tvPtr, stylePtr)
2424 TreeView *tvPtr;
2425 TreeViewStyle *stylePtr;
2426 {
2427 GC newGC;
2428 TreeViewBarBox *cbPtr = (TreeViewBarBox *)stylePtr;
2429 XColor *bgColor;
2430 XGCValues gcValues;
2431 unsigned long gcMask;
2432
2433 bgColor = Tk_3DBorderColor(CHOOSE(tvPtr->border, stylePtr->border));
2434
2435 gcValues.background = bgColor->pixel;
2436 gcValues.foreground = CHOOSE(tvPtr->fgColor, stylePtr->fgColor)->pixel;
2437 ConfigureTextBox(tvPtr, stylePtr);
2438 gcMask = GCForeground;
2439 gcValues.foreground = cbPtr->fillColor->pixel;
2440 newGC = Tk_GetGC(tvPtr->tkwin, gcMask, &gcValues);
2441 if (cbPtr->fillGC != NULL) {
2442 Tk_FreeGC(tvPtr->display, cbPtr->fillGC);
2443 }
2444 cbPtr->fillGC = newGC;
2445
2446 gcMask = GCForeground | GCLineWidth;
2447 gcValues.line_width = cbPtr->lineWidth;
2448 gcValues.foreground = cbPtr->boxColor->pixel;
2449 newGC = Tk_GetGC(tvPtr->tkwin, gcMask, &gcValues);
2450 if (cbPtr->boxGC != NULL) {
2451 Tk_FreeGC(tvPtr->display, cbPtr->boxGC);
2452 }
2453 cbPtr->boxGC = newGC;
2454 if (cbPtr->barBg) {
2455 bgColor = Tk_3DBorderColor(cbPtr->barBg);
2456 gcValues.background = bgColor->pixel;
2457 gcValues.foreground = bgColor->pixel;
2458 newGC = Tk_GetGC(tvPtr->tkwin, gcMask, &gcValues);
2459 if (cbPtr->bgGC != NULL) {
2460 Tk_FreeGC(tvPtr->display, cbPtr->bgGC);
2461 }
2462 cbPtr->bgGC = newGC;
2463 }
2464 stylePtr->flags |= STYLE_DIRTY;
2465 }
2466
2467 /*
2468 *----------------------------------------------------------------------
2469 *
2470 * MeasureBarbox --
2471 *
2472 * Determines the space requirements for the "barbox" given
2473 * the value to be displayed. Depending upon whether an icon
2474 * or text is displayed and their relative placements, this
2475 * routine computes the space needed for the text entry.
2476 *
2477 * Results:
2478 * None.
2479 *
2480 * Side Effects:
2481 * The width and height fields of *valuePtr* are set with the
2482 * computed dimensions.
2483 *
2484 *----------------------------------------------------------------------
2485 */
2486 static void
2487 MeasureBarBox(tvPtr, stylePtr, valuePtr)
2488 TreeView *tvPtr;
2489 TreeViewStyle *stylePtr;
2490 TreeViewValue *valuePtr;
2491 {
2492 TreeViewBarBox *cbPtr = (TreeViewBarBox *)stylePtr;
2493 TreeViewColumn *columnPtr = valuePtr->columnPtr;
2494 TreeViewEntry *entryPtr;
2495 int iconWidth, iconHeight;
2496 int textWidth, textHeight;
2497 int gap, bGap;
2498 int boxWidth, boxHeight;
2499 TreeViewIcon icon;
2500 int rel = 0;
2501
2502 entryPtr = valuePtr->entryPtr;
2503 bGap = stylePtr->gap;
2504 if (cbPtr->barWidth <= 0) {
2505 boxWidth = 0;
2506 bGap = 0;
2507 } else if (cbPtr->barWidth >= 4000) {
2508 boxWidth = 4000;
2509 } else {
2510 boxWidth = ODD(cbPtr->barWidth);
2511 }
2512 if (cbPtr->barHeight <= 0) {
2513 boxHeight = 0;
2514 } else if (cbPtr->barHeight >= 4000) {
2515 boxHeight = 4000;
2516 } else {
2517 boxHeight = ODD(cbPtr->barHeight);
2518 }
2519
2520 textWidth = textHeight = iconWidth = iconHeight = 0;
2521 valuePtr->width = valuePtr->height = 0;
2522 icon = (stylePtr->icon?stylePtr->icon:(columnPtr->stylePtr?columnPtr->stylePtr->icon:NULL));
2523 if (icon != NULL && tvPtr->hideStyleIcons == 0) {
2524 iconWidth = TreeViewIconWidth(icon);
2525 iconHeight = TreeViewIconHeight(icon);
2526 }
2527 /* TODO: recalc over/under only on change.*/
2528 gap = 0;
2529 if (cbPtr->showValue) {
2530
2531 if (valuePtr->textPtr != NULL) {
2532 Blt_Free(valuePtr->textPtr);
2533 valuePtr->textPtr = NULL;
2534 }
2535 if (valuePtr->string != NULL) {
2536 /* New string defined. */
2537 TextStyle ts;
2538 Tcl_Obj *fmtObj;
2539
2540 fmtObj = NotNullObj(cbPtr->formatCmd);
2541 if (fmtObj == NULL) {
2542 fmtObj = NotNullObj(columnPtr->formatCmd);
2543 }
2544 if (fmtObj == NULL) {
2545 fmtObj = NotNullObj(tvPtr->formatCmd);
2546 }
2547
2548 Blt_InitTextStyle(&ts);
2549 ts.font = CHOOSE3(tvPtr->font, columnPtr->font, stylePtr->font);
2550 ts.anchor = TK_ANCHOR_NW;
2551 ts.justify = valuePtr->columnPtr->justify;
2552 if (fmtObj) {
2553 Tcl_DString cmdString;
2554 char *string;
2555 int result;
2556 Tcl_Interp *interp = tvPtr->interp;
2557
2558 Tcl_Preserve(entryPtr);
2559 rel = 1;
2560 Blt_TreeViewPercentSubst(tvPtr, valuePtr->entryPtr, valuePtr->columnPtr, Tcl_GetString(fmtObj), valuePtr->string, &cmdString);
2561 result = Tcl_GlobalEval(interp, Tcl_DStringValue(&cmdString));
2562 if ((entryPtr->flags & ENTRY_DELETED) || (tvPtr->flags & TV_DELETED)) {
2563 Tcl_Release(entryPtr);
2564 return;
2565 }
2566
2567 Blt_TreeViewOptsInit(tvPtr);
2568 Tcl_DStringFree(&cmdString);
2569 if (result == TCL_OK) {
2570 string = Tcl_GetStringResult(interp);
2571 valuePtr->textPtr = Blt_GetTextLayoutStr(string, &ts);
2572 }
2573 }
2574 if (valuePtr->textPtr == NULL) {
2575 valuePtr->textPtr = Blt_GetTextLayoutStr(valuePtr->string, &ts);
2576 }
2577 }
2578 if (valuePtr->textPtr != NULL && tvPtr->hideStyleText == 0) {
2579 textWidth = valuePtr->textPtr->width;
2580 textHeight = valuePtr->textPtr->height;
2581 if (stylePtr->icon != NULL) {
2582 gap = stylePtr->gap;
2583 }
2584 }
2585
2586 if (stylePtr->icon != NULL) {
2587 gap = stylePtr->gap;
2588 }
2589 }
2590 valuePtr->width = stylePtr->gap + bGap + boxWidth + iconWidth + gap + textWidth + 2;
2591 valuePtr->height = MAX3(boxHeight, textHeight, iconHeight);
2592 if (rel) Tcl_Release(entryPtr);
2593 }
2594
2595 /*
2596 *----------------------------------------------------------------------
2597 *
2598 * DrawBarbox --
2599 *
2600 * Draws the "checkbox" given the screen coordinates and the
2601 * value to be displayed.
2602 *
2603 * Results:
2604 * None.
2605 *
2606 * Side Effects:
2607 * The checkbox value is drawn.
2608 *
2609 *----------------------------------------------------------------------
2610 */
2611 static void
2612 DrawBarBox(tvPtr, drawable, entryPtr, valuePtr, stylePtr, icon, x, y)
2613 TreeView *tvPtr;
2614 Drawable drawable;
2615 TreeViewEntry *entryPtr;
2616 TreeViewValue *valuePtr;
2617 TreeViewStyle *stylePtr;
2618 TreeViewIcon icon;
2619 int x, y;
2620 {
2621 GC gc;
2622 TreeViewColumn *columnPtr;
2623 TreeViewBarBox *cbPtr = (TreeViewBarBox *)stylePtr;
2624 int iconX, iconY, iconWidth, iconHeight;
2625 int textX, textY, textHeight, ttlWidth, bGap, iGap;
2626 int gap, columnWidth;
2627 TextLayout *textPtr;
2628 int boxX, boxY, boxWidth, boxHeight, bw;
2629 TreeViewStyle *csPtr, sRec = *stylePtr;
2630 int valWidth = (valuePtr->textPtr?valuePtr->width:(icon?TreeViewIconWidth(icon):0));
2631 double curValue;
2632 char *string;
2633 TextStyle ts;
2634 XColor *color;
2635 TextLayout *layPtr;
2636 int showValue = (tvPtr->hideStyleText ? 0 : cbPtr->showValue);
2637
2638 layPtr = (tvPtr->hideStyleText?NULL:valuePtr->textPtr);
2639
2640 string = NULL;
2641 textPtr = NULL;
2642 columnPtr = valuePtr->columnPtr;
2643 csPtr = columnPtr->stylePtr;
2644
2645 drawTextBox(tvPtr, drawable, entryPtr, valuePtr, stylePtr, icon, x, y, &sRec);
2646 gc = sRec.gc;
2647
2648 columnWidth = columnPtr->width - PADDING(columnPtr->pad);
2649 if (!valuePtr->string) {
2650 return;
2651 }
2652 if (Tcl_GetDouble(NULL, valuePtr->string, &curValue) != TCL_OK) {
2653 if (sscanf(valuePtr->string, "%lg", &curValue) != 1) {
2654 return;
2655 }
2656 }
2657 if (cbPtr->maxValue<=cbPtr->minValue) {
2658 return;
2659 }
2660
2661 #ifdef notdef
2662 textX = textY = iconX = iconY = 0; /* Suppress compiler warning. */
2663 #endif
2664 iconWidth = iconHeight = 0;
2665 bGap = stylePtr->gap;
2666 iGap = 0;
2667 if (cbPtr->barWidth<=0) {
2668 boxWidth = 0;
2669 bGap = 0;
2670 } else if (cbPtr->barWidth >= 4000) {
2671 boxWidth = 4000;
2672 } else {
2673 boxWidth = ODD(cbPtr->barWidth);
2674 }
2675 if (cbPtr->barHeight<=0) {
2676 boxHeight = 0;
2677 } else if (cbPtr->barHeight >= 4000) {
2678 boxHeight = 4000;
2679 } else {
2680 boxHeight = ODD(cbPtr->barHeight);
2681 }
2682 ttlWidth = ( boxWidth + stylePtr->gap * 2);
2683 if (showValue) {
2684 ttlWidth += (valWidth + stylePtr->gap);
2685 Blt_InitTextStyle(&ts);
2686 ts.font = CHOOSE(tvPtr->font, stylePtr->font);
2687 ts.anchor = TK_ANCHOR_NW;
2688 ts.justify = columnPtr->justify;
2689 }
2690 if (icon != NULL) {
2691 iGap = stylePtr->gap;
2692 iconWidth = TreeViewIconWidth(icon);
2693 iconHeight = TreeViewIconHeight(icon);
2694 ttlWidth += iconWidth + stylePtr->gap;
2695 }
2696
2697 if (columnWidth > ttlWidth) {
2698 switch(columnPtr->justify) {
2699 case TK_JUSTIFY_RIGHT:
2700 x += (columnWidth - ttlWidth - stylePtr->gap*2);
2701 break;
2702 case TK_JUSTIFY_CENTER:
2703 x += (columnWidth - ttlWidth) / 2;
2704 break;
2705 case TK_JUSTIFY_LEFT:
2706 break;
2707 }
2708 }
2709
2710 /*
2711 * Draw the barbox
2712 */
2713 boxX = x + iGap;
2714 boxY = y + (entryPtr->height - boxHeight) / 2;
2715 if (curValue<cbPtr->minValue) {
2716 bw = 0;
2717 } else if (curValue > cbPtr->maxValue) {
2718 bw = boxWidth;
2719 } else if (cbPtr->minValue >= cbPtr->maxValue) {
2720 bw = 0;
2721 } else {
2722 int diff = (cbPtr->maxValue-cbPtr->minValue);
2723 bw = (int)(boxWidth*(1.0*(curValue-cbPtr->minValue)/diff));
2724 }
2725 if (boxHeight && boxWidth) {
2726 if (cbPtr->barBg) {
2727 XFillRectangle(tvPtr->display, drawable, cbPtr->bgGC, boxX, boxY, boxWidth, boxHeight);
2728 }
2729 if (bw>0) {
2730 if (Blt_HasTile(stylePtr->fillTile)) {
2731 Blt_SetTileOrigin(tvPtr->tkwin, stylePtr->fillTile, -boxX, -boxY);
2732 Blt_TileRectangle(tvPtr->tkwin, drawable, stylePtr->fillTile,
2733 boxX, boxY, bw, boxHeight );
2734 } else if (csPtr != NULL && Blt_HasTile(csPtr->fillTile)) {
2735 Blt_SetTileOrigin(tvPtr->tkwin, csPtr->fillTile, -boxX, -boxY);
2736 Blt_TileRectangle(tvPtr->tkwin, drawable, csPtr->fillTile,
2737 boxX, boxY, bw, boxHeight );
2738 } else {
2739
2740 XFillRectangle(tvPtr->display, drawable, cbPtr->fillGC, boxX, boxY, bw, boxHeight);
2741 }
2742 }
2743 XDrawRectangle(tvPtr->display, drawable, cbPtr->boxGC, boxX, boxY,
2744 boxWidth, boxHeight);
2745 }
2746
2747 textHeight = 0;
2748 gap = 0;
2749 if (showValue) {
2750
2751 int disabled = (entryPtr->state == STATE_DISABLED);
2752
2753 if (disabled) {
2754 color = tvPtr->disabledColor;
2755 } else if (Blt_TreeViewEntryIsSelected(tvPtr, entryPtr, columnPtr)) {
2756 color = SELECT_FG(tvPtr);
2757 } else if (entryPtr->color != NULL) {
2758 color = entryPtr->color;
2759 } else {
2760 color = sRec.fgColor;
2761 GetColorPats(tvPtr, entryPtr, valuePtr, stylePtr, &color );
2762 }
2763 Blt_SetDrawTextStyle(&ts, sRec.font, gc, color, sRec.fgColor, stylePtr->shadow.color, 0.0, TK_ANCHOR_NW, columnPtr->justify, 0, stylePtr->shadow.offset);
2764 textPtr = valuePtr->textPtr; // Blt_GetTextLayout(string, &ts);
2765 textHeight = textPtr->height;
2766 if (icon != NULL) {
2767 gap = stylePtr->gap;
2768 }
2769 }
2770 x = boxX + boxWidth + bGap;
2771
2772 /* The icon sits to the left of the text. */
2773 iconX = x;
2774 iconY = y + (entryPtr->height - iconHeight) / 2;
2775 textX = iconX + iconWidth + gap;
2776 textY = y + (entryPtr->height - textHeight) / 2;
2777
2778 valuePtr->iX = iconX;
2779 valuePtr->iY = iconY;
2780 valuePtr->iW = iconWidth;
2781 valuePtr->iH = iconHeight;
2782 valuePtr->tX = textX;
2783 valuePtr->tY = textY;
2784 valuePtr->tW = (textPtr?textPtr->width:0);
2785 valuePtr->tH = textHeight;
2786
2787 if (icon != NULL) {
2788 if (Blt_TreeViewRedrawIcon(tvPtr, entryPtr, columnPtr, icon, 0, 0, iconWidth,
2789 iconHeight, drawable, iconX, iconY) != TCL_OK) return;
2790 } else {
2791 valuePtr->iW = 0;
2792 }
2793 if ((showValue) && (textPtr != NULL)) {
2794 XSetForeground(tvPtr->display, gc, color->pixel);
2795 Blt_DrawTextLayout(tvPtr->tkwin, drawable, textPtr, &ts, textX, textY);
2796 if (color != sRec.fgColor) {
2797 XSetForeground(tvPtr->display, gc, sRec.fgColor->pixel);
2798 }
2799 } else {
2800 valuePtr->tW = 0;
2801 }
2802 stylePtr->flags &= ~STYLE_DIRTY;
2803 }
2804
2805 #if 0
2806 /*
2807 *----------------------------------------------------------------------
2808 *
2809 * PickBarbox --
2810 *
2811 * Draws the "checkbox" given the screen coordinates and the
2812 * value to be displayed.
2813 *
2814 * Results:
2815 * None.
2816 *
2817 * Side Effects:
2818 * The checkbox value is drawn.
2819 *
2820 *----------------------------------------------------------------------
2821 */
2822 static int
2823 PickBarBox(entryPtr, valuePtr, stylePtr, worldX, worldY)
2824 TreeViewEntry *entryPtr;
2825 TreeViewValue *valuePtr;
2826 TreeViewStyle *stylePtr;
2827 int worldX, worldY;
2828 {
2829 TreeViewColumn *columnPtr;
2830 TreeViewBarBox *cbPtr = (TreeViewBarBox *)stylePtr;
2831 int columnWidth;
2832 int x, y, width, height;
2833
2834 columnPtr = valuePtr->columnPtr;
2835 columnWidth = columnPtr->width -
2836 (2 * columnPtr->borderWidth + PADDING(columnPtr->pad));
2837 if (columnWidth > valuePtr->width) {
2838 switch(columnPtr->justify) {
2839 case TK_JUSTIFY_RIGHT:
2840 worldX += (columnWidth - valuePtr->width);
2841 break;
2842 case TK_JUSTIFY_CENTER:
2843 worldX += (columnWidth - valuePtr->width) / 2;
2844 break;
2845 case TK_JUSTIFY_LEFT:
2846 break;
2847 }
2848 }
2849 width = ODD(cbPtr->barWidth) + 2 * cbPtr->lineWidth;
2850 height = ODD(cbPtr->barHeight) + 2 * cbPtr->lineWidth;
2851 x = columnPtr->worldX + columnPtr->pad.side1 + cbPtr->gap -
2852 cbPtr->lineWidth;
2853 y = entryPtr->worldY + (entryPtr->height - height) / 2;
2854 if ((worldX >= x) && (worldX < (x + width)) &&
2855 (worldY >= y) && (worldY < (y + height))) {
2856 return TRUE;
2857 }
2858 return FALSE;
2859 }
2860 #endif
2861 /*
2862 *----------------------------------------------------------------------
2863 *
2864 * EditBarbox --
2865 *
2866 * Edits the "checkbox".
2867 *
2868 * Results:
2869 * None.
2870 *
2871 * Side Effects:
2872 * The checkbox value is drawn.
2873 *
2874 *----------------------------------------------------------------------
2875 */
2876 static int
2877 EditBarBox(tvPtr, entryPtr, valuePtr, stylePtr, x, y, retVal)
2878 TreeView *tvPtr;
2879 TreeViewEntry *entryPtr;
2880 TreeViewValue *valuePtr;
2881 TreeViewStyle *stylePtr;
2882 int x;
2883 int y;
2884 int *retVal;
2885 {
2886 *retVal = 0;
2887 return TCL_OK;
2888 }
2889
2890 /*
2891 *----------------------------------------------------------------------
2892 *
2893 * FreeBarbox --
2894 *
2895 * Releases resources allocated for the checkbox. The resources
2896 * freed by this routine are specific only to the "checkbox".
2897 * Other resources (common to all styles) are freed in the
2898 * Blt_TreeViewFreeStyle routine.
2899 *
2900 * Results:
2901 * None.
2902 *
2903 * Side Effects:
2904 * GCs allocated for the checkbox are freed.
2905 *
2906 *----------------------------------------------------------------------
2907 */
2908 static void
2909 FreeBarBox(tvPtr, stylePtr)
2910 TreeView *tvPtr;
2911 TreeViewStyle *stylePtr;
2912 {
2913 TreeViewBarBox *cbPtr = (TreeViewBarBox *)stylePtr;
2914
2915 FreeTextBox(tvPtr, stylePtr);
2916 if (cbPtr->fillGC != NULL) {
2917 Tk_FreeGC(tvPtr->display, cbPtr->fillGC);
2918 }
2919 if (cbPtr->boxGC != NULL) {
2920 Tk_FreeGC(tvPtr->display, cbPtr->boxGC);
2921 }
2922 if (cbPtr->bgGC != NULL) {
2923 Tk_FreeGC(tvPtr->display, cbPtr->bgGC);
2924 }
2925 }
2926
2927 /*
2928 *----------------------------------------------------------------------
2929 *
2930 * CreateWindowBox --
2931 *
2932 * Creates a "textbox" style.
2933 *
2934 * Results:
2935 * A pointer to the new style structure.
2936 *
2937 *----------------------------------------------------------------------
2938 */
2939 static TreeViewStyle *
2940 CreateWindowBox(tvPtr, hPtr)
2941 TreeView *tvPtr;
2942 Blt_HashEntry *hPtr;
2943 {
2944 TreeViewWindowBox *tbPtr;
2945
2946 tbPtr = (TreeViewWindowBox *)newStyle(tvPtr, hPtr, sizeof(TreeViewWindowBox));
2947 tbPtr->classPtr = &windowBoxClass;
2948 tbPtr->flags = STYLE_WINDOWBOX;
2949 return (TreeViewStyle *)tbPtr;
2950 }
2951
2952 /*
2953 *----------------------------------------------------------------------
2954 *
2955 * ConfigureWindowBox --
2956 *
2957 * Configures a "textbox" style. This routine performs
2958 * generates the GCs required for a textbox style.
2959 *
2960 * Results:
2961 * None.
2962 *
2963 * Side Effects:
2964 * GCs are created for the style.
2965 *
2966 *----------------------------------------------------------------------
2967 */
2968 static void
2969 ConfigureWindowBox(tvPtr, stylePtr)
2970 TreeView *tvPtr;
2971 TreeViewStyle *stylePtr;
2972 {
2973 TreeViewWindowBox *tbPtr = (TreeViewWindowBox *)stylePtr;
2974 tbPtr->flags |= STYLE_DIRTY;
2975 }
2976
2977 /*
2978 *----------------------------------------------------------------------
2979 *
2980 * MeasureWindowBox --
2981 *
2982 * Determines the space requirements for the "textbox" given
2983 * the value to be displayed. Depending upon whether an icon
2984 * or text is displayed and their relative placements, this
2985 * routine computes the space needed for the text entry.
2986 *
2987 * Results:
2988 * None.
2989 *
2990 * Side Effects:
2991 * The width and height fields of *valuePtr* are set with the
2992 * computed dimensions.
2993 *
2994 *----------------------------------------------------------------------
2995 */
2996 static void
2997 MeasureWindowBox(tvPtr, stylePtr, valuePtr)
2998 TreeView *tvPtr;
2999 TreeViewStyle *stylePtr;
3000 TreeViewValue *valuePtr;
3001 {
3002 TreeViewWindowBox *tbPtr = (TreeViewWindowBox *)stylePtr;
3003 valuePtr->width = tbPtr->windowWidth;
3004 valuePtr->height = tbPtr->windowHeight;
3005 }
3006
3007
3008 typedef struct {
3009 int flags;
3010 char *name;
3011 TreeView *tvPtr;
3012 TreeViewEntry *entryPtr;
3013 TreeViewColumn *columnPtr;
3014 Blt_HashEntry *hPtr;
3015 Tk_Window tkwin;
3016 TreeViewWindowBox *stylePtr;
3017 } WindowCell;
3018
3019 static void EmbWinStructureProc( ClientData clientData, XEvent *eventPtr);
3020
3021 static void
3022 EmbWinRemove(WindowCell *wcPtr) {
3023 Blt_HashEntry *hPtr;
3024 TreeView *tvPtr = wcPtr->tvPtr;
3025 hPtr = Blt_FindHashEntry(&tvPtr->winTable, wcPtr->name);
3026 if (hPtr != NULL && wcPtr == (WindowCell*)Blt_GetHashValue(hPtr)) {
3027 Blt_DeleteHashEntry(&tvPtr->winTable, hPtr);
3028 }
3029 Blt_Free(wcPtr->name);
3030 wcPtr->name = NULL;
3031 if (wcPtr->hPtr) Blt_DeleteHashEntry(&tvPtr->winCellTable, wcPtr->hPtr);
3032 wcPtr->hPtr = NULL;
3033 if (wcPtr->tkwin) {
3034 Tk_DeleteEventHandler(wcPtr->tkwin, StructureNotifyMask,
3035 EmbWinStructureProc, (ClientData) wcPtr);
3036 Tk_ManageGeometry(wcPtr->tkwin, NULL, NULL);
3037 wcPtr->tkwin = NULL;
3038 }
3039 Blt_Free(wcPtr);
3040 }
3041
3042 /* Free all windows on widget delete. */
3043 void
3044 Blt_TreeViewFreeWindows( TreeView *tvPtr)
3045 {
3046 Blt_HashEntry *hPtr;
3047 Blt_HashSearch cursor;
3048 WindowCell *wcPtr;
3049
3050 for (hPtr = Blt_FirstHashEntry(&tvPtr->winCellTable, &cursor); hPtr != NULL;
3051 hPtr = Blt_NextHashEntry(&cursor)) {
3052 wcPtr = Blt_GetHashValue(hPtr);
3053 if (wcPtr) {
3054 EmbWinRemove(wcPtr);
3055 }
3056 }
3057 }
3058
3059 static void
3060 EmbWinUnmapNow(Tk_Window ewTkwin, Tk_Window tkwin)
3061 {
3062 if (tkwin != Tk_Parent(ewTkwin)) {
3063 Tk_UnmaintainGeometry(ewTkwin, tkwin);
3064 }
3065 Tk_UnmapWindow(ewTkwin);
3066 }
3067
3068 static void EmbWinRequestProc(ClientData clientData,
3069 Tk_Window tkwin)
3070 {
3071 }
3072
3073 static void EmbWinLostSlaveProc(ClientData clientData, Tk_Window tkwin);
3074
3075 static Tk_GeomMgr windowGeomType = {
3076 "treeview", /* name */
3077 EmbWinRequestProc, /* requestProc */
3078 EmbWinLostSlaveProc, /* lostSlaveProc */
3079 };
3080
3081
3082 void
3083 Blt_TreeViewMarkWindows( TreeView *tvPtr, int flag)
3084 {
3085 Blt_HashEntry *hPtr;
3086 Blt_HashSearch cursor;
3087 WindowCell *wcPtr;
3088
3089 for (hPtr = Blt_FirstHashEntry(&tvPtr->winCellTable, &cursor); hPtr != NULL;
3090 hPtr = Blt_NextHashEntry(&cursor)) {
3091 wcPtr = Blt_GetHashValue(hPtr);
3092 if (wcPtr) {
3093 if (flag == TV_WINDOW_CLEAR) {
3094 /* Clear window drawn flags. */
3095 wcPtr->flags &= ~TV_WINDOW_DRAW;
3096 } else if (flag == TV_WINDOW_UNMAP && (wcPtr->flags&TV_WINDOW_DRAW)==0) {
3097 /* Unmapped undrawn window. */
3098 EmbWinUnmapNow(wcPtr->tkwin, tvPtr->tkwin);
3099 }
3100 }
3101 }
3102 }
3103
3104 static WindowCell *
3105 bltTreeViewFindWindow(TreeViewEntry *entryPtr,
3106 TreeViewColumn *columnPtr)
3107 {
3108 TreeView *tvPtr = columnPtr->tvPtr;
3109 Blt_HashEntry *hPtr;
3110 WindowCell *wcPtr;
3111 Tcl_DString dStr;
3112 char *key;
3113
3114 Tcl_DStringInit(&dStr);
3115 Tcl_DStringAppendElement(&dStr, columnPtr->key);
3116 Tcl_DStringAppendElement(&dStr, Blt_Itoa(entryPtr->node->inode));
3117 key = Tcl_DStringValue(&dStr);
3118 hPtr = Blt_FindHashEntry(&tvPtr->winCellTable, key);
3119 Tcl_DStringFree(&dStr);
3120 if (hPtr == NULL) return NULL;
3121 wcPtr = (WindowCell*)Blt_GetHashValue(hPtr);
3122 return wcPtr;
3123 }
3124
3125 static int isValidSubWin( TreeView *tvPtr, Tk_Window tkwin) {
3126 Tk_Window ancestor, parent;
3127 parent = Tk_Parent(tkwin);
3128 for (ancestor = tvPtr->tkwin; ; ancestor = Tk_Parent(ancestor)) {
3129 if (ancestor == parent) {
3130 break;
3131 }
3132 if (Tk_IsTopLevel(ancestor)) {
3133 return 0;
3134 }
3135 }
3136 if (Tk_IsTopLevel(tkwin) || (tkwin == tvPtr->tkwin)) {
3137 return 0;
3138 }
3139 return 1;
3140 }
3141
3142 static WindowCell *
3143 bltTreeViewWindowMake( TreeView *tvPtr, TreeViewEntry *entryPtr,
3144 TreeViewValue *valuePtr, TreeViewWindowBox *wbPtr)
3145 {
3146 char *name, *key;
3147 Blt_HashEntry *hPtr;
3148 WindowCell *wcPtr = NULL, *w2Ptr;
3149 TreeViewColumn *columnPtr = valuePtr->columnPtr;
3150 Tcl_DString dStr;
3151 Tk_Window tkwin;
3152 int result, isNew;
3153 Tcl_Interp *interp;
3154 char *execCmd = wbPtr->windowCmd;
3155
3156 interp = tvPtr->interp;
3157
3158 Tcl_DStringInit(&dStr);
3159 Tcl_DStringAppendElement(&dStr, columnPtr->key);
3160 Tcl_DStringAppendElement(&dStr, Blt_Itoa(entryPtr->node->inode));
3161 key = Tcl_DStringValue(&dStr);
3162 hPtr = Blt_CreateHashEntry(&tvPtr->winCellTable, key, &isNew);
3163 Tcl_DStringFree(&dStr);
3164 Tcl_DStringInit(&dStr);
3165
3166 if (hPtr == NULL) return NULL;
3167 if (!isNew) {
3168 wcPtr = (WindowCell*)Blt_GetHashValue(hPtr);
3169 if (wcPtr && wcPtr->tkwin == NULL) {
3170 return NULL;
3171 }
3172 return wcPtr;
3173 }
3174
3175 wcPtr = (WindowCell*)Blt_Calloc(1, sizeof(WindowCell));
3176 Blt_SetHashValue(hPtr, wcPtr);
3177 wcPtr->name = NULL;
3178 wcPtr->tvPtr = tvPtr;
3179 wcPtr->columnPtr = columnPtr;
3180 wcPtr->entryPtr = entryPtr;
3181 wcPtr->hPtr = hPtr;
3182 wcPtr->stylePtr = wbPtr;
3183 wcPtr->flags |= TV_WINDOW_DRAW;
3184
3185 if (execCmd != NULL) {
3186 Tcl_DString cmdString;
3187
3188 Blt_TreeViewPercentSubst(tvPtr, entryPtr, columnPtr, execCmd, valuePtr->string, &cmdString);
3189 result = Tcl_GlobalEval(interp, Tcl_DStringValue(&cmdString));
3190 Blt_TreeViewOptsInit(tvPtr);
3191 Tcl_DStringFree(&cmdString);
3192 if ((entryPtr->flags & ENTRY_DELETED) || (tvPtr->flags & TV_DELETED)) {
3193 result = TCL_ERROR;
3194 }
3195 if (result != TCL_OK) {
3196 goto error;
3197 }
3198 name = Tcl_GetStringResult(interp);
3199 } else {
3200 name = valuePtr->string;
3201 if (name == NULL) {
3202 goto error;
3203 }
3204 if (name[0] != '.') {
3205 Tcl_DStringAppend(&dStr, Tk_PathName(tvPtr->tkwin), -1);
3206 Tcl_DStringAppend(&dStr, ".", -1);
3207 Tcl_DStringAppend(&dStr, name, -1);
3208 name = Tcl_DStringValue(&dStr);
3209 }
3210 }
3211 tkwin = Tk_NameToWindow(tvPtr->interp, name, tvPtr->tkwin);
3212 if (tkwin == NULL || !isValidSubWin(tvPtr, tkwin)) {
3213 goto error;
3214 }
3215 if (name && name[0]) {
3216
3217 wcPtr->name = Blt_Strdup(name);
3218 hPtr = Blt_CreateHashEntry(&tvPtr->winTable, wcPtr->name, &isNew);
3219 if (hPtr != NULL) {
3220 w2Ptr = (WindowCell*)Blt_GetHashValue(hPtr);
3221 if (w2Ptr && (w2Ptr->flags&TV_WINDOW_DRAW)) {
3222 goto error;
3223 }
3224 Blt_SetHashValue(hPtr, wcPtr);
3225 }
3226 }
3227 Tcl_DStringFree(&dStr);
3228 if (execCmd == NULL) {
3229 entryPtr->flags |= ENTRY_DATA_WINDOW;
3230 }
3231 entryPtr->flags |= ENTRY_WINDOW;
3232 wcPtr->tkwin = tkwin;
3233 Tk_ManageGeometry(tkwin, &windowGeomType, wcPtr);
3234 Tk_CreateEventHandler(tkwin, StructureNotifyMask,
3235 EmbWinStructureProc, (ClientData) wcPtr);
3236 return wcPtr;
3237
3238 error:
3239 if (wcPtr) {
3240 Blt_DeleteHashEntry(&tvPtr->winCellTable, wcPtr->hPtr);
3241 if (wcPtr->name) Blt_Free(wcPtr->name);
3242 Blt_Free(wcPtr);
3243 }
3244 Tcl_DStringFree(&dStr);
3245 return NULL;
3246 }
3247
3248 /* Some other manager took control. */
3249 static void EmbWinLostSlaveProc(ClientData clientData, Tk_Window tkwin)
3250 {
3251 register WindowCell *wcPtr = (WindowCell *) clientData;
3252 EmbWinUnmapNow(tkwin, wcPtr->tvPtr->tkwin);
3253 EmbWinRemove(wcPtr);
3254 }
3255
3256 static void
3257 EmbWinStructureProc(clientData, eventPtr)
3258 ClientData clientData; /* Pointer to record describing window item. */
3259 XEvent *eventPtr; /* Describes what just happened. */
3260 {
3261 register WindowCell *ewPtr = (WindowCell *) clientData;
3262
3263 if (eventPtr->type != DestroyNotify) {
3264 return;
3265 }
3266 EmbWinRemove(ewPtr);
3267 }
3268
3269 int
3270 Blt_WinResizeAlways(Tk_Window tkwin)
3271 {
3272 while (tkwin != NULL) {
3273 #ifdef Tk_IsResizeYes
3274 if (Tk_IsResizeYes(tkwin)) return 1;
3275 #endif
3276 if (Tk_TopWinHierarchy(tkwin)) break;
3277 tkwin = Tk_Parent(tkwin);
3278 }
3279 return 0;
3280 }
3281
3282 static void
3283 EmbWinDisplay(TreeView *tvPtr, WindowCell *wcPtr,
3284 int x, int y, int width, int height)
3285 {
3286 Tk_Window tkwin = tvPtr->tkwin;
3287 Tk_Window cwTkwin = wcPtr->tkwin;
3288 int diff, reqWidth, reqHeight, sticky, diffx, diffy;
3289
3290
3291 if ((diff = (y-tvPtr->titleHeight- tvPtr->insetY))<0) {
3292 height += diff;
3293 y -= diff;
3294 }
3295 if (width < 2 || height < 2) {
3296 if (wcPtr->flags&TV_WINDOW_DRAW) {
3297 EmbWinUnmapNow(cwTkwin, tkwin);
3298 }
3299 return;
3300 }
3301 reqWidth = Tk_ReqWidth(cwTkwin);
3302 if (reqWidth > width) { reqWidth = width; }
3303 reqHeight = Tk_ReqHeight(cwTkwin);
3304 if (reqHeight > height) { reqHeight = height; }
3305 diffx = width - reqWidth;
3306 diffy = height - reqHeight;
3307
3308 sticky = wcPtr->stylePtr->sticky;
3309
3310 if (sticky&STICK_EAST && sticky&STICK_WEST) {
3311 reqWidth += diffx;
3312 }
3313 if (sticky&STICK_NORTH && sticky&STICK_SOUTH) {
3314 reqHeight += diffy;
3315 }
3316 if (!(sticky&STICK_WEST)) {
3317 x += (sticky&STICK_EAST) ? diffx : diffx/2;
3318 }
3319 if (!(sticky&STICK_NORTH)) {
3320 y += (sticky&STICK_SOUTH) ? diffy : diffy/2;
3321 }
3322 width = reqWidth;
3323 height = reqHeight;
3324 if (tkwin == Tk_Parent(cwTkwin)) {
3325 if ((x != Tk_X(cwTkwin)) || (y != Tk_Y(cwTkwin))
3326 || (width != Tk_Width(cwTkwin))
3327 || (height != Tk_Height(cwTkwin))
3328 || Blt_WinResizeAlways(cwTkwin)
3329 ) {
3330 Tk_MoveResizeWindow(cwTkwin, x, y, width, height);
3331 }
3332 Tk_MapWindow(cwTkwin);
3333 } else {
3334 Tk_MaintainGeometry(cwTkwin, tkwin, x, y, width, height);
3335 }
3336 wcPtr->flags |= TV_WINDOW_DRAW;
3337 }
3338
3339 /*
3340 * Called when a cell has a window from data.
3341 */
3342 void
3343 Blt_TreeViewWindowUpdate(TreeViewEntry *entryPtr, TreeViewColumn *columnPtr)
3344 {
3345 TreeViewWindowBox *wbPtr;
3346 WindowCell *wcPtr;
3347
3348 if (entryPtr->flags & ENTRY_DATA_WINDOW) {
3349 /* Cell may already have a window from data. */
3350
3351 } else if (columnPtr->stylePtr != NULL &&
3352 columnPtr->stylePtr->classPtr->className[0] == 'w') {
3353 wbPtr = (TreeViewWindowBox *)columnPtr->stylePtr;
3354 if (wbPtr->windowCmd != NULL) return;
3355
3356 } else {
3357 return;
3358 }
3359 wcPtr = bltTreeViewFindWindow(entryPtr, columnPtr);
3360 if (wcPtr == NULL || wcPtr->tkwin == NULL) return;
3361 EmbWinUnmapNow(wcPtr->tkwin, wcPtr->tvPtr->tkwin);
3362 Tk_ManageGeometry(wcPtr->tkwin, NULL, NULL);
3363 EmbWinRemove(wcPtr);
3364 }
3365
3366 void
3367 Blt_TreeViewWindowRelease(TreeViewEntry *entryPtr, TreeViewColumn *columnPtr)
3368 {
3369 Blt_HashEntry *hPtr;
3370 Blt_HashSearch cursor;
3371 WindowCell *wcPtr;
3372 TreeView *tvPtr;
3373
3374 tvPtr = (columnPtr?columnPtr->tvPtr:entryPtr->tvPtr);
3375
3376 for (hPtr = Blt_FirstHashEntry(&tvPtr->winCellTable, &cursor); hPtr != NULL;
3377 hPtr = Blt_NextHashEntry(&cursor)) {
3378 wcPtr = (WindowCell*)Blt_GetHashValue(hPtr);
3379 if (wcPtr == NULL) continue;
3380 if (entryPtr && entryPtr == wcPtr->entryPtr) {
3381 EmbWinUnmapNow(wcPtr->tkwin, wcPtr->tvPtr->tkwin);
3382 EmbWinRemove(wcPtr);
3383 continue;
3384 }
3385 if (columnPtr && columnPtr == wcPtr->columnPtr) {
3386 EmbWinUnmapNow(wcPtr->tkwin, wcPtr->tvPtr->tkwin);
3387 EmbWinRemove(wcPtr);
3388 continue;
3389 }
3390 }
3391 }
3392 /*
3393 *----------------------------------------------------------------------
3394 *
3395 * DrawWindowBox --
3396 *
3397 * Draws the "windowbox" given the screen coordinates.
3398 * The window name is taken from the data value.
3399 *
3400 * Results:
3401 * None.
3402 *
3403 * Side Effects:
3404 * The window is drawn.
3405 *
3406 *----------------------------------------------------------------------
3407 */
3408 static void
3409 DrawWindowBox(tvPtr, drawable, entryPtr, valuePtr, stylePtr, icon, x, y)
3410 TreeView *tvPtr;
3411 Drawable drawable;
3412 TreeViewEntry *entryPtr;
3413 TreeViewValue *valuePtr;
3414 TreeViewStyle *stylePtr;
3415 TreeViewIcon icon;
3416 int x, y;
3417 {
3418 TreeViewColumn *columnPtr;
3419 TreeViewWindowBox *tbPtr = (TreeViewWindowBox *)stylePtr;
3420 Tk_Window tkwin;
3421 int width, height, diff;
3422 WindowCell *wcPtr;
3423 TreeViewStyle sRec = *stylePtr;
3424
3425 columnPtr = valuePtr->columnPtr;
3426
3427 Tcl_Preserve(entryPtr);
3428 wcPtr = bltTreeViewWindowMake(tvPtr, entryPtr, valuePtr, tbPtr);
3429 if ((entryPtr->flags & ENTRY_DELETED) || (tvPtr->flags & TV_DELETED)) {
3430 Tcl_Release(entryPtr);
3431 return;
3432 }
3433 Tcl_Release(entryPtr);
3434
3435 drawTextBox(tvPtr, drawable, entryPtr, valuePtr, stylePtr, icon, x, y, &sRec);
3436
3437 if (wcPtr != NULL) {
3438 int columnWidth = columnPtr->width -
3439 (2 * columnPtr->borderWidth + PADDING(columnPtr->pad));
3440
3441 tkwin = wcPtr->tkwin;
3442 width = columnWidth;
3443 height = entryPtr->height-1;
3444 if ((diff = (y-tvPtr->titleHeight- tvPtr->insetY))<0) {
3445 height += diff;
3446 y -= diff;
3447 }
3448 EmbWinDisplay(tvPtr, wcPtr, x, y, width, height);
3449 }
3450 stylePtr->flags &= ~STYLE_DIRTY;
3451 }
3452
3453 /*
3454 *----------------------------------------------------------------------
3455 *
3456 * EditWindowbox --
3457 *
3458 * Edits the "windowbox".
3459 *
3460 * Results:
3461 * None.
3462 *
3463 *----------------------------------------------------------------------
3464 */
3465 /*ARGSUSED*/
3466 static int
3467 EditWindowBox(tvPtr, entryPtr, valuePtr, stylePtr, x, y, retVal)
3468 TreeView *tvPtr;
3469 TreeViewEntry *entryPtr;
3470 TreeViewValue *valuePtr;
3471 TreeViewStyle *stylePtr; /* Not used. */
3472 int x;
3473 int y;
3474 int *retVal;
3475 {
3476 return TCL_ERROR;
3477 }
3478
3479 /*
3480 *----------------------------------------------------------------------
3481 *
3482 * FreeWindowBox --
3483 *
3484 * Releases resources allocated for the textbox. The resources
3485 * freed by this routine are specific only to the "textbox".
3486 * Other resources (common to all styles) are freed in the
3487 * Blt_TreeViewFreeStyle routine.
3488 *
3489 * Results:
3490 * None.
3491 *
3492 * Side Effects:
3493 * GCs allocated for the textbox are freed.
3494 *
3495 *----------------------------------------------------------------------
3496 */
3497 static void
3498 FreeWindowBox(tvPtr, stylePtr)
3499 TreeView *tvPtr;
3500 TreeViewStyle *stylePtr;
3501 {
3502 TreeViewWindowBox *tbPtr = (TreeViewWindowBox *)stylePtr;
3503 Blt_HashEntry *hPtr;
3504 Blt_HashSearch cursor;
3505 WindowCell *wcPtr;
3506
3507 if (!tbPtr) return;
3508
3509 for (hPtr = Blt_FirstHashEntry(&tvPtr->winCellTable, &cursor); hPtr != NULL;
3510 hPtr = Blt_NextHashEntry(&cursor)) {
3511 wcPtr = (WindowCell*)Blt_GetHashValue(hPtr);
3512 if (wcPtr && stylePtr == (TreeViewStyle*)wcPtr->stylePtr) {
3513 EmbWinRemove(wcPtr);
3514 }
3515 }
3516
3517 }
3518
3519 static TreeViewStyle *
3520 GetStyle(interp, tvPtr, styleName)
3521 Tcl_Interp *interp;
3522 TreeView *tvPtr;
3523 char *styleName;
3524 {
3525 Blt_HashEntry *hPtr;
3526
3527 hPtr = Blt_FindHashEntry(&tvPtr->styleTable, styleName);
3528 if (hPtr == NULL) {
3529 if (interp != NULL) {
3530 Tcl_AppendResult(interp, "can't find style \"", styleName,
3531 "\"", (char *)NULL);
3532 }
3533 return NULL;
3534 }
3535 return Blt_GetHashValue(hPtr);
3536 }
3537
3538 int
3539 Blt_TreeViewGetStyle(interp, tvPtr, styleName, stylePtrPtr)
3540 Tcl_Interp *interp;
3541 TreeView *tvPtr;
3542 char *styleName;
3543 TreeViewStyle **stylePtrPtr;
3544 {
3545 TreeViewStyle *stylePtr;
3546
3547 stylePtr = GetStyle(interp, tvPtr, styleName);
3548 if (stylePtr == NULL) {
3549 return TCL_ERROR;
3550 }
3551 stylePtr->refCount++;
3552 *stylePtrPtr = stylePtr;
3553 return TCL_OK;
3554 }
3555
3556 int
3557 Blt_TreeViewGetStyleMake(interp, tvPtr, styleName, stylePtrPtr, columnPtr, entryPtr, valuePtr)
3558 Tcl_Interp *interp;
3559 TreeView *tvPtr;
3560 char *styleName;
3561 TreeViewStyle **stylePtrPtr;
3562 TreeViewColumn *columnPtr;
3563 TreeViewEntry *entryPtr;
3564 TreeViewValue *valuePtr;
3565 {
3566 TreeViewStyle *stylePtr = NULL;
3567 Tcl_DString dString;
3568 int result;
3569
3570 if (strlen(styleName)==0) {
3571 Tcl_AppendResult(interp, "can not use style with empty name", 0);
3572 return TCL_ERROR;
3573 }
3574 if (Blt_TreeViewGetStyle(NULL, tvPtr, styleName, &stylePtr) != TCL_OK) {
3575 if (tvPtr->styleCmd == NULL) {
3576 if (stylePtr == NULL) {
3577 if (interp != NULL) {
3578 Tcl_AppendResult(interp, "style not found: ", styleName, 0);
3579 }
3580 return TCL_ERROR;
3581 }
3582 } else if (!strcmp(tvPtr->styleCmd, "%W style create textbox %V")) {
3583 stylePtr = Blt_TreeViewCreateStyle(interp, tvPtr, STYLE_TEXTBOX, styleName);
3584 assert(stylePtr);
3585 Blt_TreeViewUpdateStyleGCs(tvPtr, stylePtr);
3586
3587 } else {
3588 Tcl_DStringInit(&dString);
3589 Blt_TreeViewPercentSubst(tvPtr, entryPtr, columnPtr, tvPtr->styleCmd, styleName, &dString);
3590 /* TODO: should save/restore intep state. */
3591 result = Tcl_GlobalEval(tvPtr->interp, Tcl_DStringValue(&dString));
3592 Tcl_DStringFree(&dString);
3593 if ((tvPtr->flags & TV_DELETED)) {
3594 return TCL_ERROR;
3595 }
3596 if (result != TCL_OK) {
3597 if (interp != NULL) {
3598 Tcl_AppendResult(interp, "error in -stylecommand ", tvPtr->styleCmd, " for: ", styleName, 0);
3599 }
3600 return TCL_ERROR;
3601 }
3602 result = Blt_TreeViewGetStyle(interp, tvPtr, styleName, &stylePtr);
3603 if (result != TCL_OK) {
3604 if (interp != NULL) {
3605 Tcl_AppendResult(interp, "style not found: ", styleName, 0);
3606 }
3607 return TCL_ERROR;
3608 }
3609 Blt_TreeViewUpdateStyleGCs(tvPtr, stylePtr);
3610 if (interp != NULL) {
3611 Tcl_ResetResult(interp);
3612 }
3613 }
3614 }
3615 *stylePtrPtr = stylePtr;
3616 return TCL_OK;
3617 }
3618
3619 static TreeViewStyle *
3620 CreateStyle(interp, tvPtr, type, styleName, objc, objv, create)
3621 Tcl_Interp *interp;
3622 TreeView *tvPtr; /* TreeView widget. */
3623 int type; /* Type of style: either
3624 * STYLE_TEXTBOX,
3625 * STYLE_COMBOBOX, or
3626 * STYLE_CHECKBOX */
3627 char *styleName; /* Name of the new style. */
3628 int objc;
3629 Tcl_Obj *CONST *objv;
3630 int create;
3631 {
3632 Blt_HashEntry *hPtr;
3633 int isNew, ref = 1;
3634 TreeViewStyle *stylePtr;
3635
3636 hPtr = Blt_CreateHashEntry(&tvPtr->styleTable, styleName, &isNew);
3637 if (!isNew) {
3638 /* Don't kick an error unless styleCmd is changed. */
3639 if (create && (tvPtr->styleCmd == NULL || strcmp(tvPtr->styleCmd, "%W style create textbox %V") == 0 || (tvPtr->styleCmd[0] == 0))) {
3640 stylePtr = Blt_GetHashValue(hPtr);
3641 if (type == (stylePtr->flags&STYLE_TYPE)) {
3642 ref = 0;
3643 goto doconf;
3644 }
3645 }
3646 if (interp != NULL) {
3647 Tcl_AppendResult(interp, "style \"", styleName,
3648 "\" already exists", (char *)NULL);
3649 }
3650 return NULL;
3651 }
3652 /* Create the new marker based upon the given type */
3653 switch (type) {
3654 case STYLE_TEXTBOX:
3655 stylePtr = CreateTextBox(tvPtr, hPtr);
3656 break;
3657 case STYLE_COMBOBOX:
3658 stylePtr = CreateComboBox(tvPtr, hPtr);
3659 break;
3660 case STYLE_CHECKBOX:
3661 stylePtr = CreateCheckBox(tvPtr, hPtr);
3662 break;
3663 case STYLE_WINDOWBOX:
3664 stylePtr = CreateWindowBox(tvPtr, hPtr);
3665 break;
3666 case STYLE_BARBOX:
3667 stylePtr = CreateBarBox(tvPtr, hPtr);
3668 break;
3669 default:
3670 return NULL;
3671 }
3672 doconf:
3673 Blt_TreeViewOptsInit(tvPtr);
3674 if (Blt_ConfigureComponentFromObj(tvPtr->interp, tvPtr->tkwin, styleName,
3675 stylePtr->classPtr->className, stylePtr->classPtr->specsPtr,
3676 objc, objv, (char *)stylePtr, 0) != TCL_OK) {
3677 if (ref) {
3678 Blt_TreeViewFreeStyle(tvPtr, stylePtr);
3679 }
3680 return NULL;
3681 }
3682 if (stylePtr->tile != NULL) {
3683 Blt_SetTileChangedProc(stylePtr->tile, Blt_TreeViewTileChangedProc, tvPtr);
3684 }
3685 if (stylePtr->fillTile != NULL) {
3686 Blt_SetTileChangedProc(stylePtr->fillTile, Blt_TreeViewTileChangedProc, tvPtr);
3687 }
3688 stylePtr->refCount += ref;
3689 return stylePtr;
3690 }
3691
3692 void
3693 Blt_TreeViewUpdateStyleGCs(tvPtr, stylePtr)
3694 TreeView *tvPtr;
3695 TreeViewStyle *stylePtr;
3696 {
3697 if (tvPtr->font == NULL) return;
3698 (*stylePtr->classPtr->configProc)(tvPtr, stylePtr);
3699 stylePtr->flags |= STYLE_DIRTY;
3700 Blt_TreeViewEventuallyRedraw(tvPtr);
3701 }
3702
3703 void
3704 Blt_TreeViewUpdateStyles(tvPtr)
3705 TreeView *tvPtr;
3706 {
3707 Blt_HashEntry *hPtr;
3708 Blt_HashSearch cursor;
3709 TreeViewStyle *stylePtr;
3710 Blt_TreeViewUpdateStyleGCs(tvPtr, tvPtr->stylePtr);
3711
3712 for (hPtr = Blt_FirstHashEntry(&tvPtr->styleTable, &cursor); hPtr != NULL;
3713 hPtr = Blt_NextHashEntry(&cursor)) {
3714 stylePtr = Blt_GetHashValue(hPtr);
3715 Blt_TreeViewUpdateStyleGCs(tvPtr, stylePtr);
3716 }
3717 }
3718
3719 TreeViewStyle *
3720 Blt_TreeViewCreateStyle(interp, tvPtr, type, styleName)
3721 Tcl_Interp *interp;
3722 TreeView *tvPtr; /* TreeView widget. */
3723 int type; /* Type of style: either
3724 * STYLE_TEXTBOX,
3725 * STYLE_COMBOBOX, or
3726 * STYLE_CHECKBOX */
3727 char *styleName; /* Name of the new style. */
3728 {
3729 return CreateStyle(interp, tvPtr, type, styleName, 0, (Tcl_Obj **)NULL, 0);
3730 }
3731
3732 void
3733 Blt_TreeViewFreeStyle(tvPtr, stylePtr)
3734 TreeView *tvPtr;
3735 TreeViewStyle *stylePtr;
3736 {
3737 stylePtr->refCount--;
3738 #ifdef notdef
3739 fprint(f(stderr, "Blt_TreeViewFreeStyle %s count=%d\n", stylePtr->name,
3740 stylePtr->refCount);
3741 #endif
3742 /* Remove the style from the hash table so that it's name can be used.*/
3743 /* If no cell is using the style, remove it.*/
3744 if ((stylePtr->refCount <= 0) && !(stylePtr->flags & STYLE_USER)){
3745 #ifdef notdef
3746 fprintf(stderr, "freeing %s\n", stylePtr->name);
3747 #endif
3748 /*Blt_HashEntry *hPtr;
3749 hPtr = Blt_FindHashEntry(&tvPtr->styleTagTable, stylePtr->name, &isNew);
3750 if (hPtr != NULL) {
3751 Blt_DeleteHashEntry(&tvPtr->styleTagTable, hPtr);
3752 }*/
3753 Blt_TreeViewOptsInit(tvPtr);
3754 Blt_FreeObjOptions(tvPtr->interp,
3755 stylePtr->classPtr->specsPtr, (char *)stylePtr,
3756 tvPtr->display, 0);
3757 (*stylePtr->classPtr->freeProc)(tvPtr, stylePtr);
3758 if (stylePtr->hashPtr != NULL) {
3759 Blt_DeleteHashEntry(&tvPtr->styleTable, stylePtr->hashPtr);
3760 }
3761 if (stylePtr->name != NULL) {
3762 Blt_Free(stylePtr->name);
3763 }
3764 if (tvPtr->subStylePtr == stylePtr) { tvPtr->subStylePtr = NULL; }
3765 if (tvPtr->altStylePtr == stylePtr) { tvPtr->altStylePtr = NULL; }
3766 if (tvPtr->emptyStylePtr == stylePtr) { tvPtr->emptyStylePtr = NULL; }
3767 Blt_Free(stylePtr);
3768 }
3769 }
3770
3771 void
3772 Blt_TreeViewSetStyleIcon(tvPtr, stylePtr, icon)
3773 TreeView *tvPtr;
3774 TreeViewStyle *stylePtr;
3775 TreeViewIcon icon;
3776 {
3777 TreeViewTextBox *tbPtr = (TreeViewTextBox *)stylePtr;
3778
3779 if (tbPtr && tbPtr->icon != NULL) {
3780 Blt_TreeViewFreeIcon(tvPtr, tbPtr->icon);
3781 }
3782 tbPtr->icon = icon;
3783 }
3784
3785 GC
3786 Blt_TreeViewGetStyleGC(tvPtr, stylePtr)
3787 TreeView *tvPtr;
3788 TreeViewStyle *stylePtr;
3789 {
3790 TreeViewTextBox *tbPtr = (TreeViewTextBox *)stylePtr;
3791 return (tbPtr && tbPtr->gc) ? tbPtr->gc : tvPtr->stylePtr->gc;
3792 }
3793
3794 Tk_3DBorder
3795 Blt_TreeViewGetStyleBorder(tvPtr, stylePtr)
3796 TreeView *tvPtr;
3797 TreeViewStyle *stylePtr;
3798 {
3799 TreeViewTextBox *tbPtr = (TreeViewTextBox *)stylePtr;
3800 Tk_3DBorder border;
3801
3802 if (!tbPtr) {
3803 return tvPtr->border;
3804 }
3805 border = (tbPtr->flags & STYLE_HIGHLIGHT)
3806 ? tbPtr->highlightBorder : tbPtr->border;
3807 return (border != NULL) ? border : tvPtr->border;
3808 }
3809
3810 Tk_Font
3811 Blt_TreeViewGetStyleFont(tvPtr, columnPtr, stylePtr)
3812 TreeView *tvPtr;
3813 TreeViewColumn *columnPtr;
3814 TreeViewStyle *stylePtr;
3815 {
3816 TreeViewTextBox *tbPtr = (TreeViewTextBox *)stylePtr;
3817
3818 if (tbPtr != NULL && tbPtr->font != NULL) {
3819 return tbPtr->font;
3820 }
3821 if (columnPtr != NULL && columnPtr->font != NULL) {
3822 return columnPtr->font;
3823 }
3824 return tvPtr->font;
3825 }
3826
3827 XColor *
3828 Blt_TreeViewGetStyleFg(tvPtr, columnPtr, stylePtr)
3829 TreeView *tvPtr;
3830 TreeViewColumn *columnPtr;
3831 TreeViewStyle *stylePtr;
3832 {
3833 TreeViewTextBox *tbPtr = (TreeViewTextBox *)stylePtr;
3834
3835 if (tbPtr && tbPtr->fgColor != NULL) {
3836 return tbPtr->fgColor;
3837 }
3838 if (columnPtr && columnPtr->fgColor) {
3839 return columnPtr->fgColor;
3840 }
3841 return tvPtr->fgColor;
3842 }
3843
3844 static void
3845 DrawValue(tvPtr, entryPtr, valuePtr)
3846 TreeView *tvPtr;
3847 TreeViewEntry *entryPtr;
3848 TreeViewValue *valuePtr;
3849 {
3850 Drawable drawable;
3851 int sx, sy, dx, dy;
3852 int width, height, ishid;
3853 int left, right, top, bottom;
3854 TreeViewColumn *columnPtr;
3855 TreeViewStyle *stylePtr;
3856 Tk_3DBorder selBorder;
3857
3858 stylePtr = valuePtr->stylePtr;
3859 ishid = (stylePtr?stylePtr->hidden:0);
3860 if (stylePtr == NULL) {
3861 stylePtr = CHOOSE(tvPtr->stylePtr, valuePtr->columnPtr->stylePtr);
3862 }
3863 if (stylePtr->cursor != None) {
3864 if (valuePtr == tvPtr->activeValuePtr) {
3865 Tk_DefineCursor(tvPtr->tkwin, stylePtr->cursor);
3866 } else {
3867 if (tvPtr->cursor != None) {
3868 Tk_DefineCursor(tvPtr->tkwin, tvPtr->cursor);
3869 } else {
3870 Tk_UndefineCursor(tvPtr->tkwin);
3871 }
3872 }
3873 }
3874 columnPtr = valuePtr->columnPtr;
3875 dx = SCREENX(tvPtr, columnPtr->worldX) + columnPtr->pad.side1-1;
3876 dy = SCREENY(tvPtr, entryPtr->worldY);
3877 height = entryPtr->height - 1;
3878 width = valuePtr->columnPtr->width - PADDING(columnPtr->pad);
3879
3880 top = tvPtr->titleHeight + tvPtr->insetY;
3881 bottom = Tk_Height(tvPtr->tkwin) - tvPtr->insetY;
3882 left = tvPtr->insetX;
3883 right = Tk_Width(tvPtr->tkwin) - tvPtr->insetX;
3884
3885 if (((dx + width) < left) || (dx > right) ||
3886 ((dy + height) < top) || (dy > bottom)) {
3887 return; /* Value is clipped. */
3888 }
3889
3890 drawable = Tk_GetPixmap(tvPtr->display, Tk_WindowId(tvPtr->tkwin),
3891 width, height, Tk_Depth(tvPtr->tkwin));
3892 /* Draw the background of the value. */
3893
3894 if (Blt_TreeViewEntryIsSelected(tvPtr, entryPtr, columnPtr)) {
3895 selBorder = SELECT_BORDER(tvPtr);
3896 Blt_Fill3DRectangle(tvPtr->tkwin, drawable, selBorder, 0, 0, width, height,
3897 0, TK_RELIEF_FLAT);
3898 } else if ((valuePtr == tvPtr->activeValuePtr) ||
3899 (!Blt_TreeViewEntryIsSelected(tvPtr, entryPtr, columnPtr))) {
3900 Tk_3DBorder border;
3901
3902 border = Blt_TreeViewGetStyleBorder(tvPtr, tvPtr->stylePtr);
3903 Blt_Fill3DRectangle(tvPtr->tkwin, drawable, border, 0, 0, width, height,
3904 0, TK_RELIEF_FLAT);
3905 } else if (Blt_HasTile(tvPtr->tile) == 0 && Blt_HasTile(columnPtr->tile) == 0) {
3906
3907 Blt_Draw3DRectangle(tvPtr->tkwin, drawable, SELECT_BORDER(tvPtr), 0, 0,
3908 width, height, tvPtr->selBorderWidth, tvPtr->selRelief);
3909 }
3910 Blt_TreeViewDrawValue(tvPtr, entryPtr, valuePtr, drawable, 0, 0, entryPtr->flags & ENTRY_ALTROW, ishid);
3911
3912 /* Clip the drawable if necessary */
3913 sx = sy = 0;
3914 if (dx < left) {
3915 width -= left - dx;
3916 sx += left - dx;
3917 dx = left;
3918 }
3919 if ((dx + width) >= right) {
3920 width -= (dx + width) - right;
3921 }
3922 if (dy < top) {
3923 height -= top - dy;
3924 sy += top - dy;
3925 dy = top;
3926 }
3927 if ((dy + height) >= bottom) {
3928 height -= (dy + height) - bottom;
3929 }
3930 XCopyArea(tvPtr->display, drawable, Tk_WindowId(tvPtr->tkwin),
3931 tvPtr->lineGC, sx, sy, width, height, dx, dy);
3932 Tk_FreePixmap(tvPtr->display, drawable);
3933 }
3934
3935 /*
3936 *----------------------------------------------------------------------
3937 *
3938 * StyleActivateOp --
3939 *
3940 * Turns on/off highlighting for a particular style.
3941 *
3942 * .t style activate entry column
3943 *
3944 * Results:
3945 * A standard Tcl result. If TCL_ERROR is returned, then
3946 * interp->result contains an error message.
3947 *
3948 *----------------------------------------------------------------------
3949 */
3950 /*ARGSUSED*/
3951 static int
3952 StyleActivateOp(tvPtr, interp, objc, objv)
3953 TreeView *tvPtr;
3954
3955 Tcl_Interp *interp;
3956 int objc; /* Not used. */
3957 Tcl_Obj *CONST *objv;
3958 {
3959 TreeViewEntry *entryPtr;
3960 TreeViewValue *valuePtr, *oldPtr;
3961
3962 oldPtr = tvPtr->activeValuePtr;
3963 if (objc == 3) {
3964 Tcl_Obj *listObjPtr;
3965
3966 valuePtr = tvPtr->activeValuePtr;
3967 entryPtr = tvPtr->activePtr;
3968 listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
3969 if ((entryPtr != NULL) && (valuePtr != NULL)) {
3970 Tcl_Obj *objPtr;
3971 objPtr = Tcl_NewIntObj(Blt_TreeNodeId(entryPtr->node));
3972 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
3973 objPtr = Tcl_NewStringObj(valuePtr->columnPtr->key, -1);
3974 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
3975 }
3976 Tcl_SetObjResult(interp, listObjPtr);
3977 return TCL_OK;
3978 } else if (objc == 4) {
3979 tvPtr->activeValuePtr = NULL;
3980 if ((oldPtr != NULL) && (tvPtr->activePtr != NULL)) {
3981 DrawValue(tvPtr, tvPtr->activePtr, oldPtr);
3982 }
3983 } else {
3984 TreeViewColumn *columnPtr;
3985
3986 if (Blt_TreeViewGetEntry(tvPtr, objv[3], &entryPtr) != TCL_OK) {
3987 return TCL_ERROR;
3988 }
3989
3990 if (Blt_TreeViewGetColumn(interp, tvPtr, objv[4], &columnPtr)
3991 != TCL_OK) {
3992 return TCL_ERROR;
3993 }
3994 valuePtr = Blt_TreeViewFindValue(entryPtr, columnPtr);
3995 if (valuePtr == NULL) {
3996 return TCL_OK;
3997 }
3998 tvPtr->activePtr = entryPtr;
3999 tvPtr->activeColumnPtr = columnPtr;
4000 oldPtr = tvPtr->activeValuePtr;
4001 tvPtr->activeValuePtr = valuePtr;
4002 if (valuePtr != oldPtr) {
4003 if (oldPtr != NULL) {
4004 DrawValue(tvPtr, entryPtr, oldPtr);
4005 }
4006 if (valuePtr != NULL) {
4007 DrawValue(tvPtr, entryPtr, valuePtr);
4008 }
4009 }
4010 }
4011 return TCL_OK;
4012 }
4013
4014
4015 /*
4016 *----------------------------------------------------------------------
4017 *
4018 * StyleCgetOp --
4019 *
4020 * .t style cget "styleName" -background
4021 *
4022 *----------------------------------------------------------------------
4023 */
4024 /*ARGSUSED*/
4025 static int
4026 StyleCgetOp(tvPtr, interp, objc, objv)
4027 TreeView *tvPtr;
4028 Tcl_Interp *interp;
4029 int objc; /* Not used. */
4030 Tcl_Obj *CONST *objv;
4031 {
4032 TreeViewStyle *stylePtr;
4033
4034 stylePtr = GetStyle(interp, tvPtr, Tcl_GetString(objv[3]));
4035 if (stylePtr == NULL) {
4036 return TCL_ERROR;
4037 }
4038 Blt_TreeViewOptsInit(tvPtr);
4039 return Blt_ConfigureValueFromObj(interp, tvPtr->tkwin,
4040 stylePtr->classPtr->specsPtr, (char *)stylePtr, objv[4], 0);
4041 }
4042
4043 /*
4044 *----------------------------------------------------------------------
4045 *
4046 * StyleCheckBoxOp --
4047 *
4048 * .t style checkbox "styleName" -background blue
4049 *
4050 *----------------------------------------------------------------------
4051 */
4052 /*ARGSUSED*/
4053 static int
4054 StyleCheckBoxOp(tvPtr, interp, objc, objv)
4055 TreeView *tvPtr;
4056 Tcl_Interp *interp;
4057 int objc; /* Not used. */
4058 Tcl_Obj *CONST *objv;
4059 {
4060 TreeViewStyle *stylePtr;
4061
4062 stylePtr = CreateStyle(interp, tvPtr, STYLE_CHECKBOX,
4063 Tcl_GetString(objv[3]), objc - 4, objv + 4, 1);
4064 if (stylePtr == NULL) {
4065 return TCL_ERROR;
4066 }
4067 stylePtr->refCount = 0;
4068 stylePtr->flags |= STYLE_USER;
4069 Blt_TreeViewUpdateStyleGCs(tvPtr, stylePtr);
4070 Tcl_SetObjResult(interp, objv[3]);
4071 return TCL_OK;
4072 }
4073
4074
4075 /*
4076 *----------------------------------------------------------------------
4077 *
4078 * StyleComboBoxOp --
4079 *
4080 * .t style combobox "styleName" -background blue
4081 *
4082 *----------------------------------------------------------------------
4083 */
4084 /*ARGSUSED*/
4085 static int
4086 StyleComboBoxOp(tvPtr, interp, objc, objv)
4087 TreeView *tvPtr;
4088 Tcl_Interp *interp;
4089 int objc; /* Not used. */
4090 Tcl_Obj *CONST *objv;
4091 {
4092 TreeViewStyle *stylePtr;
4093
4094 stylePtr = CreateStyle(interp, tvPtr, STYLE_COMBOBOX,
4095 Tcl_GetString(objv[3]), objc - 4, objv + 4, 1);
4096 if (stylePtr == NULL) {
4097 return TCL_ERROR;
4098 }
4099 stylePtr->refCount = 0;
4100 stylePtr->flags |= STYLE_USER;
4101 Blt_TreeViewUpdateStyleGCs(tvPtr, stylePtr);
4102 Tcl_SetObjResult(interp, objv[3]);
4103 return TCL_OK;
4104 }
4105
4106 /*
4107 *----------------------------------------------------------------------
4108 *
4109 * StyleConfigureOp --
4110 *
4111 * This procedure is called to process a list of configuration
4112 * options database, in order to reconfigure a style.
4113 *
4114 * .t style configure "styleName" option value
4115 *
4116 * Results:
4117 * A standard Tcl result. If TCL_ERROR is returned, then
4118 * interp->result contains an error message.
4119 *
4120 * Side effects:
4121 * Configuration information, such as text string, colors, font,
4122 * etc. get set for stylePtr; old resources get freed, if there
4123 * were any.
4124 *
4125 *----------------------------------------------------------------------
4126 */
4127 static int
4128 StyleConfigureOp(tvPtr, interp, objc, objv)
4129 TreeView *tvPtr;
4130 Tcl_Interp *interp;
4131 int objc;
4132 Tcl_Obj *CONST *objv;
4133 {
4134 TreeViewStyle *stylePtr;
4135
4136 if (Blt_TreeViewGetStyleMake(interp, tvPtr, Tcl_GetString(objv[3]), &stylePtr,
4137 NULL, NULL, NULL) != TCL_OK) {
4138 return TCL_ERROR;
4139 }
4140 stylePtr->refCount--;
4141
4142 Blt_TreeViewOptsInit(tvPtr);
4143 if (objc == 4) {
4144 return Blt_ConfigureInfoFromObj(interp, tvPtr->tkwin,
4145 stylePtr->classPtr->specsPtr, (char *)stylePtr, (Tcl_Obj *)NULL, 0);
4146 } else if (objc == 5) {
4147 return Blt_ConfigureInfoFromObj(interp, tvPtr->tkwin,
4148 stylePtr->classPtr->specsPtr, (char *)stylePtr, objv[4], 0);
4149 }
4150 if (Blt_ConfigureWidgetFromObj(interp, tvPtr->tkwin,
4151 stylePtr->classPtr->specsPtr, objc - 4, objv + 4, (char *)stylePtr,
4152 BLT_CONFIG_OBJV_ONLY, NULL) != TCL_OK) {
4153 return TCL_ERROR;
4154 }
4155 if (stylePtr->tile != NULL) {
4156 Blt_SetTileChangedProc(stylePtr->tile, Blt_TreeViewTileChangedProc, tvPtr);
4157 }
4158 if (stylePtr->fillTile != NULL) {
4159 Blt_SetTileChangedProc(stylePtr->fillTile, Blt_TreeViewTileChangedProc, tvPtr);
4160 }
4161 (*stylePtr->classPtr->configProc)(tvPtr, stylePtr);
4162 Blt_TreeViewMakeStyleDirty(tvPtr);
4163 Blt_TreeViewEventuallyRedraw(tvPtr);
4164 return TCL_OK;
4165 }
4166
4167 /*
4168 *----------------------------------------------------------------------
4169 *
4170 * StyleForgetOp --
4171 *
4172 * Eliminates one or more style names whose
4173 * reference count is zero (i.e. no one else is using it).
4174 *
4175 * .t style forget "styleName"...
4176 *
4177 * Results:
4178 * A standard Tcl result. If TCL_ERROR is returned, then
4179 * interp->result contains an error message.
4180 *
4181 *----------------------------------------------------------------------
4182 */
4183 static int
4184 StyleForgetOp(tvPtr, interp, objc, objv)
4185 TreeView *tvPtr;
4186
4187 Tcl_Interp *interp;
4188 int objc;
4189 Tcl_Obj *CONST *objv;
4190 {
4191 TreeViewStyle *stylePtr;
4192 int i;
4193
4194 for (i = 3; i < objc; i++) {
4195 stylePtr = GetStyle(interp, tvPtr, Tcl_GetString(objv[i]));
4196 if (stylePtr == NULL) {
4197 return TCL_ERROR;
4198 }
4199 if (stylePtr->refCount > 1 || stylePtr == tvPtr->stylePtr) {
4200 continue;
4201 }
4202 if (stylePtr->hashPtr != NULL) {
4203 Blt_DeleteHashEntry(&tvPtr->styleTable, stylePtr->hashPtr);
4204 stylePtr->hashPtr = NULL;
4205 }
4206 stylePtr->refCount--;
4207 stylePtr->flags &= ~STYLE_USER;
4208 Blt_TreeViewFreeStyle(tvPtr, stylePtr);
4209 }
4210 Blt_TreeViewEventuallyRedraw(tvPtr);
4211 return TCL_OK;
4212 }
4213
4214 static int
4215 StyleUseOp(tvPtr, interp, objc, objv)
4216 TreeView *tvPtr;
4217
4218 Tcl_Interp *interp;
4219 int objc;
4220 Tcl_Obj *CONST *objv;
4221 {
4222 TreeViewStyle *stylePtr;
4223
4224 stylePtr = GetStyle(interp, tvPtr, Tcl_GetString(objv[3]));
4225 if (stylePtr == NULL) {
4226 return TCL_ERROR;
4227 }
4228 Tcl_SetObjResult(interp, Tcl_NewIntObj(stylePtr->refCount-1));
4229 return TCL_OK;
4230 }
4231
4232
4233 static int StyleLookup(char *string) {
4234 if (!strcmp(string, "combobox")) {
4235 return STYLE_COMBOBOX;
4236 }
4237 if (!strcmp(string, "textbox")) {
4238 return STYLE_TEXTBOX;
4239 }
4240 if (!strcmp(string, "barbox")) {
4241 return STYLE_BARBOX;
4242 }
4243 if (!strcmp(string, "windowbox")) {
4244 return STYLE_WINDOWBOX;
4245 }
4246 if (!strcmp(string, "checkbox")) {
4247 return STYLE_CHECKBOX;
4248 }
4249 return -1;
4250 }
4251
4252 /*
4253 *----------------------------------------------------------------------
4254 *
4255 * StyleTypeOp --
4256 *
4257 * Return the type of a style.
4258 *
4259 * .t style type "styleName"...
4260 *
4261 * Results:
4262 * A standard Tcl result. If TCL_ERROR is returned, then
4263 * interp->result contains an error message.
4264 *
4265 *----------------------------------------------------------------------
4266 */
4267 static int
4268 StyleTypeOp(tvPtr, interp, objc, objv)
4269 TreeView *tvPtr;
4270
4271 Tcl_Interp *interp;
4272 int objc;
4273 Tcl_Obj *CONST *objv;
4274 {
4275 TreeViewStyle *stylePtr, *newStylePtr;
4276 TreeViewAllStyles all;
4277 const char *cp;
4278 char *newType;
4279 int nType;
4280
4281 if (objc == 3) {
4282 cp = "textbox combobox checkbox barbox windowbox";
4283 Tcl_AppendResult(interp, cp, 0);
4284 return TCL_OK;
4285 }
4286 stylePtr = GetStyle(interp, tvPtr, Tcl_GetString(objv[3]));
4287 if (stylePtr == NULL) {
4288 return TCL_ERROR;
4289 }
4290 if (stylePtr->flags & STYLE_CHECKBOX) {
4291 cp = "checkbox";
4292 } else if (stylePtr->flags & STYLE_COMBOBOX) {
4293 cp = "combobox";
4294 } else if (stylePtr->flags & STYLE_WINDOWBOX) {
4295 cp = "windowbox";
4296 } else if (stylePtr->flags & STYLE_BARBOX) {
4297 cp = "barbox";
4298 } else {
4299 cp = "textbox";
4300 }
4301
4302 if (objc == 4) {
4303 Tcl_AppendResult(interp, cp, 0);
4304 return TCL_OK;
4305 }
4306 if (!strcmp(stylePtr->name, "text")) {
4307 Tcl_AppendResult(interp, "can not change type of style \"text\"", 0);
4308 return TCL_ERROR;
4309 }
4310 newType = Tcl_GetString(objv[4]);
4311 nType = StyleLookup( newType );
4312 if (nType<0) {
4313 Tcl_AppendResult(interp, "unknown type: ", newType, 0);
4314 return TCL_ERROR;
4315 }
4316 /* if (!strcmp(newType, cp)) {
4317 return TCL_OK;
4318 }*/
4319 /* Change the style */
4320 newStylePtr = CreateStyle(interp, tvPtr, nType, "__%%StyleTypeSet%%_", 0, 0, 0);
4321 if (newStylePtr == NULL) {
4322 return TCL_ERROR;
4323 }
4324 newStylePtr->flags |= STYLE_USER;
4325 memcpy(&all, stylePtr, sizeof(all));
4326 memcpy(stylePtr, newStylePtr, sizeof(all));
4327 memcpy(newStylePtr, &all, sizeof(all));
4328 newStylePtr->refCount = stylePtr->refCount;
4329 stylePtr->refCount = all.tb.refCount ;
4330 newStylePtr->hashPtr = stylePtr->hashPtr;
4331 stylePtr->hashPtr = all.tb.hashPtr ;
4332 newStylePtr->name = stylePtr->name;
4333 stylePtr->name = all.tb.name ;
4334
4335 newStylePtr->flags &= ~STYLE_USER;
4336 Blt_TreeViewFreeStyle(tvPtr, newStylePtr);
4337 Blt_TreeViewUpdateStyleGCs(tvPtr, stylePtr);
4338 tvPtr->flags |= (TV_DIRTY | TV_LAYOUT | TV_SCROLL | TV_UPDATE);
4339 Blt_TreeViewMakeStyleDirty(tvPtr);
4340 Blt_TreeViewEventuallyRedraw(tvPtr);
4341 return TCL_OK;
4342 }
4343
4344 /*
4345 *----------------------------------------------------------------------
4346 *
4347 * StyleHighlightOp --
4348 *
4349 * Turns on/off highlighting for a particular style.
4350 *
4351 * .t style highlight styleName ?on|off?
4352 *
4353 * Results:
4354 * A standard Tcl result. If TCL_ERROR is returned, then
4355 * interp->result contains an error message.
4356 *
4357 *----------------------------------------------------------------------
4358 */
4359 /*ARGSUSED*/
4360 static int
4361 StyleHighlightOp(tvPtr, interp, objc, objv)
4362 TreeView *tvPtr;
4363
4364 Tcl_Interp *interp;
4365 int objc; /* Not used. */
4366 Tcl_Obj *CONST *objv;
4367 {
4368 TreeViewStyle *stylePtr;
4369 int bool, oldBool;
4370
4371 stylePtr = GetStyle(interp, tvPtr, Tcl_GetString(objv[3]));
4372 if (stylePtr == NULL) {
4373 return TCL_ERROR;
4374 }
4375 oldBool = ((stylePtr->flags & STYLE_HIGHLIGHT) != 0);
4376 if (objc<=4) {
4377 Tcl_SetObjResult(interp, Tcl_NewIntObj(oldBool));
4378 return TCL_OK;
4379 }
4380 if (Tcl_GetBooleanFromObj(interp, objv[4], &bool) != TCL_OK) {
4381 return TCL_ERROR;
4382 }
4383 if (oldBool != bool) {
4384 if (bool) {
4385 stylePtr->flags |= STYLE_HIGHLIGHT;
4386 } else {
4387 stylePtr->flags &= ~STYLE_HIGHLIGHT;
4388 }
4389 Blt_TreeViewEventuallyRedraw(tvPtr);
4390 }
4391 return TCL_OK;
4392 }
4393
4394 /*
4395 *----------------------------------------------------------------------
4396 *
4397 * StyleNamesOp --
4398 *
4399 * Lists the names of all the current styles in the treeview widget.
4400 *
4401 * .t style names
4402 *
4403 * Results:
4404 * Always TCL_OK.
4405 *
4406 *----------------------------------------------------------------------
4407 */
4408 /*ARGSUSED*/
4409 static int
4410 StyleNamesOp(tvPtr, interp, objc, objv)
4411 TreeView *tvPtr;
4412
4413 Tcl_Interp *interp;
4414 int objc; /* Not used. */
4415 Tcl_Obj *CONST *objv; /* Not used. */
4416 {
4417 Blt_HashEntry *hPtr;
4418 Blt_HashSearch cursor;
4419 Tcl_Obj *listObjPtr, *objPtr;
4420 TreeViewStyle *stylePtr;
4421
4422 listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
4423 for (hPtr = Blt_FirstHashEntry(&tvPtr->styleTable, &cursor); hPtr != NULL;
4424 hPtr = Blt_NextHashEntry(&cursor)) {
4425 stylePtr = Blt_GetHashValue(hPtr);
4426 objPtr = Tcl_NewStringObj(stylePtr->name, -1);
4427 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
4428 }
4429 Tcl_SetObjResult(interp, listObjPtr);
4430 return TCL_OK;
4431 }
4432
4433 static int
4434 StyleSlavesOp(tvPtr, interp, objc, objv)
4435 TreeView *tvPtr;
4436
4437 Tcl_Interp *interp;
4438 int objc;
4439 Tcl_Obj *CONST *objv;
4440 {
4441 Blt_HashEntry *hPtr;
4442 Blt_HashSearch cursor;
4443 char *name, *window = NULL;
4444 Tcl_DString dStr;
4445 TreeViewColumn *columnPtr = NULL;
4446 TreeViewEntry *entryPtr = NULL;
4447 TreeViewStyle *stylePtr = NULL;
4448 int visible;
4449 WindowCell *wcPtr;
4450 int sub = 0, chkVis = 0;
4451
4452 if (!(objc%2)) {
4453 goto argerr;
4454 }
4455 while (objc>3) {
4456 char *string;
4457
4458 string = Tcl_GetString(objv[3]);
4459 if (string[0] != '-') {
4460 argerr:
4461 Tcl_AppendResult(interp, "expected -col, -id, -style, -visible, or -info", 0);
4462 return TCL_ERROR;
4463 }
4464 if ((strcmp(string, "-col") == 0)) {
4465 if (Blt_TreeViewGetColumn(interp, tvPtr, objv[4], &columnPtr)
4466 != TCL_OK) {
4467 return TCL_ERROR;
4468 }
4469 } else if ((strcmp(string, "-info") == 0)) {
4470
4471 window = Tcl_GetString(objv[4]);
4472
4473 } else if ((strcmp(string, "-id") == 0)) {
4474 if (Blt_TreeViewGetEntry(tvPtr, objv[4], &entryPtr)
4475 != TCL_OK) {
4476 return TCL_ERROR;
4477 }
4478 } else if ((strcmp(string, "-visible") == 0)) {
4479 if (Tcl_GetBooleanFromObj(interp, objv[4], &visible) != TCL_OK) {
4480 return TCL_ERROR;
4481 }
4482 chkVis = 1;
4483 } else if ((strcmp(string, "-style") == 0)) {
4484 stylePtr = GetStyle(interp, tvPtr, Tcl_GetString(objv[4]));
4485 if (stylePtr == NULL) {
4486 return TCL_ERROR;
4487 }
4488 } else break;
4489
4490 objc -= 2;
4491 objv += 2;
4492 sub++;
4493 }
4494 if (objc != 3) {
4495 goto argerr;
4496 }
4497
4498
4499 Tcl_DStringInit(&dStr);
4500 for (hPtr = Blt_FirstHashEntry(&tvPtr->winTable, &cursor); hPtr != NULL;
4501 hPtr = Blt_NextHashEntry(&cursor)) {
4502 name = (char*)Blt_GetHashKey(&tvPtr->winTable, hPtr);
4503 if (sub) {
4504 wcPtr = (WindowCell*)Blt_GetHashValue(hPtr);
4505 if (wcPtr == NULL) continue;
4506 if (columnPtr && columnPtr != wcPtr->columnPtr) continue;
4507 if (entryPtr && entryPtr != wcPtr->entryPtr) continue;
4508 if (stylePtr && stylePtr != (TreeViewStyle*)wcPtr->stylePtr) continue;
4509 if (chkVis) {
4510 if (wcPtr->flags&TV_WINDOW_DRAW) {
4511 if (!visible) continue;
4512 } else {
4513 if (visible) continue;
4514 }
4515 }
4516 if (window) {
4517 if (wcPtr->tkwin == NULL) continue;
4518 if (strcmp(window,Tk_PathName(wcPtr->tkwin))) continue;
4519 Tcl_DStringAppendElement(&dStr, "-style");
4520 Tcl_DStringAppendElement(&dStr, wcPtr->stylePtr->name);
4521 Tcl_DStringAppendElement(&dStr, "-col");
4522 Tcl_DStringAppendElement(&dStr, wcPtr->columnPtr->key);
4523 Tcl_DStringAppendElement(&dStr, "-id");
4524 Tcl_DStringAppendElement(&dStr, Blt_Itoa(Blt_TreeNodeId(wcPtr->entryPtr->node)));
4525 Tcl_DStringAppendElement(&dStr, "-visible");
4526 Tcl_DStringAppendElement(&dStr, (wcPtr->flags&TV_WINDOW_DRAW)?"True":"False");
4527 Tcl_DStringResult(interp, &dStr);
4528 return TCL_OK;
4529 }
4530 }
4531 if (name != NULL) {
4532 Tcl_DStringAppendElement(&dStr, name);
4533 }
4534 }
4535 Tcl_DStringResult(interp, &dStr);
4536 return TCL_OK;
4537 }
4538
4539 /*
4540 *----------------------------------------------------------------------
4541 *
4542 * StyleSetOp --
4543 *
4544 * Sets a style for a given key for all the ids given.
4545 *
4546 * .t style set styleName column node...
4547 *
4548 * Results:
4549 * A standard Tcl result. If TCL_ERROR is returned, then
4550 * interp->result contains an error message.
4551 *
4552 *----------------------------------------------------------------------
4553 */
4554 static int
4555 StyleSetOp(tvPtr, interp, objc, objv)
4556 TreeView *tvPtr;
4557
4558 Tcl_Interp *interp;
4559 int objc;
4560 Tcl_Obj *CONST *objv;
4561 {
4562 TreeViewColumn *columnPtr;
4563 TreeViewEntry *entryPtr;
4564 TreeViewStyle *stylePtr = NULL, *oldStylePtr;
4565 TreeViewTagInfo info = {0};
4566 char *string;
4567 int i, count;
4568
4569 count = 0;
4570 if (Blt_TreeViewGetColumn(interp, tvPtr, objv[4], &columnPtr) != TCL_OK) {
4571 return TCL_ERROR;
4572 }
4573 string = Tcl_GetString(objv[3]);
4574 if (string[0]) {
4575 if (Blt_TreeViewGetStyleMake(interp, tvPtr, string, &stylePtr, columnPtr,
4576 NULL, NULL) != TCL_OK) {
4577 return TCL_ERROR;
4578 }
4579 stylePtr->refCount--;
4580 }
4581 if (stylePtr) {
4582 stylePtr->flags |= STYLE_LAYOUT;
4583 }
4584 for (i = 5; i < objc; i++) {
4585 if (Blt_TreeViewFindTaggedEntries(tvPtr, objv[i], &info) != TCL_OK) {
4586 return TCL_ERROR;
4587 }
4588 for (entryPtr = Blt_TreeViewFirstTaggedEntry(&info); entryPtr != NULL;
4589 entryPtr = Blt_TreeViewNextTaggedEntry(&info)) {
4590 register TreeViewValue *valuePtr;
4591
4592 if (columnPtr == &tvPtr->treeColumn) {
4593 if (stylePtr == entryPtr->realStylePtr) continue;
4594 if (stylePtr) stylePtr->refCount++;
4595 oldStylePtr = entryPtr->realStylePtr;
4596 entryPtr->realStylePtr = stylePtr;
4597 if (stylePtr) stylePtr->refCount++;
4598 if (oldStylePtr != NULL) {
4599 Blt_TreeViewFreeStyle(tvPtr, oldStylePtr);
4600 }
4601 count++;
4602 continue;
4603 }
4604
4605 for (valuePtr = entryPtr->values; valuePtr != NULL;
4606 valuePtr = valuePtr->nextPtr) {
4607 if (valuePtr->columnPtr == columnPtr) {
4608 if (stylePtr == valuePtr->stylePtr) break;
4609 if (stylePtr) stylePtr->refCount++;
4610 oldStylePtr = valuePtr->stylePtr;
4611 valuePtr->stylePtr = stylePtr;
4612 if (stylePtr) stylePtr->refCount++;
4613 if (oldStylePtr != NULL) {
4614 Blt_TreeViewFreeStyle(tvPtr, oldStylePtr);
4615 }
4616 count++;
4617 break;
4618 }
4619 }
4620 }
4621 Blt_TreeViewDoneTaggedEntries(&info);
4622 }
4623 tvPtr->flags |= (TV_DIRTY | TV_LAYOUT | TV_SCROLL | TV_UPDATE);
4624 Blt_TreeViewMakeStyleDirty(tvPtr);
4625 Blt_TreeViewEventuallyRedraw(tvPtr);
4626 Tcl_SetObjResult(interp, Tcl_NewIntObj(count));
4627 return TCL_OK;
4628 }
4629
4630 /*
4631 *----------------------------------------------------------------------
4632 *
4633 * StyleFindOp --
4634 *
4635 * Find all entries with the given style.
4636 * If a column is given, find entries with the given style in that column.
4637 *
4638 * .t style find styleName ?tagorid? ?column?
4639 *
4640 * Results:
4641 * A standard Tcl result. If TCL_ERROR is returned, then
4642 * interp->result contains an error message.
4643 *
4644 *----------------------------------------------------------------------
4645 */
4646 static int
4647 StyleFindOp(tvPtr, interp, objc, objv)
4648 TreeView *tvPtr;
4649
4650 Tcl_Interp *interp;
4651 int objc;
4652 Tcl_Obj *CONST *objv;
4653 {
4654 TreeViewEntry *entryPtr;
4655 TreeViewStyle *stylePtr;
4656 TreeViewTagInfo info = {0};
4657 TreeViewColumn *columnPtr = NULL;
4658 Tcl_Obj *listObjPtr, *objPtr;
4659
4660 if (tvPtr->styleCmd == NULL || strcmp(tvPtr->styleCmd, "%W style create textbox %V")) {
4661 stylePtr = GetStyle(interp, tvPtr, Tcl_GetString(objv[3]));
4662 if (stylePtr == NULL) {
4663 return TCL_ERROR;
4664 }
4665 } else {
4666 stylePtr = GetStyle(NULL, tvPtr, Tcl_GetString(objv[3]));
4667 if (stylePtr == NULL) {
4668 return TCL_OK;
4669 }
4670 }
4671 if (objc>5) {
4672 if (Blt_TreeViewGetColumn(interp, tvPtr, objv[5], &columnPtr) != TCL_OK) {
4673 return TCL_ERROR;
4674 }
4675 }
4676 if (objc>4) {
4677 if (Blt_TreeViewFindTaggedEntries(tvPtr, objv[4], &info) != TCL_OK) {
4678 return TCL_ERROR;
4679 }
4680 } else {
4681 objPtr = Tcl_NewStringObj("all", -1);
4682 if (Blt_TreeViewFindTaggedEntries(tvPtr, objPtr, &info) != TCL_OK) {
4683 Tcl_DecrRefCount(objPtr);
4684 return TCL_ERROR;
4685 }
4686 Tcl_DecrRefCount(objPtr);
4687 }
4688
4689 listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
4690 for (entryPtr = Blt_TreeViewFirstTaggedEntry(&info); entryPtr != NULL;
4691 entryPtr = Blt_TreeViewNextTaggedEntry(&info)) {
4692 register TreeViewValue *valuePtr;
4693
4694 if (columnPtr == NULL || columnPtr == &tvPtr->treeColumn) {
4695 if (entryPtr->realStylePtr == stylePtr) {
4696 objPtr = Tcl_NewIntObj(Blt_TreeNodeId(entryPtr->node));
4697 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
4698 continue;
4699 }
4700 }
4701
4702 for (valuePtr = entryPtr->values; valuePtr != NULL;
4703 valuePtr = valuePtr->nextPtr) {
4704 if (columnPtr && valuePtr->columnPtr != columnPtr) continue;
4705 if (valuePtr->stylePtr != stylePtr) continue;
4706 objPtr = Tcl_NewIntObj(Blt_TreeNodeId(entryPtr->node));
4707 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
4708 break;
4709 }
4710 }
4711 Blt_TreeViewDoneTaggedEntries(&info);
4712 Tcl_SetObjResult(interp, listObjPtr);
4713 return TCL_OK;
4714 }
4715
4716 /*
4717 *----------------------------------------------------------------------
4718 *
4719 * StyleTextBoxOp --
4720 *
4721 * .t style textbox "styleName" -background blue
4722 *
4723 *----------------------------------------------------------------------
4724 */
4725 /*ARGSUSED*/
4726 static int
4727 StyleTextBoxOp(tvPtr, interp, objc, objv)
4728 TreeView *tvPtr;
4729 Tcl_Interp *interp;
4730 int objc; /* Not used. */
4731 Tcl_Obj *CONST *objv;
4732 {
4733 TreeViewStyle *stylePtr;
4734
4735 stylePtr = CreateStyle(interp, tvPtr, STYLE_TEXTBOX,
4736 Tcl_GetString(objv[3]), objc - 4, objv + 4, 1);
4737 if (stylePtr == NULL) {
4738 return TCL_ERROR;
4739 }
4740 stylePtr->refCount = 0;
4741 stylePtr->flags |= STYLE_USER;
4742 Blt_TreeViewUpdateStyleGCs(tvPtr, stylePtr);
4743 Tcl_SetObjResult(interp, objv[3]);
4744 return TCL_OK;
4745 }
4746
4747 /*
4748 *----------------------------------------------------------------------
4749 *
4750 * StyleWindowBoxOp --
4751 *
4752 * .t style window "styleName"
4753 *
4754 *----------------------------------------------------------------------
4755 */
4756 /*ARGSUSED*/
4757 static int
4758 StyleWindowBoxOp(tvPtr, interp, objc, objv)
4759 TreeView *tvPtr;
4760 Tcl_Interp *interp;
4761 int objc; /* Not used. */
4762 Tcl_Obj *CONST *objv;
4763 {
4764 TreeViewStyle *stylePtr;
4765
4766 stylePtr = CreateStyle(interp, tvPtr, STYLE_WINDOWBOX,
4767 Tcl_GetString(objv[3]), objc - 4, objv + 4, 1);
4768 if (stylePtr == NULL) {
4769 return TCL_ERROR;
4770 }
4771 stylePtr->refCount = 0;
4772 stylePtr->flags |= STYLE_USER;
4773 Blt_TreeViewUpdateStyleGCs(tvPtr, stylePtr);
4774 Tcl_SetObjResult(interp, objv[3]);
4775 return TCL_OK;
4776 }
4777 /*
4778 *----------------------------------------------------------------------
4779 *
4780 * StyleBarBoxOp --
4781 *
4782 * .t style textbox "styleName" -background blue
4783 *
4784 *----------------------------------------------------------------------
4785 */
4786 /*ARGSUSED*/
4787 static int
4788 StyleBarBoxOp(tvPtr, interp, objc, objv)
4789 TreeView *tvPtr;
4790 Tcl_Interp *interp;
4791 int objc; /* Not used. */
4792 Tcl_Obj *CONST *objv;
4793 {
4794 TreeViewStyle *stylePtr;
4795
4796 stylePtr = CreateStyle(interp, tvPtr, STYLE_BARBOX,
4797 Tcl_GetString(objv[3]), objc - 4, objv + 4, 1);
4798 if (stylePtr == NULL) {
4799 return TCL_ERROR;
4800 }
4801 stylePtr->refCount = 0;
4802 stylePtr->flags |= STYLE_USER;
4803 Blt_TreeViewUpdateStyleGCs(tvPtr, stylePtr);
4804 Tcl_SetObjResult(interp, objv[3]);
4805 return TCL_OK;
4806 }
4807
4808
4809 /*
4810 *----------------------------------------------------------------------
4811 *
4812 * StyleGetOp --
4813 *
4814 * Get style set for each given key for the id given.
4815 *
4816 * .t style get column tagorid
4817 *
4818 * Results:
4819 * A standard Tcl result. If TCL_ERROR is returned, then
4820 * interp->result contains an error message.
4821 *
4822 *----------------------------------------------------------------------
4823 */
4824 static int
4825 StyleGetOp(tvPtr, interp, objc, objv)
4826 TreeView *tvPtr;
4827 Tcl_Interp *interp;
4828 int objc;
4829 Tcl_Obj *CONST *objv;
4830 {
4831 TreeViewColumn *columnPtr;
4832 TreeViewEntry *entryPtr;
4833 TreeViewTagInfo info = {0};
4834 Tcl_Obj *listObjPtr, *objPtr;
4835
4836 if (Blt_TreeViewGetColumn(interp, tvPtr, objv[3], &columnPtr) != TCL_OK) {
4837 return TCL_ERROR;
4838 }
4839
4840 if (Blt_TreeViewFindTaggedEntries(tvPtr, objv[4], &info) != TCL_OK) {
4841 return TCL_ERROR;
4842 }
4843 listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL);
4844 for (entryPtr = Blt_TreeViewFirstTaggedEntry(&info); entryPtr != NULL;
4845 entryPtr = Blt_TreeViewNextTaggedEntry(&info)) {
4846 register TreeViewValue *valuePtr;
4847
4848 if (columnPtr == &tvPtr->treeColumn) {
4849 if (entryPtr->realStylePtr != NULL) {
4850 objPtr = Tcl_NewStringObj(entryPtr->realStylePtr->name, -1);
4851 } else {
4852 objPtr = Tcl_NewStringObj("",0);
4853 }
4854 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
4855 continue;
4856 }
4857
4858 for (valuePtr = entryPtr->values; valuePtr != NULL;
4859 valuePtr = valuePtr->nextPtr) {
4860 if (valuePtr->columnPtr == columnPtr) {
4861 if (valuePtr->stylePtr != NULL) {
4862 objPtr = Tcl_NewStringObj(valuePtr->stylePtr->name, -1);
4863 } else {
4864 objPtr = Tcl_NewStringObj("",0);
4865 }
4866 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);
4867 break;
4868 }
4869 }
4870 }
4871 Blt_TreeViewDoneTaggedEntries(&info);
4872 Tcl_SetObjResult(interp, listObjPtr);
4873 return TCL_OK;
4874 }
4875
4876 #if 0
4877 /*
4878 *----------------------------------------------------------------------
4879 *
4880 * StylePriorityOp --
4881 *
4882 * Get style with highest priority for given key for the id given.
4883 *
4884 * .t style priority column tagorid
4885 *
4886 * Results:
4887 * A standard Tcl result. If TCL_ERROR is returned, then
4888 * interp->result contains an error message.
4889 *
4890 *----------------------------------------------------------------------
4891 */
4892 static int
4893 StylePriorityOp(tvPtr, interp, objc, objv)
4894 TreeView *tvPtr;
4895 Tcl_Interp *interp;
4896 int objc;
4897 Tcl_Obj *CONST *objv;
4898 {
4899 TreeViewColumn *columnPtr;
4900 TreeViewEntry *entryPtr;
4901 TreeViewValue *valuePtr;
4902 TreeViewStyle *s[4];
4903 int i, h = -1, p = -1;
4904
4905 s[3] = tvPtr->stylePtr;
4906
4907 if (Blt_TreeViewGetColumn(interp, tvPtr, objv[3], &columnPtr) != TCL_OK) {
4908 return TCL_ERROR;
4909 }
4910
4911 if (Blt_TreeViewGetEntry(tvPtr, objv[4], &entryPtr) != TCL_OK) {
4912 return TCL_ERROR;
4913 }
4914
4915 if (columnPtr == &tvPtr->treeColumn) {
4916 s[0] = entryPtr->realStylePtr;
4917 } else {
4918 s[0] = NULL;
4919 for (valuePtr = entryPtr->values; valuePtr != NULL;
4920 valuePtr = valuePtr->nextPtr) {
4921 if (valuePtr->columnPtr == columnPtr) {
4922 s[0] = valuePtr->stylePtr;
4923 break;
4924 }
4925 }
4926 }
4927 s[1] = entryPtr->stylePtr;
4928 s[2] = columnPtr->stylePtr;
4929 for (i=0; i<4; i++) {
4930 if (s[i]==0) continue;
4931 if (h<0) { h = i; }
4932 if (s[i]->priority > p) {
4933 h = i;
4934 p = s[i]->priority;
4935 }
4936 }
4937 Tcl_SetObjResult(interp, Tcl_NewStringObj(s[h]->name, -1));
4938 return TCL_OK;
4939 }
4940 #endif
4941 /*
4942 *----------------------------------------------------------------------
4943 *
4944 * StyleCreateOp --
4945 *
4946 * .t style create "styleType" "styleName" -background blue
4947 *
4948 *----------------------------------------------------------------------
4949 */
4950 /*ARGSUSED*/
4951 static int
4952 StyleCreateOp(tvPtr, interp, objc, objv)
4953 TreeView *tvPtr;
4954 Tcl_Interp *interp;
4955 int objc; /* Not used. */
4956 Tcl_Obj *CONST *objv;
4957 {
4958 char *string;
4959
4960 string = Tcl_GetString(objv[3]);
4961 if (!strcmp(string, "combobox")) {
4962 return StyleComboBoxOp(tvPtr, interp, objc-1, objv+1);
4963 }
4964 if (!strcmp(string, "textbox")) {
4965 return StyleTextBoxOp(tvPtr, interp, objc-1, objv+1);
4966 }
4967 if (!strcmp(string, "barbox")) {
4968 return StyleBarBoxOp(tvPtr, interp, objc-1, objv+1);
4969 }
4970 if (!strcmp(string, "windowbox")) {
4971 return StyleWindowBoxOp(tvPtr, interp, objc-1, objv+1);
4972 }
4973 if (!strcmp(string, "checkbox")) {
4974 return StyleCheckBoxOp(tvPtr, interp, objc-1, objv+1);
4975 }
4976 Tcl_AppendResult(interp, "bad style type \"", string, "\", should be one of: textbox, barbox, checkbox, combobox, or windowbox", 0);
4977 return TCL_ERROR;
4978 }
4979
4980 /*
4981 *----------------------------------------------------------------------
4982 *
4983 * StyleOp --
4984 *
4985 * .t style activate $node $column
4986 * .t style activate
4987 * .t style cget "highlight" -foreground
4988 * .t style configure "highlight" -fg blue -bg green
4989 * .t style checkbox "highlight"
4990 * .t style highlight "highlight" on|off
4991 * .t style combobox "highlight"
4992 * .t style text "highlight"
4993 * .t style forget "highlight"
4994 * .t style get "mtime" $node
4995 * .t style names
4996 * .t style set "highlight" "mtime" all
4997 * .t style unset "mtime" all
4998 *
4999 *----------------------------------------------------------------------
5000 */
5001 static Blt_OpSpec styleOps[] = {
5002 {"activate", 1, (Blt_Op)StyleActivateOp, 3, 5,"?entry column?",},
5003 /*{"barbox", 2, (Blt_Op)StyleBarBoxOp, 4, 0, "styleName options...",},*/
5004 {"cget", 2, (Blt_Op)StyleCgetOp, 5, 5, "styleName option",},
5005 /*{"checkbox", 2, (Blt_Op)StyleCheckBoxOp, 4, 0, "styleName options...",},
5006 {"combobox", 3, (Blt_Op)StyleComboBoxOp, 4, 0, "styleName options...",},*/
5007 {"configure", 3, (Blt_Op)StyleConfigureOp, 4, 0, "styleName options...",},
5008 {"create", 2, (Blt_Op)StyleCreateOp, 5, 0, "type styleName options...",},
5009 {"find", 2, (Blt_Op)StyleFindOp, 4, 6, "styleName ?tagOrId? ?column?",},
5010 {"forget", 2, (Blt_Op)StyleForgetOp, 3, 0, "styleName...",},
5011 {"get", 1, (Blt_Op)StyleGetOp, 5, 5, "column tagOrId",},
5012 {"highlight", 1, (Blt_Op)StyleHighlightOp, 4, 5, "styleName ?boolean?",},
5013 {"names", 1, (Blt_Op)StyleNamesOp, 3, 3, "",},
5014 /*{"priority", 1, (Blt_Op)StylePriorityOp, 5, 5, "column tagOrId",}, */
5015 {"set", 2, (Blt_Op)StyleSetOp, 6, 0, "styleName column tagOrId ...",},
5016 {"slaves", 2, (Blt_Op)StyleSlavesOp, 3, 0, "?-col col? ?-entry id? ?-style name? ?-visible bool? ?-info win?",},
5017 /*{"textbox", 2, (Blt_Op)StyleTextBoxOp, 4, 0, "styleName options...",}, */
5018 {"type", 2, (Blt_Op)StyleTypeOp, 3, 5, "?styleName? ?newType?",},
5019 {"use", 2, (Blt_Op)StyleUseOp, 4, 4, "styleName",},
5020 /*{"windowbox", 2, (Blt_Op)StyleWindowBoxOp, 4, 0, "styleName options...",},*/
5021 };
5022
5023 static int nStyleOps = sizeof(styleOps) / sizeof(Blt_OpSpec);
5024
5025 int
5026 Blt_TreeViewStyleOp(tvPtr, interp, objc, objv)
5027 TreeView *tvPtr;
5028 Tcl_Interp *interp;
5029 int objc;
5030 Tcl_Obj *CONST *objv;
5031 {
5032 Blt_Op proc;
5033 int result;
5034
5035 proc = Blt_GetOpFromObj(interp, nStyleOps, styleOps, BLT_OP_ARG2, objc,
5036 objv, 0);
5037 if (proc == NULL) {
5038 return TCL_ERROR;
5039 }
5040 result = (*proc)(tvPtr, interp, objc, objv);
5041 return result;
5042 }
5043 #endif /* NO_TREEVIEW */