After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 101814 - Add string conversion callback to gtkimcontextxim
Add string conversion callback to gtkimcontextxim
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Input Methods
2.3.x
Other Linux
: Normal normal
: ---
Assigned To: Hidetoshi Tajima
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2002-12-22 17:14 UTC by Theppitak Karoonboonyanan
Modified: 2011-02-04 16:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
imxim patch for proper Thai XIM openning (1.69 KB, patch)
2002-12-22 17:18 UTC, Theppitak Karoonboonyanan
none Details | Review
experimental patch for StringConversionCallback (3.88 KB, patch)
2002-12-23 14:29 UTC, Theppitak Karoonboonyanan
none Details | Review
Summarized patch for the callback and for making Thai uses imxim by default (4.87 KB, patch)
2003-01-01 10:45 UTC, Theppitak Karoonboonyanan
none Details | Review
XFree86 patch for testing Thai XIM (xfree86-assigned sequence no. = 5553) (8.52 KB, patch)
2003-01-01 10:56 UTC, Theppitak Karoonboonyanan
none Details | Review
string conversion callback polishing (2.35 KB, patch)
2003-01-24 04:15 UTC, Theppitak Karoonboonyanan
none Details | Review
The summarized patch against GTK+ 2.2.1 (6.10 KB, patch)
2003-02-20 16:47 UTC, Theppitak Karoonboonyanan
none Details | Review
A proposed patch against CVS head (2004-02-16 snapshot) (6.36 KB, patch)
2004-02-19 10:32 UTC, Theppitak Karoonboonyanan
none Details | Review
My version of patch (8.00 KB, patch)
2004-03-11 23:29 UTC, Owen Taylor
none Details | Review

Description Theppitak Karoonboonyanan 2002-12-22 17:14:46 UTC
When using GTK+ 2.1.3 under th_TH locale, choosing XIM as the
input method (e.g. in gedit) will crash the program.

I find it's because of preedit and status style of IM openning,
which is suitable for CJK, but not for Thai.

So, I try patching as in the attached patch, and it works.

My another proposal to imxim is to provide one more callback
for Thai: StringConversionCallback, which is already supported
in XFree86 4.1.0+, so that the designed retrieve-surrounding
signal can be in action.
Comment 1 Theppitak Karoonboonyanan 2002-12-22 17:18:54 UTC
Created attachment 13172 [details] [review]
imxim patch for proper Thai XIM openning
Comment 2 Theppitak Karoonboonyanan 2002-12-23 14:26:47 UTC
Sorry, the symptom was not a crash. (It did crash in
2.1.0, but it had been fixed before 2.1.3.)
Rather, it's about dysfunction.

With my second proposal regarding the additional callback,
I've tried hacking out an experimental patch as attached.
Comment 3 Theppitak Karoonboonyanan 2002-12-23 14:29:02 UTC
Created attachment 13186 [details] [review]
experimental patch for StringConversionCallback
Comment 4 Hidetoshi Tajima 2002-12-23 21:43:06 UTC
With Thai XIM, what are returned when GtkIMContext queries a list of
supported input styles? If it has XNPreeditCallback, then
GtkIMContextXIM
is doing a right thing, otherwise, there may be something wrong with
chooing the input style either in the setup_styles() or in the 
choose_better_style()?

As to setting XNStringCallback, it will be perhaps better simply call
XSetICValues () without checking the locale name.
  - It is not true to judge from locale name - not all platforms has
     thai XIM implementation with XNStringCallback. 
  - The XSetICValues() call will return XNStringCallback if it is not
     supported by the XIM

[If we really want to check before calling XSetICValues, we may want
to chek the supported ic values(XNQueryICValuesList) to see if 
XNStringCallback is included or not, but I doubt that it is very
trustworthy
with all XIM implementations.]
  
Comment 5 Theppitak Karoonboonyanan 2002-12-24 17:41:29 UTC
The supported styles returned are
- 0x810 (PreeditNone|StatusNone)
- 0x408 (PreeditNothing|StatusNothing)


