5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 #include "glass_window.h" 26 #include "glass_general.h" 27 #include "glass_gtkcompat.h" 28 29 #include <cstring> 30 #include <cstdlib> 31 32 bool WindowContextBase::hasIME() { 33 return xim.enabled; 34 } 35 36 static XKeyPressedEvent convert_event(GdkEventKey *event) { 37 XKeyPressedEvent result; 38 memset(&result, 0, sizeof (result)); 39 40 result.type = (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease; 41 result.send_event = event->send_event; 42 result.display = gdk_x11_display_get_xdisplay(glass_gdk_window_get_display(event->window)); 43 result.window = result.subwindow = GDK_WINDOW_XID(event->window); 44 result.root = GDK_WINDOW_XID(gdk_screen_get_root_window(glass_gdk_window_get_screen(event->window))); 128 129 mainEnv->CallVoidMethod((jobject) client, jViewNotifyPreeditMode, JNI_TRUE); 130 CHECK_JNI_EXCEPTION_RET(mainEnv, -1); 131 return -1; // No restrictions 132 } 133 134 static void im_preedit_done(XIM im_xim, XPointer client, XPointer call) { 135 (void)im_xim; 136 (void)call; 137 138 mainEnv->CallVoidMethod((jobject) client, jViewNotifyPreeditMode, JNI_FALSE); 139 CHECK_JNI_EXCEPTION(mainEnv); 140 } 141 142 static void im_preedit_draw(XIM im_xim, XPointer client, XPointer call) { 143 (void)im_xim; 144 (void)call; 145 146 XIMPreeditDrawCallbackStruct *data = (XIMPreeditDrawCallbackStruct*) call; 147 jstring text = NULL; 148 if (data->text != NULL && data->text->string.multi_byte != NULL) { 149 if (data->text->encoding_is_wchar) { 150 size_t csize = wcstombs(NULL, data->text->string.wide_char, 0); 151 char *ctext = new char[csize + 1]; 152 wcstombs(ctext, data->text->string.wide_char, csize + 1); 153 text = mainEnv->NewStringUTF(ctext); 154 EXCEPTION_OCCURED(mainEnv); 155 delete[] ctext; 156 } else { 157 text = mainEnv->NewStringUTF(data->text->string.multi_byte); 158 EXCEPTION_OCCURED(mainEnv); 159 } 160 } 161 162 mainEnv->CallVoidMethod((jobject)client, jViewNotifyInputMethodDraw, 163 text, data->chg_first, data->chg_length, data->caret); 164 CHECK_JNI_EXCEPTION(mainEnv) 165 } 166 167 static void im_preedit_caret(XIM im_xim, XPointer client, XPointer call) { 168 (void)im_xim; 169 170 XIMPreeditCaretCallbackStruct *data = (XIMPreeditCaretCallbackStruct*) call; 171 mainEnv->CallVoidMethod((jobject)client, jViewNotifyInputMethodCaret, 172 data->position, data->direction, data->style); 173 CHECK_JNI_EXCEPTION(mainEnv) 174 } 175 176 static XIMStyle get_best_supported_style(XIM im_xim) 177 { 178 XIMStyles* styles; 179 int i; 180 XIMStyle result = 0; 181 182 if (XGetIMValues(im_xim, XNQueryInputStyle, &styles, NULL) != NULL) { // NULL means it's OK 183 return 0; | 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #include "com_sun_glass_ui_View.h" 27 #include "glass_window.h" 28 #include "glass_general.h" 29 #include "glass_gtkcompat.h" 30 31 #include <cstring> 32 #include <cstdlib> 33 34 bool WindowContextBase::hasIME() { 35 return xim.enabled; 36 } 37 38 static XKeyPressedEvent convert_event(GdkEventKey *event) { 39 XKeyPressedEvent result; 40 memset(&result, 0, sizeof (result)); 41 42 result.type = (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease; 43 result.send_event = event->send_event; 44 result.display = gdk_x11_display_get_xdisplay(glass_gdk_window_get_display(event->window)); 45 result.window = result.subwindow = GDK_WINDOW_XID(event->window); 46 result.root = GDK_WINDOW_XID(gdk_screen_get_root_window(glass_gdk_window_get_screen(event->window))); 130 131 mainEnv->CallVoidMethod((jobject) client, jViewNotifyPreeditMode, JNI_TRUE); 132 CHECK_JNI_EXCEPTION_RET(mainEnv, -1); 133 return -1; // No restrictions 134 } 135 136 static void im_preedit_done(XIM im_xim, XPointer client, XPointer call) { 137 (void)im_xim; 138 (void)call; 139 140 mainEnv->CallVoidMethod((jobject) client, jViewNotifyPreeditMode, JNI_FALSE); 141 CHECK_JNI_EXCEPTION(mainEnv); 142 } 143 144 static void im_preedit_draw(XIM im_xim, XPointer client, XPointer call) { 145 (void)im_xim; 146 (void)call; 147 148 XIMPreeditDrawCallbackStruct *data = (XIMPreeditDrawCallbackStruct*) call; 149 jstring text = NULL; 150 jbyteArray attr = NULL; 151 152 if (data->text != NULL) { 153 if (data->text->string.multi_byte) { 154 if (data->text->encoding_is_wchar) { 155 size_t csize = wcstombs(NULL, data->text->string.wide_char, 0); 156 char *ctext = new char[csize + 1]; 157 wcstombs(ctext, data->text->string.wide_char, csize + 1); 158 text = mainEnv->NewStringUTF(ctext); 159 delete[] ctext; 160 CHECK_JNI_EXCEPTION(mainEnv); 161 } else { 162 text = mainEnv->NewStringUTF(data->text->string.multi_byte); 163 CHECK_JNI_EXCEPTION(mainEnv); 164 } 165 } 166 167 if (XIMFeedback* fb = data->text->feedback) { 168 attr = mainEnv->NewByteArray(data->text->length); 169 CHECK_JNI_EXCEPTION(mainEnv) 170 jbyte v[data->text->length]; 171 for (int i = 0; i < data->text->length; i++) { 172 if (fb[i] & XIMReverse) { 173 v[i] = com_sun_glass_ui_View_IME_ATTR_TARGET_NOTCONVERTED; 174 } else if (fb[i] & XIMHighlight) { 175 v[i] = com_sun_glass_ui_View_IME_ATTR_TARGET_CONVERTED; 176 } else if (fb[i] & XIMUnderline) { 177 v[i] = com_sun_glass_ui_View_IME_ATTR_CONVERTED; 178 } else { 179 v[i] = com_sun_glass_ui_View_IME_ATTR_INPUT; 180 } 181 } 182 mainEnv->SetByteArrayRegion(attr, 0, data->text->length, v); 183 CHECK_JNI_EXCEPTION(mainEnv) 184 } 185 } 186 187 mainEnv->CallVoidMethod((jobject)client, jViewNotifyInputMethodDraw, 188 text, data->chg_first, data->chg_length, data->caret, attr); 189 CHECK_JNI_EXCEPTION(mainEnv) 190 } 191 192 static void im_preedit_caret(XIM im_xim, XPointer client, XPointer call) { 193 (void)im_xim; 194 195 XIMPreeditCaretCallbackStruct *data = (XIMPreeditCaretCallbackStruct*) call; 196 mainEnv->CallVoidMethod((jobject)client, jViewNotifyInputMethodCaret, 197 data->position, data->direction, data->style); 198 CHECK_JNI_EXCEPTION(mainEnv) 199 } 200 201 static XIMStyle get_best_supported_style(XIM im_xim) 202 { 203 XIMStyles* styles; 204 int i; 205 XIMStyle result = 0; 206 207 if (XGetIMValues(im_xim, XNQueryInputStyle, &styles, NULL) != NULL) { // NULL means it's OK 208 return 0; |