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