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