File : input_windows.ads


-----------------------------------------------------------------------
--                              Win_IO                               --
--     A simple set of packages for graphical input and output       --
--                                                                   --
--                       Copyright (C) 2001-2010                     --
--                 Universidad de Cantabria, SPAIN                   --
--                                                                   --
-- Author: Michael Gonzalez       mgh@unican.es                      --
--                                                                   --
-- This is free software; you can redistribute it and/or             --
-- modify it under the terms of the GNU General Public               --
-- License as published by the Free Software Foundation; either      --
-- version 2 of the License, or (at your option) any later version.  --
--                                                                   --
-- This software 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 the GNU --
-- General Public License for more details.                          --
--                                                                   --
-- You should have received a copy of the GNU General Public         --
-- License along with this program; if not, write to the             --
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      --
-- Boston, MA 02111-1307, USA.                                       --
--                                                                   --
-----------------------------------------------------------------------
--                                                                   --
-- The Input_Windows package provides a simple window with           --
-- I/O capabilities for data of the types Integer, Float, and String --
-- Several data can be displayed and/or retrieved on the same window --
--                                                                   --
-- This package requires Gtkada-2.2.0 or later                       --
--                                                                   --
-----------------------------------------------------------------------

with Named_Lists;
with Var_Strings;
with Input_Window_Pkg;
with Gtk.Label; use Gtk.Label;
with Gtk.Gentry; use Gtk.GEntry;
with Windows_Exceptions;

package Input_Windows is

   -----------------------------------------------------------------------
   --
   --                           INPUT_WINDOW
   --
   --  An Input_Window is a window that provides the following items:
   --
   --    - An area on which text can be written, for displaying messages
   --      or results
   --
   --    - A scrollable area on which many input/output entry boxes may
   --      be created. Each box has a label and an editable area that
   --      is used to display and modify a value of type Integer, Float,
   --      or String
   --
   --    - An OK button that indicates that the user has finished editing
   --
   --    - A Cancel button that raises the Cancelled exception
   --
   -----------------------------------------------------------------------

   type Input_Window_Type is private;

   -----------------------------------------------------------------------
   --                      INPUT_WINDOW Operations
   --
   --  Input_Window  (Title)         --  Create the window, with the
   --                                --  specified title
   --
   --  Put_Line      (IW,            --  Put the Str String on the results
   --                 Str)           --  area of the IW window
   --
   --  Create_Entry  (IW,            --  Create an entry box on the IW window
   --                 Label,         --  with this label
   --                 Initial_Value) --  and this initial value (Integer)
   --                                --  may raise Repeated_Label
   --
   --  Create_Entry  (IW,            --  Create an entry box on the IW window
   --                 Label,         --  with this label
   --                 Initial_Value) --  and this initial value (Float)
   --                                --  may raise Repeated_Label
   --
   --  Create_Entry  (IW,            --  Create an entry box on the IW window
   --                 Label,         --  with this label
   --                 Initial_Value) --  and this initial value (String)
   --                                --  may raise Repeated_Label
   --
   --  Wait          (IW,            --  Display Message on the results area
   --                 Message)       --  of the IW window, and wait for the
   --                                --  OK button to be pressed. This will
   --                                --  be an indication that the data on the
   --                                --  entry boxes has been edited
   --                                --  May raise Canceled if the Cancel button
   --                                --  is pressed
   --                                --  Before returning, it hides the window
   --
   --  Note: the operations below only work after the Wait operation
   --        has returned
   --
   --  Get           (IW,            --  Read an Integer from the entry box
   --                 Label,         --  matching Label in the IW window
   --                 Item)          --  Value is returned here
   --                                --  May raise Label_Not_Found
   --                                --  May raise Data_Error if text on the
   --                                --  entry box is not an integer
   --
   --  Get           (IW,            --  Read a Float from the entry box
   --                 Label,         --  matching Label in the IW window
   --                 Item)          --  Value is returned here
   --                                --  May raise Label_Not_Found
   --                                --  May raise Data_Error if text on the
   --                                --  entry box is not a float
   --
   --  Get           (IW,            --  Read a String from the entry box
   --                 Label,         --  matching Label in the IW window
   --                 Item)          --  Value is returned here; if the
   --                                --  Item parameter is longer than the
   --                                --  text in the box it is padded with spaces
   --                                --  if the Item parameter is shorter, then
   --                                --  the input text is truncated
   --                                --  May raise Label_Not_Found
   --
   --  Get_Line      (IW,            --  Read a String from the entry box
   --                 Label,         --  matching Label in the IW window
   --                 Item,          --  Works similar to Ada.Text_IO.Get_Line,
   --                 Num)           --  returning the input text in the first
   --                                --  characters of Item, and the number of
   --                                --  read characters in Num
   --                                --  May raise Label_Not_Found
   --
   -----------------------------------------------------------------------

   function Input_Window
     (Title : String)
     return Input_Window_Type;

   procedure Put_Line
     (IW : in out Input_Window_Type;
      Str : String);

   procedure Create_Entry
     (IW : in out Input_Window_Type;
      Label : String;
      Initial_Value : String);
   -- may raise Repeated_Label
   procedure Create_Entry
     (IW : in out Input_Window_Type;
      Label : String;
      Initial_Value : Integer);
   -- may raise Repeated_Label
   procedure Create_Entry
     (IW : in out Input_Window_Type;
      Label : String;
      Initial_Value : Float);
   -- may raise Repeated_Label

   procedure Wait
     (IW : in out Input_Window_Type;
      Message : String);
   -- may raise Canceled

   procedure Get
     (IW : in out Input_Window_Type;
      Label : String;
      Item : out Integer);
   -- may raise Label_Not_Found or Data_Error
   procedure Get
     (IW : in out Input_Window_Type;
      Label : String;
      Item : out Float);
   -- may raise Label_Not_Found or Data_Error
   procedure Get
     (IW : in out Input_Window_Type;
      Label : String;
      Item : out String);
   -- may raise Label_Not_Found
   procedure Get_Line
     (IW : in out Input_Window_Type;
      Label : String;
      Item  : out String;
      Num   : out Natural);
   -- may raise Label_Not_Found

   Label_Not_Found : exception renames Windows_Exceptions.Label_Not_Found;
   Repeated_Label : exception  renames Windows_Exceptions.Repeated_Label;
   Data_Error : exception;
   Canceled : exception renames Windows_Exceptions.Canceled;
   Cancelled : exception renames Windows_Exceptions.Canceled;

private

   type Input_Entry is record
      Name, Value : Var_Strings.Var_String;
      Text_Entry : Gtk_Entry;
      Text_Label : Gtk_Label;
   end record;

   function Name (E : Input_Entry ) return Var_Strings.Var_String;

   package Lists is new Named_Lists (Input_Entry,Name);

   type Input_Window_Type is record
      Win : Input_Window_Pkg.Input_Window_Access;
      Entries : Lists.List;
   end record;

end Input_Windows;