[gtkmm] Gtk::CssProvider: Add CssProviderError and signal_parsing_error()



commit d99e8aece4652bcd9eb32d5707d56d7dadd68bd1
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Sun Dec 7 11:30:51 2014 +0100

    Gtk::CssProvider: Add CssProviderError and signal_parsing_error()
    
    * gtk/src/cssprovider.[hg|ccg]: Add CssProviderError, signal_parsing_error()
    and load_from_resource().
    * gtk/src/gtk_signals.defs: Update with CssProvider::signal_parsing_error().
    * gtk/src/gtk_signals.defs.patch: Change the type of parameter 'error' (p1) to
    signal_parsing_error() handlers.
    * tools/extra_defs_gen/generate_defs_gtk.cc:
    Add get_defs(GTK_TYPE_CSS_PROVIDER).
    * tools/m4/convert_gtk.m4: Add conversion for CssProviderError.

 gtk/src/cssprovider.ccg                   |   81 +++++++++++++++++++++++++++++
 gtk/src/cssprovider.hg                    |   17 ++++++-
 gtk/src/gtk_signals.defs                  |   48 +++++++++++++++++
 gtk/src/gtk_signals.defs.patch            |   67 ++++++++++++++++--------
 tools/extra_defs_gen/generate_defs_gtk.cc |    1 +
 tools/m4/convert_gtk.m4                   |    1 +
 6 files changed, 192 insertions(+), 23 deletions(-)
---
diff --git a/gtk/src/cssprovider.ccg b/gtk/src/cssprovider.ccg
index c2bbf59..145c990 100644
--- a/gtk/src/cssprovider.ccg
+++ b/gtk/src/cssprovider.ccg
@@ -17,6 +17,39 @@
 
 #include <gtk/gtk.h>
 
+namespace
+{
+static void CssProvider_signal_parsing_error_callback(GtkCssProvider* self, GtkCssSection* p0,const GError* 
p1,void* data)
+{
+  using namespace Gtk;
+  typedef sigc::slot< void,const Glib::RefPtr<const CssSection>&,const Glib::Error& > SlotType;
+
+  CssProvider* obj = dynamic_cast<CssProvider*>(Glib::ObjectBase::_get_current_wrapper((GObject*) self));
+  // Do not try to call a signal on a disassociated wrapper.
+  if(obj)
+  {
+    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 ofGlib::Error.
+      try
+      {
+        if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data))
+          (*static_cast<SlotType*>(slot))(Glib::wrap(p0, true), ex);
+      }
+      catch (...)
+      {
+         Glib::exception_handlers_invoke();
+      }
+    }
+  }
+}
+
+} // anonymous namespace
+
 namespace Gtk
 {
 
@@ -30,4 +63,52 @@ bool CssProvider::load_from_data(const std::string& data)
   return retvalue;
 }
 
+//TODO: When we can break ABI, remove no_default_handler in _WRAP_SIGNAL and
+// uncomment CssProvider_Class::parsing_error_callback().
+#if 0
+void CssProvider_Class::parsing_error_callback(GtkCssProvider* self, GtkCssSection* p0, const GError* p1)
+{
+  Glib::ObjectBase *const 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_())
+  {
+    CppObjectType *const 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 ofGlib::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();
+        }
+      }
+    }
+  }
+
+  BaseClassType *const 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);
+}
+#endif
 } //namespace Gtk
diff --git a/gtk/src/cssprovider.hg b/gtk/src/cssprovider.hg
index b9c6215..e217881 100644
--- a/gtk/src/cssprovider.hg
+++ b/gtk/src/cssprovider.hg
@@ -16,6 +16,7 @@
  */
 
 #include <gtkmm/styleprovider.h>
+#include <gtkmm/csssection.h>
 #include <glibmm/object.h>
 #include <giomm/file.h>
 
