with mcc.gui.container.window;
with mcc.gui.colors;

with ada.text_Io;
use ada.text_io;

procedure window_test is
   Window  : aliased mcc.gui.container.window.main_window;
   Window1 : aliased mcc.gui.container.window.subwindow;
   
   procedure Key_Listener (
      Obj   : in out mcc.gui.Sized_Object'Class;
      Event : in     mcc.gui.Key_Event) is
   begin
      put_line(standard_output,"key " &
         mcc.gui.key_action_type'image(event.action) &
         mcc.gui.key_type'image(event.key));
   end Key_Listener;

   procedure Mouse_Listener (
      Obj   : in out mcc.gui.Sized_Object'Class;
      Event : in     mcc.gui.Mouse_Event) is
   begin
      put_line(standard_output,
         mcc.gui.mouse_action_type'image(event.action) & " " &
         mcc.gui.mouse_button'image(event.button) &
         natural'image(event.x) & natural'image(event.y));
   end Mouse_Listener;

   procedure resize_procedure(
      obj : in out mcc.gui.container.window.window'class;
      width : in integer;
      height :in integer) is
   begin
      if width /= 300 or else height /= 300 then
         put_line(standard_output,integer'image(width) &
            integer'image(height));
         mcc.gui.container.window.resize(obj,300,300);
      end if;
   end resize_procedure;

   Count : Integer := 0;
   procedure close_handler(
      obj : in out mcc.gui.container.window.window'class) is
   begin
      if Count < 3 then
         Count := Count + 1;
         put_line(standard_output,"not closing window");
      else
         put_line(standard_output,"closing window");
         mcc.gui.container.window.destroy(obj);
      end if;
   end close_handler;
begin
   put_line(standard_output,"hello world");
   -- test window functions
   mcc.gui.container.window.create(window,
      100,100,300,300);
   mcc.gui.container.window.set_title(window,"Fr""ed");
   mcc.gui.container.window.show(window);
   put_line(standard_output,"shown");
--   delay 2.0;
   
   mcc.gui.container.window.hide(window);
   put_line(standard_output,"hidden");
--   delay 0.5;
   mcc.gui.bell;
--   delay 0.5;
   mcc.gui.container.window.show(window);
   put_line(standard_output,"visible");
   mcc.gui.container.window.move(window,500,500);
   mcc.gui.container.window.set_background_color(window,
      mcc.gui.colors.named_color(mcc.gui.colors.red));
--      
   mcc.gui.container.window.set_resize_handler(window'unchecked_access,
      resize_procedure'unrestricted_access);
   mcc.gui.container.window.set_close_handler(window'unchecked_access,
      close_handler'unrestricted_access);
   mcc.gui.set_key_listener(window'unchecked_access,
      key_listener'unrestricted_access);
   mcc.gui.set_mouse_listener(window'unchecked_access,
      mouse_listener'unrestricted_access);
      
   mcc.gui.container.window.create(window1,
      100,100,300,300);
   mcc.gui.container.window.to_top(window);
   Mcc.Gui.Container.Window.Set_Cursor(Window,
      mcc.gui.resize_sw);

   mcc.gui.container.window.event_loop;
end window_test;
