+#ifdef G_OS_WIN32
+
+static void
+correct_libdir_prefix (gchar **path)
+{
+ /* GTK_LIBDIR is the build-time libdir */
+ if (strncmp (*path, GTK_LIBDIR, strlen (GTK_LIBDIR)) == 0)
+ {
+ /* This is an entry put there by make install on the
+ * packager's system. On Windows a prebuilt GTK+
+ * package can be installed in a random
+ * location. The gtk.immodules file distributed in
+ * such a package contains paths from the package
+ * builder's machine. Replace the path with the real
+ * one on this machine.
+ */
+ gchar *tem = *path;
+ *path = g_strconcat (_gtk_get_libdir (), tem + strlen (GTK_LIBDIR), NULL);
+ g_free (tem);
+ }
+}
+
+static void
+correct_localedir_prefix (gchar **path)
+{
+ /* See above */
+ if (strncmp (*path, GTK_LOCALEDIR, strlen (GTK_LOCALEDIR)) == 0)
+ {
+ gchar *tem = *path;
+ *path = g_strconcat (_gtk_get_localedir (), tem + strlen (GTK_LOCALEDIR), NULL);
+ g_free (tem);
+ }
+}
+#endif
+
+
+G_GNUC_UNUSED static GtkIMModule *
+add_builtin_module (const gchar *module_name,
+ const GtkIMContextInfo **contexts,
+ int n_contexts)
+{
+ GtkIMModule *module = g_object_new (GTK_TYPE_IM_MODULE, NULL);
+ GSList *infos = NULL;
+ int i;
+
+ for (i = 0; i < n_contexts; i++)
+ {
+ GtkIMContextInfo *info = g_new (GtkIMContextInfo, 1);
+ info->context_id = g_strdup (contexts[i]->context_id);
+ info->context_name = g_strdup (contexts[i]->context_name);
+ info->domain = g_strdup (contexts[i]->domain);
+ info->domain_dirname = g_strdup (contexts[i]->domain_dirname);
+#ifdef G_OS_WIN32
+ correct_localedir_prefix ((char **) &info->domain_dirname);
+#endif
+ info->default_locales = g_strdup (contexts[i]->default_locales);
+ infos = g_slist_prepend (infos, info);
+ }
+
+ module->builtin = TRUE;
+ g_type_module_set_name (G_TYPE_MODULE (module), module_name);
+ add_module (module, infos);
+
+ return module;
+}
+