summaryrefslogtreecommitdiffstats
path: root/demos/imovie.tcl
blob: a9884704c0d6eafc4ecb27c4e288a1475469d9a1 (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
# RCS: @(#) $Id: imovie.tcl,v 1.16 2006/11/30 02:41:38 treectrl Exp $

#
# Demo: iMovie
#
proc DemoIMovie {} {

    set T [DemoList]

    #
    # Configure the treectrl widget
    #

    $T configure -showroot no -showbuttons no -showlines no \
	-selectmode browse -orient horizontal -wrap window \
	-showheader no -background #dcdcdc

    #
    # Create columns
    #

    $T column create -tags C0

    InitPics imovie-*

    switch -- $::thisPlatform {
	macintosh -
	macosx {
	    set font1 {Geneva 9}
	    set font2 {Geneva 10}
	}
	unix {
	    set font1 {Helvetica 12}
	    set font2 {Helvetica 14}
	}
	default {
	    set font1 {Helvetica 8}
	    set font2 {Helvetica 10}
	}
    }

    #
    # Create elements
    #

    $T element create elemTime text -font [list $font1]
    $T element create elemName text -font [list $font2] -lines 1 -width 80
    $T element create elemRect rect -fill {#ffdc5a {selected} white {}} \
	-outline #827878 -outlinewidth 1
    $T element create elemImg image
    $T element create elemShadow rect -outline gray -outlinewidth 1 -open wn

    #
    # Create styles using the elements
    #

    set S [$T style create STYLE -orient vertical]
    $T style elements $S {elemShadow elemRect elemTime elemImg elemName}
    $T style layout $S elemShadow -detach yes -padx {1 2} -pady {1 2} -iexpand xy
    $T style layout $S elemTime -padx {2 0}
    $T style layout $S elemImg -pady {0 1}
    $T style layout $S elemName -expand we -ipady {0 2} -padx {0 3} -squeeze x
    $T style layout $S elemRect -union {elemTime elemImg elemName} \
	-ipadx 6 -padx {0 3} -pady {0 3}

    # Set default item style
    $T column configure C0 -itemstyle $S

    #
    # Create items and assign styles
    #

    for {set i 0} {$i < 5} {incr i} {
	foreach {time name image} {
	    15:20 "Clip 1" imovie-01
	    19:18 "Clip 2" imovie-02
	    07:20 "Clip 3" imovie-03
	    07:20 "Clip 4" imovie-04
	    07:20 "Clip 5" imovie-05
	    07:20 "Clip 6" imovie-06
	    07:20 "Clip 7" imovie-07
	} {
	    set I [$T item create]
#			$T item style set $I C0 $S
	    $T item element configure $I C0 \
		elemTime -text $time + \
		elemImg -image $image + \
		elemName -text $name
	    $T item lastchild root $I
	}
    }

    $T notify bind $T <Edit-accept> {
	%T item element configure %I %C %E -text %t
    }

    bind DemoIMovie <ButtonPress-1> {
	iMovieButton1 %W %x %y
    }

    bindtags $T [list $T DemoIMovie TreeCtrl [winfo toplevel $T] all]

    return
}

proc iMovieButton1 {T x y} {
    focus $T
    set id [$T identify $x $y]

    # Click outside any item
    if {$id eq ""} {

    # Click in header
    } elseif {[lindex $id 0] eq "header"} {
	::TreeCtrl::ButtonPress1 $T $x $y

    # Click in item
    } elseif {[lindex $id 0] eq "item"} {
	::TreeCtrl::ButtonPress1 $T $x $y
	update
	lassign $id where item arg1 arg2 arg3 arg4
	switch $arg1 {
	    column {
		set I [lindex $id 1]
		if {[llength $id] == 6} {
		    set E [lindex $id end]
		    if {$E eq "elemName"} {
			set exists [winfo exists $T.entry]
			::TreeCtrl::EntryOpen $T $I C0 $E
			if {!$exists} {
			    $T.entry configure -borderwidth 0 -justify center \
				-background #ffdc5a
			    scan [$T item bbox $I C0 $E] "%d %d %d %d" x1 y1 x2 y2
			    place $T.entry -y [expr {$y1 - 1}]
			}
			$T.entry selection clear
			scan [$T item bbox $I] "%d %d %d %d" x1 y1 x2 y2
			set left [expr {$x1 + 6 - 1}]
			set right [expr {$x2 - 3 - 6 + 1}]
			place $T.entry -x $left -width [expr {$right - $left}]
			$T.entry icursor [$T.entry index @[expr {$x - ($x1 + 1)}]]
			# Disable mouse tracking
			unset ::TreeCtrl::Priv(buttonMode)
		    }
		}
	    }
	}
    }
    return -code break
}