home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Freeware 31 / FreelogHS31.iso / Texte / scribus / scribus-1.3.3.9-win32-install.exe / tcl / tix8.1 / PopMenu.tcl < prev    next >
Text File  |  2002-09-21  |  6KB  |  240 lines

  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. #    $Id: PopMenu.tcl,v 1.4.2.2 2002/09/21 08:02:11 idiscovery Exp $
  4. #
  5. # PopMenu.tcl --
  6. #
  7. #    This file implements the TixPopupMenu widget
  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.  
  16. global tkPriv
  17. if {![llength [info globals tkPriv]]} {
  18.     tk::unsupported::ExposePrivateVariable tkPriv
  19. }
  20. #--------------------------------------------------------------------------
  21. # tkPriv elements used in this file:
  22. #
  23. # inMenubutton -    
  24. #--------------------------------------------------------------------------
  25. #
  26. foreach fun {tkMenuUnpost tkMbButtonUp tkMbEnter tkMbPost} {
  27.     if {![llength [info commands $fun]]} {
  28.     tk::unsupported::ExposePrivateCommand $fun
  29.     }
  30. }
  31. unset fun
  32.  
  33. tixWidgetClass tixPopupMenu {
  34.     -classname TixPopupMenu
  35.     -superclass tixShell
  36.     -method {
  37.     bind post unbind
  38.     }
  39.     -flag {
  40.      -buttons -installcolormap -postcmd -spring -state -title
  41.     }
  42.     -configspec {
  43.     {-buttons buttons Buttons {{3 {Any}}}}
  44.     {-installcolormap installColormap InstallColormap false}
  45.     {-postcmd postCmd PostCmd ""}
  46.     {-spring spring Spring 1 tixVerifyBoolean}
  47.     {-state state State normal}
  48.     {-cursor corsor Cursor arrow}
  49.     }
  50.     -static {
  51.     -buttons
  52.     }
  53.     -default  {
  54.     {*Menu.tearOff            0}
  55.     }
  56. }
  57.  
  58. proc tixPopupMenu:InitWidgetRec {w} {
  59.     upvar #0 $w data
  60.  
  61.     tixChainMethod $w InitWidgetRec
  62.  
  63.     set data(g:clients)   ""
  64. }
  65.  
  66. proc tixPopupMenu:ConstructWidget {w} {
  67.     upvar #0 $w data
  68.  
  69.     tixChainMethod $w ConstructWidget
  70.  
  71.     wm overrideredirect $w 1
  72.     wm withdraw $w
  73.  
  74.     set data(w:menubutton) [menubutton $w.menubutton -text $data(-title) \
  75.                 -menu $w.menubutton.menu -anchor w]
  76.     set data(w:menu) [menu $w.menubutton.menu]
  77.  
  78.     pack $data(w:menubutton) -expand yes -fill both
  79. }
  80.  
  81. proc tixPopupMenu:SetBindings {w} {
  82.     upvar #0 $w data
  83.  
  84.     tixChainMethod $w SetBindings
  85.  
  86.     foreach elm $data(-buttons) {
  87.     set btn [lindex $elm 0]
  88.     foreach mod [lindex $elm 1] {
  89.         tixBind TixPopupMenu:MB:$w <$mod-ButtonPress-$btn> \
  90.         "tixPopupMenu:Unpost $w"
  91.     
  92.         tixBind TixPopupMenu:$w <$mod-ButtonPress-$btn> \
  93.         "tixPopupMenu:post $w %W %x %y"
  94.     }
  95.  
  96.     tixBind TixPopupMenu:MB:$w <ButtonRelease-$btn> \
  97.         "tixPopupMenu:BtnRelease $w %X %Y"
  98.  
  99.     tixBind TixPopupMenu:M:$w <Unmap> \
  100.         "tixPopupMenu:Unmap $w"
  101.     tixBind TixPopupMenu:$w <ButtonRelease-$btn> \
  102.         "tixPopupMenu:BtnRelease $w %X %Y"
  103.  
  104.     tixAddBindTag $data(w:menubutton) TixPopupMenu:MB:$w
  105.     tixAddBindTag $data(w:menu)       TixPopupMenu:M:$w
  106.     }
  107. }
  108.  
  109.  
  110. #----------------------------------------------------------------------
  111. # PrivateMethods:
  112. #----------------------------------------------------------------------
  113. proc tixPopupMenu:Unpost {w} {
  114.     upvar #0 $w data
  115.  
  116.     catch {
  117.     tkMenuUnpost ""
  118.     }
  119. #   tkMbButtonUp $data(w:menubutton)
  120. }
  121.  
  122. proc tixPopupMenu:BtnRelease {w rootX rootY} {
  123.     upvar #0 $w data
  124.  
  125.     set cW [winfo containing -displayof $w $rootX $rootY]
  126.  
  127.     if {$data(-spring)} {
  128.     tixPopupMenu:Unpost $w
  129.     }
  130. }
  131.  
  132. proc tixPopupMenu:Unmap {w} {
  133.     upvar #0 $w data
  134.     wm withdraw $w
  135. }
  136.  
  137. proc tixPopupMenu:Destructor {w} {
  138.     upvar #0 $w data
  139.  
  140.     foreach client $data(g:clients) {
  141.     if {[winfo exists $client]} {
  142.         tixDeleteBindTag $client TixPopupMenu:$w
  143.     }
  144.     }
  145.  
  146.     # delete the extra bindings
  147.     #
  148.     foreach tag [list TixPopupMenu:MB:$w TixPopupMenu:M:$w] {
  149.     foreach e [bind $tag] {
  150.         bind $tag $e ""
  151.     }
  152.     }
  153.  
  154.     tixChainMethod $w Destructor
  155. }
  156.  
  157. proc tixPopupMenu:config-title {w value} {
  158.     upvar #0 $w data
  159.  
  160.     $data(w:menubutton) config -text $value
  161. }
  162.  
  163. #----------------------------------------------------------------------
  164. # PublicMethods:
  165. #----------------------------------------------------------------------
  166. proc tixPopupMenu:bind {w args} {
  167.     upvar #0 $w data
  168.  
  169.     foreach client $args {
  170.     if {[lsearch $data(g:clients) $client] == -1} {
  171.         lappend data(g:clients) $client
  172.         tixAppendBindTag $client TixPopupMenu:$w
  173.     }
  174.     }
  175. }
  176.  
  177. proc tixPopupMenu:unbind {w args} {
  178.     upvar #0 $w data
  179.  
  180.     foreach client $args {
  181.     if {[winfo exists $client]} {
  182.         set index [lsearch $data(g:clients) $client]
  183.         if {$index != -1} {
  184.         tixDeleteBindTag $client TixPopupMenu:$w
  185.         set data(g:clients) [lreplace $data(g:clients) $index $index]
  186.         }
  187.     }
  188.     }
  189. }
  190.  
  191. proc tixPopupMenu:post {w client x y} {
  192.     upvar #0 $w data
  193.     global tkPriv
  194.  
  195.     if {$data(-state)  == "disabled"} {
  196.     return
  197.     }
  198.  
  199.     set rootx [expr $x + [winfo rootx $client]]
  200.     set rooty [expr $y + [winfo rooty $client]]
  201.  
  202.     if {$data(-postcmd) != ""} {
  203.     set ret [tixEvalCmdBinding $w $data(-postcmd) "" $rootx $rooty]
  204.     if {![tixGetBoolean $ret]} {
  205.         return
  206.     }
  207.     }
  208.  
  209.     if {[tixGetBoolean -nocomplain $data(-installcolormap)]} {
  210.     wm colormapwindows . "$w"
  211.     }
  212.  
  213.  
  214.     set menuWidth [winfo reqwidth $data(w:menu)]
  215.     set width     [winfo reqwidth  $w]
  216.     set height    [winfo reqheight $w]
  217.  
  218.     if {$width < $menuWidth} {
  219.     set width $menuWidth
  220.     }
  221.  
  222.     set wx $rootx
  223.     set wy $rooty
  224.  
  225.     # trick: the following lines allow the popup menu
  226.     # acquire a stable width and height when it is finally
  227.     # put on the visible screen. Advoid flashing
  228.     #
  229.     wm geometry $w +10000+10000
  230.     wm deiconify $w
  231.     raise $w
  232.  
  233.     update
  234.     wm geometry $w $width\x$height+$wx+$wy
  235.     update
  236.  
  237.     tkMbEnter $data(w:menubutton)
  238.     tkMbPost $tkPriv(inMenubutton) $rootx $rooty
  239. }
  240.