button.tcl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. # button.tcl --
  2. #
  3. # This file defines the default bindings for Tk label, button,
  4. # checkbutton, and radiobutton widgets and provides procedures
  5. # that help in implementing those bindings.
  6. #
  7. # Copyright (c) 1992-1994 The Regents of the University of California.
  8. # Copyright (c) 1994-1996 Sun Microsystems, Inc.
  9. # Copyright (c) 2002 ActiveState Corporation.
  10. #
  11. # See the file "license.terms" for information on usage and redistribution
  12. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  13. #
  14. #-------------------------------------------------------------------------
  15. # The code below creates the default class bindings for buttons.
  16. #-------------------------------------------------------------------------
  17. if {[tk windowingsystem] eq "aqua"} {
  18. bind Radiobutton <Enter> {
  19. tk::ButtonEnter %W
  20. }
  21. bind Radiobutton <1> {
  22. tk::ButtonDown %W
  23. }
  24. bind Radiobutton <ButtonRelease-1> {
  25. tk::ButtonUp %W
  26. }
  27. bind Checkbutton <Enter> {
  28. tk::ButtonEnter %W
  29. }
  30. bind Checkbutton <1> {
  31. tk::ButtonDown %W
  32. }
  33. bind Checkbutton <ButtonRelease-1> {
  34. tk::ButtonUp %W
  35. }
  36. bind Checkbutton <Leave> {
  37. tk::ButtonLeave %W
  38. }
  39. }
  40. if {"win32" eq [tk windowingsystem]} {
  41. bind Checkbutton <equal> {
  42. tk::CheckRadioInvoke %W select
  43. }
  44. bind Checkbutton <plus> {
  45. tk::CheckRadioInvoke %W select
  46. }
  47. bind Checkbutton <minus> {
  48. tk::CheckRadioInvoke %W deselect
  49. }
  50. bind Checkbutton <1> {
  51. tk::CheckRadioDown %W
  52. }
  53. bind Checkbutton <ButtonRelease-1> {
  54. tk::ButtonUp %W
  55. }
  56. bind Checkbutton <Enter> {
  57. tk::CheckRadioEnter %W
  58. }
  59. bind Checkbutton <Leave> {
  60. tk::ButtonLeave %W
  61. }
  62. bind Radiobutton <1> {
  63. tk::CheckRadioDown %W
  64. }
  65. bind Radiobutton <ButtonRelease-1> {
  66. tk::ButtonUp %W
  67. }
  68. bind Radiobutton <Enter> {
  69. tk::CheckRadioEnter %W
  70. }
  71. }
  72. if {"x11" eq [tk windowingsystem]} {
  73. bind Checkbutton <Return> {
  74. if {!$tk_strictMotif} {
  75. tk::CheckInvoke %W
  76. }
  77. }
  78. bind Radiobutton <Return> {
  79. if {!$tk_strictMotif} {
  80. tk::CheckRadioInvoke %W
  81. }
  82. }
  83. bind Checkbutton <1> {
  84. tk::CheckInvoke %W
  85. }
  86. bind Radiobutton <1> {
  87. tk::CheckRadioInvoke %W
  88. }
  89. bind Checkbutton <Enter> {
  90. tk::CheckEnter %W
  91. }
  92. bind Radiobutton <Enter> {
  93. tk::ButtonEnter %W
  94. }
  95. bind Checkbutton <Leave> {
  96. tk::CheckLeave %W
  97. }
  98. }
  99. bind Button <space> {
  100. tk::ButtonInvoke %W
  101. }
  102. bind Checkbutton <space> {
  103. tk::CheckRadioInvoke %W
  104. }
  105. bind Radiobutton <space> {
  106. tk::CheckRadioInvoke %W
  107. }
  108. bind Button <<Invoke>> {
  109. tk::ButtonInvoke %W
  110. }
  111. bind Checkbutton <<Invoke>> {
  112. tk::CheckRadioInvoke %W
  113. }
  114. bind Radiobutton <<Invoke>> {
  115. tk::CheckRadioInvoke %W
  116. }
  117. bind Button <FocusIn> {}
  118. bind Button <Enter> {
  119. tk::ButtonEnter %W
  120. }
  121. bind Button <Leave> {
  122. tk::ButtonLeave %W
  123. }
  124. bind Button <1> {
  125. tk::ButtonDown %W
  126. }
  127. bind Button <ButtonRelease-1> {
  128. tk::ButtonUp %W
  129. }
  130. bind Checkbutton <FocusIn> {}
  131. bind Radiobutton <FocusIn> {}
  132. bind Radiobutton <Leave> {
  133. tk::ButtonLeave %W
  134. }
  135. if {"win32" eq [tk windowingsystem]} {
  136. #########################
  137. # Windows implementation
  138. #########################
  139. # ::tk::ButtonEnter --
  140. # The procedure below is invoked when the mouse pointer enters a
  141. # button widget. It records the button we're in and changes the
  142. # state of the button to active unless the button is disabled.
  143. #
  144. # Arguments:
  145. # w - The name of the widget.
  146. proc ::tk::ButtonEnter w {
  147. variable ::tk::Priv
  148. if {[$w cget -state] ne "disabled"} {
  149. # If the mouse button is down, set the relief to sunken on entry.
  150. # Overwise, if there's an -overrelief value, set the relief to that.
  151. set Priv($w,relief) [$w cget -relief]
  152. if {$Priv(buttonWindow) eq $w} {
  153. $w configure -relief sunken -state active
  154. set Priv($w,prelief) sunken
  155. } elseif {[set over [$w cget -overrelief]] ne ""} {
  156. $w configure -relief $over
  157. set Priv($w,prelief) $over
  158. }
  159. }
  160. set Priv(window) $w
  161. }
  162. # ::tk::ButtonLeave --
  163. # The procedure below is invoked when the mouse pointer leaves a
  164. # button widget. It changes the state of the button back to inactive.
  165. # Restore any modified relief too.
  166. #
  167. # Arguments:
  168. # w - The name of the widget.
  169. proc ::tk::ButtonLeave w {
  170. variable ::tk::Priv
  171. if {[$w cget -state] ne "disabled"} {
  172. $w configure -state normal
  173. }
  174. # Restore the original button relief if it was changed by Tk.
  175. # That is signaled by the existence of Priv($w,prelief).
  176. if {[info exists Priv($w,relief)]} {
  177. if {[info exists Priv($w,prelief)] && \
  178. $Priv($w,prelief) eq [$w cget -relief]} {
  179. $w configure -relief $Priv($w,relief)
  180. }
  181. unset -nocomplain Priv($w,relief) Priv($w,prelief)
  182. }
  183. set Priv(window) ""
  184. }
  185. # ::tk::ButtonDown --
  186. # The procedure below is invoked when the mouse button is pressed in
  187. # a button widget. It records the fact that the mouse is in the button,
  188. # saves the button's relief so it can be restored later, and changes
  189. # the relief to sunken.
  190. #
  191. # Arguments:
  192. # w - The name of the widget.
  193. proc ::tk::ButtonDown w {
  194. variable ::tk::Priv
  195. # Only save the button's relief if it does not yet exist. If there
  196. # is an overrelief setting, Priv($w,relief) will already have been set,
  197. # and the current value of the -relief option will be incorrect.
  198. if {![info exists Priv($w,relief)]} {
  199. set Priv($w,relief) [$w cget -relief]
  200. }
  201. if {[$w cget -state] ne "disabled"} {
  202. set Priv(buttonWindow) $w
  203. $w configure -relief sunken -state active
  204. set Priv($w,prelief) sunken
  205. # If this button has a repeatdelay set up, get it going with an after
  206. after cancel $Priv(afterId)
  207. set delay [$w cget -repeatdelay]
  208. set Priv(repeated) 0
  209. if {$delay > 0} {
  210. set Priv(afterId) [after $delay [list tk::ButtonAutoInvoke $w]]
  211. }
  212. }
  213. }
  214. # ::tk::ButtonUp --
  215. # The procedure below is invoked when the mouse button is released
  216. # in a button widget. It restores the button's relief and invokes
  217. # the command as long as the mouse hasn't left the button.
  218. #
  219. # Arguments:
  220. # w - The name of the widget.
  221. proc ::tk::ButtonUp w {
  222. variable ::tk::Priv
  223. if {$Priv(buttonWindow) eq $w} {
  224. set Priv(buttonWindow) ""
  225. # Restore the button's relief if it was cached.
  226. if {[info exists Priv($w,relief)]} {
  227. if {[info exists Priv($w,prelief)] && \
  228. $Priv($w,prelief) eq [$w cget -relief]} {
  229. $w configure -relief $Priv($w,relief)
  230. }
  231. unset -nocomplain Priv($w,relief) Priv($w,prelief)
  232. }
  233. # Clean up the after event from the auto-repeater
  234. after cancel $Priv(afterId)
  235. if {$Priv(window) eq $w && [$w cget -state] ne "disabled"} {
  236. $w configure -state normal
  237. # Only invoke the command if it wasn't already invoked by the
  238. # auto-repeater functionality
  239. if { $Priv(repeated) == 0 } {
  240. uplevel #0 [list $w invoke]
  241. }
  242. }
  243. }
  244. }
  245. # ::tk::CheckRadioEnter --
  246. # The procedure below is invoked when the mouse pointer enters a
  247. # checkbutton or radiobutton widget. It records the button we're in
  248. # and changes the state of the button to active unless the button is
  249. # disabled.
  250. #
  251. # Arguments:
  252. # w - The name of the widget.
  253. proc ::tk::CheckRadioEnter w {
  254. variable ::tk::Priv
  255. if {[$w cget -state] ne "disabled"} {
  256. if {$Priv(buttonWindow) eq $w} {
  257. $w configure -state active
  258. }
  259. if {[set over [$w cget -overrelief]] ne ""} {
  260. set Priv($w,relief) [$w cget -relief]
  261. set Priv($w,prelief) $over
  262. $w configure -relief $over
  263. }
  264. }
  265. set Priv(window) $w
  266. }
  267. # ::tk::CheckRadioDown --
  268. # The procedure below is invoked when the mouse button is pressed in
  269. # a button widget. It records the fact that the mouse is in the button,
  270. # saves the button's relief so it can be restored later, and changes
  271. # the relief to sunken.
  272. #
  273. # Arguments:
  274. # w - The name of the widget.
  275. proc ::tk::CheckRadioDown w {
  276. variable ::tk::Priv
  277. if {![info exists Priv($w,relief)]} {
  278. set Priv($w,relief) [$w cget -relief]
  279. }
  280. if {[$w cget -state] ne "disabled"} {
  281. set Priv(buttonWindow) $w
  282. set Priv(repeated) 0
  283. $w configure -state active
  284. }
  285. }
  286. }
  287. if {"x11" eq [tk windowingsystem]} {
  288. #####################
  289. # Unix implementation
  290. #####################
  291. # ::tk::ButtonEnter --
  292. # The procedure below is invoked when the mouse pointer enters a
  293. # button widget. It records the button we're in and changes the
  294. # state of the button to active unless the button is disabled.
  295. #
  296. # Arguments:
  297. # w - The name of the widget.
  298. proc ::tk::ButtonEnter {w} {
  299. variable ::tk::Priv
  300. if {[$w cget -state] ne "disabled"} {
  301. # On unix the state is active just with mouse-over
  302. $w configure -state active
  303. # If the mouse button is down, set the relief to sunken on entry.
  304. # Overwise, if there's an -overrelief value, set the relief to that.
  305. set Priv($w,relief) [$w cget -relief]
  306. if {$Priv(buttonWindow) eq $w} {
  307. $w configure -relief sunken
  308. set Priv($w,prelief) sunken
  309. } elseif {[set over [$w cget -overrelief]] ne ""} {
  310. $w configure -relief $over
  311. set Priv($w,prelief) $over
  312. }
  313. }
  314. set Priv(window) $w
  315. }
  316. # ::tk::ButtonLeave --
  317. # The procedure below is invoked when the mouse pointer leaves a
  318. # button widget. It changes the state of the button back to inactive.
  319. # Restore any modified relief too.
  320. #
  321. # Arguments:
  322. # w - The name of the widget.
  323. proc ::tk::ButtonLeave w {
  324. variable ::tk::Priv
  325. if {[$w cget -state] ne "disabled"} {
  326. $w configure -state normal
  327. }
  328. # Restore the original button relief if it was changed by Tk.
  329. # That is signaled by the existence of Priv($w,prelief).
  330. if {[info exists Priv($w,relief)]} {
  331. if {[info exists Priv($w,prelief)] && \
  332. $Priv($w,prelief) eq [$w cget -relief]} {
  333. $w configure -relief $Priv($w,relief)
  334. }
  335. unset -nocomplain Priv($w,relief) Priv($w,prelief)
  336. }
  337. set Priv(window) ""
  338. }
  339. # ::tk::ButtonDown --
  340. # The procedure below is invoked when the mouse button is pressed in
  341. # a button widget. It records the fact that the mouse is in the button,
  342. # saves the button's relief so it can be restored later, and changes
  343. # the relief to sunken.
  344. #
  345. # Arguments:
  346. # w - The name of the widget.
  347. proc ::tk::ButtonDown w {
  348. variable ::tk::Priv
  349. # Only save the button's relief if it does not yet exist. If there
  350. # is an overrelief setting, Priv($w,relief) will already have been set,
  351. # and the current value of the -relief option will be incorrect.
  352. if {![info exists Priv($w,relief)]} {
  353. set Priv($w,relief) [$w cget -relief]
  354. }
  355. if {[$w cget -state] ne "disabled"} {
  356. set Priv(buttonWindow) $w
  357. $w configure -relief sunken
  358. set Priv($w,prelief) sunken
  359. # If this button has a repeatdelay set up, get it going with an after
  360. after cancel $Priv(afterId)
  361. set delay [$w cget -repeatdelay]
  362. set Priv(repeated) 0
  363. if {$delay > 0} {
  364. set Priv(afterId) [after $delay [list tk::ButtonAutoInvoke $w]]
  365. }
  366. }
  367. }
  368. # ::tk::ButtonUp --
  369. # The procedure below is invoked when the mouse button is released
  370. # in a button widget. It restores the button's relief and invokes
  371. # the command as long as the mouse hasn't left the button.
  372. #
  373. # Arguments:
  374. # w - The name of the widget.
  375. proc ::tk::ButtonUp w {
  376. variable ::tk::Priv
  377. if {$w eq $Priv(buttonWindow)} {
  378. set Priv(buttonWindow) ""
  379. # Restore the button's relief if it was cached.
  380. if {[info exists Priv($w,relief)]} {
  381. if {[info exists Priv($w,prelief)] && \
  382. $Priv($w,prelief) eq [$w cget -relief]} {
  383. $w configure -relief $Priv($w,relief)
  384. }
  385. unset -nocomplain Priv($w,relief) Priv($w,prelief)
  386. }
  387. # Clean up the after event from the auto-repeater
  388. after cancel $Priv(afterId)
  389. if {$Priv(window) eq $w && [$w cget -state] ne "disabled"} {
  390. # Only invoke the command if it wasn't already invoked by the
  391. # auto-repeater functionality
  392. if { $Priv(repeated) == 0 } {
  393. uplevel #0 [list $w invoke]
  394. }
  395. }
  396. }
  397. }
  398. }
  399. if {[tk windowingsystem] eq "aqua"} {
  400. ####################
  401. # Mac implementation
  402. ####################
  403. # ::tk::ButtonEnter --
  404. # The procedure below is invoked when the mouse pointer enters a
  405. # button widget. It records the button we're in and changes the
  406. # state of the button to active unless the button is disabled.
  407. #
  408. # Arguments:
  409. # w - The name of the widget.
  410. proc ::tk::ButtonEnter {w} {
  411. variable ::tk::Priv
  412. if {[$w cget -state] ne "disabled"} {
  413. # If there's an -overrelief value, set the relief to that.
  414. if {$Priv(buttonWindow) eq $w} {
  415. $w configure -state active
  416. } elseif {[set over [$w cget -overrelief]] ne ""} {
  417. set Priv($w,relief) [$w cget -relief]
  418. set Priv($w,prelief) $over
  419. $w configure -relief $over
  420. }
  421. }
  422. set Priv(window) $w
  423. }
  424. # ::tk::ButtonLeave --
  425. # The procedure below is invoked when the mouse pointer leaves a
  426. # button widget. It changes the state of the button back to
  427. # inactive. If we're leaving the button window with a mouse button
  428. # pressed (Priv(buttonWindow) == $w), restore the relief of the
  429. # button too.
  430. #
  431. # Arguments:
  432. # w - The name of the widget.
  433. proc ::tk::ButtonLeave w {
  434. variable ::tk::Priv
  435. if {$w eq $Priv(buttonWindow)} {
  436. $w configure -state normal
  437. }
  438. # Restore the original button relief if it was changed by Tk.
  439. # That is signaled by the existence of Priv($w,prelief).
  440. if {[info exists Priv($w,relief)]} {
  441. if {[info exists Priv($w,prelief)] && \
  442. $Priv($w,prelief) eq [$w cget -relief]} {
  443. $w configure -relief $Priv($w,relief)
  444. }
  445. unset -nocomplain Priv($w,relief) Priv($w,prelief)
  446. }
  447. set Priv(window) ""
  448. }
  449. # ::tk::ButtonDown --
  450. # The procedure below is invoked when the mouse button is pressed in
  451. # a button widget. It records the fact that the mouse is in the button,
  452. # saves the button's relief so it can be restored later, and changes
  453. # the relief to sunken.
  454. #
  455. # Arguments:
  456. # w - The name of the widget.
  457. proc ::tk::ButtonDown w {
  458. variable ::tk::Priv
  459. if {[$w cget -state] ne "disabled"} {
  460. set Priv(buttonWindow) $w
  461. $w configure -state active
  462. # If this button has a repeatdelay set up, get it going with an after
  463. after cancel $Priv(afterId)
  464. set Priv(repeated) 0
  465. if { ![catch {$w cget -repeatdelay} delay] } {
  466. if {$delay > 0} {
  467. set Priv(afterId) [after $delay [list tk::ButtonAutoInvoke $w]]
  468. }
  469. }
  470. }
  471. }
  472. # ::tk::ButtonUp --
  473. # The procedure below is invoked when the mouse button is released
  474. # in a button widget. It restores the button's relief and invokes
  475. # the command as long as the mouse hasn't left the button.
  476. #
  477. # Arguments:
  478. # w - The name of the widget.
  479. proc ::tk::ButtonUp w {
  480. variable ::tk::Priv
  481. if {$Priv(buttonWindow) eq $w} {
  482. set Priv(buttonWindow) ""
  483. $w configure -state normal
  484. # Restore the button's relief if it was cached.
  485. if {[info exists Priv($w,relief)]} {
  486. if {[info exists Priv($w,prelief)] && \
  487. $Priv($w,prelief) eq [$w cget -relief]} {
  488. $w configure -relief $Priv($w,relief)
  489. }
  490. unset -nocomplain Priv($w,relief) Priv($w,prelief)
  491. }
  492. # Clean up the after event from the auto-repeater
  493. after cancel $Priv(afterId)
  494. if {$Priv(window) eq $w && [$w cget -state] ne "disabled"} {
  495. # Only invoke the command if it wasn't already invoked by the
  496. # auto-repeater functionality
  497. if { $Priv(repeated) == 0 } {
  498. uplevel #0 [list $w invoke]
  499. }
  500. }
  501. }
  502. }
  503. }
  504. ##################
  505. # Shared routines
  506. ##################
  507. # ::tk::ButtonInvoke --
  508. # The procedure below is called when a button is invoked through
  509. # the keyboard. It simulate a press of the button via the mouse.
  510. #
  511. # Arguments:
  512. # w - The name of the widget.
  513. proc ::tk::ButtonInvoke w {
  514. if {[winfo exists $w] && [$w cget -state] ne "disabled"} {
  515. set oldRelief [$w cget -relief]
  516. set oldState [$w cget -state]
  517. $w configure -state active -relief sunken
  518. after 100 [list ::tk::ButtonInvokeEnd $w $oldState $oldRelief]
  519. }
  520. }
  521. # ::tk::ButtonInvokeEnd --
  522. # The procedure below is called after a button is invoked through
  523. # the keyboard. It simulate a release of the button via the mouse.
  524. #
  525. # Arguments:
  526. # w - The name of the widget.
  527. # oldState - Old state to be set back.
  528. # oldRelief - Old relief to be set back.
  529. proc ::tk::ButtonInvokeEnd {w oldState oldRelief} {
  530. if {[winfo exists $w]} {
  531. $w configure -state $oldState -relief $oldRelief
  532. uplevel #0 [list $w invoke]
  533. }
  534. }
  535. # ::tk::ButtonAutoInvoke --
  536. #
  537. # Invoke an auto-repeating button, and set it up to continue to repeat.
  538. #
  539. # Arguments:
  540. # w button to invoke.
  541. #
  542. # Results:
  543. # None.
  544. #
  545. # Side effects:
  546. # May create an after event to call ::tk::ButtonAutoInvoke.
  547. proc ::tk::ButtonAutoInvoke {w} {
  548. variable ::tk::Priv
  549. after cancel $Priv(afterId)
  550. set delay [$w cget -repeatinterval]
  551. if {$Priv(window) eq $w} {
  552. incr Priv(repeated)
  553. uplevel #0 [list $w invoke]
  554. }
  555. if {$delay > 0} {
  556. set Priv(afterId) [after $delay [list tk::ButtonAutoInvoke $w]]
  557. }
  558. }
  559. # ::tk::CheckRadioInvoke --
  560. # The procedure below is invoked when the mouse button is pressed in
  561. # a checkbutton or radiobutton widget, or when the widget is invoked
  562. # through the keyboard. It invokes the widget if it
  563. # isn't disabled.
  564. #
  565. # Arguments:
  566. # w - The name of the widget.
  567. # cmd - The subcommand to invoke (one of invoke, select, or deselect).
  568. proc ::tk::CheckRadioInvoke {w {cmd invoke}} {
  569. if {[$w cget -state] ne "disabled"} {
  570. uplevel #0 [list $w $cmd]
  571. }
  572. }
  573. # Special versions of the handlers for checkbuttons on Unix that do the magic
  574. # to make things work right when the checkbutton indicator is hidden;
  575. # radiobuttons don't need this complexity.
  576. # ::tk::CheckInvoke --
  577. # The procedure below invokes the checkbutton, like ButtonInvoke, but handles
  578. # what to do when the checkbutton indicator is missing. Only used on Unix.
  579. #
  580. # Arguments:
  581. # w - The name of the widget.
  582. proc ::tk::CheckInvoke {w} {
  583. variable ::tk::Priv
  584. if {[$w cget -state] ne "disabled"} {
  585. # Additional logic to switch the "selected" colors around if necessary
  586. # (when we're indicator-less).
  587. if {![$w cget -indicatoron] && [info exist Priv($w,selectcolor)]} {
  588. if {[$w cget -selectcolor] eq $Priv($w,aselectcolor)} {
  589. $w configure -selectcolor $Priv($w,selectcolor)
  590. } else {
  591. $w configure -selectcolor $Priv($w,aselectcolor)
  592. }
  593. }
  594. uplevel #0 [list $w invoke]
  595. }
  596. }
  597. # ::tk::CheckEnter --
  598. # The procedure below enters the checkbutton, like ButtonEnter, but handles
  599. # what to do when the checkbutton indicator is missing. Only used on Unix.
  600. #
  601. # Arguments:
  602. # w - The name of the widget.
  603. proc ::tk::CheckEnter {w} {
  604. variable ::tk::Priv
  605. if {[$w cget -state] ne "disabled"} {
  606. # On unix the state is active just with mouse-over
  607. $w configure -state active
  608. # If the mouse button is down, set the relief to sunken on entry.
  609. # Overwise, if there's an -overrelief value, set the relief to that.
  610. set Priv($w,relief) [$w cget -relief]
  611. if {$Priv(buttonWindow) eq $w} {
  612. $w configure -relief sunken
  613. set Priv($w,prelief) sunken
  614. } elseif {[set over [$w cget -overrelief]] ne ""} {
  615. $w configure -relief $over
  616. set Priv($w,prelief) $over
  617. }
  618. # Compute what the "selected and active" color should be.
  619. if {![$w cget -indicatoron] && [$w cget -selectcolor] ne ""} {
  620. set Priv($w,selectcolor) [$w cget -selectcolor]
  621. lassign [winfo rgb $w [$w cget -selectcolor]] r1 g1 b1
  622. lassign [winfo rgb $w [$w cget -activebackground]] r2 g2 b2
  623. set Priv($w,aselectcolor) \
  624. [format "#%04x%04x%04x" [expr {($r1+$r2)/2}] \
  625. [expr {($g1+$g2)/2}] [expr {($b1+$b2)/2}]]
  626. # use uplevel to work with other var resolvers
  627. if {[uplevel #0 [list set [$w cget -variable]]]
  628. eq [$w cget -onvalue]} {
  629. $w configure -selectcolor $Priv($w,aselectcolor)
  630. }
  631. }
  632. }
  633. set Priv(window) $w
  634. }
  635. # ::tk::CheckLeave --
  636. # The procedure below leaves the checkbutton, like ButtonLeave, but handles
  637. # what to do when the checkbutton indicator is missing. Only used on Unix.
  638. #
  639. # Arguments:
  640. # w - The name of the widget.
  641. proc ::tk::CheckLeave {w} {
  642. variable ::tk::Priv
  643. if {[$w cget -state] ne "disabled"} {
  644. $w configure -state normal
  645. }
  646. # Restore the original button "selected" color; assume that the user
  647. # wasn't monkeying around with things too much.
  648. if {![$w cget -indicatoron] && [info exist Priv($w,selectcolor)]} {
  649. $w configure -selectcolor $Priv($w,selectcolor)
  650. }
  651. unset -nocomplain Priv($w,selectcolor) Priv($w,aselectcolor)
  652. # Restore the original button relief if it was changed by Tk. That is
  653. # signaled by the existence of Priv($w,prelief).
  654. if {[info exists Priv($w,relief)]} {
  655. if {[info exists Priv($w,prelief)] && \
  656. $Priv($w,prelief) eq [$w cget -relief]} {
  657. $w configure -relief $Priv($w,relief)
  658. }
  659. unset -nocomplain Priv($w,relief) Priv($w,prelief)
  660. }
  661. set Priv(window) ""
  662. }
  663. return
  664. # Local Variables:
  665. # mode: tcl
  666. # fill-column: 78
  667. # End: