source: trunk/kitgen/8.x/blt/library/treeview.tcl

Last change on this file was 175, checked in by demin, 12 years ago

initial commit

File size: 24.9 KB
Line 
1
2# ======================================================================
3#
4# treeview.tcl
5#
6# ----------------------------------------------------------------------
7# Bindings for the BLT treeview widget
8# ----------------------------------------------------------------------
9#
10# AUTHOR: George Howlett
11# Bell Labs Innovations for Lucent Technologies
12# gah@lucent.com
13# http://www.tcltk.com/blt
14#
15# RCS: $Id: treeview.tcl,v 1.25 2002/08/06 05:08:24 ghowlett Exp $
16#
17# ----------------------------------------------------------------------
18# Copyright (c) 1998 Lucent Technologies, Inc.
19# ----------------------------------------------------------------------
20#
21# Permission to use, copy, modify, and distribute this software and its
22# documentation for any purpose and without fee is hereby granted,
23# provided that the above copyright notice appear in all copies and that
24# both that the copyright notice and warranty disclaimer appear in
25# supporting documentation, and that the names of Lucent Technologies
26# any of their entities not be used in advertising or publicity
27# pertaining to distribution of the software without specific, written
28# prior permission.
29#
30# Lucent Technologies disclaims all warranties with regard to this
31# software, including all implied warranties of merchantability and
32# fitness. In no event shall Lucent be liable for any special, indirect
33# or consequential damages or any damages whatsoever resulting from loss
34# of use, data or profits, whether in an action of contract, negligence
35# or other tortuous action, arising out of or in connection with the use
36# or performance of this software.
37#
38# ======================================================================
39
40namespace eval blt::tv {
41 set afterId ""
42 set scroll 0
43 set column ""
44 set space off
45 set x 0
46 set y 0
47}
48
49image create photo blt::tv::normalCloseFolder -format gif -data {
50 R0lGODlhEAANAMIAAAAAAH9/f///////AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
51 AAM8WBrM+rAEQWmIb5KxiWjNInCkV32AJHRlGQBgDA7vdN4vUa8tC78qlrCWmvRKsJTquHkp
52 ZTKAsiCtWq0JADs=
53}
54image create photo blt::tv::normalOpenFolder -format gif -data {
55 R0lGODlhEAANAMIAAAAAAH9/f///////AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
56 AAM1WBrM+rAEMigJ8c3Kb3OSII6kGABhp1JnaK1VGwjwKwtvHqNzzd263M3H4n2OH1QBwGw6
57 nQkAOw==
58}
59image create photo blt::tv::activeCloseFolder -format gif -data {
60 R0lGODlhEAANAMIAAAAAAH9/f/////+/AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
61 AAM8WBrM+rAEQWmIb5KxiWjNInCkV32AJHRlGQBgDA7vdN4vUa8tC78qlrCWmvRKsJTquHkp
62 ZTKAsiCtWq0JADs=
63}
64image create photo blt::tv::activeOpenFolder -format gif -data {
65 R0lGODlhEAANAMIAAAAAAH9/f/////+/AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
66 AAM1WBrM+rAEMigJ8c3Kb3OSII6kGABhp1JnaK1VGwjwKwtvHqNzzd263M3H4n2OH1QBwGw6
67 nQkAOw==
68}
69
70if { $tcl_platform(platform) == "windows" } {
71 if { $tk_version >= 8.3 } {
72 set cursor "@[file join $blt_library treeview.cur]"
73 } else {
74 set cursor "size_we"
75 }
76 option add *${className}.ResizeCursor [list $cursor]
77} else {
78 option add *${className}.ResizeCursor \
79 "@$blt_library/treeview.xbm $blt_library/treeview_m.xbm black white"
80}
81
82# ----------------------------------------------------------------------
83#
84# Initialize --
85#
86# Invoked by internally by Treeview_Init routine. Initializes
87# the default bindings for the treeview widget entries. These
88# are local to the widget, so they can't be set through the
89# widget's class bind tags.
90#
91# ----------------------------------------------------------------------
92proc blt::tv::Initialize { w } {
93 #
94 # Active entry bindings
95 #
96 $w bind Entry <Enter> {
97 %W entry highlight current
98 }
99 $w bind Entry <Leave> {
100 %W entry highlight ""
101 }
102
103 #
104 # Button bindings
105 #
106 $w button bind all <ButtonRelease-1> {
107 %W see -anchor nw current
108 %W toggle current
109 }
110 $w button bind all <Enter> {
111 %W button highlight current
112 }
113 $w button bind all <Leave> {
114 %W button highlight ""
115 }
116
117 #
118 # ButtonPress-1
119 #
120 # Performs the following operations:
121 #
122 # 1. Clears the previous selection.
123 # 2. Selects the current entry.
124 # 3. Sets the focus to this entry.
125 # 4. Scrolls the entry into view.
126 # 5. Sets the selection anchor to this entry, just in case
127 # this is "multiple" mode.
128 #
129
130 $w bind Entry <ButtonPress-1> {
131 blt::tv::SetSelectionAnchor %W current
132 set blt::tv::scroll 1
133 }
134
135 $w bind Entry <Double-ButtonPress-1> {
136 %W toggle current
137 }
138
139 #
140 # B1-Motion
141 #
142 # For "multiple" mode only. Saves the current location of the
143 # pointer for auto-scrolling. Resets the selection mark.
144 #
145 $w bind Entry <B1-Motion> {
146 set blt::tv::x %x
147 set blt::tv::y %y
148 set index [%W nearest %x %y]
149 if { [%W cget -selectmode] == "multiple" } {
150 %W selection mark $index
151 } else {
152 blt::tv::SetSelectionAnchor %W $index
153 }
154 }
155
156 #
157 # ButtonRelease-1
158 #
159 # For "multiple" mode only.
160 #
161 $w bind Entry <ButtonRelease-1> {
162 if { [%W cget -selectmode] == "multiple" } {
163 %W selection anchor current
164 }
165 after cancel $blt::tv::afterId
166 set blt::tv::scroll 0
167 }
168
169 #
170 # Shift-ButtonPress-1
171 #
172 # For "multiple" mode only.
173 #
174
175 $w bind Entry <Shift-ButtonPress-1> {
176 if { [%W cget -selectmode] == "multiple" && [%W selection present] } {
177 if { [%W index anchor] == "" } {
178 %W selection anchor current
179 }
180 set index [%W index anchor]
181 %W selection clearall
182 %W selection set $index current
183 } else {
184 blt::tv::SetSelectionAnchor %W current
185 }
186 }
187 $w bind Entry <Shift-Double-ButtonPress-1> {
188 # do nothing
189 }
190 $w bind Entry <Shift-B1-Motion> {
191 # do nothing
192 }
193 $w bind Entry <Shift-ButtonRelease-1> {
194 after cancel $blt::tv::afterId
195 set blt::tv::scroll 0
196 }
197
198 #
199 # Control-ButtonPress-1
200 #
201 # For "multiple" mode only.
202 #
203 $w bind Entry <Control-ButtonPress-1> {
204 if { [%W cget -selectmode] == "multiple" } {
205 set index [%W index current]
206 %W selection toggle $index
207 %W selection anchor $index
208 } else {
209 blt::tv::SetSelectionAnchor %W current
210 }
211 }
212 $w bind Entry <Control-Double-ButtonPress-1> {
213 # do nothing
214 }
215 $w bind Entry <Control-B1-Motion> {
216 # do nothing
217 }
218 $w bind Entry <Control-ButtonRelease-1> {
219 after cancel $blt::tv::afterId
220 set blt::tv::scroll 0
221 }
222
223 $w bind Entry <Control-Shift-ButtonPress-1> {
224 if { [%W cget -selectmode] == "multiple" && [%W selection present] } {
225 if { [%W index anchor] == "" } {
226 %W selection anchor current
227 }
228 if { [%W selection includes anchor] } {
229 %W selection set anchor current
230 } else {
231 %W selection clear anchor current
232 %W selection set current
233 }
234 } else {
235 blt::tv::SetSelectionAnchor %W current
236 }
237 }
238 $w bind Entry <Control-Shift-Double-ButtonPress-1> {
239 # do nothing
240 }
241 $w bind Entry <Control-Shift-B1-Motion> {
242 # do nothing
243 }
244
245 $w bind Entry <Shift-ButtonPress-3> {
246 blt::tv::EditColumn %W %X %Y
247 }
248
249 $w column bind all <Enter> {
250 %W column highlight [%W column current]
251 }
252 $w column bind all <Leave> {
253 %W column highlight ""
254 }
255 $w column bind Rule <Enter> {
256 %W column highlight [%W column current]
257 %W column resize activate [%W column current]
258 }
259 $w column bind Rule <Leave> {
260 %W column highlight ""
261 %W column resize activate ""
262 }
263 $w column bind Rule <ButtonPress-1> {
264 %W column resize anchor %x
265 }
266 $w column bind Rule <B1-Motion> {
267 %W column resize mark %x
268 }
269 $w column bind Rule <ButtonRelease-1> {
270 %W column configure [%W column current] -width [%W column resize set]
271 }
272 $w column bind all <ButtonPress-1> {
273 set blt::tv::column [%W column current]
274 %W column configure $blt::tv::column -titlerelief sunken
275 }
276 $w column bind all <ButtonRelease-1> {
277 set column [%W column current]
278 if { $column != "" } {
279 %W column invoke $column
280 }
281 %W column configure $blt::tv::column -titlerelief raised
282 }
283 $w bind TextBoxStyle <ButtonPress-3> {
284 if { [%W edit -root -test %X %Y] } {
285 break
286 }
287 }
288 $w bind TextBoxStyle <ButtonRelease-3> {
289 if { [%W edit -root -test %X %Y] } {
290 blt::tv::EditColumn %W %X %Y
291 break
292 }
293 }
294 $w bind CheckBoxStyle <Enter> {
295 set column [%W column current]
296 if { [%W column cget $column -edit] } {
297 %W style activate current $column
298 }
299 }
300 $w bind CheckBoxStyle <Leave> {
301 %W style activate ""
302 }
303 $w bind CheckBoxStyle <ButtonPress-1> {
304 set column [%W column current]
305 if { [%W column cget $column -edit] } {
306 break
307 }
308 }
309 $w bind CheckBoxStyle <B1-Motion> {
310 set column [%W column current]
311 if { [%W column cget $column -edit] } {
312 break
313 }
314 }
315 $w bind CheckBoxStyle <ButtonRelease-1> {
316 if { [%W edit -root -test %X %Y] } {
317 %W edit -root %X %Y
318 break
319 }
320 }
321 $w bind ComboBoxStyle <ButtonPress-1> {
322 set column [%W column current]
323 if { [%W column cget $column -edit] } {
324 break
325 }
326 }
327 $w bind ComboBoxStyle <ButtonRelease-1> {
328 if { [%W edit -root -test %X %Y] } {
329 %W edit -root %X %Y
330 break
331 }
332 }
333}
334
335# ----------------------------------------------------------------------
336#
337# AutoScroll --
338#
339# Invoked when the user is selecting elements in a treeview
340# widget and drags the mouse pointer outside of the widget.
341# Scrolls the view in the direction of the pointer.
342#
343# ----------------------------------------------------------------------
344proc blt::tv::AutoScroll { w } {
345 if { ![winfo exists $w] } {
346 return
347 }
348 set x $blt::tv::x
349 set y $blt::tv::y
350
351 set index [$w nearest $x $y]
352
353 if {$y >= [winfo height $w]} {
354 $w yview scroll 1 units
355 set neighbor down
356 } elseif {$y < 0} {
357 $w yview scroll -1 units
358 set neighbor up
359 } else {
360 set neighbor $index
361 }
362 if { [$w cget -selectmode] == "single" } {
363 blt::tv::SetSelectionAnchor $w $neighbor
364 } else {
365 $w selection mark $index
366 }
367 set ::blt::tv::afterId [after 50 blt::tv::AutoScroll $w]
368}
369
370proc blt::tv::SetSelectionAnchor { w tagOrId } {
371 set index [$w index $tagOrId]
372 # If the anchor hasn't changed, don't do anything
373 if { $index != [$w index anchor] } {
374 $w selection clearall
375 $w see $index
376 $w focus $index
377 $w selection set $index
378 $w selection anchor $index
379 }
380}
381
382# ----------------------------------------------------------------------
383#
384# MoveFocus --
385#
386# Invoked by KeyPress bindings. Moves the active selection to
387# the entry <where>, which is an index such as "up", "down",
388# "prevsibling", "nextsibling", etc.
389#
390# ----------------------------------------------------------------------
391proc blt::tv::MoveFocus { w tagOrId } {
392 catch {$w focus $tagOrId}
393 if { [$w cget -selectmode] == "single" } {
394 $w selection clearall
395 $w selection set focus
396 $w selection anchor focus
397 }
398 $w see focus
399}
400
401# ----------------------------------------------------------------------
402#
403# MovePage --
404#
405# Invoked by KeyPress bindings. Pages the current view up or
406# down. The <where> argument should be either "top" or
407# "bottom".
408#
409# ----------------------------------------------------------------------
410proc blt::tv::MovePage { w where } {
411
412 # If the focus is already at the top/bottom of the window, we want
413 # to scroll a page. It's really one page minus an entry because we
414 # want to see the last entry on the next/last page.
415 if { [$w index focus] == [$w index view.$where] } {
416 if {$where == "top"} {
417 $w yview scroll -1 pages
418 $w yview scroll 1 units
419 } else {
420 $w yview scroll 1 pages
421 $w yview scroll -1 units
422 }
423 }
424 update
425
426 # Adjust the entry focus and the view. Also activate the entry.
427 # just in case the mouse point is not in the widget.
428 $w entry highlight view.$where
429 $w focus view.$where
430 $w see view.$where
431 if { [$w cget -selectmode] == "single" } {
432 $w selection clearall
433 $w selection set focus
434 }
435}
436
437# ----------------------------------------------------------------------
438#
439# NextMatch --
440#
441# Invoked by KeyPress bindings. Searches for an entry that
442# starts with the letter <char> and makes that entry active.
443#
444# ----------------------------------------------------------------------
445proc blt::tv::NextMatch { w key } {
446 if {[string match {[ -~]} $key]} {
447 set last [$w index focus]
448 set next [$w index next]
449 while { $next != $last } {
450 set label [$w entry cget $next -label]
451 set label [string index $label 0]
452 if { [string tolower $label] == [string tolower $key] } {
453 break
454 }
455 set next [$w index -at $next next]
456 }
457 $w focus $next
458 if {[$w cget -selectmode] == "single"} {
459 $w selection clearall
460 $w selection set focus
461 }
462 $w see focus
463 }
464}
465
466#------------------------------------------------------------------------
467#
468# InsertText --
469#
470# Inserts a text string into an entry at the insertion cursor.
471# If there is a selection in the entry, and it covers the point
472# of the insertion cursor, then delete the selection before
473# inserting.
474#
475# Arguments:
476# w Widget where to insert the text.
477# text Text string to insert (usually just a single character)
478#
479#------------------------------------------------------------------------
480proc blt::tv::InsertText { w text } {
481 if { [string length $text] > 0 } {
482 set index [$w index insert]
483 if { ($index >= [$w index sel.first]) &&
484 ($index <= [$w index sel.last]) } {
485 $w delete sel.first sel.last
486 }
487 $w insert $index $text
488 }
489}
490
491#------------------------------------------------------------------------
492#
493# Transpose -
494#
495# This procedure implements the "transpose" function for entry
496# widgets. It tranposes the characters on either side of the
497# insertion cursor, unless the cursor is at the end of the line.
498# In this case it transposes the two characters to the left of
499# the cursor. In either case, the cursor ends up to the right
500# of the transposed characters.
501#
502# Arguments:
503# w The entry window.
504#
505#------------------------------------------------------------------------
506proc blt::tv::Transpose { w } {
507 set i [$w index insert]
508 if {$i < [$w index end]} {
509 incr i
510 }
511 set first [expr {$i-2}]
512 if {$first < 0} {
513 return
514 }
515 set new [string index [$w get] [expr {$i-1}]][string index [$w get] $first]
516 $w delete $first $i
517 $w insert insert $new
518}
519
520#------------------------------------------------------------------------
521#
522# GetSelection --
523#
524# Returns the selected text of the entry with respect to the
525# -show option.
526#
527# Arguments:
528# w Entry window from which the text to get
529#
530#------------------------------------------------------------------------
531
532proc blt::tv::GetSelection { w } {
533 set text [string range [$w get] [$w index sel.first] \
534 [expr [$w index sel.last] - 1]]
535 if {[$w cget -show] != ""} {
536 regsub -all . $text [string index [$w cget -show] 0] text
537 }
538 return $text
539}
540
541proc blt::tv::EditColumn { w x y } {
542 $w see current
543 if { [winfo exists $w.edit] } {
544 destroy $w.edit
545 }
546 if { ![$w edit -root -test $x $y] } {
547 return
548 }
549 $w edit -root $x $y
550 update
551 focus $w.edit
552 $w.edit selection range 0 end
553 grab set $w.edit
554 tkwait window $w.edit
555 grab release $w.edit
556}
557
558#
559# ButtonPress assignments
560#
561# B1-Enter start auto-scrolling
562# B1-Leave stop auto-scrolling
563# ButtonPress-2 start scan
564# B2-Motion adjust scan
565# ButtonRelease-2 stop scan
566#
567
568bind ${className} <ButtonPress-2> {
569 set blt::tv::cursor [%W cget -cursor]
570 %W configure -cursor hand1
571 %W scan mark %x %y
572}
573
574bind ${className} <B2-Motion> {
575 %W scan dragto %x %y
576}
577
578bind ${className} <ButtonRelease-2> {
579 %W configure -cursor $blt::tv::cursor
580}
581
582bind ${className} <B1-Leave> {
583 if { $blt::tv::scroll } {
584 blt::tv::AutoScroll %W
585 }
586}
587
588bind ${className} <B1-Enter> {
589 after cancel $blt::tv::afterId
590}
591
592#
593# KeyPress assignments
594#
595# Up
596# Down
597# Shift-Up
598# Shift-Down
599# Prior (PageUp)
600# Next (PageDn)
601# Left
602# Right
603# space Start selection toggle of entry currently with focus.
604# Return Start selection toggle of entry currently with focus.
605# Home
606# End
607# F1
608# F2
609# ASCII char Go to next open entry starting with character.
610#
611# KeyRelease
612#
613# space Stop selection toggle of entry currently with focus.
614# Return Stop selection toggle of entry currently with focus.
615
616
617bind ${className} <KeyPress-Up> {
618 blt::tv::MoveFocus %W up
619 if { $blt::tv::space } {
620 %W selection toggle focus
621 }
622}
623
624bind ${className} <KeyPress-Down> {
625 blt::tv::MoveFocus %W down
626 if { $blt::tv::space } {
627 %W selection toggle focus
628 }
629}
630
631bind ${className} <Shift-KeyPress-Up> {
632 blt::tv::MoveFocus %W prevsibling
633}
634
635bind ${className} <Shift-KeyPress-Down> {
636 blt::tv::MoveFocus %W nextsibling
637}
638
639bind ${className} <KeyPress-Prior> {
640 blt::tv::MovePage %W top
641}
642
643bind ${className} <KeyPress-Next> {
644 blt::tv::MovePage %W bottom
645}
646
647bind ${className} <KeyPress-Left> {
648 %W close focus
649}
650bind ${className} <KeyPress-Right> {
651 %W open focus
652 %W see focus -anchor w
653}
654
655bind ${className} <KeyPress-space> {
656 if { [%W cget -selectmode] == "single" } {
657 if { [%W selection includes focus] } {
658 %W selection clearall
659 } else {
660 %W selection clearall
661 %W selection set focus
662 }
663 } else {
664 %W selection toggle focus
665 }
666 set blt::tv::space on
667}
668
669bind ${className} <KeyRelease-space> {
670 set blt::tv::space off
671}
672
673bind ${className} <KeyPress-Return> {
674 blt::tv::MoveFocus %W focus
675 set blt::tv::space on
676}
677
678bind ${className} <KeyRelease-Return> {
679 set blt::tv::space off
680}
681
682bind ${className} <KeyPress> {
683 blt::tv::NextMatch %W %A
684}
685
686bind ${className} <KeyPress-Home> {
687 blt::tv::MoveFocus %W top
688}
689
690bind ${className} <KeyPress-End> {
691 blt::tv::MoveFocus %W bottom
692}
693
694bind ${className} <KeyPress-F1> {
695 %W open -r root
696}
697
698bind ${className} <KeyPress-F2> {
699 eval %W close -r [%W entry children root]
700}
701
702#
703# Differences between id "current" and operation nearest.
704#
705# set index [$w index current]
706# set index [$w nearest $x $y]
707#
708# o Nearest gives you the closest entry.
709# o current is "" if
710# 1) the pointer isn't over an entry.
711# 2) the pointer is over a open/close button.
712# 3)
713#
714
715#
716# Edit mode assignments
717#
718# ButtonPress-3 Enables/disables edit mode on entry. Sets focus to
719# entry.
720#
721# KeyPress
722#
723# Left Move insertion position to previous.
724# Right Move insertion position to next.
725# Up Move insertion position up one line.
726# Down Move insertion position down one line.
727# Return End edit mode.
728# Shift-Return Line feed.
729# Home Move to first position.
730# End Move to last position.
731# ASCII char Insert character left of insertion point.
732# Del Delete character right of insertion point.
733# Delete Delete character left of insertion point.
734# Ctrl-X Cut
735# Ctrl-V Copy
736# Ctrl-P Paste
737#
738# KeyRelease
739#
740# ButtonPress-1 Start selection if in entry, otherwise clear selection.
741# B1-Motion Extend/reduce selection.
742# ButtonRelease-1 End selection if in entry, otherwise use last
743# selection.
744# B1-Enter Disabled.
745# B1-Leave Disabled.
746# ButtonPress-2 Same as above.
747# B2-Motion Same as above.
748# ButtonRelease-2 Same as above.
749#
750#
751
752
753# Standard Motif bindings:
754
755bind ${className}Editor <ButtonPress-1> {
756 %W icursor @%x,%y
757 %W selection clear
758}
759
760bind ${className}Editor <Left> {
761 %W icursor last
762 %W selection clear
763}
764
765bind ${className}Editor <Right> {
766 %W icursor next
767 %W selection clear
768}
769
770bind ${className}Editor <Shift-Left> {
771 set new [expr {[%W index insert] - 1}]
772 if {![%W selection present]} {
773 %W selection from insert
774 %W selection to $new
775 } else {
776 %W selection adjust $new
777 }
778 %W icursor $new
779}
780
781bind ${className}Editor <Shift-Right> {
782 set new [expr {[%W index insert] + 1}]
783 if {![%W selection present]} {
784 %W selection from insert
785 %W selection to $new
786 } else {
787 %W selection adjust $new
788 }
789 %W icursor $new
790}
791
792bind ${className}Editor <Home> {
793 %W icursor 0
794 %W selection clear
795}
796bind ${className}Editor <Shift-Home> {
797 set new 0
798 if {![%W selection present]} {
799 %W selection from insert
800 %W selection to $new
801 } else {
802 %W selection adjust $new
803 }
804 %W icursor $new
805}
806bind ${className}Editor <End> {
807 %W icursor end
808 %W selection clear
809}
810bind ${className}Editor <Shift-End> {
811 set new end
812 if {![%W selection present]} {
813 %W selection from insert
814 %W selection to $new
815 } else {
816 %W selection adjust $new
817 }
818 %W icursor $new
819}
820
821bind ${className}Editor <Delete> {
822 if { [%W selection present]} {
823 %W delete sel.first sel.last
824 } else {
825 %W delete insert
826 }
827}
828
829bind ${className}Editor <BackSpace> {
830 if { [%W selection present] } {
831 %W delete sel.first sel.last
832 } else {
833 set index [expr [%W index insert] - 1]
834 if { $index >= 0 } {
835 %W delete $index $index
836 }
837 }
838}
839
840bind ${className}Editor <Control-space> {
841 %W selection from insert
842}
843
844bind ${className}Editor <Select> {
845 %W selection from insert
846}
847
848bind ${className}Editor <Control-Shift-space> {
849 %W selection adjust insert
850}
851
852bind ${className}Editor <Shift-Select> {
853 %W selection adjust insert
854}
855
856bind ${className}Editor <Control-slash> {
857 %W selection range 0 end
858}
859
860bind ${className}Editor <Control-backslash> {
861 %W selection clear
862}
863
864bind ${className}Editor <KeyPress> {
865 blt::tv::InsertText %W %A
866}
867
868# Ignore all Alt, Meta, and Control keypresses unless explicitly bound.
869# Otherwise, if a widget binding for one of these is defined, the
870# <KeyPress> class binding will also fire and insert the character,
871# which is wrong. Ditto for Escape, Return, and Tab.
872
873bind ${className}Editor <Alt-KeyPress> {
874 # nothing
875}
876
877bind ${className}Editor <Meta-KeyPress> {
878 # nothing
879}
880
881bind ${className}Editor <Control-KeyPress> {
882 # nothing
883}
884
885bind ${className}Editor <Escape> {
886 %W cancel
887}
888
889bind ${className}Editor <Return> {
890 %W apply
891}
892
893bind ${className}Editor <Shift-Return> {
894 blt::tv::InsertText %W "\n"
895}
896
897bind ${className}Editor <KP_Enter> {
898 # nothing
899}
900
901bind ${className}Editor <Tab> {
902 # nothing
903}
904
905if {![string compare $tcl_platform(platform) "macintosh"]} {
906 bind ${className}Editor <Command-KeyPress> {
907 # nothing
908 }
909}
910
911# On Windows, paste is done using Shift-Insert. Shift-Insert already
912# generates the <<Paste>> event, so we don't need to do anything here.
913if { [string compare $tcl_platform(platform) "windows"] != 0 } {
914 bind ${className}Editor <Insert> {
915 catch {blt::tv::InsertText %W [selection get -displayof %W]}
916 }
917}
918
919# Additional emacs-like bindings:
920bind ${className}Editor <ButtonPress-3> {
921 set parent [winfo parent %W]
922 %W cancel
923 after idle {
924 blt::tv::EditColumn $parent %X %Y
925 }
926}
927
928bind ${className}Editor <Control-a> {
929 %W icursor 0
930 %W selection clear
931}
932
933bind ${className}Editor <Control-b> {
934 %W icursor [expr {[%W index insert] - 1}]
935 %W selection clear
936}
937
938bind ${className}Editor <Control-d> {
939 %W delete insert
940}
941
942bind ${className}Editor <Control-e> {
943 %W icursor end
944 %W selection clear
945}
946
947bind ${className}Editor <Control-f> {
948 %W icursor [expr {[%W index insert] + 1}]
949 %W selection clear
950}
951
952bind ${className}Editor <Control-h> {
953 if {[%W selection present]} {
954 %W delete sel.first sel.last
955 } else {
956 set index [expr [%W index insert] - 1]
957 if { $index >= 0 } {
958 %W delete $index $index
959 }
960 }
961}
962
963bind ${className}Editor <Control-k> {
964 %W delete insert end
965}
966
967if 0 {
968 bind ${className}Editor <Control-t> {
969 blt::tv::Transpose %W
970 }
971 bind ${className}Editor <Meta-b> {
972 %W icursor [blt::tv::PreviousWord %W insert]
973 %W selection clear
974 }
975 bind ${className}Editor <Meta-d> {
976 %W delete insert [blt::tv::NextWord %W insert]
977 }
978 bind ${className}Editor <Meta-f> {
979 %W icursor [blt::tv::NextWord %W insert]
980 %W selection clear
981 }
982 bind ${className}Editor <Meta-BackSpace> {
983 %W delete [blt::tv::PreviousWord %W insert] insert
984 }
985 bind ${className}Editor <Meta-Delete> {
986 %W delete [blt::tv::PreviousWord %W insert] insert
987 }
988 # tkEntryNextWord -- Returns the index of the next word position
989 # after a given position in the entry. The next word is platform
990 # dependent and may be either the next end-of-word position or the
991 # next start-of-word position after the next end-of-word position.
992 #
993 # Arguments:
994 # w - The entry window in which the cursor is to move.
995 # start - Position at which to start search.
996
997 if {![string compare $tcl_platform(platform) "windows"]} {
998 proc blt::tv::NextWord {w start} {
999 set pos [tcl_endOfWord [$w get] [$w index $start]]
1000 if {$pos >= 0} {
1001 set pos [tcl_startOfNextWord [$w get] $pos]
1002 }
1003 if {$pos < 0} {
1004 return end
1005 }
1006 return $pos
1007 }
1008 } else {
1009 proc blt::tv::NextWord {w start} {
1010 set pos [tcl_endOfWord [$w get] [$w index $start]]
1011 if {$pos < 0} {
1012 return end
1013 }
1014 return $pos
1015 }
1016 }
1017
1018 # PreviousWord --
1019 #
1020 # Returns the index of the previous word position before a given
1021 # position in the entry.
1022 #
1023 # Arguments:
1024 # w - The entry window in which the cursor is to move.
1025 # start - Position at which to start search.
1026
1027 proc blt::tv::PreviousWord {w start} {
1028 set pos [tcl_startOfPreviousWord [$w get] [$w index $start]]
1029 if {$pos < 0} {
1030 return 0
1031 }
1032 return $pos
1033 }
1034}
1035
Note: See TracBrowser for help on using the repository browser.