[gtkmm] Gtk::Button: Re-insert set_image_from_icon_name()



commit 7532637dda0a1181095e473e499964d24615a6f7
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Mon Nov 7 18:26:14 2016 +0100

    Gtk::Button: Re-insert set_image_from_icon_name()
    
    It was removed in a previous commit because it called the removed
    set_image(). That was not necessary. Keep set_image_from_icon_name(),
    but let it call the new set_icon_name(). Bug #773642

 gtk/src/button.ccg |   19 ++++++++++++++++++-
 gtk/src/button.hg  |   26 ++++++++++++++++++++++----
 2 files changed, 40 insertions(+), 5 deletions(-)
---
diff --git a/gtk/src/button.ccg b/gtk/src/button.ccg
index 70bd67d..116b836 100644
--- a/gtk/src/button.ccg
+++ b/gtk/src/button.ccg
@@ -27,5 +27,22 @@ Button::Button(const Glib::ustring& label, bool mnemonic)
   _CONSTRUCT("label", label.c_str(), "use_underline", gboolean(mnemonic))
 {}
 
-} // namespace Gtk
+void Button::set_image_from_icon_name(const Glib::ustring& icon_name, IconSize size, bool use_fallback)
+{
+  // It would be possible to create a Gtk::Image and add it with Container::add()
+  // instead of calling set_icon_name(), but only set_icon_name() sets style classes
+  // appropriately for a button with an icon.
+
+  set_icon_name(icon_name);
+  if (size == ICON_SIZE_BUTTON && !use_fallback)
+    return;
 
+  auto image = dynamic_cast<Image*>(get_child());
+  if (image)
+  {
+    image->set_from_icon_name(icon_name, size);
+    image->property_use_fallback() = use_fallback;
+  }
+}
+
+} // namespace Gtk
diff --git a/gtk/src/button.hg b/gtk/src/button.hg
index 331ccff..f52c829 100644
--- a/gtk/src/button.hg
+++ b/gtk/src/button.hg
@@ -44,7 +44,7 @@ class Button
 public:
 
   /** Create an empty button.
-   * With an empty button, you can Gtk::Button::add() a widget
+   * With an empty button, you can Gtk::Container::add() a widget
    * such as a Gtk::Image or Gtk::Box.
    *
    * If you just wish to add a Gtk::Label,
@@ -57,13 +57,12 @@ public:
 
   /** Simple Push Button with label.
    * Create a button with the given label inside. You won't be able
-   * to add a widget in this button since it already has a Gtk::Label
-   * in it
+   * to add a widget in this button since it already has a Gtk::Label in it.
    */
   explicit Button(const Glib::ustring& label, bool mnemonic = false);
 
   //We don't wrap gtk_button_new_from_icon_name() to avoid a clash with the label constructor.
-  //But set_icon_name() is a replacement.
+  //But set_icon_name() and set_image_from_icon_name() are replacements.
   _IGNORE(gtk_button_new_from_icon_name)
 
   _WRAP_METHOD(void clicked(), gtk_button_clicked)
@@ -79,6 +78,25 @@ public:
   _WRAP_METHOD(void set_icon_name(const Glib::ustring& icon_name), gtk_button_set_icon_name)
   _WRAP_METHOD(Glib::ustring get_icon_name() const, gtk_button_get_icon_name)
 
+  /** Sets the image to an icon from the current icon theme.
+   * If the icon name isn't known, a "broken image" icon will be
+   * displayed instead. If the current icon theme is changed, the icon
+   * will be updated appropriately.
+   *
+   * This is a convenience wrapper around Gtk::Image::set_from_icon_name() and
+   * Gtk::Image::property_use_fallback(). With the default values of @a size
+   * and @a use_fallback, it's identical to set_icon_name().
+   *
+   * @param icon_name An icon name.
+   * @param size An icon size. Can be either an IconSize or a BuiltinIconSize.
+   * @param use_fallback Whether the icon displayed in the Gtk::Image will use
+   *        standard icon names fallback. See also Gtk::ICON_LOOKUP_GENERIC_FALLBACK.
+   *
+   * @newin{3,12}
+   */
+  void set_image_from_icon_name(const Glib::ustring& icon_name,
+    IconSize size = ICON_SIZE_BUTTON, bool use_fallback = false);
+
   _WRAP_SIGNAL(void clicked(), "clicked")
   _IGNORE_SIGNAL("activate") // Action signal
 


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