About the locale checking, yeah, my patches were dirty hacks,
just to show "if" it's forced like this, it works.
Please feel free to adjust to what you think suitable.
Comment 6 Theppitak Karoonboonyanan 2002-12-26 01:30:10 UTC
It's weird that when I change the code back (remove the locale
checkings), it still works. A similar confusion had once
happenned when I first added the locale checkings. GTK+
appeared stubborn to change and I had to enforce with
stronger condition (i.e. in he setup_style() itself) before
it changed.

So, I wonder if there is any saving to status file regarding
the preedit-style and status-style properties.

If not, it may be my own confusion.

In addition, I've found two more defects in the callback
function in my last patch:
- In case ForwardChar, q is not updated in the for loop.
  It should be q = g_utf8_next_char (q);
- In case BackwardChar, the string (text or surrounding) 
  should be reversed (according to the protocol).
Comment 7 Theppitak Karoonboonyanan 2003-01-01 10:43:04 UTC
I've finished the summarized patch for the callback and for 
making Thai uses imxim by default.

To test the patch with Thai XIM, you need another patch
for XFree86 which adds capability to correct the input
sequence to the XIM (will be attached later).
Comment 8 Theppitak Karoonboonyanan 2003-01-01 10:45:32 UTC
Created attachment 13303 [details] [review]
Summarized patch for the callback and for making Thai uses imxim by default
Comment 9 Theppitak Karoonboonyanan 2003-01-01 10:56:37 UTC
Created attachment 13304 [details] [review]
XFree86 patch for testing Thai XIM (xfree86-assigned sequence no. = 5553)
Comment 10 Theppitak Karoonboonyanan 2003-01-01 11:04:12 UTC
Note: The patches were based on Hideki Hiura's explanation on
the actual semantics of StringConversionCallback. Many thanks
to him.
Comment 11 Theppitak Karoonboonyanan 2003-01-06 01:54:47 UTC
FYI: I find XFree86 has accepted the patch to its CVS.
Comment 12 Owen Taylor 2003-01-23 00:01:34 UTC
the crash/misbehavior you were seeing is almost certainly
a dup of bug 103549, where the selected input style would
depend on the contents of unitialized memory.

Patch review comments:

 - 'if (i > 0) break;' should be broken onto two lines
 - You need to handle failure of g_locale_from_utf8(); it's
   quite likely the text in the widget won't be representable
   in the locale encoding.
 - You need to handle failure of malloc().
 - The algorithm for getting the range really doesn't
   look right to me. I've mailed xfree86-i18n and 
   Hideki Hiura for additional clarification.
Comment 13 Theppitak Karoonboonyanan 2003-01-24 04:13:27 UTC
Thank you for the patch review.

> - 'if (i > 0) break;' should be broken onto two lines

Done.

> - You need to handle failure of g_locale_from_utf8(); it's
>   quite likely the text in the widget won't be representable
>   in the locale encoding.

It's already handled by the "if (text)" block after the
"switch (conv_data->direction)" block. Any failure will be blocked here.
(Comment added.)

> - You need to handle failure of malloc().

Done.

> - The algorithm for getting the range really doesn't
>   look right to me. I've mailed xfree86-i18n and
>   Hideki Hiura for additional clarification.

Waiting for response.
Comment 14 Theppitak Karoonboonyanan 2003-01-24 04:15:58 UTC
Created attachment 13792 [details] [review]
string conversion callback polishing
Comment 15 Theppitak Karoonboonyanan 2003-02-20 16:45:13 UTC
I propose another patch that summarizes
all changes, plus XIM protocol fixing, and
querying the IM values before setting the
callback.

The XIM protocol part, however, depends on
signness of the XIMStringConversionPosition
type in Xlib.h, for which a patch is under
submission to XFree86. This may need
confirmation from X11 as well.
Comment 16 Theppitak Karoonboonyanan 2003-02-20 16:47:25 UTC
Created attachment 14473 [details] [review]
The summarized patch against GTK+ 2.2.1
Comment 17 Theppitak Karoonboonyanan 2003-03-17 08:45:53 UTC
While waiting for the response about the
protocol change, which may take several
steps, I propose a pretty feasible way for
Thai input method: raise the priority of
Bug #81031, in which some patches for
imthai have been proposed.
Comment 18 Noah Levitt 2004-02-19 04:01:47 UTC
Thep, is your patch still correct according to whatever has been
decided about the protocol? How can it be tested?
Comment 19 Theppitak Karoonboonyanan 2004-02-19 10:28:02 UTC
There has been no response regarding the XIMStringConversionPosition
signedness so far. So, only positive values are safe for the time being.

