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