[gtk+] Make gtk-im-context-none work



commit b0b38c106deaa77d7bcbd4ecb7de6b41c07a9d22
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Feb 23 22:00:55 2015 -0500

    Make gtk-im-context-none work
    
    This was added a few years ago, as a way to have _no_ im context
    at all. But it didn't actually work. Make it work, and streamline
    the handling of none by moving it all to gtkimmodule.c.
    
    As part of this, add context to the translated names of all
    im modules we ship.

 gtk/gtkimmodule.c                   |   47 ++++++++++++++++++++++++++--------
 gtk/gtkimmulticontext.c             |   38 ++++++++--------------------
 modules/input/imam-et.c             |    2 +-
 modules/input/imbroadway.c          |    2 +-
 modules/input/imcedilla.c           |    2 +-
 modules/input/imcyrillic-translit.c |    2 +-
 modules/input/imime.c               |    4 +-
 modules/input/iminuktitut.c         |    2 +-
 modules/input/imipa.c               |    2 +-
 modules/input/immultipress.c        |    2 +-
 modules/input/imquartz.c            |    2 +-
 modules/input/imthai.c              |    2 +-
 modules/input/imti-er.c             |    2 +-
 modules/input/imti-et.c             |    2 +-
 modules/input/imviqr.c              |    2 +-
 modules/input/imxim.c               |    2 +-
 16 files changed, 62 insertions(+), 53 deletions(-)
---
diff --git a/gtk/gtkimmodule.c b/gtk/gtkimmodule.c
index 2122b10..1a90a22 100644
--- a/gtk/gtkimmodule.c
+++ b/gtk/gtkimmodule.c
@@ -65,6 +65,7 @@
 #include "deprecated/gtkrc.h"
 
 #define SIMPLE_ID "gtk-im-context-simple"
+#define NONE_ID   "gtk-im-context-none"
 
 /**
  * GtkIMContextInfo:
@@ -520,7 +521,7 @@ compare_gtkimcontextinfo_name(const GtkIMContextInfo **a,
  *            The structures it points are statically allocated and should
  *            not be modified or freed.
  * @n_contexts: the length of the array stored in @contexts
- * 
+ *
  * List all available types of input method context
  */
 void
@@ -535,7 +536,23 @@ _gtk_im_module_list (const GtkIMContextInfo ***contexts,
 #endif
                GtkIMContextInfo simple_context_info = {
     SIMPLE_ID,
-    N_("Simple"),
+    NC_("input method menu", "Simple"),
+    GETTEXT_PACKAGE,
+#ifdef GTK_LOCALEDIR
+    GTK_LOCALEDIR,
+#else
+    "",
+#endif
+    ""
+  };
+
+  static
+#ifndef G_OS_WIN32
+         const
+#endif
+               GtkIMContextInfo none_context_info = {
+    NONE_ID,
+    NC_("input method menu", "None"),
     GETTEXT_PACKAGE,
 #ifdef GTK_LOCALEDIR
     GTK_LOCALEDIR,
@@ -561,19 +578,22 @@ _gtk_im_module_list (const GtkIMContextInfo ***contexts,
        */
       simple_context_info.domain_dirname = g_strdup (simple_context_info.domain_dirname);
       correct_localedir_prefix ((char **) &simple_context_info.domain_dirname);
+      none_context_info.domain_dirname = g_strdup (none_context_info.domain_dirname);
+      correct_localedir_prefix ((char **) &none_context_info.domain_dirname);
     }
 #endif
 
   if (n_contexts)
-    *n_contexts = (n_loaded_contexts + 1);
+    *n_contexts = n_loaded_contexts + 2;
 
   if (contexts)
     {
       GSList *tmp_list;
       int i;
-      
-      *contexts = g_new (const GtkIMContextInfo *, n_loaded_contexts + 1);
 
+      *contexts = g_new (const GtkIMContextInfo *, n_loaded_contexts + 2);
+
+      (*contexts)[n++] = &none_context_info;
       (*contexts)[n++] = &simple_context_info;
 
       tmp_list = modules_list;
@@ -583,12 +603,12 @@ _gtk_im_module_list (const GtkIMContextInfo ***contexts,
 
          for (i=0; i<module->n_contexts; i++)
            (*contexts)[n++] = module->contexts[i];
-         
+  
          tmp_list = tmp_list->next;
        }
 
-      /* fisrt element (Default) should always be at top */
-      qsort ((*contexts)+1, n-1, sizeof (GtkIMContextInfo *), (GCompareFunc)compare_gtkimcontextinfo_name);
+      /* first elements (Simple and None) should always be at top */
+      qsort ((*contexts)+2, n-2, sizeof (GtkIMContextInfo *), (GCompareFunc)compare_gtkimcontextinfo_name);
     }
 }
 
@@ -607,7 +627,10 @@ _gtk_im_module_create (const gchar *context_id)
 {
   GtkIMModule *im_module;
   GtkIMContext *context = NULL;
-  
+
+  if (strcmp (context_id, NONE_ID) == 0)
+    return NULL;
+
   if (!contexts_hash)
     gtk_im_module_initialize ();
 
@@ -625,12 +648,12 @@ _gtk_im_module_create (const gchar *context_id)
              context = im_module->create (context_id);
              g_type_module_unuse (G_TYPE_MODULE (im_module));
            }
-         
+
          if (!context)
            g_warning ("Loading IM context type '%s' failed", context_id);
        }
     }
