1. ------------------------------------------------------------------------------ 
  2. --                                                                          -- 
  3. --      Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet       -- 
  4. --                     Copyright (C) 2000-2014, AdaCore                     -- 
  5. --                                                                          -- 
  6. -- This library is free software;  you can redistribute it and/or modify it -- 
  7. -- under terms of the  GNU General Public License  as published by the Free -- 
  8. -- Software  Foundation;  either version 3,  or (at your  option) any later -- 
  9. -- version. This library is distributed in the hope that it will be useful, -- 
  10. -- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- -- 
  11. -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE.                            -- 
  12. --                                                                          -- 
  13. -- As a special exception under Section 7 of GPL version 3, you are granted -- 
  14. -- additional permissions described in the GCC Runtime Library Exception,   -- 
  15. -- version 3.1, as published by the Free Software Foundation.               -- 
  16. --                                                                          -- 
  17. -- You should have received a copy of the GNU General Public License and    -- 
  18. -- a copy of the GCC Runtime Library Exception along with this program;     -- 
  19. -- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    -- 
  20. -- <http://www.gnu.org/licenses/>.                                          -- 
  21. --                                                                          -- 
  22. ------------------------------------------------------------------------------ 
  23.  
  24. --  <description> 
  25. --  The Gtk.Accel_Label.Gtk_Accel_Label widget is a subclass of 
  26. --  Gtk.Label.Gtk_Label that also displays an accelerator key on the right of 
  27. --  the label text, e.g. 'Ctl+S'. It is commonly used in menus to show the 
  28. --  keyboard short-cuts for commands. 
  29. -- 
  30. --  The accelerator key to display is not set explicitly. Instead, the 
  31. --  Gtk.Accel_Label.Gtk_Accel_Label displays the accelerators which have been 
  32. --  added to a particular widget. This widget is set by calling 
  33. --  Gtk.Accel_Label.Set_Accel_Widget. 
  34. -- 
  35. --  For example, a Gtk.Menu_Item.Gtk_Menu_Item widget may have an accelerator 
  36. --  added to emit the "activate" signal when the 'Ctl+S' key combination is 
  37. --  pressed. A Gtk.Accel_Label.Gtk_Accel_Label is created and added to the 
  38. --  Gtk.Menu_Item.Gtk_Menu_Item, and Gtk.Accel_Label.Set_Accel_Widget is called 
  39. --  with the Gtk.Menu_Item.Gtk_Menu_Item as the second argument. The 
  40. --  Gtk.Accel_Label.Gtk_Accel_Label will now display 'Ctl+S' after its label. 
  41. -- 
  42. --  Note that creating a Gtk.Menu_Item.Gtk_Menu_Item with 
  43. --  Gtk.Menu_Item.Gtk_New_With_Label (or one of the similar functions for 
  44. --  Gtk.Check_Menu_Item.Gtk_Check_Menu_Item and 
  45. --  Gtk.Radio_Menu_Item.Gtk_Radio_Menu_Item) automatically adds a 
  46. --  Gtk.Accel_Label.Gtk_Accel_Label to the Gtk.Menu_Item.Gtk_Menu_Item and 
  47. --  calls Gtk.Accel_Label.Set_Accel_Widget to set it up for you. 
  48. -- 
  49. --  A Gtk.Accel_Label.Gtk_Accel_Label will only display accelerators which 
  50. --  have Gtk.Target_List.Accel_Visible set (see 
  51. --  Gtk.Accel_Group.Gtk_Accel_Flags). A Gtk.Accel_Label.Gtk_Accel_Label can 
  52. --  display multiple accelerators and even signal names, though it is almost 
  53. --  always used to display just one accelerator key. 
  54. -- 
  55. --  == Creating a simple menu item with an accelerator key. == 
  56. -- 
  57. --    GtkWidget *save_item; 
  58. --    GtkAccelGroup *accel_group; 
  59. --    /<!---->* Create a GtkAccelGroup and add it to the window. *<!---->/ 
  60. --    accel_group = gtk_accel_group_new (<!-- -->); 
  61. --       gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); 
  62. --       /<!---->* Create the menu item using the convenience function. *<!---->/ 
  63. --       save_item = gtk_menu_item_new_with_label ("Save"); 
  64. --       gtk_widget_show (save_item); 
  65. --       gtk_container_add (GTK_CONTAINER (menu), save_item); 
  66. --       /<!---->* Now add the accelerator to the GtkMenuItem. Note that since we called 
  67. --          gtk_menu_item_new_with_label(<!-- -->) to create the GtkMenuItem the 
  68. --          GtkAccelLabel is automatically set up to display the GtkMenuItem 
  69. --          accelerators. We just need to make sure we use GTK_ACCEL_VISIBLE here. *<!---->/ 
  70. --             gtk_widget_add_accelerator (save_item, "activate", accel_group, 
  71. --             GDK_KEY_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); 
  72. -- 
  73. -- 
  74. --  </description> 
  75. pragma Ada_2005; 
  76.  
  77. pragma Warnings (Off, "*is already use-visible*"); 
  78. with Gdk.Types;       use Gdk.Types; 
  79. with Glib;            use Glib; 
  80. with Glib.Properties; use Glib.Properties; 
  81. with Glib.Types;      use Glib.Types; 
  82. with Gtk.Buildable;   use Gtk.Buildable; 
  83. with Gtk.Label;       use Gtk.Label; 
  84. with Gtk.Widget;      use Gtk.Widget; 
  85.  
  86. package Gtk.Accel_Label is 
  87.  
  88.    type Gtk_Accel_Label_Record is new Gtk_Label_Record with null record; 
  89.    type Gtk_Accel_Label is access all Gtk_Accel_Label_Record'Class; 
  90.  
  91.    ------------------ 
  92.    -- Constructors -- 
  93.    ------------------ 
  94.  
  95.    procedure Gtk_New 
  96.       (Accel_Label : out Gtk_Accel_Label; 
  97.        String      : UTF8_String); 
  98.    procedure Initialize 
  99.       (Accel_Label : not null access Gtk_Accel_Label_Record'Class; 
  100.        String      : UTF8_String); 
  101.    --  Creates a new Gtk.Accel_Label.Gtk_Accel_Label. 
  102.    --  "string": the label string. Must be non-null. 
  103.  
  104.    function Gtk_Accel_Label_New 
  105.       (String : UTF8_String) return Gtk_Accel_Label; 
  106.    --  Creates a new Gtk.Accel_Label.Gtk_Accel_Label. 
  107.    --  "string": the label string. Must be non-null. 
  108.  
  109.    function Get_Type return Glib.GType; 
  110.    pragma Import (C, Get_Type, "gtk_accel_label_get_type"); 
  111.  
  112.    ------------- 
  113.    -- Methods -- 
  114.    ------------- 
  115.  
  116.    function Get_Accel_Widget 
  117.       (Accel_Label : not null access Gtk_Accel_Label_Record) 
  118.        return Gtk.Widget.Gtk_Widget; 
  119.    --  Fetches the widget monitored by this accelerator label. See 
  120.    --  Gtk.Accel_Label.Set_Accel_Widget. 
  121.  
  122.    procedure Set_Accel_Widget 
  123.       (Accel_Label  : not null access Gtk_Accel_Label_Record; 
  124.        Accel_Widget : not null access Gtk.Widget.Gtk_Widget_Record'Class); 
  125.    --  Sets the widget to be monitored by this accelerator label. 
  126.    --  "accel_widget": the widget to be monitored. 
  127.  
  128.    function Get_Accel_Width 
  129.       (Accel_Label : not null access Gtk_Accel_Label_Record) return Guint; 
  130.    --  Returns the width needed to display the accelerator key(s). This is 
  131.    --  used by menus to align all of the Gtk.Menu_Item.Gtk_Menu_Item widgets, 
  132.    --  and shouldn't be needed by applications. 
  133.  
  134.    function Refetch 
  135.       (Accel_Label : not null access Gtk_Accel_Label_Record) return Boolean; 
  136.    --  Recreates the string representing the accelerator keys. This should not 
  137.    --  be needed since the string is automatically updated whenever 
  138.    --  accelerators are added or removed from the associated widget. 
  139.  
  140.    procedure Set_Accel 
  141.       (Accel_Label      : not null access Gtk_Accel_Label_Record; 
  142.        Accelerator_Key  : Guint; 
  143.        Accelerator_Mods : Gdk.Types.Gdk_Modifier_Type); 
  144.    --  Manually sets a keyval and modifier mask as the accelerator rendered by 
  145.    --  Accel_Label. 
  146.    --  If a keyval and modifier are explicitly set then these values are used 
  147.    --  regardless of any associated accel closure or widget. 
  148.    --  Providing an Accelerator_Key of 0 removes the manual setting. 
  149.    --  Since: gtk+ 3.6 
  150.    --  "accelerator_key": a keyval, or 0 
  151.    --  "accelerator_mods": the modifier mask for the accel 
  152.  
  153.    procedure Set_Accel_Closure 
  154.       (Accel_Label   : not null access Gtk_Accel_Label_Record; 
  155.        Accel_Closure : System.Address); 
  156.    --  Sets the closure to be monitored by this accelerator label. The closure 
  157.    --  must be connected to an accelerator group; see Gtk.Accel_Group.Connect. 
  158.    --  "accel_closure": the closure to monitor for accelerator changes. 
  159.  
  160.    ---------------- 
  161.    -- Properties -- 
  162.    ---------------- 
  163.    --  The following properties are defined for this widget. See 
  164.    --  Glib.Properties for more information on properties) 
  165.  
  166.    Accel_Closure_Property : constant Glib.Properties.Property_String := 
  167.    Glib.Properties.Build ("accel-closure");--  Unknown type: GObject.Closure 
  168.  
  169.    Accel_Widget_Property : constant Glib.Properties.Property_Object; 
  170.    --  Type: Gtk.Widget.Gtk_Widget 
  171.  
  172.    ---------------- 
  173.    -- Interfaces -- 
  174.    ---------------- 
  175.    --  This class implements several interfaces. See Glib.Types 
  176.    -- 
  177.    --  - "Buildable" 
  178.  
  179.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  180.      (Gtk.Buildable.Gtk_Buildable, Gtk_Accel_Label_Record, Gtk_Accel_Label); 
  181.    function "+" 
  182.      (Widget : access Gtk_Accel_Label_Record'Class) 
  183.    return Gtk.Buildable.Gtk_Buildable 
  184.    renames Implements_Gtk_Buildable.To_Interface; 
  185.    function "-" 
  186.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  187.    return Gtk_Accel_Label 
  188.    renames Implements_Gtk_Buildable.To_Object; 
  189.  
  190. private 
  191.    Accel_Widget_Property : constant Glib.Properties.Property_Object := 
  192.      Glib.Properties.Build ("accel-widget"); 
  193. end Gtk.Accel_Label;