@@ -25,6 +26,9 @@ _PINCLUDE(glibmm/private/object_p.h)
 
 namespace Gtk
 {
+/** Exception class for Gtk::CssProvider errors.
+ */
+_WRAP_GERROR(CssProviderError, GtkCssProviderError, GTK_CSS_PROVIDER_ERROR)
 
 /** CSS-like styling for widgets, implementing the StyleProvider base class.
  *
@@ -64,12 +68,23 @@ public:
 
   _WRAP_METHOD(bool load_from_file(const Glib::RefPtr<const Gio::File>& file), 
gtk_css_provider_load_from_file, errthrow)
   _WRAP_METHOD(bool load_from_path(const std::string& path), gtk_css_provider_load_from_path, errthrow)
+  _WRAP_METHOD(void load_from_resource(const std::string& resource_path), 
gtk_css_provider_load_from_resource)
 
   _WRAP_METHOD(static Glib::RefPtr<CssProvider> get_default(), gtk_css_provider_get_default, refreturn)
 
   _WRAP_METHOD(static Glib::RefPtr<CssProvider> get_named(const Glib::ustring& name, const Glib::ustring& 
variant), gtk_css_provider_get_named, refreturn)
 
-  //There are no properties or signals.
+  //TODO: When we can break ABI, remove no_default_handler and
+  // uncomment CssProvider_Class::parsing_error_callback() in the .ccg file.
+#m4 _CONVERSION(`GtkCssSection*',`const Glib::RefPtr<const CssSection>&',`Glib::wrap($3, true)')
+#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)
+  /** @param error The parsing error. The referenced object may belong to a subclass of Glib::Error, such as 
Gtk::CssProviderError.
+   */
+  _WRAP_SIGNAL(void parsing_error(const Glib::RefPtr<const CssSection>& section, const Glib::Error& error), 
"parsing-error", custom_c_callback, no_default_handler)
+
+  //There are no properties.
 };
 
 } // namespace Gtk
diff --git a/gtk/src/gtk_signals.defs b/gtk/src/gtk_signals.defs
index d3565b5..24ef63d 100644
--- a/gtk/src/gtk_signals.defs
+++ b/gtk/src/gtk_signals.defs
@@ -3003,6 +3003,18 @@
   (construct-only #f)
 )
 
