1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
29
30 #include "awt.h"
31 #include "awt_p.h"
32
33 #include <sun_awt_X11InputMethodBase.h>
34 #include <sun_awt_X11_XInputMethod.h>
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <sys/time.h>
39 #include <X11/keysym.h>
40 #include <X11/Xlib.h>
41
42 #define THROW_OUT_OF_MEMORY_ERROR() \
43 JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), NULL)
44
45 struct X11InputMethodIDs {
46 jfieldID pData;
47 } x11InputMethodIDs;
48
49 static void PreeditStartCallback(XIC, XPointer, XPointer);
50 static void PreeditDoneCallback(XIC, XPointer, XPointer);
51 static void PreeditDrawCallback(XIC, XPointer,
52 XIMPreeditDrawCallbackStruct *);
53 static void PreeditCaretCallback(XIC, XPointer,
54 XIMPreeditCaretCallbackStruct *);
55 #if defined(__linux__) || defined(MACOSX)
56 static void StatusStartCallback(XIC, XPointer, XPointer);
57 static void StatusDoneCallback(XIC, XPointer, XPointer);
58 static void StatusDrawCallback(XIC, XPointer,
59 XIMStatusDrawCallbackStruct *);
60 #endif
61
62 #define ROOT_WINDOW_STYLES (XIMPreeditNothing | XIMStatusNothing)
63 #define NO_STYLES (XIMPreeditNone | XIMStatusNone)
64
65 #define PreeditStartIndex 0
66 #define PreeditDoneIndex 1
67 #define PreeditDrawIndex 2
68 #define PreeditCaretIndex 3
69 #if defined(__linux__) || defined(MACOSX)
70 #define StatusStartIndex 4
71 #define StatusDoneIndex 5
72 #define StatusDrawIndex 6
73 #define NCALLBACKS 7
74 #else
75 #define NCALLBACKS 4
76 #endif
77
78 /*
79 * Callback function pointers: the order has to match the *Index
80 * values above.
81 */
82 static XIMProc callback_funcs[NCALLBACKS] = {
83 (XIMProc)PreeditStartCallback,
84 (XIMProc)PreeditDoneCallback,
85 (XIMProc)PreeditDrawCallback,
86 (XIMProc)PreeditCaretCallback,
87 #if defined(__linux__) || defined(MACOSX)
88 (XIMProc)StatusStartCallback,
89 (XIMProc)StatusDoneCallback,
90 (XIMProc)StatusDrawCallback,
91 #endif
92 };
93
94 #if defined(__linux__) || defined(MACOSX)
95 #define MAX_STATUS_LEN 100
96 typedef struct {
97 Window w; /*status window id */
98 Window root; /*the root window id */
99 Window parent; /*parent shell window */
100 int x, y; /*parent's upperleft position */
101 int width, height; /*parent's width, height */
102 GC lightGC; /*gc for light border */
103 GC dimGC; /*gc for dim border */
158
159 Window currentFocusWindow = 0; /* current window that has focus for input
160 method. (the best place to put this
161 information should be
162 currentX11InputMethodInstance's pData) */
163 static XIM X11im = NULL;
164 Display * dpy = NULL;
165
166 #define GetJNIEnv() (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2)
167
168 static void DestroyXIMCallback(XIM, XPointer, XPointer);
169 static void OpenXIMCallback(Display *, XPointer, XPointer);
170 /* Solaris XIM Extention */
171 #define XNCommitStringCallback "commitStringCallback"
172 static void CommitStringCallback(XIC, XPointer, XPointer);
173
174 static X11InputMethodData * getX11InputMethodData(JNIEnv *, jobject);
175 static void setX11InputMethodData(JNIEnv *, jobject, X11InputMethodData *);
176 static void destroyX11InputMethodData(JNIEnv *, X11InputMethodData *);
177 static void freeX11InputMethodData(JNIEnv *, X11InputMethodData *);
178
179 #ifdef __solaris__
180 /* Prototype for this function is missing in Solaris X11R6 Xlib.h */
181 extern char *XSetIMValues(
182 #if NeedVarargsPrototypes
183 XIM /* im */, ...
184 #endif
185 );
186 #endif
187
188 /*
189 * This function is stolen from /src/solaris/hpi/src/system_md.c
190 * It is used in setting the time in Java-level InputEvents
191 */
192 jlong
193 awt_util_nowMillisUTC()
194 {
195 struct timeval t;
196 gettimeofday(&t, NULL);
197 return ((jlong)t.tv_sec) * 1000 + (jlong)(t.tv_usec/1000);
1002
1003 if (pX11IMData->ic_active == (XIC)0
1004 || pX11IMData->ic_passive == (XIC)0) {
1005 return False;
1006 }
1007
1008 /*
1009 * Use commit string call back if possible.
1010 * This will ensure the correct order of preedit text and commit text
1011 */
1012 {
1013 XIMCallback cb;
1014 cb.client_data = (XPointer) pX11IMData->x11inputmethod;
1015 cb.callback = (XIMProc) CommitStringCallback;
1016 XSetICValues (pX11IMData->ic_active, XNCommitStringCallback, &cb, NULL);
1017 if (pX11IMData->ic_active != pX11IMData->ic_passive) {
1018 XSetICValues (pX11IMData->ic_passive, XNCommitStringCallback, &cb, NULL);
1019 }
1020 }
1021
1022 /* Add the global reference object to X11InputMethod to the list. */
1023 addToX11InputMethodGRefList(pX11IMData->x11inputmethod);
1024
1025 return True;
1026
1027 err:
1028 if (preedit)
1029 XFree((void *)preedit);
1030 THROW_OUT_OF_MEMORY_ERROR();
1031 return False;
1032 }
1033
1034 static void
1035 PreeditStartCallback(XIC ic, XPointer client_data, XPointer call_data)
1036 {
1037 /*ARGSUSED*/
1038 /* printf("Native: PreeditStartCallback\n"); */
1039 }
1040
1041 static void
1042 PreeditDoneCallback(XIC ic, XPointer client_data, XPointer call_data)
1043 {
1044 /*ARGSUSED*/
1045 /* printf("Native: PreeditDoneCallback\n"); */
1046 }
1047
1048 /*
1049 * Translate the preedit draw callback items to Java values and invoke
1050 * X11InputMethod.dispatchComposedText().
1051 *
1052 * client_data: X11InputMethod object
1053 */
1054 static void
1055 PreeditDrawCallback(XIC ic, XPointer client_data,
1056 XIMPreeditDrawCallbackStruct *pre_draw)
1057 {
1058 JNIEnv *env = GetJNIEnv();
1146 PreeditCaretCallback(XIC ic, XPointer client_data,
1147 XIMPreeditCaretCallbackStruct *pre_caret)
1148 {
1149 /*ARGSUSED*/
1150 /* printf("Native: PreeditCaretCallback\n"); */
1151 }
1152
1153 #if defined(__linux__) || defined(MACOSX)
1154 static void
1155 StatusStartCallback(XIC ic, XPointer client_data, XPointer call_data)
1156 {
1157 /*ARGSUSED*/
1158 /*printf("StatusStartCallback:\n"); */
1159 }
1160
1161 static void
1162 StatusDoneCallback(XIC ic, XPointer client_data, XPointer call_data)
1163 {
1164 /*ARGSUSED*/
1165 /*printf("StatusDoneCallback:\n"); */
1166 }
1167
1168 static void
1169 StatusDrawCallback(XIC ic, XPointer client_data,
1170 XIMStatusDrawCallbackStruct *status_draw)
1171 {
1172 /*ARGSUSED*/
1173 /*printf("StatusDrawCallback:\n"); */
1174 JNIEnv *env = GetJNIEnv();
1175 X11InputMethodData *pX11IMData = NULL;
1176 StatusWindow *statusWindow;
1177
1178 AWT_LOCK();
1179
1180 if (!isX11InputMethodGRefInList((jobject)client_data)) {
1181 if ((jobject)client_data == currentX11InputMethodInstance) {
1182 currentX11InputMethodInstance = NULL;
1183 }
1184 goto finally;
1185 }
1535 }
1536
1537 /*
1538 * Class: sun_awt_X11InputMethodBase
1539 * Method: setCompositionEnabledNative
1540 * Signature: (Z)Z
1541 *
1542 * This method tries to set the XNPreeditState attribute associated with the current
1543 * XIC to the passed in 'enable' state.
1544 *
1545 * Return JNI_TRUE if XNPreeditState attribute is successfully changed to the
1546 * 'enable' state; Otherwise, if XSetICValues fails to set this attribute,
1547 * java.lang.UnsupportedOperationException will be thrown. JNI_FALSE is returned if this
1548 * method fails due to other reasons.
1549 */
1550 JNIEXPORT jboolean JNICALL Java_sun_awt_X11InputMethodBase_setCompositionEnabledNative
1551 (JNIEnv *env, jobject this, jboolean enable)
1552 {
1553 X11InputMethodData *pX11IMData;
1554 char * ret = NULL;
1555
1556 AWT_LOCK();
1557 pX11IMData = getX11InputMethodData(env, this);
1558
1559 if ((pX11IMData == NULL) || (pX11IMData->current_ic == NULL)) {
1560 AWT_UNLOCK();
1561 return JNI_FALSE;
1562 }
1563
1564 ret = XSetICValues(pX11IMData->current_ic, XNPreeditState,
1565 (enable ? XIMPreeditEnable : XIMPreeditDisable), NULL);
1566 AWT_UNLOCK();
1567
1568 if ((ret != 0) && (strcmp(ret, XNPreeditState) == 0)) {
1569 JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", "");
1570 }
1571
1572 return (jboolean)(ret == 0);
1573 }
1574
1575 /*
1576 * Class: sun_awt_X11InputMethodBase
1577 * Method: isCompositionEnabledNative
1578 * Signature: ()Z
1579 *
1580 * This method tries to get the XNPreeditState attribute associated with the current XIC.
1581 *
1582 * Return JNI_TRUE if the XNPreeditState is successfully retrieved. Otherwise, if
1583 * XGetICValues fails to get this attribute, java.lang.UnsupportedOperationException
1584 * will be thrown. JNI_FALSE is returned if this method fails due to other reasons.
1585 */
1586 JNIEXPORT jboolean JNICALL Java_sun_awt_X11InputMethodBase_isCompositionEnabledNative
1587 (JNIEnv *env, jobject this)
1588 {
1589 X11InputMethodData *pX11IMData = NULL;
1590 char * ret = NULL;
1591 XIMPreeditState state;
1592
1593 AWT_LOCK();
1594 pX11IMData = getX11InputMethodData(env, this);
1595
1596 if ((pX11IMData == NULL) || (pX11IMData->current_ic == NULL)) {
1597 AWT_UNLOCK();
1598 return JNI_FALSE;
1599 }
1600
1601 ret = XGetICValues(pX11IMData->current_ic, XNPreeditState, &state, NULL);
1602 AWT_UNLOCK();
1603
1604 if ((ret != 0) && (strcmp(ret, XNPreeditState) == 0)) {
1605 JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", "");
1606 return JNI_FALSE;
1607 }
1608
1609 return (jboolean)(state == XIMPreeditEnable);
1610 }
1611
1612 JNIEXPORT void JNICALL Java_sun_awt_X11_XInputMethod_adjustStatusWindow
1613 (JNIEnv *env, jobject this, jlong window)
1614 {
1615 #if defined(__linux__) || defined(MACOSX)
1616 AWT_LOCK();
1617 adjustStatusWindow(window);
1618 AWT_UNLOCK();
1619 #endif
1620 }
|
1 /*
2 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
29
30 #include "awt.h"
31 #include "awt_p.h"
32
33 #include <sun_awt_X11InputMethodBase.h>
34 #include <sun_awt_X11_XInputMethod.h>
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <sys/time.h>
39 #include <X11/keysym.h>
40 #include <X11/Xlib.h>
41
42 #define THROW_OUT_OF_MEMORY_ERROR() \
43 JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), NULL)
44
45 struct X11InputMethodIDs {
46 jfieldID pData;
47 } x11InputMethodIDs;
48
49 static int PreeditStartCallback(XIC, XPointer, XPointer);
50 static void PreeditDoneCallback(XIC, XPointer, XPointer);
51 static void PreeditDrawCallback(XIC, XPointer,
52 XIMPreeditDrawCallbackStruct *);
53 static void PreeditCaretCallback(XIC, XPointer,
54 XIMPreeditCaretCallbackStruct *);
55 #if defined(__linux__) || defined(MACOSX)
56 static void StatusStartCallback(XIC, XPointer, XPointer);
57 static void StatusDoneCallback(XIC, XPointer, XPointer);
58 static void StatusDrawCallback(XIC, XPointer,
59 XIMStatusDrawCallbackStruct *);
60 #endif
61
62 #define ROOT_WINDOW_STYLES (XIMPreeditNothing | XIMStatusNothing)
63 #define NO_STYLES (XIMPreeditNone | XIMStatusNone)
64
65 #define PreeditStartIndex 0
66 #define PreeditDoneIndex 1
67 #define PreeditDrawIndex 2
68 #define PreeditCaretIndex 3
69 #if defined(__linux__) || defined(MACOSX)
70 #define StatusStartIndex 4
71 #define StatusDoneIndex 5
72 #define StatusDrawIndex 6
73 #define NCALLBACKS 7
74 #else
75 #define NCALLBACKS 4
76 #endif
77
78 /*
79 * Callback function pointers: the order has to match the *Index
80 * values above.
81 */
82 static XIMProc callback_funcs[NCALLBACKS] = {
83 (XIMProc)(void *)&PreeditStartCallback,
84 (XIMProc)PreeditDoneCallback,
85 (XIMProc)PreeditDrawCallback,
86 (XIMProc)PreeditCaretCallback,
87 #if defined(__linux__) || defined(MACOSX)
88 (XIMProc)StatusStartCallback,
89 (XIMProc)StatusDoneCallback,
90 (XIMProc)StatusDrawCallback,
91 #endif
92 };
93
94 #if defined(__linux__) || defined(MACOSX)
95 #define MAX_STATUS_LEN 100
96 typedef struct {
97 Window w; /*status window id */
98 Window root; /*the root window id */
99 Window parent; /*parent shell window */
100 int x, y; /*parent's upperleft position */
101 int width, height; /*parent's width, height */
102 GC lightGC; /*gc for light border */
103 GC dimGC; /*gc for dim border */
158
159 Window currentFocusWindow = 0; /* current window that has focus for input
160 method. (the best place to put this
161 information should be
162 currentX11InputMethodInstance's pData) */
163 static XIM X11im = NULL;
164 Display * dpy = NULL;
165
166 #define GetJNIEnv() (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2)
167
168 static void DestroyXIMCallback(XIM, XPointer, XPointer);
169 static void OpenXIMCallback(Display *, XPointer, XPointer);
170 /* Solaris XIM Extention */
171 #define XNCommitStringCallback "commitStringCallback"
172 static void CommitStringCallback(XIC, XPointer, XPointer);
173
174 static X11InputMethodData * getX11InputMethodData(JNIEnv *, jobject);
175 static void setX11InputMethodData(JNIEnv *, jobject, X11InputMethodData *);
176 static void destroyX11InputMethodData(JNIEnv *, X11InputMethodData *);
177 static void freeX11InputMethodData(JNIEnv *, X11InputMethodData *);
178 #if defined(__linux__) || defined(MACOSX)
179 static Window getParentWindow(Window);
180 #endif
181
182 #ifdef __solaris__
183 /* Prototype for this function is missing in Solaris X11R6 Xlib.h */
184 extern char *XSetIMValues(
185 #if NeedVarargsPrototypes
186 XIM /* im */, ...
187 #endif
188 );
189 #endif
190
191 /*
192 * This function is stolen from /src/solaris/hpi/src/system_md.c
193 * It is used in setting the time in Java-level InputEvents
194 */
195 jlong
196 awt_util_nowMillisUTC()
197 {
198 struct timeval t;
199 gettimeofday(&t, NULL);
200 return ((jlong)t.tv_sec) * 1000 + (jlong)(t.tv_usec/1000);
1005
1006 if (pX11IMData->ic_active == (XIC)0
1007 || pX11IMData->ic_passive == (XIC)0) {
1008 return False;
1009 }
1010
1011 /*
1012 * Use commit string call back if possible.
1013 * This will ensure the correct order of preedit text and commit text
1014 */
1015 {
1016 XIMCallback cb;
1017 cb.client_data = (XPointer) pX11IMData->x11inputmethod;
1018 cb.callback = (XIMProc) CommitStringCallback;
1019 XSetICValues (pX11IMData->ic_active, XNCommitStringCallback, &cb, NULL);
1020 if (pX11IMData->ic_active != pX11IMData->ic_passive) {
1021 XSetICValues (pX11IMData->ic_passive, XNCommitStringCallback, &cb, NULL);
1022 }
1023 }
1024
1025 // The code set the IC mode that the preedit state is not initialied
1026 // at XmbResetIC. This attribute can be set at XCreateIC. I separately
1027 // set the attribute to avoid the failure of XCreateIC at some platform
1028 // which does not support the attribute.
1029 if (pX11IMData->ic_active != 0)
1030 XSetICValues(pX11IMData->ic_active,
1031 XNResetState, XIMInitialState,
1032 NULL);
1033 if (pX11IMData->ic_passive != 0
1034 && pX11IMData->ic_active != pX11IMData->ic_passive)
1035 XSetICValues(pX11IMData->ic_passive,
1036 XNResetState, XIMInitialState,
1037 NULL);
1038
1039 /* Add the global reference object to X11InputMethod to the list. */
1040 addToX11InputMethodGRefList(pX11IMData->x11inputmethod);
1041
1042 /* Unset focus to avoid unexpected IM on */
1043 setXICFocus(pX11IMData->ic_active, False);
1044 if (pX11IMData->ic_active != pX11IMData->ic_passive)
1045 setXICFocus(pX11IMData->ic_passive, False);
1046
1047 return True;
1048
1049 err:
1050 if (preedit)
1051 XFree((void *)preedit);
1052 THROW_OUT_OF_MEMORY_ERROR();
1053 return False;
1054 }
1055
1056 static int
1057 PreeditStartCallback(XIC ic, XPointer client_data, XPointer call_data)
1058 {
1059 /*ARGSUSED*/
1060 /* printf("Native: PreeditStartCallback\n"); */
1061 return -1;
1062 }
1063
1064 static void
1065 PreeditDoneCallback(XIC ic, XPointer client_data, XPointer call_data)
1066 {
1067 /*ARGSUSED*/
1068 /* printf("Native: PreeditDoneCallback\n"); */
1069 }
1070
1071 /*
1072 * Translate the preedit draw callback items to Java values and invoke
1073 * X11InputMethod.dispatchComposedText().
1074 *
1075 * client_data: X11InputMethod object
1076 */
1077 static void
1078 PreeditDrawCallback(XIC ic, XPointer client_data,
1079 XIMPreeditDrawCallbackStruct *pre_draw)
1080 {
1081 JNIEnv *env = GetJNIEnv();
1169 PreeditCaretCallback(XIC ic, XPointer client_data,
1170 XIMPreeditCaretCallbackStruct *pre_caret)
1171 {
1172 /*ARGSUSED*/
1173 /* printf("Native: PreeditCaretCallback\n"); */
1174 }
1175
1176 #if defined(__linux__) || defined(MACOSX)
1177 static void
1178 StatusStartCallback(XIC ic, XPointer client_data, XPointer call_data)
1179 {
1180 /*ARGSUSED*/
1181 /*printf("StatusStartCallback:\n"); */
1182 }
1183
1184 static void
1185 StatusDoneCallback(XIC ic, XPointer client_data, XPointer call_data)
1186 {
1187 /*ARGSUSED*/
1188 /*printf("StatusDoneCallback:\n"); */
1189 JNIEnv *env = GetJNIEnv();
1190 X11InputMethodData *pX11IMData = NULL;
1191 StatusWindow *statusWindow;
1192
1193 AWT_LOCK();
1194
1195 if (!isX11InputMethodGRefInList((jobject)client_data)) {
1196 if ((jobject)client_data == currentX11InputMethodInstance) {
1197 currentX11InputMethodInstance = NULL;
1198 }
1199 goto finally;
1200 }
1201
1202 if (NULL == (pX11IMData = getX11InputMethodData(env, (jobject)client_data))
1203 || NULL == (statusWindow = pX11IMData->statusWindow)){
1204 goto finally;
1205 }
1206 currentX11InputMethodInstance = (jobject)client_data;
1207
1208 onoffStatusWindow(pX11IMData, 0, False);
1209
1210 finally:
1211 AWT_UNLOCK();
1212 }
1213
1214 static void
1215 StatusDrawCallback(XIC ic, XPointer client_data,
1216 XIMStatusDrawCallbackStruct *status_draw)
1217 {
1218 /*ARGSUSED*/
1219 /*printf("StatusDrawCallback:\n"); */
1220 JNIEnv *env = GetJNIEnv();
1221 X11InputMethodData *pX11IMData = NULL;
1222 StatusWindow *statusWindow;
1223
1224 AWT_LOCK();
1225
1226 if (!isX11InputMethodGRefInList((jobject)client_data)) {
1227 if ((jobject)client_data == currentX11InputMethodInstance) {
1228 currentX11InputMethodInstance = NULL;
1229 }
1230 goto finally;
1231 }
1581 }
1582
1583 /*
1584 * Class: sun_awt_X11InputMethodBase
1585 * Method: setCompositionEnabledNative
1586 * Signature: (Z)Z
1587 *
1588 * This method tries to set the XNPreeditState attribute associated with the current
1589 * XIC to the passed in 'enable' state.
1590 *
1591 * Return JNI_TRUE if XNPreeditState attribute is successfully changed to the
1592 * 'enable' state; Otherwise, if XSetICValues fails to set this attribute,
1593 * java.lang.UnsupportedOperationException will be thrown. JNI_FALSE is returned if this
1594 * method fails due to other reasons.
1595 */
1596 JNIEXPORT jboolean JNICALL Java_sun_awt_X11InputMethodBase_setCompositionEnabledNative
1597 (JNIEnv *env, jobject this, jboolean enable)
1598 {
1599 X11InputMethodData *pX11IMData;
1600 char * ret = NULL;
1601 XVaNestedList pr_atrb;
1602 #if defined(__linux__) || defined(MACOSX)
1603 Boolean calledXSetICFocus = False;
1604 #endif
1605
1606 AWT_LOCK();
1607 pX11IMData = getX11InputMethodData(env, this);
1608
1609 if ((pX11IMData == NULL) || (pX11IMData->current_ic == NULL)) {
1610 AWT_UNLOCK();
1611 return JNI_FALSE;
1612 }
1613
1614 #if defined(__linux__) || defined(MACOSX)
1615 if (NULL != pX11IMData->statusWindow) {
1616 Window focus = 0;
1617 int revert_to;
1618 #if defined(_LP64) && !defined(_LITTLE_ENDIAN)
1619 // The Window value which is used for XGetICValues must be 32bit on BigEndian XOrg's xlib
1620 unsigned int w = 0;
1621 #else
1622 Window w = 0;
1623 #endif
1624 XGetInputFocus(awt_display, &focus, &revert_to);
1625 XGetICValues(pX11IMData->current_ic, XNFocusWindow, &w, NULL);
1626 if (RevertToPointerRoot == revert_to
1627 && pX11IMData->ic_active != pX11IMData->ic_passive) {
1628 if (pX11IMData->current_ic == pX11IMData->ic_active) {
1629 if (getParentWindow(focus) == getParentWindow(w)) {
1630 XUnsetICFocus(pX11IMData->ic_active);
1631 calledXSetICFocus = True;
1632 }
1633 }
1634 }
1635 }
1636 #endif
1637 pr_atrb = XVaCreateNestedList(0,
1638 XNPreeditState, (enable ? XIMPreeditEnable : XIMPreeditDisable),
1639 NULL);
1640 ret = XSetICValues(pX11IMData->current_ic, XNPreeditAttributes, pr_atrb, NULL);
1641 XFree((void *)pr_atrb);
1642 #if defined(__linux__) || defined(MACOSX)
1643 if (calledXSetICFocus) {
1644 XSetICFocus(pX11IMData->ic_active);
1645 }
1646 #endif
1647 AWT_UNLOCK();
1648
1649 if ((ret != 0)
1650 && ((strcmp(ret, XNPreeditAttributes) == 0)
1651 || (strcmp(ret, XNPreeditState) == 0))) {
1652 JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", "");
1653 }
1654
1655 return (jboolean)(ret == 0);
1656 }
1657
1658 /*
1659 * Class: sun_awt_X11InputMethodBase
1660 * Method: isCompositionEnabledNative
1661 * Signature: ()Z
1662 *
1663 * This method tries to get the XNPreeditState attribute associated with the current XIC.
1664 *
1665 * Return JNI_TRUE if the XNPreeditState is successfully retrieved. Otherwise, if
1666 * XGetICValues fails to get this attribute, java.lang.UnsupportedOperationException
1667 * will be thrown. JNI_FALSE is returned if this method fails due to other reasons.
1668 */
1669 JNIEXPORT jboolean JNICALL Java_sun_awt_X11InputMethodBase_isCompositionEnabledNative
1670 (JNIEnv *env, jobject this)
1671 {
1672 X11InputMethodData *pX11IMData = NULL;
1673 char * ret = NULL;
1674 #if defined(_LP64) && !defined(_LITTLE_ENDIAN)
1675 // XIMPreeditState value which is used for XGetICValues must be 32bit on BigEndian XOrg's xlib
1676 unsigned int state = XIMPreeditUnKnown;
1677 #else
1678 XIMPreeditState state = XIMPreeditUnKnown;
1679 #endif
1680
1681 XVaNestedList pr_atrb;
1682
1683 AWT_LOCK();
1684 pX11IMData = getX11InputMethodData(env, this);
1685
1686 if ((pX11IMData == NULL) || (pX11IMData->current_ic == NULL)) {
1687 AWT_UNLOCK();
1688 return JNI_FALSE;
1689 }
1690
1691 pr_atrb = XVaCreateNestedList(0, XNPreeditState, &state, NULL);
1692 ret = XGetICValues(pX11IMData->current_ic, XNPreeditAttributes, pr_atrb, NULL);
1693 XFree((void *)pr_atrb);
1694 AWT_UNLOCK();
1695
1696 if ((ret != 0)
1697 && ((strcmp(ret, XNPreeditAttributes) == 0)
1698 || (strcmp(ret, XNPreeditState) == 0))) {
1699 JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", "");
1700 return JNI_FALSE;
1701 }
1702
1703 return (jboolean)(state == XIMPreeditEnable);
1704 }
1705
1706 JNIEXPORT void JNICALL Java_sun_awt_X11_XInputMethod_adjustStatusWindow
1707 (JNIEnv *env, jobject this, jlong window)
1708 {
1709 #if defined(__linux__) || defined(MACOSX)
1710 AWT_LOCK();
1711 adjustStatusWindow(window);
1712 AWT_UNLOCK();
1713 #endif
1714 }
1715
1716 #if defined(__linux__) || defined(MACOSX)
1717 static Window getParentWindow(Window w)
1718 {
1719 Window root=None, parent=None, *ignore_children=NULL;
1720 unsigned int ignore_uint=0;
1721 Status status = 0;
1722
1723 if (w == None)
1724 return None;
1725 status = XQueryTree(dpy, w, &root, &parent, &ignore_children, &ignore_uint);
1726 XFree(ignore_children);
1727 if (status == 0)
1728 return None;
1729 return parent;
1730 }
1731 #endif
|