
class IGSList  < TkFrame

  def initialize(parent,w,h)
    opts= TkDefaults::GUI['IGSList.frame.main']
    super(parent,opts)
    opts= TkDefaults::GUI['IGSList.frame.titlebar']
    f1=TkFrame.new(self,opts).pack('side'=>'left','fill'=>'both','expand'=>'yes')
    opts= TkDefaults::GUI['IGSList.canvas.titlebar']
    @titlebar= TkCanvas.new(f1,opts).pack('fill'=>'x','expand'=>'no')

    make_texture(@titlebar,Defaults::DEFS['IGSList_title_background'],w,1)
    opts= TkDefaults::GUI['IGSList.canvas.list']

    @canvas=TkCanvas.new(f1,opts).pack('fill'=>'both','expand'=>'yes')

    $ip._eval("#{@canvas.path} bind rect_outline <Enter> {#{@canvas.path} itemconfigure current -outline gray}")
    $ip._eval("#{@canvas.path} bind rect_outline <Leave> {#{@canvas.path} itemconfigure current -outline {}}")


    opts= TkDefaults::GUI['IGSList.scrollbar'].update( 'command' => proc { |*args| @canvas.yview *args}) 

    scrollbar=TkScrollbar.new(self,opts).pack( 
                                              'side' => 'left',
                                              'fill' => 'y')
    @canvas.yscrollcommand(proc { |*args| scrollbar.set *args })
    @posy=0
    @maxw=0
    @steph=0
    make_texture(@canvas,Defaults::DEFS['IGSList_background'],w,h)

    @updating=false

#@canvas.bind('Button-4',proc{@canvas.yview("scroll",1,"units")})
$ip._eval("bind #{@canvas.path} <Button-4> {#{@canvas.path} yview scroll -2 units}")
$ip._eval("bind #{@canvas.path} <Button-5> {#{@canvas.path} yview scroll 2 units}")

  end

  def set_title (title)
    @titlebar.itemconfigure('title','fill' => Defaults::DEFS['IGSList_title_foreground'])
    @titlebar.configure('width'=>title.width,'height' => title.height)

  end

  def make_texture(canvas,image,dimx,dimy)

    w= image.width
    h= image.height


    for i in 0...dimx
      for j in 0...dimy

        $ip._eval("#{canvas.path} create image #{i*w} #{j*h} -anchor nw -image #{image.path}")

      end
    end
    @t_dimx = dimx
    @t_dimy = dimy
    @t_width = w
    @t_height = h
    @t_img = image

  end

  def  add_entry (entry)

    @posy += entry.height + 1
    @maxw = entry.width if entry.width > @maxw
    @steph =   entry.height 

    if @posy > @t_dimy * @t_height - entry.height
      for i in 0...@t_dimx
        TkcImage.new(@canvas,i*@t_width,@t_dimy*@t_height,'anchor'=>'nw', 'image'=> @t_img)
        $ip._eval("#{@canvas.path} create image #{i*@t_width} #{@t_dimy*@t_height} -anchor nw -image #{@t_img.path}")
      end
      @t_dimy += 1
    end
  end

  def clear
    @posy=0
    @maxw=0
    @steph=0

     # @canvas.delete('entry')
    $ip._eval("#{@canvas.path} delete entry")
  end

  def refresh
    @canvas.configure('yscrollincrement'=>@steph, 'width'=> @maxw, 'scrollregion'=> [0,0,0,@posy])
  end




end # class




