[gtkmm] Gtk: MenuButton derives from Widget, and other modifications



commit 62651da37f834e894c8e8df4a07f954081c57936
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Tue May 21 11:24:45 2019 +0200

    Gtk: MenuButton derives from Widget, and other modifications
    
    * gtk/src/cssprovider.[ccg|hg]:
    * gtk/src/linkbutton.hg: Signals have no default handlers.
    GtkCssProviderClass and GtkLinkButtonClass have become private.
    * gtk/src/menubutton.hg: Derive MenuButton from Widget instead of
    ToggleButton. Add set/get/property_icon_name(), set/get/property_label().

 gtk/src/cssprovider.ccg | 47 +----------------------------------------------
 gtk/src/cssprovider.hg  |  3 ++-
 gtk/src/linkbutton.hg   |  3 ++-
 gtk/src/menubutton.hg   | 34 ++++++++++++++++++++++------------
 4 files changed, 27 insertions(+), 60 deletions(-)
---
diff --git a/gtk/src/cssprovider.ccg b/gtk/src/cssprovider.ccg
index c540228a..6b8820b6 100644
--- a/gtk/src/cssprovider.ccg
+++ b/gtk/src/cssprovider.ccg
@@ -34,7 +34,7 @@ static void CssProvider_signal_parsing_error_callback(GtkCssProvider* self, GtkC
     }
     catch (const Glib::Error& ex)
     {
-      // ex can be (and usually is) an instance of a subclass ofGlib::Error.
+      // ex can be (and usually is) an instance of a subclass of Glib::Error.
       try
       {
         if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data))
@@ -58,49 +58,4 @@ void CssProvider::load_from_data(const std::string& data)
   gtk_css_provider_load_from_data(gobj(), data.c_str(), -1);
 }
 
-void CssProvider_Class::parsing_error_callback(GtkCssProvider* self, GtkCssSection* p0, const GError* p1)
-{
-  const auto obj_base = static_cast<Glib::ObjectBase*>(
-      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
-
-  // Non-gtkmmproc-generated custom classes implicitly call the default
-  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
-  // generated classes can use this optimisation, which avoids the unnecessary
-  // parameter conversions if there is no possibility of the virtual function
-  // being overridden:
-  if(obj_base && obj_base->is_derived_())
-  {
-    const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
-    if(obj) // This can be NULL during destruction.
-    {
-      try
-      {
-        Glib::Error::throw_exception(g_error_copy(p1));
-      }
-      catch (const Glib::Error& ex)
-      {
-        // ex can be (and usually is) an instance of a subclass of Glib::Error.
-        try // Trap C++ exceptions which would normally be lost because this is a C callback.
-        {
-          // Call the virtual member method, which derived classes might override.
-          obj->on_parsing_error(Glib::wrap(p0, true), ex);
-          return;
-        }
-        catch(...)
-        {
-          Glib::exception_handlers_invoke();
-        }
-      }
-    }
-  }
-
-  const auto base = static_cast<BaseClassType*>(
-        g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The 
original underlying C class).
-    );
-
-  // Call the original underlying C function:
-  if(base && base->parsing_error)
-    (*base->parsing_error)(self, p0, p1);
-}
-
 } //namespace Gtk
diff --git a/gtk/src/cssprovider.hg b/gtk/src/cssprovider.hg
index da5be23c..cbad3904 100644
--- a/gtk/src/cssprovider.hg
+++ b/gtk/src/cssprovider.hg
@@ -74,9 +74,10 @@ public:
 #m4 _CONVERSION(`const Glib::RefPtr<const CssSection>&',`GtkCssSection*',__CONVERT_CONST_REFPTR_TO_P)
 #m4 _CONVERSION(`const GError*',`const Glib::Error&',`Glib::Error(g_error_copy($3))')
 #m4 _CONVERSION(`const Glib::Error&',`const GError*',__FR2P)
+  // no_default_handler because GtkCssProviderClass is private.
   /** @param error The parsing error. The referenced object may belong to a subclass of Glib::Error, such as 
Gtk::CssParserError.
    */
-  _WRAP_SIGNAL(void parsing_error(const Glib::RefPtr<const CssSection>& section, const Glib::Error& error), 
"parsing-error", custom_c_callback)
+  _WRAP_SIGNAL(void parsing_error(const Glib::RefPtr<const CssSection>& section, const Glib::Error& error), 
"parsing-error", no_default_handler, custom_c_callback)
 
   //There are no properties.
 };
diff --git a/gtk/src/linkbutton.hg b/gtk/src/linkbutton.hg
index 8d9f6b2b..eceea70a 100644
--- a/gtk/src/linkbutton.hg
+++ b/gtk/src/linkbutton.hg
@@ -60,7 +60,8 @@ public:
   _WRAP_PROPERTY("uri", Glib::ustring)
   _WRAP_PROPERTY("visited", bool)
 
