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.Buttons;                   use Widgets.Buttons; 
  10.  
  11. private with Widgets.Scrollbars; 
  12.  
  13. package Widgets.Containers.Scroll_Panes is 
  14.  
  15.     -- A Scroll_Pane is a simple container widget with horizontal and 
  16.     -- vertical scrollbars that control a client widget's viewport. The client 
  17.     -- is displayed within the Scroll_Pane's content area as a child widget. 
  18.     -- Clients should implement the Scrollable interface to support scrolling. 
  19.     type Scroll_Pane is new Container and Button_Listener with private; 
  20.     type A_Scroll_Pane is access all Scroll_Pane'Class; 
  21.  
  22.     -- Creates a new Scroll_Pane within 'view' with id 'id'. 
  23.     function Create_Scroll_Pane( view : not null access Game_Views.Game_View'Class; 
  24.                                  id   : String ) return A_Scroll_Pane; 
  25.     pragma Precondition( id'Length > 0 ); 
  26.     pragma Postcondition( Create_Scroll_Pane'Result /= null ); 
  27.  
  28.     -- Shows or hides the horizontal scrollbar. If 'draw' is True, the scrollbar 
  29.     -- will be drawn. Toggling the draw state of the scrollbar will repack the 
  30.     -- scroll pane. 
  31.     procedure Draw_Hbar( this : access Scroll_Pane; draw : Boolean ); 
  32.  
  33.     -- Shows or hides the vertical scrollbar. If 'draw' is True, the scrollbar 
  34.     -- will be drawn. Toggling the draw state of the scrollbar will repack the 
  35.     -- scroll pane. 
  36.     procedure Draw_Vbar( this : access Scroll_Pane; draw : Boolean ); 
  37.  
  38.     -- Sets the single client widget of the scroll pane. If the scroll pane 
  39.     -- already has a client, the old one will be deleted. The client widget 
  40.     -- should implement the Scrollable interface to support scrolling. 'client' 
  41.     -- will be consumed. 
  42.     procedure Set_Client( this   : access Scroll_Pane; 
  43.                           client : in out A_Widget ); 
  44.     pragma Postcondition( client = null ); 
  45.  
  46.     -- Sets the padding (in pixels) between the edges of the client and the 
  47.     -- edges of the scroll pane and scroll bars. See diagram below. 
  48.     -- 
  49.     --  padding   padding 
  50.     --  --        -- 
  51.     -- +------------+--+ 
  52.     -- |            |##|  | padding 
  53.     -- |  +------+  |v | 
  54.     -- |  |client|  |b | 
  55.     -- |  |      |  |a | 
  56.     -- |  +------+  |r | 
  57.     -- |            |##|  | padding 
  58.     -- +------------+--+ 
  59.     -- |#   hbar   #|//| 
  60.     -- +------------+--+ 
  61.     procedure Set_Padding( this : access Scroll_Pane; padding : Natural ); 
  62.  
  63. private 
  64.  
  65.     use Widgets.Scrollbars; 
  66.  
  67.     type Scroll_Pane is new Container and Button_Listener with 
  68.         record 
  69.             client   : A_Widget := null; 
  70.             hscroll  : A_H_Scrollbar := null; 
  71.             vscroll  : A_V_Scrollbar := null; 
  72.             left, 
  73.             right, 
  74.             up, 
  75.             down     : A_Button := null; 
  76.             drawHbar, 
  77.             drawVbar : Boolean := True; 
  78.             padding  : Natural := 0;      -- used for all sides 
  79.         end record; 
  80.  
  81.     -- Re-applies the scroll pane's child layout, taking into account the 
  82.     -- visibility of the scroll bars and the padding distance around the client. 
  83.     procedure Adjust_Layout( this : access Scroll_Pane ); 
  84.  
  85.     procedure Construct( this : access Scroll_Pane; 
  86.                          view : not null access Game_Views.Game_View'Class; 
  87.                          id   : String ); 
  88.     pragma Precondition( id'Length > 0 ); 
  89.  
  90.     -- Draws the scroll pane's background, including the small square in the 
  91.     -- lower right that appears when both scroll bars are visible. 
  92.     procedure Draw_Content( this : access Scroll_Pane ); 
  93.  
  94.     -- Returns the client's scrolling increment, in pixels, in the X dimension. 
  95.     -- A default scroll increment will be returned if the scroll pane does not 
  96.     -- have a client, or the client does not implement Scrollable. 
  97.     function Get_Inc_X( this : access Scroll_Pane ) return Integer; 
  98.  
  99.     -- Returns the client's scrolling increment, in pixels, in the Y dimension. 
  100.     -- A default scroll increment will be returned if the scroll pane does not 
  101.     -- have a client, or the client does not implement Scrollable. 
  102.     function Get_Inc_Y( this : access Scroll_Pane ) return Integer; 
  103.  
  104.     -- Handles Press and Held actions from the buttons at the ends of the scroll 
  105.     -- bars. 
  106.     procedure Handle_Action( this   : access Scroll_Pane; 
  107.                              action : A_Button_Action ); 
  108.  
  109.     -- Handles mouse scroll wheel actions to scroll vertically, if the client 
  110.     -- doesn't handle them. 
  111.     procedure On_Mouse_Scroll( this    : access Scroll_Pane; 
  112.                                x, y    : Integer; 
  113.                                amount  : Integer; 
  114.                                handled : in out Boolean ); 
  115.  
  116.     -- Adjusts the child layout after a resize. 
  117.     procedure On_Resize( this : access Scroll_Pane ); 
  118.  
  119. end Widgets.Containers.Scroll_Panes;