summaryrefslogtreecommitdiffstats
path: root/demos/mycomputer.tcl
blob: b2de18dc9d7f35849101fe7fdff8fc6de2012cee (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
# RCS: @(#) $Id: mycomputer.tcl,v 1.3 2006/10/28 01:26:03 treectrl Exp $

proc DemoMyComputer {} {

    set T .f2.f1.t

    #
    # Configure the treectrl widget
    #

    $T configure -showroot no -showbuttons no -showlines no \
	-selectmode browse -xscrollincrement 20 \
	-font [.menubar cget -font]

    #
    # Create columns
    #

    $T column create -text Name -tags name -width 200
    $T column create -text Type -tags type -width 120
    $T column create -text "Total Size" -tags size -justify right -width 100 \
	-arrowside left -arrowgravity right
    $T column create -text "Free Space" -tags free -justify right -width 100
    $T column create -text Comments -tags comment -width 120

    #
    # Create elements
    #

    $T element create txtHeader text -font [list "[$T cget -font] bold"]
    $T element create txtName text -fill [list $::SystemHighlightText {selected focus}] \
	-lines 1
    $T element create txtOther text -lines 1
    $T element create elemRectSel rect -fill [list $::SystemHighlight {selected focus} gray {selected !focus}] -showfocus yes
    $T element create rectDivider rect -fill blue -height 1 -width 250

    #
    # Create styles using the elements
    #

    # header
    set S [$T style create styHeader -orient vertical]
    $T style elements $S {txtHeader rectDivider}
    $T style layout $S txtHeader -padx 10 -pady {10 0} -expand ns
    $T style layout $S rectDivider -pady {2 8}

    # name
    set S [$T style create styName -orient horizontal]
    $T style elements $S {elemRectSel txtName}
    $T style layout $S txtName -padx {16 0} -squeeze x -expand ns
    $T style layout $S elemRectSel -union [list txtName] -ipadx 2 -pady 1 -iexpand ns

    # other text
    set S [$T style create styOther]
    $T style elements $S txtOther
    $T style layout $S txtOther -padx 6 -squeeze x -expand ns

    # List of lists: {column style element ...} specifying text elements
    # the user can edit
    TreeCtrl::SetEditable $T {
    }

    # List of lists: {column style element ...} specifying elements
    # the user can click on or select with the selection rectangle
    TreeCtrl::SetSensitive $T {
	{name styName txtName}
    }

    # List of lists: {column style element ...} specifying elements
    # added to the drag image when dragging selected items
    TreeCtrl::SetDragImage $T {
	{name styName txtName}
    }

    #
    # Create items and assign styles
    #

    foreach {name type size free comment} {
	"Files Stored on This Computer" "" "" "" ""
	"Shared Documents" "File Folder" "" "" ""
	"Tim's Documents" "File Folder" "" "" ""
	"Hard Disk Drives" "" "" "" ""
	"Local Disk (C:)" "Local Disk" "55.8 GB" "1.84 GB" ""
	"Devices with Removable Storage" "" "" "" ""
	"3.5 Floppy (A:)" "3.5-Inch Floppy Disk" "" "" ""
	"DVD Drive (D:)" "CD Drive" "" "" ""
	"CD-RW Drive (E:)" "CD Drive" "" "" ""
	"Other" "" "" "" ""
	"My Logitech Pictures" "System Folder" "" "" ""
	"Scanners and Cameras" "" "" "" ""
	"Logitech QuickCam Messenger" "Digital camera" "" "" ""
    } {
	set I [$T item create]
	if {$type eq ""} {
	    $T item style set $I 0 styHeader
	    $T item span $I 0 5
	    # The headers are disabled so they can't be selected and
	    # keyboard navigation skips over them.
	    $T item enabled $I false
	    $T item text $I name $name
	} else {
	    $T item style set $I name styName type styOther
	    $T item text $I name $name type $type
	    if {$size ne ""} {
		$T item style set $I size styOther free styOther
		$T item text $I size $size free $free
	    }
	}
	$T item lastchild root $I
    }

#    bindtags $T [list $T TreeCtrlFileList TreeCtrl [winfo toplevel $T] all]
}