with Ada.Strings.Unbounded;          use Ada.Strings.Unbounded;
with System;                         use System;

with RASCAL.ToolboxWindow;           use RASCAL.ToolboxWindow;
with RASCAL.Toolbox;                 use RASCAL.Toolbox;
with RASCAL.ToolboxWritableField;    use RASCAL.ToolboxWritableField;
with RASCAL.ToolboxTask;             use RASCAL.ToolboxTask;
with RASCAL.ToolboxScrolllist;       use RASCAL.ToolboxScrolllist;
with RASCAL.OS;                      use RASCAL.OS;

package RASCAL.Suggestions is


   type String_Pointer is access all String;
   
   type SuggestionList          is array (Positive range <>) of String_Pointer;
   type SuggestionList_Pointer  is access SuggestionList;

   Not_Initialised            : exception;
   Gadget_not_recognised      : exception;
   Task_Is_Initialised        : exception;
   
   type TEL_Suggestion is
        new ATEL_Toolbox_WritableField_ValueChanged with null record;

   --
   -- Initialises the Suggestions package. Not calling it results in a runtime exception.
   --
   procedure Initialise (TB_Task : in ToolBox_Task_Pointer);
  
   --
   -- Add a gadget, for which suggestions are to be displayed.
   --
   procedure Add_Gadget (Object : in Object_ID;
                         Gadget : in Component_ID);

   --
   -- Add a suggestion to the listdisplay for a gadget.
   --
   procedure Add_Suggestion (Object     : in Object_ID;
                             Gadget     : in Component_ID;
                             Suggestion : in String_Pointer);

   --
   -- Returns an array containing the suggestions for a gadget.
   --
   function Get_Suggestions (Object : in Object_ID;
                             Gadget : in Component_ID) return SuggestionList_Pointer;

   --
   --
   --
   procedure Handle (The : in TEL_Suggestion);

private

   Start_StringArraySize     : constant Positive := 10;
   Start_PointerArraySize    : constant Positive := 10;

   Current_PointerArrayIndex : Positive := 1;

   type Suggestion is
   record
   Object         : Object_ID;
   Gadget         : Component_ID;
   Current_Index  : Positive := 1;
   SuggestionArray: SuggestionList_Pointer := new SuggestionList(1..Start_StringArraySize);
   end record;

   type Suggestion_Pointer is access Suggestion;

   type SuggestionsList is array (Positive range <>) of Suggestion_Pointer;
   type SuggestionsList_Pointer is access SuggestionsList;

   Suggestions : SuggestionsList_Pointer; 

   ID : ToolBox_Task_Pointer;

   SuggestionGadget_Created : boolean := false;
   Suggestion_Gadget        : Scrolllist_Gadget;
   Suggestion_GadgetId      : Component_ID;

end RASCAL.Suggestions;