entry.tcl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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. bind Entry <Mod4-Key> {# nothing}
  205. }
  206. # Tk-on-Cocoa generates characters for these two keys. [Bug 2971663]
  207. bind Entry <<NextLine>> {# nothing}
  208. bind Entry <<PrevLine>> {# nothing}
  209. # On Windows, paste is done using Shift-Insert. Shift-Insert already
  210. # generates the <<Paste>> event, so we don't need to do anything here.
  211. if {[tk windowingsystem] ne "win32"} {
  212. bind Entry <Insert> {
  213. catch {tk::EntryInsert %W [::tk::GetSelection %W PRIMARY]}
  214. }
  215. }
  216. # Additional emacs-like bindings:
  217. bind Entry <Control-d> {
  218. if {!$tk_strictMotif} {
  219. %W delete insert
  220. }
  221. }
  222. bind Entry <Control-h> {
  223. if {!$tk_strictMotif} {
  224. tk::EntryBackspace %W
  225. }
  226. }
  227. bind Entry <Control-k> {
  228. if {!$tk_strictMotif} {
  229. %W delete insert end
  230. }
  231. }
  232. bind Entry <Control-t> {
  233. if {!$tk_strictMotif} {
  234. tk::EntryTranspose %W
  235. }
  236. }
  237. bind Entry <Meta-b> {
  238. if {!$tk_strictMotif} {
  239. tk::EntrySetCursor %W [tk::EntryPreviousWord %W insert]
  240. }
  241. }
  242. bind Entry <Meta-d> {
  243. if {!$tk_strictMotif} {
  244. %W delete insert [tk::EntryNextWord %W insert]
  245. }
  246. }
  247. bind Entry <Meta-f> {
  248. if {!$tk_strictMotif} {
  249. tk::EntrySetCursor %W [tk::EntryNextWord %W insert]
  250. }
  251. }
  252. bind Entry <Meta-BackSpace> {
  253. if {!$tk_strictMotif} {
  254. %W delete [tk::EntryPreviousWord %W insert] insert
  255. }
  256. }
  257. bind Entry <Meta-Delete> {
  258. if {!$tk_strictMotif} {
  259. %W delete [tk::EntryPreviousWord %W insert] insert
  260. }
  261. }
  262. # Bindings for IME text input and accents.
  263. bind Entry <<TkStartIMEMarkedText>> {
  264. dict set ::tk::Priv(IMETextMark) "%W" [%W index insert]
  265. }
  266. bind Entry <<TkEndIMEMarkedText>> {
  267. if {[catch {dict get $::tk::Priv(IMETextMark) "%W"} mark]} {
  268. bell
  269. } else {
  270. %W selection range $mark insert
  271. }
  272. }
  273. bind Entry <<TkClearIMEMarkedText>> {
  274. %W delete [dict get $::tk::Priv(IMETextMark) "%W"] [%W index insert]
  275. }
  276. bind Entry <<TkAccentBackspace>> {
  277. tk::EntryBackspace %W
  278. }
  279. # A few additional bindings of my own.
  280. if {[tk windowingsystem] ne "aqua"} {
  281. bind Entry <Button-2> {
  282. if {!$tk_strictMotif} {
  283. ::tk::EntryScanMark %W %x
  284. }
  285. }
  286. bind Entry <B2-Motion> {
  287. if {!$tk_strictMotif} {
  288. ::tk::EntryScanDrag %W %x
  289. }
  290. }
  291. } else {
  292. bind Entry <Button-3> {
  293. if {!$tk_strictMotif} {
  294. ::tk::EntryScanMark %W %x
  295. }
  296. }
  297. bind Entry <B3-Motion> {
  298. if {!$tk_strictMotif} {
  299. ::tk::EntryScanDrag %W %x
  300. }
  301. }
  302. }
  303. # ::tk::EntryClosestGap --
  304. # Given x and y coordinates, this procedure finds the closest boundary
  305. # between characters to the given coordinates and returns the index
  306. # of the character just after the boundary.
  307. #
  308. # Arguments:
  309. # w - The entry window.
  310. # x - X-coordinate within the window.
  311. proc ::tk::EntryClosestGap {w x} {
  312. set pos [$w index @$x]
  313. set bbox [$w bbox $pos]
  314. if {($x - [lindex $bbox 0]) < ([lindex $bbox 2]/2)} {
  315. return $pos
  316. }
  317. incr pos
  318. }
  319. # ::tk::EntryButton1 --
  320. # This procedure is invoked to handle button-1 presses in entry
  321. # widgets. It moves the insertion cursor, sets the selection anchor,
  322. # and claims the input focus.
  323. #
  324. # Arguments:
  325. # w - The entry window in which the button was pressed.
  326. # x - The x-coordinate of the button press.
  327. proc ::tk::EntryButton1 {w x} {
  328. variable ::tk::Priv
  329. set Priv(selectMode) char
  330. set Priv(mouseMoved) 0
  331. set Priv(pressX) $x
  332. $w icursor [EntryClosestGap $w $x]
  333. $w selection from insert
  334. if {"disabled" ne [$w cget -state]} {
  335. focus $w
  336. }
  337. }
  338. # ::tk::EntryMouseSelect --
  339. # This procedure is invoked when dragging out a selection with
  340. # the mouse. Depending on the selection mode (character, word,
  341. # line) it selects in different-sized units. This procedure
  342. # ignores mouse motions initially until the mouse has moved from
  343. # one character to another or until there have been multiple clicks.
  344. #
  345. # Arguments:
  346. # w - The entry window in which the button was pressed.
  347. # x - The x-coordinate of the mouse.
  348. proc ::tk::EntryMouseSelect {w x} {
  349. variable ::tk::Priv
  350. set cur [EntryClosestGap $w $x]
  351. set anchor [$w index anchor]
  352. if {($cur != $anchor) || (abs($Priv(pressX) - $x) >= 3)} {
  353. set Priv(mouseMoved) 1
  354. }
  355. switch $Priv(selectMode) {
  356. char {
  357. if {$Priv(mouseMoved)} {
  358. if {$cur < $anchor} {
  359. $w selection range $cur $anchor
  360. } elseif {$cur > $anchor} {
  361. $w selection range $anchor $cur
  362. } else {
  363. $w selection clear
  364. }
  365. }
  366. }
  367. word {
  368. if {$cur < $anchor} {
  369. set before [tcl_wordBreakBefore [$w get] $cur]
  370. set after [tcl_wordBreakAfter [$w get] $anchor-1]
  371. } elseif {$cur > $anchor} {
  372. set before [tcl_wordBreakBefore [$w get] $anchor]
  373. set after [tcl_wordBreakAfter [$w get] $cur-1]
  374. } else {
  375. if {[$w index @$Priv(pressX)] < $anchor} {
  376. incr anchor -1
  377. }
  378. set before [tcl_wordBreakBefore [$w get] $anchor]
  379. set after [tcl_wordBreakAfter [$w get] $anchor]
  380. }
  381. if {$before < 0} {
  382. set before 0
  383. }
  384. if {$after < 0} {
  385. set after end
  386. }
  387. $w selection range $before $after
  388. }
  389. line {
  390. $w selection range 0 end
  391. }
  392. }
  393. if {$Priv(mouseMoved)} {
  394. $w icursor $cur
  395. }
  396. update idletasks
  397. }
  398. # ::tk::EntryPaste --
  399. # This procedure sets the insertion cursor to the current mouse position,
  400. # pastes the selection there, and sets the focus to the window.
  401. #
  402. # Arguments:
  403. # w - The entry window.
  404. # x - X position of the mouse.
  405. proc ::tk::EntryPaste {w x} {
  406. $w icursor [EntryClosestGap $w $x]
  407. catch {$w insert insert [::tk::GetSelection $w PRIMARY]}
  408. if {"disabled" ne [$w cget -state]} {
  409. focus $w
  410. }
  411. }
  412. # ::tk::EntryAutoScan --
  413. # This procedure is invoked when the mouse leaves an entry window
  414. # with button 1 down. It scrolls the window left or right,
  415. # depending on where the mouse is, and reschedules itself as an
  416. # "after" command so that the window continues to scroll until the
  417. # mouse moves back into the window or the mouse button is released.
  418. #
  419. # Arguments:
  420. # w - The entry window.
  421. proc ::tk::EntryAutoScan {w} {
  422. variable ::tk::Priv
  423. set x $Priv(x)
  424. if {![winfo exists $w]} {
  425. return
  426. }
  427. if {$x >= [winfo width $w]} {
  428. $w xview scroll 2 units
  429. EntryMouseSelect $w $x
  430. } elseif {$x < 0} {
  431. $w xview scroll -2 units
  432. EntryMouseSelect $w $x
  433. }
  434. set Priv(afterId) [after 50 [list tk::EntryAutoScan $w]]
  435. }
  436. # ::tk::EntryKeySelect --
  437. # This procedure is invoked when stroking out selections using the
  438. # keyboard. It moves the cursor to a new position, then extends
  439. # the selection to that position.
  440. #
  441. # Arguments:
  442. # w - The entry window.
  443. # new - A new position for the insertion cursor (the cursor hasn't
  444. # actually been moved to this position yet).
  445. proc ::tk::EntryKeySelect {w new} {
  446. if {![$w selection present]} {
  447. $w selection from insert
  448. $w selection to $new
  449. } else {
  450. $w selection adjust $new
  451. }
  452. $w icursor $new
  453. }
  454. # ::tk::EntryInsert --
  455. # Insert a string into an entry at the point of the insertion cursor.
  456. # If there is a selection in the entry, and it covers the point of the
  457. # insertion cursor, then delete the selection before inserting.
  458. #
  459. # Arguments:
  460. # w - The entry window in which to insert the string
  461. # s - The string to insert (usually just a single character)
  462. proc ::tk::EntryInsert {w s} {
  463. if {$s eq ""} {
  464. return
  465. }
  466. catch {
  467. set insert [$w index insert]
  468. if {([$w index sel.first] <= $insert)
  469. && ([$w index sel.last] >= $insert)} {
  470. $w delete sel.first sel.last
  471. }
  472. }
  473. $w insert insert $s
  474. EntrySeeInsert $w
  475. }
  476. # ::tk::EntryBackspace --
  477. # Backspace over the character just before the insertion cursor.
  478. # If backspacing would move the cursor off the left edge of the
  479. # window, reposition the cursor at about the middle of the window.
  480. #
  481. # Arguments:
  482. # w - The entry window in which to backspace.
  483. proc ::tk::EntryBackspace w {
  484. if {[$w selection present]} {
  485. $w delete sel.first sel.last
  486. } else {
  487. set x [$w index insert]
  488. if {$x > 0} {
  489. $w delete [expr {$x-1}]
  490. }
  491. if {[$w index @0] >= [$w index insert]} {
  492. set range [$w xview]
  493. set left [lindex $range 0]
  494. set right [lindex $range 1]
  495. $w xview moveto [expr {$left - ($right - $left)/2.0}]
  496. }
  497. }
  498. }
  499. # ::tk::EntrySeeInsert --
  500. # Make sure that the insertion cursor is visible in the entry window.
  501. # If not, adjust the view so that it is.
  502. #
  503. # Arguments:
  504. # w - The entry window.
  505. proc ::tk::EntrySeeInsert w {
  506. set c [$w index insert]
  507. if {($c < [$w index @0]) || ($c > [$w index @[winfo width $w]])} {
  508. $w xview $c
  509. }
  510. }
  511. # ::tk::EntrySetCursor -
  512. # Move the insertion cursor to a given position in an entry. Also
  513. # clears the selection, if there is one in the entry, and makes sure
  514. # that the insertion cursor is visible.
  515. #
  516. # Arguments:
  517. # w - The entry window.
  518. # pos - The desired new position for the cursor in the window.
  519. proc ::tk::EntrySetCursor {w pos} {
  520. $w icursor $pos
  521. $w selection clear
  522. EntrySeeInsert $w
  523. }
  524. # ::tk::EntryTranspose -
  525. # This procedure implements the "transpose" function for entry widgets.
  526. # It tranposes the characters on either side of the insertion cursor,
  527. # unless the cursor is at the end of the line. In this case it
  528. # transposes the two characters to the left of the cursor. In either
  529. # case, the cursor ends up to the right of the transposed characters.
  530. #
  531. # Arguments:
  532. # w - The entry window.
  533. proc ::tk::EntryTranspose w {
  534. set i [$w index insert]
  535. if {$i < [$w index end]} {
  536. incr i
  537. }
  538. if {$i < 2} {
  539. return
  540. }
  541. set first [expr {$i-2}]
  542. set data [$w get]
  543. set new [string index $data $i-1][string index $data $first]
  544. $w delete $first $i
  545. $w insert insert $new
  546. EntrySeeInsert $w
  547. }
  548. # ::tk::EntryNextWord --
  549. # Returns the index of the next word position after a given position in the
  550. # entry. The next word is platform dependent and may be either the next
  551. # end-of-word position or the next start-of-word position after the next
  552. # end-of-word position.
  553. #
  554. # Arguments:
  555. # w - The entry window in which the cursor is to move.
  556. # start - Position at which to start search.
  557. if {[tk windowingsystem] eq "win32"} {
  558. proc ::tk::EntryNextWord {w start} {
  559. # the check on [winfo class] is because the spinbox also uses this proc
  560. if {[winfo class $w] eq "Entry" && [$w cget -show] ne ""} {
  561. return end
  562. }
  563. set pos [tcl_endOfWord [$w get] [$w index $start]]
  564. if {$pos >= 0} {
  565. set pos [tcl_startOfNextWord [$w get] $pos]
  566. }
  567. if {$pos < 0} {
  568. return end
  569. }
  570. return $pos
  571. }
  572. } else {
  573. proc ::tk::EntryNextWord {w start} {
  574. # the check on [winfo class] is because the spinbox also uses this proc
  575. if {[winfo class $w] eq "Entry" && [$w cget -show] ne ""} {
  576. return end
  577. }
  578. set pos [tcl_endOfWord [$w get] [$w index $start]]
  579. if {$pos < 0} {
  580. return end
  581. }
  582. return $pos
  583. }
  584. }
  585. # ::tk::EntryPreviousWord --
  586. #
  587. # Returns the index of the previous word position before a given
  588. # position in the entry.
  589. #
  590. # Arguments:
  591. # w - The entry window in which the cursor is to move.
  592. # start - Position at which to start search.
  593. proc ::tk::EntryPreviousWord {w start} {
  594. # the check on [winfo class] is because the spinbox also uses this proc
  595. if {[winfo class $w] eq "Entry" && [$w cget -show] ne ""} {
  596. return 0
  597. }
  598. set pos [tcl_startOfPreviousWord [$w get] [$w index $start]]
  599. if {$pos < 0} {
  600. return 0
  601. }
  602. return $pos
  603. }
  604. # ::tk::EntryScanMark --
  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::EntryScanMark {w x} {
  612. $w scan mark $x
  613. set ::tk::Priv(x) $x
  614. set ::tk::Priv(y) 0 ; # not used
  615. set ::tk::Priv(mouseMoved) 0
  616. }
  617. # ::tk::EntryScanDrag --
  618. #
  619. # Marks the start of a possible scan drag operation
  620. #
  621. # Arguments:
  622. # w - The entry window from which the text to get
  623. # x - x location on screen
  624. proc ::tk::EntryScanDrag {w x} {
  625. # Make sure these exist, as some weird situations can trigger the
  626. # motion binding without the initial press. [Bug #220269]
  627. if {![info exists ::tk::Priv(x)]} {set ::tk::Priv(x) $x}
  628. # allow for a delta
  629. if {abs($x-$::tk::Priv(x)) > 2} {
  630. set ::tk::Priv(mouseMoved) 1
  631. }
  632. $w scan dragto $x
  633. }
  634. # ::tk::EntryGetSelection --
  635. #
  636. # Returns the selected text of the entry with respect to the -show option.
  637. #
  638. # Arguments:
  639. # w - The entry window from which the text to get
  640. proc ::tk::EntryGetSelection {w} {
  641. set entryString [string range [$w get] [$w index sel.first] \
  642. [$w index sel.last]-1]
  643. if {[$w cget -show] ne ""} {
  644. return [string repeat [string index [$w cget -show] 0] \
  645. [string length $entryString]]
  646. }
  647. return $entryString
  648. }