------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 1995 by International Computer Science Institute            --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------

-- Author: Matthias Ernst <tisi@beutlin.desy.de>

class DEMO_LISTBOX is
   include GUI_UTIL;
   
   attr listbox: TK_LISTBOX;
   attr entry: TK_ENTRY;
   attr button: TK_BUTTON;
   
   insert_item(i:TK_EVENT_INFO) is
      -- insert the entry's content at the end of the list
      
      listbox.insert(listbox.index_end, entry.get_text);
   end;
   
   print_list is
      -- print the content of the listbox to stdout
      -- two different ways should produce the same
      
      #OUT + "===== with get ! =======\n";
      loop
	 #OUT + listbox.get!(once 0, once listbox.index_end) + "\n";
      end;
      #OUT + "=== with get(index) ====\n";
      loop index ::= listbox.size.times!;
	 #OUT + listbox.get(index) + "\n"
      end;
      #OUT + "========================\n";
   end;
   
   init is
      listbox := #(root_window, "listbox",
		   TK_LISTBOX_CFG::std.selectmode_multiple, TK_PACK::left);
      entry   := #(root_window, "entry",   
		   TK_ENTRY_CFG::std,   TK_PACK::top);
      button  := #(root_window, "button", 
		   TK_BUTTON_CFG::std.text("Print list"), TK_PACK::top);
      button.command := bind(print_list);
			      
      entry.bind_event(TK_KEY_EVENT::Press.Return, bind(insert_item(_)));
   end;
   
end; 
-------------------------------------------------------------------

