NoteBook.tcl 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: NoteBook.tcl,v 1.7 2004/03/28 02:44:57 hobbs Exp $
  4. #
  5. # NoteBook.tcl --
  6. #
  7. # tixNoteBook: NoteBook type of window.
  8. #
  9. # Copyright (c) 1993-1999 Ioi Kim Lam.
  10. # Copyright (c) 2000-2001 Tix Project Group.
  11. # Copyright (c) 2004 ActiveState
  12. #
  13. # See the file "license.terms" for information on usage and redistribution
  14. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  15. #
  16. tixWidgetClass tixNoteBook {
  17. -classname TixNoteBook
  18. -superclass tixVStack
  19. -method {
  20. }
  21. -flag {
  22. }
  23. -configspec {
  24. {-takefocus takeFocus TakeFocus 0 tixVerifyBoolean}
  25. }
  26. -default {
  27. {.nbframe.tabPadX 8}
  28. {.nbframe.tabPadY 5}
  29. {.nbframe.borderWidth 2}
  30. {*nbframe.relief raised}
  31. }
  32. }
  33. proc tixNoteBook:InitWidgetRec {w} {
  34. upvar #0 $w data
  35. tixChainMethod $w InitWidgetRec
  36. set data(pad-x1) 0
  37. set data(pad-x2) 0
  38. set data(pad-y1) 20
  39. set data(pad-y2) 0
  40. }
  41. proc tixNoteBook:ConstructWidget {w} {
  42. upvar #0 $w data
  43. tixChainMethod $w ConstructWidget
  44. set data(w:top) [tixNoteBookFrame $w.nbframe -slave 1 -takefocus 1]
  45. set data(w:nbframe) $data(w:top)
  46. bind $data(w:top) <ButtonPress-1> [list tixNoteBook:MouseDown $w %x %y]
  47. bind $data(w:top) <ButtonRelease-1> [list tixNoteBook:MouseUp $w %x %y]
  48. bind $data(w:top) <B1-Motion> [list tixNoteBook:MouseDown $w %x %y]
  49. bind $data(w:top) <Left> [list tixNoteBook:FocusNext $w prev]
  50. bind $data(w:top) <Right> [list tixNoteBook:FocusNext $w next]
  51. bind $data(w:top) <Return> [list tixNoteBook:SetFocusByKey $w]
  52. bind $data(w:top) <space> [list tixNoteBook:SetFocusByKey $w]
  53. }
  54. #----------------------------------------------------------------------
  55. # Public methods
  56. #----------------------------------------------------------------------
  57. proc tixNoteBook:add {w child args} {
  58. upvar #0 $w data
  59. set ret [eval tixChainMethod $w add $child $args]
  60. set new_args ""
  61. foreach {flag value} $args {
  62. if {$flag ne "-createcmd" && $flag ne "-raisecmd"} {
  63. lappend new_args $flag
  64. lappend new_args $value
  65. }
  66. }
  67. eval [linsert $new_args 0 $data(w:top) add $child]
  68. return $ret
  69. }
  70. proc tixNoteBook:raise {w child} {
  71. upvar #0 $w data
  72. tixChainMethod $w raise $child
  73. if {[$data(w:top) pagecget $child -state] eq "normal"} {
  74. $data(w:top) activate $child
  75. }
  76. }
  77. proc tixNoteBook:delete {w child} {
  78. upvar #0 $w data
  79. tixChainMethod $w delete $child
  80. $data(w:top) delete $child
  81. }
  82. #----------------------------------------------------------------------
  83. # Private methods
  84. #----------------------------------------------------------------------
  85. proc tixNoteBook:Resize {w} {
  86. upvar #0 $w data
  87. # We have to take care of the size of the tabs so that
  88. #
  89. set rootReq [$data(w:top) geometryinfo]
  90. set tW [lindex $rootReq 0]
  91. set tH [lindex $rootReq 1]
  92. set data(pad-x1) 2
  93. set data(pad-x2) 2
  94. set data(pad-y1) [expr {$tH + $data(-ipadx) + 1}]
  95. set data(pad-y2) 2
  96. set data(minW) [expr {$tW}]
  97. set data(minH) [expr {$tH}]
  98. # Now that we know data(pad-y1), we can chain the call
  99. #
  100. tixChainMethod $w Resize
  101. }
  102. proc tixNoteBook:MouseDown {w x y} {
  103. upvar #0 $w data
  104. focus $data(w:top)
  105. set name [$data(w:top) identify $x $y]
  106. $data(w:top) focus $name
  107. set data(w:down) $name
  108. }
  109. proc tixNoteBook:MouseUp {w x y} {
  110. upvar #0 $w data
  111. #it could happen (using the tk/menu) that a MouseUp
  112. #proceeds without a MouseDown event!!
  113. if {![info exists data(w:down)] || ![info exists data(w:top)]} {
  114. return
  115. }
  116. set name [$data(w:top) identify $x $y]
  117. if {$name ne "" && $name eq $data(w:down)
  118. && [$data(w:top) pagecget $name -state] eq "normal"} {
  119. $data(w:top) activate $name
  120. tixCallMethod $w raise $name
  121. } else {
  122. $data(w:top) focus ""
  123. }
  124. }
  125. #----------------------------------------------------------------------
  126. #
  127. # Section for keyboard bindings
  128. #
  129. #----------------------------------------------------------------------
  130. proc tixNoteBook:FocusNext {w dir} {
  131. upvar #0 $w data
  132. if {[$data(w:top) info focus] == ""} {
  133. set name [$data(w:top) info active]
  134. $data(w:top) focus $name
  135. if {$name ne ""} {
  136. return
  137. }
  138. } else {
  139. set name [$data(w:top) info focus$dir]
  140. $data(w:top) focus $name
  141. }
  142. }
  143. proc tixNoteBook:SetFocusByKey {w} {
  144. upvar #0 $w data
  145. set name [$data(w:top) info focus]
  146. if {$name ne "" && [$data(w:top) pagecget $name -state] eq "normal"} {
  147. tixCallMethod $w raise $name
  148. $data(w:top) activate $name
  149. }
  150. }
  151. #----------------------------------------------------------------------
  152. # Automatic bindings for alt keys
  153. #----------------------------------------------------------------------
  154. proc tixNoteBookFind {w char} {
  155. set char [string tolower $char]
  156. foreach child [winfo child $w] {
  157. if {![winfo ismapped $w]} {
  158. continue
  159. }
  160. switch -exact -- [winfo class $child] {
  161. Toplevel { continue }
  162. TixNoteBook {
  163. set nbframe [$child subwidget nbframe]
  164. foreach page [$nbframe info pages] {
  165. set char2 [string index [$nbframe pagecget $page -label] \
  166. [$nbframe pagecget $page -underline]]
  167. if {($char eq [string tolower $char2] || $char eq "")
  168. && [$nbframe pagecget $page -state] ne "disabled"} {
  169. return [list $child $page]
  170. }
  171. }
  172. }
  173. }
  174. # Well, this notebook doesn't match with the key, but maybe
  175. # it contains a "subnotebook" that will match ..
  176. set match [tixNoteBookFind $child $char]
  177. if {$match ne ""} {
  178. return $match
  179. }
  180. }
  181. return ""
  182. }
  183. proc tixTraverseToNoteBook {w char} {
  184. if {$char eq ""} {
  185. return 0
  186. }
  187. if {![winfo exists $w]} {
  188. return 0
  189. }
  190. set list [tixNoteBookFind [winfo toplevel $w] $char]
  191. if {$list ne ""} {
  192. [lindex $list 0] raise [lindex $list 1]
  193. return 1
  194. }
  195. return 0
  196. }
  197. #----------------------------------------------------------------------
  198. # Set default class bindings
  199. #----------------------------------------------------------------------
  200. bind all <Alt-KeyPress> "+tixTraverseToNoteBook %W %A"
  201. bind all <Meta-KeyPress> "+tixTraverseToNoteBook %W %A"