-  
+
   if (!context)
      return gtk_im_context_simple_new ();
   else
@@ -694,6 +717,8 @@ lookup_immodule (gchar **immodules_list)
     {
       if (g_strcmp0 (*immodules_list, SIMPLE_ID) == 0)
         return SIMPLE_ID;
+      else if (g_strcmp0 (*immodules_list, NONE_ID) == 0)
+        return NONE_ID;
       else
        {
          gboolean found;
diff --git a/gtk/gtkimmulticontext.c b/gtk/gtkimmulticontext.c
index 9d2a1ad..6422abe 100644
--- a/gtk/gtkimmulticontext.c
+++ b/gtk/gtkimmulticontext.c
@@ -38,8 +38,6 @@
  */
 
 
-#define NONE_ID "gtk-im-context-none"
-
 struct _GtkIMMulticontextPrivate
 {
   GtkIMContext          *slave;
@@ -274,12 +272,12 @@ gtk_im_multicontext_get_slave (GtkIMMulticontext *multicontext)
 
       priv->context_id = g_strdup (get_effective_context_id (multicontext));
 
-      if (g_strcmp0 (priv->context_id, NONE_ID) == 0)
-        return NULL;
-
       slave = _gtk_im_module_create (priv->context_id);
-      gtk_im_multicontext_set_slave (multicontext, slave, FALSE);
-      g_object_unref (slave);
+      if (slave)
+        {
+          gtk_im_multicontext_set_slave (multicontext, slave, FALSE);
+          g_object_unref (slave);
+        }
     }
 
   return priv->slave;
@@ -618,19 +616,6 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
   gtk_widget_show (menuitem);
   gtk_menu_shell_append (menushell, menuitem);
 
-  menuitem = gtk_radio_menu_item_new_with_label (group, C_("input method menu", "None"));
-  if (g_strcmp0 (priv->context_id_aux, NONE_ID) == 0)
-    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), TRUE);
-  g_object_set_data (G_OBJECT (menuitem), I_("gtk-context-id"), NONE_ID);
-  g_signal_connect (menuitem, "activate", G_CALLBACK (activate_cb), context);
-  gtk_widget_show (menuitem);
-  gtk_menu_shell_append (menushell, menuitem);
-  group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
-  
-  menuitem = gtk_separator_menu_item_new ();
-  gtk_widget_show (menuitem);
-  gtk_menu_shell_append (menushell, menuitem);
-
   _gtk_im_module_list (&contexts, &n_contexts);
 
   for (i = 0; i < n_contexts; i++)
@@ -649,7 +634,7 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
                   * GTK+. Input method may have a name in the GTK+
                   * message catalog.
                   */
-                 translated_name = _(contexts[i]->context_name);
+                 translated_name = C_("input method menu", contexts[i]->context_name);
                }
              else
                {
@@ -688,9 +673,8 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
 #else
       translated_name = contexts[i]->context_name;
 #endif
-      menuitem = gtk_radio_menu_item_new_with_label (group,
-                                                    translated_name);
-      
+      menuitem = gtk_radio_menu_item_new_with_label (group, translated_name);
+
       if ((priv->context_id_aux &&
            strcmp (contexts[i]->context_id, priv->context_id_aux) == 0))
         gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), TRUE);
@@ -704,10 +688,10 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context,
           text = g_strdup_printf (C_("input method menu", "System (%s)"), translated_name);
           gtk_label_set_text (GTK_LABEL (label), text);
           g_free (text);
-        }     
- 
+        }
+
       group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menuitem));