+;; From GtkCssProvider
+
+(define-signal parsing-error
+  (of-object "GtkCssProvider")
+  (return-type "void")
+  (when "last")
+  (parameters
+    '("GtkCssSection*" "p0")
+    '("const-GError*" "p1")
+  )
+)
+
 ;; From GtkDialog
 
 (define-signal response
@@ -10246,6 +10258,24 @@
   (construct-only #f)
 )
 
+(define-property fallback
+  (of-object "GtkTextTag")
+  (prop-type "GParamBoolean")
+  (docs "Whether font fallback is enabled.")
+  (readable #t)
+  (writable #t)
+  (construct-only #f)
+)
+
+(define-property letter-spacing
+  (of-object "GtkTextTag")
+  (prop-type "GParamInt")
+  (docs "Extra spacing between graphemes")
+  (readable #t)
+  (writable #t)
+  (construct-only #f)
+)
+
 (define-property accumulative-margin
   (of-object "GtkTextTag")
   (prop-type "GParamBoolean")
@@ -10489,6 +10519,24 @@
   (construct-only #f)
 )
 
+(define-property fallback-set
+  (of-object "GtkTextTag")
+  (prop-type "GParamBoolean")
+  (docs "Whether this tag affects font fallback")
+  (readable #t)
+  (writable #t)
+  (construct-only #f)
+)
+
+(define-property letter-spacing-set
+  (of-object "GtkTextTag")
+  (prop-type "GParamBoolean")
+  (docs "Whether this tag affects letter spacing")
+  (readable #t)
+  (writable #t)
+  (construct-only #f)
+)
+
 ;; From GtkTextTagTable
 
 (define-signal tag-changed
diff --git a/gtk/src/gtk_signals.defs.patch b/gtk/src/gtk_signals.defs.patch
index b81331f..e8cb60b 100644
--- a/gtk/src/gtk_signals.defs.patch
+++ b/gtk/src/gtk_signals.defs.patch
@@ -1,6 +1,6 @@
---- gtk/src/gtk_signals.defs.orig      2013-09-11 22:05:42.655978022 +0200
-+++ gtk/src/gtk_signals.defs   2013-09-11 22:07:53.554448890 +0200
-@@ -2455,21 +2455,21 @@
+--- ./../../gtk/src/gtk_signals.defs.orig      2014-12-05 19:06:03.563410776 +0100
++++ ./../../gtk/src/gtk_signals.defs   2014-12-05 19:08:11.984484502 +0100
+@@ -2472,21 +2472,21 @@
    (construct-only #f)
  )
  
@@ -23,7 +23,7 @@
    (return-type "void")
    (when "first")
  )
-@@ -2519,21 +2519,21 @@
+@@ -2536,21 +2536,21 @@
    (construct-only #f)
  )
  
@@ -46,7 +46,7 @@
    (readable #t)
    (writable #t)
    (construct-only #f)
-@@ -2674,21 +2674,21 @@
+@@ -2691,21 +2691,21 @@
    (of-object "GtkComboBox")
    (return-type "void")
    (when "last")
@@ -69,7 +69,30 @@
    (of-object "GtkComboBox")
    (prop-type "GParamObject")
    (docs "The model for the combo box")
-@@ -3119,31 +3119,31 @@
+@@ -3004,21 +3004,21 @@
+ )
+ 
+ ;; From GtkCssProvider
+ 
+ (define-signal parsing-error
+   (of-object "GtkCssProvider")
+   (return-type "void")
+   (when "last")
+   (parameters
+     '("GtkCssSection*" "p0")
+-    '("GError*" "p1")
++    '("const-GError*" "p1")
+   )
+ )
+ 
+ ;; From GtkDialog
+ 
+ (define-signal response
+   (of-object "GtkDialog")
+   (return-type "void")
+   (when "last")
+   (parameters
+@@ -3157,31 +3157,31 @@
      '("const-gchar*" "p0")
    )
  )
@@ -103,7 +126,7 @@
    (readable #t)
    (writable #t)
    (construct-only #f)
-@@ -5219,21 +5219,21 @@
+@@ -5987,21 +5987,21 @@
    (of-object "GtkMenuItem")
    (return-type "void")
    (when "first")
@@ -126,7 +149,7 @@
    (parameters
      '("gint" "p0")
    )
-@@ -5805,32 +5805,32 @@
+@@ -6594,32 +6594,32 @@
    (construct-only #f)
  )
  
@@ -163,7 +186,7 @@
    (when "first")
    (parameters
      '("const-gchar*" "p0")
-@@ -5843,41 +5843,41 @@
+@@ -6638,41 +6638,41 @@
    (return-type "void")
    (when "first")
  )
@@ -209,7 +232,7 @@
    (docs "The location to highlight in the sidebar")
    (readable #t)
    (writable #t)
-@@ -6160,21 +6160,21 @@
+@@ -7017,21 +7017,21 @@
  )
  
  (define-signal status-changed
@@ -232,7 +255,7 @@
    (parameters
      '("GtkWidget*" "p0")
      '("GtkPageSetup*" "p1")
-@@ -6922,21 +6922,21 @@
+@@ -7779,21 +7779,21 @@
    (docs "Whether the child is revealed and the animation target reached")
    (readable #t)
    (writable #f)
@@ -255,7 +278,7 @@
    (of-object "GtkScale")
    (prop-type "GParamInt")
    (docs "The number of decimal places that are displayed in the value")
-@@ -7318,21 +7318,21 @@
+@@ -8213,21 +8213,21 @@
    (prop-type "GParamString")
    (docs "Name of default font to use")
    (readable #t)
@@ -278,7 +301,7 @@
    (prop-type "GParamString")
    (docs "List of currently active GTK modules")
    (readable #t)
-@@ -7931,21 +7931,21 @@
+@@ -8889,21 +8889,21 @@
    (of-object "GtkSpinButton")
    (return-type "void")
    (when "last")
@@ -301,7 +324,7 @@
  )
  
  (define-signal wrapped
-@@ -8057,39 +8057,39 @@
+@@ -9100,39 +9100,39 @@
    )
  )
  
@@ -344,7 +367,7 @@
    (parameters
      '("gint" "p0")
      '("gint" "p1")
-@@ -8097,21 +8097,21 @@
+@@ -9140,21 +9140,21 @@
      '("GtkTooltip*" "p3")
    )
  )
@@ -367,7 +390,7 @@
  )
  
  (define-signal size-changed
-@@ -8713,53 +8713,53 @@
+@@ -9774,53 +9774,53 @@
    (of-object "GtkTextBuffer")
    (return-type "void")
    (when "last")
@@ -426,7 +449,7 @@
  )
  
  (define-signal end-user-action
-@@ -8853,21 +8853,21 @@
+@@ -9914,21 +9914,21 @@
  
  ;; From GtkTextTag
  
@@ -449,7 +472,7 @@
    (readable #t)
    (writable #t)
    (construct-only #t)
-@@ -9846,21 +9846,21 @@
+@@ -10952,21 +10952,21 @@
    )
  )
  
@@ -472,7 +495,7 @@
    (return-type "void")
    (when "first")
  )
-@@ -10595,30 +10595,30 @@
+@@ -11701,30 +11701,30 @@
    (parameters
      '("gboolean" "p0")
    )
@@ -505,7 +528,7 @@
    (parameters
      '("gboolean" "p0")
    )
-@@ -10673,198 +10673,198 @@
+@@ -11779,198 +11779,198 @@
    (parameters
      '("GdkEvent*" "p0")
    )
@@ -724,7 +747,7 @@
    (parameters
      '("GtkSelectionData*" "p0")
      '("guint" "p1")
-@@ -10880,30 +10880,30 @@
+@@ -11986,30 +11986,30 @@
      '("guint" "p1")
      '("guint" "p2")
    )
@@ -757,7 +780,7 @@
    (parameters
      '("GdkDragContext*" "p0")
      '("guint" "p1")
-@@ -10995,48 +10995,48 @@
+@@ -12101,48 +12101,48 @@
      '("guint" "p4")
      '("guint" "p5")
    )
diff --git a/tools/extra_defs_gen/generate_defs_gtk.cc b/tools/extra_defs_gen/generate_defs_gtk.cc
index 30fa543..12d213e 100644
--- a/tools/extra_defs_gen/generate_defs_gtk.cc
+++ b/tools/extra_defs_gen/generate_defs_gtk.cc
@@ -98,6 +98,7 @@ int main(int argc, char** argv)
             << get_defs( GTK_TYPE_COMBO_BOX )
             << get_defs( GTK_TYPE_CONTAINER )
             << get_defs( GTK_TYPE_CELL_VIEW )
+            << get_defs( GTK_TYPE_CSS_PROVIDER )
             << get_defs( GTK_TYPE_DIALOG )
             << get_defs( GTK_TYPE_DRAWING_AREA )
             << get_defs( GTK_TYPE_EDITABLE )
diff --git a/tools/m4/convert_gtk.m4 b/tools/m4/convert_gtk.m4
index 4fcd8a8..9b90251 100644
--- a/tools/m4/convert_gtk.m4
+++ b/tools/m4/convert_gtk.m4
@@ -75,6 +75,7 @@ _CONV_ENUM(Gtk,CalendarDisplayOptions)
 _CONV_ENUM(Gtk,CellRendererMode)
 _CONV_ENUM(Gtk,CellRendererState)
 _CONV_ENUM(Gtk,CornerType)
+_CONV_ENUM(Gtk,CssProviderError)
 _CONV_ENUM(Gtk,CssSectionType)
 _CONV_ENUM(Gtk,CurveType)
 _CONV_ENUM(Gtk,DeleteType)


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