SGrid.tcl 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: SGrid.tcl,v 1.6 2002/01/24 09:13:58 idiscovery Exp $
  4. #
  5. # SGrid.tcl --
  6. #
  7. # This file implements Scrolled Grid widgets
  8. #
  9. # Copyright (c) 1993-1999 Ioi Kim Lam.
  10. # Copyright (c) 2000-2001 Tix Project Group.
  11. #
  12. # See the file "license.terms" for information on usage and redistribution
  13. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  14. #
  15. global tkPriv
  16. if {![llength [info globals tkPriv]]} {
  17. tk::unsupported::ExposePrivateVariable tkPriv
  18. }
  19. #--------------------------------------------------------------------------
  20. # tkPriv elements used in this file:
  21. #
  22. # x -
  23. # y -
  24. # X -
  25. # Y -
  26. #--------------------------------------------------------------------------
  27. #
  28. tixWidgetClass tixScrolledGrid {
  29. -classname TixScrolledGrid
  30. -superclass tixScrolledWidget
  31. -method {
  32. }
  33. -flag {
  34. }
  35. -configspec {
  36. }
  37. -default {
  38. {.scrollbar auto}
  39. {*grid.borderWidth 1}
  40. {*grid.Background #c3c3c3}
  41. {*grid.highlightBackground #d9d9d9}
  42. {*grid.relief sunken}
  43. {*grid.takeFocus 1}
  44. {*Scrollbar.takeFocus 0}
  45. }
  46. }
  47. proc tixScrolledGrid:ConstructWidget {w} {
  48. upvar #0 $w data
  49. tixChainMethod $w ConstructWidget
  50. set data(w:grid) [tixGrid $w.grid]
  51. set data(w:hsb) \
  52. [scrollbar $w.hsb -orient horizontal -takefocus 0]
  53. set data(w:vsb) \
  54. [scrollbar $w.vsb -orient vertical -takefocus 0]
  55. set data(pw:client) $data(w:grid)
  56. pack $data(w:grid) -expand yes -fill both -padx 0 -pady 0
  57. }
  58. proc tixScrolledGrid:SetBindings {w} {
  59. upvar #0 $w data
  60. tixChainMethod $w SetBindings
  61. $data(w:grid) config \
  62. -xscrollcommand "$data(w:hsb) set"\
  63. -yscrollcommand "$data(w:vsb) set"\
  64. -sizecmd [list tixScrolledWidget:Configure $w] \
  65. -formatcmd "tixCallMethod $w FormatCmd"
  66. $data(w:hsb) config -command "$data(w:grid) xview"
  67. $data(w:vsb) config -command "$data(w:grid) yview"
  68. bindtags $data(w:grid) \
  69. "$data(w:grid) TixSGrid TixGrid [winfo toplevel $data(w:grid)] all"
  70. tixSetMegaWidget $data(w:grid) $w
  71. }
  72. #----------------------------------------------------------------------
  73. # RAW event bindings
  74. #----------------------------------------------------------------------
  75. proc tixScrolledGridBind {} {
  76. tixBind TixScrolledGrid <ButtonPress-1> {
  77. tixScrolledGrid:Button-1 [tixGetMegaWidget %W] %x %y
  78. }
  79. tixBind TixScrolledGrid <Shift-ButtonPress-1> {
  80. tixScrolledGrid:Shift-Button-1 %W %x %y
  81. }
  82. tixBind TixScrolledGrid <Control-ButtonPress-1> {
  83. tixScrolledGrid:Control-Button-1 %W %x %y
  84. }
  85. tixBind TixScrolledGrid <ButtonRelease-1> {
  86. tixScrolledGrid:ButtonRelease-1 %W %x %y
  87. }
  88. tixBind TixScrolledGrid <Double-ButtonPress-1> {
  89. tixScrolledGrid:Double-1 %W %x %y
  90. }
  91. tixBind TixScrolledGrid <B1-Motion> {
  92. set tkPriv(x) %x
  93. set tkPriv(y) %y
  94. set tkPriv(X) %X
  95. set tkPriv(Y) %Y
  96. tixScrolledGrid:B1-Motion %W %x %y
  97. }
  98. tixBind TixScrolledGrid <Control-B1-Motion> {
  99. set tkPriv(x) %x
  100. set tkPriv(y) %y
  101. set tkPriv(X) %X
  102. set tkPriv(Y) %Y
  103. tixScrolledGrid:Control-B1-Motion %W %x %y
  104. }
  105. tixBind TixScrolledGrid <B1-Leave> {
  106. set tkPriv(x) %x
  107. set tkPriv(y) %y
  108. set tkPriv(X) %X
  109. set tkPriv(Y) %Y
  110. tixScrolledGrid:B1-Leave %W
  111. }
  112. tixBind TixScrolledGrid <B1-Enter> {
  113. tixScrolledGrid:B1-Enter %W %x %y
  114. }
  115. tixBind TixScrolledGrid <Control-B1-Leave> {
  116. set tkPriv(x) %x
  117. set tkPriv(y) %y
  118. set tkPriv(X) %X
  119. set tkPriv(Y) %Y
  120. tixScrolledGrid:Control-B1-Leave %W
  121. }
  122. tixBind TixScrolledGrid <Control-B1-Enter> {
  123. tixScrolledGrid:Control-B1-Enter %W %x %y
  124. }
  125. # Keyboard bindings
  126. #
  127. tixBind TixScrolledGrid <Up> {
  128. tixScrolledGrid:DirKey %W up
  129. }
  130. tixBind TixScrolledGrid <Down> {
  131. tixScrolledGrid:DirKey %W down
  132. }
  133. tixBind TixScrolledGrid <Left> {
  134. tixScrolledGrid:DirKey %W left
  135. }
  136. tixBind TixScrolledGrid <Right> {
  137. tixScrolledGrid:DirKey %W right
  138. }
  139. tixBind TixScrolledGrid <Prior> {
  140. %W yview scroll -1 pages
  141. }
  142. tixBind TixScrolledGrid <Next> {
  143. %W yview scroll 1 pages
  144. }
  145. tixBind TixScrolledGrid <Return> {
  146. tixScrolledGrid:Return %W
  147. }
  148. tixBind TixScrolledGrid <space> {
  149. tixScrolledGrid:Space %W
  150. }
  151. }
  152. #----------------------------------------------------------------------
  153. #
  154. #
  155. # Mouse bindings
  156. #
  157. #
  158. #----------------------------------------------------------------------
  159. proc tixScrolledGrid:Button-1 {w x y} {
  160. if {[$w cget -state] == "disabled"} {
  161. return
  162. }
  163. if {[$w cget -takefocus]} {
  164. focus $w
  165. }
  166. case [tixScrolled:GetState $w] {
  167. {0} {
  168. tixScrolledGrid:GoState s1 $w $x $y
  169. }
  170. {b0} {
  171. tixScrolledGrid:GoState b1 $w $x $y
  172. }
  173. {m0} {
  174. tixScrolledGrid:GoState m1 $w $x $y
  175. }
  176. {e0} {
  177. tixScrolledGrid:GoState e1 $w $x $y
  178. }
  179. }
  180. }
  181. #----------------------------------------------------------------------
  182. #
  183. # option configs
  184. #----------------------------------------------------------------------
  185. #----------------------------------------------------------------------
  186. #
  187. # Widget commands
  188. #----------------------------------------------------------------------
  189. #----------------------------------------------------------------------
  190. #
  191. # Private Methods
  192. #----------------------------------------------------------------------
  193. #----------------------------------------------------------------------
  194. # Virtual Methods
  195. #----------------------------------------------------------------------
  196. proc tixScrolledGrid:FormatCmd {w area x1 y1 x2 y2} {
  197. # do nothing
  198. }
  199. #----------------------------------------------------------------------
  200. # virtual functions to query the client window's scroll requirement
  201. #----------------------------------------------------------------------
  202. proc tixScrolledGrid:GeometryInfo {w mW mH} {
  203. upvar #0 $w data
  204. if {$mW < 1} {
  205. set mW 1
  206. }
  207. if {$mH < 1} {
  208. set mH 1
  209. }
  210. return [$data(w:grid) geometryinfo $mW $mH]
  211. }