-  _WRAP_SIGNAL(bool activate_link(), "activate-link")
+  // no_default_handler because GtkLinkButtonClass is private.
+  _WRAP_SIGNAL(bool activate_link(), "activate-link", no_default_handler)
 };
 
 
diff --git a/gtk/src/menubutton.hg b/gtk/src/menubutton.hg
index 9f6f6edd..df5396d2 100644
--- a/gtk/src/menubutton.hg
+++ b/gtk/src/menubutton.hg
@@ -15,30 +15,33 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <gtkmm/togglebutton.h>
+#include <gtkmm/widget.h>
 #include <gtkmm/menu.h>
 #include <gtkmm/popover.h>
 #include <giomm/menumodel.h>
 _DEFS(gtkmm,gtk)
-_PINCLUDE(gtkmm/private/togglebutton_p.h)
+_PINCLUDE(gtkmm/private/widget_p.h)
 
 namespace Gtk
 {
 
 /** A widget that shows a menu when clicked on.
  *
- * This menu can be provided either as a Gtk::Menu, or an abstract Gio::MenuModel.
+ * This menu can be provided either as a Gtk::Menu, a Gtk::Popover or an
+ * abstract Gio::MenuModel.
  *
- * This widget can hold any valid child widget. That is, it can hold
- * almost any other standard Gtk::Widget. The most commonly used child is the
- * provided Gtk::Arrow.
+ * The %Gtk::MenuButton widget can show either an icon (set with set_icon_name())
+ * or a label (set with set_label()). If neither is explicitly set,
+ * a Gtk::Image is automatically created, using an arrow image oriented according
+ * to set_direction() or the generic “open-menu-symbolic” icon if the direction
+ * is not set.
  *
  * @ingroup Widgets
  * @newin{3,6}
  */
-class MenuButton : public ToggleButton
+class MenuButton : public Widget
 {
-  _CLASS_GTKOBJECT(MenuButton, GtkMenuButton, GTK_MENU_BUTTON, Gtk::ToggleButton, GtkToggleButton)
+  _CLASS_GTKOBJECT(MenuButton, GtkMenuButton, GTK_MENU_BUTTON, Gtk::Widget, GtkWidget)
 public:
 
   _CTOR_DEFAULT
@@ -61,9 +64,9 @@ public:
   _WRAP_METHOD(const Popover* get_popover() const, gtk_menu_button_get_popover, constversion)
 
   _WRAP_METHOD(void set_use_popover(bool use_popover = true), gtk_menu_button_set_use_popover)
-  _WRAP_METHOD(bool get_use_popover(), gtk_menu_button_get_use_popover)
+  _WRAP_METHOD(bool get_use_popover() const, gtk_menu_button_get_use_popover)
 
-  _WRAP_METHOD(void set_direction(ArrowType   direction), gtk_menu_button_set_direction)
+  _WRAP_METHOD(void set_direction(ArrowType direction), gtk_menu_button_set_direction)
   _WRAP_METHOD(ArrowType get_direction() const, gtk_menu_button_get_direction)
 
   _WRAP_METHOD(void set_menu_model(const Glib::RefPtr<const Gio::MenuModel>& menu_model), 
gtk_menu_button_set_menu_model)
@@ -77,7 +80,13 @@ public:
 
   _WRAP_METHOD(void set_align_widget(Widget& align_widget), gtk_menu_button_set_align_widget)
   _WRAP_METHOD(Widget* get_align_widget(), gtk_menu_button_get_align_widget)
-  _WRAP_METHOD(const Widget* get_align_widget() const, gtk_menu_button_get_align_widget)
+  _WRAP_METHOD(const Widget* get_align_widget() const, gtk_menu_button_get_align_widget, constversion)
+
+  _WRAP_METHOD(void set_icon_name(const Glib::ustring& icon_name), gtk_menu_button_set_icon_name)
+  _WRAP_METHOD(Glib::ustring get_icon_name() const, gtk_menu_button_get_icon_name)
+
+  _WRAP_METHOD(void set_label(const Glib::ustring& label), gtk_menu_button_set_label)
+  _WRAP_METHOD(Glib::ustring get_label() const, gtk_menu_button_get_label)
 
   _WRAP_PROPERTY("popup", Menu*)
   _WRAP_PROPERTY("menu-model", Glib::RefPtr<Gio::MenuModel>)
@@ -85,7 +94,8 @@ public:
   _WRAP_PROPERTY("direction", ArrowType)
   _WRAP_PROPERTY("use-popover", bool)
   _WRAP_PROPERTY("popover", Popover*)
-
+  _WRAP_PROPERTY("icon-name", Glib::ustring)
+  _WRAP_PROPERTY("label", Glib::ustring)
 };
 
 } /* namespace Gtk */


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