# gui/implementation/SplitBox.tcl

    @implementation SplitBox {
      - init {} {
          $super init
          $super hideBorder
          set top [set left [frame $frame.frame1 -bd 0 -relief flat]]
          set bottom [set right [frame $frame.frame2 -bd 0 -relief flat]]
          set separator [frame $frame.separator -relief flat -bd 0]
          set split 0.5
          set orientation horizontal
          set bullet [label $frame.separator.bullet -image [@image bullet] \
            -padx 0 -pady 0 -bd 0]

          set e [entry $frame._entry]
          set highlightBackground [$e cget -selectbackground]
          destroy $e

          bind $frame.separator <B1-Motion> "$self slideFromX: %X andY: %Y"
          bind $frame.separator.bullet <B1-Motion> "$self slideFromX: %X andY: %Y"
          bind $frame.separator <ButtonPress-1> "$self highlight"
          bind $frame.separator <ButtonRelease-1> "$self unHighlight"
          bind $frame.separator.bullet <ButtonPress-1> "$self highlight"
          bind $frame.separator.bullet <ButtonRelease-1> "$self unHighlight"

          bind $frame.separator <Double-ButtonPress-1> "$self toggle"
          bind $frame.separator.bullet <Double-ButtonPress-1> "$self toggle"

          eval bind $frame.separator [@removeBindingsOnDestroyEvent]
          eval bind $frame.separator.bullet [@removeBindingsOnDestroyEvent]
          $self rebuild
        }

      - rebuild {} {
          if {"$orientation" == "horizontal"} {
            place $top -relx 0.0 -rely 0.0 -relheight $split \
              -height -2 -relwidth 1 -width 0 \
              -anchor nw -y 0
            place $bottom -relx 0.0 -rely 1.0 \
              -relheight [expr 1 - $split] -height -7 -width 0 \
              -relwidth 1 -anchor sw -y 0
            place $separator -relx 0.0 -rely $split \
              -relwidth 1 -height 7 -width 0 -x 0 -y -1 \
              -relheight {} -anchor nw
            place $bullet -relx 0.5 -rely 0 -y 0 -bordermode outside
          } else {
            place $left -relx 0.0 -rely 0.0 -relwidth $split \
              -width -2 -relheight 1 -anchor nw -height 0
            place $right -relx 1.0 -rely 0.0 -relwidth [expr 1 - $split] \
              -width -7 -height 0 \
              -relheight 1 -anchor ne
            place $separator -relx $split -rely 0.0 -width 7 \
              -relheight 1 -height 0 -x 0 -y 0 \
              -relwidth {} -anchor nw
            place $bullet -rely 0.5 -relx 0 -x 0 -bordermode outside
          }
        }

      - split: fraction {
          if {"$fraction" != "0.98"} { set lastSplit $fraction } else { lappend lastSplit 0.98 }
          set split [format %.2f $fraction]
          if {"$orientation" == "horizontal"} {
            place $top -relheight $split
            place $bottom -relheight [expr {1.0 - $split}]
            place $separator -rely $split
          } else {
            place $left -relwidth $split
            place $right -relwidth [expr {1.0 - $split}]
            place $separator -relx $split
          }
        }
      - split {} {
          return $split
        }

      - maxSplit {} {
          $self split: 0.98
        }

      - lastSplit {} {
          set lastSplit [lindex $lastSplit 0]
          $self split: $lastSplit
        }

      - toggle {} {
          if {[llength $lastSplit] > 1} { $self lastSplit } else { $self maxSplit }
        }

      - highlight {} {
          $separator configure -bg $highlightBackground
          $bullet configure -bg $highlightBackground
        }
      - unHighlight {} {
          $separator configure -bg [$frame cget -bg]
          $bullet configure -bg [$frame cget -bg]
        }

      - slideFromX:andY: {x y} {
          if {"$orientation" == "horizontal"} {
            set i [expr ($y - [winfo rooty $frame])/double([winfo height $frame])]
          } else {
            set i [expr ($x - [winfo rootx $frame])/double([winfo width $frame])]
          }
          $self split: $i
        }

      - orientation {} { return $orientation }
      - orientation: horizontalOrVertical {
          set orientation $horizontalOrVertical
          $self rebuild
        }

      - top {} {
          return $top
        }
      - bottom {} {
          return $bottom
        }
      - left {} {
          return $left
        }
      - right {} {
          return $right
        }
    }