1. package Widgets.Scrollbars is 
  2.  
  3.     -- An abstract scrollbar widget. A scrollbar has a client widget that it is 
  4.     -- responsible for scrolling. The amount that can be scrolled is the 
  5.     -- difference between the client's content region and its viewport. 
  6.     type Scrollbar is abstract new Widget and Resize_Listener with private; 
  7.  
  8.     -- Calculates where the scroll button will be drawn on the scrollbar, based 
  9.     -- on the size of the client widget and the location and size of its 
  10.     -- viewport. 'min' and 'max' are in the range of 0..[scroll_dimension]-1, in 
  11.     -- pixels. For example, if this is a horizontal scrollbar for a client that 
  12.     -- is completely visible in the horizontal dimension, then 'min' will return 
  13.     -- 0 and 'max' will return Scrollbar.Get_Width - 1. This is because the 
  14.     -- button should entirely fill the area scrollbar. 
  15.     procedure Calculate_Button( this : access Scrollbar; min, max : out Integer ) is abstract; 
  16.  
  17.     -- Sets the client widget of the scrollbar; ie: the widget that will be 
  18.     -- controlled. 'client' will not belong to the scrollbar. The client of a 
  19.     -- scrollbar should be removed before its deleted. If 'client' is null, the 
  20.     -- scrollbar will have no client. 
  21.     procedure Set_Client( this : not null access Scrollbar'Class; client : A_Widget ); 
  22.  
  23.     ---------------------------------------------------------------------------- 
  24.  
  25.     -- A horizontal scrollbar widget. 
  26.     type H_Scrollbar is new Scrollbar with private; 
  27.     type A_H_Scrollbar is access all H_Scrollbar'Class; 
  28.  
  29.     -- Creates a horizontal scrollbar within 'view' with widget id 'id'. 
  30.     function Create_H_Scrollbar( view : not null access Game_Views.Game_View'Class; 
  31.                                  id   : String ) return A_H_Scrollbar; 
  32.     pragma Precondition( id'Length > 0 ); 
  33.     pragma Postcondition( Create_H_Scrollbar'Result /= null ); 
  34.  
  35.     ---------------------------------------------------------------------------- 
  36.  
  37.     -- A vertical scrollbar widget. 
  38.     type V_Scrollbar is new Scrollbar with private; 
  39.     type A_V_Scrollbar is access all V_Scrollbar'Class; 
  40.  
  41.     -- Creates a vertical scrollbar within 'view' with widget id 'id'. 
  42.     function Create_V_Scrollbar( view : not null access Game_Views.Game_View'Class; 
  43.                                  id   : String ) return A_V_Scrollbar; 
  44.     pragma Precondition( id'Length > 0 ); 
  45.     pragma Postcondition( Create_V_Scrollbar'Result /= null ); 
  46.  
  47. private 
  48.  
  49.     type Scrollbar is abstract new Widget and Resize_Listener with 
  50.         record 
  51.             client : A_Widget := null;      -- widget to scroll 
  52.             pageUp,                         -- true when paging up 
  53.             pageDown,                       -- true when paging down 
  54.             dragging : Boolean := False;    -- true when button is dragged 
  55.             dragPos  : Integer := 0; 
  56.         end record; 
  57.  
  58.     procedure Construct( this : access Scrollbar; 
  59.                          view : not null access Game_Views.Game_View'Class; 
  60.                          id   : String ); 
  61.     pragma Precondition( id'Length > 0 ); 
  62.  
  63.     procedure Delete( this : in out Scrollbar ); 
  64.  
  65.     procedure Handle_Action( this   : access Scrollbar; 
  66.                              action : A_Resize_Action ); 
  67.  
  68.     procedure Handle_Mouse_Release( this : access Scrollbar; 
  69.                                     evt  : not null A_Mouse_Button_Event ); 
  70.  
  71.     ---------------------------------------------------------------------------- 
  72.  
  73.     type H_Scrollbar is new Scrollbar with null record; 
  74.  
  75.     procedure Calculate_Button( this : access H_Scrollbar; min, max : out Integer ); 
  76.  
  77.     procedure Draw_Content( this : access H_Scrollbar; dc : Drawing_Context ); 
  78.  
  79.     procedure Handle_Mouse_Held( this : access H_Scrollbar; 
  80.                                  evt  : not null A_Mouse_Button_Event ); 
  81.  
  82.     procedure Handle_Mouse_Move( this : access H_Scrollbar; 
  83.                                  evt  : not null A_Mouse_Event ); 
  84.  
  85.     procedure Handle_Mouse_Press( this : access H_Scrollbar; 
  86.                                   evt  : not null A_Mouse_Button_Event ); 
  87.  
  88.     ---------------------------------------------------------------------------- 
  89.  
  90.     type V_Scrollbar is new Scrollbar with null record; 
  91.  
  92.     procedure Calculate_Button( this : access V_Scrollbar; min, max : out Integer ); 
  93.  
  94.     procedure Draw_Content( this : access V_Scrollbar; dc : Drawing_Context ); 
  95.  
  96.     procedure Handle_Mouse_Held( this : access V_Scrollbar; 
  97.                                  evt  : not null A_Mouse_Button_Event ); 
  98.  
  99.     procedure Handle_Mouse_Move( this : access V_Scrollbar; 
  100.                                  evt  : not null A_Mouse_Event ); 
  101.  
  102.     procedure Handle_Mouse_Press( this : access V_Scrollbar; 
  103.                                   evt  : not null A_Mouse_Button_Event ); 
  104.  
  105. end Widgets.Scrollbars;