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.Menu_Button.Gtk_Menu_Button widget is used to display a menu when 
  26. --  clicked on. This menu can be provided either as a Gtk.Menu.Gtk_Menu, or an 
  27. --  abstract Glib.Menu_Model.Gmenu_Model. 
  28. -- 
  29. --  The Gtk.Menu_Button.Gtk_Menu_Button widget can hold any valid child 
  30. --  widget. That is, it can hold almost any other standard 
  31. --  Gtk.Widget.Gtk_Widget. The most commonly used child is the provided 
  32. --  Gtk.Arrow.Gtk_Arrow. 
  33. -- 
  34. --  The positioning of the menu is determined by the 
  35. --  Gtk.Menu_Button.Gtk_Menu_Button:direction property of the menu button and 
  36. --  the Gtk.Widget.Gtk_Widget:halign or Gtk.Widget.Gtk_Widget:valign properties 
  37. --  of the menu. For example, when the direction is Gtk.Enums.Arrow_Down and 
  38. --  the horizontal alignment is Gtk.Widget.Align_Start, the menu will be 
  39. --  positioned below the button, with the starting edge (depending on the text 
  40. --  direction) of the menu aligned with the starting edge of the button. If 
  41. --  there is not enough space below the button, the menu is popped up above the 
  42. --  button instead. If the alignment would move part of the menu offscreen, it 
  43. --  is 'pushed in'. 
  44. -- 
  45. --  
  46. -- 
  47. --  
  48. -- 
  49. --  halign = start 
  50. -- 
  51. --  halign = center 
  52. -- 
  53. --  halign = end 
  54. -- 
  55. --  direction = down 
  56. -- 
  57. --  <inlinemediaobject> <imageobject><imagedata fileref="down-start.png" 
  58. --  format="PNG"/></imageobject> </inlinemediaobject> 
  59. --  <inlinemediaobject> <imageobject><imagedata fileref="down-center.png" 
  60. --  format="PNG"/></imageobject> </inlinemediaobject> 
  61. --  <inlinemediaobject> <imageobject><imagedata fileref="down-end.png" 
  62. --  format="PNG"/></imageobject> </inlinemediaobject> 
  63. --  direction = up 
  64. -- 
  65. --  <inlinemediaobject> <imageobject><imagedata fileref="up-start.png" 
  66. --  format="PNG"/></imageobject> </inlinemediaobject> 
  67. --  <inlinemediaobject> <imageobject><imagedata fileref="up-center.png" 
  68. --  format="PNG"/></imageobject> </inlinemediaobject> 
  69. --  <inlinemediaobject> <imageobject><imagedata fileref="up-end.png" 
  70. --  format="PNG"/></imageobject> </inlinemediaobject> 
  71. --  
  72. -- 
  73. --  
  74. -- 
  75. --  direction = left 
  76. -- 
  77. --  direction = right 
  78. -- 
  79. --  valign = start 
  80. -- 
  81. --  <inlinemediaobject> <imageobject><imagedata fileref="left-start.png" 
  82. --  format="PNG"/></imageobject> </inlinemediaobject> 
  83. --  <inlinemediaobject> <imageobject><imagedata fileref="right-start.png" 
  84. --  format="PNG"/></imageobject> </inlinemediaobject> 
  85. --  valign = center 
  86. -- 
  87. --  <inlinemediaobject> <imageobject><imagedata fileref="left-center.png" 
  88. --  format="PNG"/></imageobject> </inlinemediaobject> 
  89. --  <inlinemediaobject> <imageobject><imagedata fileref="right-center.png" 
  90. --  format="PNG"/></imageobject> </inlinemediaobject> 
  91. --  valign = end 
  92. -- 
  93. --  <inlinemediaobject> <imageobject><imagedata fileref="left-end.png" 
  94. --  format="PNG"/></imageobject> </inlinemediaobject> 
  95. --  <inlinemediaobject> <imageobject><imagedata fileref="right-end.png" 
  96. --  format="PNG"/></imageobject> </inlinemediaobject> 
  97. --  </description> 
  98. pragma Ada_2005; 
  99.  
  100. pragma Warnings (Off, "*is already use-visible*"); 
  101. with Glib;              use Glib; 
  102. with Glib.Menu_Model;   use Glib.Menu_Model; 
  103. with Glib.Properties;   use Glib.Properties; 
  104. with Glib.Types;        use Glib.Types; 
  105. with Glib.Variant;      use Glib.Variant; 
  106. with Gtk.Action;        use Gtk.Action; 
  107. with Gtk.Actionable;    use Gtk.Actionable; 
  108. with Gtk.Activatable;   use Gtk.Activatable; 
  109. with Gtk.Buildable;     use Gtk.Buildable; 
  110. with Gtk.Enums;         use Gtk.Enums; 
  111. with Gtk.Menu;          use Gtk.Menu; 
  112. with Gtk.Toggle_Button; use Gtk.Toggle_Button; 
  113. with Gtk.Widget;        use Gtk.Widget; 
  114.  
  115. package Gtk.Menu_Button is 
  116.  
  117.    type Gtk_Menu_Button_Record is new Gtk_Toggle_Button_Record with null record; 
  118.    type Gtk_Menu_Button is access all Gtk_Menu_Button_Record'Class; 
  119.  
  120.    ------------------ 
  121.    -- Constructors -- 
  122.    ------------------ 
  123.  
  124.    procedure Gtk_New (Self : out Gtk_Menu_Button); 
  125.    procedure Initialize 
  126.       (Self : not null access Gtk_Menu_Button_Record'Class); 
  127.    --  Creates a new Gtk.Menu_Button.Gtk_Menu_Button widget with 
  128.    --  downwards-pointing arrow as the only child. You can replace the child 
  129.    --  widget with another Gtk.Widget.Gtk_Widget should you wish to. 
  130.    --  Since: gtk+ 3.6 
  131.  
  132.    function Gtk_Menu_Button_New return Gtk_Menu_Button; 
  133.    --  Creates a new Gtk.Menu_Button.Gtk_Menu_Button widget with 
  134.    --  downwards-pointing arrow as the only child. You can replace the child 
  135.    --  widget with another Gtk.Widget.Gtk_Widget should you wish to. 
  136.    --  Since: gtk+ 3.6 
  137.  
  138.    function Get_Type return Glib.GType; 
  139.    pragma Import (C, Get_Type, "gtk_menu_button_get_type"); 
  140.  
  141.    ------------- 
  142.    -- Methods -- 
  143.    ------------- 
  144.  
  145.    function Get_Align_Widget 
  146.       (Self : not null access Gtk_Menu_Button_Record) 
  147.        return Gtk.Widget.Gtk_Widget; 
  148.    --  Returns the parent Gtk.Widget.Gtk_Widget to use to line up with menu. 
  149.    --  Since: gtk+ 3.6 
  150.  
  151.    procedure Set_Align_Widget 
  152.       (Self         : not null access Gtk_Menu_Button_Record; 
  153.        Align_Widget : access Gtk.Widget.Gtk_Widget_Record'Class); 
  154.    --  Sets the Gtk.Widget.Gtk_Widget to use to line the menu with when popped 
  155.    --  up. Note that the Align_Widget must contain the 
  156.    --  Gtk.Menu_Button.Gtk_Menu_Button itself. 
  157.    --  Setting it to null means that the popup menu will be aligned with the 
  158.    --  button itself. 
  159.    --  Since: gtk+ 3.6 
  160.    --  "align_widget": a Gtk.Widget.Gtk_Widget 
  161.  
  162.    function Get_Direction 
  163.       (Self : not null access Gtk_Menu_Button_Record) 
  164.        return Gtk.Enums.Gtk_Arrow_Type; 
  165.    --  Returns the direction the menu will be pointing at when popped up. 
  166.    --  Since: gtk+ 3.6 
  167.  
  168.    procedure Set_Direction 
  169.       (Self      : not null access Gtk_Menu_Button_Record; 
  170.        Direction : Gtk.Enums.Gtk_Arrow_Type); 
  171.    --  Sets the direction in which the menu will be popped up, as well as 
  172.    --  changing the arrow's direction. The child will not be changed to an 
  173.    --  arrow if it was customized. 
  174.    --  If the menu when popped out would have collided with screen edges, we 
  175.    --  will do our best to keep it inside the screen and fully visible. 
  176.    --  If you pass Gtk.Enums.Arrow_None for a Direction, the menu will behave 
  177.    --  as if you passed Gtk.Enums.Arrow_Down (although you won't see any 
  178.    --  arrows). 
  179.    --  Since: gtk+ 3.6 
  180.    --  "direction": a Gtk.Enums.Gtk_Arrow_Type 
  181.  
  182.    function Get_Menu_Model 
  183.       (Self : not null access Gtk_Menu_Button_Record) 
  184.        return Glib.Menu_Model.Gmenu_Model; 
  185.    --  Returns the Glib.Menu_Model.Gmenu_Model used to generate the menu. 
  186.    --  Since: gtk+ 3.6 
  187.  
  188.    procedure Set_Menu_Model 
  189.       (Self       : not null access Gtk_Menu_Button_Record; 
  190.        Menu_Model : access Glib.Menu_Model.Gmenu_Model_Record'Class); 
  191.    --  Sets the Glib.Menu_Model.Gmenu_Model from which the 
  192.    --  Gtk.Menu_Button.Gtk_Menu_Button:popup property will be filled in, or 
  193.    --  null to disable the button. 
  194.    --  The Gtk.Menu.Gtk_Menu will be created with Gtk.Menu.Gtk_New_From_Model, 
  195.    --  so actions will be connected as documented there. 
  196.    --  If Gtk.Menu_Button.Gtk_Menu_Button:popup is already set, then its 
  197.    --  content will be lost and replaced by our newly created 
  198.    --  Gtk.Menu.Gtk_Menu. 
  199.    --  Since: gtk+ 3.6 
  200.    --  "menu_model": a Glib.Menu_Model.Gmenu_Model 
  201.  
  202.    function Get_Popup 
  203.       (Self : not null access Gtk_Menu_Button_Record) 
  204.        return Gtk.Menu.Gtk_Menu; 
  205.    --  Returns the Gtk.Menu.Gtk_Menu that pops out of the button. 
  206.    --  Since: gtk+ 3.6 
  207.  
  208.    procedure Set_Popup 
  209.       (Self  : not null access Gtk_Menu_Button_Record; 
  210.        Popup : access Gtk.Widget.Gtk_Widget_Record'Class); 
  211.    --  Sets the Gtk.Menu.Gtk_Menu that will be popped up when the button is 
  212.    --  clicked, or null to disable the button. If 
  213.    --  Gtk.Menu_Button.Gtk_Menu_Button:menu-model is set, it will be set to 
  214.    --  null. 
  215.    --  Since: gtk+ 3.6 
  216.    --  "popup": a Gtk.Menu.Gtk_Menu 
  217.  
  218.    --------------------------------------------- 
  219.    -- Inherited subprograms (from interfaces) -- 
  220.    --------------------------------------------- 
  221.    --  Methods inherited from the Buildable interface are not duplicated here 
  222.    --  since they are meant to be used by tools, mostly. If you need to call 
  223.    --  them, use an explicit cast through the "-" operator below. 
  224.  
  225.    function Get_Action_Name 
  226.       (Self : not null access Gtk_Menu_Button_Record) return UTF8_String; 
  227.  
  228.    procedure Set_Action_Name 
  229.       (Self        : not null access Gtk_Menu_Button_Record; 
  230.        Action_Name : UTF8_String); 
  231.  
  232.    function Get_Action_Target_Value 
  233.       (Self : not null access Gtk_Menu_Button_Record) 
  234.        return Glib.Variant.Gvariant; 
  235.  
  236.    procedure Set_Action_Target_Value 
  237.       (Self         : not null access Gtk_Menu_Button_Record; 
  238.        Target_Value : Glib.Variant.Gvariant); 
  239.  
  240.    procedure Set_Detailed_Action_Name 
  241.       (Self                 : not null access Gtk_Menu_Button_Record; 
  242.        Detailed_Action_Name : UTF8_String); 
  243.  
  244.    procedure Do_Set_Related_Action 
  245.       (Self   : not null access Gtk_Menu_Button_Record; 
  246.        Action : not null access Gtk.Action.Gtk_Action_Record'Class); 
  247.  
  248.    function Get_Related_Action 
  249.       (Self : not null access Gtk_Menu_Button_Record) 
  250.        return Gtk.Action.Gtk_Action; 
  251.  
  252.    procedure Set_Related_Action 
  253.       (Self   : not null access Gtk_Menu_Button_Record; 
  254.        Action : not null access Gtk.Action.Gtk_Action_Record'Class); 
  255.  
  256.    function Get_Use_Action_Appearance 
  257.       (Self : not null access Gtk_Menu_Button_Record) return Boolean; 
  258.  
  259.    procedure Set_Use_Action_Appearance 
  260.       (Self           : not null access Gtk_Menu_Button_Record; 
  261.        Use_Appearance : Boolean); 
  262.  
  263.    procedure Sync_Action_Properties 
  264.       (Self   : not null access Gtk_Menu_Button_Record; 
  265.        Action : access Gtk.Action.Gtk_Action_Record'Class); 
  266.  
  267.    ---------------- 
  268.    -- Properties -- 
  269.    ---------------- 
  270.    --  The following properties are defined for this widget. See 
  271.    --  Glib.Properties for more information on properties) 
  272.  
  273.    Align_Widget_Property : constant Glib.Properties.Property_Object; 
  274.    --  Type: Gtk.Container.Gtk_Container 
  275.    --  The Gtk.Widget.Gtk_Widget to use to align the popup menu with. 
  276.  
  277.    Direction_Property : constant Gtk.Enums.Property_Gtk_Arrow_Type; 
  278.    --  The Gtk.Enums.Gtk_Arrow_Type representing the direction in which the 
  279.    --  menu will be popped out. 
  280.  
  281.    Menu_Model_Property : constant Glib.Properties.Property_Boxed; 
  282.    --  Type: Gio.Menu_Model 
  283.    --  The Glib.Menu_Model.Gmenu_Model from which the menu to pop up will be 
  284.    --  created. See Gtk.Menu_Button.Set_Menu_Model for the interaction with the 
  285.    --  Gtk.Menu_Button.Gtk_Menu_Button:popup property. 
  286.  
  287.    Popup_Property : constant Glib.Properties.Property_Object; 
  288.    --  Type: Gtk.Menu.Gtk_Menu 
  289.    --  The Gtk.Menu.Gtk_Menu that will be popped up when the button is 
  290.    --  clicked. 
  291.  
  292.    ---------------- 
  293.    -- Interfaces -- 
  294.    ---------------- 
  295.    --  This class implements several interfaces. See Glib.Types 
  296.    -- 
  297.    --  - "Actionable" 
  298.    -- 
  299.    --  - "Activatable" 
  300.    -- 
  301.    --  - "Buildable" 
  302.  
  303.    package Implements_Gtk_Actionable is new Glib.Types.Implements 
  304.      (Gtk.Actionable.Gtk_Actionable, Gtk_Menu_Button_Record, Gtk_Menu_Button); 
  305.    function "+" 
  306.      (Widget : access Gtk_Menu_Button_Record'Class) 
  307.    return Gtk.Actionable.Gtk_Actionable 
  308.    renames Implements_Gtk_Actionable.To_Interface; 
  309.    function "-" 
  310.      (Interf : Gtk.Actionable.Gtk_Actionable) 
  311.    return Gtk_Menu_Button 
  312.    renames Implements_Gtk_Actionable.To_Object; 
  313.  
  314.    package Implements_Gtk_Activatable is new Glib.Types.Implements 
  315.      (Gtk.Activatable.Gtk_Activatable, Gtk_Menu_Button_Record, Gtk_Menu_Button); 
  316.    function "+" 
  317.      (Widget : access Gtk_Menu_Button_Record'Class) 
  318.    return Gtk.Activatable.Gtk_Activatable 
  319.    renames Implements_Gtk_Activatable.To_Interface; 
  320.    function "-" 
  321.      (Interf : Gtk.Activatable.Gtk_Activatable) 
  322.    return Gtk_Menu_Button 
  323.    renames Implements_Gtk_Activatable.To_Object; 
  324.  
  325.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  326.      (Gtk.Buildable.Gtk_Buildable, Gtk_Menu_Button_Record, Gtk_Menu_Button); 
  327.    function "+" 
  328.      (Widget : access Gtk_Menu_Button_Record'Class) 
  329.    return Gtk.Buildable.Gtk_Buildable 
  330.    renames Implements_Gtk_Buildable.To_Interface; 
  331.    function "-" 
  332.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  333.    return Gtk_Menu_Button 
  334.    renames Implements_Gtk_Buildable.To_Object; 
  335.  
  336. private 
  337.    Popup_Property : constant Glib.Properties.Property_Object := 
  338.      Glib.Properties.Build ("popup"); 
  339.    Menu_Model_Property : constant Glib.Properties.Property_Boxed := 
  340.      Glib.Properties.Build ("menu-model"); 
  341.    Direction_Property : constant Gtk.Enums.Property_Gtk_Arrow_Type := 
  342.      Gtk.Enums.Build ("direction"); 
  343.    Align_Widget_Property : constant Glib.Properties.Property_Object := 
  344.      Glib.Properties.Build ("align-widget"); 
  345. end Gtk.Menu_Button;