+ return gtk_data_prefix;
+}
+
+#endif /* G_OS_WIN32 */
+
+static gchar **
+get_module_path (void)
+{
+ const gchar *module_path_env;
+ const gchar *exe_prefix;
+ const gchar *home_dir;
+ gchar *home_gtk_dir = NULL;
+ gchar *module_path;
+ gchar *default_dir;
+ static gchar **result = NULL;
+
+ if (result)
+ return result;
+
+ home_dir = g_get_home_dir();
+ if (home_dir)
+ home_gtk_dir = g_build_filename (home_dir, ".gtk-2.0", NULL);
+
+ module_path_env = g_getenv ("GTK_PATH");
+ exe_prefix = g_getenv ("GTK_EXE_PREFIX");
+
+ if (exe_prefix)
+ default_dir = g_build_filename (exe_prefix, "lib", "gtk-2.0", NULL);
+ else
+ default_dir = g_build_filename (GTK_LIBDIR, "gtk-2.0", NULL);
+
+ if (module_path_env && home_gtk_dir)
+ module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S,
+ module_path_env, home_gtk_dir, default_dir, NULL);
+ else if (module_path_env)
+ module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S,
+ module_path_env, default_dir, NULL);
+ else if (home_gtk_dir)
+ module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S,
+ home_gtk_dir, default_dir, NULL);
+ else
+ module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S,
+ default_dir, NULL);
+
+ g_free (home_gtk_dir);
+ g_free (default_dir);
+
+ result = pango_split_file_list (module_path);
+ g_free (module_path);
+
+ return result;
+}
+
+/**
+ * _gtk_get_module_path:
+ * @type: the type of the module, for instance 'modules', 'engines', immodules'
+ *
+ * Determines the search path for a particular type of module.
+ *
+ * Return value: the search path for the module type. Free with g_strfreev().
+ **/
+gchar **
+_gtk_get_module_path (const gchar *type)
+{
+ gchar **paths = get_module_path();
+ gchar **path;
+ gchar **result;
+ gint count = 0;
+
+ for (path = paths; *path; path++)
+ count++;
+
+ result = g_new (gchar *, count * 4 + 1);
+
+ count = 0;
+ for (path = get_module_path (); *path; path++)
+ {
+ gint use_version, use_host;
+
+ for (use_version = TRUE; use_version >= FALSE; use_version--)
+ for (use_host = TRUE; use_host >= FALSE; use_host--)
+ {
+ gchar *tmp_dir;
+
+ if (use_version && use_host)
+ tmp_dir = g_build_filename (*path, GTK_BINARY_VERSION, GTK_HOST, type, NULL);
+ else if (use_version)
+ tmp_dir = g_build_filename (*path, GTK_BINARY_VERSION, type, NULL);
+ else if (use_host)
+ tmp_dir = g_build_filename (*path, GTK_HOST, type, NULL);
+ else
+ tmp_dir = g_build_filename (*path, type, NULL);
+
+ result[count++] = tmp_dir;
+ }
+ }
+
+ result[count++] = NULL;
+
+ return result;
+}
+
+/* Like g_module_path, but use .la as the suffix
+ */
+static gchar*
+module_build_la_path (const gchar *directory,
+ const gchar *module_name)
+{
+ gchar *filename;
+ gchar *result;
+
+ if (strncmp (module_name, "lib", 3) == 0)
+ filename = (gchar *)module_name;
+ else
+ filename = g_strconcat ("lib", module_name, ".la", NULL);
+
+ if (directory && *directory)
+ result = g_build_filename (directory, filename, NULL);
+ else
+ result = g_strdup (filename);
+
+ if (filename != module_name)
+ g_free (filename);
+
+ return result;
+}
+
+/**
+ * _gtk_find_module:
+ * @name: the name of the module
+ * @type: the type of the module, for instance 'modules', 'engines', immodules'
+ *
+ * Looks for a dynamically loadable module named @name of type @type in the
+ * standard GTK+ module search path.
+ *
+ * Return value: the pathname to the found module, or %NULL if it wasn't found.
+ * Free with g_free().
+ **/
+gchar *
+_gtk_find_module (const gchar *name,
+ const gchar *type)
+{
+ gchar **paths;
+ gchar **path;
+ gchar *module_name = NULL;
+
+ if (g_path_is_absolute (name))
+ return g_strdup (name);
+
+ paths = _gtk_get_module_path (type);
+ for (path = paths; *path; path++)
+ {
+ gchar *tmp_name;
+
+ tmp_name = g_module_build_path (*path, name);
+ if (g_file_test (tmp_name, G_FILE_TEST_EXISTS))
+ {
+ module_name = tmp_name;
+ goto found;
+ }
+ g_free(tmp_name);
+
+ tmp_name = module_build_la_path (*path, name);
+ if (g_file_test (tmp_name, G_FILE_TEST_EXISTS))
+ {
+ module_name = tmp_name;
+ goto found;
+ }
+ g_free(tmp_name);
+ }
+
+ found:
+ g_strfreev (paths);
+ return module_name;
+}
+
+static GModule *
+find_module (const gchar *name)
+{
+ GModule *module;
+ gchar *module_name;
+
+ module_name = _gtk_find_module (name, "modules");
+ if (!module_name)
+ {
+ /* As last resort, try loading without an absolute path (using system
+ * library path)
+ */
+ module_name = g_module_build_path (NULL, name);
+ }
+
+ module = g_module_open (module_name, G_MODULE_BIND_LAZY);
+ g_free(module_name);
+
+ return module;
+}
+
+static GSList *
+load_module (GSList *module_list,
+ const gchar *name)
+{
+ GtkModuleInitFunc modinit_func = NULL;
+ GtkModuleInfo *info;
+ GModule *module = NULL;
+
+ if (g_module_supported ())
+ {
+ module = find_module (name);
+ if (module &&
+ g_module_symbol (module, "gtk_module_init", (gpointer *) &modinit_func) &&
+ modinit_func)
+ {
+ if (!g_slist_find (module_list, (gconstpointer) modinit_func))
+ {
+ g_module_make_resident (module);
+ info = g_new (GtkModuleInfo, 1);
+
+ info->init_func = modinit_func;
+ g_module_symbol (module, "gtk_module_display_init",
+ (gpointer *) &info->display_init_func);
+
+ module_list = g_slist_prepend (module_list, info);
+ }
+ else
+ {
+ g_module_close (module);
+ module = NULL;
+ }
+ }
+ }
+ if (!modinit_func)
+ {
+ g_message ("Failed to load module \"%s\": %s",
+ module ? g_module_name (module) : name,
+ g_module_error ());
+ if (module)
+ g_module_close (module);
+ }
+
+ return module_list;
+}
+
+static GSList *
+load_modules (const char *module_str)
+{
+ gchar **module_names = pango_split_file_list (module_str);
+ GSList *module_list = NULL;
+ gint i;
+
+ for (i = 0; module_names[i]; i++)
+ module_list = load_module (module_list, module_names[i]);
+
+ module_list = g_slist_reverse (module_list);
+
+ g_strfreev (module_names);
+
+ return module_list;
+}
+
+static gboolean do_setlocale = TRUE;
+
+/**
+ * gtk_disable_setlocale:
+ *
+ * Prevents gtk_init() and gtk_init_check() from automatically
+ * calling <literal>setlocale (LC_ALL, "")</literal>. You would
+ * want to use this function if you wanted to set the locale for
+ * your program to something other than the user's locale, or if
+ * you wanted to set different values for different locale categories.
+ *
+ * Most programs should not need to call this function.
+ **/
+void
+gtk_disable_setlocale (void)
+{
+ if (gtk_initialized)
+ g_warning ("gtk_disable_setlocale() must be called before gtk_init()");
+
+ do_setlocale = FALSE;
+}
+
+#ifdef G_PLATFORM_WIN32