|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace eval ttk { |
|
namespace eval entry { |
|
variable State |
|
|
|
set State(x) 0 |
|
set State(selectMode) none |
|
set State(anchor) 0 |
|
set State(scanX) 0 |
|
set State(scanIndex) 0 |
|
set State(scanMoved) 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set State(scanNum) 1 |
|
set State(scanDen) 1 |
|
set State(deadband) 3 |
|
} |
|
} |
|
|
|
|
|
|
|
option add *TEntry.cursor [ttk::cursor text] widgetDefault |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bind TEntry <<Cut>> { ttk::entry::Cut %W } |
|
bind TEntry <<Copy>> { ttk::entry::Copy %W } |
|
bind TEntry <<Paste>> { ttk::entry::Paste %W } |
|
bind TEntry <<Clear>> { ttk::entry::Clear %W } |
|
|
|
|
|
|
|
|
|
bind TEntry <Button-1> { ttk::entry::Press %W %x } |
|
bind TEntry <Shift-Button-1> { ttk::entry::Shift-Press %W %x } |
|
bind TEntry <Double-Button-1> { ttk::entry::Select %W %x word } |
|
bind TEntry <Triple-Button-1> { ttk::entry::Select %W %x line } |
|
bind TEntry <B1-Motion> { ttk::entry::Drag %W %x } |
|
|
|
bind TEntry <B1-Leave> { ttk::entry::DragOut %W %m } |
|
bind TEntry <B1-Enter> { ttk::entry::DragIn %W } |
|
bind TEntry <ButtonRelease-1> { ttk::entry::Release %W } |
|
|
|
bind TEntry <<ToggleSelection>> { |
|
%W instate {!readonly !disabled} { %W icursor @%x ; focus %W } |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
if {[tk windowingsystem] ne "aqua"} { |
|
bind TEntry <Button-2> { ttk::entry::ScanMark %W %x } |
|
bind TEntry <B2-Motion> { ttk::entry::ScanDrag %W %x } |
|
bind TEntry <ButtonRelease-2> { ttk::entry::ScanRelease %W %x } |
|
} else { |
|
bind TEntry <Button-3> { ttk::entry::ScanMark %W %x } |
|
bind TEntry <B3-Motion> { ttk::entry::ScanDrag %W %x } |
|
bind TEntry <ButtonRelease-3> { ttk::entry::ScanRelease %W %x } |
|
} |
|
bind TEntry <<PasteSelection>> { ttk::entry::ScanRelease %W %x } |
|
|
|
|
|
|
|
bind TEntry <<PrevChar>> { ttk::entry::Move %W prevchar } |
|
bind TEntry <<NextChar>> { ttk::entry::Move %W nextchar } |
|
bind TEntry <<PrevWord>> { ttk::entry::Move %W prevword } |
|
bind TEntry <<NextWord>> { ttk::entry::Move %W nextword } |
|
bind TEntry <<LineStart>> { ttk::entry::Move %W home } |
|
bind TEntry <<LineEnd>> { ttk::entry::Move %W end } |
|
|
|
bind TEntry <<SelectPrevChar>> { ttk::entry::Extend %W prevchar } |
|
bind TEntry <<SelectNextChar>> { ttk::entry::Extend %W nextchar } |
|
bind TEntry <<SelectPrevWord>> { ttk::entry::Extend %W prevword } |
|
bind TEntry <<SelectNextWord>> { ttk::entry::Extend %W nextword } |
|
bind TEntry <<SelectLineStart>> { ttk::entry::Extend %W home } |
|
bind TEntry <<SelectLineEnd>> { ttk::entry::Extend %W end } |
|
|
|
bind TEntry <<SelectAll>> { %W selection range 0 end } |
|
bind TEntry <<SelectNone>> { %W selection clear } |
|
|
|
bind TEntry <<TraverseIn>> { %W selection range 0 end; %W icursor end } |
|
|
|
|
|
|
|
bind TEntry <Key> { ttk::entry::Insert %W %A } |
|
bind TEntry <Delete> { ttk::entry::Delete %W } |
|
bind TEntry <BackSpace> { ttk::entry::Backspace %W } |
|
|
|
|
|
|
|
|
|
|
|
bind TEntry <Alt-Key> {# nothing} |
|
bind TEntry <Meta-Key> {# nothing} |
|
bind TEntry <Control-Key> {# nothing} |
|
bind TEntry <Escape> {# nothing} |
|
bind TEntry <Return> {# nothing} |
|
bind TEntry <KP_Enter> {# nothing} |
|
bind TEntry <Tab> {# nothing} |
|
|
|
|
|
|
|
if {[tk windowingsystem] eq "aqua"} { |
|
bind TEntry <Command-Key> {# nothing} |
|
bind TEntry <Mod4-Key> {# nothing} |
|
} |
|
|
|
bind TEntry <<PrevLine>> {# nothing} |
|
bind TEntry <<NextLine>> {# nothing} |
|
|
|
|
|
|
|
bind TEntry <Control-d> { ttk::entry::Delete %W } |
|
bind TEntry <Control-h> { ttk::entry::Backspace %W } |
|
bind TEntry <Control-k> { %W delete insert end } |
|
|
|
|
|
|
|
bind TEntry <<TkStartIMEMarkedText>> { |
|
dict set ::tk::Priv(IMETextMark) "%W" [%W index insert] |
|
} |
|
bind TEntry <<TkEndIMEMarkedText>> { |
|
if { [catch {dict get $::tk::Priv(IMETextMark) "%W"} mark] } { |
|
bell |
|
} else { |
|
%W selection range $mark insert |
|
} |
|
} |
|
bind TEntry <<TkClearIMEMarkedText>> { |
|
%W delete [dict get $::tk::Priv(IMETextMark) "%W"] [%W index insert] |
|
} |
|
bind TEntry <<TkAccentBackspace>> { |
|
ttk::entry::Backspace %W |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::entry::EntrySelection {w} { |
|
set entryString [string range [$w get] [$w index sel.first] \ |
|
[expr {[$w index sel.last] - 1}]] |
|
if {[$w cget -show] ne ""} { |
|
return [string repeat [string index [$w cget -show] 0] \ |
|
[string length $entryString]] |
|
} |
|
return $entryString |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::Paste {w} { |
|
catch { |
|
set clipboard [::tk::GetSelection $w CLIPBOARD] |
|
PendingDelete $w |
|
$w insert insert $clipboard |
|
See $w insert |
|
} |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::Copy {w} { |
|
if {![catch {EntrySelection $w} selection]} { |
|
clipboard clear -displayof $w |
|
clipboard append -displayof $w $selection |
|
} |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::Clear {w} { |
|
catch { $w delete sel.first sel.last } |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::Cut {w} { |
|
Copy $w; Clear $w |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::entry::ClosestGap {w x} { |
|
set pos [$w index @$x] |
|
set bbox [$w bbox $pos] |
|
if {$x - [lindex $bbox 0] > [lindex $bbox 2]/2} { |
|
incr pos |
|
} |
|
return $pos |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::See {w {index insert}} { |
|
set c [$w index $index] |
|
|
|
if {$c < [$w index @0] || $c >= [$w index @[winfo width $w]]} { |
|
$w xview $c |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
set ::ttk::entry::State(startNext) \ |
|
[string equal [tk windowingsystem] "win32"] |
|
|
|
proc ttk::entry::NextWord {w start} { |
|
|
|
if {[winfo class $w] eq "TEntry" && [$w cget -show] ne ""} { |
|
return end |
|
} |
|
variable State |
|
set pos [tcl_endOfWord [$w get] [$w index $start]] |
|
if {$pos >= 0 && $State(startNext)} { |
|
set pos [tcl_startOfNextWord [$w get] $pos] |
|
} |
|
if {$pos < 0} { |
|
return end |
|
} |
|
return $pos |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::PrevWord {w start} { |
|
|
|
if {[winfo class $w] eq "TEntry" && [$w cget -show] ne ""} { |
|
return 0 |
|
} |
|
set pos [tcl_startOfPreviousWord [$w get] [$w index $start]] |
|
if {$pos < 0} { |
|
return 0 |
|
} |
|
return $pos |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::RelIndex {w where {index insert}} { |
|
switch -- $where { |
|
prevchar { expr {[$w index $index] - 1} } |
|
nextchar { expr {[$w index $index] + 1} } |
|
prevword { PrevWord $w $index } |
|
nextword { NextWord $w $index } |
|
home { return 0 } |
|
end { $w index end } |
|
default { error "Bad relative index $index" } |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
proc ttk::entry::Move {w where} { |
|
$w icursor [RelIndex $w $where] |
|
$w selection clear |
|
See $w insert |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::entry::ExtendTo {w index} { |
|
set index [$w index $index] |
|
set insert [$w index insert] |
|
|
|
|
|
if {![$w selection present]} { |
|
set anchor $insert |
|
} else { |
|
set selfirst [$w index sel.first] |
|
set sellast [$w index sel.last] |
|
|
|
if { ($index < $selfirst) |
|
|| ($insert == $selfirst && $index <= $sellast) |
|
} { |
|
set anchor $sellast |
|
} else { |
|
set anchor $selfirst |
|
} |
|
} |
|
|
|
|
|
if {$anchor < $index} { |
|
$w selection range $anchor $index |
|
} else { |
|
$w selection range $index $anchor |
|
} |
|
|
|
$w icursor $index |
|
return $anchor |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::Extend {w where} { |
|
ExtendTo $w [RelIndex $w $where] |
|
See $w |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::entry::Press {w x} { |
|
variable State |
|
|
|
$w icursor [ClosestGap $w $x] |
|
$w selection clear |
|
$w instate !disabled { focus $w } |
|
|
|
|
|
set State(x) $x |
|
set State(selectMode) char |
|
set State(anchor) [$w index insert] |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::entry::Shift-Press {w x} { |
|
variable State |
|
|
|
focus $w |
|
set anchor [ExtendTo $w @$x] |
|
|
|
set State(x) $x |
|
set State(selectMode) char |
|
set State(anchor) $anchor |
|
} |
|
|
|
|
|
|
|
|
|
|
|
proc ttk::entry::Select {w x mode} { |
|
variable State |
|
set cur [ClosestGap $w $x] |
|
|
|
switch -- $mode { |
|
word { WordSelect $w $cur $cur } |
|
line { LineSelect $w $cur $cur } |
|
char { # no-op } |
|
} |
|
|
|
set State(anchor) $cur |
|
set State(selectMode) $mode |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::Drag {w x} { |
|
variable State |
|
set State(x) $x |
|
DragTo $w $x |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::DragTo {w x} { |
|
variable State |
|
|
|
set cur [ClosestGap $w $x] |
|
switch $State(selectMode) { |
|
char { CharSelect $w $State(anchor) $cur } |
|
word { WordSelect $w $State(anchor) $cur } |
|
line { LineSelect $w $State(anchor) $cur } |
|
none { # no-op } |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::entry::DragOut {w mode} { |
|
variable State |
|
if {$State(selectMode) ne "none" && $mode eq "NotifyNormal"} { |
|
ttk::Repeatedly ttk::entry::AutoScroll $w |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::entry::DragIn {w} { |
|
ttk::CancelRepeat |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::Release {w} { |
|
variable State |
|
set State(selectMode) none |
|
ttk::CancelRepeat |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::entry::AutoScroll {w} { |
|
variable State |
|
if {![winfo exists $w]} return |
|
set x $State(x) |
|
if {$x > [winfo width $w]} { |
|
$w xview scroll 2 units |
|
DragTo $w $x |
|
} elseif {$x < 0} { |
|
$w xview scroll -2 units |
|
DragTo $w $x |
|
} |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::CharSelect {w from to} { |
|
if {$to <= $from} { |
|
$w selection range $to $from |
|
} else { |
|
$w selection range $from $to |
|
} |
|
$w icursor $to |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::WordSelect {w from to} { |
|
if {$to < $from} { |
|
set first [WordBack [$w get] $to] |
|
set last [WordForward [$w get] $from] |
|
$w icursor $first |
|
} else { |
|
set first [WordBack [$w get] $from] |
|
set last [WordForward [$w get] $to] |
|
$w icursor $last |
|
} |
|
$w selection range $first $last |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::WordBack {text index} { |
|
if {[set pos [tcl_wordBreakBefore $text $index]] < 0} { return 0 } |
|
return $pos |
|
} |
|
proc ttk::entry::WordForward {text index} { |
|
if {[set pos [tcl_wordBreakAfter $text $index]] < 0} { return end } |
|
return $pos |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::LineSelect {w _ _} { |
|
variable State |
|
$w selection range 0 end |
|
$w icursor end |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::entry::ScanMark {w x} { |
|
variable State |
|
set State(scanX) $x |
|
set State(scanIndex) [$w index @0] |
|
set State(scanMoved) 0 |
|
} |
|
|
|
|
|
|
|
proc ttk::entry::ScanDrag {w x} { |
|
variable State |
|
|
|
set dx [expr {$State(scanX) - $x}] |
|
if {abs($dx) > $State(deadband)} { |
|
set State(scanMoved) 1 |
|
} |
|
set left [expr {$State(scanIndex) + ($dx*$State(scanNum))/$State(scanDen)}] |
|
$w xview $left |
|
|
|
if {$left != [set newLeft [$w index @0]]} { |
|
|
|
|
|
|
|
|
|
set State(scanX) $x |
|
set State(scanIndex) $newLeft |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::entry::ScanRelease {w x} { |
|
variable State |
|
if {!$State(scanMoved)} { |
|
$w instate {!disabled !readonly} { |
|
$w icursor [ClosestGap $w $x] |
|
catch {$w insert insert [::tk::GetSelection $w PRIMARY]} |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::entry::PendingDelete {w} { |
|
if {[$w selection present]} { |
|
$w icursor sel.first |
|
$w delete sel.first sel.last |
|
return 1 |
|
} |
|
return 0 |
|
} |
|
|
|
|
|
|
|
|
|
|
|
proc ttk::entry::Insert {w s} { |
|
if {$s eq ""} { return } |
|
PendingDelete $w |
|
$w insert insert $s |
|
See $w insert |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::entry::Backspace {w} { |
|
if {[PendingDelete $w]} { |
|
See $w |
|
return |
|
} |
|
set x [expr {[$w index insert] - 1}] |
|
if {$x < 0} { return } |
|
|
|
$w delete $x |
|
|
|
if {[$w index @0] >= [$w index insert]} { |
|
set range [$w xview] |
|
set left [lindex $range 0] |
|
set right [lindex $range 1] |
|
$w xview moveto [expr {$left - ($right - $left)/2.0}] |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::entry::Delete {w} { |
|
if {![PendingDelete $w]} { |
|
$w delete insert |
|
} |
|
} |
|
|
|
|
|
|