1# RCS: @(#) $Id: textvariable.tcl,v 1.7 2006/11/30 02:41:39 treectrl Exp $
2
3proc DemoTextvariable {} {
4
5    set T [DemoList]
6
7    #
8    # Configure the treectrl widget
9    #
10
11    $T configure -showroot no -showbuttons no -showlines no \
12	-selectmode extended -xscrollincrement 20 \
13	-yscrollincrement 10 -showheader yes
14if {!$::clip} {
15    # Hide the borders because child windows appear on top of them
16    $T configure -borderwidth 0 -highlightthickness 0
17}
18    #
19    # Create columns
20    #
21
22    $T column create -text "Resize Me!" -justify center -tags C0
23    $T configure -treecolumn C0
24
25    #
26    # Create elements
27    #
28
29    $T element create eWindow window
30    $T element create eRect rect
31    $T element create eText1 text -width 300
32    $T element create eText2 text -wrap none
33
34    #
35    # Create styles using the elements
36    #
37
38    set S [$T style create s1 -orient horizontal]
39    $T style elements $S eText1
40    $T style layout $S eText1 -padx 10 -pady 6 -squeeze x
41
42    set S [$T style create s2 -orient vertical]
43    $T style elements $S {eRect eText2 eWindow}
44    $T style layout $S eRect -union {eText2 eWindow} -ipadx 8 -ipady 8 -padx 4 -pady {0 4}
45    $T style layout $S eText2 -pady {0 6} -squeeze x
46    $T style layout $S eWindow -iexpand x -squeeze x
47
48    #
49    # Create items and assign styles
50    #
51
52    set I [$T item create]
53    $T item style set $I C0 s1
54    $T item element configure $I C0 eText1 -text "Each text element and entry widget share the same -textvariable. Editing the text in the entry automatically updates the text element."
55    $T item lastchild root $I
56
57    foreach i {0 1} color {gray75 "light blue"} {
58	set I [$T item create]
59	$T item style set $I C0 s2
60if {$::clip} {
61	set clip [frame $T.clip$I -borderwidth 0]
62	set e [$::entryCmd $clip.e -width 48 -textvariable tvar$I]
63	$T item element configure $I C0 \
64	    eRect -fill [list $color] + \
65	    eText2 -textvariable tvar$I + \
66	    eWindow -window $clip -clip yes
67} else {
68	set e [$::entryCmd $T.e$I -width 48 -textvariable tvar$I]
69	$T item element configure $I C0 \
70	    eRect -fill [list $color] + \
71	    eText2 -textvariable tvar$I + \
72	    eWindow -window $e
73}
74	$T item lastchild root $I
75	set ::tvar$I "This is item $I"
76    }
77
78    return
79}
80
81