summaryrefslogtreecommitdiff
path: root/gtk/gtkimcontextime.c
diff options
context:
space:
mode:
authorChun-wei Fan <fanc999@yahoo.com.tw>2018-10-09 17:06:39 +0800
committerChun-wei Fan <fanc999@yahoo.com.tw>2018-10-09 17:10:23 +0800
commit1ca5b415711111cc037dff9a52d10d632137a3cb (patch)
tree02a5bea039b0ca00efcf848c44fd0c5141288df2 /gtk/gtkimcontextime.c
parentcebf5ed46cc326fd4eacfc434e83d1b581cff1f9 (diff)
downloadgtk+-1ca5b415711111cc037dff9a52d10d632137a3cb.tar.gz
gtkimcontextime.c: Fix Korean input
Commit 64a489ad inadvertently introduced a regression that broke Korean text input because the changes there resulted that only the last input string that we have from ImmGetCompositionStringW() for each time the commit signal is emitted is kept, and also as a result the final Korean character that is input by hitting space is also lost as a result, as we didn't check for whether we are done with preediting. Fix these issues by doing the following when we receive the WM_IME_COMPOSITION message with GCS_RESULTSTR from Windows: -Do not emit the commit signal during WM_IME_ENDCOMPOSITION, and... -Emit the commit signal anyways, as we did before c255ba68, however... -We still save up the string to commit, because we need to re-compute the cursor position when we do ->get_preedit_string(), which needs to take the GCS_RESULTSTR string we get from WM_IME_COMPOSITION into account as well, so that we avoid getting the Pango criticals that occur during Chinese (and most likely Japanese) input as the cursor position is out-of-range. Fixes issue #1350.
Diffstat (limited to 'gtk/gtkimcontextime.c')
-rw-r--r--gtk/gtkimcontextime.c89
1 files changed, 55 insertions, 34 deletions
diff --git a/gtk/gtkimcontextime.c b/gtk/gtkimcontextime.c
index 706c1e54f2..2d776b4560 100644
--- a/gtk/gtkimcontextime.c
+++ b/gtk/gtkimcontextime.c
@@ -466,30 +466,53 @@ get_utf8_preedit_string (GtkIMContextIME *context_ime, gint *pos_ret)
len = ImmGetCompositionStringW (himc, GCS_COMPSTR, NULL, 0);
if (len > 0)
- {
- GError *error = NULL;
- gpointer buf = g_alloca (len);
-
- ImmGetCompositionStringW (himc, GCS_COMPSTR, buf, len);
- len /= 2;
- utf8str = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
- if (error)
- {
- g_warning ("%s", error->message);
- g_error_free (error);
- }
-
- if (pos_ret)
- {
- pos = ImmGetCompositionStringW (himc, GCS_CURSORPOS, NULL, 0);
- if (pos < 0 || len < pos)
- {
- g_warning ("ImmGetCompositionString: "
- "Invalid cursor position!");
- pos = 0;
- }
- }
- }
+ {
+ GError *error = NULL;
+ gpointer buf = g_alloca (len);
+
+ ImmGetCompositionStringW (himc, GCS_COMPSTR, buf, len);
+ len /= 2;
+ utf8str = g_utf16_to_utf8 (buf, len, NULL, NULL, &error);
+ if (error)
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
+ if (pos_ret)
+ {
+ pos = ImmGetCompositionStringW (himc, GCS_CURSORPOS, NULL, 0);
+ if (pos < 0 || len < pos)
+ {
+ g_warning ("ImmGetCompositionString: "
+ "Invalid cursor position!");
+ pos = 0;
+ }
+ }
+ }
+ }
+
+ if (context_ime->commit_string)
+ {
+ if (utf8str)
+ {
+ gchar *utf8str_new = g_strdup (utf8str);
+
+ /* Note: We *don't* want to update context_ime->commit_string here!
+ * Otherwise it will be updated repeatedly, not what we want!
+ */
+ g_free (utf8str);
+ utf8str = g_strconcat (context_ime->commit_string,
+ utf8str_new,
+ NULL);
+ g_free (utf8str_new);
+ pos += g_utf8_strlen (context_ime->commit_string, -1);
+ }
+ else
+ {
+ utf8str = g_strdup (context_ime->commit_string);
+ pos = g_utf8_strlen (context_ime->commit_string, -1);
+ }
}
if (!utf8str)
@@ -1065,10 +1088,15 @@ gtk_im_context_ime_message_filter (GdkWin32Display *display,
g_warning ("%s", error->message);
g_error_free (error);
}
- }
- if (context_ime->commit_string)
- retval = GDK_WIN32_MESSAGE_FILTER_REMOVE;
+ if (context_ime->commit_string)
+ {
+ g_signal_emit_by_name (context, "commit", context_ime->commit_string);
+ g_free (context_ime->commit_string);
+ context_ime->commit_string = NULL;
+ retval = GDK_WIN32_MESSAGE_FILTER_REMOVE;
+ }
+ }
}
if (context_ime->use_preedit)
@@ -1089,13 +1117,6 @@ gtk_im_context_ime_message_filter (GdkWin32Display *display,
g_signal_emit_by_name (context, "preedit-changed");
g_signal_emit_by_name (context, "preedit-end");
- if (context_ime->commit_string)
- {
- g_signal_emit_by_name (context, "commit", context_ime->commit_string);
- g_free (context_ime->commit_string);
- context_ime->commit_string = NULL;
- }
-
if (context_ime->use_preedit)
retval = GDK_WIN32_MESSAGE_FILTER_REMOVE;
break;