summaryrefslogtreecommitdiffstats
path: root/generic/tkTreeNotify.c
blob: b117e3c2f0310841def9931e6a7eb9621351cd88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
/* 
 * tkTreeNotify.c --
 *
 *	This module implements "qebind.c" events for treectrl widgets.
 *
 * Copyright (c) 2002-2006 Tim Baker
 *
 * RCS: @(#) $Id: tkTreeNotify.c,v 1.21 2006/12/23 04:32:08 treectrl Exp $
 */

#include "tkTreeCtrl.h"
#include "tclInt.h" /* TclFormatInt */

static int EVENT_EXPAND,
    DETAIL_EXPAND_BEFORE,
    DETAIL_EXPAND_AFTER;
static int EVENT_COLLAPSE,
    DETAIL_COLLAPSE_BEFORE,
    DETAIL_COLLAPSE_AFTER;
static int EVENT_SELECTION;
static int EVENT_ACTIVEITEM;
static int EVENT_SCROLL,
    DETAIL_SCROLL_X,
    DETAIL_SCROLL_Y;
static int EVENT_ITEM_DELETE;
static int EVENT_ITEM_VISIBILITY;

/*
 *----------------------------------------------------------------------
 *
 * ExpandItem --
 *
 *	Append an item ID to a dynamic string.
 *
 * Results:
 *	DString gets longer.
 *
 * Side effects:
 *	Memory may be allocated.
 *
 *----------------------------------------------------------------------
 */

static void
ExpandItem(
    TreeCtrl *tree,		/* Widget info. */
    int id,			/* Item ID. */
    Tcl_DString *result		/* Gets appended. Caller must initialize. */
    )
{
    if (tree->itemPrefixLen) {
	char buf[10 + TCL_INTEGER_SPACE];
	(void) sprintf(buf, "%s%d", tree->itemPrefix, id);
	Tcl_DStringAppend(result, buf, -1);
    } else
	QE_ExpandNumber(id, result);
}

/*
 *----------------------------------------------------------------------
 *
 * DumpPercents --
 *
 *	Appends a sublist to a dynamic string. The sublist contains
 *	%-char,value pairs. This is to handle the %? substitution.
 *
 * Results:
 *	DString gets longer.
 *
 * Side effects:
 *	Memory may be allocated.
 *
 *----------------------------------------------------------------------
 */

static void
DumpPercents(
    QE_ExpandArgs *args,	/* %-substitution args. */
    QE_ExpandProc proc,		/* Function to return value for a given
				 * %-char. */
    CONST char *chars		/* NULL-terminated list of %-chars. */
    )
{
    char which = args->which;
    char buf[2];
    int i;

    buf[1] = '\0';

    Tcl_DStringStartSublist(args->result);
    for (i = 0; chars[i]; i++) {
	args->which = chars[i];
	buf[0] = chars[i];
	Tcl_DStringAppendElement(args->result, buf);
	Tcl_DStringAppend(args->result, " ", 1);
	(*proc)(args);
    }
    Tcl_DStringEndSublist(args->result);
    args->which = which;
}

/*
 *----------------------------------------------------------------------
 *
 * Percents_Any --
 *
 *	Append a value for a single %-char to a dynamic string. This
 *	function handles the default %-chars (d,e,P,W,T, and ?) and
 *	calls QE_ExpandUnknown() for any unrecognized %-char.
 *
 * Results:
 *	DString gets longer.
 *
 * Side effects:
 *	Memory may be allocated.
 *
 *----------------------------------------------------------------------
 */

