[gtkmm] Gtk::Builder: Add expose_[object|widget](), [set|get]_application()



commit 419b6735889df67ab2c071ff2f9d14694d2acd55
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Mon Feb 3 15:23:45 2014 +0100

    Gtk::Builder: Add expose_[object|widget](), [set|get]_application()
    
    * gtk/src/builder.hg: Add expose_object(), expose_widget(),
    set_application(), get_application(). Remove some TODO comments.
    * gtk/src/builder.ccg: Remove a TODO comment.

 gtk/src/builder.ccg |    3 ++-
 gtk/src/builder.hg  |   22 ++++++++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/gtk/src/builder.ccg b/gtk/src/builder.ccg
index 1ce2393..bad9dd7 100644
--- a/gtk/src/builder.ccg
+++ b/gtk/src/builder.ccg
@@ -16,6 +16,7 @@
  */
 
 #include <glibmm/vectorutils.h>
+#include <gtkmm/application.h>
 
 #include <gtk/gtk.h>
 
@@ -249,7 +250,7 @@ GtkWidget* Builder::get_cwidget(const Glib::ustring& name)
   {
     g_critical("gtkmm: object `%s' (type=`%s') (in GtkBuilder file) is not a widget type.",
                name.c_str(), G_OBJECT_TYPE_NAME(cobject));
-    /* TODO: Unref/sink it? */
+    // Don't unref cobject. gtk_builder_get_object() does not give us a reference.
     return 0;
   }
 
diff --git a/gtk/src/builder.hg b/gtk/src/builder.hg
index 66e442e..68449cf 100644
--- a/gtk/src/builder.hg
+++ b/gtk/src/builder.hg
@@ -26,6 +26,7 @@ _PINCLUDE(glibmm/private/object_p.h)
 
 namespace Gtk
 {
+class Application;
 
 /** Exception class for Gdk::Builder errors.
  */
@@ -386,8 +387,20 @@ public:
    */
   _WRAP_METHOD(bool add_from_string(const char* buffer, gsize length), gtk_builder_add_from_string, errthrow)
 
+  _WRAP_METHOD(void expose_object(const Glib::ustring& name, const Glib::RefPtr<Glib::Object>& object), 
gtk_builder_expose_object)
+#m4 _CONVERSION(`Widget&',`GObject*',`G_OBJECT(($3).gobj())')
+  /** Add @a widget to the builder object pool so it can be referenced just like any
+   * other object built by builder.
+   * 
+   * @newin{3,12}
+   * @param name The name of the widget exposed to the builder.
+   * @param widget The widget to expose.
+   */
+  _WRAP_METHOD(void expose_widget(const Glib::ustring& name, Widget& widget{object}), 
gtk_builder_expose_object)
+
   //TODO: Custom-implement this and prevent it from being used with GTK_WIDGET-derived types?
-  //TODO: Make this return a Glib::RefPtr<Gtk::Buildable>? Check what the C API really does - and document 
that if so.
+  // A Builder can contain objects that don't derive from Buildable,
+  // for instance if objects have been added with expose_object().
   /** Gets the object named @a name.
    * 
    * @newin{2,12}
@@ -520,6 +533,10 @@ public:
   _WRAP_METHOD(void set_translation_domain(const Glib::ustring& domain), gtk_builder_set_translation_domain)
   _WRAP_METHOD(Glib::ustring get_translation_domain() const, gtk_builder_get_translation_domain)
 
+  _WRAP_METHOD(void set_application(const Glib::RefPtr<Application>& application), 
gtk_builder_set_application)
+  _WRAP_METHOD(Glib::RefPtr<Application> get_application(), gtk_builder_get_application, refreturn)
+  _WRAP_METHOD(Glib::RefPtr<const Application> get_application() const, gtk_builder_get_application, 
refreturn, constversion)
+
   //We ignore gtk_builder_get_type_from_name() because it only seems useful when implementing GtkBuildable 
for widgets.
   _IGNORE(gtk_builder_get_type_from_name)
 
@@ -536,9 +553,6 @@ dnl
   klass->get_type_from_name = &get_type_from_name_vfunc_callback;
   _POP()
 #m4end
-
-  // TODO: Make sure this is actually invoked even with disabled vfuncs so
-  // that GtkBuilder creates gtkmm's GObjects.
 };
 
 } // namespace Gtk


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