[gtkmm] Gtk::RadioMenuItem, RadioToolButton: Add join_group()



commit 2f8492072182dabceb46a1b8848cb4f462b032b8
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Sun Aug 7 16:37:12 2016 +0200

    Gtk::RadioMenuItem, RadioToolButton: Add join_group()
    
    * demos/gtk-demo/example_iconbrowser.cc: Use join_group().
    * gtk/src/radiobutton.hg: Add property_group().
    * gtk/src/radiomenuitem.[ccg|hg]:
    * gtk/src/radiotoolbutton.[ccg|hg]: Add join_group(), constructors without
    a RadioButtonGroup parameter, and property_group(). Bug #769374

 demos/gtk-demo/example_iconbrowser.cc |    3 +-
 gtk/src/radiobutton.hg                |   29 ++++++++++++++++-------
 gtk/src/radiomenuitem.ccg             |   10 +++++--
 gtk/src/radiomenuitem.hg              |   28 ++++++++++++++---------
 gtk/src/radiotoolbutton.ccg           |   12 +++++++++-
 gtk/src/radiotoolbutton.hg            |   40 +++++++++++++++++++++++---------
 6 files changed, 85 insertions(+), 37 deletions(-)
---
diff --git a/demos/gtk-demo/example_iconbrowser.cc b/demos/gtk-demo/example_iconbrowser.cc
index 89383e5..c8fd0a7 100644
--- a/demos/gtk-demo/example_iconbrowser.cc
+++ b/demos/gtk-demo/example_iconbrowser.cc
@@ -202,8 +202,7 @@ Example_IconBrowser::Example_IconBrowser()
   m_header_radio_button_box.pack_start(m_symbolic_radio);
   m_normal_radio.set_mode(false); // Make it look as a normal button
   m_symbolic_radio.set_mode(false);
-  Gtk::RadioButtonGroup group = m_normal_radio.get_group();
-  m_symbolic_radio.set_group(group);
+  m_symbolic_radio.join_group(m_normal_radio);
 
   m_button_size_group = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_VERTICAL);
   m_button_size_group->add_widget(m_normal_radio);
diff --git a/gtk/src/radiobutton.hg b/gtk/src/radiobutton.hg
index c8c0491..e33f1a1 100644
--- a/gtk/src/radiobutton.hg
+++ b/gtk/src/radiobutton.hg
@@ -25,10 +25,21 @@ _PINCLUDE(gtkmm/private/checkbutton_p.h)
 namespace Gtk
 {
 
-/** A single radio button performs the same basic function as a Gtk::CheckButton, as its position in the 
object hierarchy reflects. It is only when multiple radio buttons are grouped together that they become a 
different user interface component in their own right.
- * Every radio button is a member of some group of radio buttons. When one is selected, all other radio 
buttons in the same group are deselected. A Gtk::RadioButton gives the user a choice from many options.
- * After constructing the first RadioButton in a group, use get_group() and provide this Group to the 
constructors ot the other RadioButtons in the same group.
- * To remove a Gtk::RadioButton from one group and make it part of a new one, use set_group().
+/** A choice from multiple check buttons.
+ *
+ * A single radio button performs the same basic function as a Gtk::CheckButton,
+ * as its position in the object hierarchy reflects. It is only when multiple
+ * radio buttons are grouped together that they become a different user
+ * interface component in their own right.
+ *
+ * Every radio button is a member of some group of radio buttons. When one is
+ * selected, all other radio buttons in the same group are deselected. A
+ * %Gtk::RadioButton is one way of giving the user a choice from many options.
+ *
+ * After constructing the first %RadioButton in a group, use get_group() and
+ * provide this Group to the constructors ot the other RadioButtons in the same
+ * group, or use join_group(). To remove a %Gtk::RadioButton from one group and
+ * make it part of a new one, use set_group() or join_group().
  *
  * The RadioButton widget looks like this:
  * @image html radiobutton1.png
@@ -40,7 +51,7 @@ class RadioButton : public CheckButton
   _CLASS_GTKOBJECT(RadioButton,GtkRadioButton,GTK_RADIO_BUTTON,Gtk::CheckButton,GtkCheckButton)
   _IGNORE(gtk_radio_button_new_from_widget, gtk_radio_button_new_with_mnemonic_from_widget, 
gtk_radio_button_new_with_label_from_widget)
 public:
-  typedef RadioButtonGroup Group;
+  using Group = RadioButtonGroup;
 
   RadioButton();
   explicit RadioButton(const Glib::ustring& label, bool mnemonic = false);
@@ -68,11 +79,10 @@ public:
    */
   _WRAP_METHOD(Group get_group(), gtk_radio_button_get_group)
 
- //TODO: Remove set/get_group() now that we have join_group()?
- /** Set the radio button's group.
+  /** Set the radio button's group.
    * You can obtain a suitable group from another radio button by using get_group().
    *
-   * @result The group to which the radio button should belong.
+   * @param group The group to which the radio button should belong.
    */
   void set_group(Group& group);
 
@@ -85,7 +95,8 @@ public:
 
   _WRAP_SIGNAL(void group_changed(), "group_changed")
 
-  //Probably wouldn't work: _WRAP_PROPERTY("group", Group)
+  /// Note that %property_group() corresponds to join_group(), rather than to get_group() and set_group().
+  _WRAP_PROPERTY("group", RadioButton*, newin "3,22")
 };
 
 } //namespace Gtk
