# gui/implementation/ProgressBox.tcl

    @implementation ProgressBox {
      - init {} {
          $super init
          $super hideBorder
          set bg [[entry $frame.e] cget -selectbackground]
          set lightBg [$frame.e cget -background]
          destroy $frame.e
          set canvas [canvas $frame.bar -width 100 -height 20 -relief sunken -bd 1]
          $canvas configure -bg $lightBg
          set items(value) [$canvas create text 50 10 \
            -text 0 -font Fixed -anchor e -fill black -tag value]
          set items(unit) [$canvas create text 55 10 \
            -text % -font Fixed -anchor w -fill black]
          set items(bar) [$canvas create rectangle -100 0 0 20 \
            -fill $bg -outline $bg -tag bar]
          grid $canvas -sticky snew
          $canvas configure -scrollregion {0 0 100 20}
          set timer(value) 60
          set timer(step) 600
          set timer(id) 0
          set value 0
        }

      - value: aValueFrom0To100 {
          $canvas move $items(bar) [expr $aValueFrom0To100 - $value] 0
          $canvas itemconfigure $items(value) -text $aValueFrom0To100
          set value $aValueFrom0To100
          $canvas raise $items(value)
          $canvas raise $items(unit)
          if {[info exists callbacks(Change)] \
            && [string length $callbacks(Change)]} {
            catch {eval $callbacks(Change)}
          }
        }
      - value {} {
          return $value
        }

      - timerStep: aTimeValueInMs {
          if {$aTimeValueInMs == 0 } {
            $self stop
          } else {
            set timer(step) $aTimeValueInMs
            set timer(value) [expr $timer(step) * 100]
          }
        }

      - timerStep {} {
          return $timer(step)
        }

      - timer: aTimeValueInSec {
          if {$aTimeValueInSec == 0 } {
            $self stop
          } else {
            set timer(value) [expr $aTimeValueInSec * 1000]
            set timer(step) [expr $timer(value) / 100]
          }
        }

      - timer {} {
          return $timer(value)
        }

      - start {} {
          return [$self run]
        }

      - run {} {
          if {$value < 100} {
            $self value: [expr $value + 1]
            set timer(id) [after $timer(step) $self start]
          } else {
            set timer(id) 0
            if {[info exists callbacks(End)] \
              && [string length callbacks(End)]} {
              catch {eval $callbacks(End)}
            }
          }
        }

      - onChange: aCallback {
          set callbacks(Change) $aCallback
        }

      - onEnd: aCallback {
          set callbacks(End) $aCallback
        }

      - stop {} {
          if {$timer(id) != 0} {
            after cancel $timer(id)
            set timer(id) 0
          }

        }

      - reset {} {
          $self value: 0
        }
    }