summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2000-09-19 15:17:13 +0000
committerOwen Taylor <otaylor@src.gnome.org>2000-09-19 15:17:13 +0000
commit257e0f26efef81772816a722f730df0387a54263 (patch)
tree13f1c2b8a78e0d2d225fdb94ff965f8e04deaba6
parentf787ebb03f24399b9f862caf9116ce7c34cbd3df (diff)
downloadgtk+-gtk-new-im.tar.gz
Rip out support for multiple locales; that simple doesn't work reliablygtk-new-im
Tue Sep 19 10:54:22 2000 Owen Taylor <otaylor@redhat.com> * modules/input/{gtkimcontextxim.[ch],imxim.c}: Rip out support for multiple locales; that simple doesn't work reliably with current Xlib * gtk/gtkimcontext*.[ch] gtk/gtkimmulticontext.[ch] gtk/gtktextlayout.[ch] gtk/gtktextview.c gtk/gtkentry.c: Add support for positioning the cursor within the preedit string. * modules/input/gtkimcontextxim.[ch]:
-rw-r--r--ChangeLog12
-rw-r--r--ChangeLog.pre-2-012
-rw-r--r--ChangeLog.pre-2-1012
-rw-r--r--ChangeLog.pre-2-212
-rw-r--r--ChangeLog.pre-2-412
-rw-r--r--ChangeLog.pre-2-612
-rw-r--r--ChangeLog.pre-2-812
-rw-r--r--gtk/gtkentry.c16
-rw-r--r--gtk/gtkentry.h1
-rw-r--r--gtk/gtkimcontext.c13
-rw-r--r--gtk/gtkimcontext.h6
-rw-r--r--gtk/gtkimcontextsimple.c9
-rw-r--r--gtk/gtkimmulticontext.c8
-rw-r--r--gtk/gtktextlayout.c14
-rw-r--r--gtk/gtktextlayout.h4
-rw-r--r--gtk/gtktextview.c5
-rw-r--r--gtk/testtext.c1
-rw-r--r--modules/input/gtkimcontextxim.c110
-rw-r--r--modules/input/gtkimcontextxim.h7
-rw-r--r--modules/input/imxim.c8
-rw-r--r--tests/testtext.c1
21 files changed, 212 insertions, 75 deletions
diff --git a/ChangeLog b/ChangeLog
index e45931e7d9..5852a3f57c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Tue Sep 19 10:54:22 2000 Owen Taylor <otaylor@redhat.com>
+
+ * modules/input/{gtkimcontextxim.[ch],imxim.c}: Rip
+ out support for multiple locales; that simple doesn't
+ work reliably with current Xlib
+
+ * gtk/gtkimcontext*.[ch] gtk/gtkimmulticontext.[ch]
+ gtk/gtktextlayout.[ch] gtk/gtktextview.c gtk/gtkentry.c:
+ Add support for positioning the cursor within the preedit string.
+
+ * modules/input/gtkimcontextxim.[ch]:
+
Mon Sep 18 23:56:32 2000 Owen Taylor <otaylor@redhat.com>
* modules/input/{imxim.c,gtkimcontextxim.[ch]}: Start
diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0
index e45931e7d9..5852a3f57c 100644
--- a/ChangeLog.pre-2-0
+++ b/ChangeLog.pre-2-0
@@ -1,3 +1,15 @@
+Tue Sep 19 10:54:22 2000 Owen Taylor <otaylor@redhat.com>
+
+ * modules/input/{gtkimcontextxim.[ch],imxim.c}: Rip
+ out support for multiple locales; that simple doesn't
+ work reliably with current Xlib
+
+ * gtk/gtkimcontext*.[ch] gtk/gtkimmulticontext.[ch]
+ gtk/gtktextlayout.[ch] gtk/gtktextview.c gtk/gtkentry.c:
+ Add support for positioning the cursor within the preedit string.
+
+ * modules/input/gtkimcontextxim.[ch]:
+
Mon Sep 18 23:56:32 2000 Owen Taylor <otaylor@redhat.com>
* modules/input/{imxim.c,gtkimcontextxim.[ch]}: Start
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index e45931e7d9..5852a3f57c 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,15 @@
+Tue Sep 19 10:54:22 2000 Owen Taylor <otaylor@redhat.com>
+
+ * modules/input/{gtkimcontextxim.[ch],imxim.c}: Rip
+ out support for multiple locales; that simple doesn't
+ work reliably with current Xlib
+
+ * gtk/gtkimcontext*.[ch] gtk/gtkimmulticontext.[ch]
+ gtk/gtktextlayout.[ch] gtk/gtktextview.c gtk/gtkentry.c:
+ Add support for positioning the cursor within the preedit string.
+
+ * modules/input/gtkimcontextxim.[ch]:
+
Mon Sep 18 23:56:32 2000 Owen Taylor <otaylor@redhat.com>
* modules/input/{imxim.c,gtkimcontextxim.[ch]}: Start
diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2
index e45931e7d9..5852a3f57c 100644
--- a/ChangeLog.pre-2-2
+++ b/ChangeLog.pre-2-2
@@ -1,3 +1,15 @@
+Tue Sep 19 10:54:22 2000 Owen Taylor <otaylor@redhat.com>
+
+ * modules/input/{gtkimcontextxim.[ch],imxim.c}: Rip
+ out support for multiple locales; that simple doesn't
+ work reliably with current Xlib
+
+ * gtk/gtkimcontext*.[ch] gtk/gtkimmulticontext.[ch]
+ gtk/gtktextlayout.[ch] gtk/gtktextview.c gtk/gtkentry.c:
+ Add support for positioning the cursor within the preedit string.
+
+ * modules/input/gtkimcontextxim.[ch]:
+
Mon Sep 18 23:56:32 2000 Owen Taylor <otaylor@redhat.com>
* modules/input/{imxim.c,gtkimcontextxim.[ch]}: Start
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index e45931e7d9..5852a3f57c 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -1,3 +1,15 @@
+Tue Sep 19 10:54:22 2000 Owen Taylor <otaylor@redhat.com>
+
+ * modules/input/{gtkimcontextxim.[ch],imxim.c}: Rip
+ out support for multiple locales; that simple doesn't
+ work reliably with current Xlib
+
+ * gtk/gtkimcontext*.[ch] gtk/gtkimmulticontext.[ch]
+ gtk/gtktextlayout.[ch] gtk/gtktextview.c gtk/gtkentry.c:
+ Add support for positioning the cursor within the preedit string.
+
+ * modules/input/gtkimcontextxim.[ch]:
+
Mon Sep 18 23:56:32 2000 Owen Taylor <otaylor@redhat.com>
* modules/input/{imxim.c,gtkimcontextxim.[ch]}: Start
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index e45931e7d9..5852a3f57c 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,15 @@
+Tue Sep 19 10:54:22 2000 Owen Taylor <otaylor@redhat.com>
+
+ * modules/input/{gtkimcontextxim.[ch],imxim.c}: Rip
+ out support for multiple locales; that simple doesn't
+ work reliably with current Xlib
+
+ * gtk/gtkimcontext*.[ch] gtk/gtkimmulticontext.[ch]
+ gtk/gtktextlayout.[ch] gtk/gtktextview.c gtk/gtkentry.c:
+ Add support for positioning the cursor within the preedit string.
+
+ * modules/input/gtkimcontextxim.[ch]:
+
Mon Sep 18 23:56:32 2000 Owen Taylor <otaylor@redhat.com>
* modules/input/{imxim.c,gtkimcontextxim.[ch]}: Start
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index e45931e7d9..5852a3f57c 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,15 @@
+Tue Sep 19 10:54:22 2000 Owen Taylor <otaylor@redhat.com>
+
+ * modules/input/{gtkimcontextxim.[ch],imxim.c}: Rip
+ out support for multiple locales; that simple doesn't
+ work reliably with current Xlib
+
+ * gtk/gtkimcontext*.[ch] gtk/gtkimmulticontext.[ch]
+ gtk/gtktextlayout.[ch] gtk/gtktextview.c gtk/gtkentry.c:
+ Add support for positioning the cursor within the preedit string.
+
+ * modules/input/gtkimcontextxim.[ch]:
+
Mon Sep 18 23:56:32 2000 Owen Taylor <otaylor@redhat.com>
* modules/input/{imxim.c,gtkimcontextxim.[ch]}: Start
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index ab9782f96a..5ad764c49e 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -1557,10 +1557,14 @@ gtk_entry_preedit_changed_cb (GtkIMContext *context,
GtkEntry *entry)
{
gchar *preedit_string;
+ gint cursor_pos;
gtk_im_context_get_preedit_string (entry->im_context,
- &preedit_string, NULL);
+ &preedit_string, NULL,
+ &cursor_pos);
entry->preedit_length = strlen (preedit_string);
+ cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1));
+ cursor_pos = g_utf8_offset_to_pointer (preedit_string, cursor_pos) - preedit_string;
g_free (preedit_string);
gtk_entry_recompute (entry);
@@ -1618,7 +1622,7 @@ gtk_entry_create_layout (GtkEntry *entry,
if (include_preedit)
{
gtk_im_context_get_preedit_string (entry->im_context,
- &preedit_string, &preedit_attrs);
+ &preedit_string, &preedit_attrs, NULL);
preedit_length = entry->preedit_length;
}
@@ -1859,15 +1863,11 @@ gtk_entry_get_cursor_locations (GtkEntry *entry,
gint *weak_x)
{
PangoLayout *layout = gtk_entry_get_layout (entry, TRUE);
- gint cursor_index = g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text;
+ gint index = g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text;
PangoRectangle strong_pos, weak_pos;
- gint index;
-
- index = g_utf8_offset_to_pointer (entry->text, entry->current_pos) - entry->text;
- if (index >= cursor_index)
- index += entry->preedit_length;
+ index += entry->preedit_cursor;
pango_layout_get_cursor_pos (layout, index, &strong_pos, &weak_pos);
g_object_unref (G_OBJECT (layout));
diff --git a/gtk/gtkentry.h b/gtk/gtkentry.h
index 1971cfca89..765da78f03 100644
--- a/gtk/gtkentry.h
+++ b/gtk/gtkentry.h
@@ -86,6 +86,7 @@ struct _GtkEntry
guint16 n_bytes; /* length in use, in bytes */
guint16 preedit_length; /* length of preedit string, in bytes */
+ guint16 preedit_cursor; /* offset of cursor within preedit string, in bytes */
};
struct _GtkEntryClass
diff --git a/gtk/gtkimcontext.c b/gtk/gtkimcontext.c
index 240bac39b7..0541e25516 100644
--- a/gtk/gtkimcontext.c
+++ b/gtk/gtkimcontext.c
@@ -35,7 +35,8 @@ static void gtk_im_context_init (GtkIMContext *im_context);
static void gtk_im_context_real_get_preedit_string (GtkIMContext *context,
gchar **str,
- PangoAttrList **attrs);
+ PangoAttrList **attrs,
+ gint *cursor_pos);
static gboolean gtk_im_context_real_filter_keypress (GtkIMContext *context,
GdkEventKey *event);
@@ -118,12 +119,15 @@ gtk_im_context_init (GtkIMContext *im_context)
static void
gtk_im_context_real_get_preedit_string (GtkIMContext *context,
gchar **str,
- PangoAttrList **attrs)
+ PangoAttrList **attrs,
+ gint *cursor_pos)
{
if (str)
*str = g_strdup ("");
if (attrs)
*attrs = pango_attr_list_new ();
+ if (cursor_pos)
+ *cursor_pos = 0;
}
static gboolean
@@ -175,7 +179,8 @@ gtk_im_context_set_client_window (GtkIMContext *context,
void
gtk_im_context_get_preedit_string (GtkIMContext *context,
gchar **str,
- PangoAttrList **attrs)
+ PangoAttrList **attrs,
+ gint *cursor_pos)
{
GtkIMContextClass *klass;
@@ -183,7 +188,7 @@ gtk_im_context_get_preedit_string (GtkIMContext *context,
g_return_if_fail (GTK_IS_IM_CONTEXT (context));
klass = GTK_IM_CONTEXT_GET_CLASS (context);
- klass->get_preedit_string (context, str, attrs);
+ klass->get_preedit_string (context, str, attrs, cursor_pos);
}
/**
diff --git a/gtk/gtkimcontext.h b/gtk/gtkimcontext.h
index 8c786508b9..6435c4eaf8 100644
--- a/gtk/gtkimcontext.h
+++ b/gtk/gtkimcontext.h
@@ -60,7 +60,8 @@ struct _GtkIMContextClass
GdkWindow *window);
void (*get_preedit_string) (GtkIMContext *context,
gchar **str,
- PangoAttrList **attrs);
+ PangoAttrList **attrs,
+ gint *cursor_pos);
gboolean (*filter_keypress) (GtkIMContext *context,
GdkEventKey *event);
void (*focus_in) (GtkIMContext *context);
@@ -74,7 +75,8 @@ void gtk_im_context_set_client_window (GtkIMContext *context,
GdkWindow *window);
void gtk_im_context_get_preedit_string (GtkIMContext *context,
gchar **str,
- PangoAttrList **attrs);
+ PangoAttrList **attrs,
+ gint *cursor_pos);
gboolean gtk_im_context_filter_keypress (GtkIMContext *context,
GdkEventKey *event);
void gtk_im_context_focus_in (GtkIMContext *context);
diff --git a/gtk/gtkimcontextsimple.c b/gtk/gtkimcontextsimple.c
index 397c18a9d9..a01c85c3bd 100644
--- a/gtk/gtkimcontextsimple.c
+++ b/gtk/gtkimcontextsimple.c
@@ -747,7 +747,8 @@ static gboolean gtk_im_context_simple_filter_keypress (GtkIMContext
static void gtk_im_context_simple_reset (GtkIMContext *context);
static void gtk_im_context_simple_get_preedit_string (GtkIMContext *context,
gchar **str,
- PangoAttrList **attrs);
+ PangoAttrList **attrs,
+ gint *cursor_pos);
static GObjectClass *parent_class;
@@ -1006,7 +1007,8 @@ gtk_im_context_simple_reset (GtkIMContext *context)
static void
gtk_im_context_simple_get_preedit_string (GtkIMContext *context,
gchar **str,
- PangoAttrList **attrs)
+ PangoAttrList **attrs,
+ gint *cursor_pos)
{
char outbuf[7];
int len = 0;
@@ -1031,6 +1033,9 @@ gtk_im_context_simple_get_preedit_string (GtkIMContext *context,
pango_attr_list_insert (*attrs, attr);
}
}
+
+ if (cursor_pos)
+ cursor_pos = context_simple->tentative_match ? 1 : 0;
}
/**
diff --git a/gtk/gtkimmulticontext.c b/gtk/gtkimmulticontext.c
index 20e39e5b5f..2ec808356f 100644
--- a/gtk/gtkimmulticontext.c
+++ b/gtk/gtkimmulticontext.c
@@ -41,7 +41,8 @@ static void gtk_im_multicontext_set_client_window (GtkIMContext
GdkWindow *window);
static void gtk_im_multicontext_get_preedit_string (GtkIMContext *context,
gchar **str,
- PangoAttrList **attrs);
+ PangoAttrList **attrs,
+ gint *cursor_pos);
static gboolean gtk_im_multicontext_filter_keypress (GtkIMContext *context,
GdkEventKey *event);
static void gtk_im_multicontext_focus_in (GtkIMContext *context);
@@ -200,13 +201,14 @@ gtk_im_multicontext_set_client_window (GtkIMContext *context,
static void
gtk_im_multicontext_get_preedit_string (GtkIMContext *context,
gchar **str,
- PangoAttrList **attrs)
+ PangoAttrList **attrs,
+ gint *cursor_pos)
{
GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context);
GtkIMContext *slave = gtk_im_multicontext_get_slave (multicontext);
if (slave)
- gtk_im_context_get_preedit_string (slave, str, attrs);
+ gtk_im_context_get_preedit_string (slave, str, attrs, cursor_pos);
else
{
if (str)
diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c
index ac0530252c..5d070a5bb7 100644
--- a/gtk/gtktextlayout.c
+++ b/gtk/gtktextlayout.c
@@ -343,6 +343,7 @@ gtk_text_layout_set_screen_width (GtkTextLayout *layout, gint width)
* @layout: a #PangoLayout
* @preedit_string: a string to display at the insertion point
* @preedit_attrs: a #PangoAttrList of attributes that apply to @preedit_string
+ * @cursor_pos: position of cursor within preedit string in chars
*
* Set the preedit string and attributes. The preedit string is a
* string showing text that is currently being edited and not
@@ -351,7 +352,8 @@ gtk_text_layout_set_screen_width (GtkTextLayout *layout, gint width)
void
gtk_text_layout_set_preedit_string (GtkTextLayout *layout,
const gchar *preedit_string,
- PangoAttrList *preedit_attrs)
+ PangoAttrList *preedit_attrs,
+ gint cursor_pos)
{
GtkTextIter iter;
GtkTextLine *line;
@@ -372,12 +374,16 @@ gtk_text_layout_set_preedit_string (GtkTextLayout *layout,
layout->preedit_len = strlen (layout->preedit_string);
pango_attr_list_ref (preedit_attrs);
layout->preedit_attrs = preedit_attrs;
+
+ cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (layout->preedit_string, -1));
+ layout->preedit_cursor = g_utf8_offset_to_pointer (layout->preedit_string, cursor_pos) - layout->preedit_string;
}
else
{
layout->preedit_string = NULL;
layout->preedit_len = 0;
layout->preedit_attrs = NULL;
+ layout->preedit_cursor = 0;
}
/* Now invalidate the paragraph containing the cursor
@@ -1526,6 +1532,8 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout,
else if (seg->type == &gtk_text_right_mark_type ||
seg->type == &gtk_text_left_mark_type)
{
+ gint cursor_offset = 0;
+
/* At the insertion point, add the preedit string, if any */
if (gtk_text_btree_mark_is_insert (_gtk_text_buffer_get_btree (layout->buffer),
@@ -1544,6 +1552,8 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout,
memcpy (text + byte_offset, layout->preedit_string, layout->preedit_len);
byte_offset += layout->preedit_len;
+
+ cursor_offset = layout->preedit_cursor - layout->preedit_len;
}
}
@@ -1551,7 +1561,7 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout,
if (seg->body.mark.visible)
{
- cursor_byte_offsets = g_slist_prepend (cursor_byte_offsets, GINT_TO_POINTER (byte_offset));
+ cursor_byte_offsets = g_slist_prepend (cursor_byte_offsets, GINT_TO_POINTER (byte_offset + cursor_offset));
cursor_segs = g_slist_prepend (cursor_segs, seg);
}
}
diff --git a/gtk/gtktextlayout.h b/gtk/gtktextlayout.h
index ce35949da4..0318a068e4 100644
--- a/gtk/gtktextlayout.h
+++ b/gtk/gtktextlayout.h
@@ -76,6 +76,7 @@ struct _GtkTextLayout
gchar *preedit_string;
PangoAttrList *preedit_attrs;
gint preedit_len;
+ gint preedit_cursor;
};
struct _GtkTextLayoutClass
@@ -165,7 +166,8 @@ void gtk_text_layout_set_screen_width (GtkTextLayout *layout,
gint width);
void gtk_text_layout_set_preedit_string (GtkTextLayout *layout,
const gchar *preedit_string,
- PangoAttrList *preedit_attrs);
+ PangoAttrList *preedit_attrs,
+ gint cursor_pos);
void gtk_text_layout_set_cursor_visible (GtkTextLayout *layout,
gboolean cursor_visible);
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index a6220e71a4..7351cfd148 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -2946,9 +2946,10 @@ gtk_text_view_preedit_changed_handler (GtkIMContext *context,
{
gchar *str;
PangoAttrList *attrs;
+ gint cursor_pos;
- gtk_im_context_get_preedit_string (context, &str, &attrs);
- gtk_text_layout_set_preedit_string (text_view->layout, str, attrs);
+ gtk_im_context_get_preedit_string (context, &str, &attrs, &cursor_pos);
+ gtk_text_layout_set_preedit_string (text_view->layout, str, attrs, cursor_pos);
pango_attr_list_unref (attrs);
g_free (str);
diff --git a/gtk/testtext.c b/gtk/testtext.c
index c215c3ad12..96cef1b00d 100644
--- a/gtk/testtext.c
+++ b/gtk/testtext.c
@@ -1444,6 +1444,7 @@ main (int argc, char** argv)
int i;
test_init ();
+ gtk_set_locale ();
gtk_init (&argc, &argv);
buffer = create_buffer ();
diff --git a/modules/input/gtkimcontextxim.c b/modules/input/gtkimcontextxim.c
index 0f16655339..6a15a340e4 100644
--- a/modules/input/gtkimcontextxim.c
+++ b/modules/input/gtkimcontextxim.c
@@ -40,7 +40,8 @@ static gboolean gtk_im_context_xim_filter_keypress (GtkIMContext *co
static void gtk_im_context_xim_reset (GtkIMContext *context);
static void gtk_im_context_xim_get_preedit_string (GtkIMContext *context,
gchar **str,
- PangoAttrList **attrs);
+ PangoAttrList **attrs,
+ gint *cursor_pos);
static XIC gtk_im_context_xim_get_ic (GtkIMContextXIM *context_xim);
static GObjectClass *parent_class;
@@ -152,7 +153,6 @@ get_im (const char *locale)
GSList *tmp_list = open_ims;
GtkXIMInfo *info;
XIM im = NULL;
- char *old_locale;
while (tmp_list)
{
@@ -164,15 +164,14 @@ get_im (const char *locale)
}
info = NULL;
- old_locale = g_strdup (setlocale (LC_CTYPE, NULL));
- if (setlocale (LC_CTYPE, locale) && XSupportsLocale ())
+ if (XSupportsLocale ())
{
if (!XSetLocaleModifiers (""))
g_warning ("can not set locale modifiers");
-
+
im = XOpenIM (GDK_DISPLAY(), NULL, NULL, NULL);
-
+
if (im)
{
info = g_new (GtkXIMInfo, 1);
@@ -185,9 +184,6 @@ get_im (const char *locale)
}
}
- setlocale (LC_CTYPE, old_locale);
- g_free (old_locale);
-
return info;
}
@@ -223,7 +219,6 @@ gtk_im_context_xim_finalize (GObject *obj)
}
g_free (context_xim->mb_charset);
- g_free (context_xim->wide_charset);
}
static void
@@ -242,22 +237,22 @@ gtk_im_context_xim_set_client_window (GtkIMContext *context,
}
GtkIMContext *
-gtk_im_context_xim_new (const gchar *locale,
- const gchar *mb_charset,
- const gchar *wide_charset)
+gtk_im_context_xim_new (void)
{
GtkXIMInfo *info;
GtkIMContextXIM *result;
+ gchar *charset;
- info = get_im (locale);
+ info = get_im (setlocale (LC_CTYPE, NULL));
if (!info)
return NULL;
result = GTK_IM_CONTEXT_XIM (gtk_type_new (GTK_TYPE_IM_CONTEXT_XIM));
result->im_info = info;
- result->mb_charset = g_strdup (mb_charset);
- result->wide_charset = g_strdup (wide_charset);
+
+ g_get_charset (&charset);
+ result->mb_charset = g_strdup (charset);
return GTK_IM_CONTEXT (result);
}
@@ -267,10 +262,11 @@ mb_to_utf8 (GtkIMContextXIM *context_xim,
const char *str)
{
GError *error = NULL;
-
- gchar *result = g_convert (str, -1,
- "UTF-8", context_xim->mb_charset,
- NULL, NULL, &error);
+ gchar *result;
+
+ result = g_convert (str, -1,
+ "UTF-8", context_xim->mb_charset,
+ NULL, NULL, &error);
if (!result)
{
@@ -425,12 +421,16 @@ add_feedback_attr (PangoAttrList *attrs,
pango_attr_list_change (attrs, attr);
}
+
+ if (feedback & ~FEEDBACK_MASK)
+ g_warning ("Unrendered feedback style: %#lx", feedback & ~FEEDBACK_MASK);
}
static void
gtk_im_context_xim_get_preedit_string (GtkIMContext *context,
gchar **str,
- PangoAttrList **attrs)
+ PangoAttrList **attrs,
+ gint *cursor_pos)
{
GtkIMContextXIM *context_xim = GTK_IM_CONTEXT_XIM (context);
gchar *utf8 = g_ucs4_to_utf8 (context_xim->preedit_chars, context_xim->preedit_length);
@@ -464,6 +464,9 @@ gtk_im_context_xim_get_preedit_string (GtkIMContext *context,
*str = utf8;
else
g_free (utf8);
+
+ if (cursor_pos)
+ *cursor_pos = context_xim->preedit_cursor;
}
static void
@@ -497,10 +500,17 @@ xim_text_to_utf8 (GtkIMContextXIM *context, XIMText *xim_text, gchar **text)
if (xim_text && xim_text->string.multi_byte)
{
+ if (xim_text->encoding_is_wchar)
+ {
+ g_warning ("Wide character return from Xlib not currently supported");
+ *text = NULL;
+ return 0;
+ }
+
result = g_convert (xim_text->string.multi_byte,
- xim_text->encoding_is_wchar ? xim_text->length : -1,
+ -1,
"UTF-8",
- xim_text->encoding_is_wchar ? context->wide_charset : context->mb_charset,
+ context->mb_charset,
NULL, &text_length, &error);
if (result)
@@ -509,12 +519,12 @@ xim_text_to_utf8 (GtkIMContextXIM *context, XIMText *xim_text, gchar **text)
if (text_length != xim_text->length)
{
- g_warning ("Size mismatch when converting text from input method: supplied length = %d\n, result length = %d\n", xim_text->length, text_length);
+ g_warning ("Size mismatch when converting text from input method: supplied length = %d\n, result length = %d", xim_text->length, text_length);
}
}
else
{
- g_warning ("Error converting text from IM to UCS-4: %s\n", error->message);
+ g_warning ("Error converting text from IM to UCS-4: %s", error->message);
g_error_free (error);
}
@@ -546,6 +556,8 @@ preedit_draw_callback (XIC xic,
gint chg_first = CLAMP (call_data->chg_first, 0, context->preedit_length);
gint chg_length = CLAMP (call_data->chg_length, 0, context->preedit_length - chg_first);
+ context->preedit_cursor = call_data->caret;
+
if (chg_first != call_data->chg_first || chg_length != call_data->chg_length)
g_warning ("Invalid change to preedit string, first=%d length=%d (orig length == %d)",
call_data->chg_first, call_data->chg_length, context->preedit_length);
@@ -600,11 +612,23 @@ preedit_draw_callback (XIC xic,
static void
-preedit_caret_callback (XIC xic,
- XPointer client_data,
- XIMPreeditCaretCallbackStruct call_data)
+preedit_caret_callback (XIC xic,
+ XPointer client_data,
+ XIMPreeditCaretCallbackStruct *call_data)
{
-}
+ GtkIMContextXIM *context = GTK_IM_CONTEXT_XIM (client_data);
+
+ if (call_data->direction == XIMAbsolutePosition)
+ {
+ context->preedit_cursor = call_data->position;
+ gtk_signal_emit_by_name (GTK_OBJECT (context), "preedit-changed");
+ }
+ else
+ {
+ g_warning ("Caret movement command: %d %d %d not supported",
+ call_data->position, call_data->direction, call_data->style);
+ }
+}
static void
status_start_callback (XIC xic,
@@ -656,14 +680,14 @@ gtk_im_context_xim_get_ic (GtkIMContextXIM *context_xim)
{
if ((context_xim->im_info->style & PREEDIT_MASK) == XIMPreeditCallbacks)
{
- context_xim->preedit_start_callback.client_data = context_xim;
- context_xim->preedit_start_callback.callback = preedit_start_callback;
- context_xim->preedit_done_callback.client_data = context_xim;
- context_xim->preedit_done_callback.callback = preedit_done_callback;
- context_xim->preedit_draw_callback.client_data = context_xim;
- context_xim->preedit_draw_callback.callback = preedit_draw_callback;
- context_xim->preedit_caret_callback.client_data = context_xim;
- context_xim->preedit_caret_callback.callback = preedit_caret_callback;
+ context_xim->preedit_start_callback.client_data = (XPointer)context_xim;
+ context_xim->preedit_start_callback.callback = (XIMProc)preedit_start_callback;
+ context_xim->preedit_done_callback.client_data = (XPointer)context_xim;
+ context_xim->preedit_done_callback.callback = (XIMProc)preedit_done_callback;
+ context_xim->preedit_draw_callback.client_data = (XPointer)context_xim;
+ context_xim->preedit_draw_callback.callback = (XIMProc)preedit_draw_callback;
+ context_xim->preedit_caret_callback.client_data = (XPointer)context_xim;
+ context_xim->preedit_caret_callback.callback = (XIMProc)preedit_caret_callback;
name1 = XNPreeditAttributes;
list1 = XVaCreateNestedList (0,
@@ -678,12 +702,12 @@ gtk_im_context_xim_get_ic (GtkIMContextXIM *context_xim)
{
XVaNestedList *status_attrs;
- context_xim->status_start_callback.client_data = context_xim;
- context_xim->status_start_callback.callback = status_start_callback;
- context_xim->status_done_callback.client_data = context_xim;
- context_xim->status_done_callback.callback = status_done_callback;
- context_xim->status_draw_callback.client_data = context_xim;
- context_xim->status_draw_callback.callback = status_draw_callback;
+ context_xim->status_start_callback.client_data = (XPointer)context_xim;
+ context_xim->status_start_callback.callback = (XIMProc)status_start_callback;
+ context_xim->status_done_callback.client_data = (XPointer)context_xim;
+ context_xim->status_done_callback.callback = (XIMProc)status_done_callback;
+ context_xim->status_draw_callback.client_data = (XPointer)context_xim;
+ context_xim->status_draw_callback.callback = (XIMProc)status_draw_callback;
status_attrs = XVaCreateNestedList (0,
XNStatusStartCallback, &context_xim->status_start_callback,
diff --git a/modules/input/gtkimcontextxim.h b/modules/input/gtkimcontextxim.h
index 64294d1155..2e3e6f1a8c 100644
--- a/modules/input/gtkimcontextxim.h
+++ b/modules/input/gtkimcontextxim.h
@@ -51,7 +51,6 @@ struct _GtkIMContextXIM
GtkXIMInfo *im_info;
gchar *mb_charset;
- gchar *wide_charset;
GdkWindow *client_window;
@@ -60,6 +59,8 @@ struct _GtkIMContextXIM
gunichar *preedit_chars;
XIMFeedback *feedbacks;
+ gint preedit_cursor;
+
XIMCallback preedit_start_callback;
XIMCallback preedit_done_callback;
XIMCallback preedit_draw_callback;
@@ -78,9 +79,7 @@ struct _GtkIMContextXIMClass
};
void gtk_im_context_xim_register_type (GtkModule *module);
-GtkIMContext *gtk_im_context_xim_new (const gchar *locale,
- const gchar *mb_charset,
- const gchar *wide_charset);
+GtkIMContext *gtk_im_context_xim_new (void);
#ifdef __cplusplus
}
diff --git a/modules/input/imxim.c b/modules/input/imxim.c
index 1b8c6c6920..eda9cb64c1 100644
--- a/modules/input/imxim.c
+++ b/modules/input/imxim.c
@@ -23,8 +23,8 @@
#include <string.h>
static const GtkIMContextInfo xim_ja_info = {
- "xim-ja", /* ID */
- N_("Japanese (XIM)"), /* Human readable name */
+ "xim", /* ID */
+ N_("X Input Method"), /* Human readable name */
"gtk+", /* Translation domain */
GTK_LOCALEDIR, /* Dir for bindtextdomain (not strictly needed for "gtk+") */
"ja" /* Languages for which this module is the default */
@@ -56,8 +56,8 @@ im_module_list (const GtkIMContextInfo ***contexts,
GtkIMContext *
im_module_create (const gchar *context_id)
{
- if (strcmp (context_id, "xim-ja") == 0)
- return gtk_im_context_xim_new ("ja_JP.eucjp", "EUC-JP", "INTERNAL");
+ if (strcmp (context_id, "xim") == 0)
+ return gtk_im_context_xim_new ();
else
return NULL;
}
diff --git a/tests/testtext.c b/tests/testtext.c
index c215c3ad12..96cef1b00d 100644
--- a/tests/testtext.c
+++ b/tests/testtext.c
@@ -1444,6 +1444,7 @@ main (int argc, char** argv)
int i;
test_init ();
+ gtk_set_locale ();
gtk_init (&argc, &argv);
buffer = create_buffer ();