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_Menu_Listener class provides a mechanism for registering 
  10. -- any method of a class, matching a certain prototype, as a menu action handler. 
  11. -- 
  12. -- Instantiate this package with the class and class-wide access type of an 
  13. -- object that will handle menu actions. 
  14. generic 
  15.     type Target (<>) is tagged limited private; 
  16. package Widgets.Menu_Items.Simple_Listeners is 
  17.  
  18.     type A_Handler is access 
  19.         procedure( object : not null access Target'Class; 
  20.                    action : A_Menu_Action ); 
  21.  
  22.     -- Invokes the 'handler' method of 'obj' for menu actions matching 'id'. 
  23.     function Listener( id      : Action_Id; 
  24.                        obj     : access Target'Class; 
  25.                        handler : not null A_Handler ) return A_Menu_Listener; 
  26.     pragma Postcondition( Listener'Result /= null ); 
  27.  
  28.     -- Invokes the 'handler' method of 'obj' for Menu_Selected actions. 
  29.     function Listener( obj     : access Target'Class; 
  30.                        handler : not null A_Handler ) return A_Menu_Listener; 
  31.  
  32. private 
  33.  
  34.     type Simple_Menu_Listener is new Simple_Action_Listener and 
  35.                                      Menu_Listener with 
  36.         record 
  37.             id      : Action_Id; 
  38.             object  : access Target'Class := null; 
  39.             handler : A_Handler := null; 
  40.         end record; 
  41.  
  42.     -- Invokes the handler procedure of the simple menu listener's target. 
  43.     procedure Handle_Action( this   : access Simple_Menu_Listener; 
  44.                              action : A_Menu_Action ); 
  45.  
  46. end Widgets.Menu_Items.Simple_Listeners;