-      
+
       g_object_set_data (G_OBJECT (menuitem), I_("gtk-context-id"),
                         (char *)contexts[i]->context_id);
       g_signal_connect (menuitem, "activate",
diff --git a/modules/input/imam-et.c b/modules/input/imam-et.c
index a45f580..f3d7628 100644
--- a/modules/input/imam-et.c
+++ b/modules/input/imam-et.c
@@ -449,7 +449,7 @@ am_et_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo am_et_info = { 
   "am_et",                /* ID */
-  N_("Amharic (EZ+)"),     /* Human readable name */
+  NC_("input method menu", "Amharic (EZ+)"),     /* Human readable name */
   GETTEXT_PACKAGE,        /* Translation domain */
    GTK_LOCALEDIR,         /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "am"                    /* Languages for which this module is the default */
diff --git a/modules/input/imbroadway.c b/modules/input/imbroadway.c
index d0394f3..140aa0e 100644
--- a/modules/input/imbroadway.c
+++ b/modules/input/imbroadway.c
@@ -48,7 +48,7 @@ static GObjectClass *parent_class;
 static const GtkIMContextInfo imbroadway_info =
 {
   "broadway",      /* ID */
-  "Broadway",      /* Human readable name */
+  NC_("input method menu", "Broadway"),      /* Human readable name */
   GETTEXT_PACKAGE, /* Translation domain */
   GTK_LOCALEDIR,   /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "",              /* Languages for which this module is the default */
diff --git a/modules/input/imcedilla.c b/modules/input/imcedilla.c
index 9b230f4..74790b7 100644
--- a/modules/input/imcedilla.c
+++ b/modules/input/imcedilla.c
@@ -87,7 +87,7 @@ cedilla_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo cedilla_info = { 
   "cedilla",                      /* ID */
-  N_("Cedilla"),                   /* Human readable name */
+  NC_("input method menu", "Cedilla"), /* Human readable name */
   GETTEXT_PACKAGE,                /* Translation domain */
   GTK_LOCALEDIR,                  /* Dir for bindtextdomain */
   "az:ca:co:fr:gv:oc:pt:sq:tr:wa"  /* Languages for which this module is the default */
diff --git a/modules/input/imcyrillic-translit.c b/modules/input/imcyrillic-translit.c
index 48a5435..68b0392 100644
--- a/modules/input/imcyrillic-translit.c
+++ b/modules/input/imcyrillic-translit.c
@@ -212,7 +212,7 @@ cyrillic_translit_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo cyrillic_translit_info = { 
   "cyrillic_translit",            /* ID */
-  N_("Cyrillic (Transliterated)"), /* Human readable name */
+  NC_("input menthod menu", "Cyrillic (Transliterated)"), /* Human readable name */
   GETTEXT_PACKAGE,                /* Translation domain */
    GTK_LOCALEDIR,                 /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   ""                              /* Languages for which this module is the default */
diff --git a/modules/input/imime.c b/modules/input/imime.c
index 7bb5758..d2943cf 100644
--- a/modules/input/imime.c
+++ b/modules/input/imime.c
@@ -27,8 +27,8 @@
 
 static const GtkIMContextInfo ime_info = {
   "ime",
-  "Windows IME",
-  "gtk+",
+  NC_("input method menu", "Windows IME"),
+  GETTEXT_PACKAGE,
   "",
   "ja:ko:zh",
 };
diff --git a/modules/input/iminuktitut.c b/modules/input/iminuktitut.c
index 35fdb90..651e4be 100644
--- a/modules/input/iminuktitut.c
+++ b/modules/input/iminuktitut.c
@@ -122,7 +122,7 @@ inuktitut_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo inuktitut_info = { 
   "inuktitut",            /* ID */
-  N_("Inuktitut (Transliterated)"),         /* Human readable name */
+  NC_("input method menu", "Inuktitut (Transliterated)"), /* Human readable name */
   GETTEXT_PACKAGE,        /* Translation domain */
   GTK_LOCALEDIR,          /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "iu"                    /* Languages for which this module is the default */
diff --git a/modules/input/imipa.c b/modules/input/imipa.c
index 24ac684..efbc3bd 100644
--- a/modules/input/imipa.c
+++ b/modules/input/imipa.c
@@ -140,7 +140,7 @@ ipa_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo ipa_info = { 
   "ipa",                  /* ID */
-  N_("IPA"),                       /* Human readable name */
+  NC_("input method menu", "IPA"), /* Human readable name */
   GETTEXT_PACKAGE,                /* Translation domain */
    GTK_LOCALEDIR,                 /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   ""                              /* Languages for which this module is the default */
diff --git a/modules/input/immultipress.c b/modules/input/immultipress.c
index c4c0202..89608cb 100644
--- a/modules/input/immultipress.c
+++ b/modules/input/immultipress.c
@@ -27,7 +27,7 @@
  */
 static const GtkIMContextInfo info = { 
   CONTEXT_ID,             /* ID */
-  N_("Multipress"),     /* Human readable name */
+  NC_("input method menu", "Multipress"),     /* Human readable name */
   GETTEXT_PACKAGE,        /* Translation domain. Defined in configure.ac */
   MULTIPRESS_LOCALEDIR,           /* Dir for bindtextdomain (not strictly needed for "gtk+"). Defined in the 
Makefile.am */
   ""                      /* Languages for which this module is the default */
diff --git a/modules/input/imquartz.c b/modules/input/imquartz.c
index fa2afd3..5db6481 100644
--- a/modules/input/imquartz.c
+++ b/modules/input/imquartz.c
@@ -55,7 +55,7 @@ static GObjectClass *parent_class;
 static const GtkIMContextInfo imquartz_info =
 {
   "quartz",
-  "Mac OS X Quartz",
+  NC_("input method menu", "Mac OS X Quartz"),
   GETTEXT_PACKAGE,
   GTK_LOCALEDIR,
   "ja:ko:zh:*",
diff --git a/modules/input/imthai.c b/modules/input/imthai.c
index 586c0b8..5a05a9a 100644
--- a/modules/input/imthai.c
+++ b/modules/input/imthai.c
@@ -30,7 +30,7 @@ GType type_thai = 0;
 
 static const GtkIMContextInfo thai_info = { 
   "thai",         /* ID */
-  N_("Thai-Lao"),  /* Human readable name */
+  NC_("input method menu", "Thai-Lao"),  /* Human readable name */
   GETTEXT_PACKAGE, /* Translation domain */
   GTK_LOCALEDIR,   /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "lo:th"         /* Languages for which this module is the default */
diff --git a/modules/input/imti-er.c b/modules/input/imti-er.c
index ec1af41..a95ed60 100644
--- a/modules/input/imti-er.c
+++ b/modules/input/imti-er.c
@@ -448,7 +448,7 @@ ti_er_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo ti_er_info = { 
   "ti_er",                /* ID */
-  N_("Tigrigna-Eritrean (EZ+)"),         /* Human readable name */
+  NC_("input method menu", "Tigrigna-Eritrean (EZ+)"), /* Human readable name */
   GETTEXT_PACKAGE,        /* Translation domain */
    GTK_LOCALEDIR,         /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "ti"                    /* Languages for which this module is the default */
diff --git a/modules/input/imti-et.c b/modules/input/imti-et.c
index 23caadb..0030020 100644
--- a/modules/input/imti-et.c
+++ b/modules/input/imti-et.c
@@ -448,7 +448,7 @@ ti_et_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo ti_et_info = { 
   "ti_et",                /* ID */
-  N_("Tigrigna-Ethiopian (EZ+)"),         /* Human readable name */
+  NC_("input method menu", "Tigrigna-Ethiopian (EZ+)"), /* Human readable name */
   GETTEXT_PACKAGE,        /* Translation domain */
    GTK_LOCALEDIR,         /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "ti"                    /* Languages for which this module is the default */
diff --git a/modules/input/imviqr.c b/modules/input/imviqr.c
index f074b29..d9572f5 100644
--- a/modules/input/imviqr.c
+++ b/modules/input/imviqr.c
@@ -239,7 +239,7 @@ viqr_init (GtkIMContextSimple *im_context)
 
 static const GtkIMContextInfo viqr_info = { 
   "viqr",                 /* ID */
-  N_("Vietnamese (VIQR)"), /* Human readable name */
+  NC_("input method menu", "Vietnamese (VIQR)"), /* Human readable name */
   GETTEXT_PACKAGE,        /* Translation domain */
    GTK_LOCALEDIR,         /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "vi"                    /* Languages for which this module is the default */
diff --git a/modules/input/imxim.c b/modules/input/imxim.c
index fd8f38b..aff332b 100644
--- a/modules/input/imxim.c
+++ b/modules/input/imxim.c
@@ -23,7 +23,7 @@
 
 static const GtkIMContextInfo xim_ja_info = { 
   "xim",                          /* ID */
-  N_("X Input Method"),            /* Human readable name */
+  NC_("input method menu", "X Input Method"), /* Human readable name */
   GETTEXT_PACKAGE,                /* Translation domain */
   GTK_LOCALEDIR,                  /* Dir for bindtextdomain (not strictly needed for "gtk+") */
   "ko:ja:th:zh"                           /* Languages for which this module is the default */


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