1. package Widgets.Buttons.Checkboxes is 
  2.  
  3.     -- A Checkbox is a variation of a button that toggles its state when 
  4.     -- pressed with a mouse or activated with the keyboard. It differs from a 
  5.     -- toggle button in that it has a checkbox icon that changes with the state, 
  6.     -- not a pressed/released look. It's state remains until the mouse presses 
  7.     -- on it again to toggle the state back again. 
  8.     type Checkbox is new Button with private; 
  9.     type A_Checkbox is access all Checkbox'Class; 
  10.  
  11.     -- Creates a new checkbox within 'view' with id 'id'. 'text' is the 
  12.     -- checkbox's text and 'icon' is the filename to use for the icon next to 
  13.     -- the text. Both are optional but at least one should be specified or the 
  14.     -- checkbox will be blank. The default state of the new checkbox is False. 
  15.     function Create_Checkbox( view : not null access Game_Views.Game_View'Class; 
  16.                               id   : String; 
  17.                               text : String := ""; 
  18.                               icon : String := "" ) return A_Checkbox; 
  19.     pragma Precondition( id'Length > 0 ); 
  20.     pragma Postcondition( Create_Checkbox'Result /= null ); 
  21.  
  22.     -- Sets the filename of the checkmark icon to display in the box when the 
  23.     -- checkbox is checked. The icon should be BOX_SIZE pixels square. 
  24.     procedure Set_Check_Icon( this : access Checkbox; icon : String ); 
  25.  
  26. private 
  27.  
  28.     -- the width of the checkmark icon 
  29.     BOX_SIZE : constant := 12; 
  30.  
  31.     ---------------------------------------------------------------------------- 
  32.  
  33.     type Checkbox is new Button with 
  34.         record 
  35.             checkIcon : Natural := 0; 
  36.         end record; 
  37.  
  38.     -- Draws the checkbox widget. 
  39.     procedure Draw_Content( this : access Checkbox; dc : Drawing_Context ); 
  40.  
  41.     -- Returns the minimum height of the checkbox, based on its icon and text. 
  42.     function Get_Min_Height( this : access Checkbox ) return Natural; 
  43.  
  44.     -- Returns the minimum width of the button, based on its icon and text. 
  45.     function Get_Min_Width( this : access Checkbox ) return Natural; 
  46.  
  47.     -- Handles Space, Enter and Keypad-Enter keys to toggle the state of the 
  48.     -- checkbox. 
  49.     function Handle_Key_Press( this : access Checkbox; 
  50.                                evt  : not null A_Key_Event ) return Boolean; 
  51.  
  52.     -- Handles a left mouse button press to toggle the state of the checkbox. 
  53.     -- The other mouse buttons are not used. 
  54.     procedure Handle_Mouse_Press( this : access Checkbox; 
  55.                                   evt  : not null A_Mouse_Button_Event ); 
  56.  
  57. end Widgets.Buttons.Checkboxes;