1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --   Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet   -- 
  5. --                Copyright (C) 2000-2007 AdaCore                    -- 
  6. --                                                                   -- 
  7. -- This library is free software; you can redistribute it and/or     -- 
  8. -- modify it under the terms of the GNU General Public               -- 
  9. -- License as published by the Free Software Foundation; either      -- 
  10. -- version 2 of the License, or (at your option) any later version.  -- 
  11. --                                                                   -- 
  12. -- This library is distributed in the hope that it will be useful,   -- 
  13. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  14. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  15. -- General Public License for more details.                          -- 
  16. --                                                                   -- 
  17. -- You should have received a copy of the GNU General Public         -- 
  18. -- License along with this library; if not, write to the             -- 
  19. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  20. -- Boston, MA 02111-1307, USA.                                       -- 
  21. --                                                                   -- 
  22. -- -- -- -- -- -- -- -- -- -- -- --
  23. ----------------------------------------------------------------------- 
  24.  
  25. --  <description> 
  26. --  A Gtk_Spin_Button is a single line text editing widget for text that 
  27. --  represents a number. At the right hand side of the text line there are 
  28. --  small up- and down arrow buttons for incrementing or decrementing 
  29. --  (spinning) the number within a given range. 
  30. --  It allows the value to have zero or a number of decimal places and 
  31. --  to be incremented/decremented in configurable steps. 
  32. --  The action of holding down one of the buttons optionally results in an 
  33. --  acceleration of change in the value according to how long it is 
  34. --  depressed. 
  35. -- 
  36. --  See Gtk.GEntry for a text editing widget without spin buttons. 
  37. --  </description> 
  38. --  <c_version>2.8.17</c_version> 
  39. --  <group>Numeric/Text Data Entry</group> 
  40. --  <screenshot>gtk-spin_button</screenshot> 
  41. --  <testgtk>create_spin.adb</testgtk> 
  42.  
  43. with Glib.Generic_Properties; 
  44. with Glib.Properties; 
  45. with Gtk.Adjustment; 
  46. with Gtk.GEntry; 
  47.  
  48. package Gtk.Spin_Button is 
  49.  
  50.    type Gtk_Spin_Button_Record is new Gtk.GEntry.Gtk_Entry_Record with private; 
  51.    type Gtk_Spin_Button is access all Gtk_Spin_Button_Record'Class; 
  52.  
  53.    type Gtk_Spin_Button_Update_Policy is 
  54.      (Update_Always, 
  55.       --  Update always, errors are ignored while converting text into a 
  56.       --  numeric value. 
  57.  
  58.       Update_If_Valid 
  59.       --  The spin button's value gets changed if the text input is a numeric 
  60.       --  value that is within the range specified by the adjustment. 
  61.      ); 
  62.    --  Determine the update policy of the spin button which affects the 
  63.    --  behaviour when parsing inserted text and syncing its value with the 
  64.    --  values of the adjustment. 
  65.    pragma Convention (C, Gtk_Spin_Button_Update_Policy); 
  66.  
  67.    type Gtk_Spin_Type is 
  68.      (Spin_Step_Forward, 
  69.       Spin_Step_Backward, 
  70.       Spin_Page_Forward, 
  71.       Spin_Page_Backward, 
  72.       Spin_Home, 
  73.       Spin_End, 
  74.       Spin_User_Defined); 
  75.    --  Determine how manual spinning should be done. 
  76.    --  See also the Spin procedure. 
  77.    pragma Convention (C, Gtk_Spin_Type); 
  78.  
  79.    procedure Gtk_New 
  80.      (Spin_Button : out Gtk_Spin_Button; 
  81.       Adjustment  : Gtk.Adjustment.Gtk_Adjustment; 
  82.       Climb_Rate  : Gdouble; 
  83.       The_Digits  : Gint); 
  84.    --  Create a spin button with the given parameters. 
  85.    --  Adjustment contains the range, current value, step value and 
  86.    --  "page" value. The step value is the increment/decrement when pressing 
  87.    --  mouse button 1 on a button; the page value when mouse button 2 is 
  88.    --  pressed. Additionally, mouse button 3 can be used to jump directly to 
  89.    --  the or lower values when used to select one of the buttons. 
  90.    --  Climb_Rate takes a value between 0.0 and 1.0 and indicates the 
  91.    --  amount of acceleration that the Spin Button has. 
  92.    --  The_Digits is the number of digits behind the decimal point to be 
  93.    --  displayed for the value. 
  94.  
  95.    procedure Gtk_New 
  96.      (Spin_Button : out Gtk_Spin_Button; 
  97.       Min         : Gdouble; 
  98.       Max         : Gdouble; 
  99.       Step        : Gdouble); 
  100.    --  Same as above, but with explicit range instead of an adjustment. 
  101.    --  The adjustment associated with Spin_Button is created internally. 
  102.  
  103.    procedure Initialize 
  104.      (Spin_Button : access Gtk_Spin_Button_Record'Class; 
  105.       Adjustment  : Gtk.Adjustment.Gtk_Adjustment; 
  106.       Climb_Rate  : Gdouble; 
  107.       The_Digits  : Gint); 
  108.    --  Internal initialization function. 
  109.    --  See the section "Creating your own widgets" in the documentation. 
  110.  
  111.    procedure Initialize 
  112.      (Spin_Button : access Gtk_Spin_Button_Record'Class; 
  113.       Min         : Gdouble; 
  114.       Max         : Gdouble; 
  115.       Step        : Gdouble); 
  116.    --  Internal initialization function. 
  117.  
  118.    function Get_Type return Gtk.Gtk_Type; 
  119.    --  Return the internal value associated with a Gtk_Spin_Button. 
  120.  
  121.    procedure Set_Adjustment 
  122.      (Spin_Button : access Gtk_Spin_Button_Record; 
  123.       Adjustment  : Gtk.Adjustment.Gtk_Adjustment); 
  124.    function Get_Adjustment 
  125.      (Spin_Button : access Gtk_Spin_Button_Record) 
  126.       return Gtk.Adjustment.Gtk_Adjustment; 
  127.    --  Set or Get the adjustment settings of the spin button. 
  128.  
  129.    procedure Set_Digits 
  130.      (Spin_Button : access Gtk_Spin_Button_Record; 
  131.       The_Digits  : Guint); 
  132.    function Get_Digits 
  133.      (Spin_Button : access Gtk_Spin_Button_Record) return Guint; 
  134.    --  Set or Get number of decimals of the spin button. 
  135.  
  136.    procedure Set_Increments 
  137.      (Spin_Button : access Gtk_Spin_Button_Record; 
  138.       Step        : Gdouble; 
  139.       Page        : Gdouble); 
  140.    procedure Get_Increments 
  141.      (Spin_Button : access Gtk_Spin_Button_Record; 
  142.       Step        : out Gdouble; 
  143.       Page        : out Gdouble); 
  144.    --  Set or Get the increments for a single step and a page move. 
  145.  
  146.    procedure Set_Range 
  147.      (Spin_Button : access Gtk_Spin_Button_Record; 
  148.       Min         : Gdouble; 
  149.       Max         : Gdouble); 
  150.    procedure Get_Range 
  151.      (Spin_Button : access Gtk_Spin_Button_Record; 
  152.       Min         : out Gdouble; 
  153.       Max         : out Gdouble); 
  154.    --  Set or Get range of the spin button. 
  155.  
  156.    procedure Set_Value 
  157.      (Spin_Button : access Gtk_Spin_Button_Record; 
  158.       Value       : Gdouble); 
  159.    function Get_Value 
  160.      (Spin_Button : access Gtk_Spin_Button_Record) return Gdouble; 
  161.    --  Set or Get the current value of the spin button in a double. 
  162.  
  163.    function Get_Value_As_Int 
  164.      (Spin_Button : access Gtk_Spin_Button_Record) return Gint; 
  165.    --  Return the current value of the spin button in an integer. 
  166.  
  167.    procedure Set_Update_Policy 
  168.      (Spin_Button : access Gtk_Spin_Button_Record; 
  169.       Policy      : Gtk_Spin_Button_Update_Policy); 
  170.    function Get_Update_Policy 
  171.      (Spin_Button : access Gtk_Spin_Button_Record) 
  172.       return Gtk_Spin_Button_Update_Policy; 
  173.    --  Set the update policy of the spin button. 
  174.    --  See Gtk_Spin_Button_Update_Policy for the meaning of Policy. 
  175.  
  176.    procedure Set_Numeric 
  177.      (Spin_Button : access Gtk_Spin_Button_Record; 
  178.       Numeric     : Boolean); 
  179.    function Get_Numeric 
  180.      (Spin_Button : access Gtk_Spin_Button_Record) return Boolean; 
  181.    --  If Numeric is True, then only a numeric value can be typed in the 
  182.    --  text entry, otherwise also nonnumeric text. 
  183.  
  184.    procedure Spin 
  185.      (Spin_Button : access Gtk_Spin_Button_Record; 
  186.       Direction   : Gtk_Spin_Type; 
  187.       Step        : Gdouble); 
  188.    --  Set the value of the spin button relative to its current value. 
  189.    --  Depending on Direction, it will be incremented or decremented with 
  190.    --  the step value. 
  191.  
  192.    procedure Set_Wrap 
  193.      (Spin_Button : access Gtk_Spin_Button_Record; Wrap : Boolean); 
  194.    function Get_Wrap 
  195.      (Spin_Button : access Gtk_Spin_Button_Record) return Boolean; 
  196.    --  Set whether the spin button should "wrap around" when exceeding the 
  197.    --  upper and lower limits. 
  198.  
  199.    procedure Set_Snap_To_Ticks 
  200.     (Spin_Button   : access Gtk_Spin_Button_Record; 
  201.      Snap_To_Ticks : Boolean); 
  202.    function Get_Snap_To_Ticks 
  203.     (Spin_Button : access Gtk_Spin_Button_Record) return Boolean; 
  204.    --  Set the spin button to round the value to the nearest step value 
  205.    --  which is set within its adjustment settings. 
  206.  
  207.    procedure Update (Spin_Button : access Gtk_Spin_Button_Record); 
  208.    --  Manually force an update of the spin button. 
  209.  
  210.    ---------------- 
  211.    -- Properties -- 
  212.    ---------------- 
  213.  
  214.    --  <properties> 
  215.    --  The following properties are defined for this widget. See 
  216.    --  Glib.Properties for more information on properties. 
  217.    -- 
  218.    --  Name:  Adjustment_Property 
  219.    --  Type:  Object 
  220.    --  Descr: The adjustment that holds the value of the spinbutton 
  221.    -- 
  222.    --  Name:  Climb_Rate_Property 
  223.    --  Type:  Double 
  224.    --  Descr: The acceleration rate when you hold down a button 
  225.    -- 
  226.    --  Name:  Digits_Property 
  227.    --  Type:  Uint 
  228.    --  Descr: The number of decimal places to display 
  229.    -- 
  230.    --  Name:  Numeric_Property 
  231.    --  Type:  Boolean 
  232.    --  Descr: Whether non-numeric characters should be ignored 
  233.    -- 
  234.    --  Name:  Snap_To_Ticks_Property 
  235.    --  Type:  Boolean 
  236.    --  Descr: Whether erroneous values are automatically changed to a spin 
  237.    --         button's nearest step increment 
  238.    -- 
  239.    --  Name:  Update_Policy_Property 
  240.    --  Type:  Enum 
  241.    --  Descr: Whether the spin button should update always, or only when the 
  242.    --         value is legal 
  243.    -- 
  244.    --  Name:  Value_Property 
  245.    --  Type:  Double 
  246.    --  Descr: Reads the current value, or sets a new value 
  247.    -- 
  248.    --  Name:  Wrap_Property 
  249.    --  Type:  Boolean 
  250.    --  Descr: Whether a spin button should wrap upon reaching its limits 
  251.    -- 
  252.    --  </properties> 
  253.  
  254.    package Spin_Button_Update_Policy_Properties is new 
  255.      Glib.Generic_Properties.Generic_Internal_Discrete_Property 
  256.        (Gtk_Spin_Button_Update_Policy); 
  257.    type Property_Spin_Button_Update_Policy_Type is new 
  258.      Spin_Button_Update_Policy_Properties.Property; 
  259.  
  260.    Adjustment_Property    : constant Glib.Properties.Property_Object; 
  261.    Climb_Rate_Property    : constant Glib.Properties.Property_Double; 
  262.    Digits_Property        : constant Glib.Properties.Property_Uint; 
  263.    Numeric_Property       : constant Glib.Properties.Property_Boolean; 
  264.    Snap_To_Ticks_Property : constant Glib.Properties.Property_Boolean; 
  265.    Update_Policy_Property : constant Property_Spin_Button_Update_Policy_Type; 
  266.    Value_Property         : constant Glib.Properties.Property_Double; 
  267.    Wrap_Property          : constant Glib.Properties.Property_Boolean; 
  268.  
  269.    ------------- 
  270.    -- Signals -- 
  271.    ------------- 
  272.  
  273.    --  <signals> 
  274.    --  The following new signals are defined for this widget: 
  275.    -- 
  276.    --  - "change_value" 
  277.    --    procedure Handler 
  278.    --      (Spin : access Gtk_Spin_Button_Record'Class; 
  279.    --       Typ  : Gtk_Scroll_Type); 
  280.    --    You should emit this signal to request a change in the value of the 
  281.    --    spin button. This is mostly useful as a keybinding, and is bound, by 
  282.    --    default, to the arrow keys, PageUp, PageDown, Home and End keys. 
  283.    -- 
  284.    --  - "input" 
  285.    --    procedure Handler 
  286.    --       (Spin  : access Gtk_Spin_Button_Record'Class; 
  287.    --        Value : out Gint); 
  288.    --    ??? 
  289.    -- 
  290.    --  - "output" 
  291.    --    procedure Handler (Spin : access Gtk_Spin_Button_Record'Class); 
  292.    --    ??? 
  293.    -- 
  294.    --  - "value_changed" 
  295.    --    procedure Handler (Spin : access Gtk_Spin_Button_Record'Class); 
  296.    --    Emitted when the value of the spin button has changed. 
  297.    -- 
  298.    --  </signals> 
  299.  
  300.    Signal_Change_Value  : constant Glib.Signal_Name := "change_value"; 
  301.    Signal_Input         : constant Glib.Signal_Name := "input"; 
  302.    Signal_Output        : constant Glib.Signal_Name := "output"; 
  303.    Signal_Value_Changed : constant Glib.Signal_Name := "value_changed"; 
  304.  
  305. private 
  306.    type Gtk_Spin_Button_Record is new Gtk.GEntry.Gtk_Entry_Record 
  307.    with null record; 
  308.  
  309.    Adjustment_Property : constant Glib.Properties.Property_Object := 
  310.      Glib.Properties.Build ("adjustment"); 
  311.    Climb_Rate_Property : constant Glib.Properties.Property_Double := 
  312.      Glib.Properties.Build ("climb-rate"); 
  313.    Digits_Property : constant Glib.Properties.Property_Uint := 
  314.      Glib.Properties.Build ("digits"); 
  315.    Numeric_Property : constant Glib.Properties.Property_Boolean := 
  316.      Glib.Properties.Build ("numeric"); 
  317.    Snap_To_Ticks_Property : constant Glib.Properties.Property_Boolean := 
  318.      Glib.Properties.Build ("snap-to-ticks"); 
  319.    Update_Policy_Property : constant Property_Spin_Button_Update_Policy_Type := 
  320.      Build ("update-policy"); 
  321.    Value_Property : constant Glib.Properties.Property_Double := 
  322.      Glib.Properties.Build ("value"); 
  323.    Wrap_Property : constant Glib.Properties.Property_Boolean := 
  324.      Glib.Properties.Build ("wrap"); 
  325.  
  326.    pragma Import (C, Get_Type, "gtk_spin_button_get_type"); 
  327. end Gtk.Spin_Button; 
  328.  
  329. --  The following function is for the sake of the C++ binding only: 
  330. --  No binding: gtk_spin_button_configure