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. -- The Simple_Key_Listener class provides a mechanism for registering any 
  10. -- method of a class, matching a certain prototype, as a key action handler. 
  11. -- 
  12. -- Instantiate this package with the class and class-wide access type of an 
  13. -- object that will handle key actions. 
  14. generic 
  15.     type Target (<>) is tagged limited private; 
  16. package Widgets.Simple_Key_Listeners is 
  17.  
  18.     type A_Handler is access 
  19.         procedure( object : not null access Target'Class; 
  20.                    action : A_Key_Action ); 
  21.  
  22.     -- Creates a new Key_Listener object to forward 'id' actions from key 'key' 
  23.     -- with modifier keys matching 'modifiers' to the 'handler' method of 'obj'. 
  24.     function Listener( key       : Integer; 
  25.                        modifiers : Modifiers_Pattern; 
  26.                        id        : Action_Id; 
  27.                        obj       : access Target'Class; 
  28.                        handler   : A_Handler ) return A_Key_Listener; 
  29.     pragma Postcondition( Listener'Result /= null ); 
  30.  
  31.     -- Creates a new Key_Listener object to forward 'id' actions from key 'key' 
  32.     -- to the 'handler' method of 'obj'. 
  33.     function Listener( key     : Integer; 
  34.                        id      : Action_Id; 
  35.                        obj     : access Target'Class; 
  36.                        handler : A_Handler ) return A_Key_Listener; 
  37.     pragma Postcondition( Listener'Result /= null ); 
  38.  
  39. private 
  40.  
  41.     type Simple_Key_Listener is new Simple_Action_Listener and 
  42.                                     Key_Listener with 
  43.         record 
  44.             key       : Integer; 
  45.             modifiers : Modifiers_Pattern; 
  46.             id        : Action_Id; 
  47.             object    : access Target'Class := null; 
  48.             handler   : A_Handler := null; 
  49.         end record; 
  50.  
  51.     -- Calls the handler method of the object if action's Action_Id matches the 
  52.     -- Action_Id given at construction, and the modifiers pressed during the 
  53.     -- action match the Modifiers_Pattern given at construction. 'handled' will 
  54.     -- be returned as True if the handler method is invoked. 
  55.     procedure Handle_Action( this    : access Simple_Key_Listener; 
  56.                              action  : A_Key_Action; 
  57.                              handled : out Boolean ); 
  58.  
  59. end Widgets.Simple_Key_Listeners;