[gtk+/composite-templates-new: 4/18] Work around access to global resources without calling gtk_init()



commit 0cd0e36fef4529396764b1fd09c516822166e21f
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Sun Mar 24 17:16:20 2013 +0900

    Work around access to global resources without calling gtk_init()
    
    Some utilities such as GIR and gtk-doc, initialize class vtables without
    initializing GTK+, with composite templates accessing resources this
    causes a hand full of unneeded warnings.
    
    The workaround for now is the use a private function _gtk_ensure_resources()
    which is both called while initializing GTK+, and at the beginning of
    gtk_container_class_set_template_from_resource() (the private function
    ensures that the resource will only ever be registered GOnce).

 gtk/gtkcontainer.c    |    7 +++++++
 gtk/gtkmain.c         |    3 +--
 gtk/gtkprivate.c      |   16 ++++++++++++++++
 gtk/gtkprivate.h      |    2 ++
 gtk/tests/Makefile.am |    1 +
 5 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 202f5cc..e5b2d7d 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -3890,6 +3890,13 @@ gtk_container_class_set_template_from_resource (GtkContainerClass    *container_
   g_return_if_fail (container_class->tmpl == NULL);
   g_return_if_fail (resource_name && resource_name[0]);
 
+  /* This is a hack, because class initializers now access resources
+   * and GIR/gtk-doc initializes classes without initializing GTK+,
+   * we ensure that our base resources are registered here and
+   * avoid warnings which building GIRs/documentation.
+   */
+  _gtk_ensure_resources ();
+
   bytes = g_resources_lookup_data (resource_name, 0, &error);
   if (!bytes)
     {
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index fbf8293..594f4f4 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -120,7 +120,6 @@
 #include "gtkmodulesprivate.h"
 #include "gtkprivate.h"
 #include "gtkrecentmanager.h"
-#include "gtkresources.h"
 #include "gtkselectionprivate.h"
 #include "gtksettingsprivate.h"
 #include "gtktooltip.h"
@@ -707,7 +706,7 @@ do_post_parse_initialization (int    *argc,
       g_warning ("Whoever translated default:LTR did so wrongly.\n");
   }
 
-  _gtk_register_resource ();
+  _gtk_ensure_resources ();
 
   _gtk_accel_map_init ();
 
diff --git a/gtk/gtkprivate.c b/gtk/gtkprivate.c
index 70151f9..3177d47 100644
--- a/gtk/gtkprivate.c
+++ b/gtk/gtkprivate.c
@@ -30,6 +30,7 @@
 #include "gdk/gdk.h"
 
 #include "gtkprivate.h"
+#include "gtkresources.h"
 
 
 #if !defined G_OS_WIN32 && !(defined GDK_WINDOWING_QUARTZ && defined QUARTZ_RELOCATION)
@@ -251,3 +252,18 @@ _gtk_translate_keyboard_accel_state (GdkKeymap       *keymap,
 
   return retval;
 }
+
+static gpointer
+register_resources (gpointer data)
+{
+  _gtk_register_resource ();
+  return NULL;
+}
+
+void
+_gtk_ensure_resources (void)
+{
+  static GOnce register_resources_once = G_ONCE_INIT;
+
+  g_once (&register_resources_once, register_resources, NULL);
+}
diff --git a/gtk/gtkprivate.h b/gtk/gtkprivate.h
index 5b05f5b..093334f 100644
--- a/gtk/gtkprivate.h
+++ b/gtk/gtkprivate.h
@@ -59,6 +59,8 @@ gboolean      _gtk_fnmatch                (const char *pattern,
 
 gchar       * _gtk_get_lc_ctype           (void);
 
+void          _gtk_ensure_resources       (void);
+
 gboolean _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
                                            GValue                *return_accu,
                                            const GValue          *handler_return,
diff --git a/gtk/tests/Makefile.am b/gtk/tests/Makefile.am
index b28105d..4fbbdab 100644
--- a/gtk/tests/Makefile.am
+++ b/gtk/tests/Makefile.am
@@ -148,6 +148,7 @@ regression_tests_LDADD               = $(progs_ldadd)
 TEST_PROGS                     += keyhash
 keyhash_SOURCES                         = keyhash.c \
                                   ../gtkkeyhash.c ../gtkkeyhash.h \
+                                  ../gtkresources.c ../gtkresources.h \
                                   ../gtkprivate.c ../gtkprivate.h
 keyhash_LDADD                   = $(progs_ldadd)
 keyhash_CFLAGS                  = -DGTK_COMPILATION \


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