gui/implementation/ComboBox.tcl


@implementation ComboBox {
  - init {} {
      $super init 
      $self hideBorder
      $frame configure -bd 1 -relief sunken
      grid \
        [set entry [entry $frame.entry -relief flat]] \
        [set pushButton [button $frame.button -padx 0m -pady 0m \
          -command "$self toggleVisibilityOfListbox"]] \
        -sticky snew
      $frame.button configure -image [@image down_arrow] -width 12
      grid rowconfigure $frame 0 -weight 1
      grid columnconfigure $frame 0 -weight 1
      set listbox [[ListBox newWithPath: .listbox$self] height: 5]
      [$listbox path] configure -bd 2 -relief groove
      $listbox onSelection: "
        $self selection: \[\$self selection\]
        \$self hide
      "
    }
  - forwardInvocation: msg {
      if [$listbox respondsTo: [@selector $msg]] {
        set res [eval $listbox $msg]
        if {"$res" == "$listbox"} { return $self } else { return $res }
      } else {
        return [$super $msg]
      }
    }
  - toggleVisibilityOfListbox {} {
      if [winfo ismapped .listbox$self] {
        $self hideListbox
      } else {
        $self showListbox
      }
    }
  - showListbox {} {
      place .listbox$self -in $frame -x 0 -rely 1.0 -y +2 -relwidth 1 \
        -bordermode outside
      raise .listbox$self
    }
  - hideListbox {} {
      catch {place forget .listbox$self}
    }
  - selection {} {
      return [$entry get]
    }
  - selection: aValue {
      $entry delete 0 end
      $entry insert end $aValue
    }
  - dealloc {} {
      $listbox dealloc
      catch {destroy $entry $pushButton}
      return [$super dealloc]
    }
  - show {} {
      grid $path
    }
}