1. -- 
  2. -- Copyright (c) 2012 Kevin Wellwood 
  3. -- All rights reserved. 
  4. -- 
  5. -- This source code is distributed under the Modified BSD License. For terms and 
  6. -- conditions, see license.txt. 
  7. -- 
  8.  
  9. with Objects;                           use Objects; 
  10.  
  11. limited with Widgets; 
  12.  
  13. private with Ada.Containers; 
  14.  
  15. package Actions is 
  16.  
  17.     -- Represents a type of action that can occur to a widget, such as a click, 
  18.     -- toggle, press, etc. 
  19.     type Action_Id is private; 
  20.  
  21.     function "="( l, r : Action_Id ) return Boolean; 
  22.  
  23.     -- Converts 'actName' to its corresponding Action_Id value using a string 
  24.     -- hashing function. 
  25.     function To_Action_Id( actName : String ) return Action_Id; 
  26.  
  27.     ---------------------------------------------------------------------------- 
  28.  
  29.     -- Represents a specific instance of an action that occurred relative to a 
  30.     -- widget in the GUI, such as a click at a certain location on a widget, a 
  31.     -- toggle or press of a button, etc. 
  32.     type Action is abstract new Object with private; 
  33.  
  34.     -- All Actions have a type (represented by an Action_Id) and the widget that 
  35.     -- reported the action. Additional information about the action may be 
  36.     -- included, depending on the concrete Action class. A concrete Action class 
  37.     -- represents a set of action types that all share the same kind of action 
  38.     -- information, or come from the same class of Widget. 
  39.     procedure Construct( this   : access Action; 
  40.                          id     : Action_Id; 
  41.                          source : not null access Widgets.Widget'Class ); 
  42.  
  43.     -- Returns the identity of the action. This is the specific type of action 
  44.     -- that occured at the source widget, like Click, Input_Entered, etc. 
  45.     function Get_Id( this : not null access Action'Class ) return Action_Id; 
  46.  
  47.     -- Returns a reference to the widget that reported the action. 
  48.     function Get_Source( this : not null access Action'Class ) return access Widgets.Widget'Class; 
  49.  
  50.     ---------------------------------------------------------------------------- 
  51.  
  52.     -- An interface from which all concrete Action_Listener interfaces are to be 
  53.     -- inherited from. This interface does not define any procedures because it 
  54.     -- is not used directly. The Action_Listener interface is useful for storing 
  55.     -- instances of different implementors of Action_Listeners in a common 
  56.     -- container. 
  57.     type Action_Listener is limited interface; 
  58.     type A_Action_Listener is access all Action_Listener'Class; 
  59.  
  60.     ---------------------------------------------------------------------------- 
  61.  
  62.     -- A Simple_Action_Listener is the abstract base class for light weight 
  63.     -- action listener objects that simply pass along an Action to an 
  64.     -- appropriate handler procedure. A Simple_Action_Listener is intended to be 
  65.     -- owned and deleted by the widget with which it is registered. 
  66.     type Simple_Action_Listener is abstract new Limited_Object with null record; 
  67.  
  68. private 
  69.  
  70.     use Ada.Containers; 
  71.  
  72.     -- An Action_Id is a hash value of an action name. 
  73.     type Action_Id is new Ada.Containers.Hash_Type; 
  74.  
  75.     type Action is abstract new Object with 
  76.         record 
  77.             id     : Action_Id := Action_Id'First; 
  78.             source : access Widgets.Widget'Class; 
  79.         end record; 
  80.  
  81. end Actions;