diff --git a/gtk/src/radiomenuitem.ccg b/gtk/src/radiomenuitem.ccg
index 8ce3518..f7d3f70 100644
--- a/gtk/src/radiomenuitem.ccg
+++ b/gtk/src/radiomenuitem.ccg
@@ -25,6 +25,13 @@ typedef Gtk::RadioMenuItem::Group Group; //So that the generate get_group return
 namespace Gtk
 {
 
+RadioMenuItem::RadioMenuItem(const Glib::ustring &label, bool mnemonic)
+:
+  _CONSTRUCT()
+{
+  add_accel_label(label, mnemonic);
+}
+
 RadioMenuItem::RadioMenuItem(Group& groupx)
 :
   _CONSTRUCT()
@@ -53,7 +60,4 @@ void RadioMenuItem::reset_group()
   gtk_radio_menu_item_set_group(gobj(), nullptr);
 }
 
-
-
 } // namespace Gtk
-
diff --git a/gtk/src/radiomenuitem.hg b/gtk/src/radiomenuitem.hg
index e2ef604..bcda32c 100644
--- a/gtk/src/radiomenuitem.hg
+++ b/gtk/src/radiomenuitem.hg
@@ -35,36 +35,42 @@ class RadioMenuItem : public CheckMenuItem
 {
   _CLASS_GTKOBJECT(RadioMenuItem, GtkRadioMenuItem, GTK_RADIO_MENU_ITEM, Gtk::CheckMenuItem, 
GtkCheckMenuItem)
 public:
+  using Group = RadioButtonGroup;
 
-  typedef RadioButtonGroup Group;
+  /** @newin{3,22}
+   */
+  _CTOR_DEFAULT()
+
+  /** @newin{3,22}
+   */
+  explicit RadioMenuItem(const Glib::ustring& label, bool mnemonic = false);
 
   RadioMenuItem(Group& groupx);
   _IGNORE(gtk_radio_menu_item_new)
   RadioMenuItem(Group& groupx, const Glib::ustring& label, bool mnemonic = false);
   _IGNORE(gtk_radio_menu_item_new_with_label, gtk_radio_menu_item_new_with_mnemonic)
 
-  //We ignore the _new_*_from_widget() functions because they are just the same as calling get_group() and 
set_group() ourselves.
+  //We ignore the _new_*_from_widget() functions because they are just the same as calling join_group() 
ourselves.
   _IGNORE(gtk_radio_menu_item_new_from_widget, gtk_radio_menu_item_new_with_mnemonic_from_widget, 
gtk_radio_menu_item_new_with_label_from_widget)
 
   _WRAP_METHOD(Group get_group(), gtk_radio_menu_item_get_group)
   _IGNORE(gtk_radio_menu_item_set_group)
   void set_group(Group& group);
-  void reset_group();
 
-  /** Emitted when the group of radio menu items that a radio menu item belongs
-   * to changes. This is emitted when a radio menu item switches from
-   * being alone to being part of a group of 2 or more menu items, or
-   * vice-versa, and when a buttton is moved from one group of 2 or
-   * more menu items to a different one, but not when the composition
-   * of the group that a menu item belongs to changes.
+  /** Removes the radio menu item from the group.
    */
+  void reset_group();
+
+#m4 _CONVERSION(`RadioMenuItem&',`GtkRadioMenuItem*',`($3).gobj()')
+  _WRAP_METHOD(void join_group(RadioMenuItem& group_source), gtk_radio_menu_item_join_group, newin "3,22")
+
   _WRAP_SIGNAL(void group_changed(), "group_changed")
 
-  //Probably wouldn't work: _WRAP_PROPERTY("group", Group)
+  /// Note that %property_group() corresponds to join_group(), rather than to get_group() and set_group().
+  _WRAP_PROPERTY("group", RadioMenuItem*, newin "3,22")
 
 protected:
   void constructor(const Group& group);
 };
 
 } /* namspace Gtk */