static void
Percents_Any(
    QE_ExpandArgs *args,	/* %-substitution args. */
    QE_ExpandProc proc,		/* Function to return value for a given
				* %-char. */
    CONST char *chars		/* NULL-terminated list of %-chars. */
    )
{
    struct {
	TreeCtrl *tree;
    } *data = args->clientData;
    char chars2[64];

    switch (args->which) {
	case 'd': /* detail */
	    QE_ExpandDetail(args->bindingTable, args->event, args->detail,
		args->result);
	    break;

	case 'e': /* event */
	    QE_ExpandEvent(args->bindingTable, args->event, args->result);
	    break;

	case 'P': /* pattern */
	    QE_ExpandPattern(args->bindingTable, args->event, args->detail, args->result);
	    break;

	case 'W': /* object */
	    QE_ExpandString((char *) args->object, args->result);
	    break;

	case 'T': /* tree */
	    QE_ExpandString(Tk_PathName(data->tree->tkwin), args->result);
	    break;

	case '?':
	    strcpy(chars2, "TWPed");
	    strcat(chars2, chars);
	    DumpPercents(args, proc, chars2);
	    break;

	default:
	    QE_ExpandUnknown(args->which, args->result);
	    break;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Percents_Expand --
 *
 *	%-substitution callback for <Expand>.
 *
 * Results:
 *	DString gets longer.
 *
 * Side effects:
 *	Memory may be allocated.
 *
 *----------------------------------------------------------------------
 */

static void
Percents_Expand(
    QE_ExpandArgs *args		/* %-substitution args. */
    )
{
    struct {
	TreeCtrl *tree; /* Must be first. See Percents_Any(). */
	int id;
    } *data = args->clientData;

    switch (args->which) {
	case 'I':
	    ExpandItem(data->tree, data->id, args->result);
	    break;

	default:
	    Percents_Any(args, Percents_Expand, "I");
	    break;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Percents_ItemVisibility --
 *
 *	%-substitution callback for <ItemVisibility>.
 *
 * Results:
 *	DString gets longer.
 *
 * Side effects:
 *	Memory may be allocated.
 *
 *----------------------------------------------------------------------
 */

static void
Percents_ItemVisibility(
    QE_ExpandArgs *args		/* %-substitution args. */
    )
{
    struct {
	TreeCtrl *tree; /* Must be first. See Percents_Any(). */
	TreeItemList *v;
	TreeItemList *h;
    } *data = args->clientData;
    TreeCtrl *tree = data->tree;
    TreeItemList *table;
    int i, count;

    switch (args->which) {
	case 'v':
	case 'h':
	    table = (args->which == 'v') ? data->v : data->h;
	    Tcl_DStringStartSublist(args->result);
	    count = TreeItemList_Count(table);
	    for (i = 0; i < count; i++) {
		TreeItem item = TreeItemList_Nth(table, i);
		if (tree->itemPrefixLen) {
		    char buf[10 + TCL_INTEGER_SPACE];
		    (void) sprintf(buf, "%s%d", tree->itemPrefix,
			    TreeItem_GetID(tree, item));
		    Tcl_DStringAppendElement(args->result, buf);
		} else {
		    char string[TCL_INTEGER_SPACE];
		    TclFormatInt(string, TreeItem_GetID(tree, item));
		    Tcl_DStringAppendElement(args->result, string);
		}
	    }
	    Tcl_DStringEndSublist(args->result);
	    break;

	default:
	    Percents_Any(args, Percents_ItemVisibility, "vh");
	    break;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Percents_Selection --
 *
 *	%-substitution callback for <Selection>.
 *
 * Results:
 *	DString gets longer.
 *
 * Side effects:
 *	Memory may be allocated.
 *
 *----------------------------------------------------------------------
 */

static void
Percents_Selection(
    QE_ExpandArgs *args		/* %-substitution args. */
    )
{
    struct {
	TreeCtrl *tree; /* Must be first. See Percents_Any(). */
	TreeItemList *select;
	TreeItemList *deselect;
	int count;
    } *data = args->clientData;
    TreeCtrl *tree = data->tree;
    TreeItemList *itemList;
    int i, count;

    switch (args->which) {
	case 'c':
	    QE_ExpandNumber(data->count, args->result);
	    break;
	case 'D':
	case 'S':
	    itemList = (args->which == 'D') ? data->deselect : data->select;
	    if (itemList == NULL) {
		Tcl_DStringAppend(args->result, "{}", 2);
		break;
	    }
	    Tcl_DStringStartSublist(args->result);
	    count = TreeItemList_Count(itemList);
	    for (i = 0; i < count; i++) {
		TreeItem item = TreeItemList_Nth(itemList, i);
		if (tree->itemPrefixLen) {
		    char buf[10 + TCL_INTEGER_SPACE];
		    (void) sprintf(buf, "%s%d", tree->itemPrefix,
			    TreeItem_GetID(tree, item));
		    Tcl_DStringAppendElement(args->result, buf);
		} else {
		    char string[TCL_INTEGER_SPACE];
		    TclFormatInt(string, TreeItem_GetID(tree, item));
		    Tcl_DStringAppendElement(args->result, string);
		}
	    }
	    Tcl_DStringEndSublist(args->result);
	    break;

	default:
	    Percents_Any(args, Percents_Selection, "cSD");
	    break;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Percents_ActiveItem --
 *
 *	%-substitution callback for <ActiveItem>.
 *
 * Results:
 *	DString gets longer.
 *
 * Side effects:
 *	Memory may be allocated.
 *
 *----------------------------------------------------------------------
 */

static void
Percents_ActiveItem(
    QE_ExpandArgs *args		/* %-substitution args. */
    )
{
    struct {
	TreeCtrl *tree; /* Must be first. See Percents_Any(). */
	int prev;
	int current;
    } *data = args->clientData;

    switch (args->which) {
	case 'c':
	    ExpandItem(data->tree, data->current, args->result);
	    break;

	case 'p':
	    ExpandItem(data->tree, data->prev, args->result);
	    break;

	default:
	    Percents_Any(args, Percents_ActiveItem, "cp");
	    break;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Percents_Scroll --
 *
 *	%-substitution callback for <Scroll>.
 *
 * Results:
 *	DString gets longer.
 *
 * Side effects:
 *	Memory may be allocated.
 *
 *----------------------------------------------------------------------
 */

static void
Percents_Scroll(
    QE_ExpandArgs *args		/* %-substitution args. */
    )
{
    struct {
	TreeCtrl *tree; /* Must be first. See Percents_Any(). */
	double lower;
	double upper;
    } *data = args->clientData;

    switch (args->which) {
	case 'l':
	    QE_ExpandDouble(data->lower, args->result);
	    break;

	case 'u':
	    QE_ExpandDouble(data->upper, args->result);
	    break;

	default:
	    Percents_Any(args, Percents_Scroll, "lu");
	    break;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TreeNotifyCmd --
 *
 *	This procedure is invoked to process the [notify] widget
 *	command.  See the user documentation for details on what
 *	it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *----------------------------------------------------------------------
 */

int
TreeNotifyCmd(
    ClientData clientData,	/* Widget info. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *CONST objv[]	/* Argument values. */
    )
{
    TreeCtrl *tree = clientData;
    static CONST char *commandName[] = { "bind", "configure", "detailnames",
	"eventnames", "generate", "install", "linkage", "unbind", "uninstall",
	(char *) NULL };
    enum {
	COMMAND_BIND, COMMAND_CONFIGURE, COMMAND_DETAILNAMES,
	COMMAND_EVENTNAMES, COMMAND_GENERATE, COMMAND_INSTALL,
	COMMAND_LINKAGE, COMMAND_UNBIND, COMMAND_UNINSTALL
    };
    int index;

    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 2, objv, "command ?arg arg ...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObj(interp, objv[2], commandName, "command", 0,
	&index) != TCL_OK) {
	return TCL_ERROR;
    }

    switch (index) {
	case COMMAND_BIND: {
	    return QE_BindCmd(tree->bindingTable, 2, objc, objv);
	}

	case COMMAND_CONFIGURE: {
	    return QE_ConfigureCmd(tree->bindingTable, 2, objc, objv);
	}

	/* T notify detailnames $eventName */
	case COMMAND_DETAILNAMES: {
	    char *eventName;

	    if (objc != 4) {
		Tcl_WrongNumArgs(interp, 3, objv, "eventName");
		return TCL_ERROR;
	    }
	    eventName = Tcl_GetString(objv[3]);
	    return QE_GetDetailNames(tree->bindingTable, eventName);
	}

	/* T notify eventnames */
	case COMMAND_EVENTNAMES: {
	    if (objc != 3) {
		Tcl_WrongNumArgs(interp, 3, objv, (char *) NULL);
		return TCL_ERROR;
	    }
	    return QE_GetEventNames(tree->bindingTable);
	}

	case COMMAND_GENERATE: {
	    return QE_GenerateCmd(tree->bindingTable, 2, objc, objv);
	}

	case COMMAND_INSTALL: {
	    return QE_InstallCmd(tree->bindingTable, 2, objc, objv);
	}

	case COMMAND_LINKAGE: {
	    return QE_LinkageCmd(tree->bindingTable, 2, objc, objv);
	}

	case COMMAND_UNBIND: {
	    return QE_UnbindCmd(tree->bindingTable, 2, objc, objv);
	}

	case COMMAND_UNINSTALL: {
	    return QE_UninstallCmd(tree->bindingTable, 2, objc, objv);
	}
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TreeNotify_OpenClose --
 *
 *	Generate an <Expand> or <Collapse> event.
 *
 * Results:
 *	Any scripts bound to the event are evaluated.
 *
 * Side effects:
 *	Whatever binding scripts do.
 *
 *----------------------------------------------------------------------
 */

void
TreeNotify_OpenClose(
    TreeCtrl *tree,		/* Widget info. */
    TreeItem item,		/* Item token. */
    int state,			/* STATE_OPEN or 0 */
    int before			/* TRUE for <xxx-before> event, FALSE for
				 * <xxx-after> event. */
    )
{
    QE_Event event;
    struct {
	TreeCtrl *tree; /* Must be first. See Percents_Any(). */
	int id;
    } data;

    data.tree = tree;
    data.id = TreeItem_GetID(tree, item);

    if (state & STATE_OPEN) {
	event.type = EVENT_EXPAND;
	event.detail = before ? DETAIL_EXPAND_BEFORE : DETAIL_EXPAND_AFTER;
    } else {
	event.type = EVENT_COLLAPSE;
	event.detail = before ? DETAIL_COLLAPSE_BEFORE : DETAIL_COLLAPSE_AFTER;
    }
    event.clientData = (ClientData) &data;
    (void) QE_BindEvent(tree->bindingTable, &event);
}

/*
 *----------------------------------------------------------------------
 *
 * TreeNotify_Selection --
 *
 *	Generate a <Selection> event.
 *
 * Results:
 *	Any scripts bound to the event are evaluated.
 *
 * Side effects:
 *	Whatever binding scripts do.
 *
 *----------------------------------------------------------------------
 */

void
TreeNotify_Selection(
    TreeCtrl *tree,		/* Widget info. */
    TreeItemList *select,	/* List of items or NULL. */
    TreeItemList *deselect	/* List of items or NULL. */
    )
{
    QE_Event event;
    struct {
	TreeCtrl *tree; /* Must be first. See Percents_Any(). */
	TreeItemList *select;
	TreeItemList *deselect;
	int count;
    } data;

    data.tree = tree;
    data.select = select;
    data.deselect = deselect;
    data.count = tree->selectCount;

    event.type = EVENT_SELECTION;
    event.detail = 0;
    event.clientData = (ClientData) &data;

    (void) QE_BindEvent(tree->bindingTable, &event);
}

/*
 *----------------------------------------------------------------------
 *
 * TreeNotify_ActiveItem --
 *
 *	Generate an <ActiveItem> event.
 *
 * Results:
 *	Any scripts bound to the event are evaluated.
 *
 * Side effects:
 *	Whatever binding scripts do.
 *
 *----------------------------------------------------------------------
 */

void
TreeNotify_ActiveItem(
    TreeCtrl *tree,		/* Widget info. */
    TreeItem itemPrev,		/* Previous active item. */
    TreeItem itemCur		/* Current active item. */
    )
{
    QE_Event event;
    struct {
	TreeCtrl *tree; /* Must be first. See Percents_Any(). */
	int prev;
	int current;
    } data;

    data.tree = tree;
    data.prev = TreeItem_GetID(tree, itemPrev);
    data.current = TreeItem_GetID(tree, itemCur);

    event.type = EVENT_ACTIVEITEM;
    event.detail = 0;
    event.clientData = (ClientData) &data;

    (void) QE_BindEvent(tree->bindingTable, &event);
}

/*
 *----------------------------------------------------------------------
 *
 * TreeNotify_Scroll --
 *
 *	Generate a <Scroll> event.
 *
 * Results:
 *	Any scripts bound to the event are evaluated.
 *
 * Side effects:
 *	Whatever binding scripts do.
 *
 *----------------------------------------------------------------------
 */

void
TreeNotify_Scroll(
    TreeCtrl *tree,		/* Widget info. */
    double fractions[2],	/* Fractions suitable for a scrollbar's
				 * [set] command. */
    int vertical		/* TRUE for <Scroll-y>, FALSE for
				 * <Scroll-x>. */
    )
{
    QE_Event event;
    struct {
	TreeCtrl *tree; /* Must be first. See Percents_Any(). */
	double lower;
	double upper;
    } data;

    data.tree = tree;
    data.lower = fractions[0];
    data.upper = fractions[1];

    event.type = EVENT_SCROLL;
    event.detail = vertical ? DETAIL_SCROLL_Y : DETAIL_SCROLL_X;
    event.clientData = (ClientData) &data;

    (void) QE_BindEvent(tree->bindingTable, &event);
}

/*
 *----------------------------------------------------------------------
 *
 * Percents_ItemDelete --
 *
 *	%-substitution callback for <ItemDelete>.
 *
 * Results:
 *	DString gets longer.
 *
 * Side effects:
 *	Memory may be allocated.
 *
 *----------------------------------------------------------------------
 */

static void
Percents_ItemDelete(
    QE_ExpandArgs *args			/* %-substitution args. */
    )
{
    struct {
	TreeCtrl *tree; /* Must be first. See Percents_Any(). */
	TreeItemList *items;
    } *data = args->clientData;
    TreeCtrl *tree = data->tree;
    int i, count;

    switch (args->which) {
	case 'i':
	    Tcl_DStringStartSublist(args->result);
	    count = TreeItemList_Count(data->items);
	    for (i = 0; i < count; i++) {
		TreeItem item = TreeItemList_Nth(data->items, i);
		if (tree->itemPrefixLen) {
		    char buf[10 + TCL_INTEGER_SPACE];
		    (void) sprintf(buf, "%s%d", tree->itemPrefix,
			    TreeItem_GetID(tree, item));
		    Tcl_DStringAppendElement(args->result, buf);
		} else {
		    char string[TCL_INTEGER_SPACE];
		    TclFormatInt(string, TreeItem_GetID(tree, item));
		    Tcl_DStringAppendElement(args->result, string);
		}
	    }
	    Tcl_DStringEndSublist(args->result);
	    break;

	default:
	    Percents_Any(args, Percents_ItemDelete, "i");
	    break;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TreeNotify_ItemDeleted --
 *
 *	Generate an <ItemDelete> event.
 *
 * Results:
 *	Any scripts bound to the event are evaluated.
 *
 * Side effects:
 *	Whatever binding scripts do.
 *
 *----------------------------------------------------------------------
 */

void
TreeNotify_ItemDeleted(
    TreeCtrl *tree,		/* Widget info. */
    TreeItemList *items		/* List of items. */
    )
{
    QE_Event event;
    struct {
	TreeCtrl *tree; /* Must be first. See Percents_Any(). */
	TreeItemList *items;
    } data;

    data.tree = tree;
    data.items = items;

    event.type = EVENT_ITEM_DELETE;
    event.detail = 0;
    event.clientData = (ClientData) &data;

    (void) QE_BindEvent(tree->bindingTable, &event);
}

/*
 *----------------------------------------------------------------------
 *
 * TreeNotify_ItemVisibility --
 *
 *	Generate an <ItemVisibility> event.
 *
 * Results:
 *	Any scripts bound to the event are evaluated.
 *
 * Side effects:
 *	Whatever binding scripts do.
 *
 *----------------------------------------------------------------------
 */

void
TreeNotify_ItemVisibility(
    TreeCtrl *tree,		/* Widget info. */
    TreeItemList *v,		/* List of newly-visible items. */
    TreeItemList *h		/* List of newly-hidden items. */
    )
{
    QE_Event event;
    struct {
	TreeCtrl *tree; /* Must be first. See Percents_Any(). */
	TreeItemList *v;
	TreeItemList *h;
    } data;

    data.tree = tree;
    data.v = v;
    data.h = h;

    event.type = EVENT_ITEM_VISIBILITY;
    event.detail = 0;
    event.clientData = (ClientData) &data;

    (void) QE_BindEvent(tree->bindingTable, &event);
}

/*
 *----------------------------------------------------------------------
 *
 * TreeNotify_Init --
 *
 *	Perform event-related initialization when a new TreeCtrl is
 *	created.
 *
 * Results:
 *	Installs all the static events and details.
 *
 * Side effects:
 *	Memory is allocated.
 *
 *----------------------------------------------------------------------
 */

int
TreeNotify_Init(
    TreeCtrl *tree		/* Widget info. */
    )
{
    tree->bindingTable = QE_CreateBindingTable(tree->interp);

    EVENT_EXPAND = QE_InstallEvent(tree->bindingTable, "Expand", Percents_Expand);
    DETAIL_EXPAND_BEFORE = QE_InstallDetail(tree->bindingTable, "before", EVENT_EXPAND, NULL);
    DETAIL_EXPAND_AFTER = QE_InstallDetail(tree->bindingTable, "after", EVENT_EXPAND, NULL);

    EVENT_COLLAPSE = QE_InstallEvent(tree->bindingTable, "Collapse", Percents_Expand);
    DETAIL_COLLAPSE_BEFORE = QE_InstallDetail(tree->bindingTable, "before", EVENT_COLLAPSE, NULL);
    DETAIL_COLLAPSE_AFTER = QE_InstallDetail(tree->bindingTable, "after", EVENT_COLLAPSE, NULL);

    EVENT_SELECTION = QE_InstallEvent(tree->bindingTable, "Selection", Percents_Selection);

    EVENT_ACTIVEITEM = QE_InstallEvent(tree->bindingTable, "ActiveItem", Percents_ActiveItem);

    EVENT_SCROLL = QE_InstallEvent(tree->bindingTable, "Scroll", Percents_Scroll);
    DETAIL_SCROLL_X = QE_InstallDetail(tree->bindingTable, "x", EVENT_SCROLL, NULL);
    DETAIL_SCROLL_Y = QE_InstallDetail(tree->bindingTable, "y", EVENT_SCROLL, NULL);

    EVENT_ITEM_DELETE = QE_InstallEvent(tree->bindingTable, "ItemDelete", Percents_ItemDelete);

    EVENT_ITEM_VISIBILITY = QE_InstallEvent(tree->bindingTable, "ItemVisibility", Percents_ItemVisibility);

    return TCL_OK;
}