--
-- Copyright (c) 2012 Kevin Wellwood
-- All rights reserved.
--
-- This source code is distributed under the Modified BSD License. For terms and
-- conditions, see license.txt.
--
private with Ada.Containers.Indefinite_Doubly_Linked_Lists;
package Widgets.Containers is
-- A Container widget is a parent widget that contains multiple child
-- widgets. Each child widget is drawn within the content area of the
-- parent. Widget layouts applied to child widgets are relative to the
-- content area of their container. An input event not handled by a widget
-- will be passed up the widget tree to its container.
type Container is abstract new Widget with private;
type A_Container is access all Container'Class;
-- Applies the container's special child layout to the given child widget.
procedure Apply_Container_Layout( this : access Container;
child : not null A_Widget );
-- Brings the 'child' widget to the front of the drawing Z-order within this
-- container. If 'child' overlaps any sibling widgets, it will be drawn on
-- top.
procedure Bring_To_Front( this : access Container;
child : not null A_Widget );
-- Gives focus to 'target'. If this widget is not rooted with a window, the
-- operation will be ignored. If the widget does not accept focus, the next
-- possible candidate will be receive focus.
procedure Give_Focus( this : access Container; target : not null A_Widget );
private
WIDGET_NOT_FOUND : exception;
-- provides a linked list of widgets
package Widget_Lists is new Ada.Containers.Indefinite_Doubly_Linked_Lists( A_Widget, "=" );
----------------------------------------------------------------------------
type Container is abstract new Widget with
record
children : Widget_Lists.List;
childLayout : A_Layout := null;
end record;
procedure Delete( this : in out Container );
-- Adds 'child' as a child widget of this container. The child's parent is
-- set by this procedure. If 'consume' is True, 'child' will be consumed,
-- otherwise it will be left as-is. In either case, however, the Container
-- will own 'child' after this is called, and will delete it if it's still a
-- child at the time of deletion.
procedure Add_Child( this : access Container;
child : in out A_Widget;
consume : Boolean := True );
pragma Precondition( child /= null );
pragma Postcondition( consume xor child /= null );
-- Removes and deletes a child widget. If the given widget is not a child
-- then a WIDGET_NOT_FOUND exception will be raised. 'child' will be
-- consumed if successful.
procedure Delete_Child( this : access Container;
child : in out A_Widget );
pragma Precondition( child /= null );
pragma Postcondition( child = null );
-- Removes and deletes all child widgets.
procedure Delete_Children( this : access Container );
-- Draws self before drawing children, in a back-to-front order.
procedure Draw( this : access Container );
-- Draws each of the children onto the widget's drawing area.
procedure Draw_Children( this : access Container );
-- Draws the container's background content behind its children. This will
-- be called before child widgets are drawn on top of the widget's
-- background content. Override this procedure to draw the container
-- widget's background.
procedure Draw_Content( this : access Container ) is null;
-- Draws the container's foreground content over its children. This will be
-- called after child widgets are drawn. Override this procedure to draw the
-- container widget's foreground.
procedure Draw_Content_Foreground( this : access Container ) is null;
-- Returns the child widget (or self) containing the given coordinates
-- relative to the widget's viewport, and the widget coordinates that
-- 'x','y' map to ('wx','wy') within the found widget's content area.
procedure Find_Widget_At( this : access Container;
x, y : Integer;
wx, wy : out Integer;
found : out A_Widget );
-- Invokes Handle_Rooted on each of the children and then handles the rooted
-- notification for itself.
procedure Handle_Rooted( this : access Container; rooted : Boolean );
-- Invokes Handle_Shown on each of the children and then handles the
-- showing notification for itself.
procedure Handle_Shown( this : access Container; shown : Boolean );
-- Calls Pack on each of the children after packing self.
procedure Pack( this : access Container );
-- Removes the widget from the child list without deleting it. The child's
-- parent reference is set to null. An exception will be raised if 'child'
-- is not a child of the widget.
procedure Remove_Child( this : access Container;
child : not null A_Widget );
end Widgets.Containers;