with Objects; use Objects;
limited with Widgets;
private with Ada.Containers;
package Actions is
-- Represents a type of action that can occur to a widget, such as a click,
-- toggle, press, etc.
type Action_Id is private;
function "="( l, r : Action_Id ) return Boolean;
-- Converts 'actName' to its corresponding Action_Id value using a string
-- hashing function.
function To_Action_Id( actName : String ) return Action_Id;
----------------------------------------------------------------------------
-- Represents a specific instance of an action that occurred relative to a
-- widget in the GUI, such as a click at a certain location on a widget, a
-- toggle or press of a button, etc.
type Action is abstract new Object with private;
-- All Actions have a type (represented by an Action_Id) and the widget that
-- reported the action. Additional information about the action may be
-- included, depending on the concrete Action class. A concrete Action class
-- represents a set of action types that all share the same kind of action
-- information, or come from the same class of Widget.
procedure Construct( this : access Action;
id : Action_Id;
source : not null access Widgets.Widget'Class );
-- Returns the identity of the action. This is the specific type of action
-- that occured at the source widget, like Click, Input_Entered, etc.
function Get_Id( this : not null access Action'Class ) return Action_Id;
-- Returns a reference to the widget that reported the action.
function Get_Source( this : not null access Action'Class ) return access Widgets.Widget'Class;
----------------------------------------------------------------------------
-- An interface from which all concrete Action_Listener interfaces are to be
-- inherited from. This interface does not define any procedures because it
-- is not used directly. The Action_Listener interface is useful for storing
-- instances of different implementors of Action_Listeners in a common
-- container.
type Action_Listener is limited interface;
type A_Action_Listener is access all Action_Listener'Class;
private
use Ada.Containers;
-- An Action_Id is a hash value of an action name.
type Action_Id is new Ada.Containers.Hash_Type;
type Action is abstract new Object with
record
id : Action_Id := Action_Id'First;
source : access Widgets.Widget'Class;
end record;
end Actions;