--
-- Copyright (c) 2012 Kevin Wellwood
-- All rights reserved.
--
-- This source code is distributed under the Modified BSD License. For terms and
-- conditions, see license.txt.
--
-- The Simple_Key_Listener class provides a mechanism for registering any
-- method of a class, matching a certain prototype, as a key action handler.
--
-- Instantiate this package with the class and class-wide access type of an
-- object that will handle key actions.
generic
type Target (<>) is tagged limited private;
package Widgets.Simple_Key_Listeners is
type A_Handler is access
procedure( object : not null access Target'Class;
action : A_Key_Action );
-- Creates a new Key_Listener object to forward 'id' actions from key 'key'
-- with modifier keys matching 'modifiers' to the 'handler' method of 'obj'.
function Listener( key : Integer;
modifiers : Modifiers_Pattern;
id : Action_Id;
obj : access Target'Class;
handler : A_Handler ) return A_Key_Listener;
pragma Postcondition( Listener'Result /= null );
-- Creates a new Key_Listener object to forward 'id' actions from key 'key'
-- to the 'handler' method of 'obj'.
function Listener( key : Integer;
id : Action_Id;
obj : access Target'Class;
handler : A_Handler ) return A_Key_Listener;
pragma Postcondition( Listener'Result /= null );
private
type Simple_Key_Listener is new Simple_Action_Listener and
Key_Listener with
record
key : Integer;
modifiers : Modifiers_Pattern;
id : Action_Id;
object : access Target'Class := null;
handler : A_Handler := null;
end record;
-- Calls the handler method of the object if action's Action_Id matches the
-- Action_Id given at construction, and the modifiers pressed during the
-- action match the Modifiers_Pattern given at construction. 'handled' will
-- be returned as True if the handler method is invoked.
procedure Handle_Action( this : access Simple_Key_Listener;
action : A_Key_Action;
handled : out Boolean );
end Widgets.Simple_Key_Listeners;