1. private with Ada.Containers.Indefinite_Doubly_Linked_Lists; 
  2.  
  3. package Widgets.Containers is 
  4.  
  5.     type Container is abstract new Widget with private; 
  6.     type A_Container is access all Container'Class; 
  7.  
  8.     -- Adds 'child' as a child widget of this container. The child's parent is 
  9.     -- set by this procedure. 
  10.     procedure Add( this    : access Container; 
  11.                    child   : in out A_Widget; 
  12.                    consume : Boolean := True ); 
  13.     pragma Precondition( child /= null ); 
  14.     pragma Postcondition( consume xor child /= null ); 
  15.  
  16.     -- Brings the child widget to the front of the drawing Z-order within this 
  17.     -- container. 
  18.     procedure Bring_To_Front( this  : access Container; 
  19.                               child : not null A_Widget ); 
  20.  
  21.     -- Applies the container's special child layout to the given child widget. 
  22.     procedure Apply_Container_Layout( this  : access Container; 
  23.                                       child : not null A_Widget ); 
  24.  
  25.     -- Removes and deletes all child widgets. 
  26.     procedure Delete_Children( this : access Container ); 
  27.  
  28.     procedure Draw_Content( this : access Container; dc : Drawing_Context ) is abstract; 
  29.  
  30.     -- Removes the widget from the child list without deleting it. The child's 
  31.     -- parent reference is not modified. 
  32.     procedure Remove( this : access Container; child : not null A_Widget ); 
  33.  
  34. private 
  35.  
  36.     WIDGET_NOT_FOUND : exception; 
  37.  
  38.     package Widget_Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists( A_Widget, "=" ); 
  39.  
  40.     ---------------------------------------------------------------------------- 
  41.  
  42.     type Container is abstract new Widget with 
  43.         record 
  44.             childbmp        : A_Bitmap := null; 
  45.             children        : Widget_Lists.List; 
  46.             childLayout     : A_Layout := null; 
  47.  
  48.             -- If True, Draw_Content will be called a second time after drawing 
  49.             -- children, with the layer of the drawing context set to Foreground. 
  50.             -- This is so the widget can draw over its children. Setting this to 
  51.             -- True will cause Draw_Content to be called twice on every redraw, 
  52.             -- regardless of the container's dirty flag, which is expensive. 
  53.             drawForeground : Boolean := False; 
  54.         end record; 
  55.  
  56.     procedure Delete( this : in out Container ); 
  57.  
  58.     -- Removes and deletes a child widget. If the given widget is not a child 
  59.     -- then WIDGET_NOT_FOUND exception will be raised. Child will be consumed if 
  60.     -- successful. 
  61.     procedure Delete_Child( this : access Container; child : in out A_Widget ); 
  62.     pragma Precondition( child /= null ); 
  63.     pragma Postcondition( child = null ); 
  64.  
  65.     procedure Draw( this : access Container; 
  66.                     bmp  : not null A_Bitmap; 
  67.                     x, y : Integer ); 
  68.  
  69.     procedure Draw_Children( this : access Container; 
  70.                              bmp  : not null A_Bitmap ); 
  71.  
  72.     procedure Find_Widget( this   : access Container; 
  73.                            x, y   : Integer; 
  74.                            wx, wy : out Integer; 
  75.                            found  : out A_Widget ); 
  76.  
  77.     -- Calls Handle_Ancestor_Hidden on each of the children after handling 
  78.     -- Handle_Ancestor_Hidden for self. 
  79.     procedure Handle_Ancestor_Hidden( this : access Container ); 
  80.  
  81.     -- Calls Handle_Ancestor_Unhidden on each of the children after handling 
  82.     -- Handle_Ancestor_Unhidden for self. 
  83.     procedure Handle_Ancestor_Unhidden( this : access Container ); 
  84.  
  85.    -- Resizes each of the children after resizing self. 
  86.     procedure Handle_Resize( this : access Container ); 
  87.  
  88.     -- Calls Pack on each of the children after packing self. 
  89.     procedure Pack( this : access Container ); 
  90.  
  91.     procedure Set_Zoom( this : access Container; zoom : Float ); 
  92.  
  93. end Widgets.Containers;