2 # ----------------------------------------------------------------------
3 # Bindings for the BLT hiertable widget
4 # ----------------------------------------------------------------------
5 # AUTHOR: George Howlett
6 # Bell Labs Innovations for Lucent Technologies
8 # http://www.tcltk.com/blt
10 # RCS: $Id: bltHiertable.tcl,v 1.18 2000/06/23 00:40:05 gah Exp $
12 # ----------------------------------------------------------------------
13 # Copyright (c) 1998 Lucent Technologies, Inc.
14 # ======================================================================
16 # Permission to use, copy, modify, and distribute this software and its
17 # documentation for any purpose and without fee is hereby granted,
18 # provided that the above copyright notice appear in all copies and that
19 # both that the copyright notice and warranty disclaimer appear in
20 # supporting documentation, and that the names of Lucent Technologies
21 # any of their entities not be used in advertising or publicity
22 # pertaining to distribution of the software without specific, written
25 # Lucent Technologies disclaims all warranties with regard to this
26 # software, including all implied warranties of merchantability and
27 # fitness. In no event shall Lucent be liable for any special, indirect
28 # or consequential damages or any damages whatsoever resulting from loss
29 # of use, data or profits, whether in an action of contract, negligence
30 # or other tortuous action, arising out of or in connection with the use
31 # or performance of this software.
33 # ======================================================================
35 namespace eval blt::Hiertable {
45 # ButtonPress assignments
47 # B1-Enter start auto-scrolling
48 # B1-Leave stop auto-scrolling
49 # ButtonPress-2 start scan
50 # B2-Motion adjust scan
51 # ButtonRelease-2 stop scan
54 bind Hiertable <ButtonPress-2> {
55 set blt::Hiertable::cursor [%W cget -cursor]
56 %W configure -cursor hand1
60 bind Hiertable <B2-Motion> {
64 bind Hiertable <ButtonRelease-2> {
65 %W configure -cursor $blt::Hiertable::cursor
68 bind Hiertable <B1-Leave> {
69 if { $blt::Hiertable::scroll } {
70 blt::Hiertable::AutoScroll %W
74 bind Hiertable <B1-Enter> {
75 after cancel $blt::Hiertable::afterId
79 # KeyPress assignments
89 # space Start selection toggle of entry currently with focus.
90 # Return Start selection toggle of entry currently with focus.
95 # ASCII char Go to next open entry starting with character.
99 # space Stop selection toggle of entry currently with focus.
100 # Return Stop selection toggle of entry currently with focus.
103 bind Hiertable <KeyPress-Up> {
104 blt::Hiertable::MoveFocus %W up
105 if { $blt::Hiertable::space } {
106 %W selection toggle focus
110 bind Hiertable <KeyPress-Down> {
111 blt::Hiertable::MoveFocus %W down
112 if { $blt::Hiertable::space } {
113 %W selection toggle focus
117 bind Hiertable <Shift-KeyPress-Up> {
118 blt::Hiertable::MoveFocus %W prevsibling
121 bind Hiertable <Shift-KeyPress-Down> {
122 blt::Hiertable::MoveFocus %W nextsibling
125 bind Hiertable <KeyPress-Prior> {
126 blt::Hiertable::MovePage %W top
129 bind Hiertable <KeyPress-Next> {
130 blt::Hiertable::MovePage %W bottom
133 bind Hiertable <KeyPress-Left> {
136 bind Hiertable <KeyPress-Right> {
138 %W see focus -anchor w
141 bind Hiertable <KeyPress-space> {
142 if { [%W cget -selectmode] == "single" } {
143 if { [%W selection includes focus] } {
144 %W selection clearall
146 %W selection clearall
147 %W selection set focus
150 %W selection toggle focus
152 set blt::Hiertable::space on
155 bind Hiertable <KeyRelease-space> {
156 set blt::Hiertable::space off
159 bind Hiertable <KeyPress-Return> {
160 blt::Hiertable::MoveFocus %W focus
161 set blt::Hiertable::space on
164 bind Hiertable <KeyRelease-Return> {
165 set blt::Hiertable::space off
168 bind Hiertable <KeyPress> {
169 blt::Hiertable::NextMatchingEntry %W %A
172 bind Hiertable <KeyPress-Home> {
173 blt::Hiertable::MoveFocus %W top
176 bind Hiertable <KeyPress-End> {
177 blt::Hiertable::MoveFocus %W bottom
180 bind Hiertable <KeyPress-F1> {
184 bind Hiertable <KeyPress-F2> {
185 eval %W close -r [%W entry children root]
189 # Differences between "current" and nearest.
191 # set index [$widget index current]
192 # set index [$widget nearest $x $y]
194 # o Nearest gives you the closest entry.
196 # 1) the pointer isn't over an entry.
197 # 2) the pointer is over a open/close button.
201 # ----------------------------------------------------------------------
203 # USAGE: blt::Hiertable::Init <hiertable>
205 # Invoked by internally by Hiertable_Init routine. Initializes the
206 # default bindings for the hiertable widget entries. These are local
207 # to the widget, so they can't be set through the widget's class
210 # Arguments: hiertable hierarchy widget
212 # ----------------------------------------------------------------------
213 proc blt::Hiertable::Init { widget } {
215 # Active entry bindings
217 $widget bind Entry <Enter> {
218 %W entry highlight current
220 $widget bind Entry <Leave> {
221 %W entry highlight ""
227 $widget button bind all <ButtonRelease-1> {
228 %W see -anchor nw current
231 $widget button bind all <Enter> {
232 %W button highlight current
234 $widget button bind all <Leave> {
235 %W button highlight ""
241 # Performs the following operations:
243 # 1. Clears the previous selection.
244 # 2. Selects the current entry.
245 # 3. Sets the focus to this entry.
246 # 4. Scrolls the entry into view.
247 # 5. Sets the selection anchor to this entry, just in case
248 # this is "multiple" mode.
251 $widget bind Entry <ButtonPress-1> {
252 blt::Hiertable::SetSelectionAnchor %W current
253 set blt::Hiertable::scroll 1
256 $widget bin Entry <Double-ButtonPress-1> {
263 # For "multiple" mode only. Saves the current location of the
264 # pointer for auto-scrolling. Resets the selection mark.
266 $widget bind Entry <B1-Motion> {
267 set blt::Hiertable::x %x
268 set blt::Hiertable::y %y
269 set index [%W nearest %x %y]
270 if { [%W cget -selectmode] == "multiple" } {
271 %W selection mark $index
273 blt::Hiertable::SetSelectionAnchor %W $index
280 # For "multiple" mode only.
282 $widget bind Entry <ButtonRelease-1> {
283 if { [%W cget -selectmode] == "multiple" } {
284 %W selection anchor current
286 after cancel $blt::Hiertable::afterId
287 set blt::Hiertable::scroll 0
291 # Shift-ButtonPress-1
293 # For "multiple" mode only.
296 $widget bind Entry <Shift-ButtonPress-1> {
297 if { [%W cget -selectmode] == "multiple" && [%W selection present] } {
298 if { [%W index anchor] == "" } {
299 %W selection anchor current
301 set index [%W index anchor]
302 %W selection clearall
303 %W selection set $index current
305 blt::Hiertable::SetSelectionAnchor %W current
308 $widget bin Entry <Shift-Double-ButtonPress-1> {
309 puts <Shift-Double-ButtonPress-1>
312 $widget bind Entry <Shift-B1-Motion> {
315 $widget bind Entry <Shift-ButtonRelease-1> {
316 after cancel $blt::Hiertable::afterId
317 set blt::Hiertable::scroll 0
321 # Control-ButtonPress-1
323 # For "multiple" mode only.
325 $widget bind Entry <Control-ButtonPress-1> {
326 if { [%W cget -selectmode] == "multiple" } {
327 set index [%W index current]
328 %W selection toggle $index
329 %W selection anchor $index
331 blt::Hiertable::SetSelectionAnchor %W current
334 $widget bin Entry <Control-Double-ButtonPress-1> {
335 puts <Control-Double-ButtonPress-1>
338 $widget bind Entry <Control-B1-Motion> {
341 $widget bind Entry <Control-ButtonRelease-1> {
342 after cancel $blt::Hiertable::afterId
343 set blt::Hiertable::scroll 0
346 $widget bind Entry <Control-Shift-ButtonPress-1> {
347 if { [%W cget -selectmode] == "multiple" && [%W selection present] } {
348 if { [%W index anchor] == "" } {
349 %W selection anchor current
351 if { [%W selection includes anchor] } {
352 %W selection set anchor current
354 %W selection clear anchor current
355 %W selection set current
358 blt::Hiertable::SetSelectionAnchor %W current
361 $widget bin Entry <Control-Shift-Double-ButtonPress-1> {
362 puts <Control-Shift-Double-ButtonPress-1>
365 $widget bind Entry <Control-Shift-B1-Motion> {
368 $widget column bind all <Enter> {
369 %W column highlight [%W column current]
371 $widget column bind all <Leave> {
372 %W column highlight ""
374 $widget column bind Rule <Enter> {
375 %W column highlight [%W column current]
376 %W column resize activate [%W column current]
378 $widget column bind Rule <Leave> {
379 %W column highlight ""
380 %W column resize activate ""
382 $widget column bind Rule <ButtonPress-1> {
383 %W column resize anchor %x
385 $widget column bind Rule <B1-Motion> {
386 %W column resize mark %x
388 $widget column bind Rule <ButtonRelease-1> {
389 %W column configure [%W column current] -width [%W column resize set]
391 $widget column bind all <ButtonRelease-1> {
392 set column [%W column nearest %x %y]
393 if { $column != "" } {
394 %W column invoke $column
399 # ----------------------------------------------------------------------
400 # USAGE: blt::Hiertable::AutoScroll <hiertable>
402 # Invoked when the user is selecting elements in a hiertable widget
403 # and drags the mouse pointer outside of the widget. Scrolls the
404 # view in the direction of the pointer.
406 # Arguments: hiertable hierarchy widget
408 # ----------------------------------------------------------------------
409 proc blt::Hiertable::AutoScroll { widget } {
410 if { ![winfo exists $widget] } {
413 set x $blt::Hiertable::x
414 set y $blt::Hiertable::y
416 set index [$widget nearest $x $y]
417 if { $y >= [winfo height $widget] } {
418 $widget yview scroll 1 units
420 } elseif { $y < 0 } {
421 $widget yview scroll -1 units
426 if { [$widget cget -selectmode] == "single" } {
427 blt::Hiertable::SetSelectionAnchor $widget $neighbor
429 $widget selection mark $index
431 set ::blt::Hiertable::afterId [after 10 blt::Hiertable::AutoScroll $widget]
434 proc blt::Hiertable::SetSelectionAnchor { widget index } {
435 set index [$widget index $index]
436 $widget selection clearall
439 $widget selection set $index
440 $widget selection anchor $index
443 # ----------------------------------------------------------------------
444 # USAGE: blt::Hiertable::MoveFocus <hiertable> <where>
446 # Invoked by KeyPress bindings. Moves the active selection to the
447 # entry <where>, which is an index such as "up", "down", "prevsibling",
448 # "nextsibling", etc.
449 # ----------------------------------------------------------------------
450 proc blt::Hiertable::MoveFocus { widget where } {
451 catch {$widget focus $where}
452 if { [$widget cget -selectmode] == "single" } {
453 $widget selection clearall
454 $widget selection set focus
459 # ----------------------------------------------------------------------
460 # USAGE: blt::Hiertable::MovePage <hiertable> <where>
461 # Arguments: hiertable hierarchy widget
463 # Invoked by KeyPress bindings. Pages the current view up or down.
464 # The <where> argument should be either "top" or "bottom".
465 # ----------------------------------------------------------------------
467 proc blt::Hiertable::MovePage { widget where } {
469 # If the focus is already at the top/bottom of the window, we want
470 # to scroll a page. It's really one page minus an entry because we
471 # want to see the last entry on the next/last page.
472 if { [$widget index focus] == [$widget index view.$where] } {
473 if {$where == "top"} {
474 $widget yview scroll -1 pages
475 $widget yview scroll 1 units
477 $widget yview scroll 1 pages
478 $widget yview scroll -1 units
483 # Adjust the entry focus and the view. Also activate the entry.
484 # just in case the mouse point is not in the widget.
485 $widget entry highlight view.$where
486 $widget focus view.$where
487 $widget see view.$where
488 if { [$widget cget -selectmode] == "single" } {
489 $widget selection clearall
490 $widget selection set focus
494 # ----------------------------------------------------------------------
495 # USAGE: blt::Hiertable::NextMatchingEntry <hiertable> <char>
496 # Arguments: hiertable hierarchy widget
498 # Invoked by KeyPress bindings. Searches for an entry that starts
499 # with the letter <char> and makes that entry active.
500 # ----------------------------------------------------------------------
502 proc blt::Hiertable::NextMatchingEntry { widget key } {
503 if {[string match {[ -~]} $key]} {
504 set last [$widget index focus]
505 set next [$widget index next]
506 while { $next != $last } {
507 set label [$widget entry cget $next -label]
508 if { [string index $label 0] == $key } {
511 set next [$widget index -at $next next]
514 if {[$widget cget -selectmode] == "single"} {
515 $widget selection clearall
516 $widget selection set focus
523 # Edit mode assignments
525 # ButtonPress-3 Enables/disables edit mode on entry. Sets focus to
530 # Left Move insertion position to previous.
531 # Right Move insertion position to next.
532 # Up Move insertion position up one line.
533 # Down Move insertion position down one line.
534 # Return End edit mode.
535 # Shift-Return Line feed.
536 # Home Move to first position.
537 # End Move to last position.
538 # ASCII char Insert character left of insertion point.
539 # Del Delete character right of insertion point.
540 # Delete Delete character left of insertion point.
547 # ButtonPress-1 Start selection if in entry, otherwise clear selection.
548 # B1-Motion Extend/reduce selection.
549 # ButtonRelease-1 End selection if in entry, otherwise use last selection.
552 # ButtonPress-2 Same as above.
553 # B2-Motion Same as above.
554 # ButtonRelease-2 Same as above.
556 # All bindings in editting mode will "break" to override other bindings.
560 bind xEditor <ButtonPress-3> {
561 set node [%W nearest %x %y]
562 %W entry insert $node @%x,%y ""
563 # %W entry insert $node 2 ""
567 image create photo blt::Hiertable::CloseNormalFolder -format gif -data {
568 R0lGODlhEAANAPIAAAAAAH9/f7+/v///////AAAAAAAAAAAAACH+JEZpbGUgd3JpdHRlbiBi
569 eSBBZG9iZSBQaG90b3Nob3CoIDUuMAAsAAAAABAADQAAAzk4Gsz6cIQ44xqCZCGbk4MmclAA
570 gNs4ml7rEaxVAkKc3gTAnBO+sbyQT6M7gVQpk9HlAhgHzqhUmgAAOw==
572 image create photo blt::Hiertable::OpenNormalFolder -format gif -data {
573 R0lGODlhEAANAPIAAAAAAH9/f7+/v///AP///wAAAAAAAAAAACH+JEZpbGUgd3JpdHRlbiBi
574 eSBBZG9iZSBQaG90b3Nob3CoIDUuMAAsAAAAABAADQAAAzNIGsz6kAQxqAjxzcpvc1KWBUDY
575 nRQZWmilYi37EmztlrAt43R8mzrO60P8lAiApHK5TAAAOw==
577 image create photo blt::Hiertable::CloseActiveFolder -format gif -data {
578 R0lGODlhEAANAPIAAAAAAH9/f7+/v/////+/AAAAAAAAAAAAACH+JEZpbGUgd3JpdHRlbiBi
579 eSBBZG9iZSBQaG90b3Nob3CoIDUuMAAsAAAAABAADQAAAzk4Gsz6cIQ44xqCZCGbk4MmclAA
580 gNs4ml7rEaxVAkKc3gTAnBO+sbyQT6M7gVQpk9HlAhgHzqhUmgAAOw==
582 image create photo blt::Hiertable::OpenActiveFolder -format gif -data {
583 R0lGODlhEAANAPIAAAAAAH9/f7+/v/+/AP///wAAAAAAAAAAACH+JEZpbGUgd3JpdHRlbiBi
584 eSBBZG9iZSBQaG90b3Nob3CoIDUuMAAsAAAAABAADQAAAzNIGsz6kAQxqAjxzcpvc1KWBUDY
585 nRQZWmilYi37EmztlrAt43R8mzrO60P8lAiApHK5TAAAOw==
589 image create photo blt::Hiertable::CloseNormalFolder -format gif -data {
590 R0lGODlhEAANAMIAAAAAAH9/f///////AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
591 AAM8WBrM+rAEQWmIb5KxiWjNInCkV32AJHRlGQBgDA7vdN4vUa8tC78qlrCWmvRKsJTquHkp
594 image create photo blt::Hiertable::OpenNormalFolder -format gif -data {
595 R0lGODlhEAANAMIAAAAAAH9/f///////AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
596 AAM1WBrM+rAEMigJ8c3Kb3OSII6kGABhp1JnaK1VGwjwKwtvHqNzzd263M3H4n2OH1QBwGw6
599 image create photo blt::Hiertable::CloseActiveFolder -format gif -data {
600 R0lGODlhEAANAMIAAAAAAH9/f/////+/AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
601 AAM8WBrM+rAEQWmIb5KxiWjNInCkV32AJHRlGQBgDA7vdN4vUa8tC78qlrCWmvRKsJTquHkp
604 image create photo blt::Hiertable::OpenActiveFolder -format gif -data {
605 R0lGODlhEAANAMIAAAAAAH9/f/////+/AL+/vwAA/wAAAAAAACH5BAEAAAUALAAAAAAQAA0A
606 AAM1WBrM+rAEMigJ8c3Kb3OSII6kGABhp1JnaK1VGwjwKwtvHqNzzd263M3H4n2OH1QBwGw6
611 if { $tcl_platform(platform) == "windows" } {
612 if { $tk_version >= 8.3 } {
613 set cursor "@[file join $blt_library htresize.cur]"
617 option add *Hiertable.ResizeCursor $cursor
619 option add *Hiertable.ResizeCursor \
620 "@$blt_library/htresize.xbm $blt_library/htresize_m.xbm black white"
623 # Standard Motif bindings:
625 bind HiertableEditor <ButtonPress-1> {
626 [winfo parent %W] text icursor @%x,%y
629 bind HiertableEditor <Left> {
630 [winfo parent %W] text icursor last
632 bind HiertableEditor <Right> {
633 [winfo parent %W] text icursor next
635 bind HiertableEditor <Shift-Left> {
636 tkEntryKeySelect %W [expr {[%W index insert] - 1}]
639 bind HiertableEditor <Shift-Right> {
640 tkEntryKeySelect %W [expr {[%W index insert] + 1}]
644 bind HiertableEditor <Home> {
645 [winfo parent %W] text icursor 0
647 bind HiertableEditor <Shift-Home> {
648 tkEntryKeySelect %W 0
651 bind HiertableEditor <End> {
652 [winfo parent %W] text icursor end
654 bind HiertableEditor <Shift-End> {
655 tkEntryKeySelect %W end
659 bind HiertableEditor <Delete> {
660 if {[[winfo parent %W] text selection present]} {
661 [winfo parent %W] delete sel.first sel.last
663 [winfo parent %W] delete insert
666 bind HiertableEditor <BackSpace> {
667 blt::Hiertable::EditorBackspace [winfo parent %W]
670 bind HiertableEditor <Control-space> {
671 [winfo parent %W] text selection from insert
673 bind HiertableEditor <Select> {
674 [winfo parent %W] text selection from insert
676 bind HiertableEditor <Control-Shift-space> {
677 [winfo parent %W] text selection adjust insert
679 bind HiertableEditor <Shift-Select> {
680 [winfo parent %W] text selection adjust insert
682 bind HiertableEditor <Control-slash> {
683 [winfo parent %W] text selection range 0 end
685 bind HiertableEditor <Control-backslash> {
686 [winfo parent %W] text selection clear
688 bind HiertableEditor <KeyPress> {
689 blt::Hiertable::Insert [winfo parent %W] %A
692 # Ignore all Alt, Meta, and Control keypresses unless explicitly bound.
693 # Otherwise, if a widget binding for one of these is defined, the
694 # <KeyPress> class binding will also fire and insert the character,
695 # which is wrong. Ditto for Escape, Return, and Tab.
697 bind HiertableEditor <Alt-KeyPress> {
700 bind HiertableEditor <Meta-KeyPress> {
703 bind HiertableEditor <Control-KeyPress> {
706 bind HiertableEditor <Escape> {
707 [winfo parent %W] text cancel
709 bind HiertableEditor <Return> {
710 [winfo parent %W] text apply
712 bind HiertableEditor <Shift-Return> {
713 blt::Hiertable::Insert [winfo parent %W] "\n"
715 bind HiertableEditor <KP_Enter> {# nothing}
716 bind HiertableEditor <Tab> {# nothing}
717 if {![string compare $tcl_platform(platform) "macintosh"]} {
718 bind HiertableEditor <Command-KeyPress> {# nothing}
721 # On Windows, paste is done using Shift-Insert. Shift-Insert already
722 # generates the <<Paste>> event, so we don't need to do anything here.
723 if {[string compare $tcl_platform(platform) "windows"]} {
724 bind HiertableEditor <Insert> {
725 catch {tkEntryInsert %W [selection get -displayof %W]}
729 # Additional emacs-like bindings:
731 bind HiertableEditor <Control-a> {
732 tkEntrySetCursor %W 0
734 bind HiertableEditor <Control-b> {
735 tkEntrySetCursor %W [expr {[%W index insert] - 1}]
738 bind HiertableEditor <Control-d> {
739 %W text delete insert
741 bind HiertableEditor <Control-e> {
742 tkEntrySetCursor %W end
744 bind HiertableEditor <Control-f> {
745 tkEntrySetCursor %W [expr {[%W index insert] + 1}]
747 bind HiertableEditor <Control-h> {
748 blt::Hiertable::EditorBackspace [winfo parent %W]
750 bind HiertableEditor <Control-k> {
751 %W text delete insert end
753 bind HiertableEditor <Control-t> {
756 bind HiertableEditor <Meta-b> {
757 tkEntrySetCursor %W [tkEntryPreviousWord %W insert]
759 bind HiertableEditor <Meta-d> {
760 %W delete insert [tkEntryNextWord %W insert]
762 bind Entry <Meta-f> {
763 tkEntrySetCursor %W [tkEntryNextWord %W insert]
765 bind Entry <Meta-BackSpace> {
766 %W delete [tkEntryPreviousWord %W insert] insert
768 bind Entry <Meta-Delete> {
769 %W delete [tkEntryPreviousWord %W insert] insert
773 proc tkEntryKeySelect {w new} {
774 if {![$w selection present]} {
775 $w selection from insert
778 $w selection adjust $new
783 # blt::Hiertable::Insert --
784 # Insert a string into an entry at the point of the insertion cursor.
785 # If there is a selection in the entry, and it covers the point of the
786 # insertion cursor, then delete the selection before inserting.
789 # w - The entry window in which to insert the string
790 # s - The string to insert (usually just a single character)
792 proc blt::Hiertable::Insert {w s} {
793 if {![string compare $s ""]} {
796 $w text insert insert $s
799 proc blt::xHiertableInsert {w s} {
800 if {![string compare $s ""]} {
804 set insert [$w text index insert]
805 if {([$w text index sel.first] <= $insert)
806 && ([$w text index sel.last] >= $insert)} {
807 $w delete sel.first sel.last
814 # tkEntryBackspace --
815 # Backspace over the character just before the insertion cursor.
816 # If backspacing would move the cursor off the left edge of the
817 # window, reposition the cursor at about the middle of the window.
820 # w - The entry window in which to backspace.
822 proc blt::Hiertable::EditorBackspace w {
823 if {[$w text selection present]} {
824 $w text delete sel.first sel.last
826 set index [expr [$w text index insert] - 1]
828 $w text delete $index $index
833 proc tkEntryBackspace w {
834 if {[$w selection present]} {
835 $w delete sel.first sel.last
837 set x [expr {[$w index insert] - 1}]
838 if {$x >= 0} {$w delete $x}
839 if {[$w index @0] >= [$w index insert]} {
841 set left [lindex $range 0]
842 set right [lindex $range 1]
843 $w xview moveto [expr {$left - ($right - $left)/2.0}]
848 # tkEntrySeeInsert --
849 # Make sure that the insertion cursor is visible in the entry window.
850 # If not, adjust the view so that it is.
853 # w - The entry window.
855 proc tkEntrySeeInsert w {
856 set c [$w index insert]
857 set left [$w index @0]
862 set x [winfo width $w]
863 if {$c > [$w index @[winfo width $w]]} {
869 # Move the insertion cursor to a given position in an entry. Also
870 # clears the selection, if there is one in the entry, and makes sure
871 # that the insertion cursor is visible.
874 # w - The entry window.
875 # pos - The desired new position for the cursor in the window.
877 proc tkEntrySetCursor {w pos} {
884 # This procedure implements the "transpose" function for entry widgets.
885 # It tranposes the characters on either side of the insertion cursor,
886 # unless the cursor is at the end of the line. In this case it
887 # transposes the two characters to the left of the cursor. In either
888 # case, the cursor ends up to the right of the transposed characters.
891 # w - The entry window.
893 proc tkEntryTranspose w {
894 set i [$w index insert]
895 if {$i < [$w index end]} {
898 set first [expr {$i-2}]
902 set new [string index [$w get] [expr {$i-1}]][string index [$w get] $first]
904 $w insert insert $new
909 # Returns the index of the next word position after a given position in the
910 # entry. The next word is platform dependent and may be either the next
911 # end-of-word position or the next start-of-word position after the next
912 # end-of-word position.
915 # w - The entry window in which the cursor is to move.
916 # start - Position at which to start search.
918 if {![string compare $tcl_platform(platform) "windows"]} {
919 proc tkEntryNextWord {w start} {
920 set pos [tcl_endOfWord [$w get] [$w index $start]]
922 set pos [tcl_startOfNextWord [$w get] $pos]
930 proc tkEntryNextWord {w start} {
931 set pos [tcl_endOfWord [$w get] [$w index $start]]
939 # tkEntryPreviousWord --
941 # Returns the index of the previous word position before a given
942 # position in the entry.
945 # w - The entry window in which the cursor is to move.
946 # start - Position at which to start search.
948 proc tkEntryPreviousWord {w start} {
949 set pos [tcl_startOfPreviousWord [$w get] [$w index $start]]
955 # tkEntryGetSelection --
957 # Returns the selected text of the entry with respect to the -show option.
960 # w - The entry window from which the text to get
962 proc tkEntryGetSelection {w} {
963 set entryString [string range [$w get] [$w index sel.first] \
964 [expr [$w index sel.last] - 1]]
965 if {[$w cget -show] != ""} {
966 regsub -all . $entryString [string index [$w cget -show] 0] entryString