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 / Meter.tcl < prev    next >
Text File  |  2001-11-03  |  3KB  |  138 lines

  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. #    $Id: Meter.tcl,v 1.1.1.1.2.1 2001/11/03 06:54:00 idiscovery Exp $
  4. #
  5. # Meter.tcl --
  6. #
  7. #    Implements the tixMeter 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.  
  17. tixWidgetClass tixMeter {
  18.     -classname TixMeter
  19.     -superclass tixPrimitive
  20.     -method {
  21.     }
  22.     -flag {
  23.     -foreground -text -value
  24.     }
  25.     -configspec {
  26.     {-fillcolor fillColor FillColor #8080ff}
  27.     {-foreground foreground Foreground black}
  28.     {-text text Text ""}
  29.     {-value value Value 0}
  30.     }
  31.     -default {
  32.     {.relief        sunken}
  33.     {.borderWidth        2}
  34.     {.width            150}
  35.     }
  36. }
  37.  
  38. proc tixMeter:InitWidgetRec {w} {
  39.     upvar #0 $w data
  40.     global env
  41.  
  42.     tixChainMethod $w InitWidgetRec
  43. }
  44.  
  45. #----------------------------------------------------------------------
  46. #        Construct widget
  47. #----------------------------------------------------------------------
  48. proc tixMeter:ConstructWidget {w} {
  49.     upvar #0 $w data
  50.  
  51.     tixChainMethod $w ConstructWidget
  52.  
  53.     set data(w:canvas) [canvas $w.canvas]
  54.     pack $data(w:canvas) -expand yes -fill both
  55.  
  56.     tixMeter:Update $w
  57. }
  58.  
  59. proc tixMeter:SetBindings {w} {
  60.     upvar #0 $w data
  61.  
  62.     tixChainMethod $w SetBindings
  63. }
  64.  
  65. proc tixMeter:Update {w} {
  66.     upvar #0 $w data
  67.  
  68.     # set the width of the canvas
  69.     set W [expr $data(-width)-\
  70.     ([$data(w:root) cget -bd]+[$data(w:root) cget -highlightthickness]*2)]
  71.     $data(w:canvas) config -width $W
  72.  
  73.     if {$data(-text) == ""} {
  74.     set text [format "%d%%" [expr int($data(-value)*100)]]
  75.     } else {
  76.     set text $data(-text)
  77.     }
  78.  
  79.     # (Create/Modify) the text item.
  80.     #
  81.     if {![info exists data(text)]} {
  82.     set data(text) [$data(w:canvas) create text 0 0 -text $text]
  83.     } else {
  84.     $data(w:canvas) itemconfig $data(text) -text $text
  85.     }
  86.  
  87.     set bbox [$data(w:canvas) bbox $data(text)]
  88.  
  89.     set itemW [expr [lindex $bbox 2]-[lindex $bbox 0]]
  90.     set itemH [expr [lindex $bbox 3]-[lindex $bbox 1]]
  91.  
  92.  
  93.     $data(w:canvas) coord $data(text) [expr $W/2] [expr $itemH/2+4]
  94.  
  95.     set H [expr $itemH + 4]
  96.     $data(w:canvas) config -height [expr $H]
  97.  
  98.  
  99.     set rectW [expr int($W*$data(-value))]
  100.  
  101.     if {![info exists data(rect)]} {
  102.     set data(rect) [$data(w:canvas) create rectangle 0 0 $rectW 1000]
  103.     } else {
  104.     $data(w:canvas) coord $data(rect) 0 0 $rectW 1000
  105.     }
  106.  
  107.     $data(w:canvas) itemconfig $data(rect) \
  108.     -fill $data(-fillcolor) -outline $data(-fillcolor)
  109.  
  110.     $data(w:canvas) raise $data(text)
  111. }
  112.  
  113. #----------------------------------------------------------------------
  114. # Configuration
  115. #----------------------------------------------------------------------
  116. proc tixMeter:config-value {w value} {
  117.     upvar #0 $w data
  118.  
  119.     set data(-value) $value
  120.     tixMeter:Update $w
  121. }
  122.  
  123. proc tixMeter:config-text {w value} {
  124.     upvar #0 $w data
  125.  
  126.     set data(-text) $value
  127.     tixMeter:Update $w
  128. }
  129.  
  130. proc tixMeter:config-fillcolor {w value} {
  131.     upvar #0 $w data
  132.  
  133.     set data(-fillcolor) $value
  134.     tixMeter:Update $w
  135. }
  136.   
  137.  
  138.