Debian Codegraph @

pTk/mTk/tixGeneric/tixHList.c

raw symbols SCIP
1
2 /* $Id: tixHList.c,v 1.3 2000/10/17 16:38:11 idiscovery Exp $ */
3
4 /*
5 * tixHList.c --
6 *
7 * This module implements "HList" widgets.
8 *
9 * Copyright (c) 1996, Expert Interface Technologies
10 *
11 * See the file "license.terms" for information on usage and redistribution
12 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 *
14 */
15
16 #include "tixPort.h"
17 #include "tixInt.h"
18 #include "tkInt.h"
19 #include "tixHList.h"
20 #include "tixDef.h"
21
22 /*
23 * Information used for argv parsing.
24 */
25
26 static Tk_ConfigSpec configSpecs[] = {
27 {TK_CONFIG_COLOR, "-background", "background", "Background",
28 DEF_HLIST_BG_COLOR, Tk_Offset(WidgetRecord, normalBg),
29 TK_CONFIG_COLOR_ONLY},
30
31 {TK_CONFIG_COLOR, "-background", "background", "Background",
32 DEF_HLIST_BG_MONO, Tk_Offset(WidgetRecord, normalBg),
33 TK_CONFIG_MONO_ONLY},
34
35 {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *) NULL,
36 (char *) NULL, 0, 0},
37
38 {TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL,
39 (char *) NULL, 0, 0},
40
41 {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
42 DEF_HLIST_BORDER_WIDTH, Tk_Offset(WidgetRecord, borderWidth), 0},
43
44 {TK_CONFIG_CALLBACK, "-browsecmd", "browseCmd", "BrowseCmd",
45 DEF_HLIST_BROWSE_COMMAND, Tk_Offset(WidgetRecord, browseCmd),
46 TK_CONFIG_NULL_OK},
47
48 {TK_CONFIG_INT, "-columns", "columns", "Columns",
49 DEF_HLIST_COLUMNS, Tk_Offset(WidgetRecord, numColumns),
50 TK_CONFIG_NULL_OK},
51
52 {TK_CONFIG_CALLBACK, "-command", "command", "Command",
53 DEF_HLIST_COMMAND, Tk_Offset(WidgetRecord, command),
54 TK_CONFIG_NULL_OK},
55
56 {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
57 DEF_HLIST_CURSOR, Tk_Offset(WidgetRecord, cursor),
58 TK_CONFIG_NULL_OK},
59
60 {TK_CONFIG_CALLBACK, "-dragcmd", "dragCmd", "DragCmd",
61 DEF_HLIST_DRAG_COMMAND, Tk_Offset(WidgetRecord, dragCmd),
62 TK_CONFIG_NULL_OK},
63
64 {TK_CONFIG_BOOLEAN, "-drawbranch", "drawBranch", "DrawBranch",
65 DEF_HLIST_DRAW_BRANCH, Tk_Offset(WidgetRecord, drawBranch), 0},
66
67 {TK_CONFIG_CALLBACK, "-dropcmd", "dropCmd", "DropCmd",
68 DEF_HLIST_DROP_COMMAND, Tk_Offset(WidgetRecord, dropCmd),
69 TK_CONFIG_NULL_OK},
70
71 {TK_CONFIG_BOOLEAN, "-exportselection", "exportSelection",
72 "ExportSelection", DEF_HLIST_EXPORT_SELECTION,
73 Tk_Offset(WidgetRecord, exportSelection), 0},
74
75 {TK_CONFIG_SYNONYM, "-fg", "foreground", (char *) NULL,
76 (char *) NULL, 0, 0},
77
78 {TK_CONFIG_FONT, "-font", "font", "Font",
79 DEF_HLIST_FONT, Tk_Offset(WidgetRecord, font), 0},
80
81 {TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground",
82 DEF_HLIST_FG_COLOR, Tk_Offset(WidgetRecord, normalFg),
83 TK_CONFIG_COLOR_ONLY},
84
85 {TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground",
86 DEF_HLIST_FG_MONO, Tk_Offset(WidgetRecord, normalFg),
87 TK_CONFIG_MONO_ONLY},
88
89 {TK_CONFIG_PIXELS, "-gap", "gap", "Gap",
90 DEF_HLIST_GAP, Tk_Offset(WidgetRecord, gap), 0},
91
92 {TK_CONFIG_BOOLEAN, "-header", "header", "Header",
93 DEF_HLIST_HEADER, Tk_Offset(WidgetRecord, useHeader), 0},
94
95 {TK_CONFIG_INT, "-height", "height", "Height",
96 DEF_HLIST_HEIGHT, Tk_Offset(WidgetRecord, height), 0},
97
98 {TK_CONFIG_BORDER, "-highlightbackground", "highlightBackground",
99 "HighlightBackground",
100 DEF_HLIST_BG_COLOR, Tk_Offset(WidgetRecord, border),
101 TK_CONFIG_COLOR_ONLY},
102
103 {TK_CONFIG_BORDER, "-highlightbackground", "highlightBackground",
104 "HighlightBackground",
105 DEF_HLIST_BG_MONO, Tk_Offset(WidgetRecord, border),
106 TK_CONFIG_MONO_ONLY},
107
108 {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
109 DEF_HLIST_HIGHLIGHT_COLOR, Tk_Offset(WidgetRecord, highlightColorPtr),
110 TK_CONFIG_COLOR_ONLY},
111
112 {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
113 DEF_HLIST_HIGHLIGHT_MONO, Tk_Offset(WidgetRecord, highlightColorPtr),
114 TK_CONFIG_MONO_ONLY},
115
116 {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",
117 "HighlightThickness",
118 DEF_HLIST_HIGHLIGHT_WIDTH, Tk_Offset(WidgetRecord, highlightWidth), 0},
119
120 {TK_CONFIG_PIXELS, "-indent", "indent", "Indent",
121 DEF_HLIST_INDENT, Tk_Offset(WidgetRecord, indent), 0},
122
123 {TK_CONFIG_BOOLEAN, "-indicator", "indicator", "Indicator",
124 DEF_HLIST_INDICATOR, Tk_Offset(WidgetRecord, useIndicator), 0},
125
126 {TK_CONFIG_CALLBACK, "-indicatorcmd", "indicatorCmd", "IndicatorCmd",
127 DEF_HLIST_INDICATOR_CMD, Tk_Offset(WidgetRecord, indicatorCmd),
128 TK_CONFIG_NULL_OK},
129
130 {TK_CONFIG_CUSTOM, "-itemtype", "itemType", "ItemType",
131 DEF_HLIST_ITEM_TYPE, Tk_Offset(WidgetRecord, diTypePtr),
132 0, &tixConfigItemType},
133
134 {TK_CONFIG_PIXELS, "-padx", "padX", "Pad",
135 DEF_HLIST_PADX, Tk_Offset(WidgetRecord, padX), 0},
136
137 {TK_CONFIG_PIXELS, "-pady", "padY", "Pad",
138 DEF_HLIST_PADY, Tk_Offset(WidgetRecord, padY), 0},
139
140 {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
141 DEF_HLIST_RELIEF, Tk_Offset(WidgetRecord, relief), 0},
142
143 {TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
144 DEF_HLIST_SELECT_BG_COLOR, Tk_Offset(WidgetRecord, selectBorder),
145 TK_CONFIG_COLOR_ONLY},
146
147 {TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
148 DEF_HLIST_SELECT_BG_MONO, Tk_Offset(WidgetRecord, selectBorder),
149 TK_CONFIG_MONO_ONLY},
150
151 {TK_CONFIG_PIXELS, "-selectborderwidth", "selectBorderWidth","BorderWidth",
152 DEF_HLIST_SELECT_BORDERWIDTH,Tk_Offset(WidgetRecord, selBorderWidth),0},
153
154 {TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background",
155 DEF_HLIST_SELECT_FG_COLOR, Tk_Offset(WidgetRecord, selectFg),
156 TK_CONFIG_COLOR_ONLY},
157
158 {TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background",
159 DEF_HLIST_SELECT_FG_MONO, Tk_Offset(WidgetRecord, selectFg),
160 TK_CONFIG_MONO_ONLY},
161
162 {TK_CONFIG_UID, "-selectmode", "selectMode", "SelectMode",
163 DEF_HLIST_SELECT_MODE, Tk_Offset(WidgetRecord, selectMode), 0},
164
165 {TK_CONFIG_STRING, "-separator", "separator", "Separator",
166 DEF_HLIST_SEPARATOR, Tk_Offset(WidgetRecord, separator), 0},
167
168 {TK_CONFIG_CALLBACK, "-sizecmd", "sizeCmd", "SizeCmd",
169 DEF_HLIST_SIZE_COMMAND, Tk_Offset(WidgetRecord, sizeCmd),
170 TK_CONFIG_NULL_OK},
171
172 {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",
173 DEF_HLIST_TAKE_FOCUS, Tk_Offset(WidgetRecord, takeFocus),
174 TK_CONFIG_NULL_OK},
175
176 {TK_CONFIG_BOOLEAN, "-wideselection", "wideSelection", "WideSelection",
177 DEF_HLIST_WIDE_SELECT, Tk_Offset(WidgetRecord, wideSelect), 0},
178
179 {TK_CONFIG_INT, "-width", "width", "Width",
180 DEF_HLIST_WIDTH, Tk_Offset(WidgetRecord, width), 0},
181
182 {TK_CONFIG_CALLBACK, "-xscrollcommand", "xScrollCommand", "ScrollCommand",
183 DEF_HLIST_X_SCROLL_COMMAND, Tk_Offset(WidgetRecord, xScrollCmd),
184 TK_CONFIG_NULL_OK},
185
186 {TK_CONFIG_CALLBACK, "-yscrollcommand", "yScrollCommand", "ScrollCommand",
187 DEF_HLIST_Y_SCROLL_COMMAND, Tk_Offset(WidgetRecord, yScrollCmd),
188 TK_CONFIG_NULL_OK},
189
190 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
191 (char *) NULL, 0, 0}
192 };
193
194 static Tk_ConfigSpec entryConfigSpecs[] = {
195 {TK_CONFIG_LANGARG, "-data", (char *) NULL, (char *) NULL,
196 DEF_HLISTENTRY_DATA, Tk_Offset(HListElement, data), TK_CONFIG_NULL_OK},
197
198 {TK_CONFIG_UID, "-state", (char*)NULL, (char*)NULL,
199 DEF_HLISTENTRY_STATE, Tk_Offset(HListElement, state), 0},
200
201 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
202 (char *) NULL, 0, 0}
203 };
204
205 /*
206 * Forward declarations for procedures defined later in this file:
207 */
208 /* These are standard procedures for TK widgets
209 * implemeted in C
210 */
211
212 static void WidgetCmdDeletedProc _ANSI_ARGS_((
213 ClientData clientData));
214 static int WidgetConfigure _ANSI_ARGS_((Tcl_Interp *interp,
215 WidgetPtr wPtr, int argc, char **argv,
216 int flags));
217 static void WidgetDestroy _ANSI_ARGS_((char *clientData));
218 static void WidgetEventProc _ANSI_ARGS_((ClientData clientData,
219 XEvent *eventPtr));
220 static int WidgetCommand _ANSI_ARGS_((ClientData clientData,
221 Tcl_Interp *, int argc, char **argv));
222 static void WidgetDisplay _ANSI_ARGS_((ClientData clientData));
223
224 /* Extra procedures for this widget
225 */
226 static HListElement * AllocElement _ANSI_ARGS_((WidgetPtr wPtr,
227 HListElement * parent, char * pathName,
228 char * name, char * ditemType));
229 static void AppendList _ANSI_ARGS_((WidgetPtr wPtr,
230 HListElement *parent, HListElement *chPtr, int at,
231 HListElement *afterPtr,
232 HListElement *beforePtr));
233 static void CancelRedrawWhenIdle _ANSI_ARGS_((
234 WidgetPtr wPtr));
235 static void CheckScrollBar _ANSI_ARGS_((WidgetPtr wPtr,
236 int which));
237 static void ComputeBranchPosition _ANSI_ARGS_((
238 WidgetPtr wPtr, HListElement *chPtr));
239 static void ComputeElementGeometry _ANSI_ARGS_((WidgetPtr wPtr,
240 HListElement *chPtr, int indent));
241 static void ComputeOneElementGeometry _ANSI_ARGS_((WidgetPtr wPtr,
242 HListElement *chPtr, int indent));
243 static int ConfigElement _ANSI_ARGS_((WidgetPtr wPtr,
244 HListElement *chPtr, int argc, char ** argv,
245 int flags, int forced));
246 static int CurSelection _ANSI_ARGS_((Tcl_Interp * interp,
247 WidgetPtr wPtr, HListElement * chPtr));
248 static void DeleteNode _ANSI_ARGS_((WidgetPtr wPtr,
249 HListElement * chPtr));
250 static void DeleteOffsprings _ANSI_ARGS_((WidgetPtr wPtr,
251 HListElement * chPtr));
252 static void DeleteSiblings _ANSI_ARGS_((WidgetPtr wPtr,
253 HListElement * chPtr));
254 static void DrawElements _ANSI_ARGS_((WidgetPtr wPtr,
255 Pixmap pixmap, GC gc, HListElement * chPtr,
256 int x, int y, int xOffset));
257 static void DrawOneElement _ANSI_ARGS_((WidgetPtr wPtr,
258 Pixmap pixmap, GC gc, HListElement * chPtr,
259 int x, int y, int xOffset));
260 static HListElement * FindElementAtPosition _ANSI_ARGS_((WidgetPtr wPtr,
261 int y));
262 static HListElement * FindNextEntry _ANSI_ARGS_((WidgetPtr wPtr,
263 HListElement * chPtr));
264 static HListElement * FindPrevEntry _ANSI_ARGS_((WidgetPtr wPtr,
265 HListElement * chPtr));
266 static void FreeElement _ANSI_ARGS_((WidgetPtr wPtr,
267 HListElement * chPtr));
268 static HListElement * NewElement _ANSI_ARGS_((Tcl_Interp *interp,
269 WidgetPtr wPtr, int argc, char ** argv,
270 char * pathName, char * defParentName,
271 int * newArgc, Tcl_Obj *** newArgv));
272 static void RedrawWhenIdle _ANSI_ARGS_((WidgetPtr wPtr));
273 static int XScrollByPages _ANSI_ARGS_((WidgetPtr wPtr,
274 int count));
275 static int XScrollByUnits _ANSI_ARGS_((WidgetPtr wPtr,
276 int count));
277 static int YScrollByPages _ANSI_ARGS_((WidgetPtr wPtr,
278 int count));
279 static int YScrollByUnits _ANSI_ARGS_((WidgetPtr wPtr,
280 int count));
281 static int SelectionModifyRange _ANSI_ARGS_((WidgetPtr wPtr,
282 HListElement * from, HListElement * to,
283 int select));
284 static void SelectionAdd _ANSI_ARGS_((WidgetPtr wPtr,
285 HListElement * chPtr));
286 static void HL_SelectionClear _ANSI_ARGS_((WidgetPtr wPtr,
287 HListElement * chPtr));
288 static void HL_SelectionClearAll _ANSI_ARGS_((WidgetPtr wPtr,
289 HListElement * chPtr, int *changed_ret));
290 static void HL_SelectionClearNotifyAncestors _ANSI_ARGS_((
291 WidgetPtr wPtr, HListElement * chPtr));
292 static void SelectionNotifyAncestors _ANSI_ARGS_((
293 WidgetPtr wPtr, HListElement * chPtr));
294 static void UpdateOneScrollBar _ANSI_ARGS_((WidgetPtr wPtr,
295 LangCallback *command, int total, int window, int first));
296 static void UpdateScrollBars _ANSI_ARGS_((WidgetPtr wPtr,
297 int sizeChanged));
298 static void DItemSizeChangedProc _ANSI_ARGS_((
299 Tix_DItem *iPtr));
300 static void SubWindowEventProc _ANSI_ARGS_((ClientData clientData,
301 XEvent *eventPtr));
302 static void GetScrollFractions _ANSI_ARGS_((int total,
303 int window, int first, double * first_ret,
304 double * last_ret));
305 static int Tix_HLSeeElement _ANSI_ARGS_((
306 WidgetPtr wPtr, HListElement * chPtr,
307 int callRedraw));
308 static int Tix_HLBBox _ANSI_ARGS_((Tcl_Interp * interp,
309 WidgetPtr wPtr, HListElement * chPtr));
310 static void GetSelectedText _ANSI_ARGS_((WidgetPtr wPtr,
311 HListElement * chPtr, Tcl_DString * selection));
312
313 static int HListFetchSelection _ANSI_ARGS_((
314 ClientData clientData, int offset, char *buffer,
315 int maxBytes));
316 static void HListLostSelection _ANSI_ARGS_((ClientData clientData));
317
318 static TIX_DECLARE_SUBCMD(Tix_HLAdd);
319 static TIX_DECLARE_SUBCMD(Tix_HLAddChild);
320 static TIX_DECLARE_SUBCMD(Tix_HLCGet);
321 static TIX_DECLARE_SUBCMD(Tix_HLConfig);
322 static TIX_DECLARE_SUBCMD(Tix_HLDelete);
323 static TIX_DECLARE_SUBCMD(Tix_HLEntryCget);
324 static TIX_DECLARE_SUBCMD(Tix_HLEntryConfig);
325 static TIX_DECLARE_SUBCMD(Tix_HLGeometryInfo);
326 static TIX_DECLARE_SUBCMD(Tix_HLHide);
327 static TIX_DECLARE_SUBCMD(Tix_HLInfo);
328 static TIX_DECLARE_SUBCMD(Tix_HLNearest);
329 static TIX_DECLARE_SUBCMD(Tix_HLSee);
330 static TIX_DECLARE_SUBCMD(Tix_HLSelection);
331 static TIX_DECLARE_SUBCMD(Tix_HLSetSite);
332 static TIX_DECLARE_SUBCMD(Tix_HLShow);
333 static TIX_DECLARE_SUBCMD(Tix_HLXView);
334 static TIX_DECLARE_SUBCMD(Tix_HLYView);
335
336
337
338 /*
339 *--------------------------------------------------------------
340 *
341 * Tix_HListCmd --
342 *
343 * This procedure is invoked to process the "HList" Tcl
344 * command. It creates a new "HList" widget.
345 *
346 * Results:
347 * A standard Tcl result.
348 *
349 * Side effects:
350 * A new widget is created and configured.
351 *
352 *--------------------------------------------------------------
353 */
354 int
355 Tix_HListCmd(clientData, interp, argc, argv)
356 ClientData clientData;
357 Tcl_Interp *interp; /* Current interpreter. */
358 int argc; /* Number of arguments. */
359 char **argv; /* Argument strings. */
360 {
361 Tk_Window mainw = (Tk_Window) clientData;
362 WidgetPtr wPtr;
363 Tk_Window tkwin, subwin;
364
365 if (argc < 2) {
366 Tcl_AppendResult(interp, "wrong # args: should be \"",
367 argv[0], " pathName ?options?\"", (char *) NULL);
368 return TCL_ERROR;
369 }
370
371 /*
372 * Allocate the main window for this window. Then allocate a subwindow
373 * to act as the header. The subwidget will always be raised to the top
374 * so that it won't be obscured by any window items
375 */
376 tkwin = Tk_CreateWindowFromPath(interp, mainw, argv[1], (char *) NULL);
377 if (tkwin == NULL) {
378 return TCL_ERROR;
379 }
380 subwin = Tix_CreateSubWindow(interp, tkwin, "header");
381 if (subwin == NULL) {
382 Tk_DestroyWindow(tkwin);
383 return TCL_ERROR;
384 }
385
386 Tk_SetClass(tkwin, "TixHList");
387 Tk_SetClass(subwin, "TixHListHeader");
388
389 /*
390 * Allocate and initialize the widget record.
391 */
392 wPtr = (WidgetPtr) ckalloc(sizeof(WidgetRecord));
393
394 /* Init the hash table first (needed before calling AllocElement) */
395 Tcl_InitHashTable(&wPtr->childTable, TCL_STRING_KEYS);
396
397 wPtr->dispData.tkwin = tkwin;
398 wPtr->dispData.display = Tk_Display(tkwin);
399 wPtr->dispData.interp = interp;
400 wPtr->dispData.sizeChangedProc = DItemSizeChangedProc;
401 wPtr->font = NULL;
402 wPtr->normalBg = NULL;
403 wPtr->normalFg = NULL;
404 wPtr->border = NULL;
405 wPtr->borderWidth = 0;
406 wPtr->selectBorder = NULL;
407 wPtr->selBorderWidth = 0;
408 wPtr->selectFg = NULL;
409 wPtr->backgroundGC = None;
410 wPtr->normalGC = None;
411 wPtr->selectGC = None;
412 wPtr->anchorGC = None;
413 wPtr->dropSiteGC = None;
414 wPtr->highlightWidth = 0;
415 wPtr->highlightColorPtr = NULL;
416 wPtr->highlightGC = None;
417 wPtr->relief = TK_RELIEF_FLAT;
418 wPtr->cursor = None;
419 wPtr->indent = 0;
420 wPtr->resizing = 0;
421 wPtr->redrawing = 0;
422 wPtr->hasFocus = 0;
423 wPtr->topPixel = 0;
424 wPtr->leftPixel = 0;
425 wPtr->separator = NULL;
426 wPtr->selectMode = NULL;
427 wPtr->anchor = NULL;
428 wPtr->dragSite = NULL;
429 wPtr->dropSite = NULL;
430 wPtr->command = NULL;
431 wPtr->browseCmd = NULL;
432 wPtr->sizeCmd = NULL;
433 wPtr->dragCmd = NULL;
434 wPtr->dropCmd = NULL;
435 wPtr->takeFocus = NULL;
436 wPtr->xScrollCmd = NULL;
437 wPtr->yScrollCmd = NULL;
438 wPtr->scrollUnit[0] = 1;
439 wPtr->scrollUnit[1] = 1;
440 wPtr->serial = 0;
441 wPtr->numColumns = 1;
442 wPtr->initialized = 0;
443 wPtr->allDirty = 0;
444 wPtr->headerDirty = 0;
445 wPtr->needToRaise = 0;
446 wPtr->drawBranch = 1;
447 wPtr->wideSelect = 0;
448 wPtr->diTypePtr = NULL;
449 wPtr->reqSize = NULL;
450 wPtr->actualSize = NULL;
451 wPtr->root = NULL;
452 wPtr->totalSize[0] = 1;
453 wPtr->totalSize[1] = 1;
454 wPtr->useIndicator = 0;
455 wPtr->indicatorCmd = NULL;
456 wPtr->headers = NULL;
457 wPtr->useHeader = 0;
458 wPtr->headerHeight = 0;
459 wPtr->headerWin = subwin;
460 wPtr->elmToSee = 0;
461
462 Tix_LinkListInit(&wPtr->mappedWindows);
463
464 Tk_CreateEventHandler(wPtr->dispData.tkwin,
465 ExposureMask|StructureNotifyMask|FocusChangeMask,
466 WidgetEventProc, (ClientData) wPtr);
467 Tk_CreateEventHandler(wPtr->headerWin,
468 ExposureMask|StructureNotifyMask,
469 SubWindowEventProc, (ClientData) wPtr);
470 Tk_CreateSelHandler(wPtr->dispData.tkwin, XA_PRIMARY, XA_STRING,
471 HListFetchSelection, (ClientData) wPtr, XA_STRING);
472
473 wPtr->widgetCmd = Tcl_CreateCommand(interp,
474 Tk_PathName(wPtr->dispData.tkwin), WidgetCommand, (ClientData) wPtr,
475 WidgetCmdDeletedProc);
476 if (WidgetConfigure(interp, wPtr, argc-2, argv+2, 0) != TCL_OK) {
477 Tk_DestroyWindow(wPtr->dispData.tkwin);
478 return TCL_ERROR;
479 }
480 if (Tix_HLCreateHeaders(interp, wPtr) != TCL_OK) {
481 Tk_DestroyWindow(wPtr->dispData.tkwin);
482 return TCL_ERROR;
483 }
484
485 /* Must call this **after** wPtr->numColumns is set */
486 wPtr->reqSize = Tix_HLAllocColumn(wPtr, NULL);
487 wPtr->actualSize = Tix_HLAllocColumn(wPtr, NULL);
488 wPtr->root = AllocElement(wPtr, 0, 0, 0, 0);
489
490 wPtr->initialized = 1;
491
492 interp->result = Tk_PathName(wPtr->dispData.tkwin);
493 return TCL_OK;
494 }
495
496
497 /*
498 *--------------------------------------------------------------
499 *
500 * WidgetCommand --
501 *
502 * This procedure is invoked to process the Tcl command
503 * that corresponds to a widget managed by this module.
504 * See the user documentation for details on what it does.
505 *
506 * Results:
507 * A standard Tcl result.
508 *
509 * Side effects:
510 * See the user documentation.
511 *
512 *--------------------------------------------------------------
513 */
514
515 static int
516 WidgetCommand(clientData, interp, argc, argv)
517 ClientData clientData; /* Information about the widget. */
518 Tcl_Interp *interp; /* Current interpreter. */
519 int argc; /* Number of arguments. */
520 char **argv; /* Argument strings. */
521 {
522 int code;
523
524 static Tix_SubCmdInfo subCmdInfo[] = {
525 {TIX_DEFAULT_LEN, "add", 1, TIX_VAR_ARGS, Tix_HLAdd,
526 "entryPath"},
527 {TIX_DEFAULT_LEN, "addchild", 1, TIX_VAR_ARGS, Tix_HLAddChild,
528 "parentEntryPath"},
529 {TIX_DEFAULT_LEN, "anchor", 1, 2, Tix_HLSetSite,
530 "option ?entryPath?"},
531 {TIX_DEFAULT_LEN, "cget", 1, 1, Tix_HLCGet,
532 "option"},
533 {TIX_DEFAULT_LEN, "column", 0, TIX_VAR_ARGS, Tix_HLColumn,
534 "?option? ?args ...?"},
535 {TIX_DEFAULT_LEN, "configure", 0, TIX_VAR_ARGS, Tix_HLConfig,
536 "?option? ?value? ?option value ... ?"},
537 {TIX_DEFAULT_LEN, "delete", 1, 2, Tix_HLDelete,
538 "option ?entryPath?"},
539 {TIX_DEFAULT_LEN, "dragsite", 1, 2, Tix_HLSetSite,
540 "option ?entryPath?"},
541 {TIX_DEFAULT_LEN, "dropsite", 1, 2, Tix_HLSetSite,
542 "option ?entryPath?"},
543 {TIX_DEFAULT_LEN, "entrycget", 2, 2, Tix_HLEntryCget,
544 "entryPath option"},
545 {TIX_DEFAULT_LEN, "entryconfigure", 1, TIX_VAR_ARGS, Tix_HLEntryConfig,
546 "entryPath ?option? ?value? ?option value ... ?"},
547 {TIX_DEFAULT_LEN, "geometryinfo", 0, 2, Tix_HLGeometryInfo,
548 "?width height?"},
549 {TIX_DEFAULT_LEN, "header", 1, TIX_VAR_ARGS, Tix_HLHeader,
550 "option ?args ...?"},
551 {TIX_DEFAULT_LEN, "hide", 2, 2, Tix_HLHide,
552 "option entryPath"},
553 {TIX_DEFAULT_LEN, "item", 0, TIX_VAR_ARGS, Tix_HLItem,
554 "?option? ?args ...?"},
555 {TIX_DEFAULT_LEN, "indicator", 1, TIX_VAR_ARGS, Tix_HLIndicator,
556 "option ?args ...?"},
557 {TIX_DEFAULT_LEN, "info", 1, TIX_VAR_ARGS, Tix_HLInfo,
558 "option ?args ...?"},
559 {TIX_DEFAULT_LEN, "nearest", 1, 1, Tix_HLNearest,
560 "y"},
561 {TIX_DEFAULT_LEN, "see", 1, 1, Tix_HLSee,
562 "entryPath"},
563 {TIX_DEFAULT_LEN, "selection", 1, 3, Tix_HLSelection,
564 "option arg ?arg ...?"},
565 {TIX_DEFAULT_LEN, "show", 2, 2, Tix_HLShow,
566 "option entryPath"},
567 {TIX_DEFAULT_LEN, "xview", 0, 3, Tix_HLXView,
568 "args"},
569 {TIX_DEFAULT_LEN, "yview", 0, 3, Tix_HLYView,
570 "args"},
571 };
572
573 static Tix_CmdInfo cmdInfo = {
574 Tix_ArraySize(subCmdInfo), 1, TIX_VAR_ARGS, "?option? arg ?arg ...?",
575 };
576
577 Tcl_Preserve(clientData);
578 code = Tix_HandleSubCmds(&cmdInfo, subCmdInfo, clientData,
579 interp, argc, argv);
580 Tcl_Release(clientData);
581
582 return code;
583 }
584
585 /*----------------------------------------------------------------------
586 * "add" sub command --
587 *
588 * Add a new item into the list
589 *----------------------------------------------------------------------
590 */
591 static int
592 Tix_HLAdd(clientData, interp, argc, argv)
593 ClientData clientData;
594 Tcl_Interp *interp; /* Current interpreter. */
595 int argc; /* Number of arguments. */
596 char **argv; /* Argument strings. */
597 {
598 WidgetPtr wPtr = (WidgetPtr) clientData;
599 HListElement * chPtr;
600 char * pathName = argv[0];
601 int code = TCL_ERROR;
602 Tcl_Obj ** newArgv = NULL;
603 int newArgc = 0;
604
605 argc --;
606 argv ++;
607
608 if ((chPtr = NewElement(interp, wPtr, argc, argv, pathName,
609 NULL, &newArgc, &newArgv)) == NULL) {
610 goto cleanup;
611 }
612
613 if (newArgc > 0) {
614 if (ConfigElement(wPtr, chPtr, newArgc, newArgv, 0, 1) != TCL_OK) {
615 DeleteNode(wPtr, chPtr);
616 goto cleanup;
617 }
618 } else {
619 if (Tix_DItemConfigure(chPtr->col[0].iPtr, 0, 0, 0) != TCL_OK) {
620 DeleteNode(wPtr, chPtr);
621 goto cleanup;
622 }
623 }
624
625 Tcl_AppendResult(interp, chPtr->pathName, NULL);
626 code = TCL_OK;
627
628 cleanup:
629 if (newArgv) {
630 ckfree((void*) newArgv);
631 }
632 return code;
633 }
634
635 /*----------------------------------------------------------------------
636 * "addchild" sub command --
637 *
638 * Replacement for "add" sub command: it is more flexible and
639 * you can have default names for entries.
640 *
641 * Add a new item into the list
642 *----------------------------------------------------------------------
643 */
644 static int
645 Tix_HLAddChild(clientData, interp, argc, argv)
646 ClientData clientData;
647 Tcl_Interp *interp; /* Current interpreter. */
648 int argc; /* Number of arguments. */
649 char **argv; /* Argument strings. */
650 {
651 WidgetPtr wPtr = (WidgetPtr) clientData;
652 HListElement * chPtr;
653 char * parentName;
654 int code = TCL_ERROR;
655 Tcl_Obj ** newArgv = NULL;
656 int newArgc = 0;
657
658 parentName = argv[0];
659 if (argv[0] && strcmp(argv[0], "") == 0) {
660 parentName = NULL;
661 }
662
663 argc --;
664 argv ++;
665 if ((chPtr = NewElement(interp, wPtr, argc, argv, NULL,
666 parentName, &newArgc, &newArgv)) == NULL) {
667 goto cleanup;
668 }
669
670 if (newArgc > 0) {
671 if (ConfigElement(wPtr, chPtr, newArgc, newArgv, 0, 1) != TCL_OK) {
672 DeleteNode(wPtr, chPtr);
673 goto cleanup;
674 }
675 } else {
676 if (Tix_DItemConfigure(chPtr->col[0].iPtr, 0, 0, 0) != TCL_OK) {
677 DeleteNode(wPtr, chPtr);
678 goto cleanup;
679 }
680 }
681
682 Tcl_AppendResult(interp, chPtr->pathName, NULL);
683 code = TCL_OK;
684
685 cleanup:
686 if (newArgv) {
687 ckfree((void*) newArgv);
688 }
689 return code;
690 }
691
692 /*----------------------------------------------------------------------
693 * "anchor", "dragsite" and "dropsire" sub commands --
694 *
695 * Set/remove the anchor element
696 *----------------------------------------------------------------------
697 */
698 static int
699 Tix_HLSetSite(clientData, interp, argc, argv)
700 ClientData clientData;
701 Tcl_Interp *interp; /* Current interpreter. */
702 int argc; /* Number of arguments. */
703 char **argv; /* Argument strings. */
704 {
705 int changed = 0;
706 WidgetPtr wPtr = (WidgetPtr) clientData;
707 HListElement * chPtr;
708 HListElement ** changePtr;
709 size_t len ;
710
711 /*
712 * Determine which site should be changed.
713 */
714 len = strlen(argv[-1]);
715 if (strncmp(argv[-1], "anchor", len)==0) {
716 changePtr = &wPtr->anchor;
717 }
718 else if (strncmp(argv[-1], "dragsite", len)==0) {
719 changePtr = &wPtr->dragSite;
720 }
721 else {
722 changePtr = &wPtr->dropSite;
723 }
724
725 len = strlen(argv[0]);
726 if (strncmp(argv[0], "set", len)==0) {
727 if (argc == 2) {
728 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[1])) == NULL) {
729 return TCL_ERROR;
730 }
731 if (*changePtr != chPtr) {
732 *changePtr = chPtr;
733 changed = 1;
734 }
735 } else {
736 Tcl_AppendResult(interp, "wrong # of arguments, must be: ",
737 Tk_PathName(wPtr->dispData.tkwin), " ", argv[-1],
738 " set entryPath", NULL);
739 return TCL_ERROR;
740 }
741 }
742 else if (strncmp(argv[0], "clear", len)==0) {
743 if (*changePtr != NULL) {
744 *changePtr = NULL;
745 changed = 1;
746 }
747 }
748 else {
749 Tcl_AppendResult(interp, "wrong option \"", argv[0], "\", ",
750 "must be clear or set", NULL);
751 return TCL_ERROR;
752 }
753
754 if (changed) {
755 RedrawWhenIdle(wPtr);
756 }
757
758 return TCL_OK;
759 }
760
761 /*----------------------------------------------------------------------
762 * "cget" sub command --
763 *----------------------------------------------------------------------
764 */
765 static int
766 Tix_HLCGet(clientData, interp, argc, argv)
767 ClientData clientData;
768 Tcl_Interp *interp; /* Current interpreter. */
769 int argc; /* Number of arguments. */
770 char **argv; /* Argument strings. */
771 {
772 WidgetPtr wPtr = (WidgetPtr) clientData;
773
774 return Tk_ConfigureValue(interp, wPtr->dispData.tkwin, configSpecs,
775 (char *)wPtr, argv[0], 0);
776 }
777
778 /*----------------------------------------------------------------------
779 * "configure" sub command
780 *----------------------------------------------------------------------
781 */
782 static int
783 Tix_HLConfig(clientData, interp, argc, argv)
784 ClientData clientData;
785 Tcl_Interp *interp; /* Current interpreter. */
786 int argc; /* Number of arguments. */
787 char **argv; /* Argument strings. */
788 {
789 WidgetPtr wPtr = (WidgetPtr) clientData;
790
791 if (argc == 0) {
792 return Tk_ConfigureInfo(interp, wPtr->dispData.tkwin, configSpecs,
793 (char *) wPtr, (char *) NULL, 0);
794 } else if (argc == 1) {
795 return Tk_ConfigureInfo(interp, wPtr->dispData.tkwin, configSpecs,
796 (char *) wPtr, argv[0], 0);
797 } else {
798 return WidgetConfigure(interp, wPtr, argc, argv,
799 TK_CONFIG_ARGV_ONLY);
800 }
801 }
802
803 /*----------------------------------------------------------------------
804 * "delete" sub command
805 *----------------------------------------------------------------------
806 */
807 static int
808 Tix_HLDelete(clientData, interp, argc, argv)
809 ClientData clientData;
810 Tcl_Interp *interp; /* Current interpreter. */
811 int argc; /* Number of arguments. */
812 char **argv; /* Argument strings. */
813 {
814 WidgetPtr wPtr = (WidgetPtr) clientData;
815 HListElement * chPtr;
816 size_t len;
817
818 if (strcmp(argv[0], "all") == 0) {
819 Tix_HLMarkElementDirty(wPtr, wPtr->root);
820 DeleteOffsprings(wPtr, wPtr->root);
821
822 Tix_HLResizeWhenIdle(wPtr);
823 return TCL_OK;
824 }
825 len = strlen(argv[0]);
826
827 if (argc != 2) {
828 if ((strncmp(argv[0], "entry", len) == 0) ||
829 (strncmp(argv[0], "offsprings", len) == 0) ||
830 (strncmp(argv[0], "siblings", len) == 0)) {
831
832 goto wrong_arg;
833 }
834 else {
835 goto wrong_option;
836 }
837 }
838
839 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[1])) == NULL) {
840 return TCL_ERROR;
841 }
842
843 if (strncmp(argv[0], "entry", len) == 0) {
844 Tix_HLMarkElementDirty(wPtr, chPtr->parent);
845 DeleteNode(wPtr, chPtr);
846 }
847 else if (strncmp(argv[0], "offsprings", len) == 0) {
848 Tix_HLMarkElementDirty(wPtr, chPtr);
849 DeleteOffsprings(wPtr, chPtr);
850 }
851 else if (strncmp(argv[0], "siblings", len) == 0) {
852 Tix_HLMarkElementDirty(wPtr, chPtr);
853 DeleteSiblings(wPtr, chPtr);
854 }
855 else {
856 goto wrong_arg;
857 }
858
859 Tix_HLResizeWhenIdle(wPtr);
860 return TCL_OK;
861
862 wrong_arg:
863
864 Tcl_AppendResult(interp,
865 "wrong # of arguments, should be pathName delete ", argv[0],
866 " entryPath", NULL);
867 return TCL_ERROR;
868
869 wrong_option:
870
871 Tcl_AppendResult(interp, "unknown option \"", argv[0],
872 "\" must be all, entry, offsprings or siblings", NULL);
873 return TCL_ERROR;
874
875 }
876
877 /*----------------------------------------------------------------------
878 * "entrycget" sub command
879 *----------------------------------------------------------------------
880 */
881 static int
882 Tix_HLEntryCget(clientData, interp, argc, argv)
883 ClientData clientData;
884 Tcl_Interp *interp; /* Current interpreter. */
885 int argc; /* Number of arguments. */
886 char **argv; /* Argument strings. */
887 {
888 WidgetPtr wPtr = (WidgetPtr) clientData;
889 HListElement * chPtr;
890
891 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[0])) == NULL) {
892 return TCL_ERROR;
893 }
894 if (chPtr->col[0].iPtr == NULL) {
895 Tcl_AppendResult(interp, "Item \"", argv[0],
896 "\" does not exist", (char*)NULL);
897 return TCL_ERROR;
898 }
899 return Tix_ConfigureValue2(interp, wPtr->dispData.tkwin, (char *)chPtr,
900 entryConfigSpecs, chPtr->col[0].iPtr, argv[1], 0);
901 }
902
903 /*----------------------------------------------------------------------
904 * "entryconfigure" sub command
905 *----------------------------------------------------------------------
906 */
907 static int
908 Tix_HLEntryConfig(clientData, interp, argc, argv)
909 ClientData clientData;
910 Tcl_Interp *interp; /* Current interpreter. */
911 int argc; /* Number of arguments. */
912 char **argv; /* Argument strings. */
913 {
914 WidgetPtr wPtr = (WidgetPtr) clientData;
915 HListElement * chPtr;
916
917 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[0])) == NULL) {
918 return TCL_ERROR;
919 }
920
921 if (argc == 1) {
922 return Tix_ConfigureInfo2(interp, wPtr->dispData.tkwin,
923 (char*)chPtr, entryConfigSpecs, chPtr->col[0].iPtr,
924 (char *) NULL, 0);
925 } else if (argc == 2) {
926 return Tix_ConfigureInfo2(interp, wPtr->dispData.tkwin,
927 (char*)chPtr, entryConfigSpecs, chPtr->col[0].iPtr,
928 (char *) argv[1], 0);
929 } else {
930 return ConfigElement(wPtr, chPtr, argc-1, argv+1,
931 TK_CONFIG_ARGV_ONLY, 0);
932 }
933 }
934
935 /*----------------------------------------------------------------------
936 * "geometryinfo" sub command
937 *----------------------------------------------------------------------
938 */
939 static int
940 Tix_HLGeometryInfo(clientData, interp, argc, argv)
941 ClientData clientData;
942 Tcl_Interp *interp; /* Current interpreter. */
943 int argc; /* Number of arguments. */
944 char **argv; /* Argument strings. */
945 {
946 WidgetPtr wPtr = (WidgetPtr) clientData;
947 int qSize[2];
948 double first[2], last[2];
949 char string[80];
950
951 if (argc == 2) {
952 if (Tcl_GetIntFromObj(interp, argv[0], &qSize[0]) != TCL_OK) {
953 return TCL_ERROR;
954 }
955 if (Tcl_GetIntFromObj(interp, argv[1], &qSize[1]) != TCL_OK) {
956 return TCL_ERROR;
957 }
958 } else {
959 qSize[0] = Tk_Width (wPtr->dispData.tkwin);
960 qSize[1] = Tk_Height(wPtr->dispData.tkwin);
961 }
962 qSize[0] -= 2*wPtr->borderWidth + 2*wPtr->highlightWidth;
963 qSize[1] -= 2*wPtr->borderWidth + 2*wPtr->highlightWidth;
964
965 if (wPtr->useHeader) {
966 qSize[1] -= wPtr->headerHeight;
967 }
968
969 GetScrollFractions(wPtr->totalSize[0], qSize[0], wPtr->leftPixel,
970 &first[0], &last[0]);
971 GetScrollFractions(wPtr->totalSize[1], qSize[1], wPtr->topPixel,
972 &first[1], &last[1]);
973
974 #if 0
975 /* FIXME */
976 sprintf(string, "{%f %f} {%f %f}", first[0], last[0], first[1], last[1]);
977 Tcl_AppendResult(interp, string, NULL);
978 #else
979 /* Not quite right - one list of four rather than two lists of two */
980 Tcl_DoubleResults(interp, 4, 1, first[0], last[0], first[1], last[1]);
981 #endif
982 return TCL_OK;
983 }
984
985 /*----------------------------------------------------------------------
986 * "hide" sub command
987 *----------------------------------------------------------------------
988 */
989
990 /* %% ToDo: implement the siblings ... etc options, to match those of "delete"
991 */
992 static int
993 Tix_HLHide(clientData, interp, argc, argv)
994 ClientData clientData;
995 Tcl_Interp *interp; /* Current interpreter. */
996 int argc; /* Number of arguments. */
997 char **argv; /* Argument strings. */
998 {
999 WidgetPtr wPtr = (WidgetPtr) clientData;
1000 HListElement * chPtr;
1001
1002 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[1])) == NULL) {
1003 return TCL_ERROR;
1004 }
1005
1006 Tix_HLMarkElementDirty(wPtr, chPtr->parent);
1007 chPtr->hidden = 1;
1008
1009 Tix_HLResizeWhenIdle(wPtr);
1010 return TCL_OK;
1011 }
1012
1013 /*----------------------------------------------------------------------
1014 * "show" sub command
1015 *----------------------------------------------------------------------
1016 */
1017 static int
1018 Tix_HLShow(clientData, interp, argc, argv)
1019 ClientData clientData;
1020 Tcl_Interp *interp; /* Current interpreter. */
1021 int argc; /* Number of arguments. */
1022 char **argv; /* Argument strings. */
1023 {
1024 WidgetPtr wPtr = (WidgetPtr) clientData;
1025 HListElement * chPtr;
1026
1027 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[1])) == NULL) {
1028 return TCL_ERROR;
1029 }
1030
1031 Tix_HLMarkElementDirty(wPtr, chPtr->parent);
1032 chPtr->hidden = 0;
1033
1034 Tix_HLResizeWhenIdle(wPtr);
1035 return TCL_OK;
1036 }
1037
1038 /*----------------------------------------------------------------------
1039 * "info" sub command
1040 *----------------------------------------------------------------------
1041 */
1042 static int
1043 Tix_HLInfo(clientData, interp, argc, argv)
1044 ClientData clientData;
1045 Tcl_Interp *interp; /* Current interpreter. */
1046 int argc; /* Number of arguments. */
1047 char **argv; /* Argument strings. */
1048 {
1049 WidgetPtr wPtr = (WidgetPtr) clientData;
1050 HListElement * chPtr;
1051 size_t len = strlen(argv[0]);
1052
1053 if (strncmp(argv[0], "anchor", len)==0) {
1054 if (wPtr->anchor) {
1055 Tcl_AppendResult(interp, wPtr->anchor->pathName, NULL);
1056 }
1057 return TCL_OK;
1058 }
1059 else if (strncmp(argv[0], "bbox", len)==0) {
1060 HListElement * chPtr;
1061
1062 if (argc != 2) {
1063 return Tix_ArgcError(interp, argc+2, argv-2, 3, "entryPath");
1064 }
1065 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[1])) == NULL) {
1066 return TCL_ERROR;
1067 }
1068
1069 return Tix_HLBBox(interp, wPtr, chPtr);
1070 }
1071 else if (strncmp(argv[0], "children", len)==0) {
1072 HListElement * ptr;
1073
1074 if (argc != 1 && argc != 2) {
1075 return Tix_ArgcError(interp, argc+2, argv-2, 3, "?entryPath?");
1076 }
1077 if (argc == 1 || (argc == 2 && *argv[1]==0)) {
1078 chPtr = wPtr->root;
1079 } else {
1080 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[1])) == NULL) {
1081 return TCL_ERROR;
1082 }
1083 }
1084
1085 for (ptr=chPtr->childHead; ptr; ptr=ptr->next) {
1086 Tcl_AppendElement(interp, ptr->pathName);
1087 }
1088 return TCL_OK;
1089 }
1090 else if (strncmp(argv[0], "data", len)==0) {
1091 if (argc != 2) {
1092 return Tix_ArgcError(interp, argc+2, argv-2, 3, "entryPath");
1093 }
1094 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[1])) == NULL) {
1095 return TCL_ERROR;
1096 }
1097 Tcl_IncrRefCount(chPtr->data);
1098 Tcl_SetObjResult(interp, chPtr->data);
1099 return TCL_OK;
1100 }
1101 else if (strncmp(argv[0], "dragsite", len)==0) {
1102 if (wPtr->dragSite) {
1103 Tcl_AppendResult(interp, wPtr->dragSite->pathName, NULL);
1104 }
1105 return TCL_OK;
1106 }
1107 else if (strncmp(argv[0], "dropsite", len)==0) {
1108 if (wPtr->dropSite) {
1109 Tcl_AppendResult(interp, wPtr->dropSite->pathName, NULL);
1110 }
1111 return TCL_OK;
1112 }
1113 else if (strncmp(argv[0], "exists", len)==0) {
1114 if (argc != 2) {
1115 return Tix_ArgcError(interp, argc+2, argv-2, 3, "entryPath");
1116 }
1117 chPtr = Tix_HLFindElement(interp, wPtr, argv[1]);
1118
1119 if (chPtr) {
1120 Tcl_SetIntObj(Tcl_GetObjResult(interp), 1);
1121 } else {
1122 Tcl_SetIntObj(Tcl_GetObjResult(interp), 0);
1123 }
1124 return TCL_OK;
1125 }
1126 else if (strncmp(argv[0], "hidden", len)==0) {
1127 if (argc != 2) {
1128 return Tix_ArgcError(interp, argc+2, argv-2, 3, "entryPath");
1129 }
1130 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[1])) == NULL) {
1131 return TCL_ERROR;
1132 }
1133 if (chPtr->hidden) {
1134 Tcl_SetIntObj(Tcl_GetObjResult(interp), 1);
1135 } else {
1136 Tcl_SetIntObj(Tcl_GetObjResult(interp), 0);
1137 }
1138
1139 return TCL_OK;
1140 }
1141 else if (strncmp(argv[0], "item", len)==0) {
1142 return Tix_HLItemInfo(interp, wPtr, argc-1, argv+1);
1143 }
1144 else if (strncmp(argv[0], "next", len)==0) {
1145 HListElement * nextPtr;
1146
1147 if (argc != 2) {
1148 return Tix_ArgcError(interp, argc+2, argv-2, 3, "entryPath");
1149 }
1150
1151 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[1])) == NULL) {
1152 return TCL_ERROR;
1153 }
1154
1155 nextPtr=FindNextEntry(wPtr, chPtr);
1156
1157 if (nextPtr) {
1158 Tcl_AppendResult(interp, nextPtr->pathName, NULL);
1159 }
1160
1161 return TCL_OK;
1162 }
1163 else if (strncmp(argv[0], "parent", len)==0) {
1164 if (argc != 2) {
1165 return Tix_ArgcError(interp, argc+2, argv-2, 3, "entryPath");
1166 }
1167 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[1])) == NULL) {
1168 return TCL_ERROR;
1169 }
1170
1171 Tcl_AppendResult(interp, chPtr->parent->pathName, NULL);
1172 return TCL_OK;
1173 }
1174 else if (strncmp(argv[0], "prev", len)==0) {
1175 HListElement * prevPtr;
1176
1177 if (argc != 2) {
1178 return Tix_ArgcError(interp, argc+2, argv-2, 3, "entryPath");
1179 }
1180 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[1])) == NULL) {
1181 return TCL_ERROR;
1182 }
1183 prevPtr = FindPrevEntry(wPtr, chPtr);
1184 if (prevPtr) {
1185 Tcl_AppendResult(interp, prevPtr->pathName, NULL);
1186 }
1187
1188 return TCL_OK;
1189 }
1190 else if (strncmp(argv[0], "selection", len)==0) {
1191 return CurSelection(interp, wPtr, wPtr->root);
1192 }
1193 else {
1194 Tcl_AppendResult(interp, "unknown option \"", argv[0],
1195 "\": must be anchor, bbox, children, data, dragsite, dropsite, ",
1196 "exists, hidden, item, next, parent, prev or selection",
1197 NULL);
1198 return TCL_ERROR;
1199 }
1200 }
1201
1202 /*----------------------------------------------------------------------
1203 * "info item" sub-sub command
1204 * argv[0] = x
1205 * argv[1] = y
1206 *
1207 * returns {entryPath (indicator|column#) type component}
1208 *----------------------------------------------------------------------
1209 */
1210 int
1211 Tix_HLItemInfo(interp, wPtr, argc, argv)
1212 Tcl_Interp *interp; /* Current interpreter. */
1213 WidgetPtr wPtr; /* HList widget */
1214 int argc; /* Number of arguments. */
1215 char **argv; /* Argument strings. */
1216 {
1217 HListElement * chPtr;
1218 int itemX, itemY;
1219 int listX, listY;
1220 int widX, widY;
1221 int i, m, n;
1222 char column[20];
1223
1224 /* A hack to make result a list */
1225 Tcl_Obj *result = Tcl_NewListObj(0,NULL);
1226 Tcl_SetObjResult(interp,result);
1227
1228 if (argc != 2) {
1229 return Tix_ArgcError(interp, argc+3, argv-3, 3, "x y");
1230 }
1231 if (Tcl_GetIntFromObj(interp, argv[0], &widX) != TCL_OK) {
1232 return TCL_ERROR;
1233 }
1234 if (Tcl_GetIntFromObj(interp, argv[1], &widY) != TCL_OK) {
1235 return TCL_ERROR;
1236 }
1237 if (wPtr->root->dirty || wPtr->allDirty) {
1238 /*
1239 * We must update the geometry NOW otherwise we will get a wrong entry
1240 */
1241 Tix_HLCancelResizeWhenIdle(wPtr);
1242 Tix_HLComputeGeometry((ClientData)wPtr);
1243 }
1244 if ((chPtr = FindElementAtPosition(wPtr, widY)) == NULL) {
1245 goto none;
1246 }
1247
1248 listX = widX - wPtr->borderWidth - wPtr->highlightWidth + wPtr->leftPixel;
1249 listY = widY - wPtr->borderWidth - wPtr->highlightWidth + wPtr->topPixel;
1250
1251 if (wPtr->useHeader) {
1252 listY -= wPtr->headerHeight;
1253 }
1254
1255 itemX = listX - Tix_HLElementLeftOffset(wPtr, chPtr);
1256 itemY = listY - Tix_HLElementTopOffset (wPtr, chPtr);
1257
1258 if (itemY < 0 || itemY >= chPtr->height) {
1259 goto none;
1260 }
1261 if (itemX < 0) {
1262 goto none;
1263 }
1264
1265 if (wPtr->useIndicator && itemX < wPtr->indent) {
1266 if (chPtr->indicator) {
1267 int indCenterX;
1268 int indOffX, indOffY;
1269 int indX, indY;
1270
1271 /* This "if" is a BIG HACK */
1272 if (chPtr->parent == wPtr->root) {
1273 indCenterX = wPtr->indent/2;
1274 }
1275 else if (chPtr->parent->parent == wPtr->root) {
1276 indCenterX = chPtr->parent->branchX - wPtr->indent;
1277 } else {
1278 indCenterX = chPtr->parent->branchX;
1279 }
1280
1281 indOffX = indCenterX - Tix_DItemWidth (chPtr->indicator)/2;
1282 indOffY = chPtr->iconY - Tix_DItemHeight(chPtr->indicator)/2;
1283
1284 indX = itemX - indOffX;
1285 indY = itemY - indOffY;
1286
1287 /* Is it outside of the indicator? */
1288 if (indX < 0 || indX >= Tix_DItemWidth (chPtr->indicator)) {
1289 goto none;
1290 }
1291 if (indY < 0 || indY >= Tix_DItemHeight(chPtr->indicator)) {
1292 goto none;
1293 }
1294 Tcl_AppendElement(interp, chPtr->pathName);
1295 Tcl_AppendElement(interp, "indicator");
1296 Tcl_AppendElement(interp, Tix_DItemTypeName(chPtr->indicator));
1297 Tcl_AppendElement(interp,
1298 Tix_DItemComponent(chPtr->indicator, indX, indY));
1299 return TCL_OK;
1300 } else {
1301 goto none;
1302 }
1303 }
1304
1305 /* skip the indent part */
1306
1307 if (!wPtr->useIndicator && chPtr->parent == wPtr->root) {
1308 /* indent not used only in this case */
1309 } else {
1310 itemX -= wPtr->indent;
1311 }
1312
1313 for (m=n=0,i=0; i<wPtr->numColumns; i++) {
1314 n += wPtr->actualSize[i].width;
1315 if (listX < n) {
1316 if (n > 1) {
1317 itemX = listX - m;
1318 }
1319 goto _column;
1320 }
1321 m += wPtr->actualSize[i].width;
1322 }
1323 goto none;
1324
1325 _column:
1326 sprintf(column, "%d", i);
1327 Tcl_AppendElement(interp, chPtr->pathName);
1328 Tcl_AppendElement(interp, column);
1329
1330 if (chPtr->col[i].iPtr != NULL) {
1331 Tcl_AppendElement(interp, Tix_DItemTypeName(chPtr->col[i].iPtr));
1332 Tcl_AppendElement(interp,
1333 Tix_DItemComponent(chPtr->col[i].iPtr, itemX, itemY));
1334 }
1335 return TCL_OK;
1336
1337 none:
1338 Tcl_ResetResult(interp);
1339 return TCL_OK;
1340 }
1341
1342 /*----------------------------------------------------------------------
1343 * "nearest" sub command
1344 *----------------------------------------------------------------------
1345 */
1346 static int
1347 Tix_HLNearest(clientData, interp, argc, argv)
1348 ClientData clientData;
1349 Tcl_Interp *interp; /* Current interpreter. */
1350 int argc; /* Number of arguments. */
1351 char **argv; /* Argument strings. */
1352 {
1353 WidgetPtr wPtr = (WidgetPtr) clientData;
1354 HListElement * chPtr;
1355 int y;
1356
1357 if (Tcl_GetIntFromObj(interp, argv[0], &y) != TCL_OK) {
1358 return TCL_ERROR;
1359 }
1360 if (wPtr->root->dirty || wPtr->allDirty) {
1361 /*
1362 * We must update the geometry NOW otherwise we will get a
1363 * wrong entry.
1364 */
1365 Tix_HLCancelResizeWhenIdle(wPtr);
1366 Tix_HLComputeGeometry((ClientData)wPtr);
1367 }
1368
1369 if ((chPtr = FindElementAtPosition(wPtr, y)) != NULL) {
1370 Tcl_AppendResult(interp, chPtr->pathName, NULL);
1371 }
1372 return TCL_OK;
1373 }
1374
1375 /*----------------------------------------------------------------------
1376 * "see" sub command
1377 *----------------------------------------------------------------------
1378 */
1379 static int
1380 Tix_HLSee(clientData, interp, argc, argv)
1381 ClientData clientData;
1382 Tcl_Interp *interp; /* Current interpreter. */
1383 int argc; /* Number of arguments. */
1384 char **argv; /* Argument strings. */
1385 {
1386 WidgetPtr wPtr = (WidgetPtr) clientData;
1387 HListElement * chPtr;
1388
1389 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[0])) == NULL) {
1390 return TCL_ERROR;
1391 }
1392 if (wPtr->resizing || wPtr->redrawing) {
1393 if (wPtr->elmToSee) {
1394 ckfree(wPtr->elmToSee);
1395 }
1396 wPtr->elmToSee = tixStrDup(argv[0]);
1397 return TCL_OK;
1398 } else {
1399 Tix_HLSeeElement(wPtr, chPtr, 1);
1400
1401 return TCL_OK;
1402 }
1403 }
1404
1405 /*----------------------------------------------------------------------
1406 * Tix_HLBBox --
1407 *
1408 * Returns the visible bounding box of an HList element (x1, y1, x2, y2).
1409 * Currently only y1 and y2 matters. x1 and x2 are always the left
1410 * and right edges of the window.
1411 *
1412 * Return value:
1413 * See user documenetation.
1414 *
1415 * Side effects:
1416 * None.
1417 *----------------------------------------------------------------------
1418 */
1419
1420 static int Tix_HLBBox(interp, wPtr, chPtr)
1421 Tcl_Interp * interp; /* Interpreter to report the bbox. */
1422 WidgetPtr wPtr; /* HList widget. */
1423 HListElement * chPtr; /* Get the BBox for this element.*/
1424 {
1425 int y, height;
1426 int wXSize, wYSize; /* size of the listbox window area */
1427 int pad;
1428
1429 if (!Tk_IsMapped(wPtr->dispData.tkwin)) {
1430 return TCL_OK;
1431 }
1432
1433 if (wPtr->root->dirty || wPtr->allDirty) {
1434 /*
1435 * We must update the geometry NOW otherwise we will wrong geometry
1436 * info
1437 */
1438 Tix_HLCancelResizeWhenIdle(wPtr);
1439 Tix_HLComputeGeometry((ClientData)wPtr);
1440 }
1441
1442 y = Tix_HLElementTopOffset(wPtr, chPtr) - wPtr->topPixel;
1443 pad = wPtr->borderWidth + wPtr->highlightWidth;
1444 wXSize = Tk_Width(wPtr->dispData.tkwin ) - 2*pad;
1445 wYSize = Tk_Height(wPtr->dispData.tkwin) - 2*pad;
1446
1447 if (wXSize <= 0) {
1448 wXSize = 1;
1449 }
1450 if (wYSize <= 0) {
1451 wYSize = 1;
1452 }
1453
1454 height = chPtr->height;
1455 if (height <= 0) {
1456 height = 1;
1457 }
1458
1459 if (y >= wYSize || (y+height) <= 0) {
1460 /*
1461 * The element is not visible
1462 */
1463 return TCL_OK;
1464 } else {
1465 int x1;
1466 int y1, y2;
1467 char buff[100];
1468
1469 /*
1470 * The bounding box is clipped with the visible area of the widget.
1471 */
1472
1473 x1 = pad;
1474 y1 = y + wPtr->borderWidth + wPtr->highlightWidth;
1475 y2 = y1 + height-1;
1476
1477 if (y1 < pad) {
1478 y1 = pad;
1479 }
1480 if (y2 >= pad+wYSize) {
1481 y2 = pad+wYSize -1;
1482 }
1483
1484 if (y2 >= y1) {
1485 #ifdef _LANG
1486 Tcl_Obj *result = Tcl_NewListObj(0,NULL);
1487 Tcl_ListObjAppendElement(interp, result, Tcl_NewIntObj(x1));
1488 Tcl_ListObjAppendElement(interp, result, Tcl_NewIntObj(y1));
1489 Tcl_ListObjAppendElement(interp, result, Tcl_NewIntObj(x1+wXSize-1));
1490 Tcl_ListObjAppendElement(interp, result, Tcl_NewIntObj(y2));
1491 Tcl_SetObjResult(interp, result);
1492 #else
1493 sprintf(buff, "%d %d %d %d", x1, y1, x1+wXSize-1, y2);
1494 Tcl_SetResult(interp, buff, TCL_VOLATILE);
1495 #endif
1496 }
1497 return TCL_OK;
1498 }
1499 }
1500
1501 static int Tix_HLSeeElement(wPtr, chPtr, callRedraw)
1502 WidgetPtr wPtr;
1503 HListElement * chPtr;
1504 int callRedraw;
1505 {
1506 int x, y;
1507 int cXSize, cYSize; /* element size */
1508 int wXSize, wYSize; /* size of the listbox window area */
1509 int top, left; /* new top and left offset of the HLIst */
1510 int oldTop, oldLeft;
1511
1512 oldLeft = wPtr->leftPixel;
1513 oldTop = wPtr->topPixel;
1514
1515 x = Tix_HLElementLeftOffset(wPtr, chPtr);
1516 y = Tix_HLElementTopOffset(wPtr, chPtr);
1517 if (chPtr->col[0].iPtr) {
1518 cXSize = Tix_DItemWidth(chPtr->col[0].iPtr);
1519 } else {
1520 cXSize = chPtr->col[0].width;
1521 }
1522 cYSize = chPtr->height;
1523 wXSize = Tk_Width(wPtr->dispData.tkwin) -
1524 (2*wPtr->borderWidth + 2*wPtr->highlightWidth);
1525 wYSize = Tk_Height(wPtr->dispData.tkwin) -
1526 (2*wPtr->borderWidth + 2*wPtr->highlightWidth);
1527
1528 if (wPtr->useHeader) {
1529 wYSize -= wPtr->headerHeight;
1530 }
1531
1532 if (wXSize < 0 || wYSize < 0) {
1533 /* The window is probably not visible */
1534 return TCL_OK;
1535 }
1536
1537 if (cXSize < wXSize && wPtr->numColumns == 1) {
1538 /* Align on the X direction */
1539 left = wPtr->leftPixel;
1540 if ((x < wPtr->leftPixel) || (x+cXSize > wPtr->leftPixel+wXSize)) {
1541 if (wXSize > cXSize) {
1542 left = x - (wXSize-cXSize)/2;
1543 } else {
1544 left = x;
1545 }
1546 }
1547 } else {
1548 left = wPtr->leftPixel;
1549 }
1550
1551 /* Align on the Y direction */
1552 top = wPtr->topPixel;
1553
1554 if (cYSize < wYSize) {
1555 if ((wPtr->topPixel-y)>wYSize || (y-wPtr->topPixel-wYSize) > wYSize) {
1556 /* far away, make it middle */
1557 top = y - (wYSize-cYSize)/2;
1558 }
1559 else if (y < wPtr->topPixel) {
1560 top = y;
1561 }
1562 else if (y+cYSize > wPtr->topPixel+wYSize){
1563 top = y+cYSize - wYSize ;
1564 }
1565 if (top < 0) {
1566 top = 0;
1567 }
1568 }
1569
1570 if (oldLeft != left || oldTop != top) {
1571 wPtr->leftPixel = left;
1572 wPtr->topPixel = top;
1573
1574 UpdateScrollBars(wPtr, 0);
1575 if (callRedraw) {
1576 RedrawWhenIdle(wPtr);
1577 }
1578 return 1;
1579 } else {
1580 return 0;
1581 }
1582 }
1583
1584
1585 /*----------------------------------------------------------------------
1586 * "selection" sub command
1587 * Modify the selection in this HList box
1588 *----------------------------------------------------------------------
1589 */
1590 static int
1591 Tix_HLSelection(clientData, interp, argc, argv)
1592 ClientData clientData;
1593 Tcl_Interp *interp; /* Current interpreter. */
1594 int argc; /* Number of arguments. */
1595 char **argv; /* Argument strings. */
1596 {
1597 WidgetPtr wPtr = (WidgetPtr) clientData;
1598 HListElement * chPtr;
1599 size_t len = strlen(argv[0]);
1600 int code = TCL_OK;
1601 int changed = 0;
1602 int oldSelect = (wPtr->root != NULL &&
1603 (wPtr->root->selected || (wPtr->root->numSelectedChild > 0)));
1604
1605 if (strncmp(argv[0], "clear", len)==0) {
1606 if (argc == 1) {
1607 HL_SelectionClearAll(wPtr, wPtr->root, &changed);
1608 }
1609 else {
1610 HListElement * from, * to;
1611
1612 from = Tix_HLFindElement(interp, wPtr, argv[1]);
1613 if (from == NULL) {
1614 code = TCL_ERROR;
1615 goto done;
1616 }
1617
1618 if (argc == 3) {
1619 to = Tix_HLFindElement(interp, wPtr, argv[2]);
1620 if (to == NULL) {
1621 code = TCL_ERROR;
1622 goto done;
1623 }
1624 changed = SelectionModifyRange(wPtr, from, to, 0);
1625 }
1626 else {
1627 if (from->selected == 1) {
1628 HL_SelectionClear(wPtr, from);
1629 changed = 1;
1630 }
1631 }
1632 }
1633 }
1634 else if (strncmp(argv[0], "includes", len)==0) {
1635 if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[1])) == NULL) {
1636 code = TCL_ERROR;
1637 goto done;
1638 }
1639 if (chPtr->selected) {
1640 Tcl_SetIntObj(Tcl_GetObjResult(interp), 1);
1641 } else {
1642 Tcl_SetIntObj(Tcl_GetObjResult(interp), 0);
1643 }
1644 }
1645 else if (strncmp(argv[0], "get", len)==0) {
1646 if (argc != 1) {
1647 Tix_ArgcError(interp, argc+2, argv-2, 3, "");
1648 code = TCL_ERROR;
1649 } else {
1650 code = CurSelection(interp, wPtr, wPtr->root);
1651 }
1652 }
1653 else if (strncmp(argv[0], "set", len)==0) {
1654 HListElement * from, * to;
1655
1656 if (argc < 2 || argc > 3) {
1657 Tix_ArgcError(interp, argc+2, argv-2, 3, "from ?to?");
1658 code = TCL_ERROR;
1659 goto done;
1660 }
1661
1662 from = Tix_HLFindElement(interp, wPtr, argv[1]);
1663 if (from == NULL) {
1664 code = TCL_ERROR;
1665 goto done;
1666 }
1667
1668 if (argc == 3) {
1669 to = Tix_HLFindElement(interp, wPtr, argv[2]);
1670 if (to == NULL) {
1671 code = TCL_ERROR;
1672 goto done;
1673 }
1674 changed = SelectionModifyRange(wPtr, from, to, 1);
1675 } else {
1676 if (!from->selected && !from->hidden) {
1677 SelectionAdd(wPtr, from);
1678 changed = 1;
1679 }
1680 }
1681 }
1682 else {
1683 Tcl_AppendResult(interp, "unknown option \"", argv[0],
1684 "\": must be anchor, clear, get, includes or set", NULL);
1685 code = TCL_ERROR;
1686 }
1687
1688 done:
1689 if (changed) {
1690 /*
1691 * Claim the selection if we've suddenly started exporting it and
1692 * there is a selection to export.
1693 */
1694
1695 if (wPtr->exportSelection && !oldSelect && wPtr->root != NULL &&
1696 (wPtr->root->selected || (wPtr->root->numSelectedChild > 0))) {
1697 Tk_OwnSelection(wPtr->dispData.tkwin, XA_PRIMARY, HListLostSelection,
1698 (ClientData) wPtr);
1699 }
1700 RedrawWhenIdle(wPtr);
1701 }
1702
1703 return code;
1704 }
1705
1706 /*----------------------------------------------------------------------
1707 * "xview" sub command
1708 *----------------------------------------------------------------------
1709 */
1710 static int
1711 Tix_HLXView(clientData, interp, argc, argv)
1712 ClientData clientData;
1713 Tcl_Interp *interp; /* Current interpreter. */
1714 int argc; /* Number of arguments. */
1715 char **argv; /* Argument strings. */
1716 {
1717 WidgetPtr wPtr = (WidgetPtr) clientData;
1718 HListElement * chPtr;
1719 int leftPixel;
1720 int oldLeft = wPtr->leftPixel;
1721 if (argc == 0) {
1722 Tcl_IntResults(interp, 1, 1, wPtr->leftPixel);
1723 return TCL_OK;
1724 }
1725 else if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[0])) != NULL) {
1726 leftPixel = Tix_HLElementLeftOffset(wPtr, chPtr);
1727 }
1728 else if (Tcl_GetIntFromObj(interp, argv[0], &leftPixel) == TCL_OK) {
1729 /* %% todo backward-compatible mode */
1730
1731 }
1732 else {
1733 int type, count;
1734 double fraction;
1735
1736 Tcl_ResetResult(interp);
1737
1738 /* Tk_GetScrollInfo () wants strange argc,argv combinations .. */
1739 type = Tk_GetScrollInfo(interp, argc+2, argv-2, &fraction, &count);
1740 switch (type) {
1741 case TK_SCROLL_ERROR:
1742 return TCL_ERROR;
1743
1744 case TK_SCROLL_MOVETO:
1745 leftPixel = (int)(fraction * (double)wPtr->totalSize[0]);
1746 break;
1747
1748 case TK_SCROLL_PAGES:
1749 leftPixel = XScrollByPages(wPtr, count);
1750 break;
1751
1752 case TK_SCROLL_UNITS:
1753 leftPixel = XScrollByUnits(wPtr, count);
1754 break;
1755 }
1756 }
1757
1758 if (oldLeft != leftPixel) {
1759 wPtr->leftPixel = leftPixel;
1760 UpdateScrollBars(wPtr, 0);
1761
1762 RedrawWhenIdle(wPtr);
1763 }
1764
1765 Tcl_ResetResult(interp);
1766 return TCL_OK;
1767 }
1768
1769 /*----------------------------------------------------------------------
1770 * "yview" sub command
1771 *----------------------------------------------------------------------
1772 */
1773 static int
1774 Tix_HLYView(clientData, interp, argc, argv)
1775 ClientData clientData;
1776 Tcl_Interp *interp; /* Current interpreter. */
1777 int argc; /* Number of arguments. */
1778 char **argv; /* Argument strings. */
1779 {
1780 WidgetPtr wPtr = (WidgetPtr) clientData;
1781 HListElement * chPtr;
1782 int topPixel;
1783 int oldTop = wPtr->topPixel;
1784
1785 if (argc == 0) {
1786 Tcl_IntResults(interp, 1, 1, wPtr->topPixel);
1787 return TCL_OK;
1788 }
1789 else if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[0])) != NULL) {
1790 topPixel = Tix_HLElementTopOffset(wPtr, chPtr);
1791 }
1792 else if (Tcl_GetIntFromObj(interp, argv[0], &topPixel) == TCL_OK) {
1793 /* %% todo backward-compatible mode */
1794 }
1795 else {
1796 int type, count;
1797 double fraction;
1798
1799 Tcl_ResetResult(interp);
1800
1801 /* Tk_GetScrollInfo () wants strange argc,argv combinations .. */
1802 type = Tk_GetScrollInfo(interp, argc+2, argv-2, &fraction, &count);
1803 switch (type) {
1804 case TK_SCROLL_ERROR:
1805 return TCL_ERROR;
1806
1807 case TK_SCROLL_MOVETO:
1808 topPixel = (int)(fraction * (double)wPtr->totalSize[1]);
1809 break;
1810
1811 case TK_SCROLL_PAGES:
1812 topPixel = YScrollByPages(wPtr, count);
1813 break;
1814
1815 case TK_SCROLL_UNITS:
1816 topPixel = YScrollByUnits(wPtr, count);
1817 break;
1818 }
1819 }
1820
1821 if (oldTop != topPixel) {
1822 wPtr->topPixel = topPixel;
1823 UpdateScrollBars(wPtr, 0);
1824
1825 RedrawWhenIdle(wPtr);
1826 }
1827
1828 Tcl_ResetResult(interp);
1829 return TCL_OK;
1830 }
1831
1832 /*
1833 *----------------------------------------------------------------------
1834 *
1835 * WidgetConfigure --
1836 *
1837 * This procedure is called to process an argv/argc list in
1838 * conjunction with the Tk option database to configure (or
1839 * reconfigure) a HList widget.
1840 *
1841 * Results:
1842 * The return value is a standard Tcl result. If TCL_ERROR is
1843 * returned, then interp->result contains an error message.
1844 *
1845 * Side effects:
1846 * Configuration information, such as colors, border width,
1847 * etc. get set for wPtr; old resources get freed,
1848 * if there were any.
1849 *
1850 *----------------------------------------------------------------------
1851 */
1852 static int
1853 WidgetConfigure(interp, wPtr, argc, argv, flags)
1854 Tcl_Interp *interp; /* Used for error reporting. */
1855 WidgetPtr wPtr; /* Information about widget. */
1856 int argc; /* Number of valid entries in argv. */
1857 char **argv; /* Arguments. */
1858 int flags; /* Flags to pass to
1859 * Tk_ConfigureWidget. */
1860 {
1861 XGCValues gcValues;
1862 GC newGC;
1863 TixFont oldfont;
1864 int oldColumns;
1865 Tix_StyleTemplate stTmpl;
1866 int oldExport;
1867
1868 oldExport = wPtr->exportSelection;
1869 oldfont = wPtr->font;
1870 oldColumns = wPtr->numColumns;
1871 if (Tk_ConfigureWidget(interp, wPtr->dispData.tkwin, configSpecs,
1872 argc, argv, (char *) wPtr, flags) != TCL_OK) {
1873 return TCL_ERROR;
1874 }
1875
1876 if (wPtr->initialized && oldColumns != wPtr->numColumns) {
1877 Tcl_AppendResult(interp, "Cannot change the number of columns ",
1878 (char *) NULL);
1879 wPtr->numColumns = oldColumns;
1880 return TCL_ERROR;
1881 }
1882 if (wPtr->numColumns < 1) {
1883 wPtr->numColumns = 1;
1884 }
1885
1886 if (wPtr->separator == 0 || wPtr->separator[0] == 0) {
1887 if (wPtr->separator != 0) {
1888 ckfree(wPtr->separator);
1889 }
1890 wPtr->separator = tixStrDup(".");
1891 }
1892
1893 if (oldfont != wPtr->font) {
1894 /*
1895 * Font has been changed (initialized)
1896 */
1897 TixComputeTextGeometry(wPtr->font, "0", 1,
1898 0, &wPtr->scrollUnit[0], &wPtr->scrollUnit[1]);
1899 }
1900
1901 /*
1902 * A few options need special processing, such as setting the
1903 * background from a 3-D border, or filling in complicated
1904 * defaults that couldn't be specified to Tk_ConfigureWidget.
1905 */
1906
1907 Tk_SetBackgroundFromBorder(wPtr->dispData.tkwin, wPtr->border);
1908
1909 /*
1910 * Note: GraphicsExpose events are disabled in normalGC because it's
1911 * used to copy stuff from an off-screen pixmap onto the screen (we know
1912 * that there's no problem with obscured areas).
1913 */
1914
1915 /* The background GC */
1916 gcValues.foreground = wPtr->normalBg->pixel;
1917 gcValues.graphics_exposures = False;
1918
1919 newGC = Tk_GetGC(wPtr->dispData.tkwin,
1920 GCForeground|GCGraphicsExposures, &gcValues);
1921 if (wPtr->backgroundGC != None) {
1922 Tk_FreeGC(wPtr->dispData.display, wPtr->backgroundGC);
1923 }
1924 wPtr->backgroundGC = newGC;
1925
1926 /* The normal text GC */
1927 gcValues.font = TixFontId(wPtr->font);
1928 gcValues.foreground = wPtr->normalFg->pixel;
1929 gcValues.background = wPtr->normalBg->pixel;
1930 gcValues.graphics_exposures = False;
1931
1932 newGC = Tk_GetGC(wPtr->dispData.tkwin,
1933 GCForeground|GCBackground|GCFont|GCGraphicsExposures, &gcValues);
1934 if (wPtr->normalGC != None) {
1935 Tk_FreeGC(wPtr->dispData.display, wPtr->normalGC);
1936 }
1937 wPtr->normalGC = newGC;
1938
1939 /* The selected text GC */
1940 gcValues.font = TixFontId(wPtr->font);
1941 gcValues.foreground = wPtr->selectFg->pixel;
1942 gcValues.background = Tk_3DBorderColor(wPtr->selectBorder)->pixel;
1943 gcValues.graphics_exposures = False;
1944
1945 newGC = Tk_GetGC(wPtr->dispData.tkwin,
1946 GCForeground|GCBackground|GCFont|GCGraphicsExposures, &gcValues);
1947 if (wPtr->selectGC != None) {
1948 Tk_FreeGC(wPtr->dispData.display, wPtr->selectGC);
1949 }
1950 wPtr->selectGC = newGC;
1951
1952 /* The dotted anchor lines */
1953 gcValues.foreground = wPtr->normalFg->pixel;
1954 gcValues.background = wPtr->normalBg->pixel;
1955 gcValues.graphics_exposures = False;
1956 gcValues.line_style = LineDoubleDash;
1957 gcValues.dashes = 2;
1958 gcValues.subwindow_mode = IncludeInferiors;
1959
1960 newGC = Tk_GetGC(wPtr->dispData.tkwin,
1961 GCForeground|GCBackground|GCGraphicsExposures|GCLineStyle|GCDashList|
1962 GCSubwindowMode, &gcValues);
1963 if (wPtr->anchorGC != None) {
1964 Tk_FreeGC(wPtr->dispData.display, wPtr->anchorGC);
1965 }
1966 wPtr->anchorGC = newGC;
1967
1968 /* The sloid dropsite lines */
1969 gcValues.foreground = wPtr->normalFg->pixel;
1970 gcValues.background = wPtr->normalBg->pixel;
1971 gcValues.graphics_exposures = False;
1972 gcValues.subwindow_mode = IncludeInferiors;
1973
1974 newGC = Tk_GetGC(wPtr->dispData.tkwin,
1975 GCForeground|GCBackground|GCGraphicsExposures|GCSubwindowMode,
1976 &gcValues);
1977 if (wPtr->dropSiteGC != None) {
1978 Tk_FreeGC(wPtr->dispData.display, wPtr->dropSiteGC);
1979 }
1980 wPtr->dropSiteGC = newGC;
1981
1982 /* The highlight border */
1983 gcValues.background = wPtr->selectFg->pixel;
1984 gcValues.foreground = wPtr->highlightColorPtr->pixel;
1985 gcValues.subwindow_mode = IncludeInferiors;
1986
1987 newGC = Tk_GetGC(wPtr->dispData.tkwin,
1988 GCForeground|GCBackground|GCGraphicsExposures, &gcValues);
1989 if (wPtr->highlightGC != None) {
1990 Tk_FreeGC(wPtr->dispData.display, wPtr->highlightGC);
1991 }
1992 wPtr->highlightGC = newGC;
1993
1994 /* We must set the options of the default styles so that
1995 * -- the default styles will change according to what is in
1996 * stTmpl
1997 */
1998
1999 stTmpl.font = wPtr->font;
2000 stTmpl.pad[0] = wPtr->padX;
2001 stTmpl.pad[1] = wPtr->padY;
2002 stTmpl.colors[TIX_DITEM_NORMAL].fg = wPtr->normalFg;
2003 stTmpl.colors[TIX_DITEM_NORMAL].bg = wPtr->normalBg;
2004 stTmpl.colors[TIX_DITEM_SELECTED].fg= wPtr->selectFg;
2005 stTmpl.colors[TIX_DITEM_SELECTED].bg= Tk_3DBorderColor(wPtr->selectBorder);
2006 stTmpl.flags = TIX_DITEM_FONT|TIX_DITEM_NORMAL_BG|
2007 TIX_DITEM_SELECTED_BG|TIX_DITEM_NORMAL_FG|TIX_DITEM_SELECTED_FG |
2008 TIX_DITEM_PADX|TIX_DITEM_PADY;
2009 Tix_SetDefaultStyleTemplate(wPtr->dispData.tkwin, &stTmpl);
2010
2011 /* Probably the size of the elements in this has changed */
2012 Tix_HLResizeWhenIdle(wPtr);
2013
2014 /*
2015 * Claim the selection if we've suddenly started exporting it and
2016 * there is a selection to export.
2017 */
2018
2019 if (wPtr->exportSelection && !oldExport &&
2020 wPtr->root != NULL &&
2021 (wPtr->root->selected || (wPtr->root->numSelectedChild > 0))) {
2022 Tk_OwnSelection(wPtr->dispData.tkwin, XA_PRIMARY, HListLostSelection,
2023 (ClientData) wPtr);
2024 }
2025
2026 return TCL_OK;
2027 }
2028
2029 /*
2030 *--------------------------------------------------------------
2031 *
2032 * WidgetEventProc --
2033 *
2034 * This procedure is invoked by the Tk dispatcher for various
2035 * events on HLists.
2036 *
2037 * Results:
2038 * None.
2039 *
2040 * Side effects:
2041 * When the window gets deleted, internal structures get
2042 * cleaned up. When it gets exposed, it is redisplayed.
2043 *
2044 *--------------------------------------------------------------
2045 */
2046 static void
2047 WidgetEventProc(clientData, eventPtr)
2048 ClientData clientData; /* Information about window. */
2049 XEvent *eventPtr; /* Information about event. */
2050 {
2051 WidgetPtr wPtr = (WidgetPtr) clientData;
2052
2053 switch (eventPtr->type) {
2054 case DestroyNotify:
2055 if (wPtr->dispData.tkwin != NULL) {
2056 wPtr->dispData.tkwin = NULL;
2057 wPtr->dispData.sizeChangedProc = NULL;
2058 Tcl_DeleteCommand(wPtr->dispData.interp,
2059 Tcl_GetCommandName(wPtr->dispData.interp, wPtr->widgetCmd));
2060 }
2061 Tix_HLCancelResizeWhenIdle(wPtr);
2062 CancelRedrawWhenIdle(wPtr);
2063 Tcl_EventuallyFree((ClientData) wPtr, WidgetDestroy);
2064 break;
2065
2066 case ConfigureNotify:
2067 RedrawWhenIdle(wPtr);
2068 UpdateScrollBars(wPtr, 1);
2069 break;
2070
2071 case Expose:
2072 RedrawWhenIdle(wPtr);
2073 break;
2074
2075 case FocusIn:
2076 wPtr->hasFocus = 1;
2077 RedrawWhenIdle(wPtr);
2078 break;
2079
2080 case FocusOut:
2081 wPtr->hasFocus = 0;
2082 RedrawWhenIdle(wPtr);
2083 break;
2084 }
2085 }
2086
2087 /*
2088 *--------------------------------------------------------------
2089 *
2090 * SubWindowEventProc --
2091 *
2092 * This procedure is invoked by the Tk dispatcher for various
2093 * events on the header subwindow.
2094 *--------------------------------------------------------------
2095 */
2096 static void
2097 SubWindowEventProc(clientData, eventPtr)
2098 ClientData clientData; /* Information about window. */
2099 XEvent *eventPtr; /* Information about event. */
2100 {
2101 WidgetPtr wPtr = (WidgetPtr) clientData;
2102 Tk_FakeWin * fw;
2103
2104 switch (eventPtr->type) {
2105 case DestroyNotify:
2106
2107 #ifdef TK_PARENT_DESTROYED
2108 /*
2109 * The TK_PARENT_DESTROYED symbol is no longer defined in Tk 8.0
2110 */
2111 fw = (Tk_FakeWin *) (wPtr->headerWin);
2112 if (fw->flags & TK_PARENT_DESTROYED) {
2113 break;
2114 }
2115 if (wPtr->headerWin != NULL) {
2116 panic("HList: header subwindow deleted illegally\n");
2117 }
2118 #endif
2119 break;
2120
2121 case Expose:
2122 if (wPtr->headerWin != NULL) {
2123 RedrawWhenIdle(wPtr);
2124 }
2125 break;
2126 }
2127 }
2128
2129 /*
2130 *----------------------------------------------------------------------
2131 *
2132 * WidgetDestroy --
2133 *
2134 * This procedure is invoked by Tk_EventuallyFree or Tk_Release
2135 * to clean up the internal structure of a HList at a safe time
2136 * (when no-one is using it anymore).
2137 *
2138 * Results:
2139 * None.
2140 *
2141 * Side effects:
2142 * Everything associated with the HList is freed up.
2143 *
2144 *----------------------------------------------------------------------
2145 */
2146 static void
2147 WidgetDestroy(clientData)
2148 char *clientData; /* Info about my widget. */
2149 {
2150 WidgetPtr wPtr = (WidgetPtr) clientData;
2151
2152 if (wPtr->root != NULL) {
2153 DeleteOffsprings(wPtr, wPtr->root);
2154 FreeElement(wPtr, wPtr->root);
2155 }
2156
2157 if (wPtr->backgroundGC != None) {
2158 Tk_FreeGC(wPtr->dispData.display, wPtr->backgroundGC);
2159 }
2160 if (wPtr->normalGC != None) {
2161 Tk_FreeGC(wPtr->dispData.display, wPtr->normalGC);
2162 }
2163 if (wPtr->selectGC != None) {
2164 Tk_FreeGC(wPtr->dispData.display, wPtr->selectGC);
2165 }
2166 if (wPtr->anchorGC != None) {
2167 Tk_FreeGC(wPtr->dispData.display, wPtr->anchorGC);
2168 }
2169 if (wPtr->dropSiteGC != None) {
2170 Tk_FreeGC(wPtr->dispData.display, wPtr->dropSiteGC);
2171 }
2172 if (wPtr->highlightGC != None) {
2173 Tk_FreeGC(wPtr->dispData.display, wPtr->highlightGC);
2174 }
2175
2176 /* the following two members will be NULL if the widget was destroyed
2177 * during its creation (e.g., wrong arguments during creation
2178 */
2179 if (wPtr->reqSize != NULL) {
2180 ckfree((char*)wPtr->reqSize);
2181 }
2182 if (wPtr->actualSize != NULL) {
2183 ckfree((char*)wPtr->actualSize);
2184 }
2185 if (wPtr->elmToSee != NULL) {
2186 ckfree(wPtr->elmToSee);
2187 wPtr->elmToSee = NULL;
2188 }
2189
2190 Tix_HLFreeHeaders(wPtr->dispData.interp, wPtr);
2191
2192 if (!Tix_IsLinkListEmpty(wPtr->mappedWindows)) {
2193 /*
2194 * All mapped windows should have been unmapped when the
2195 * the entries were deleted
2196 */
2197 panic("tixHList: mappedWindows not NULL");
2198 }
2199 if (wPtr->headerWin) {
2200 wPtr->headerWin = NULL;
2201 }
2202 Tcl_DeleteHashTable(&wPtr->childTable);
2203
2204 Tk_FreeOptions(configSpecs, (char *) wPtr, wPtr->dispData.display, 0);
2205 ckfree((char *) wPtr);
2206 }
2207
2208 /*
2209 *----------------------------------------------------------------------
2210 *
2211 * WidgetCmdDeletedProc --
2212 *
2213 * This procedure is invoked when a widget command is deleted. If
2214 * the widget isn't already in the process of being destroyed,
2215 * this command destroys it.
2216 *
2217 * Results:
2218 * None.
2219 *
2220 * Side effects:
2221 * The widget is destroyed.
2222 *
2223 *----------------------------------------------------------------------
2224 */
2225 static void
2226 WidgetCmdDeletedProc(clientData)
2227 ClientData clientData; /* Pointer to widget record for widget. */
2228 {
2229 WidgetPtr wPtr = (WidgetPtr) clientData;
2230
2231 /*
2232 * This procedure could be invoked either because the window was
2233 * destroyed and the command was then deleted (in which case tkwin
2234 * is NULL) or because the command was deleted, and then this procedure
2235 * destroys the widget.
2236 */
2237 if (wPtr->dispData.tkwin != NULL) {
2238 Tk_Window tkwin = wPtr->dispData.tkwin;
2239 wPtr->dispData.tkwin = NULL;
2240 wPtr->dispData.sizeChangedProc = NULL;
2241 Tk_DestroyWindow(tkwin);
2242 }
2243 }
2244
2245 /*
2246 *--------------------------------------------------------------
2247 *
2248 * Tix_HLComputeGeometry --
2249 *
2250 * This procedure is invoked to process the Tcl command
2251 * that corresponds to a widget managed by this module.
2252 * See the user documentation for details on what it does.
2253 *
2254 * Results:
2255 * A standard Tcl result.
2256 *
2257 * Side effects:
2258 * none
2259 *
2260 *--------------------------------------------------------------
2261 */
2262 void
2263 Tix_HLComputeGeometry(clientData)
2264 ClientData clientData;
2265 {
2266 WidgetPtr wPtr = (WidgetPtr)clientData;
2267 int i, reqW, reqH;
2268 int sizeChanged = 0;
2269 int width = 0;
2270
2271 if (wPtr->dispData.tkwin == NULL) {
2272 panic("No tkwin");
2273 return;
2274 }
2275
2276 wPtr->resizing = 0;
2277
2278 /* Update geometry request */
2279 if (wPtr->useHeader && wPtr->headerDirty) {
2280 Tix_HLComputeHeaderGeometry(wPtr);
2281 }
2282
2283 if (wPtr->root->dirty || wPtr->allDirty) {
2284 if (wPtr->useIndicator) {
2285 /*
2286 * If we use indicator, then the toplevel elements are indented
2287 * by wPtr->indent. Otherwise they are indented by 0 pixels
2288 */
2289 ComputeElementGeometry(wPtr, wPtr->root, wPtr->indent);
2290 } else {
2291 ComputeElementGeometry(wPtr, wPtr->root, 0);
2292 }
2293 }
2294 width = 0;
2295 for (i=0; i<wPtr->numColumns; i++) {
2296 if (wPtr->reqSize[i].width != UNINITIALIZED) {
2297 wPtr->actualSize[i].width = wPtr->reqSize[i].width;
2298 }
2299 else {
2300 /* This is the req size of the entry columns */
2301 int entReq = wPtr->root->col[i].width;
2302
2303 /* This is the req size of the header columns */
2304 int hdrReq = wPtr->headers[i]->width;
2305
2306 if (wPtr->useHeader && (hdrReq > entReq)) {
2307 wPtr->actualSize[i].width = hdrReq;
2308 } else {
2309 wPtr->actualSize[i].width = entReq;
2310 }
2311 }
2312 width += wPtr->actualSize[i].width;
2313 }
2314 sizeChanged = 1;
2315 wPtr->allDirty = 0;
2316
2317 wPtr->totalSize[0] = width;
2318 wPtr->totalSize[1] = wPtr->root->allHeight;
2319
2320 if (wPtr->width > 0) {
2321 reqW = wPtr->width * wPtr->scrollUnit[0];
2322 } else {
2323 reqW = width;
2324 }
2325 if (wPtr->height > 0) {
2326 reqH = wPtr->height * wPtr->scrollUnit[1];
2327 } else {
2328 reqH = wPtr->root->allHeight;
2329 }
2330
2331 wPtr->totalSize[0] += 2*wPtr->borderWidth + 2*wPtr->highlightWidth;
2332 wPtr->totalSize[1] += 2*wPtr->borderWidth + 2*wPtr->highlightWidth;
2333 reqW += 2*wPtr->borderWidth + 2*wPtr->highlightWidth;
2334 reqH += 2*wPtr->borderWidth + 2*wPtr->highlightWidth;
2335
2336 if (wPtr->useHeader) {
2337 reqH += wPtr->headerHeight;
2338 }
2339
2340 /* Now we need to handle the multiple columns mode */
2341
2342 Tk_GeometryRequest(wPtr->dispData.tkwin, reqW, reqH);
2343
2344 /* Update scrollbars */
2345 UpdateScrollBars(wPtr, sizeChanged);
2346
2347 RedrawWhenIdle(wPtr);
2348 }
2349
2350 /*
2351 *----------------------------------------------------------------------
2352 * Tix_HLResizeWhenIdle --
2353 *----------------------------------------------------------------------
2354 */
2355 void
2356 Tix_HLResizeWhenIdle(wPtr)
2357 WidgetPtr wPtr;
2358 {
2359 if (wPtr->dispData.tkwin == NULL) {
2360 panic("No tkwin");
2361 return;
2362 }
2363
2364 if (!wPtr->resizing) {
2365 wPtr->resizing = 1;
2366 Tcl_DoWhenIdle(Tix_HLComputeGeometry, (ClientData)wPtr);
2367 }
2368 if (wPtr->redrawing) {
2369 CancelRedrawWhenIdle(wPtr);
2370 }
2371 }
2372
2373 /*
2374 *----------------------------------------------------------------------
2375 * Tix_HLResizeNow --
2376 *----------------------------------------------------------------------
2377 */
2378 void
2379 Tix_HLResizeNow(wPtr)
2380 WidgetPtr wPtr;
2381 {
2382 if (wPtr->resizing) {
2383 wPtr->resizing = 0;
2384 Tcl_CancelIdleCall(Tix_HLComputeGeometry, (ClientData)wPtr);
2385 Tix_HLComputeGeometry((ClientData)wPtr);
2386 }
2387 }
2388
2389 /*
2390 *----------------------------------------------------------------------
2391 * Tix_HLCancelResizeWhenIdle --
2392 *----------------------------------------------------------------------
2393 */
2394 void
2395 Tix_HLCancelResizeWhenIdle(wPtr)
2396 WidgetPtr wPtr;
2397 {
2398 if (wPtr->resizing) {
2399 wPtr->resizing = 0;
2400 Tcl_CancelIdleCall(Tix_HLComputeGeometry, (ClientData)wPtr);
2401 }
2402 }
2403
2404 /*
2405 *----------------------------------------------------------------------
2406 * RedrawWhenIdle --
2407 *----------------------------------------------------------------------
2408 */
2409 static void
2410 RedrawWhenIdle(wPtr)
2411 WidgetPtr wPtr;
2412 {
2413 if (wPtr->dispData.tkwin == NULL) {
2414 panic("No tkwin");
2415 return;
2416 }
2417
2418 if (!wPtr->redrawing && Tk_IsMapped(wPtr->dispData.tkwin)) {
2419 wPtr->redrawing = 1;
2420 Tcl_DoWhenIdle(WidgetDisplay, (ClientData)wPtr);
2421 }
2422 }
2423
2424 /*
2425 *----------------------------------------------------------------------
2426 * CancelRedrawWhenIdle --
2427 *----------------------------------------------------------------------
2428 */
2429 static void
2430 CancelRedrawWhenIdle(wPtr)
2431 WidgetPtr wPtr;
2432 {
2433
2434 if (wPtr->redrawing) {
2435 wPtr->redrawing = 0;
2436 Tcl_CancelIdleCall(WidgetDisplay, (ClientData)wPtr);
2437 }
2438 }
2439
2440 /*----------------------------------------------------------------------
2441 * DItemSizeChangedProc --
2442 *
2443 * This is called whenever the size of one of the HList's items
2444 * changes its size.
2445 *----------------------------------------------------------------------
2446 */
2447 static void DItemSizeChangedProc(iPtr)
2448 Tix_DItem *iPtr;
2449 {
2450 HLItemTypeInfo * info = (HLItemTypeInfo *)iPtr->base.clientData;
2451 HListColumn * colPtr;
2452 HListElement * chPtr;
2453 HListHeader * hPtr;
2454 WidgetPtr wPtr;
2455
2456 if (info == NULL) {
2457 /* Perhaps we haven't set the clientData yet! */
2458 return;
2459 }
2460
2461 switch (info->type) {
2462 case HLTYPE_COLUMN:
2463 colPtr = (HListColumn*) info;
2464 chPtr = colPtr->chPtr;
2465
2466 if (chPtr) { /* Sanity check */
2467 Tix_HLMarkElementDirty(chPtr->wPtr, chPtr);
2468 Tix_HLResizeWhenIdle(chPtr->wPtr);
2469 }
2470 break;
2471 case HLTYPE_HEADER:
2472 hPtr = (HListHeader*)info;
2473 wPtr = hPtr->wPtr;
2474 wPtr->headerDirty = 1;
2475 if (wPtr->useHeader) {
2476 Tix_HLResizeWhenIdle(wPtr);
2477 }
2478 break;
2479 case HLTYPE_ENTRY:
2480 chPtr = (HListElement*)info;
2481
2482 if (chPtr) { /* Sanity check */
2483 Tix_HLMarkElementDirty(chPtr->wPtr, chPtr);
2484 Tix_HLResizeWhenIdle(chPtr->wPtr);
2485 }
2486 break;
2487 }
2488 }
2489
2490 /*
2491 *--------------------------------------------------------------
2492 *
2493 * AllocElement --
2494 *
2495 * Allocates a new structure for the new element and record it
2496 * in the hash table
2497 *
2498 * Results:
2499 * a pointer to the new element's structure
2500 *
2501 * Side effects:
2502 * Has table is changed
2503 *--------------------------------------------------------------
2504 */
2505 static HListElement *
2506 AllocElement(wPtr, parent, pathName, name, ditemType)
2507 WidgetPtr wPtr;
2508 HListElement * parent;
2509 char * pathName;
2510 char * name;
2511 char * ditemType;
2512 {
2513 HListElement * chPtr;
2514 Tcl_HashEntry * hashPtr;
2515 int dummy;
2516 Tix_DItem * iPtr;
2517
2518 if (ditemType == NULL) {
2519 iPtr = NULL;
2520 } else {
2521 if ((iPtr = Tix_DItemCreate(&wPtr->dispData, ditemType)) == NULL) {
2522 return NULL;
2523 }
2524 }
2525
2526 chPtr = (HListElement*)ckalloc(sizeof(HListElement));
2527
2528 if (pathName) {
2529 /* pathName == 0 is the root element */
2530 hashPtr = Tcl_CreateHashEntry(&wPtr->childTable, pathName, &dummy);
2531 Tcl_SetHashValue(hashPtr, (char*)chPtr);
2532 }
2533
2534 if (parent) {
2535 ++ parent->numCreatedChild;
2536 }
2537
2538 if (wPtr->numColumns > 1) {
2539 chPtr->col = Tix_HLAllocColumn(wPtr, chPtr);
2540 } else {
2541 chPtr->col = &chPtr->_oneCol;
2542 chPtr->_oneCol.type = HLTYPE_COLUMN;
2543 chPtr->_oneCol.self = (char*) &chPtr->_oneCol;
2544 chPtr->_oneCol.chPtr = chPtr;
2545 chPtr->_oneCol.iPtr = NULL;
2546 chPtr->_oneCol.width = 0;
2547 }
2548 if (pathName) {
2549 chPtr->pathName = tixStrDup(pathName);
2550 } else {
2551 chPtr->pathName = NULL;
2552 }
2553
2554 if (name) {
2555 chPtr->name = tixStrDup(name);
2556 } else {
2557 chPtr->name = NULL;
2558 }
2559
2560 chPtr->type = HLTYPE_ENTRY;
2561 chPtr->self = (char*)chPtr;
2562 chPtr->wPtr = wPtr;
2563 chPtr->parent = parent;
2564 chPtr->prev = NULL;
2565 chPtr->next = NULL;
2566 chPtr->childHead = NULL;
2567 chPtr->childTail = NULL;
2568 chPtr->numSelectedChild = 0;
2569 chPtr->numCreatedChild = 0;
2570 chPtr->col[0].iPtr = iPtr;
2571 chPtr->indicator = NULL;
2572
2573 chPtr->height = 0;
2574 chPtr->allHeight = 0;
2575 chPtr->selected = 0;
2576 chPtr->dirty = 0;
2577 chPtr->hidden = 0;
2578 chPtr->state = tixNormalUid;
2579 chPtr->data = NULL;
2580 chPtr->branchX = 0;
2581 chPtr->branchY = 0;
2582
2583 if (iPtr) {
2584 /* The clientdata is usedful for the DItemSizeChangedProc() */
2585 iPtr->base.clientData = (ClientData)&chPtr->col[0];
2586 }
2587
2588 return chPtr;
2589 }
2590
2591 static void
2592 FreeElement(wPtr, chPtr)
2593 WidgetPtr wPtr;
2594 HListElement * chPtr;
2595 {
2596 Tcl_HashEntry * hashPtr;
2597 int i;
2598
2599 if (chPtr->selected) {
2600 HL_SelectionClear(wPtr, chPtr);
2601 }
2602 if (wPtr->anchor == chPtr) {
2603 wPtr->anchor = NULL;
2604 }
2605 if (wPtr->dragSite == chPtr) {
2606 wPtr->dragSite = NULL;
2607 }
2608 if (wPtr->dropSite == chPtr) {
2609 wPtr->dropSite = NULL;
2610 }
2611
2612 /*
2613 * Free all the display items
2614 */
2615 for (i=0; i<wPtr->numColumns; i++) {
2616 if (chPtr->col[i].iPtr) {
2617 if (Tix_DItemType(chPtr->col[i].iPtr) == TIX_DITEM_WINDOW) {
2618 Tix_WindowItemListRemove(&wPtr->mappedWindows,
2619 chPtr->col[i].iPtr);
2620 }
2621 Tix_DItemFree(chPtr->col[i].iPtr);
2622 }
2623 }
2624 if (chPtr->indicator != NULL) {
2625 if (Tix_DItemType(chPtr->indicator) == TIX_DITEM_WINDOW) {
2626 Tix_WindowItemListRemove(&wPtr->mappedWindows,
2627 chPtr->indicator);
2628 }
2629 Tix_DItemFree(chPtr->indicator);
2630 }
2631
2632 if (chPtr->col != &chPtr->_oneCol) {
2633 /*
2634 * This space was allocated dynamically
2635 */
2636 ckfree((char*)chPtr->col);
2637 }
2638
2639 if (chPtr->pathName) {
2640 /*
2641 * Root does not have an entry in the hash table
2642 */
2643 if ((hashPtr = Tcl_FindHashEntry(&wPtr->childTable, chPtr->pathName))){
2644 Tcl_DeleteHashEntry(hashPtr);
2645 }
2646 }
2647 if (chPtr->name != NULL) {
2648 ckfree(chPtr->name);
2649 }
2650 if (chPtr->pathName != NULL) {
2651 ckfree(chPtr->pathName);
2652 }
2653 Tk_FreeOptions(entryConfigSpecs, (char *)chPtr, wPtr->dispData.display, 0);
2654
2655 ckfree((char*)chPtr);
2656 }
2657
2658 static void
2659 AppendList(wPtr, parent, chPtr, at, afterPtr, beforePtr)
2660 WidgetPtr wPtr;
2661 HListElement *parent;
2662 HListElement *chPtr;
2663 int at; /* At what position should this entry be added
2664 * default is "-1": add at the end */
2665 HListElement *afterPtr; /* after which entry should this entry be
2666 * added. Default is NULL : ignore */
2667 HListElement *beforePtr; /* before which entry should this entry be
2668 * added. Default is NULL : ignore */
2669 {
2670 if (parent->childHead == NULL) {
2671 parent->childHead = chPtr;
2672 parent->childTail = chPtr;
2673 chPtr->prev = NULL;
2674 chPtr->next = NULL;
2675 }
2676 else {
2677 if (at >= 0) {
2678 /*
2679 * Find the current element at the "at" position
2680 */
2681 HListElement *ptr;
2682 for (ptr=parent->childHead;
2683 ptr!=NULL && at > 0;
2684 ptr=ptr->next, --at) {
2685 ; /* do nothing, just keep counting */
2686 }
2687 if (ptr != NULL) {
2688 /*
2689 * We need to insert the new element *before* ptr.E.g,
2690 * if at == 0, then the new element should be the first
2691 * of the list
2692 */
2693 beforePtr = ptr;
2694 } else {
2695 /* Seems like we walked past the end of the list. Well, do
2696 * nothing here. By default, the new element will be
2697 * append to the end of the list
2698 */
2699 }
2700 }
2701 if (afterPtr != NULL) {
2702 if (afterPtr == parent->childTail) {
2703 parent->childTail = chPtr;
2704 } else {
2705 afterPtr->next->prev = chPtr;
2706 }
2707 chPtr->prev = afterPtr;
2708 chPtr->next = afterPtr->next;
2709 afterPtr->next = chPtr;
2710 return;
2711 }
2712 if (beforePtr !=NULL) {
2713 if (beforePtr == parent->childHead) {
2714 parent->childHead = chPtr;
2715 } else {
2716 beforePtr->prev->next = chPtr;
2717 }
2718 chPtr->prev = beforePtr->prev;
2719 chPtr->next = beforePtr;
2720 beforePtr->prev = chPtr;
2721 return;
2722 }
2723
2724 /*
2725 * By default, append it at the end of the list
2726 */
2727 parent->childTail->next = chPtr;
2728 chPtr->prev = parent->childTail;
2729 chPtr->next = NULL;
2730 parent->childTail = chPtr;
2731 }
2732 }
2733
2734 /*
2735 *--------------------------------------------------------------
2736 *
2737 * NewElement --
2738 *
2739 * This procedure is creates a new element and record it both
2740 * the hash table and in the tree.
2741 *
2742 * Results:
2743 * pointer to new element
2744 *
2745 * Side effects:
2746 * Hash table and tree changed if successful
2747 *--------------------------------------------------------------
2748 */
2749 static HListElement *
2750 NewElement(interp, wPtr, argc, argv, pathName, defParentName, newArgc, newArgv)
2751 Tcl_Interp *interp;
2752 WidgetPtr wPtr;
2753 int argc;
2754 Tcl_Obj *CONST *objv;
2755 char * pathName; /* Default pathname, if -pathname is not
2756 * specified in the options */
2757 char * defParentName; /* Default parent name (will NULL if pathName
2758 * is not NULL */
2759 int * newArgc;
2760 Tcl_Obj *** newArgv;
2761 {
2762 #define FIXED_SPACE 20
2763 char fixedSpace[FIXED_SPACE+1];
2764 char *p, *parentName = NULL;
2765 char *name; /* Last part of the name */
2766 int i, n, numChars;
2767 HListElement *parent;
2768 HListElement *chPtr;
2769 char sep = wPtr->separator[0];
2770 int allocated = 0;
2771 char * ditemType = NULL;
2772 HListElement *afterPtr = NULL;
2773 HListElement *beforePtr = NULL;
2774 int at = -1;
2775 int numSwitches = 0; /* counter on how many of the
2776 * -after, -before and -at switches
2777 * have been used. No more than one
2778 * of then can be used */
2779
2780 /*
2781 * (1) We need to determine the options:
2782 * -itemtype, -after, -before and/or -at.
2783 *
2784 */
2785 if (argc > 0) {
2786 size_t len;
2787 if (argc %2 != 0) {
2788 Tcl_AppendResult(interp, "value for \"", argv[argc-1],
2789 "\" missing", NULL);
2790 chPtr = NULL;
2791 goto done;
2792 }
2793 for (n=i=0; i<argc; i+=2) {
2794 len = strlen(argv[i]);
2795 if (strncmp(argv[i], "-itemtype", len) == 0) {
2796 ditemType = argv[i+1];
2797 goto copy;
2798 }
2799 else if (strncmp(argv[i], "-after", len) == 0) {
2800 afterPtr = Tix_HLFindElement(interp, wPtr, argv[i+1]);
2801 if (afterPtr == NULL) {
2802 chPtr = NULL;
2803 goto done;
2804 }
2805 ++ numSwitches;
2806 continue;
2807 }
2808 else if (strncmp(argv[i], "-before", len) == 0) {
2809 beforePtr = Tix_HLFindElement(interp, wPtr, argv[i+1]);
2810 if (beforePtr == NULL) {
2811 chPtr = NULL;
2812 goto done;
2813 }
2814 ++ numSwitches;
2815 continue;
2816 }
2817 else if (strncmp(argv[i], "-at", len) == 0) {
2818 if (Tcl_GetIntFromObj(interp, objv[i+1], &at) != TCL_OK) {
2819 chPtr = NULL;
2820 goto done;
2821 }
2822 ++ numSwitches;
2823 continue;
2824 }
2825
2826 copy:
2827 *newArgv = (Tcl_Obj**) ckrealloc((void*)*newArgv, (sizeof(Tcl_Obj*)) * (n+2));
2828 (*newArgv)[n] = objv[i];
2829 (*newArgv)[n+1] = objv[i+1];
2830 n+=2;
2831 }
2832 * newArgc = n;
2833 } else {
2834 * newArgc = 0;
2835 }
2836 if (numSwitches > 1) {
2837 Tcl_AppendResult(interp, "No more than one of the -after, -before ",
2838 "and -at options can be used", NULL);
2839 chPtr = NULL;
2840 goto done;
2841 }
2842 if (ditemType == NULL) {
2843 ditemType = wPtr->diTypePtr->name;
2844 }
2845 if (Tix_GetDItemType(interp, ditemType) == NULL) {
2846 chPtr = NULL;
2847 goto done;
2848 }
2849
2850 /*------------------------------------------------------------
2851 * (2) Create the new entry. The method depends on whether
2852 * the "add" or "addchild" command has been called
2853 *------------------------------------------------------------
2854 */
2855 if (pathName == NULL) {
2856 /* (2.a) Called by the "addchild" command. We need to generate
2857 * a default name for the child
2858 *
2859 */
2860 char buff[40];
2861
2862 parentName = defParentName;
2863 if (parentName == NULL) {
2864 parent = wPtr->root;
2865 } else {
2866 if ((parent=Tix_HLFindElement(interp, wPtr, parentName))== NULL) {
2867 Tcl_ResetResult(interp);
2868 Tcl_AppendResult(interp, "parent element \"", parentName,
2869 "\" does not exist", (char *) NULL);
2870 chPtr = NULL;
2871 goto done;
2872 }
2873 }
2874
2875 /* Generate a default name for this entry */
2876 sprintf(buff, "%d", parent->numCreatedChild);
2877 name = buff;
2878
2879 if (parentName == NULL) {
2880 pathName = tixStrDup(name);
2881 allocated = 1;
2882 }
2883 else {
2884 pathName = ckalloc(strlen(parentName)+1+ strlen(name)+1);
2885 allocated = 1;
2886 sprintf(pathName, "%s%c%s", parentName, sep, name);
2887 }
2888 }
2889 else {
2890 /* (2.b) Called by the "add" command.
2891 *
2892 * Strip the parent's name out of pathName (it's everything up
2893 * to the last dot). There are two tricky parts: (a) must
2894 * copy the parent's name somewhere else to avoid modifying
2895 * the pathName string (for large names, space for the copy
2896 * will have to be malloc'ed); (b) must special-case the
2897 * situation where the parent is ".".
2898 */
2899
2900 if ((p = strrchr(pathName, (int)sep)) == NULL) {
2901 /* This is a toplevel element (no "." in it) */
2902 name = pathName;
2903 parentName = NULL;
2904 }
2905 else {
2906 name = p+1;
2907 numChars = p-pathName;
2908 if (numChars > FIXED_SPACE) {
2909 parentName = (char *) ckalloc((unsigned)(numChars+1));
2910 } else {
2911 parentName = fixedSpace;
2912 }
2913 if (numChars == 0) {
2914 if ((pathName[0] == sep) && (pathName[1] == '\0')) {
2915 /*
2916 * The separator by itself is also a toplevel entry
2917 */
2918 parentName = 0;
2919 } else {
2920 parentName[0] = sep;
2921 parentName[1] = '\0';
2922 }
2923 }
2924 else {
2925 strncpy(parentName, pathName, (size_t) numChars);
2926 parentName[numChars] = '\0';
2927 }
2928 }
2929
2930 if (parentName == NULL) {
2931 parent = wPtr->root;
2932 } else {
2933 if ((parent = Tix_HLFindElement(interp, wPtr, parentName))==NULL) {
2934 Tcl_ResetResult(interp);
2935 Tcl_AppendResult(interp, "parent element \"", parentName,
2936 "\" does not exist", (char *) NULL);
2937 chPtr = NULL;
2938 goto done;
2939 }
2940 }
2941
2942 }
2943 if (Tix_HLFindElement(interp, wPtr, pathName) != NULL) {
2944 Tcl_AppendResult(interp, "element \"", pathName,
2945 "\" already exists", (char *) NULL);
2946 chPtr = NULL;
2947 goto done;
2948 }
2949 else {
2950 if (afterPtr != NULL && afterPtr->parent != parent) {
2951 Tcl_AppendResult(interp, "cannot add entry after \"",
2952 afterPtr->pathName, "\"", NULL);
2953 chPtr = NULL;
2954 goto done;
2955 }
2956 if (beforePtr != NULL && beforePtr->parent != parent) {
2957 Tcl_AppendResult(interp, "cannot add entry before \"",
2958 beforePtr->pathName, "\"", NULL);
2959 chPtr = NULL;
2960 goto done;
2961 }
2962
2963 Tcl_ResetResult(interp);
2964 if ((chPtr = AllocElement(wPtr, parent, pathName, name, ditemType))
2965 == NULL) {
2966 /* Some error, now chPtr == NULL */
2967 goto done;
2968 }
2969 AppendList(wPtr, parent, chPtr, at, afterPtr, beforePtr);
2970 Tix_HLMarkElementDirty(wPtr, chPtr);
2971 Tix_HLResizeWhenIdle(wPtr);
2972 goto done; /* success */
2973 }
2974
2975 done:
2976 if (allocated) {
2977 ckfree((char*)pathName);
2978 }
2979 if (parentName && parentName != fixedSpace && parentName !=defParentName) {
2980 ckfree((char*)parentName);
2981 }
2982 return chPtr;
2983 }
2984
2985 /*--------------------------------------------------------------
2986 * ConfigElement --
2987 *
2988 * This procedure configures the element according to the
2989 * options.
2990 *
2991 * Results:
2992 * A standard Tcl result.
2993 *
2994 * Side effects:
2995 * Hash table and tree changed if successful
2996 *--------------------------------------------------------------
2997 */
2998
2999 static int
3000 ConfigElement(wPtr, chPtr, argc, argv, flags, forced)
3001 WidgetPtr wPtr;
3002 HListElement *chPtr;
3003 int argc;
3004 char ** argv;
3005 int flags;
3006 int forced; /* We need a "forced" configure to ensure that
3007 * the DItem is initialized properly */
3008 {
3009 int sizeChanged;
3010
3011 if (wPtr->dispData.tkwin == NULL)
3012 panic("No tkwin");
3013
3014 if (Tix_WidgetConfigure2(wPtr->dispData.interp, wPtr->dispData.tkwin,
3015 (char*)chPtr, entryConfigSpecs, chPtr->col[0].iPtr, argc, argv, flags,
3016 forced, &sizeChanged) != TCL_OK) {
3017 return TCL_ERROR;
3018 }
3019
3020 if (sizeChanged) {
3021 Tix_HLMarkElementDirty(wPtr, chPtr);
3022 Tix_HLResizeWhenIdle(wPtr);
3023 } else {
3024 RedrawWhenIdle(wPtr);
3025 }
3026
3027 return TCL_OK;
3028 }
3029
3030 /*
3031 *--------------------------------------------------------------
3032 *
3033 * FindElementAtPosition --
3034 *
3035 * Finds a visible element nearest to a Y position
3036 *
3037 * Results:
3038 * Pointer to the element.
3039 *
3040 * Side effects:
3041 * None
3042 *--------------------------------------------------------------
3043 */
3044 static HListElement * FindElementAtPosition(wPtr, y)
3045 WidgetPtr wPtr;
3046 int y;
3047 {
3048 HListElement * chPtr = wPtr->root;
3049 int top = 0;
3050
3051 y -= wPtr->borderWidth + wPtr->highlightWidth;
3052 y += wPtr->topPixel;
3053
3054 if (wPtr->useHeader) {
3055 y -= wPtr->headerHeight;
3056 }
3057
3058 if (y < 0) {
3059 /*
3060 * Position is above the top of the list, return the first element in
3061 * the list of toplevel entries.
3062 */
3063 if (wPtr->root != NULL) {
3064 for (chPtr=wPtr->root->childHead; chPtr!=NULL; chPtr=chPtr->next) {
3065 if (!chPtr->hidden) {
3066 return chPtr;
3067 }
3068 }
3069 }
3070 return NULL;
3071 }
3072 if (y >= chPtr->allHeight) {
3073 /*
3074 * Position is past the end of the list, return the last element.
3075 */
3076 HListElement * vis;
3077
3078 chPtr=wPtr->root;
3079 while (1) {
3080 if (chPtr->childTail == NULL) {
3081 break;
3082 }
3083 for (vis = chPtr->childTail; vis && vis->hidden; vis=vis->prev) {
3084 ;
3085 }
3086 if (vis == NULL) {
3087 break;
3088 } else {
3089 chPtr = vis;
3090 continue;
3091 }
3092 }
3093 if (chPtr == wPtr->root) {
3094 /*
3095 * There is either no element, or all elements are not visible
3096 */
3097 return NULL;
3098 } else {
3099 return chPtr;
3100 }
3101 }
3102
3103 /*
3104 * The following is a tail-recursive function flatten out in a while
3105 * loop.
3106 */
3107
3108 while (1) {
3109 again:
3110 for (chPtr=chPtr->childHead; chPtr!=NULL; chPtr=chPtr->next) {
3111 if (!chPtr->hidden) {
3112 if (top <= y && y < top + chPtr->allHeight) {
3113 if (y < top + chPtr->height) {
3114 return chPtr;
3115 } else {
3116 top += chPtr->height;
3117 goto again;
3118 }
3119 } else {
3120 top += chPtr->allHeight;
3121 }
3122 }
3123 }
3124 /* FIXME: If we fall out of for loop chPtr is NULL, so we
3125 * cannot do chPtr->childHead as while loop implies
3126 * this is a quick-fix.
3127 */
3128 return NULL;
3129 }
3130 }
3131
3132 /*
3133 *--------------------------------------------------------------
3134 *
3135 * Tix_HLFindElement --
3136 *
3137 * Finds an element according to its pathname.
3138 *
3139 * Results:
3140 * Pointer to the element if found. Otherwise NULL.
3141 *
3142 * Side effects:
3143 * None
3144 *--------------------------------------------------------------
3145 */
3146 HListElement * Tix_HLFindElement(interp, wPtr, pathName)
3147 Tcl_Interp * interp;
3148 WidgetPtr wPtr;
3149 char * pathName;
3150 {
3151 Tcl_HashEntry * hashPtr;
3152
3153 if (pathName) {
3154 hashPtr = Tcl_FindHashEntry(&wPtr->childTable, pathName);
3155
3156 if (hashPtr) {
3157 return (HListElement*) Tcl_GetHashValue(hashPtr);
3158 } else {
3159 Tcl_AppendResult(interp, "Entry \"", pathName,
3160 "\" not found", NULL);
3161 return NULL;
3162 }
3163 }
3164 else {
3165 /* pathName == 0 is the root element */
3166 return wPtr->root;
3167 }
3168 }
3169
3170 /*
3171 *--------------------------------------------------------------
3172 *
3173 * SelectionModifyRange --
3174 *
3175 * Select or de-select all the elements between from and to
3176 * (inclusive), according to the "select" argument.
3177 *
3178 * select == 1 : select
3179 * select == 0 : de-select
3180 *
3181 * Return value:
3182 * Whether the selection was actually changed
3183 *--------------------------------------------------------------
3184 */
3185 static int SelectionModifyRange(wPtr, from, to, select)
3186 WidgetPtr wPtr;
3187 HListElement * from;
3188 HListElement * to;
3189 int select;
3190 {
3191 int changed = 0;
3192
3193 if (Tix_HLElementTopOffset(wPtr, from) > Tix_HLElementTopOffset(wPtr, to)){
3194 HListElement * tmp;
3195 tmp = to;
3196 to = from;
3197 from = tmp;
3198 }
3199
3200 while (1) {
3201 if (!from->hidden && (int)from->selected != select) {
3202 changed = 1;
3203 if (select) {
3204 SelectionAdd(wPtr, from);
3205 } else {
3206 HL_SelectionClear(wPtr, from);
3207 }
3208 }
3209
3210 if (from == to) {
3211 /*
3212 * Iterated to the end of the region
3213 */
3214 break;
3215 }
3216
3217 /*
3218 * Go to the next list entry
3219 */
3220 if (from->childHead) {
3221 from = from->childHead;
3222 }
3223 else if (from->next) {
3224 from = from->next;
3225 }
3226 else {
3227 /*
3228 * go to a different branch
3229 */
3230 while (from->parent->next == NULL && from != wPtr->root) {
3231 from = from->parent;
3232 }
3233 if (from == wPtr->root) {
3234 /*
3235 * Iterated over all list entries
3236 */
3237 break;
3238 } else {
3239 from = from->parent->next;
3240 }
3241 }
3242 }
3243
3244 return changed;
3245 }
3246
3247 /*
3248 *--------------------------------------------------------------
3249 *
3250 * Tix_HLElementTopOffset --
3251 *
3252 *--------------------------------------------------------------
3253 */
3254 int Tix_HLElementTopOffset(wPtr, chPtr)
3255 WidgetPtr wPtr;
3256 HListElement * chPtr;
3257 {
3258 int top;
3259 HListElement * ptr;
3260
3261 if (chPtr == wPtr->root) {
3262 return 0;
3263 }
3264 top = Tix_HLElementTopOffset(wPtr, chPtr->parent);
3265 top += chPtr->parent->height;
3266
3267 for (ptr=chPtr->parent->childHead; ptr!=NULL; ptr=ptr->next) {
3268 if (ptr == chPtr) {
3269 break;
3270 }
3271 if (ptr->hidden) {
3272 continue;
3273 }
3274 top += ptr->allHeight;
3275 }
3276 return top;
3277 }
3278
3279 /*
3280 *--------------------------------------------------------------
3281 *
3282 * Tix_HLElementLeftOffset --
3283 *
3284 *--------------------------------------------------------------
3285 */
3286 int Tix_HLElementLeftOffset(wPtr, chPtr)
3287 WidgetPtr wPtr;
3288 HListElement * chPtr;
3289 {
3290 int left;
3291
3292 if (chPtr == wPtr->root || chPtr->parent == wPtr->root) {
3293 return 0;
3294 }
3295
3296 left = Tix_HLElementLeftOffset(wPtr, chPtr->parent);
3297 left += wPtr->indent;
3298
3299 return left;
3300 }
3301
3302 /*
3303 *--------------------------------------------------------------
3304 *
3305 * CurSelection --
3306 *
3307 * returns the current selection in the result of interp;
3308 *
3309 *--------------------------------------------------------------
3310 */
3311 static int CurSelection(interp, wPtr, chPtr)
3312 Tcl_Interp * interp;
3313 WidgetPtr wPtr;
3314 HListElement * chPtr;
3315 {
3316 HListElement * ptr;
3317
3318 /* Since this recursion starts with wPtr->root, we determine
3319 * whether a node is selected when its *parent* is called. This
3320 * will save one level of recursion (otherwise all leave nodes will
3321 * be recursed once and will be slow ...
3322 */
3323 for (ptr=chPtr->childHead; ptr; ptr=ptr->next) {
3324 if (ptr->selected && !(ptr->hidden)) {
3325 Tcl_AppendElement(interp, ptr->pathName);
3326 }
3327 if (ptr->childHead) {
3328 CurSelection(interp, wPtr, ptr);
3329 }
3330 }
3331 return TCL_OK;
3332 }
3333
3334 /*
3335 *--------------------------------------------------------------
3336 *
3337 * Tix_HLMarkElementDirty --
3338 *
3339 * Marks a element "dirty", i.e., its geometry needs to be
3340 * recalculated.
3341 *
3342 * Results:
3343 * None.
3344 *
3345 * Side effects:
3346 * The element and all its ancestores are marked dirty
3347 *--------------------------------------------------------------
3348 */
3349 void Tix_HLMarkElementDirty(wPtr, chPtr)
3350 WidgetPtr wPtr;
3351 HListElement *chPtr;
3352 {
3353 HListElement *ptr;
3354
3355 for (ptr=chPtr; ptr!= NULL && ptr->dirty == 0; ptr=ptr->parent) {
3356 ptr->dirty = 1;
3357 }
3358 }
3359
3360 /*
3361 *--------------------------------------------------------------
3362 *
3363 * ComputeElementGeometry --
3364 *
3365 * Compute the geometry of this element (if its dirty) and the
3366 * geometry of all its dirty child elements
3367 *
3368 * Results:
3369 * None.
3370 *
3371 * Side effects:
3372 * The element and all its descendants are marked non-dirty
3373 *--------------------------------------------------------------
3374 */
3375
3376 static void ComputeElementGeometry(wPtr, chPtr, indent)
3377 WidgetPtr wPtr;
3378 HListElement *chPtr;
3379 int indent;
3380 {
3381 HListElement *ptr;
3382 int i;
3383
3384 if (!chPtr->dirty && !wPtr->allDirty) {
3385 return;
3386 } else {
3387 chPtr->dirty = 0;
3388 }
3389
3390 if (chPtr == wPtr->root) {
3391 int i;
3392 chPtr->height = 0;
3393 chPtr->indent = 0;
3394 for (i=0; i<wPtr->numColumns; i++) {
3395 chPtr->col[i].width = 0;
3396 }
3397 } else {
3398 ComputeOneElementGeometry(wPtr, chPtr, indent);
3399 indent += wPtr->indent;
3400 }
3401
3402 chPtr->allHeight = chPtr->height;
3403
3404 for (ptr=chPtr->childHead; ptr!=NULL; ptr=ptr->next) {
3405 if (ptr->hidden) {
3406 continue;
3407 }
3408 if (ptr->dirty || wPtr->allDirty) {
3409 ComputeElementGeometry(wPtr, ptr, indent);
3410 }
3411
3412 /* Propagate the child's size to the parent
3413 *
3414 */
3415 for (i=0; i<wPtr->numColumns; i++) {
3416 if (chPtr->col[i].width < ptr->col[i].width) {
3417 chPtr->col[i].width = ptr->col[i].width;
3418 }
3419 }
3420 chPtr->allHeight += ptr->allHeight;
3421 }
3422 }
3423
3424 /*
3425 *--------------------------------------------------------------
3426 *
3427 * ComputeOneElementGeometry --
3428 *
3429 * Compute the geometry of the element itself, not including
3430 * its children, according to its current display type.
3431 *
3432 * Results:
3433 * None.
3434 *
3435 * Side effects:
3436 * The chPtr->height fields are updated.
3437 *--------------------------------------------------------------
3438 */
3439 static void ComputeOneElementGeometry(wPtr, chPtr, indent)
3440 WidgetPtr wPtr;
3441 HListElement *chPtr;
3442 int indent;
3443 {
3444 int i;
3445
3446 chPtr->indent = indent;
3447 chPtr->height = 0;
3448
3449 ComputeBranchPosition(wPtr, chPtr);
3450
3451 for (i=0; i<wPtr->numColumns; i++) {
3452 Tix_DItem * iPtr = chPtr->col[i].iPtr;
3453 int width = 2*wPtr->selBorderWidth;
3454 int height = 2*wPtr->selBorderWidth;
3455
3456 if (iPtr != NULL) {
3457 Tix_DItemCalculateSize(iPtr);
3458 /* Tix_DItemWidth() and Tix_DItemHeight() already include padding
3459 */
3460 width += Tix_DItemWidth (iPtr);
3461 height += Tix_DItemHeight(iPtr);
3462 }
3463 if (chPtr->height < height) {
3464 chPtr->height = height;
3465 }
3466 chPtr->col[i].width = width;
3467 }
3468 chPtr->col[0].width += indent;
3469 }
3470
3471 /*
3472 *--------------------------------------------------------------
3473 *
3474 * ComputeBranchPosition --
3475 *
3476 * Compute the position of the branches
3477 *
3478 * Results:
3479 * None.
3480 *
3481 * Side effects:
3482 * The chPtr->branchX and chPtr->branchY fields are updated.
3483 *--------------------------------------------------------------
3484 */
3485 static void ComputeBranchPosition(wPtr, chPtr)
3486 WidgetPtr wPtr;
3487 HListElement *chPtr;
3488 {
3489 Tix_DItem * iPtr = chPtr->col[0].iPtr;
3490 int branchX, branchY;
3491 int iconX;
3492 int iconY;
3493 int diff;
3494
3495 if (iPtr) {
3496 if (Tix_DItemType(iPtr) == TIX_DITEM_IMAGETEXT) {
3497 /*
3498 * Calculate the bottom-middle position of the bitmap/image branch
3499 */
3500 if (iPtr->imagetext.image != NULL) {
3501 branchX = iPtr->imagetext.imageW / 2;
3502 branchY = iPtr->imagetext.imageH;
3503 if (Tix_DItemHeight(iPtr) > iPtr->imagetext.imageH) {
3504 branchY += (Tix_DItemHeight(iPtr) -
3505 iPtr->imagetext.imageH) /2;
3506 }
3507 }
3508 else if (iPtr->imagetext.bitmap != None) {
3509 branchX = iPtr->imagetext.bitmapW / 2;
3510 branchY = iPtr->imagetext.bitmapH;
3511 if (Tix_DItemHeight(iPtr) >iPtr->imagetext.bitmapH) {
3512 branchY += (Tix_DItemHeight(iPtr) -
3513 iPtr->imagetext.bitmapH) /2;
3514 }
3515 }
3516 else {
3517 branchX = wPtr->indent/2;
3518 branchY = Tix_DItemHeight(iPtr);
3519 }
3520 } else {
3521 branchX = wPtr->indent/2;
3522 branchY = Tix_DItemHeight(iPtr);
3523 }
3524
3525
3526 /* X adjustment
3527 */
3528 iconX = Tix_DItemPadX(iPtr);
3529 branchX += Tix_DItemPadX(iPtr);
3530
3531 /* Y adjustment
3532 */
3533 iconY = Tix_DItemHeight(iPtr) / 2;
3534 diff = chPtr->height - Tix_DItemHeight(iPtr);
3535 if (diff > 0) {
3536 switch (iPtr->base.stylePtr->anchor) {
3537 case TK_ANCHOR_NW: case TK_ANCHOR_N: case TK_ANCHOR_NE:
3538 diff = 0;
3539 break;
3540 case TK_ANCHOR_W: case TK_ANCHOR_CENTER: case TK_ANCHOR_E:
3541 diff /= 2;
3542 break;
3543 default:
3544 /* Do nothing */
3545 ;
3546 }
3547 branchY += diff;
3548 iconY += diff;
3549 }
3550 }
3551 else {
3552 branchX = wPtr->indent/2;
3553 branchY = chPtr->height;
3554 iconX = 0;
3555 iconY = chPtr->height/2;
3556 }
3557
3558 if (wPtr->useIndicator && chPtr->parent == wPtr->root) {
3559 branchX += wPtr->indent;
3560 }
3561
3562 chPtr->branchX = branchX - 1;
3563 chPtr->branchY = branchY - 1;
3564 chPtr->iconX = iconX - 1;
3565 chPtr->iconY = iconY - 1;
3566
3567 if (chPtr->branchX < 0) {
3568 chPtr->branchX = 0;
3569 }
3570 if (chPtr->branchY < 0) {
3571 chPtr->branchY = 0;
3572 }
3573 if (chPtr->iconX < 0) {
3574 chPtr->iconX = 0;
3575 }
3576 if (chPtr->iconY < 0) {
3577 chPtr->iconY = 0;
3578 }
3579
3580 chPtr->branchX += wPtr->selBorderWidth;
3581 chPtr->branchY += wPtr->selBorderWidth;
3582 chPtr->iconX += wPtr->selBorderWidth;
3583 chPtr->iconY += wPtr->selBorderWidth;
3584 }
3585 /*
3586 *----------------------------------------------------------------------
3587 *
3588 * WidgetDisplay --
3589 *
3590 * Draw the widget to the screen.
3591 *
3592 * Results:
3593 * None.
3594 *
3595 * Side effects:
3596 *
3597 *----------------------------------------------------------------------
3598 */
3599 static void
3600 WidgetDisplay(clientData)
3601 ClientData clientData; /* Info about my widget. */
3602 {
3603 WidgetPtr wPtr = (WidgetPtr) clientData;
3604 Drawable buffer;
3605 Tk_Window tkwin = wPtr->dispData.tkwin;
3606 int elmX, elmY;
3607 Tcl_Interp *interp = wPtr->dispData.interp;
3608
3609 wPtr->redrawing = 0; /* clear the redraw flag */
3610 wPtr->serial ++;
3611
3612 if (wPtr->elmToSee != NULL) {
3613 HListElement *chPtr;
3614
3615 if ((chPtr = Tix_HLFindElement(interp, wPtr,
3616 wPtr->elmToSee)) == NULL) {
3617 Tcl_ResetResult(interp);
3618 } else {
3619 Tix_HLSeeElement(wPtr, chPtr, 0);
3620 UpdateScrollBars(wPtr, 0);
3621 }
3622
3623 ckfree(wPtr->elmToSee);
3624 wPtr->elmToSee = NULL;
3625 }
3626
3627
3628 /*
3629 * STEP (1)
3630 * Calculate the drawing parameters
3631 */
3632 if (wPtr->wideSelect) {
3633 wPtr->selectWidth = Tk_Width(wPtr->dispData.tkwin) -
3634 (2*wPtr->borderWidth + 2*wPtr->highlightWidth);
3635 if (wPtr->selectWidth < wPtr->totalSize[0]) {
3636 wPtr->selectWidth = wPtr->totalSize[0];
3637 }
3638 }
3639
3640 /* Used to clip off elements that are too low to see */
3641 wPtr->bottomPixel = Tk_Height(wPtr->dispData.tkwin) - 2*wPtr->borderWidth
3642 - 2*wPtr->highlightWidth;
3643
3644 elmX = wPtr->borderWidth + wPtr->highlightWidth - wPtr->leftPixel;
3645 elmY = wPtr->borderWidth + wPtr->highlightWidth - wPtr->topPixel;
3646
3647 if (wPtr->useHeader) {
3648 elmY += wPtr->headerHeight;
3649 }
3650
3651 /*
3652 * STEP (2)
3653 * Draw the list body
3654 */
3655 buffer = Tix_GetRenderBuffer(wPtr->dispData.display, Tk_WindowId(tkwin),
3656 Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));
3657
3658 /* Fill the background */
3659 XFillRectangle(wPtr->dispData.display, buffer, wPtr->backgroundGC,
3660 0, 0, Tk_Width(tkwin), Tk_Height(tkwin));
3661
3662 DrawElements(wPtr, buffer, wPtr->normalGC, wPtr->root,
3663 elmX, elmY,
3664 wPtr->borderWidth + wPtr->highlightWidth - wPtr->leftPixel);
3665
3666 if (wPtr->borderWidth > 0) {
3667 /* Draw the border */
3668 Tk_Draw3DRectangle(wPtr->dispData.tkwin, buffer, wPtr->border,
3669 wPtr->highlightWidth, wPtr->highlightWidth,
3670 Tk_Width(tkwin) - 2*wPtr->highlightWidth,
3671 Tk_Height(tkwin) - 2*wPtr->highlightWidth, wPtr->borderWidth,
3672 wPtr->relief);
3673 }
3674
3675 if (wPtr->highlightWidth > 0) {
3676 /* Draw the highlight */
3677 GC gc;
3678
3679 if (wPtr->hasFocus) {
3680 gc = wPtr->highlightGC;
3681 } else {
3682 gc = Tk_3DBorderGC(wPtr->dispData.tkwin, wPtr->border,
3683 TK_3D_FLAT_GC);
3684 }
3685 Tk_DrawFocusHighlight(tkwin, gc, wPtr->highlightWidth, buffer);
3686 }
3687
3688 if (buffer != Tk_WindowId(tkwin)) {
3689 /*
3690 * Copy the information from the off-screen pixmap onto the screen,
3691 * then delete the pixmap.
3692 */
3693
3694 XCopyArea(wPtr->dispData.display, buffer, Tk_WindowId(tkwin),
3695 wPtr->normalGC, 0, 0, Tk_Width(tkwin), Tk_Height(tkwin), 0, 0);
3696 Tk_FreePixmap(wPtr->dispData.display, buffer);
3697 }
3698
3699 /*
3700 * STEP (3)
3701 * Draw the header
3702 */
3703 if (wPtr->useHeader) {
3704 /* We need to draw the header after the elements, because some
3705 * half-scrolled elements may overwrite the space for the header
3706 */
3707 int hdrX, hdrY, hdrW, hdrH, pad, xOffset;
3708 Drawable buffer;
3709
3710 pad = wPtr->borderWidth + wPtr->highlightWidth;
3711 hdrX = pad;
3712 hdrY = pad;
3713 hdrW = Tk_Width(tkwin) - 2*pad;
3714 hdrH = wPtr->headerHeight;
3715 xOffset = wPtr->leftPixel;
3716
3717 Tk_MoveResizeWindow(wPtr->headerWin, hdrX, hdrY, hdrW, hdrH);
3718 Tk_MapWindow(wPtr->headerWin);
3719
3720 buffer = Tix_GetRenderBuffer(wPtr->dispData.display,
3721 Tk_WindowId(wPtr->headerWin), hdrW, hdrH,
3722 Tk_Depth(wPtr->headerWin));
3723
3724 XFillRectangle(wPtr->dispData.display, buffer,
3725 wPtr->backgroundGC, 0, 0, hdrW, hdrH);
3726
3727 Tix_HLDrawHeader(wPtr, buffer, wPtr->normalGC,
3728 0, 0, hdrW, hdrH, xOffset);
3729
3730 if (buffer != Tk_WindowId(wPtr->headerWin)) {
3731 XCopyArea(wPtr->dispData.display, buffer,
3732 Tk_WindowId(wPtr->headerWin), wPtr->normalGC,
3733 0, 0, hdrW, hdrH, 0, 0);
3734
3735 Tk_FreePixmap(wPtr->dispData.display, buffer);
3736 }
3737
3738 /* If we map the header window, that may change the size requirement
3739 * of the HList
3740 * %% Call only when geometry is *really* changed
3741 */
3742 if (wPtr->sizeCmd) {
3743 if (LangDoCallback(wPtr->dispData.interp, wPtr->sizeCmd, 0, 0) != TCL_OK) {
3744 Tcl_AddErrorInfo(wPtr->dispData.interp,
3745 "\n (size command executed by tixHList)");
3746 Tcl_BackgroundError(wPtr->dispData.interp);
3747 }
3748 }
3749 } else {
3750 Tk_UnmapWindow(wPtr->headerWin);
3751 }
3752
3753 /* unmap those windows we mapped the last time */
3754 Tix_UnmapInvisibleWindowItems(&wPtr->mappedWindows, wPtr->serial);
3755 }
3756
3757 /*
3758 *----------------------------------------------------------------------
3759 *
3760 * DrawElements --
3761 *--------------------------------------------------------------
3762 */
3763 static void DrawElements(wPtr, pixmap, gc, chPtr, x, y, xOffset)
3764 WidgetPtr wPtr;
3765 Pixmap pixmap;
3766 GC gc;
3767 HListElement * chPtr;
3768 int x;
3769 int y;
3770 int xOffset;
3771 {
3772 HListElement * ptr, * lastVisible;
3773 int myIconX = 0, myIconY = 0; /* center of my icon */
3774 int childIconX, childIconY; /* center of child's icon */
3775 int childY, childX;
3776 int oldY;
3777 int top = wPtr->useHeader ? wPtr->headerHeight : 0,
3778 left = 0,
3779 bottom = Tk_Height(wPtr->dispData.tkwin),
3780 right = Tk_Width(wPtr->dispData.tkwin);
3781
3782 if (chPtr != wPtr->root) {
3783 if (bottom > y && (y + chPtr->height) >= top) {
3784 /* Otherwise element is not see at all */
3785 DrawOneElement(wPtr, pixmap, gc, chPtr, x, y, xOffset);
3786 }
3787 myIconX = x + chPtr->branchX;
3788 myIconY = y + chPtr->branchY;
3789
3790 if (wPtr->useIndicator && chPtr->parent == wPtr->root) {
3791 childX = x + 2 * wPtr->indent;
3792 } else {
3793 childX = x + wPtr->indent;
3794 }
3795 childY = y + chPtr->height;
3796 if (myIconX > childX) {
3797 /* Can't shift the vertical branch too much to the right */
3798 myIconX = childX;
3799 }
3800 } else {
3801 childX = x;
3802 childY = y;
3803 }
3804
3805 oldY = childY; /* saved for 2nd iteration */
3806
3807 /* find the last non-hidden element,
3808 * to determine when to draw the vertical line
3809 */
3810 lastVisible = NULL;
3811 for (ptr = chPtr->childTail; ptr!=NULL; ptr=ptr->prev) {
3812 if (! ptr->hidden) {
3813 lastVisible = ptr;
3814 break;
3815 }
3816 }
3817
3818 if (lastVisible == NULL) {
3819 /* No child is visible */
3820 return;
3821 }
3822
3823 /* First iteration : draw the entries and branches */
3824 for (ptr = chPtr->childHead; ptr!=NULL; ptr=ptr->next) {
3825 if (ptr->hidden) {
3826 continue;
3827 }
3828
3829 childIconX = childX + ptr->iconX;
3830 childIconY = childY + ptr->iconY;
3831
3832 if (bottom > childY && (childY + ptr->allHeight) >= top) {
3833
3834 /* Otherwise all descendants of ptr are not seen at all
3835 */
3836 DrawElements(wPtr, pixmap, gc, ptr, childX, childY, xOffset);
3837
3838 if (wPtr->drawBranch && chPtr != wPtr->root
3839 && top <= childIconY && childIconY <= bottom
3840 ) {
3841 /* Draw a horizontal branch to the child */
3842 XDrawLine(wPtr->dispData.display, pixmap, gc, myIconX,
3843 childIconY, childIconX, childIconY);
3844 }
3845 }
3846
3847 /*
3848 * -- no branches for toplevel elements
3849 * -- for last element, draw a vertical branch, even if element
3850 * is not seen
3851 */
3852 if (ptr == lastVisible && wPtr->drawBranch
3853 && chPtr != wPtr->root && childIconY >= top
3854 && left <= myIconX && myIconX <= right
3855 ) {
3856 /* clip vertical lines to avoid wrap-around */
3857 int y0 = myIconY < 0 ? 0 : myIconY,
3858 y1 = childIconY > bottom ? bottom : childIconY;
3859
3860 XDrawLine(wPtr->dispData.display, pixmap, gc, myIconX, y0,
3861 myIconX, y1);
3862 }
3863 childY += ptr->allHeight;
3864 }
3865
3866 if (!wPtr->useIndicator) {
3867 return;
3868 }
3869 childY = oldY;
3870
3871 /* Second iteration : draw the indicators */
3872 for (ptr = chPtr->childHead; ptr!=NULL; ptr=ptr->next) {
3873 int cY = childY;
3874
3875 if (ptr->hidden) {
3876 continue;
3877 }
3878 childY += ptr->allHeight;
3879 childIconY = cY + ptr->iconY;
3880
3881 if (bottom > cY && (cY + ptr->allHeight) >= top
3882 && ptr->indicator != NULL
3883 ) {
3884 /* Otherwise all descendants of ptr are not seen at all
3885 */
3886 int justMapped,
3887 indW = Tix_DItemWidth (ptr->indicator),
3888 indH = Tix_DItemHeight(ptr->indicator),
3889 indY = childIconY - indH/2,
3890 indX = (chPtr == wPtr->root
3891 ? (wPtr->indent / 2 + wPtr->borderWidth
3892 + wPtr->highlightWidth - wPtr->leftPixel)
3893 : myIconX) - indW/2;
3894 if ( indX > right || (indX + indW) < left
3895 || indY > bottom ||(indY + indH) < top
3896 ) {
3897 continue; /* indicator not visible */
3898 }
3899
3900 justMapped = 0;
3901 if (Tix_DItemType(ptr->indicator) == TIX_DITEM_WINDOW) {
3902 Tix_SetWindowItemSerial(&wPtr->mappedWindows,
3903 ptr->indicator, wPtr->serial);
3904 if (!Tk_IsMapped(ptr->indicator->window.tkwin)) {
3905 justMapped = 1;
3906 }
3907 }
3908
3909 /* Put down the indicator */
3910 Tix_DItemDisplay(pixmap, gc, ptr->indicator,
3911 indX, indY, indW, indH,
3912 TIX_DITEM_NORMAL_FG|TIX_DITEM_NORMAL_BG);
3913
3914 if (justMapped) {
3915 #if 1
3916 Tk_RestackWindow(ptr->indicator->window.tkwin, Below, NULL);
3917 #else
3918 XLowerWindow(Tk_Display(ptr->indicator->window.tkwin),
3919 Tk_WindowId(ptr->indicator->window.tkwin));
3920 #endif
3921 }
3922 }
3923 }
3924 }
3925
3926 /*
3927 *----------------------------------------------------------------------
3928 *
3929 * DrawOneElement --
3930 *--------------------------------------------------------------
3931 */
3932 static void DrawOneElement(wPtr, pixmap, gc, chPtr, x, y, xOffset)
3933 WidgetPtr wPtr;
3934 Pixmap pixmap;
3935 GC gc;
3936 HListElement * chPtr;
3937 int x;
3938 int y;
3939 int xOffset;
3940 {
3941 int i;
3942 int flags = TIX_DITEM_NORMAL_FG, bgFlags = 0;
3943 int selectWidth, selectX;
3944
3945 x = xOffset + chPtr->indent;
3946
3947 if (wPtr->wideSelect) {
3948 selectWidth = wPtr->selectWidth;
3949 selectX = xOffset;
3950 } else {
3951 selectWidth = Tix_DItemWidth(chPtr->col[0].iPtr)
3952 + 2*wPtr->selBorderWidth;
3953 selectX = x;
3954 }
3955
3956 if (chPtr->selected) {
3957 /*
3958 * When the ditem is selected, we have already drawn the
3959 * selection background ourself, so we don't want
3960 * DitemDisplay() to draw any background for us. So in this
3961 * case both TIX_DITEM_NORMAL_BG and TIX_DITEM_SELECTED_BG are
3962 * *not* set
3963 */
3964 Tk_Fill3DRectangle(wPtr->dispData.tkwin, pixmap, wPtr->selectBorder,
3965 selectX, y, selectWidth, chPtr->height, wPtr->selBorderWidth,
3966 TK_RELIEF_RAISED);
3967 gc = wPtr->selectGC;
3968 flags |= TIX_DITEM_SELECTED_FG;
3969 } else {
3970 /*
3971 * Set the TIX_DITEM_NORMAL_BG. This will be used unless
3972 * ACTIVE_BG and/or DISABLE_BG are set
3973 */
3974 bgFlags |= TIX_DITEM_NORMAL_BG;
3975 }
3976
3977 if (chPtr == wPtr->anchor) {
3978 flags |= TIX_DITEM_ACTIVE_FG;
3979
3980 if (!chPtr->selected) {
3981 /* don't set any background when the item is selected (otherwise
3982 * it looks messed up when wideSelect is false
3983 */
3984 bgFlags |= TIX_DITEM_ACTIVE_BG;
3985 }
3986 }
3987 if (chPtr == wPtr->dropSite) {
3988 XDrawRectangle(Tk_Display(wPtr->dispData.tkwin), pixmap,
3989 wPtr->dropSiteGC, selectX, y, selectWidth-1, chPtr->height-1);
3990 }
3991
3992 /*
3993 * Now Draw the display items in each column
3994 *
3995 * %% ToDo: clip off the non-visible items
3996 */
3997 x = xOffset;
3998 for (i=0; i<wPtr->numColumns; i++) {
3999 int drawX = x;
4000 Tix_DItem * iPtr = chPtr->col[i].iPtr;
4001 int itemWidth;
4002
4003 itemWidth = wPtr->actualSize[i].width - 2*wPtr->selBorderWidth;
4004
4005 /*
4006 * Draw the background: this is tricky because we have idented the
4007 * first column. If we call Tix_DItemDisplay() with the background
4008 * flags set, the first column will look ugly
4009 */
4010 if (iPtr != NULL) {
4011 Tix_DItemDrawBackground(pixmap, gc, iPtr,
4012 drawX + wPtr->selBorderWidth, y + wPtr->selBorderWidth,
4013 itemWidth,
4014 chPtr->height - 2*wPtr->selBorderWidth, bgFlags);
4015 }
4016
4017 if (i == 0) {
4018 drawX += chPtr->indent;
4019 itemWidth -= chPtr->indent;
4020 }
4021
4022 if (iPtr != NULL) {
4023 int justMapped = 0;
4024
4025 if (Tix_DItemType(iPtr) == TIX_DITEM_WINDOW) {
4026 Tix_SetWindowItemSerial(&wPtr->mappedWindows,iPtr,
4027 wPtr->serial);
4028 if (!Tk_IsMapped(iPtr->window.tkwin)) {
4029 justMapped = 1;
4030 }
4031 }
4032
4033 Tix_DItemDisplay(pixmap, gc, iPtr,
4034 drawX + wPtr->selBorderWidth, y + wPtr->selBorderWidth,
4035 itemWidth,
4036 chPtr->height - 2*wPtr->selBorderWidth, flags);
4037
4038 if (justMapped) {
4039 /*
4040 * We need to lower it so that it doesn't
4041 * overlap the header subwindow
4042 */
4043 #if 1
4044 Tk_RestackWindow(iPtr->window.tkwin, Below, NULL);
4045 #else
4046 XLowerWindow(Tk_Display(iPtr->window.tkwin),
4047 Tk_WindowId(iPtr->window.tkwin));
4048 #endif
4049
4050 }
4051 }
4052
4053 x += wPtr->actualSize[i].width;
4054 }
4055
4056 if (chPtr == wPtr->anchor) {
4057 int ancW, ancH;
4058 ancW = selectWidth-1;
4059 ancH = chPtr->height-1;
4060
4061 Tix_DrawAnchorLines(Tk_Display(wPtr->dispData.tkwin), pixmap,
4062 wPtr->anchorGC, selectX, y, ancW, ancH);
4063 }
4064 }
4065
4066 /*
4067 *----------------------------------------------------------------------
4068 * SelectionAdd --
4069 *--------------------------------------------------------------
4070 */
4071 static void SelectionAdd(wPtr, chPtr)
4072 WidgetPtr wPtr;
4073 HListElement * chPtr;
4074 {
4075 if (chPtr->selected) { /* sanity check */
4076 return;
4077 }
4078
4079 chPtr->selected = 1;
4080 SelectionNotifyAncestors(wPtr, chPtr->parent);
4081 }
4082
4083 /*
4084 *----------------------------------------------------------------------
4085 * HL_SelectionClear --
4086 *--------------------------------------------------------------
4087 */
4088 static void HL_SelectionClear(wPtr, chPtr)
4089 WidgetPtr wPtr;
4090 HListElement * chPtr;
4091 {
4092 if (! chPtr->selected) { /* sanity check */
4093 return;
4094 }
4095
4096 chPtr->selected = 0;
4097 HL_SelectionClearNotifyAncestors(wPtr, chPtr->parent);
4098 }
4099
4100 /*
4101 *----------------------------------------------------------------------
4102 * HL_SelectionClearAll --
4103 *--------------------------------------------------------------
4104 */
4105 static void HL_SelectionClearAll(wPtr, chPtr, changed_ret)
4106 WidgetPtr wPtr;
4107 HListElement * chPtr;
4108 int * changed_ret;
4109 {
4110 HListElement * ptr;
4111
4112 if (chPtr->selected) {
4113 *changed_ret = 1;
4114 chPtr->selected = 0;
4115 }
4116
4117 if (chPtr->numSelectedChild == 0) {
4118 return;
4119 } else {
4120 chPtr->numSelectedChild = 0;
4121
4122 for (ptr=chPtr->childHead; ptr; ptr=ptr->next) {
4123 HL_SelectionClearAll(wPtr, ptr, changed_ret);
4124 }
4125 }
4126 }
4127
4128 /*
4129 *----------------------------------------------------------------------
4130 * SelectionNotifyAncestors --
4131 *
4132 * !!This has nothing to do with SelectionNotify in X!!
4133 *
4134 * HList keeps a counter in every entry on how many of its
4135 * child entries has been selected. This will make the
4136 * "selection clear" very efficient. To keep this counter
4137 * up-to-date, we must call SelectionNotifyAncestors() or
4138 * HL_SelectionClearNotifyAncestors every time the selection
4139 * has changed.
4140 *--------------------------------------------------------------
4141 */
4142 static void SelectionNotifyAncestors(wPtr, chPtr)
4143 WidgetPtr wPtr;
4144 HListElement * chPtr;
4145 {
4146 chPtr->numSelectedChild ++;
4147
4148 if (chPtr->selected || (chPtr->numSelectedChild > 1)) {
4149 /* My ancestors already know that I have selections */
4150 return;
4151 } else {
4152 if (chPtr != wPtr->root) {
4153 SelectionNotifyAncestors(wPtr, chPtr->parent);
4154 }
4155 }
4156 }
4157
4158 static void HL_SelectionClearNotifyAncestors(wPtr, chPtr)
4159 WidgetPtr wPtr;
4160 HListElement * chPtr;
4161 {
4162 chPtr->numSelectedChild --;
4163
4164 if (chPtr->selected || (chPtr->numSelectedChild > 0)) {
4165 /* I still have selections, don't need to notify parent */
4166 return;
4167 } else {
4168 if (chPtr != wPtr->root) {
4169 SelectionNotifyAncestors(wPtr, chPtr->parent);
4170 }
4171 }
4172 }
4173 /*
4174 *--------------------------------------------------------------
4175 * DeleteOffsprings --
4176 *--------------------------------------------------------------
4177 */
4178 static void DeleteOffsprings(wPtr, chPtr)
4179 WidgetPtr wPtr;
4180 HListElement * chPtr;
4181 {
4182 HListElement * ptr;
4183 HListElement * toFree;
4184
4185 ptr=chPtr->childHead;
4186 while (ptr) {
4187 DeleteOffsprings(wPtr, ptr);
4188 toFree = ptr;
4189 ptr=ptr->next;
4190 FreeElement(wPtr, toFree);
4191 }
4192
4193 chPtr->childHead = 0;
4194 chPtr->childTail = 0;
4195 }
4196
4197 /*
4198 *--------------------------------------------------------------
4199 * DeleteSiblings --
4200 *--------------------------------------------------------------
4201 */
4202 static void DeleteSiblings(wPtr, chPtr)
4203 WidgetPtr wPtr;
4204 HListElement * chPtr;
4205 {
4206 HListElement * ptr;
4207
4208 for (ptr=chPtr->parent->childHead; ptr; ptr=ptr->next) {
4209 if (ptr != chPtr) {
4210 DeleteNode(wPtr, ptr);
4211 }
4212 }
4213 }
4214
4215 /*
4216 *----------------------------------------------------------------------
4217 * DeleteNode --
4218 *--------------------------------------------------------------
4219 */
4220 static void DeleteNode(wPtr, chPtr)
4221 WidgetPtr wPtr;
4222 HListElement * chPtr;
4223 {
4224 if (chPtr->parent == NULL) {
4225 /*
4226 * This is root node : can't delete
4227 */
4228 return;
4229 }
4230
4231 DeleteOffsprings(wPtr, chPtr);
4232
4233 /*
4234 * Check for deleting parent's first child
4235 */
4236 if (chPtr == chPtr->parent->childHead) {
4237 chPtr->parent->childHead = chPtr->next;
4238 }
4239 else {
4240 chPtr->prev->next = chPtr->next;
4241 }
4242
4243 /*
4244 * Check for 'last' child (could be both first AND last)
4245 */
4246 if (chPtr == chPtr->parent->childTail) {
4247 chPtr->parent->childTail = chPtr->prev;
4248 }
4249 else {
4250 chPtr->next->prev = chPtr->prev;
4251 }
4252
4253 FreeElement(wPtr, chPtr);
4254 }
4255
4256 /*
4257 *----------------------------------------------------------------------
4258 * UpdateOneScrollBar --
4259 *--------------------------------------------------------------
4260 */
4261 static void UpdateOneScrollBar(wPtr, command, total, window, first)
4262 WidgetPtr wPtr;
4263 LangCallback *command;
4264 int total;
4265 int window;
4266 int first;
4267 {
4268 double d_first, d_last;
4269
4270 GetScrollFractions(total, window, first, &d_first, &d_last);
4271
4272 if (LangDoCallback(wPtr->dispData.interp, command, 0, 2, " %g %g", d_first, d_last)
4273 != TCL_OK) {
4274 Tcl_AddErrorInfo(wPtr->dispData.interp,
4275 "\n (scrolling command executed by tixHList)");
4276 Tcl_BackgroundError(wPtr->dispData.interp);
4277 }
4278 }
4279
4280 /*----------------------------------------------------------------------
4281 * UpdateScrollBars
4282 *----------------------------------------------------------------------
4283 */
4284 static void UpdateScrollBars(wPtr, sizeChanged)
4285 WidgetPtr wPtr;
4286 int sizeChanged;
4287 {
4288 int total, window, first;
4289
4290 CheckScrollBar(wPtr, TIX_X);
4291 CheckScrollBar(wPtr, TIX_Y);
4292
4293 if (wPtr->xScrollCmd) {
4294 total = wPtr->totalSize[0];
4295 window = Tk_Width(wPtr->dispData.tkwin)
4296 - 2*wPtr->borderWidth - 2*wPtr->highlightWidth;
4297 first = wPtr->leftPixel;
4298 UpdateOneScrollBar(wPtr, wPtr->xScrollCmd, total, window, first);
4299 }
4300
4301 if (wPtr->yScrollCmd) {
4302 total = wPtr->totalSize[1];
4303 window = Tk_Height(wPtr->dispData.tkwin)
4304 - 2*wPtr->borderWidth - 2*wPtr->highlightWidth;
4305 first = wPtr->topPixel;
4306
4307 if (wPtr->useHeader) {
4308 window -= wPtr->headerHeight;
4309 }
4310 UpdateOneScrollBar(wPtr, wPtr->yScrollCmd, total, window, first);
4311 }
4312
4313 if (wPtr->sizeCmd && sizeChanged) {
4314 if (LangDoCallback(wPtr->dispData.interp, wPtr->sizeCmd, 0, 0) != TCL_OK) {
4315 Tcl_AddErrorInfo(wPtr->dispData.interp,
4316 "\n (size command executed by tixHList)");
4317 Tcl_BackgroundError(wPtr->dispData.interp);
4318 }
4319 }
4320 }
4321
4322 /*----------------------------------------------------------------------
4323 * XScrollByUnits
4324 *----------------------------------------------------------------------
4325 */
4326 static int XScrollByUnits(wPtr, count)
4327 WidgetPtr wPtr;
4328 int count;
4329 {
4330 return wPtr->leftPixel + count*wPtr->scrollUnit[0];
4331 }
4332
4333 /*----------------------------------------------------------------------
4334 * XScrollByPages
4335 *----------------------------------------------------------------------
4336 */
4337 static int XScrollByPages(wPtr, count)
4338 WidgetPtr wPtr;
4339 int count;
4340 {
4341 return wPtr->leftPixel + count*Tk_Width(wPtr->dispData.tkwin);
4342 }
4343
4344 /*----------------------------------------------------------------------
4345 * YScrollByUnits
4346 *----------------------------------------------------------------------
4347 */
4348 static int YScrollByUnits(wPtr, count)
4349 WidgetPtr wPtr;
4350 int count;
4351 {
4352 HListElement * chPtr;
4353 int height;
4354
4355 if ((chPtr = FindElementAtPosition(wPtr, 0))) {
4356 height = chPtr->height;
4357 } else if (wPtr->root->childHead) {
4358 height = wPtr->root->childHead->height;
4359 } else {
4360 height = 0;
4361 }
4362
4363 return wPtr->topPixel + count*height;
4364 }
4365
4366 /*----------------------------------------------------------------------
4367 * YScrollByPages
4368 *----------------------------------------------------------------------
4369 */
4370 static int YScrollByPages(wPtr, count)
4371 WidgetPtr wPtr;
4372 int count;
4373 {
4374 int window = Tk_Height(wPtr->dispData.tkwin)
4375 - 2*wPtr->borderWidth - 2*wPtr->highlightWidth;
4376
4377 if (wPtr->useHeader) {
4378 window -= wPtr->headerHeight;
4379 }
4380
4381 return wPtr->topPixel + count*window;
4382 }
4383
4384 /*----------------------------------------------------------------------
4385 * CheckScrollBar
4386 *
4387 * Make sures that the seeting of the scrollbars are correct: i.e.
4388 * the bottom element will never be scrolled up by too much.
4389 *----------------------------------------------------------------------
4390 */
4391 static void CheckScrollBar(wPtr, which)
4392 WidgetPtr wPtr;
4393 int which;
4394 {
4395 int window;
4396 int total;
4397 int first;
4398
4399 if (which == TIX_Y) {
4400 window = Tk_Height(wPtr->dispData.tkwin)
4401 - 2*wPtr->borderWidth - 2*wPtr->highlightWidth;
4402 if (wPtr->useHeader) {
4403 window -= wPtr->headerHeight;
4404 }
4405 total = wPtr->totalSize[1];
4406 first = wPtr->topPixel;
4407 } else {
4408 window = Tk_Width(wPtr->dispData.tkwin)
4409 - 2*wPtr->borderWidth - 2*wPtr->highlightWidth;
4410 total = wPtr->totalSize[0];
4411 first = wPtr->leftPixel;
4412 }
4413
4414 /* Check whether the topPixel is out of bound */
4415 if (first < 0) {
4416 first = 0;
4417 } else {
4418 if (window > total) {
4419 first = 0;
4420 } else if ((first + window) > total) {
4421 first = total - window;
4422 }
4423 }
4424
4425 if (which == TIX_Y) {
4426 wPtr->topPixel = first;
4427 } else {
4428 wPtr->leftPixel = first;
4429 }
4430 }
4431
4432 /*----------------------------------------------------------------------
4433 * GetScrollFractions --
4434 *
4435 * Compute the fractions of a scroll-able widget.
4436 *
4437 */
4438 static void GetScrollFractions(total, window, first, first_ret, last_ret)
4439 int total;
4440 int window;
4441 int first;
4442 double * first_ret;
4443 double * last_ret;
4444 {
4445 if (total == 0 || total < window) {
4446 *first_ret = 0.0;
4447 *last_ret = 1.0;
4448 } else {
4449 *first_ret = (double)(first) / (double)(total);
4450 *last_ret = (double)(first+window) / (double)(total);
4451 }
4452 }
4453
4454 /*----------------------------------------------------------------------
4455 * Find the element that's immediately below this element.
4456 *
4457 *----------------------------------------------------------------------
4458 */
4459 static HListElement *
4460 FindNextEntry(wPtr, chPtr)
4461 WidgetPtr wPtr;
4462 HListElement * chPtr;
4463 {
4464 if (chPtr->childHead != NULL) {
4465 return chPtr->childHead;
4466 }
4467 if (chPtr->next) {
4468 return chPtr->next;
4469 }
4470
4471 /* go to a different branch */
4472 while (1) {
4473 if (chPtr == wPtr->root) {
4474 return (HListElement *)NULL;
4475 }
4476 chPtr = chPtr->parent;
4477 if (chPtr->next) {
4478 return chPtr->next;
4479 }
4480 }
4481 }
4482
4483 /*----------------------------------------------------------------------
4484 * Find the element that's immediately above this element.
4485 *
4486 *----------------------------------------------------------------------
4487 */
4488 static HListElement *
4489 FindPrevEntry(wPtr, chPtr)
4490 WidgetPtr wPtr;
4491 HListElement * chPtr;
4492 {
4493 if (chPtr->prev) {
4494 /* Find the bottom of this sub-tree
4495 */
4496 for (chPtr=chPtr->prev; chPtr->childTail; chPtr = chPtr->childTail)
4497 ;
4498
4499 return chPtr;
4500 } else {
4501 if (chPtr->parent == wPtr->root) {
4502 return 0;
4503 } else {
4504 return chPtr->parent;
4505 }
4506 }
4507 }
4508
4509
4510 /*----------------------------------------------------------------------
4511 * Recurse through all items and gather the -text arguments of selected
4512 * entries.
4513 *
4514 *----------------------------------------------------------------------
4515 */
4516 static void
4517 GetSelectedText(wPtr, chPtr, selection)
4518 WidgetPtr wPtr;
4519 HListElement * chPtr;
4520 Tcl_DString * selection;
4521 {
4522 register HListElement * ptr;
4523 int needTab, j;
4524
4525 for (ptr = chPtr->childHead; ptr; ptr = ptr->next) {
4526 if (ptr->selected && !ptr->hidden) {
4527 needTab = 0;
4528 for (j = 0; j < wPtr->numColumns; j++) {
4529 Tix_DItem *iPtr = ptr->col[j].iPtr;
4530 if (needTab) {
4531 Tcl_DStringAppend(selection, "\t", 1);
4532 }
4533 if (iPtr) {
4534 switch (Tix_DItemType(iPtr)) {
4535 case TIX_DITEM_TEXT:
4536 Tcl_DStringAppend(selection,
4537 Tcl_GetString(iPtr->text.text),
4538 iPtr->text.numChars);
4539 break;
4540 case TIX_DITEM_IMAGETEXT:
4541 Tcl_DStringAppend(selection,
4542 Tcl_GetString(iPtr->imagetext.text),
4543 iPtr->imagetext.numChars);
4544 break;
4545 }
4546 }
4547 needTab = 1;
4548 }
4549 Tcl_DStringAppend(selection, "\n", 1);
4550 }
4551 if (!ptr->hidden) {
4552 if (ptr->childHead) {
4553 GetSelectedText(wPtr, ptr, selection);
4554 }
4555 }
4556 }
4557 }
4558
4559
4560 /*
4561 *----------------------------------------------------------------------
4562 *
4563 * HListFetchSelection --
4564 *
4565 * This procedure is called back by Tk when the selection is
4566 * requested by someone. It returns part or all of the selection
4567 * in a buffer provided by the caller.
4568 *
4569 * Results:
4570 * The return value is the number of non-NULL bytes stored
4571 * at buffer. Buffer is filled (or partially filled) with a
4572 * NULL-terminated string containing part or all of the selection,
4573 * as given by offset and maxBytes. The selection is returned
4574 * as a Tcl list with one list element for each element in the
4575 * listbox.
4576 *
4577 * Side effects:
4578 * None.
4579 *
4580 *----------------------------------------------------------------------
4581 */
4582
4583 static int
4584 HListFetchSelection(clientData, offset, buffer, maxBytes)
4585 ClientData clientData; /* Information about hlist widget. */
4586 int offset; /* Offset within selection of first
4587 * byte to be returned. */
4588 char *buffer; /* Location in which to place
4589 * selection. */
4590 int maxBytes; /* Maximum number of bytes to place
4591 * at buffer, not including terminating
4592 * NULL character. */
4593 {
4594 register WidgetPtr wPtr = (WidgetPtr ) clientData;
4595 Tcl_DString selection;
4596 int length, count;
4597
4598 if (!wPtr->exportSelection) {
4599 return -1;
4600 }
4601
4602 /*
4603 * Use a dynamic string to accumulate the contents of the selection.
4604 */
4605
4606 Tcl_DStringInit(&selection);
4607 GetSelectedText(wPtr, wPtr->root, &selection);
4608
4609 length = Tcl_DStringLength(&selection);
4610 if (length == 0) {
4611 return -1;
4612 }
4613
4614 /*
4615 * Copy the requested portion of the selection to the buffer.
4616 */
4617
4618 count = length - offset;
4619 if (count <= 0) {
4620 count = 0;
4621 } else {
4622 if (count > maxBytes) {
4623 count = maxBytes;
4624 }
4625 memcpy((VOID *) buffer,
4626 (VOID *) (Tcl_DStringValue(&selection) + offset),
4627 (size_t) count);
4628 }
4629 buffer[count] = '\0';
4630 Tcl_DStringFree(&selection);
4631 return count;
4632 }
4633
4634 /*
4635 *----------------------------------------------------------------------
4636 *
4637 * HListLostSelection --
4638 *
4639 * This procedure is called back by Tk when the selection is
4640 * grabbed away from a HList widget.
4641 *
4642 * Results:
4643 * None.
4644 *
4645 * Side effects:
4646 * The existing selection is unhighlighted, and the window is
4647 * marked as not containing a selection.
4648 *
4649 *----------------------------------------------------------------------
4650 */
4651
4652 static void
4653 HListLostSelection(clientData)
4654 ClientData clientData; /* Information about listbox widget. */
4655 {
4656 WidgetPtr wPtr = (WidgetPtr) clientData;
4657 int changed = 0;
4658 if ((wPtr->exportSelection) && (wPtr->root != NULL)) {
4659 HL_SelectionClearAll(wPtr, wPtr->root, &changed);
4660 if (changed) {
4661 RedrawWhenIdle(wPtr);
4662 }
4663 }
4664 }
4665
4666
4667