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 Widgets.Menu_Items;                use Widgets.Menu_Items; 
  10.  
  11. package Widgets.Containers.Pulldown_Menus is 
  12.  
  13.     -- A Pulldown_Menu is a container for menu items in the window's menu bar. 
  14.     -- It automatically sizes itself to fit the Menu_Items it contains. 
  15.     type Pulldown_Menu is new Container and Menu_Listener with private; 
  16.     type A_Pulldown_Menu is access all Pulldown_Menu'Class; 
  17.  
  18.     -- Creates a new pulldown menu within 'view' with id 'id. 'text' is the 
  19.     -- name of the pulldown menu to be displayed in a parent menu. (ie: in the 
  20.     -- menu bar.) 
  21.     function Create_Pulldown_Menu( view : not null access Game_Views.Game_View'Class; 
  22.                                    id   : String; 
  23.                                    text : String ) return A_Pulldown_Menu; 
  24.     pragma Precondition( id'Length > 0 ); 
  25.     pragma Postcondition( Create_Pulldown_Menu'Result /= null ); 
  26.  
  27.     -- Adds a Menu_Item to the bottom of the pulldown menu. 'item' will be 
  28.     -- consumed. 
  29.     procedure Add_Menu_Item( this : access Pulldown_Menu; 
  30.                              item : in out A_Menu_Item ); 
  31.     pragma Precondition( item /= null ); 
  32.     pragma Postcondition( item = null ); 
  33.  
  34.     -- Returns the pulldown menu's text to be displayed on the menu bar. 
  35.     function Get_Text( this : access Pulldown_Menu ) return String; 
  36.  
  37. private 
  38.  
  39.     type Pulldown_Menu is new Container and Menu_Listener with 
  40.         record 
  41.             text : Unbounded_String; 
  42.         end record; 
  43.  
  44.     -- Constructs the pulldown menu. 
  45.     procedure Construct( this    : access Pulldown_Menu; 
  46.                          view    : not null access Game_Views.Game_View'Class; 
  47.                          id      : String; 
  48.                          text    : String ); 
  49.     pragma Precondition( id'Length > 0 ); 
  50.  
  51.     -- Draws the background of the pulldown menu. 
  52.     procedure Draw_Content( this : access Pulldown_Menu ); 
  53.  
  54.     -- Returns the minimum height of the pulldown menu, based on the combined 
  55.     -- heights of the children. 
  56.     function Get_Min_Height( this : access Pulldown_Menu ) return Natural; 
  57.  
  58.     -- Returns the minimum width of the pulldown menu, based on the width of the 
  59.     -- widest child. 
  60.     function Get_Min_Width( this : access Pulldown_Menu ) return Natural; 
  61.  
  62.     -- Handles Menu_Actions, hiding the pulldown menu when a child is clicked. 
  63.     procedure Handle_Action( this   : access Pulldown_Menu; 
  64.                              action : A_Menu_Action ); 
  65.  
  66.     -- Packs the children and then the pulldown menu. 
  67.     procedure Pack( this : access Pulldown_Menu ); 
  68.  
  69.     -- Removes 'item' from the pulldown menu container. 
  70.     procedure Remove_Menu_Item( this : access Pulldown_Menu; 
  71.                                 item : not null A_Menu_Item ); 
  72.  
  73.     -- Returns a string representation of the pulldown menu. Useful for 
  74.     -- debugging purposes. 
  75.     function To_String( this : access Pulldown_Menu ) return String; 
  76.  
  77. end Widgets.Containers.Pulldown_Menus;