However, I think trying to cover it won't hurt. I have worked out another
patch against CVS head, with comment around the code in question added.
The code block for negative cases shall never be activated until the X
protocol is fixed. (Until then, XIM servers should not issue negative 
positions at all.)

For testing, just set locale to th_TH, with XMODIFIERS="@im=BasicCheck".
Of course, XKB map needs to be "th", e.g. "setxkbmap us,th -option 
grp:alt_shift_toggle". With XFree86 4.3.0, the Thai XIM should be able
to check & correct Thai input sequences. For example, this is an invalid
sequence:
[THO THAHAN] + [MAI EK] + [SARA II]
[U+0E17] + [U+0E48] + [U+0E35]
qwerty key strokes for th group: mju
SARA II should be inserted between THO THAHAN and MAI EK.
Comment 20 Theppitak Karoonboonyanan 2004-02-19 10:32:06 UTC
Created attachment 24546 [details] [review]
A proposed patch against CVS head (2004-02-16 snapshot)
Comment 21 Owen Taylor 2004-03-11 23:28:58 UTC
Looks pretty good; what I saw looking at the patch was:

 - A couple of formatting problems (no space in "function("
 - I think your patch leaked ic_values in 
   set_string_conversion_callback. Since we already 
   getting the same values when we open the IM initially,
   we might as well do the check only once there.
 - Without explicit casts to gshort for the position,
   GCC will optimize out things like:

    conv_data->position < 0

   because it knows it is positive.

I made a few changes to clean the above up; could you
test the new patch? If it works for you, we'll try to get
it into a 2.4.x dot release.
   
Comment 22 Owen Taylor 2004-03-11 23:29:21 UTC
Created attachment 25548 [details] [review]
My version of patch
Comment 23 Theppitak Karoonboonyanan 2004-03-12 03:27:25 UTC
Thank you for the patch review.
I have tested your patch and it works fine.
Comment 24 Theppitak Karoonboonyanan 2004-04-18 09:03:46 UTC
Patch tested. Should it be committed?
Comment 25 Matthias Clasen 2004-04-19 13:02:06 UTC
Owen already basically gave a commit-after-testing approval. Since you say it
works ok, we should get it in, ideally before 2.4.1.
Comment 26 Theppitak Karoonboonyanan 2004-04-24 10:07:14 UTC
So, I have committed Owen's patch to the HEAD. Is there other branch to commit?

--- ChangeLog   23 Apr 2004 20:01:53 -0000      1.5348
+++ ChangeLog   24 Apr 2004 09:51:57 -0000
@@ -1,3 +1,22 @@
+2004-04-24  Theppitak Karoonboonyanan  <thep@linux.thai.net>
+
+       Patch to add support for string conversion callbacks to
+       GtkIMContextXIM (#101814)
+
+       * modules/input/gtkimcontextxim.c: Set the string conversion callback
+       if supported by the XIC.
+
+       (struct _GtkIMContextXIM): Add string_conversion_callback member.
+
+       (struct _GtkXIMInfo, setup_im): Check and keep flag inidicating
+       whether string conversion callback is supported.
+
+       (gtk_im_context_get_ic, +set_string_conversion_callback,
+       +string_conversion_callback): Also initialize string conversion
+       callback, if supported, along with the IC initialization.
+
+       * modules/input/imxim.c: Make "xim" module default for Thai as well.
+
 2004-04-23  Matthias Clasen  <mclasen@redhat.com>

        * gtk/gtkclipboard.c (gtk_clipboard_wait_for_targets): Correctly
Comment 27 Theppitak Karoonboonyanan 2004-04-26 15:26:56 UTC
Mark bug as fixed.