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.Panels.Popups is 
  12.  
  13.     -- A Popup widget is a context-sensitive menu widget that contains a single 
  14.     -- column of Menu_Items. It allows widgets to register for notifications 
  15.     -- when the widget loses visibility. It's minimum size is calculated from 
  16.     -- the minimum size of its children, so its size can be computed 
  17.     -- automatically. The popup widget registers itself as a listener for menu 
  18.     -- items added to it, and hides automatically when one is activated. 
  19.     type Popup is new Panel and Menu_Listener with private; 
  20.     type A_Popup is access all Popup'Class; 
  21.  
  22.     -- Creates a new Popup menu within 'view' with id 'id'. If 'title' or 'icon' 
  23.     -- are given a value, the menu will have a title bar like a standard panel, 
  24.     -- displaying the popup menu's title text and/or icon. 'icon' is the 
  25.     -- filename of the icon in the theme's tile library. 
  26.     function Create_Popup( view  : not null access Game_Views.Game_View'Class; 
  27.                            id    : String; 
  28.                            title : String := ""; 
  29.                            icon  : String := "" ) return A_Popup; 
  30.     pragma Precondition( id'Length > 0 ); 
  31.     pragma Postcondition( Create_Popup'Result /= null ); 
  32.  
  33.     -- Appends an item to the menu. Note that a Constraint_Error will be raised 
  34.     -- if 'child' is not a Menu_Item. Otherwise, if 'consume' is True then 
  35.     -- 'child' will be consumed. Regardless of the value of 'consume', 'child' 
  36.     -- will belong to the Popup widget. 
  37.     procedure Add_Menu_Item( this : access Popup; 
  38.                              item : in out A_Menu_Item ); 
  39.     pragma Precondition( item /= null ); 
  40.     pragma Postcondition( item = null ); 
  41.  
  42. private 
  43.  
  44.     type Popup is new Panel and Menu_Listener with null record; 
  45.  
  46.     procedure Construct( this  : access Popup; 
  47.                          view  : not null access Game_Views.Game_View'Class; 
  48.                          id    : String; 
  49.                          title : String; 
  50.                          icon  : String ); 
  51.     pragma Precondition( id'Length > 0 ); 
  52.  
  53.     -- Returns the minimum height of the Popup menu, calculated as a sum of the 
  54.     -- heights of the menu's items. If the minimum height of the Popup was 
  55.     -- manually specified, it will override. 
  56.     function Get_Min_Height( this : access Popup ) return Natural; 
  57.  
  58.     -- Returns the minimum width of the Popup menu, calculated as the maximum 
  59.     -- width of the menu's items. If the minimum width of the Popup was 
  60.     -- manually specified, it will override. 
  61.     function Get_Min_Width( this : access Popup ) return Natural; 
  62.  
  63.     -- Hides the widget when a child menu item is activated. 
  64.     procedure Handle_Action( this   : access Popup; 
  65.                              action : A_Menu_Action ); 
  66.  
  67.     -- Packs the Popup menu, automatically adjusting the layout of each item 
  68.     -- to fit in the menu. If the height of the popup menu was specified to be 
  69.     -- larger than the space needed by its children, the empty space will be at 
  70.     -- the bottom. The children will fill the entire width of the menu. 
  71.     procedure Pack( this : access Popup ); 
  72.  
  73. end Widgets.Containers.Panels.Popups;