X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkimmodule.c;h=e6372f2edb6763b233b81164d2618e952e98033a;hb=9f41970832b60f3cf6644dfbd154df7ec24f26ce;hp=a8c9afb364c0c6cfe94456aaaf4d0dfc2e713784;hpb=57223c9a056bfff1635ddd1e67f660cd5a61e9ff;p=~andy%2Fgtk diff --git a/gtk/gtkimmodule.c b/gtk/gtkimmodule.c index a8c9afb36..e6372f2ed 100644 --- a/gtk/gtkimmodule.c +++ b/gtk/gtkimmodule.c @@ -12,8 +12,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * License along with this library. If not, see .Free */ /* @@ -32,25 +31,33 @@ #include #include -#include "gtkimmodule.h" +#include "gtkimmoduleprivate.h" #include "gtkimcontextsimple.h" #include "gtksettings.h" -#include "gtkmain.h" -#include "gtkrc.h" +#include "gtkprivate.h" #include "gtkintl.h" -#include "gtkalias.h" -/* Do *not* include "gtkprivate.h" in this file. If you do, the - * correct_libdir_prefix() and correct_localedir_prefix() functions - * below will have to move somewhere else. - */ +#undef GDK_DEPRECATED +#undef GDK_DEPRECATED_FOR +#define GDK_DEPRECATED +#define GDK_DEPRECATED_FOR(f) -#ifdef __GTK_PRIVATE_H__ -#error gtkprivate.h should not be included in this file -#endif +#include "deprecated/gtkrc.h" #define SIMPLE_ID "gtk-im-context-simple" +/** + * GtkIMContextInfo: + * @context_id: The unique identification string of the input method. + * @context_name: The human-readable name of the input method. + * @domain: Translation domain to be used with dgettext() + * @domain_dirname: Name of locale directory for use with bindtextdomain() + * @default_locales: A colon-separated list of locales where this input method + * should be the default. The asterisk "*" sets the default for all locales. + * + * Bookkeeping information about a loadable input method. + */ + typedef struct _GtkIMModule GtkIMModule; typedef struct _GtkIMModuleClass GtkIMModuleClass; @@ -101,7 +108,7 @@ gtk_im_module_load (GTypeModule *module) im_module->library = g_module_open (im_module->path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if (!im_module->library) { - g_warning (g_module_error()); + g_warning ("%s", g_module_error()); return FALSE; } @@ -115,7 +122,7 @@ gtk_im_module_load (GTypeModule *module) !g_module_symbol (im_module->library, "im_module_create", (gpointer *)&im_module->create)) { - g_warning (g_module_error()); + g_warning ("%s", g_module_error()); g_module_close (im_module->library); return FALSE; @@ -229,10 +236,7 @@ add_module (GtkIMModule *module, GSList *infos) static void correct_libdir_prefix (gchar **path) { - /* GTK_LIBDIR here is supposed to still have the definition from - * Makefile.am, i.e. the build-time value. Do *not* include gtkprivate.h - * in this file. - */ + /* 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 @@ -243,7 +247,6 @@ correct_libdir_prefix (gchar **path) * builder's machine. Replace the path with the real * one on this machine. */ - extern const gchar *_gtk_get_libdir (); gchar *tem = *path; *path = g_strconcat (_gtk_get_libdir (), tem + strlen (GTK_LIBDIR), NULL); g_free (tem); @@ -253,12 +256,9 @@ correct_libdir_prefix (gchar **path) static void correct_localedir_prefix (gchar **path) { - /* As above, but for GTK_LOCALEDIR. Use separate function in case - * GTK_LOCALEDIR isn't a subfolder of GTK_LIBDIR. - */ + /* See above */ if (strncmp (*path, GTK_LOCALEDIR, strlen (GTK_LOCALEDIR)) == 0) { - extern const gchar *_gtk_get_localedir (); gchar *tem = *path; *path = g_strconcat (_gtk_get_localedir (), tem + strlen (GTK_LOCALEDIR), NULL); g_free (tem); @@ -267,7 +267,7 @@ correct_localedir_prefix (gchar **path) #endif -static GtkIMModule * +G_GNUC_UNUSED static GtkIMModule * add_builtin_module (const gchar *module_name, const GtkIMContextInfo **contexts, int n_contexts) @@ -499,7 +499,7 @@ compare_gtkimcontextinfo_name(const GtkIMContextInfo **a, * @n_contexts: the length of the array stored in @contexts * * List all available types of input method context - **/ + */ void _gtk_im_module_list (const GtkIMContextInfo ***contexts, guint *n_contexts) @@ -577,8 +577,8 @@ _gtk_im_module_list (const GtkIMContextInfo ***contexts, * ID @context_id. * * Return value: a newly created input context of or @context_id, or - * if that could not be created, a newly created GtkIMContextSimple. - **/ + * if that could not be created, a newly created GtkIMContextSimple. + */ GtkIMContext * _gtk_im_module_create (const gchar *context_id) { @@ -638,6 +638,28 @@ match_locale (const gchar *locale, return 0; } +static const gchar * +lookup_immodule (gchar **immodules_list) +{ + while (immodules_list && *immodules_list) + { + if (g_strcmp0 (*immodules_list, SIMPLE_ID) == 0) + return SIMPLE_ID; + else + { + gboolean found; + gchar *context_id; + found = g_hash_table_lookup_extended (contexts_hash, *immodules_list, + (gpointer *) &context_id, NULL); + if (found) + return context_id; + } + immodules_list++; + } + + return NULL; +} + /** * _gtk_im_module_get_default_context_id: * @client_window: a window @@ -646,7 +668,7 @@ match_locale (const gchar *locale, * for the given window. * * Return value: the context ID (will never be %NULL) - **/ + */ const gchar * _gtk_im_module_get_default_context_id (GdkWindow *client_window) { @@ -654,7 +676,7 @@ _gtk_im_module_get_default_context_id (GdkWindow *client_window) const gchar *context_id = NULL; gint best_goodness = 0; gint i; - gchar *tmp_locale, *tmp; + gchar *tmp_locale, *tmp, **immodules; const gchar *envvar; GdkScreen *screen; GtkSettings *settings; @@ -662,37 +684,32 @@ _gtk_im_module_get_default_context_id (GdkWindow *client_window) if (!contexts_hash) gtk_im_module_initialize (); - envvar = g_getenv ("GTK_IM_MODULE"); - if (envvar && - (strcmp (envvar, SIMPLE_ID) == 0 || - g_hash_table_lookup (contexts_hash, envvar))) - return envvar; + envvar = g_getenv("GTK_IM_MODULE"); + if (envvar) + { + immodules = g_strsplit(envvar, ":", 0); + context_id = lookup_immodule(immodules); + g_strfreev(immodules); + + if (context_id) + return context_id; + } /* Check if the certain immodule is set in XSETTINGS. */ - if (client_window != NULL && GDK_IS_DRAWABLE (client_window)) + if (GDK_IS_WINDOW (client_window)) { - screen = gdk_drawable_get_screen (GDK_DRAWABLE (client_window)); - if (screen) - settings = gtk_settings_get_for_screen (screen); - else - settings = gtk_settings_get_default (); - + screen = gdk_window_get_screen (client_window); + settings = gtk_settings_get_for_screen (screen); g_object_get (G_OBJECT (settings), "gtk-im-module", &tmp, NULL); if (tmp) { - if (strcmp (tmp, SIMPLE_ID) == 0) - context_id = SIMPLE_ID; - else - { - GtkIMModule *module; - module = g_hash_table_lookup (contexts_hash, tmp); - if (module) - context_id = module->contexts[0]->context_id; - } + immodules = g_strsplit(tmp, ":", 0); + context_id = lookup_immodule(immodules); + g_strfreev(immodules); g_free (tmp); - if (context_id) + if (context_id) return context_id; } }