1 "proc tkTableClipboardKeysyms {copy cut paste} {\n"
2 " bind Table <$copy> {tk_tableCopy %W}\n"
3 " bind Table <$cut> {tk_tableCut %W}\n"
4 " bind Table <$paste> {tk_tablePaste %W}\n"
7 " ## You might want to check for row returned if you want to\n"
8 " ## restrict the resizing of certain rows\n"
9 " %W border mark %x %y\n"
11 "bind Table <B3-Motion> { %W border dragto %x %y }\n"
13 " if {[winfo exists %W]} {\n"
14 " tkTableBeginSelect %W [%W index @%x,%y]\n"
18 "bind Table <B1-Motion> {\n"
19 " array set tk::Priv {x %x y %y}\n"
20 " tkTableMotion %W [%W index @%x,%y]\n"
22 "bind Table <Double-1> {\n"
25 "bind Table <ButtonRelease-1> {\n"
26 " if {[winfo exists %W]} {\n"
28 " %W activate @%x,%y\n"
31 "bind Table <Shift-1> {tkTableBeginExtend %W [%W index @%x,%y]}\n"
32 "bind Table <Control-1> {tkTableBeginToggle %W [%W index @%x,%y]}\n"
33 "bind Table <B1-Enter> {tk::CancelRepeat}\n"
34 "bind Table <B1-Leave> {\n"
35 " array set tk::Priv {x %x y %y}\n"
36 " tkTableAutoScan %W\n"
39 " %W scan mark %x %y\n"
40 " array set tk::Priv {x %x y %y}\n"
41 " set tk::Priv(mouseMoved) 0\n"
43 "bind Table <B2-Motion> {\n"
44 " if {(%x != $tk::Priv(x)) || (%y != $tk::Priv(y))} { set tk::Priv(mouseMoved) 1 }\n"
45 " if $tk::Priv(mouseMoved) { %W scan dragto %x %y }\n"
47 "bind Table <ButtonRelease-2> {\n"
48 " if {!$tk::Priv(mouseMoved)} { tk_tablePaste %W [%W index @%x,%y] }\n"
50 "if {[string comp {} [info command event]]} {\n"
51 " tkTableClipboardKeysyms <Copy> <Cut> <Paste>\n"
53 " tkTableClipboardKeysyms Control-c Control-x Control-v\n"
55 "bind Table <Any-Tab> {\n"
56 " # empty to allow Tk focus movement\n"
58 "bind Table <FocusOut> {\n"
59 " catch {%W activate active}\n"
61 "bind Table <Shift-Up> {tkTableExtendSelect %W -1 0}\n"
62 "bind Table <Shift-Down> {tkTableExtendSelect %W 1 0}\n"
63 "bind Table <Shift-Left> {tkTableExtendSelect %W 0 -1}\n"
64 "bind Table <Shift-Right> {tkTableExtendSelect %W 0 1}\n"
65 "bind Table <Prior> {%W yview scroll -1 pages; %W activate @0,0}\n"
66 "bind Table <Next> {%W yview scroll 1 pages; %W activate @0,0}\n"
67 "bind Table <Control-Prior> {%W xview scroll -1 pages}\n"
68 "bind Table <Control-Next> {%W xview scroll 1 pages}\n"
69 "bind Table <Home> {%W see origin}\n"
70 "bind Table <End> {%W see end}\n"
71 "bind Table <Control-Home> {\n"
72 " %W selection clear all\n"
73 " %W activate origin\n"
74 " %W selection set active\n"
77 "bind Table <Control-End> {\n"
78 " %W selection clear all\n"
80 " %W selection set active\n"
83 "bind Table <Shift-Control-Home> {tkTableDataExtend %W origin}\n"
84 "bind Table <Shift-Control-End> {tkTableDataExtend %W end}\n"
85 "bind Table <Select> {tkTableBeginSelect %W [%W index active]}\n"
86 "bind Table <Shift-Select> {tkTableBeginExtend %W [%W index active]}\n"
87 "bind Table <Control-slash> {tkTableSelectAll %W}\n"
88 "bind Table <Control-backslash> {\n"
89 " if {[string match browse [%W cget -selectmode]]} {%W selection clear all}\n"
91 "bind Table <Up> {tkTableMoveCell %W -1 0}\n"
92 "bind Table <Down> {tkTableMoveCell %W 1 0}\n"
93 "bind Table <Left> {tkTableMoveCell %W 0 -1}\n"
94 "bind Table <Right> {tkTableMoveCell %W 0 1}\n"
95 "bind Table <Any-KeyPress> {\n"
96 " if {[string compare {} %A]} { %W insert active insert %A }\n"
98 "bind Table <BackSpace> {\n"
99 " set tk::Priv(junk) [%W icursor]\n"
100 " if {[string compare {} $tk::Priv(junk)] && $tk::Priv(junk)} {\n"
101 " %W delete active [expr {$tk::Priv(junk)-1}]\n"
104 "bind Table <Delete> {%W delete active insert}\n"
105 "bind Table <Escape> {%W reread}\n"
106 "bind Table <Return> {\n"
107 " %W insert active insert \"\n\"\n"
109 "bind Table <Control-Left> {%W icursor [expr {[%W icursor]-1}]}\n"
110 "bind Table <Control-Right> {%W icursor [expr {[%W icursor]+1}]}\n"
111 "bind Table <Control-e> {%W icursor end}\n"
112 "bind Table <Control-a> {%W icursor 0}\n"
113 "bind Table <Control-k> {%W delete active insert end}\n"
114 "bind Table <Control-equal> {tkTableChangeWidth %W active 1}\n"
115 "bind Table <Control-minus> {tkTableChangeWidth %W active -1}\n"
116 "proc tkTableBeginSelect {w el} {\n"
118 " if {[scan $el %d,%d r c] != 2} return\n"
119 " switch [$w cget -selectmode] {\n"
121 " if {[$w tag includes title $el]} {\n"
122 " ## in the title area\n"
123 " if {$r < [$w cget -titlerows]+[$w cget -roworigin]} {\n"
124 " ## We're in a column header\n"
125 " if {$c < [$w cget -titlecols]+[$w cget -colorigin]} {\n"
126 " ## We're in the topleft title area\n"
130 " set inc [$w index topleft row],$c\n"
131 " set el2 [$w index end row],$c\n"
134 " ## We're in a row header\n"
135 " set inc $r,[$w index topleft col]\n"
136 " set el2 $r,[$w index end col]\n"
142 " if [$w selection includes $inc] {\n"
143 " $w selection clear $el $el2\n"
145 " $w selection set $el $el2\n"
149 " $w selection clear all\n"
150 " if {[$w tag includes title $el]} {\n"
151 " if {$r < [$w cget -titlerows]+[$w cget -roworigin]} {\n"
152 " ## We're in a column header\n"
153 " if {$c < [$w cget -titlecols]+[$w cget -colorigin]} {\n"
154 " $w selection set origin end\n"
156 " $w selection set $el [$w index end row],$c\n"
159 " ## We're in a row header\n"
160 " $w selection set $el $r,[$w index end col]\n"
163 " $w selection set $el\n"
165 " $w selection anchor $el\n"
166 " set tk::Priv(tablePrev) $el\n"
169 " if {![$w tag includes title $el]} {\n"
170 " $w selection clear all\n"
171 " $w selection set $el\n"
172 " set tk::Priv(tablePrev) $el\n"
174 " $w selection anchor $el\n"
178 "proc tkTableMotion {w el} {\n"
180 " if {![info exists tk::Priv(tablePrev)]} {\n"
181 " set tk::Priv(tablePrev) $el\n"
184 " if {[string match $tk::Priv(tablePrev) $el]} return\n"
185 " switch [$w cget -selectmode] {\n"
187 " $w selection clear all\n"
188 " $w selection set $el\n"
189 " set tk::Priv(tablePrev) $el\n"
192 " scan $tk::Priv(tablePrev) %d,%d r c\n"
193 " scan $el %d,%d elr elc\n"
194 " if {[$w tag includes title $el]} {\n"
195 " if {$r < [$w cget -titlerows]+[$w cget -roworigin]} {\n"
196 " ## We're in a column header\n"
197 " if {$c < [$w cget -titlecols]+[$w cget -colorigin]} {\n"
198 " ## We're in the topleft title area\n"
199 " $w selection clear anchor end\n"
201 " $w selection clear anchor [$w index end row],$c\n"
203 " $w selection set anchor [$w index end row],$elc\n"
205 " ## We're in a row header\n"
206 " $w selection clear anchor $r,[$w index end col]\n"
207 " $w selection set anchor $elr,[$w index end col]\n"
210 " $w selection clear anchor $tk::Priv(tablePrev)\n"
211 " $w selection set anchor $el\n"
213 " set tk::Priv(tablePrev) $el\n"
217 "proc tkTableBeginExtend {w el} {\n"
218 " if {[string match extended [$w cget -selectmode]] &&\n"
219 " [$w selection includes anchor]} {\n"
220 " tkTableMotion $w $el\n"
223 "proc tkTableBeginToggle {w el} {\n"
225 " if {[string match extended [$w cget -selectmode]]} {\n"
226 " set tk::Priv(tablePrev) $el\n"
227 " $w selection anchor $el\n"
228 " if [$w selection includes $el] {\n"
229 " $w selection clear $el\n"
231 " $w selection set $el\n"
235 "proc tkTableAutoScan {w} {\n"
237 " if {![winfo exists $w]} return\n"
238 " set x $tk::Priv(x)\n"
239 " set y $tk::Priv(y)\n"
240 " if {$y >= [winfo height $w]} {\n"
241 " $w yview scroll 1 units\n"
242 " } elseif {$y < 0} {\n"
243 " $w yview scroll -1 units\n"
244 " } elseif {$x >= [winfo width $w]} {\n"
245 " $w xview scroll 1 units\n"
246 " } elseif {$x < 0} {\n"
247 " $w xview scroll -1 units\n"
251 " tkTableMotion $w [$w index @$x,$y]\n"
252 " set tk::Priv(afterId) [after 50 tkTableAutoScan $w]\n"
254 "proc tkTableMoveCell {w x y} {\n"
256 " if {[catch {$w index active row} r]} return\n"
257 " set c [$w index active col]\n"
258 " $w activate [incr r $x],[incr c $y]\n"
260 " switch [$w cget -selectmode] {\n"
262 " $w selection clear all\n"
263 " $w selection set active\n"
266 " $w selection clear all\n"
267 " $w selection set active\n"
268 " $w selection anchor active\n"
269 " set tk::Priv(tablePrev) [$w index active]\n"
273 "proc tkTableExtendSelect {w x y} {\n"
274 " if {[string compare extended [$w cget -selectmode]] ||\n"
275 " [catch {$w index active row} r]} return\n"
276 " set c [$w index active col]\n"
277 " $w activate [incr r $x],[incr c $y]\n"
279 " tkTableMotion $w [$w index active]\n"
281 "proc tkTableDataExtend {w el} {\n"
282 " set mode [$w cget -selectmode]\n"
283 " if {[string match extended $mode]} {\n"
286 " if [$w selection includes anchor] {tkTableMotion $w $el}\n"
287 " } elseif {[string match multiple $mode]} {\n"
292 "proc tkTableSelectAll {w} {\n"
293 " if {[regexp {^(single|browse)$} [$w cget -selectmode]]} {\n"
294 " $w selection clear all\n"
295 " $w selection set active\n"
296 " tkTableHandleType $w [$w index active]\n"
298 " $w selection set origin end\n"
301 "proc tkTableChangeWidth {w i a} {\n"
302 " set tmp [$w index $i col]\n"
303 " if {[set width [$w width $tmp]] >= 0} {\n"
304 " $w width $tmp [incr width $a]\n"
306 " $w width $tmp [incr width -$a]\n"
309 "proc tk_tableCopy w {\n"
310 " if {[selection own -displayof $w] == \"$w\"} {\n"
311 " clipboard clear -displayof $w\n"
312 " catch {clipboard append -displayof $w [selection get -displayof $w]}\n"
315 "proc tk_tableCut w {\n"
316 " if {[selection own -displayof $w] == \"$w\"} {\n"
317 " clipboard clear -displayof $w\n"
319 " clipboard append -displayof $w [selection get -displayof $w]\n"
320 " $w cursel set {}\n"
321 " $w selection clear all\n"
325 "proc tk_tablePaste {w {cell {}}} {\n"
326 " if {[string compare {} $cell]} {\n"
327 " if {[catch {selection get -displayof $w} data]} return\n"
329 " if {[catch {selection get -displayof $w -selection CLIPBOARD} data]} {\n"
334 " tk_tablePasteHandler $w [$w index $cell] $data\n"
335 " if {[$w cget -state] == \"normal\"} {focus $w}\n"
337 "proc tk_tablePasteHandler {w cell data} {\n"
338 " set rows [expr {[$w cget -rows]-[$w cget -roworigin]}]\n"
339 " set cols [expr {[$w cget -cols]-[$w cget -colorigin]}]\n"
340 " set r [$w index $cell row]\n"
341 " set c [$w index $cell col]\n"
342 " set rsep [$w cget -rowseparator]\n"
343 " set csep [$w cget -colseparator]\n"
344 " ## Assume separate rows are split by row separator if specified\n"
345 " ## If you were to want multi-character row separators, you would need:\n"
346 " # regsub -all $rsep $data <newline> data\n"
347 " # set data [join $data <newline>]\n"
348 " if {[string comp {} $rsep]} { set data [split $data $rsep] }\n"
350 " foreach line $data {\n"
351 " if {$row > $rows} break\n"
353 " ## Assume separate cols are split by col separator if specified\n"
354 " ## Unless a -separator was specified\n"
355 " if {[string comp {} $csep]} { set line [split $line $csep] }\n"
356 " ## If you were to want multi-character col separators, you would need:\n"
357 " # regsub -all $csep $line <newline> line\n"
358 " # set line [join $line <newline>]\n"
359 " foreach item $line {\n"
360 " if {$col > $cols} break\n"
361 " $w set $row,$col $item\n"