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. --  Gtk.Size_Group.Gtk_Size_Group provides a mechanism for grouping a number 
  26. --  of widgets together so they all request the same amount of space. This is 
  27. --  typically useful when you want a column of widgets to have the same size, 
  28. --  but you can't use a Gtk.Grid.Gtk_Grid widget. 
  29. -- 
  30. --  In detail, the size requested for each widget in a 
  31. --  Gtk.Size_Group.Gtk_Size_Group is the maximum of the sizes that would have 
  32. --  been requested for each widget in the size group if they were not in the 
  33. --  size group. The mode of the size group (see Gtk.Size_Group.Set_Mode) 
  34. --  determines whether this applies to the horizontal size, the vertical size, 
  35. --  or both sizes. 
  36. -- 
  37. --  Note that size groups only affect the amount of space requested, not the 
  38. --  size that the widgets finally receive. If you want the widgets in a 
  39. --  Gtk.Size_Group.Gtk_Size_Group to actually be the same size, you need to 
  40. --  pack them in such a way that they get the size they request and not more. 
  41. --  For example, if you are packing your widgets into a table, you would not 
  42. --  include the Gtk.Enums.Fill flag. 
  43. -- 
  44. --  Gtk.Size_Group.Gtk_Size_Group objects are referenced by each widget in the 
  45. --  size group, so once you have added all widgets to a 
  46. --  Gtk.Size_Group.Gtk_Size_Group, you can drop the initial reference to the 
  47. --  size group with g_object_unref. If the widgets in the size group are 
  48. --  subsequently destroyed, then they will be removed from the size group and 
  49. --  drop their references on the size group; when all widgets have been 
  50. --  removed, the size group will be freed. 
  51. -- 
  52. --  Widgets can be part of multiple size groups; GTK+ will compute the 
  53. --  horizontal size of a widget from the horizontal requisition of all widgets 
  54. --  that can be reached from the widget by a chain of size groups of type 
  55. --  Gtk.Size_Group.Horizontal or Gtk.Size_Group.Both, and the vertical size 
  56. --  from the vertical requisition of all widgets that can be reached from the 
  57. --  widget by a chain of size groups of type Gtk.Size_Group.Vertical or 
  58. --  Gtk.Size_Group.Both. 
  59. -- 
  60. --  Note that only non-contextual sizes of every widget are ever consulted by 
  61. --  size groups (since size groups have no knowledge of what size a widget will 
  62. --  be allocated in one dimension, it cannot derive how much height a widget 
  63. --  will receive for a given width). When grouping widgets that trade height 
  64. --  for width in mode Gtk.Size_Group.Vertical or Gtk.Size_Group.Both: the 
  65. --  height for the minimum width will be the requested height for all widgets 
  66. --  in the group. The same is of course true when horizontally grouping width 
  67. --  for height widgets. 
  68. -- 
  69. --  Widgets that trade height-for-width should set a reasonably large minimum 
  70. --  width by way of Gtk.Label.Gtk_Label:width-chars for instance. Widgets with 
  71. --  static sizes as well as widgets that grow (such as ellipsizing text) need 
  72. --  no such considerations. 
  73. -- 
  74. --  == GtkSizeGroup as GtkBuildable == 
  75. -- 
  76. --  Size groups can be specified in a UI definition by placing an <object> 
  77. --  element with 'class="GtkSizeGroup"' somewhere in the UI definition. The 
  78. --  widgets that belong to the size group are specified by a <widgets> element 
  79. --  that may contain multiple <widget> elements, one for each member of the 
  80. --  size group. The name attribute gives the id of the widget. 
  81. -- 
  82. --  == A UI definition fragment with GtkSizeGroup == 
  83. -- 
  84. --    <object class="GtkSizeGroup"> 
  85. --    <property name="mode">GTK_SIZE_GROUP_HORIZONTAL</property> 
  86. --    <widgets> 
  87. --    <widget name="radio1"/> 
  88. --    <widget name="radio2"/> 
  89. --    </widgets> 
  90. --    </object> 
  91. --  </description> 
  92. --  <testgtk>create_size_groups.adb</testgtk> 
  93. pragma Ada_2005; 
  94.  
  95. pragma Warnings (Off, "*is already use-visible*"); 
  96. with Glib;                    use Glib; 
  97. with Glib.Generic_Properties; use Glib.Generic_Properties; 
  98. with Glib.Object;             use Glib.Object; 
  99. with Glib.Properties;         use Glib.Properties; 
  100. with Glib.Types;              use Glib.Types; 
  101. with Gtk.Buildable;           use Gtk.Buildable; 
  102. with Gtk.Widget;              use Gtk.Widget; 
  103.  
  104. package Gtk.Size_Group is 
  105.  
  106.    type Gtk_Size_Group_Record is new GObject_Record with null record; 
  107.    type Gtk_Size_Group is access all Gtk_Size_Group_Record'Class; 
  108.  
  109.    type Size_Group_Mode is ( 
  110.       None, 
  111.       Horizontal, 
  112.       Vertical, 
  113.       Both); 
  114.    pragma Convention (C, Size_Group_Mode); 
  115.    --  The mode of the size group determines the directions in which the size 
  116.    --  group affects the requested sizes of its component widgets. 
  117.  
  118.    ---------------------------- 
  119.    -- Enumeration Properties -- 
  120.    ---------------------------- 
  121.  
  122.    package Size_Group_Mode_Properties is 
  123.       new Generic_Internal_Discrete_Property (Size_Group_Mode); 
  124.    type Property_Size_Group_Mode is new Size_Group_Mode_Properties.Property; 
  125.  
  126.    ------------------ 
  127.    -- Constructors -- 
  128.    ------------------ 
  129.  
  130.    procedure Gtk_New 
  131.       (Size_Group : out Gtk_Size_Group; 
  132.        Mode       : Size_Group_Mode := Both); 
  133.    procedure Initialize 
  134.       (Size_Group : not null access Gtk_Size_Group_Record'Class; 
  135.        Mode       : Size_Group_Mode := Both); 
  136.    --  Create a new Gtk.Size_Group.Gtk_Size_Group. 
  137.    --  "mode": the mode for the new size group. 
  138.  
  139.    function Gtk_Size_Group_New 
  140.       (Mode : Size_Group_Mode := Both) return Gtk_Size_Group; 
  141.    --  Create a new Gtk.Size_Group.Gtk_Size_Group. 
  142.    --  "mode": the mode for the new size group. 
  143.  
  144.    function Get_Type return Glib.GType; 
  145.    pragma Import (C, Get_Type, "gtk_size_group_get_type"); 
  146.  
  147.    ------------- 
  148.    -- Methods -- 
  149.    ------------- 
  150.  
  151.    procedure Add_Widget 
  152.       (Size_Group : not null access Gtk_Size_Group_Record; 
  153.        Widget     : not null access Gtk.Widget.Gtk_Widget_Record'Class); 
  154.    --  Adds a widget to a Gtk.Size_Group.Gtk_Size_Group. In the future, the 
  155.    --  requisition of the widget will be determined as the maximum of its 
  156.    --  requisition and the requisition of the other widgets in the size group. 
  157.    --  Whether this applies horizontally, vertically, or in both directions 
  158.    --  depends on the mode of the size group. See Gtk.Size_Group.Set_Mode. 
  159.    --  When the widget is destroyed or no longer referenced elsewhere, it will 
  160.    --  be removed from the size group. 
  161.    --  "widget": the Gtk.Widget.Gtk_Widget to add 
  162.  
  163.    function Get_Ignore_Hidden 
  164.       (Size_Group : not null access Gtk_Size_Group_Record) return Boolean; 
  165.    --  Returns if invisible widgets are ignored when calculating the size. 
  166.    --  Since: gtk+ 2.8 
  167.  
  168.    procedure Set_Ignore_Hidden 
  169.       (Size_Group    : not null access Gtk_Size_Group_Record; 
  170.        Ignore_Hidden : Boolean); 
  171.    --  Sets whether unmapped widgets should be ignored when calculating the 
  172.    --  size. 
  173.    --  Since: gtk+ 2.8 
  174.    --  "ignore_hidden": whether unmapped widgets should be ignored when 
  175.    --  calculating the size 
  176.  
  177.    function Get_Mode 
  178.       (Size_Group : not null access Gtk_Size_Group_Record) 
  179.        return Size_Group_Mode; 
  180.    --  Gets the current mode of the size group. See Gtk.Size_Group.Set_Mode. 
  181.  
  182.    procedure Set_Mode 
  183.       (Size_Group : not null access Gtk_Size_Group_Record; 
  184.        Mode       : Size_Group_Mode); 
  185.    --  Sets the Gtk.Size_Group.Size_Group_Mode of the size group. The mode of 
  186.    --  the size group determines whether the widgets in the size group should 
  187.    --  all have the same horizontal requisition (Gtk.Size_Group.Horizontal) all 
  188.    --  have the same vertical requisition (Gtk.Size_Group.Vertical), or should 
  189.    --  all have the same requisition in both directions (Gtk.Size_Group.Both). 
  190.    --  "mode": the mode to set for the size group. 
  191.  
  192.    function Get_Widgets 
  193.       (Size_Group : not null access Gtk_Size_Group_Record) 
  194.        return Gtk.Widget.Widget_SList.GSlist; 
  195.    --  Returns the list of widgets associated with Size_Group. 
  196.    --  Since: gtk+ 2.10 
  197.  
  198.    procedure Remove_Widget 
  199.       (Size_Group : not null access Gtk_Size_Group_Record; 
  200.        Widget     : not null access Gtk.Widget.Gtk_Widget_Record'Class); 
  201.    --  Removes a widget from a Gtk.Size_Group.Gtk_Size_Group. 
  202.    --  "widget": the Gtk.Widget.Gtk_Widget to remove 
  203.  
  204.    ---------------- 
  205.    -- Properties -- 
  206.    ---------------- 
  207.    --  The following properties are defined for this widget. See 
  208.    --  Glib.Properties for more information on properties) 
  209.  
  210.    Ignore_Hidden_Property : constant Glib.Properties.Property_Boolean; 
  211.    --  If True, unmapped widgets are ignored when determining the size of the 
  212.    --  group. 
  213.  
  214.    Mode_Property : constant Gtk.Size_Group.Property_Size_Group_Mode; 
  215.    --  Type: Size_Group_Mode 
  216.  
  217.    ---------------- 
  218.    -- Interfaces -- 
  219.    ---------------- 
  220.    --  This class implements several interfaces. See Glib.Types 
  221.    -- 
  222.    --  - "Buildable" 
  223.  
  224.    package Implements_Gtk_Buildable is new Glib.Types.Implements 
  225.      (Gtk.Buildable.Gtk_Buildable, Gtk_Size_Group_Record, Gtk_Size_Group); 
  226.    function "+" 
  227.      (Widget : access Gtk_Size_Group_Record'Class) 
  228.    return Gtk.Buildable.Gtk_Buildable 
  229.    renames Implements_Gtk_Buildable.To_Interface; 
  230.    function "-" 
  231.      (Interf : Gtk.Buildable.Gtk_Buildable) 
  232.    return Gtk_Size_Group 
  233.    renames Implements_Gtk_Buildable.To_Object; 
  234.  
  235. private 
  236.    Mode_Property : constant Gtk.Size_Group.Property_Size_Group_Mode := 
  237.      Gtk.Size_Group.Build ("mode"); 
  238.    Ignore_Hidden_Property : constant Glib.Properties.Property_Boolean := 
  239.      Glib.Properties.Build ("ignore-hidden"); 
  240. end Gtk.Size_Group;