home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / lib / blt2.4 / tabnotebook.tcl < prev    next >
Encoding:
Text File  |  2009-12-04  |  10.2 KB  |  319 lines

  1. #
  2. # tabnotebook.tcl
  3. #
  4. # ----------------------------------------------------------------------
  5. # Bindings for the BLT tabnotebook widget
  6. # ----------------------------------------------------------------------
  7. #   AUTHOR:  George Howlett
  8. #            Bell Labs Innovations for Lucent Technologies
  9. #            gah@bell-labs.com
  10. #            http://www.tcltk.com/blt
  11. # ----------------------------------------------------------------------
  12. # Copyright (c) 1998  Lucent Technologies, Inc.
  13. # ======================================================================
  14. #
  15. # Permission to use, copy, modify, and distribute this software and its
  16. # documentation for any purpose and without fee is hereby granted,
  17. # provided that the above copyright notice appear in all copies and that
  18. # both that the copyright notice and warranty disclaimer appear in
  19. # supporting documentation, and that the names of Lucent Technologies
  20. # any of their entities not be used in advertising or publicity
  21. # pertaining to distribution of the software without specific, written
  22. # prior permission.
  23. #
  24. # Lucent Technologies disclaims all warranties with regard to this
  25. # software, including all implied warranties of merchantability and
  26. # fitness.  In no event shall Lucent be liable for any special, indirect
  27. # or consequential damages or any damages whatsoever resulting from loss
  28. # of use, data or profits, whether in an action of contract, negligence
  29. # or other tortuous action, arising out of or in connection with the use
  30. # or performance of this software.
  31. #
  32. # ======================================================================
  33.  
  34. #
  35. # Indicates whether to activate (highlight) tabs when the mouse passes
  36. # over them.  This is turned off during scan operations.
  37. #
  38. set bltTabnotebook(activate) yes
  39.  
  40. # ----------------------------------------------------------------------
  41. # ButtonPress assignments
  42. #
  43. #   <ButtonPress-2>    Starts scan mechanism (pushes the tabs)
  44. #   <B2-Motion>        Adjust scan
  45. #   <ButtonRelease-2>    Stops scan
  46. #
  47. # ----------------------------------------------------------------------
  48. bind Tabnotebook <B2-Motion> {
  49.     %W scan dragto %x %y
  50. }
  51.  
  52. bind Tabnotebook <ButtonPress-2> {
  53.     set bltTabnotebook(cursor) [%W cget -cursor]
  54.     set bltTabnotebook(activate) no
  55.     %W configure -cursor hand1
  56.     %W scan mark %x %y
  57. }
  58.  
  59. bind Tabnotebook <ButtonRelease-2> {
  60.     %W configure -cursor $bltTabnotebook(cursor)
  61.     set bltTabnotebook(activate) yes
  62.     %W activate @%x,%y
  63. }
  64.  
  65. # ----------------------------------------------------------------------
  66. # KeyPress assignments
  67. #
  68. #   <KeyPress-Up>    Moves focus to the tab immediately above the 
  69. #            current.
  70. #   <KeyPress-Down>    Moves focus to the tab immediately below the 
  71. #            current.
  72. #   <KeyPress-Left>    Moves focus to the tab immediately left of the 
  73. #            currently focused tab.
  74. #   <KeyPress-Right>    Moves focus to the tab immediately right of the 
  75. #            currently focused tab.
  76. #   <KeyPress-space>    Invokes the commands associated with the current
  77. #            tab.
  78. #   <KeyPress-Return>    Same as above.
  79. #   <KeyPress>        Go to next tab starting with the ASCII character.
  80. #
  81. # ----------------------------------------------------------------------
  82. bind Tabnotebook <KeyPress-Up> { blt::SelectTab %W "up" }
  83. bind Tabnotebook <KeyPress-Down> { blt::SelectTab %W "down" }
  84. bind Tabnotebook <KeyPress-Right> { blt::SelectTab %W "right" }
  85. bind Tabnotebook <KeyPress-Left> { blt::SelectTab %W "left" }
  86. bind Tabnotebook <KeyPress-space> { %W invoke focus }
  87. bind Tabnotebook <KeyPress-Return> { %W invoke focus }
  88.  
  89. bind Tabnotebook <KeyPress> {
  90.     if { [string match {[A-Za-z0-9]*} "%A"] } {
  91.     blt::FindMatchingTab %W %A
  92.     }
  93. }
  94.  
  95. # ----------------------------------------------------------------------
  96. #
  97. # FirstMatchingTab --
  98. #
  99. #    Find the first tab (from the tab that currently has focus) 
  100. #    starting with the same first letter as the tab.  It searches
  101. #    in order of the tab positions and wraps around. If no tab
  102. #    matches, it stops back at the current tab.
  103. #
  104. # Arguments:    
  105. #    widget        Tabnotebook widget.
  106. #    key        ASCII character of key pressed
  107. #
  108. # ----------------------------------------------------------------------
  109. proc blt::FindMatchingTab { widget key } {
  110.     set key [string tolower $key]
  111.     set itab [$widget index focus]
  112.     set numTabs [$widget size]
  113.     for { set i 0 } { $i < $numTabs } { incr i } {
  114.     if { [incr itab] >= $numTabs } {
  115.         set itab 0
  116.     }
  117.     set label [string tolower [$widget tab cget $itab -text]]
  118.     if { [string index $label 0] == $key } {
  119.         break
  120.     }
  121.     }
  122.     $widget focus $itab
  123.     $widget see focus
  124. }
  125.  
  126. # ----------------------------------------------------------------------
  127. #
  128. # SelectTab --
  129. #
  130. #    Invokes the command for the tab.  If the widget associated tab 
  131. #    is currently torn off, the tearoff is raised.
  132. #
  133. # Arguments:    
  134. #    widget        Tabnotebook widget.
  135. #    x y        Unused.
  136. #
  137. # ----------------------------------------------------------------------
  138. proc blt::SelectTab { widget tab } {
  139.     set index [$widget index $tab]
  140.     if { $index != "" } {
  141.     $widget select $index
  142.     $widget focus $index
  143.     $widget see $index
  144.     set w [$widget tab tearoff $index]
  145.     if { ($w != "") && ($w != "$widget") } {
  146.         raise [winfo toplevel $w]
  147.     }
  148.     $widget invoke $index
  149.     }
  150. }
  151.  
  152. # ----------------------------------------------------------------------
  153. #
  154. # DestroyTearoff --
  155. #
  156. #    Destroys the toplevel window and the container tearoff 
  157. #    window holding the embedded widget.  The widget is placed
  158. #    back inside the tab.
  159. #
  160. # Arguments:    
  161. #    widget        Tabnotebook widget.
  162. #    tab        Tab selected.
  163. #
  164. # ----------------------------------------------------------------------
  165. proc blt::DestroyTearoff { widget tab } {
  166.     set id [$widget id $tab]
  167.     set top "$widget.toplevel-$id"
  168.     if { [winfo exists $top] } {
  169.     wm withdraw $top
  170.     update
  171.     $widget tab tearoff $tab $widget
  172.     destroy $top
  173.     }
  174. }
  175.  
  176. # ----------------------------------------------------------------------
  177. #
  178. # CreateTearoff --
  179. #
  180. #    Creates a new toplevel window and moves the embedded widget
  181. #    into it.  The toplevel is placed just below the tab.  The
  182. #    DELETE WINDOW property is set so that if the toplevel window 
  183. #    is requested to be deleted by the window manager, the embedded
  184. #    widget is placed back inside of the tab.  Note also that 
  185. #    if the tabnotebook container is ever destroyed, the toplevel is
  186. #    also destroyed.  
  187. #
  188. # Arguments:    
  189. #    widget        Tabnotebook widget.
  190. #    tab        Tab selected.
  191. #    x y        The coordinates of the mouse pointer.
  192. #
  193. # ----------------------------------------------------------------------
  194. proc blt::CreateTearoff { widget tab rootX rootY } {
  195.  
  196.     # ------------------------------------------------------------------
  197.     # When reparenting the window contained in the tab, check if the
  198.     # window or any window in its hierarchy currently has focus.
  199.     # Since we're reparenting windows behind its back, Tk can
  200.     # mistakenly activate the keyboard focus when the mouse enters the
  201.     # old toplevel.  The simplest way to deal with this problem is to
  202.     # take the focus off the window and set it to the tabnotebook widget
  203.     # itself.
  204.     # ------------------------------------------------------------------
  205.  
  206.     set focus [focus]
  207.     set window [$widget tab cget $tab -window]
  208.     set index [$widget index $tab]
  209.     if { ($focus == $window) || ([string match  $window.* $focus]) } {
  210.     focus -force $widget
  211.     }
  212.     set id [$widget id $index]
  213.     set top "$widget.toplevel-$id"
  214.     toplevel $top
  215.     $widget tab tearoff $tab $top.container
  216.     table $top $top.container -fill both
  217.  
  218.     incr rootX 10 ; incr rootY 10
  219.     wm geometry $top +$rootX+$rootY
  220.  
  221.     set parent [winfo toplevel $widget]
  222.     wm title $top "[wm title $parent]: [$widget tab cget $index -text]"
  223.     wm transient $top $parent
  224.  
  225.     # If the user tries to delete the toplevel, put the window back
  226.     # into the tab folder.  
  227.  
  228.     wm protocol $top WM_DELETE_WINDOW [list blt::DestroyTearoff $widget $tab]
  229.  
  230.     # If the container is ever destroyed, automatically destroy the
  231.     # toplevel too.  
  232.  
  233.     bind $top.container <Destroy> [list destroy $top]
  234. }
  235.  
  236. # ----------------------------------------------------------------------
  237. #
  238. # ToggleTearoff --
  239. #
  240. #    Toggles the tab tearoff.  If the tab contains a embedded widget, 
  241. #    it is placed inside of a toplevel window.  If the widget has 
  242. #    already been torn off, the widget is replaced back in the tab.
  243. #
  244. # Arguments:    
  245. #    widget        tabnotebook widget.
  246. #    x y        The coordinates of the mouse pointer.
  247. #
  248. # ----------------------------------------------------------------------
  249. proc blt::ToggleTearoff { widget x y index } {
  250.     set tab [$widget index $index]
  251.     if { $tab == "" } {
  252.     return
  253.     }
  254.     $widget invoke $tab
  255.  
  256.     set container [$widget tab tearoff $index]
  257.     if { $container == "$widget" } {
  258.     blt::CreateTearoff $widget $tab $x $y
  259.     } elseif { $container != "" } {
  260.     blt::DestroyTearoff $widget $tab
  261.     }
  262. }
  263.  
  264. # ----------------------------------------------------------------------
  265. #
  266. # TabnotebookInit
  267. #
  268. #    Invoked from C whenever a new tabnotebook widget is created.
  269. #    Sets up the default bindings for the all tab entries.  
  270. #    These bindings are local to the widget, so they can't be 
  271. #    set through the usual widget class bind tags mechanism.
  272. #
  273. #    <Enter>        Activates the tab.
  274. #    <Leave>        Deactivates all tabs.
  275. #    <ButtonPress-1>    Selects the tab and invokes its command.
  276. #    <Control-ButtonPress-1>    
  277. #            Toggles the tab tearoff.  If the tab contains
  278. #            a embedded widget, it is placed inside of a
  279. #            toplevel window.  If the widget has already
  280. #            been torn off, the widget is replaced back
  281. #            in the tab.
  282. #
  283. # Arguments:    
  284. #    widget        tabnotebook widget
  285. #
  286. # ----------------------------------------------------------------------
  287. proc blt::TabnotebookInit { widget } {
  288.     $widget bind all <Enter> { 
  289.     if { $bltTabnotebook(activate) } {
  290.         %W activate current
  291.         }
  292.     }
  293.     $widget bind all <Leave> { 
  294.         %W activate "" 
  295.     }
  296.     $widget bind all <ButtonPress-1> { 
  297.     blt::SelectTab %W "current"
  298.     }
  299.     $widget bind all <Control-ButtonPress-1> { 
  300.     blt::ToggleTearoff %W %X %Y active
  301.     }
  302.     $widget configure -perforationcommand {
  303.     blt::ToggleTearoff %W $bltTabnotebook(x) $bltTabnotebook(y) select
  304.     }
  305.     $widget bind Perforation <Enter> { 
  306.     %W perforation activate on
  307.     }
  308.     $widget bind Perforation <Leave> { 
  309.     %W perforation activate off
  310.     }
  311.     $widget bind Perforation <ButtonPress-1> { 
  312.     set bltTabnotebook(x) %X
  313.     set bltTabnotebook(y) %Y
  314.     %W perforation invoke
  315.     }
  316. }
  317.