
module GoWidget

  def create_btn
    btn_args= {'relief'=>'flat','borderwidth'=>0,
        'command'=>proc { @check.invoke } }
    @btn=TkButton.new(self,btn_args ).pack('side'=>'left','fill'=>'both','expand'=>'yes')
  end

  def configure(args)
    for i in ['text','font','image','background','foreground']
      if args[i]
        @btn.configure(i=>args[i])
        args.delete(i)
      end

    end

    for i in ['relief','borderwidth']
      if args[i]
        super(i=>args[i])
        args.delete(i)
      end
    end

    @check.configure(args)
  end

end # module GoWidget

class CheckButton  < TkFrame

  include GoWidget

  def initialize(parent=nil,args=nil)
    super(parent)

    cargs= {'indicatoron'=>'false','selectcolor'=>'','borderwidth'=>0,
        'image'=>Defaults::ICONS['uncheck'],'selectimage'=>Defaults::ICONS['check']}

    @check= TkCheckbutton.new(self,cargs).pack('side'=>'left','fill'=>'both')

    create_btn
    configure(args)

  end



end

class RadioButton < TkFrame
  include GoWidget


  def initialize(parent=nil,args=nil)
    super(parent)
    cargs= {'indicatoron'=>'false','selectcolor'=>'','borderwidth'=>0,
        'image'=>Defaults::BStones[12],'selectimage'=>Defaults::WStones[12]}
    @check= TkRadioButton.new(self,cargs).pack('side'=>'left','fill'=>'both')

    create_btn
    configure(args)
  end



end

class Menu < TkMenu

  def initialize
    super
    self.configure(TkDefaults::GUI['menu']) if TkDefaults::GUI['menu']
    self
  end


  def translate(keys=nil)
    if keys and keys.key?('label')
      if TkDefaults::MENU[keys['label']]
        keys['label']=TkDefaults::MENU[keys['label']]
      else
#	puts "MENU[\"#{keys['label']}\"]=\"\"" unless keys['label']== $user
      end
    end
  end


  def add(type, keys=nil)
    translate(keys)
    super(type,keys)
  end



  def insert(index, type, keys=nil)
    translate(keys)
    super(index, type, keys)
  end

  def entryconfigure(index,keys)
    translate(keys)
    super(index, keys)
  end

end