-
diff --git a/gtk/src/radiotoolbutton.ccg b/gtk/src/radiotoolbutton.ccg
index f294bd9..eb5db51 100644
--- a/gtk/src/radiotoolbutton.ccg
+++ b/gtk/src/radiotoolbutton.ccg
@@ -23,6 +23,12 @@ typedef Gtk::RadioToolButton::Group Group; //So that the generate get_group retu
 namespace Gtk
 {
 
+RadioToolButton::RadioToolButton(const Glib::ustring& label)
+:
+  _CONSTRUCT("label", label.c_str())
+{
+}
+
 RadioToolButton::RadioToolButton(Group& group, const Glib::ustring& label)
 :
   Glib::ObjectBase(nullptr), //Mark this class as gtkmmproc-generated, rather than a custom class, to allow 
vfunc optimisations.
@@ -74,5 +80,9 @@ void RadioToolButton::reset_group()
   gtk_radio_tool_button_set_group(gobj(), nullptr);
 }
 
-} // namespace Gtk
+void RadioToolButton::join_group(RadioToolButton& group_source)
+{
+  gtk_radio_tool_button_set_group(gobj(), gtk_radio_tool_button_get_group(group_source.gobj()));
+}
 
+} // namespace Gtk
diff --git a/gtk/src/radiotoolbutton.hg b/gtk/src/radiotoolbutton.hg
index 0acdb6f..dd159fe 100644
--- a/gtk/src/radiotoolbutton.hg
+++ b/gtk/src/radiotoolbutton.hg
@@ -27,7 +27,7 @@ namespace Gtk
 
 /** A toolbar item that contains a radio button.
  *
- * A Gtk::RadioToolButton is a Gtk::ToolItem that contains a radio button, that is,
+ * A %Gtk::RadioToolButton is a Gtk::ToolItem that contains a radio button, that is,
  * a button that is part of a group of toggle buttons where only one button can be
  * active at a time.
  *
@@ -37,24 +37,34 @@ class RadioToolButton : public ToggleToolButton
 {
   _CLASS_GTKOBJECT(RadioToolButton, GtkRadioToolButton, GTK_RADIO_TOOL_BUTTON, Gtk::ToggleToolButton, 
GtkToggleToolButton)
 public:
-  typedef RadioButtonGroup Group;
+  using Group = RadioButtonGroup;
 
   /** Creates a new Gtk::RadioToolButton and a new group.
    *
-   * The RadioToolButton will have an empty label and will reside in an newly created Group.
+   * The RadioToolButton will have an empty label and will reside in a newly created group.
    * Use get_group() to retrieve this group and pass it to other radio buttons to assign
-   * them to this group.
+   * them to this group, or use join_group().
    *
    * @newin{2,4}
    */
   _CTOR_DEFAULT()
 
+  /** Creates a new Gtk::RadioToolButton and a new group.
+   *
+   * The RadioToolButton will have the label @a label.
+   *
+   * @param label The string used to display the label for this RadioToolButton.
+   *
+   * @newin{3,22}
+   */
+  explicit RadioToolButton(const Glib::ustring& label);
+
   /** Creates a new Gtk::RadioToolButton in an existing group.
    *
    * The RadioToolButton will have the label @a label and will be put into the Group
    * @a group.
    *
-   * @param group The existing group which will be used for this RadioButton.
+   * @param group The existing group which will be used for this RadioToolButton.
    * @param label The string used to display the label for this RadioToolButton.
    *
    * @newin{2,4}
@@ -68,7 +78,7 @@ public:
    * The RadioToolButton will be created according to the StockID properties and put into
    * the Group @a group.
    *
-   * @param group The existing group which will be used for this RadioButton.
+   * @param group The existing group which will be used for this RadioToolButton.
    * @param stock_id The StockID which determines the look of the RadioToolButton.
    *
    * @newin{2,4}
@@ -78,9 +88,9 @@ public:
   _IGNORE(gtk_radio_tool_button_new_from_stock)
 #endif // GTKMM_DISABLE_DEPRECATED
 
-  //This would look to much like a copy constructor:
-  //People should use second.set_group(first.get_group()) instead.
-  //explicit RadioToolButton(RadioToolButton& group, const Gtk::StockID& stock_id = Gtk::StockID());
+  //This would look too much like a copy constructor:
+  //_WRAP_CTOR(RadioToolButton(RadioToolButton& group), gtk_radio_tool_button_new_from_widget)
+  //People should use second.join_group(first) instead.
   _IGNORE(gtk_radio_tool_button_new_with_stock_from_widget, gtk_radio_tool_button_new_from_widget)
 
   //This does not correspond to any gtk_radio_tool_button_*_new() function,
@@ -117,8 +127,16 @@ public:
   void reset_group();
   _IGNORE(gtk_radio_tool_button_set_group)
 
-  //Probably wouldn't work: _WRAP_PROPERTY("group", Group)
+  /** Joins a Gtk::RadioToolButton object to the group of another Gtk::RadioToolButton object.
+   *
+   * @newin{3,22}
+   *
+   * @param group_source A radio tool button object whose group we are joining.
+   */
+  void join_group(RadioToolButton& group_source);
+
+  /// Note that %property_group() corresponds to join_group(), rather than to get_group() and set_group().
+  _WRAP_PROPERTY("group", RadioToolButton*, newin "3,22")
 };
 
 } // namespace Gtk
-


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]