#
# SrcPref
# ----------------------------------------------------------------------
# Implements GDB source preferences dialog
#
#   PUBLIC ATTRIBUTES:
#
#   METHODS:
#
#     config ....... used to change public attributes
#
#     PRIVATE METHODS
#
#   X11 OPTION DATABASE ATTRIBUTES
#
#
# ----------------------------------------------------------------------
#   AUTHOR:  Martin M. Hunt	hunt@cygnus.com     
#            Cygnus Solutions   
#


itcl_class SrcPref {
  # ------------------------------------------------------------------
  #  CONSTRUCTOR - create new source preferences dialog
  # ------------------------------------------------------------------
  constructor {args} {
    #
    #  Create a window with the same name as this object
    #
    global prefs_state
    set attach $args
    set class [$this info class]
    @@rename $this $this-tmp-
    @@frame $this -class $class 
    @@rename $this $this-win-
    @@rename $this-tmp- $this
    build_win
  }

  # ------------------------------------------------------------------
  #  METHOD:  build_win - build the dialog
  # ------------------------------------------------------------------
  method build_win {} {
    if {$attach != 1} {
      frame $this.f
      frame $this.f.a
      frame $this.f.b
      set f $this.f.a
    } else {
      set f $this
    }

    frame $f.1
    frame $f.2
    frame $f.3
    set pc_color [pref get src PC_TAG]
    set stack_color [pref get src STACK_TAG]
    set browse_color [pref get src BROWSE_TAG]
    button $f.1.pc -fg $pc_color -bg $pc_color -text "     " \
      -command "$this pick $pc_color PC_TAG"
    button $f.2.stack -fg $stack_color -bg $stack_color -text "     " \
      -command "$this pick $stack_color STACK_TAG"
    button $f.3.browse -fg $browse_color -bg $browse_color -text "     " \
      -command "$this pick $browse_color BROWSE_TAG"

    label $f.1.plabel -text "PC color"
    label $f.2.slabel -text "STACK color"
    label $f.3.blabel -text "BROWSE color"
    pack $f.1.pc $f.1.plabel -side left
    pack $f.3.browse $f.3.blabel -side left
    pack $f.2.stack $f.2.slabel -side left
    pack $f.1 $f.2 $f.3 -side top -anchor w

    if {$attach != 1} {
      button $this.f.b.save -text Save -underline 0 -command "pref save $this"
      button $this.f.b.apply -text Apply -underline 0 -command "pref apply"
      button $this.f.b.quit -text Quit -underline 0 -command "$this delete"
      pack $this.f.b.save $this.f.b.apply $this.f.b.quit -side left -expand yes
      pack $this.f.a $this.f.b $this.f $this
    }
  }

  # ------------------------------------------------------------------
  #  DESTRUCTOR - destroy window containing widget
  # ------------------------------------------------------------------
  destructor {
    set top [winfo toplevel $this]
    manage delete $this 1
    destroy $this
    if {$attach != 1} {
      destroy $top
    }
  }

  # ------------------------------------------------------------------
  #  METHOD:  config - used to change public attributes
  # ------------------------------------------------------------------
  method config {config} {}

  # ------------------------------------------------------------------
  #  METHOD:  pick - pick colors
  # ------------------------------------------------------------------
  method pick {color tag} {
    set new_color [tk_chooseColor -initialcolor $color -title "Choose color"]
    if {$new_color != $color} {
      pref set src $tag $new_color
      reconfig
    }
  }


  # ------------------------------------------------------------------
  #  METHOD:  reconfig - used when preferences change
  # ------------------------------------------------------------------
  method reconfig {} {
    # for now, just delete and recreate
    if {$attach == 1} {
      destroy $this.1 $this.2 $this.3
    } else {
      destroy $this.f 
    }
    build_win
  }
  #
  #  PROTECTED DATA
  #
  protected attach 0
}

