entry.tcl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. # entry.tcl --
  2. #
  3. # This file defines the default bindings for Tk entry widgets and provides
  4. # procedures that help in implementing those bindings.
  5. #
  6. # Copyright (c) 1992-1994 The Regents of the University of California.
  7. # Copyright (c) 1994-1997 Sun Microsystems, Inc.
  8. #
  9. # See the file "license.terms" for information on usage and redistribution
  10. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11. #
  12. #-------------------------------------------------------------------------
  13. # Elements of tk::Priv that are used in this file:
  14. #
  15. # afterId - If non-null, it means that auto-scanning is underway
  16. # and it gives the "after" id for the next auto-scan
  17. # command to be executed.
  18. # mouseMoved - Non-zero means the mouse has moved a significant
  19. # amount since the button went down (so, for example,
  20. # start dragging out a selection).
  21. # pressX - X-coordinate at which the mouse button was pressed.
  22. # selectMode - The style of selection currently underway:
  23. # char, word, or line.
  24. # x, y - Last known mouse coordinates for scanning
  25. # and auto-scanning.
  26. # data - Used for Cut and Copy
  27. #-------------------------------------------------------------------------
  28. #-------------------------------------------------------------------------
  29. # The code below creates the default class bindings for entries.
  30. #-------------------------------------------------------------------------
  31. bind Entry <<Cut>> {
  32. if {![catch {tk::EntryGetSelection %W} tk::Priv(data)]} {
  33. clipboard clear -displayof %W
  34. clipboard append -displayof %W $tk::Priv(data)
  35. %W delete sel.first sel.last
  36. unset tk::Priv(data)
  37. }
  38. }
  39. bind Entry <<Copy>> {
  40. if {![catch {tk::EntryGetSelection %W} tk::Priv(data)]} {
  41. clipboard clear -displayof %W
  42. clipboard append -displayof %W $tk::Priv(data)
  43. unset tk::Priv(data)
  44. }
  45. }
  46. bind Entry <<Paste>> {
  47. catch {
  48. if {[tk windowingsystem] ne "x11"} {
  49. catch {
  50. %W delete sel.first sel.last
  51. }
  52. }
  53. %W insert insert [::tk::GetSelection %W CLIPBOARD]
  54. tk::EntrySeeInsert %W
  55. }
  56. }
  57. bind Entry <<Clear>> {
  58. # ignore if there is no selection
  59. catch {%W delete sel.first sel.last}
  60. }
  61. bind Entry <<PasteSelection>> {
  62. if {$tk_strictMotif || ![info exists tk::Priv(mouseMoved)]
  63. || !$tk::Priv(mouseMoved)} {
  64. tk::EntryPaste %W %x
  65. }
  66. }
  67. bind Entry <<TraverseIn>> {
  68. %W selection range 0 end
  69. %W icursor end
  70. }
  71. # Standard Motif bindings:
  72. bind Entry <Button-1> {
  73. tk::EntryButton1 %W %x
  74. %W selection clear
  75. }
  76. bind Entry <B1-Motion> {
  77. set tk::Priv(x) %x
  78. tk::EntryMouseSelect %W %x
  79. }
  80. bind Entry <Double-Button-1> {
  81. set tk::Priv(selectMode) word
  82. tk::EntryMouseSelect %W %x
  83. catch {%W icursor sel.last}
  84. }
  85. bind Entry <Triple-Button-1> {
  86. set tk::Priv(selectMode) line
  87. tk::EntryMouseSelect %W %x
  88. catch {%W icursor sel.last}
  89. }
  90. bind Entry <Shift-Button-1> {
  91. set tk::Priv(selectMode) char
  92. %W selection adjust @%x
  93. }
  94. bind Entry <Double-Shift-Button-1> {
  95. set tk::Priv(selectMode) word
  96. tk::EntryMouseSelect %W %x
  97. }
  98. bind Entry <Triple-Shift-Button-1> {
  99. set tk::Priv(selectMode) line
  100. tk::EntryMouseSelect %W %x
  101. }
  102. bind Entry <B1-Leave> {
  103. set tk::Priv(x) %x
  104. tk::EntryAutoScan %W
  105. }
  106. bind Entry <B1-Enter> {
  107. tk::CancelRepeat
  108. }
  109. bind Entry <ButtonRelease-1> {
  110. tk::CancelRepeat
  111. }
  112. bind Entry <Control-Button-1> {
  113. %W icursor @%x
  114. }
  115. bind Entry <<PrevChar>> {
  116. tk::EntrySetCursor %W [expr {[%W index insert]-1}]
  117. }
  118. bind Entry <<NextChar>> {
  119. tk::EntrySetCursor %W [expr {[%W index insert]+1}]
  120. }
  121. bind Entry <<SelectPrevChar>> {
  122. tk::EntryKeySelect %W [expr {[%W index insert]-1}]
  123. tk::EntrySeeInsert %W
  124. }
  125. bind Entry <<SelectNextChar>> {
  126. tk::EntryKeySelect %W [expr {[%W index insert]+1}]
  127. tk::EntrySeeInsert %W
  128. }
  129. bind Entry <<PrevWord>> {
  130. tk::EntrySetCursor %W [tk::EntryPreviousWord %W insert]
  131. }
  132. bind Entry <<NextWord>> {
  133. tk::EntrySetCursor %W [tk::EntryNextWord %W insert]
  134. }
  135. bind Entry <<SelectPrevWord>> {
  136. tk::EntryKeySelect %W [tk::EntryPreviousWord %W insert]
  137. tk::EntrySeeInsert %W
  138. }
  139. bind Entry <<SelectNextWord>> {
  140. tk::EntryKeySelect %W [tk::EntryNextWord %W insert]
  141. tk::EntrySeeInsert %W
  142. }
  143. bind Entry <<LineStart>> {
  144. tk::EntrySetCursor %W 0
  145. }
  146. bind Entry <<SelectLineStart>> {
  147. tk::EntryKeySelect %W 0
  148. tk::EntrySeeInsert %W
  149. }
  150. bind Entry <<LineEnd>> {
  151. tk::EntrySetCursor %W end
  152. }
  153. bind Entry <<SelectLineEnd>> {
  154. tk::EntryKeySelect %W end
  155. tk::EntrySeeInsert %W
  156. }
  157. bind Entry <Delete> {
  158. if {[%W selection present]} {
  159. %W delete sel.first sel.last
  160. } else {
  161. %W delete insert
  162. }
  163. }
  164. bind Entry <BackSpace> {
  165. tk::EntryBackspace %W
  166. }
  167. bind Entry <Control-space> {
  168. %W selection from insert
  169. }
  170. bind Entry <Select> {
  171. %W selection from insert
  172. }
  173. bind Entry <Control-Shift-space> {
  174. %W selection adjust insert
  175. }
  176. bind Entry <Shift-Select> {
  177. %W selection adjust insert
  178. }
  179. bind Entry <<SelectAll>> {
  180. %W selection range 0 end
  181. }
  182. bind Entry <<SelectNone>> {
  183. %W selection clear
  184. }
  185. bind Entry <Key> {
  186. tk::CancelRepeat
  187. tk::EntryInsert %W %A
  188. }
  189. # Ignore all Alt, Meta, and Control keypresses unless explicitly bound.
  190. # Otherwise, if a widget binding for one of these is defined, the
  191. # <Key> class binding will also fire and insert the character,
  192. # which is wrong. Ditto for Escape, Return, and Tab.
  193. bind Entry <Alt-Key> {# nothing}
  194. bind Entry <Meta-Key> {# nothing}
  195. bind Entry <Control-Key> {# nothing}
  196. bind Entry <Escape> {# nothing}
  197. bind Entry <Return> {# nothing}
  198. bind Entry <KP_Enter> {# nothing}
  199. bind Entry <Tab> {# nothing}
  200. bind Entry <Prior> {# nothing}
  201. bind Entry <Next> {# nothing}
  202. if {[tk windowingsystem] eq "aqua"} {
  203. bind Entry <Command-Key> {# nothing}
  204. }
  205. # Tk-on-Cocoa generates characters for these two keys. [Bug 2971663]
  206. bind Entry <<NextLine>> {# nothing}
  207. bind Entry <<PrevLine>> {# nothing}
  208. # On Windows, paste is done using Shift-Insert. Shift-Insert already
  209. # generates the <<Paste>> event, so we don't need to do anything here.
  210. if {[tk windowingsystem] ne "win32"} {
  211. bind Entry <Insert> {
  212. catch {tk::EntryInsert %W [::tk::GetSelection %W PRIMARY]}
  213. }
  214. }
  215. # Additional emacs-like bindings:
  216. bind Entry <Control-d> {
  217. if {!$tk_strictMotif} {
  218. %W delete insert
  219. }
  220. }
  221. bind Entry <Control-h> {
  222. if {!$tk_strictMotif} {
  223. tk::EntryBackspace %W
  224. }
  225. }
  226. bind Entry <Control-k> {
  227. if {!$tk_strictMotif} {
  228. %W delete insert end
  229. }
  230. }
  231. bind Entry <Control-t> {
  232. if {!$tk_strictMotif} {
  233. tk::EntryTranspose %W
  234. }
  235. }
  236. bind Entry <Meta-b> {
  237. if {!$tk_strictMotif} {
  238. tk::EntrySetCursor %W [tk::EntryPreviousWord %W insert]
  239. }
  240. }
  241. bind Entry <Meta-d> {
  242. if {!$tk_strictMotif} {
  243. %W delete insert [tk::EntryNextWord %W insert]
  244. }
  245. }
  246. bind Entry <Meta-f> {
  247. if {!$tk_strictMotif} {
  248. tk::EntrySetCursor %W [tk::EntryNextWord %W insert]
  249. }
  250. }
  251. bind Entry <Meta-BackSpace> {
  252. if {!$tk_strictMotif} {
  253. %W delete [tk::EntryPreviousWord %W insert] insert
  254. }
  255. }
  256. bind Entry <Meta-Delete> {
  257. if {!$tk_strictMotif} {
  258. %W delete [tk::EntryPreviousWord %W insert] insert
  259. }
  260. }
  261. # Bindings for IME text input and accents.
  262. bind Entry <<TkStartIMEMarkedText>> {
  263. dict set ::tk::Priv(IMETextMark) "%W" [%W index insert]
  264. }
  265. bind Entry <<TkEndIMEMarkedText>> {
  266. if {[catch {dict get $::tk::Priv(IMETextMark) "%W"} mark]} {
  267. bell
  268. } else {
  269. %W selection range $mark insert
  270. }
  271. }
  272. bind Entry <<TkClearIMEMarkedText>> {
  273. %W delete [dict get $::tk::Priv(IMETextMark) "%W"] [%W index insert]
  274. }
  275. bind Entry <<TkAccentBackspace>> {
  276. tk::EntryBackspace %W
  277. }
  278. # A few additional bindings of my own.
  279. if {[tk windowingsystem] ne "aqua"} {
  280. bind Entry <Button-2> {
  281. if {!$tk_strictMotif} {
  282. ::tk::EntryScanMark %W %x
  283. }
  284. }
  285. bind Entry <B2-Motion> {
  286. if {!$tk_strictMotif} {
  287. ::tk::EntryScanDrag %W %x
  288. }
  289. }
  290. } else {
  291. bind Entry <Button-3> {
  292. if {!$tk_strictMotif} {
  293. ::tk::EntryScanMark %W %x
  294. }
  295. }
  296. bind Entry <B3-Motion> {
  297. if {!$tk_strictMotif} {
  298. ::tk::EntryScanDrag %W %x
  299. }
  300. }
  301. }
  302. # ::tk::EntryClosestGap --
  303. # Given x and y coordinates, this procedure finds the closest boundary
  304. # between characters to the given coordinates and returns the index
  305. # of the character just after the boundary.
  306. #
  307. # Arguments:
  308. # w - The entry window.
  309. # x - X-coordinate within the window.
  310. proc ::tk::EntryClosestGap {w x} {
  311. set pos [$w index @$x]
  312. set bbox [$w bbox $pos]
  313. if {($x - [lindex $bbox 0]) < ([lindex $bbox 2]/2)} {
  314. return $pos
  315. }
  316. incr pos
  317. }
  318. # ::tk::EntryButton1 --
  319. # This procedure is invoked to handle button-1 presses in entry
  320. # widgets. It moves the insertion cursor, sets the selection anchor,
  321. # and claims the input focus.
  322. #
  323. # Arguments:
  324. # w - The entry window in which the button was pressed.
  325. # x - The x-coordinate of the button press.
  326. proc ::tk::EntryButton1 {w x} {
  327. variable ::tk::Priv
  328. set Priv(selectMode) char
  329. set Priv(mouseMoved) 0
  330. set Priv(pressX) $x
  331. $w icursor [EntryClosestGap $w $x]
  332. $w selection from insert
  333. if {"disabled" ne [$w cget -state]} {
  334. focus $w
  335. }
  336. }
  337. # ::tk::EntryMouseSelect --
  338. # This procedure is invoked when dragging out a selection with
  339. # the mouse. Depending on the selection mode (character, word,
  340. # line) it selects in different-sized units. This procedure
  341. # ignores mouse motions initially until the mouse has moved from
  342. # one character to another or until there have been multiple clicks.
  343. #
  344. # Arguments:
  345. # w - The entry window in which the button was pressed.
  346. # x - The x-coordinate of the mouse.
  347. proc ::tk::EntryMouseSelect {w x} {
  348. variable ::tk::Priv
  349. set cur [EntryClosestGap $w $x]
  350. set anchor [$w index anchor]
  351. if {($cur != $anchor) || (abs($Priv(pressX) - $x) >= 3)} {
  352. set Priv(mouseMoved) 1
  353. }
  354. switch $Priv(selectMode) {
  355. char {
  356. if {$Priv(mouseMoved)} {
  357. if {$cur < $anchor} {
  358. $w selection range $cur $anchor
  359. } elseif {$cur > $anchor} {
  360. $w selection range $anchor $cur
  361. } else {
  362. $w selection clear
  363. }
  364. }
  365. }
  366. word {
  367. if {$cur < $anchor} {
  368. set before [tcl_wordBreakBefore [$w get] $cur]
  369. set after [tcl_wordBreakAfter [$w get] $anchor-1]
  370. } elseif {$cur > $anchor} {
  371. set before [tcl_wordBreakBefore [$w get] $anchor]
  372. set after [tcl_wordBreakAfter [$w get] $cur-1]
  373. } else {
  374. if {[$w index @$Priv(pressX)] < $anchor} {
  375. incr anchor -1
  376. }
  377. set before [tcl_wordBreakBefore [$w get] $anchor]
  378. set after [tcl_wordBreakAfter [$w get] $anchor]
  379. }
  380. if {$before < 0} {
  381. set before 0
  382. }
  383. if {$after < 0} {
  384. set after end
  385. }
  386. $w selection range $before $after
  387. }
  388. line {
  389. $w selection range 0 end
  390. }
  391. }
  392. if {$Priv(mouseMoved)} {
  393. $w icursor $cur
  394. }
  395. update idletasks
  396. }
  397. # ::tk::EntryPaste --
  398. # This procedure sets the insertion cursor to the current mouse position,
  399. # pastes the selection there, and sets the focus to the window.
  400. #
  401. # Arguments:
  402. # w - The entry window.
  403. # x - X position of the mouse.
  404. proc ::tk::EntryPaste {w x} {
  405. $w icursor [EntryClosestGap $w $x]
  406. catch {$w insert insert [::tk::GetSelection $w PRIMARY]}
  407. if {"disabled" ne [$w cget -state]} {
  408. focus $w
  409. }
  410. }
  411. # ::tk::EntryAutoScan --
  412. # This procedure is invoked when the mouse leaves an entry window
  413. # with button 1 down. It scrolls the window left or right,
  414. # depending on where the mouse is, and reschedules itself as an
  415. # "after" command so that the window continues to scroll until the
  416. # mouse moves back into the window or the mouse button is released.
  417. #
  418. # Arguments:
  419. # w - The entry window.
  420. proc ::tk::EntryAutoScan {w} {
  421. variable ::tk::Priv
  422. set x $Priv(x)
  423. if {![winfo exists $w]} {
  424. return
  425. }
  426. if {$x >= [winfo width $w]} {
  427. $w xview scroll 2 units
  428. EntryMouseSelect $w $x
  429. } elseif {$x < 0} {
  430. $w xview scroll -2 units
  431. EntryMouseSelect $w $x
  432. }
  433. set Priv(afterId) [after 50 [list tk::EntryAutoScan $w]]
  434. }
  435. # ::tk::EntryKeySelect --
  436. # This procedure is invoked when stroking out selections using the
  437. # keyboard. It moves the cursor to a new position, then extends
  438. # the selection to that position.
  439. #
  440. # Arguments:
  441. # w - The entry window.
  442. # new - A new position for the insertion cursor (the cursor hasn't
  443. # actually been moved to this position yet).
  444. proc ::tk::EntryKeySelect {w new} {
  445. if {![$w selection present]} {
  446. $w selection from insert
  447. $w selection to $new
  448. } else {
  449. $w selection adjust $new
  450. }
  451. $w icursor $new
  452. }
  453. # ::tk::EntryInsert --
  454. # Insert a string into an entry at the point of the insertion cursor.
  455. # If there is a selection in the entry, and it covers the point of the
  456. # insertion cursor, then delete the selection before inserting.
  457. #
  458. # Arguments:
  459. # w - The entry window in which to insert the string
  460. # s - The string to insert (usually just a single character)
  461. proc ::tk::EntryInsert {w s} {
  462. if {$s eq ""} {
  463. return
  464. }
  465. catch {
  466. set insert [$w index insert]
  467. if {([$w index sel.first] <= $insert)
  468. && ([$w index sel.last] >= $insert)} {
  469. $w delete sel.first sel.last
  470. }
  471. }
  472. $w insert insert $s
  473. EntrySeeInsert $w
  474. }
  475. # ::tk::EntryBackspace --
  476. # Backspace over the character just before the insertion cursor.
  477. # If backspacing would move the cursor off the left edge of the
  478. # window, reposition the cursor at about the middle of the window.
  479. #
  480. # Arguments:
  481. # w - The entry window in which to backspace.
  482. proc ::tk::EntryBackspace w {
  483. if {[$w selection present]} {
  484. $w delete sel.first sel.last
  485. } else {
  486. set x [$w index insert]
  487. if {$x > 0} {
  488. $w delete [expr {$x-1}]
  489. }
  490. if {[$w index @0] >= [$w index insert]} {
  491. set range [$w xview]
  492. set left [lindex $range 0]
  493. set right [lindex $range 1]
  494. $w xview moveto [expr {$left - ($right - $left)/2.0}]
  495. }
  496. }
  497. }
  498. # ::tk::EntrySeeInsert --
  499. # Make sure that the insertion cursor is visible in the entry window.
  500. # If not, adjust the view so that it is.
  501. #
  502. # Arguments:
  503. # w - The entry window.
  504. proc ::tk::EntrySeeInsert w {
  505. set c [$w index insert]
  506. if {($c < [$w index @0]) || ($c > [$w index @[winfo width $w]])} {
  507. $w xview $c
  508. }
  509. }
  510. # ::tk::EntrySetCursor -
  511. # Move the insertion cursor to a given position in an entry. Also
  512. # clears the selection, if there is one in the entry, and makes sure
  513. # that the insertion cursor is visible.
  514. #
  515. # Arguments:
  516. # w - The entry window.
  517. # pos - The desired new position for the cursor in the window.
  518. proc ::tk::EntrySetCursor {w pos} {
  519. $w icursor $pos
  520. $w selection clear
  521. EntrySeeInsert $w
  522. }
  523. # ::tk::EntryTranspose -
  524. # This procedure implements the "transpose" function for entry widgets.
  525. # It tranposes the characters on either side of the insertion cursor,
  526. # unless the cursor is at the end of the line. In this case it
  527. # transposes the two characters to the left of the cursor. In either
  528. # case, the cursor ends up to the right of the transposed characters.
  529. #
  530. # Arguments:
  531. # w - The entry window.
  532. proc ::tk::EntryTranspose w {
  533. set i [$w index insert]
  534. if {$i < [$w index end]} {
  535. incr i
  536. }
  537. if {$i < 2} {
  538. return
  539. }
  540. set first [expr {$i-2}]
  541. set data [$w get]
  542. set new [string index $data $i-1][string index $data $first]
  543. $w delete $first $i
  544. $w insert insert $new
  545. EntrySeeInsert $w
  546. }
  547. # ::tk::EntryNextWord --
  548. # Returns the index of the next word position after a given position in the
  549. # entry. The next word is platform dependent and may be either the next
  550. # end-of-word position or the next start-of-word position after the next
  551. # end-of-word position.
  552. #
  553. # Arguments:
  554. # w - The entry window in which the cursor is to move.
  555. # start - Position at which to start search.
  556. if {[tk windowingsystem] eq "win32"} {
  557. proc ::tk::EntryNextWord {w start} {
  558. set pos [tcl_endOfWord [$w get] [$w index $start]]
  559. if {$pos >= 0} {
  560. set pos [tcl_startOfNextWord [$w get] $pos]
  561. }
  562. if {$pos < 0} {
  563. return end
  564. }
  565. return $pos
  566. }
  567. } else {
  568. proc ::tk::EntryNextWord {w start} {
  569. set pos [tcl_endOfWord [$w get] [$w index $start]]
  570. if {$pos < 0} {
  571. return end
  572. }
  573. return $pos
  574. }
  575. }
  576. # ::tk::EntryPreviousWord --
  577. #
  578. # Returns the index of the previous word position before a given
  579. # position in the entry.
  580. #
  581. # Arguments:
  582. # w - The entry window in which the cursor is to move.
  583. # start - Position at which to start search.
  584. proc ::tk::EntryPreviousWord {w start} {
  585. set pos [tcl_startOfPreviousWord [$w get] [$w index $start]]
  586. if {$pos < 0} {
  587. return 0
  588. }
  589. return $pos
  590. }
  591. # ::tk::EntryScanMark --
  592. #
  593. # Marks the start of a possible scan drag operation
  594. #
  595. # Arguments:
  596. # w - The entry window from which the text to get
  597. # x - x location on screen
  598. proc ::tk::EntryScanMark {w x} {
  599. $w scan mark $x
  600. set ::tk::Priv(x) $x
  601. set ::tk::Priv(y) 0 ; # not used
  602. set ::tk::Priv(mouseMoved) 0
  603. }
  604. # ::tk::EntryScanDrag --
  605. #
  606. # Marks the start of a possible scan drag operation
  607. #
  608. # Arguments:
  609. # w - The entry window from which the text to get
  610. # x - x location on screen
  611. proc ::tk::EntryScanDrag {w x} {
  612. # Make sure these exist, as some weird situations can trigger the
  613. # motion binding without the initial press. [Bug #220269]
  614. if {![info exists ::tk::Priv(x)]} {set ::tk::Priv(x) $x}
  615. # allow for a delta
  616. if {abs($x-$::tk::Priv(x)) > 2} {
  617. set ::tk::Priv(mouseMoved) 1
  618. }
  619. $w scan dragto $x
  620. }
  621. # ::tk::EntryGetSelection --
  622. #
  623. # Returns the selected text of the entry with respect to the -show option.
  624. #
  625. # Arguments:
  626. # w - The entry window from which the text to get
  627. proc ::tk::EntryGetSelection {w} {
  628. set entryString [string range [$w get] [$w index sel.first] \
  629. [$w index sel.last]-1]
  630. if {[$w cget -show] ne ""} {
  631. return [string repeat [string index [$w cget -show] 0] \
  632. [string length $entryString]]
  633. }
  634. return $entryString
  635. }