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