1# RCS: @(#) $Id: imovie.tcl,v 1.17 2009/05/17 18:39:54 treectrl Exp $ 2 3# 4# Demo: iMovie 5# 6proc DemoIMovie {} { 7 8 set T [DemoList] 9 10 # 11 # Configure the treectrl widget 12 # 13 14 $T configure -showroot no -showbuttons no -showlines no \ 15 -selectmode browse -orient horizontal -wrap window \ 16 -showheader no -background #dcdcdc 17 18 # 19 # Create columns 20 # 21 22 $T column create -tags C0 23 24 InitPics imovie-* 25 26 switch -- $::thisPlatform { 27 macintosh - 28 macosx { 29 set font1 {Geneva 9} 30 set font2 {Geneva 10} 31 } 32 unix { 33 set font1 {Helvetica 12} 34 set font2 {Helvetica 14} 35 } 36 default { 37 set font1 {Helvetica 8} 38 set font2 {Helvetica 10} 39 } 40 } 41 42 # 43 # Create elements 44 # 45 46 $T element create elemTime text -font [list $font1] 47 $T element create elemName text -font [list $font2] -lines 1 -width 80 48 $T element create elemRect rect -fill {#ffdc5a {selected} white {}} \ 49 -outline #827878 -outlinewidth 1 50 $T element create elemImg image 51 $T element create elemShadow rect -outline gray -outlinewidth 1 -open wn 52 53 # 54 # Create styles using the elements 55 # 56 57 set S [$T style create STYLE -orient vertical] 58 $T style elements $S {elemShadow elemRect elemTime elemImg elemName} 59 $T style layout $S elemShadow -detach yes -padx {1 2} -pady {1 2} -iexpand xy 60 $T style layout $S elemTime -padx {2 0} 61 $T style layout $S elemImg -pady {0 1} 62 $T style layout $S elemName -expand we -ipady {0 2} -padx {0 3} -squeeze x 63 $T style layout $S elemRect -union {elemTime elemImg elemName} \ 64 -ipadx 6 -padx {0 3} -pady {0 3} 65 66 # Set default item style 67 $T column configure C0 -itemstyle $S 68 69 # 70 # Create items and assign styles 71 # 72 73 for {set i 0} {$i < 5} {incr i} { 74 foreach {time name image} { 75 15:20 "Clip 1" imovie-01 76 19:18 "Clip 2" imovie-02 77 07:20 "Clip 3" imovie-03 78 07:20 "Clip 4" imovie-04 79 07:20 "Clip 5" imovie-05 80 07:20 "Clip 6" imovie-06 81 07:20 "Clip 7" imovie-07 82 } { 83 set I [$T item create] 84# $T item style set $I C0 $S 85 $T item element configure $I C0 \ 86 elemTime -text $time + \ 87 elemImg -image $image + \ 88 elemName -text $name 89 $T item lastchild root $I 90 } 91 } 92 93 $T notify bind $T <Edit-accept> { 94 %T item element configure %I %C %E -text %t 95 } 96 97 bind DemoIMovie <ButtonPress-1> { 98 iMovieButton1 %W %x %y 99 } 100 101 bindtags $T [list $T DemoIMovie TreeCtrl [winfo toplevel $T] all] 102 103 return 104} 105 106proc iMovieButton1 {T x y} { 107 focus $T 108 set id [$T identify $x $y] 109 110 # Click outside any item 111 if {$id eq ""} { 112 113 # Click in header 114 } elseif {[lindex $id 0] eq "header"} { 115 ::TreeCtrl::ButtonPress1 $T $x $y 116 117 # Click in item 118 } elseif {[lindex $id 0] eq "item"} { 119 ::TreeCtrl::ButtonPress1 $T $x $y 120 update 121 lassign $id where item arg1 arg2 arg3 arg4 122 switch $arg1 { 123 column { 124 set I [lindex $id 1] 125 if {[llength $id] == 6} { 126 set E [lindex $id end] 127 if {$E eq "elemName"} { 128 set exists [winfo exists $T.entry] 129 ::TreeCtrl::EntryOpen $T $I C0 $E 130 if {!$exists} { 131 $T.entry configure -borderwidth 0 -justify center \ 132 -background #ffdc5a 133 scan [$T item bbox $I C0 $E] "%d %d %d %d" x1 y1 x2 y2 134 place $T.entry -y [expr {$y1 - 1}] 135 } 136 $T.entry selection clear 137 scan [$T item bbox $I] "%d %d %d %d" x1 y1 x2 y2 138 set left [expr {$x1 + 6 - 1}] 139 set right [expr {$x2 - 3 - 6 + 1}] 140 place $T.entry -x $left -width [expr {$right - $left}] 141 $T.entry icursor [$T.entry index @[expr {$x - ($x1 + 1)}]] 142 # Disable mouse tracking 143 unset ::TreeCtrl::Priv(buttonMode) 144 } 145 } 146 } 147 } 148 } 149 return -code break 150} 151 152# 153# Demo: iMovie (Wrap) 154# 155proc DemoIMovieWrap {} { 156 157 DemoIMovie 158 159 set T [DemoList] 160 $T configure -wrap "" 161 $T item configure "root child 4" -wrap yes 162 $T item configure "root child 5" -wrap yes 163 $T item configure "root child 8" -wrap yes 164 $T item configure "root child 10" -wrap yes 165 $T item configure "root child 15" -wrap yes 166# $T item configure "root child 15" -wrap yes 167 $T item configure "root child 25" -wrap yes 168 return 169} 170