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-2013, 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. -- As a special exception, if other files instantiate generics from  -- 
  23. -- this unit, or you link this unit with other files to produce an   -- 
  24. -- executable, this  unit  does not  by itself cause  the resulting  -- 
  25. -- executable to be covered by the GNU General Public License. This  -- 
  26. -- exception does not however invalidate any other reasons why the   -- 
  27. -- executable file  might be covered by the  GNU Public License.     -- 
  28. ----------------------------------------------------------------------- 
  29.  
  30. --  <description> 
  31. --  A scale is a horizontal or vertical widget that a user can slide to choose 
  32. --  a value in a given range. This is a kind of cursor, similar to what one 
  33. --  finds on audio systems to select the volume for instance. 
  34. -- 
  35. --  </description> 
  36. --  <screenshot>gtk-scale.png</screenshot> 
  37. --  <group>Numeric/Text Data Entry</group> 
  38.  
  39. pragma Warnings (Off, "*is already use-visible*"); 
  40. with Glib;            use Glib; 
  41. with Glib.Properties; use Glib.Properties; 
  42. with Glib.Types;      use Glib.Types; 
  43. with Gtk.Adjustment;  use Gtk.Adjustment; 
  44. with Gtk.Buildable;   use Gtk.Buildable; 
  45. with Gtk.Enums;       use Gtk.Enums; 
  46. with Gtk.GRange;      use Gtk.GRange; 
  47. with Gtk.Orientable;  use Gtk.Orientable; 
  48. with Gtk.Widget;      use Gtk.Widget; 
  49. with Pango.Layout;    use Pango.Layout; 
  50.  
  51. package Gtk.Scale is 
  52.  
  53.    type Gtk_Scale_Record is new Gtk_Range_Record with null record; 
  54.    type Gtk_Scale is access all Gtk_Scale_Record'Class; 
  55.  
  56.    subtype Gtk_Hscale_Record is Gtk_Scale_Record; 
  57.    subtype Gtk_Hscale is Gtk_Scale; 
  58.  
  59.    subtype Gtk_Vscale_Record is Gtk_Scale_Record; 
  60.    subtype Gtk_Vscale is Gtk_Scale; 
  61.  
  62.    ------------------ 
  63.    -- Constructors -- 
  64.    ------------------ 
  65.  
  66.    function Get_Type return Glib.GType; 
  67.    pragma Import (C, Get_Type, "gtk_scale_get_type"); 
  68.  
  69.    procedure Gtk_New_Hscale 
  70.       (Scale      : out Gtk_Hscale; 
  71.        Adjustment : Gtk.Adjustment.Gtk_Adjustment := null); 
  72.    procedure Initialize_Hscale 
  73.       (Scale      : access Gtk_Hscale_Record'Class; 
  74.        Adjustment : Gtk.Adjustment.Gtk_Adjustment := null); 
  75.    procedure Gtk_New_Hscale 
  76.       (Scale : out Gtk_Hscale; 
  77.        Min   : Gdouble; 
  78.        Max   : Gdouble; 
  79.        Step  : Gdouble); 
  80.    procedure Initialize_Hscale 
  81.       (Scale : access Gtk_Hscale_Record'Class; 
  82.        Min   : Gdouble; 
  83.        Max   : Gdouble; 
  84.        Step  : Gdouble); 
  85.    --  Creates a new horizontal scale widget that lets the user input a number 
  86.    --  between Min and Max (including Min and Max) with the increment Step. 
  87.    --  Step must be nonzero; it's the distance the slider moves when using the 
  88.    --  arrow keys to adjust the scale value. Note that the way in which the 
  89.    --  precision is derived works best if Step is a power of ten. If the 
  90.    --  resulting precision is not suitable for your needs, use 
  91.    --  Gtk.Scale.Set_Digits to correct it. 
  92.    --  "min": minimum value 
  93.    --  "max": maximum value 
  94.    --  "step": step increment (tick size) used with keyboard shortcuts 
  95.  
  96.    function Hscale_Get_Type return Glib.GType; 
  97.    pragma Import (C, Hscale_Get_Type, "gtk_hscale_get_type"); 
  98.  
  99.    procedure Gtk_New_Vscale 
  100.       (Scale      : out Gtk_Vscale; 
  101.        Adjustment : Gtk.Adjustment.Gtk_Adjustment := null); 
  102.    procedure Initialize_Vscale 
  103.       (Scale      : access Gtk_Vscale_Record'Class; 
  104.        Adjustment : Gtk.Adjustment.Gtk_Adjustment := null); 
  105.    procedure Gtk_New_Vscale 
  106.       (Scale : out Gtk_Vscale; 
  107.        Min   : Gdouble; 
  108.        Max   : Gdouble; 
  109.        Step  : Gdouble); 
  110.    procedure Initialize_Vscale 
  111.       (Scale : access Gtk_Vscale_Record'Class; 
  112.        Min   : Gdouble; 
  113.        Max   : Gdouble; 
  114.        Step  : Gdouble); 
  115.    --  Creates a new vertical scale widget that lets the user input a number 
  116.    --  between Min and Max (including Min and Max) with the increment Step. 
  117.    --  Step must be nonzero; it's the distance the slider moves when using the 
  118.    --  arrow keys to adjust the scale value. Note that the way in which the 
  119.    --  precision is derived works best if Step is a power of ten. If the 
  120.    --  resulting precision is not suitable for your needs, use 
  121.    --  Gtk.Scale.Set_Digits to correct it. 
  122.    --  "min": minimum value 
  123.    --  "max": maximum value 
  124.    --  "step": step increment (tick size) used with keyboard shortcuts 
  125.  
  126.    function Vscale_Get_Type return Glib.GType; 
  127.    pragma Import (C, Vscale_Get_Type, "gtk_vscale_get_type"); 
  128.  
  129.    ------------- 
  130.    -- Methods -- 
  131.    ------------- 
  132.  
  133.    procedure Add_Mark 
  134.       (Scale    : access Gtk_Scale_Record; 
  135.        Value    : Gdouble; 
  136.        Position : Gtk.Enums.Gtk_Position_Type; 
  137.        Markup   : UTF8_String); 
  138.    --  Adds a mark at Value. A mark is indicated visually by drawing a tick 
  139.    --  mark next to the scale, and GTK+ makes it easy for the user to position 
  140.    --  the scale exactly at the marks value. If Markup is not null, text is 
  141.    --  shown next to the tick mark. To remove marks from a scale, use 
  142.    --  Gtk.Scale.Clear_Marks. 
  143.    --  Since: gtk+ 2.16 
  144.    --  "value": the value at which the mark is placed, must be between the 
  145.    --  lower and upper limits of the scales' adjustment 
  146.    --  "position": where to draw the mark. For a horizontal scale, GTK_POS_TOP 
  147.    --  is drawn above the scale, anything else below. For a vertical scale, 
  148.    --  GTK_POS_LEFT is drawn to the left of the scale, anything else to the 
  149.    --  right. 
  150.    --  "markup": Text to be shown at the mark, using <link 
  151.    --  linkend="PangoMarkupFormat">Pango markup</link>, or null 
  152.  
  153.    procedure Clear_Marks (Scale : access Gtk_Scale_Record); 
  154.    --  Removes any marks that have been added with Gtk.Scale.Add_Mark. 
  155.    --  Since: gtk+ 2.16 
  156.  
  157.    function Get_Digits (Scale : access Gtk_Scale_Record) return Gint; 
  158.    procedure Set_Digits 
  159.       (Scale            : access Gtk_Scale_Record; 
  160.        Number_Of_Digits : Gint); 
  161.    --  Sets the number of decimal places that are displayed in the value. Also 
  162.    --  causes the value of the adjustment to be rounded off to this number of 
  163.    --  digits, so the retrieved value matches the value the user saw. 
  164.    --  "digits": the number of decimal places to display, e.g. use 1 to 
  165.    --  display 1.0, 2 to display 1.00, etc 
  166.  
  167.    function Get_Draw_Value (Scale : access Gtk_Scale_Record) return Boolean; 
  168.    procedure Set_Draw_Value 
  169.       (Scale      : access Gtk_Scale_Record; 
  170.        Draw_Value : Boolean); 
  171.    --  Specifies whether the current value is displayed as a string next to 
  172.    --  the slider. 
  173.    --  "draw_value": True to draw the value 
  174.  
  175.    function Get_Layout 
  176.       (Scale : access Gtk_Scale_Record) return Pango.Layout.Pango_Layout; 
  177.    --  Gets the Pango.Layout.Pango_Layout used to display the scale. The 
  178.    --  returned object is owned by the scale so does not need to be freed by 
  179.    --  the caller. or null if the Gtk.Scale.Gtk_Scale:draw-value property is 
  180.    --  False. 
  181.    --  Since: gtk+ 2.4 
  182.  
  183.    procedure Get_Layout_Offsets 
  184.       (Scale : access Gtk_Scale_Record; 
  185.        X     : out Gint; 
  186.        Y     : out Gint); 
  187.    --  Obtains the coordinates where the scale will draw the 
  188.    --  Pango.Layout.Pango_Layout representing the text in the scale. Remember 
  189.    --  when using the Pango.Layout.Pango_Layout function you need to convert to 
  190.    --  and from pixels using PANGO_PIXELS or PANGO_SCALE. If the 
  191.    --  Gtk.Scale.Gtk_Scale:draw-value property is False, the return values are 
  192.    --  undefined. 
  193.    --  Since: gtk+ 2.4 
  194.    --  "x": location to store X offset of layout, or null 
  195.    --  "y": location to store Y offset of layout, or null 
  196.  
  197.    function Get_Value_Pos 
  198.       (Scale : access Gtk_Scale_Record) return Gtk.Enums.Gtk_Position_Type; 
  199.    procedure Set_Value_Pos 
  200.       (Scale : access Gtk_Scale_Record; 
  201.        Pos   : Gtk.Enums.Gtk_Position_Type); 
  202.    --  Sets the position in which the current value is displayed. 
  203.    --  "pos": the position in which the current value is displayed 
  204.  
  205.    --------------------- 
  206.    -- Interfaces_Impl -- 
  207.    --------------------- 
  208.  
  209.    function Get_Orientation 
  210.       (Self : access Gtk_Scale_Record) return Gtk.Enums.Gtk_Orientation; 
  211.    procedure Set_Orientation 
  212.       (Self        : access Gtk_Scale_Record; 
  213.        Orientation : Gtk.Enums.Gtk_Orientation); 
  214.  
  215.    ---------------- 
  216.    -- Interfaces -- 
  217.    ---------------- 
  218.    --  This class implements several interfaces. See Glib.Types 
  219.    -- 
  220.    --  - "Buildable" 
  221.    -- 
  222.    --  - "Orientable" 
  223.  
  224.    package Implements_Buildable is new Glib.Types.Implements 
  225.      (Gtk.Buildable.Gtk_Buildable, Gtk_Scale_Record, Gtk_Scale); 
  226.    function "+" 
  227.      (Widget : access Gtk_Scale_Record'Class) 
  228.    return Gtk.Buildable.Gtk_Buildable 
  229.    renames Implements_Buildable.To_Interface; 
  230.    function "-" 
  231.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  232.    return Gtk_Scale 
  233.    renames Implements_Buildable.To_Object; 
  234.  
  235.    package Implements_Orientable is new Glib.Types.Implements 
  236.      (Gtk.Orientable.Gtk_Orientable, Gtk_Scale_Record, Gtk_Scale); 
  237.    function "+" 
  238.      (Widget : access Gtk_Scale_Record'Class) 
  239.    return Gtk.Orientable.Gtk_Orientable 
  240.    renames Implements_Orientable.To_Interface; 
  241.    function "-" 
  242.      (Interf : Gtk.Orientable.Gtk_Orientable) 
  243.    return Gtk_Scale 
  244.    renames Implements_Orientable.To_Object; 
  245.  
  246.    ---------------- 
  247.    -- Properties -- 
  248.    ---------------- 
  249.    --  The following properties are defined for this widget. See 
  250.    --  Glib.Properties for more information on properties) 
  251.    -- 
  252.    --  Name: Number_Of_Digits_Property 
  253.    --  Type: Gint 
  254.    --  Flags: read-write 
  255.    -- 
  256.    --  Name: Draw_Value_Property 
  257.    --  Type: Boolean 
  258.    --  Flags: read-write 
  259.    -- 
  260.    --  Name: Value_Pos_Property 
  261.    --  Type: Gtk.Enums.Gtk_Position_Type 
  262.    --  Flags: read-write 
  263.    --  The following properties are defined for this widget. See 
  264.    --  Glib.Properties for more information on properties) 
  265.    --  The following properties are defined for this widget. See 
  266.    --  Glib.Properties for more information on properties) 
  267.  
  268.    Number_Of_Digits_Property : constant Glib.Properties.Property_Int; 
  269.    Draw_Value_Property : constant Glib.Properties.Property_Boolean; 
  270.    Value_Pos_Property : constant Gtk.Enums.Property_Gtk_Position_Type; 
  271.  
  272.    ------------- 
  273.    -- Signals -- 
  274.    ------------- 
  275.    --  The following new signals are defined for this widget: 
  276.    -- 
  277.    --  "format-value" 
  278.    --     function Handler 
  279.    --       (Self  : access Gtk_Scale_Record'Class; 
  280.    --        Value : Gdouble) return UTF8_String; 
  281.    --    --  "value": the value to format 
  282.    --  Signal which allows you to change how the scale value is displayed. 
  283.    --  Connect a signal handler which returns an allocated string representing 
  284.    --  Here's an example signal handler which displays a value 1.0 as with 
  285.    --  "--&gt;1.0&lt;--". |[ static gchar* format_value_callback (GtkScale 
  286.    --  *scale, gdouble value) { return g_strdup_printf 
  287.    --  ("--&gt;&percnt;0.*g&lt;--", gtk_scale_get_digits (scale), value); } ]| 
  288.    --  Returns allocated string representing Value 
  289.  
  290.    Signal_Format_Value : constant Glib.Signal_Name := "format-value"; 
  291.  
  292. private 
  293.    Number_Of_Digits_Property : constant Glib.Properties.Property_Int := 
  294.      Glib.Properties.Build ("digits"); 
  295.    Draw_Value_Property : constant Glib.Properties.Property_Boolean := 
  296.      Glib.Properties.Build ("draw-value"); 
  297.    Value_Pos_Property : constant Gtk.Enums.Property_Gtk_Position_Type := 
  298.      Gtk.Enums.Build ("value-pos"); 
  299. end Gtk.Scale;