1244 if (mbstr == NULL) { 1245 goto finally; 1246 } 1247 javastr = JNU_NewStringPlatform(env, (const char *)mbstr); 1248 free(mbstr); 1249 } 1250 1251 if (javastr != NULL) { 1252 JNU_CallMethodByName(env, NULL, 1253 pX11IMData->x11inputmethod, 1254 "dispatchCommittedText", 1255 "(Ljava/lang/String;J)V", 1256 javastr, 1257 awt_util_nowMillisUTC()); 1258 } 1259 finally: 1260 AWT_UNLOCK(); 1261 } 1262 1263 static void OpenXIMCallback(Display *display, XPointer client_data, XPointer call_data) { 1264 XIMCallback ximCallback; 1265 1266 X11im = XOpenIM(display, NULL, NULL, NULL); 1267 if (X11im == NULL) { 1268 return; 1269 } 1270 1271 ximCallback.callback = (XIMProc)DestroyXIMCallback; 1272 ximCallback.client_data = NULL; 1273 XSetIMValues(X11im, XNDestroyCallback, &ximCallback, NULL); 1274 } 1275 1276 static void DestroyXIMCallback(XIM im, XPointer client_data, XPointer call_data) { 1277 /* mark that XIM server was destroyed */ 1278 X11im = NULL; 1279 JNIEnv* env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 1280 /* free the old pX11IMData and set it to null. this also avoids crashing 1281 * the jvm if the XIM server reappears */ 1282 X11InputMethodData *pX11IMData = getX11InputMethodData(env, currentX11InputMethodInstance); 1283 } 1284 1285 JNIEXPORT jboolean JNICALL 1286 Java_sun_awt_X11_XInputMethod_openXIMNative(JNIEnv *env, 1287 jobject this, 1288 jlong display) 1289 { 1290 Bool registered; 1291 1292 AWT_LOCK(); 1293 1294 dpy = (Display *)jlong_to_ptr(display); 1295 1296 /* Use IMInstantiate call back only on Linux, as there is a bug in Solaris 1297 (4768335) 1298 */ 1299 #if defined(__linux__) || defined(MACOSX) 1300 registered = XRegisterIMInstantiateCallback(dpy, NULL, NULL, 1301 NULL, (XIDProc)OpenXIMCallback, NULL); 1302 if (!registered) { 1328 AWT_UNLOCK(); 1329 return JNI_FALSE; 1330 } 1331 1332 pX11IMData = (X11InputMethodData *) calloc(1, sizeof(X11InputMethodData)); 1333 if (pX11IMData == NULL) { 1334 THROW_OUT_OF_MEMORY_ERROR(); 1335 AWT_UNLOCK(); 1336 return JNI_FALSE; 1337 } 1338 1339 globalRef = (*env)->NewGlobalRef(env, this); 1340 pX11IMData->x11inputmethod = globalRef; 1341 #if defined(__linux__) || defined(MACOSX) 1342 pX11IMData->statusWindow = NULL; 1343 #endif /* __linux__ || MACOSX */ 1344 1345 pX11IMData->lookup_buf = 0; 1346 pX11IMData->lookup_buf_len = 0; 1347 1348 if (createXIC(env, pX11IMData, (Window)window) == False) { 1349 destroyX11InputMethodData((JNIEnv *) NULL, pX11IMData); 1350 pX11IMData = (X11InputMethodData *) NULL; 1351 if ((*env)->ExceptionCheck(env)) { 1352 goto finally; 1353 } 1354 } 1355 1356 setX11InputMethodData(env, this, pX11IMData); 1357 1358 finally: 1359 AWT_UNLOCK(); 1360 return (pX11IMData != NULL); 1361 } 1362 1363 JNIEXPORT void JNICALL 1364 Java_sun_awt_X11_XInputMethod_setXICFocusNative(JNIEnv *env, 1365 jobject this, 1366 jlong w, 1367 jboolean req, 1368 jboolean active) 1369 { 1370 X11InputMethodData *pX11IMData; 1371 AWT_LOCK(); 1372 pX11IMData = getX11InputMethodData(env, this); 1373 if (pX11IMData == NULL) { 1374 AWT_UNLOCK(); 1375 return; 1376 } | 1244 if (mbstr == NULL) { 1245 goto finally; 1246 } 1247 javastr = JNU_NewStringPlatform(env, (const char *)mbstr); 1248 free(mbstr); 1249 } 1250 1251 if (javastr != NULL) { 1252 JNU_CallMethodByName(env, NULL, 1253 pX11IMData->x11inputmethod, 1254 "dispatchCommittedText", 1255 "(Ljava/lang/String;J)V", 1256 javastr, 1257 awt_util_nowMillisUTC()); 1258 } 1259 finally: 1260 AWT_UNLOCK(); 1261 } 1262 1263 static void OpenXIMCallback(Display *display, XPointer client_data, XPointer call_data) { 1264 JNIEnv* env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 1265 XIMCallback ximCallback; 1266 jclass classClass; 1267 jfieldID pID, lastComponentID; 1268 jobject cdata; 1269 1270 AWT_LOCK(); 1271 X11im = XOpenIM(display, NULL, NULL, NULL); 1272 if (X11im == NULL) { 1273 AWT_UNLOCK(); 1274 return; 1275 } 1276 1277 #if defined(__linux__) 1278 classClass = (*env)->FindClass(env, "sun/awt/X11InputMethod"); 1279 if (!JNU_IsNull(env, classClass)) { 1280 pID = (*env)->GetStaticFieldID(env, classClass, 1281 "activatedInstance", "Lsun/awt/X11InputMethod;"); 1282 lastComponentID = (*env)->GetFieldID(env, classClass, 1283 "lastXICFocussedComponent", "Ljava/awt/Component;"); 1284 if (!JNU_IsNull(env, pID) && !JNU_IsNull(env, lastComponentID)) { 1285 cdata = (*env)->GetStaticObjectField(env, classClass, pID); 1286 if (!JNU_IsNull(env, cdata)) { 1287 // Claer lastXICFocussedComponent before calling activate. 1288 (*env)->SetObjectField(env, cdata, lastComponentID, NULL); 1289 JNU_CallMethodByName(env, NULL, cdata, "activate", "()V"); 1290 if ((*env)->ExceptionOccurred(env)) { 1291 (*env)->ExceptionClear(env); 1292 } 1293 } 1294 } 1295 } 1296 #endif 1297 1298 ximCallback.callback = (XIMProc)DestroyXIMCallback; 1299 ximCallback.client_data = NULL; 1300 XSetIMValues(X11im, XNDestroyCallback, &ximCallback, NULL); 1301 #if defined(__linux__) 1302 XUnregisterIMInstantiateCallback(display, NULL, NULL, NULL, 1303 OpenXIMCallback, NULL); 1304 #endif 1305 AWT_UNLOCK(); 1306 } 1307 1308 static void DestroyXIMCallback(XIM im, XPointer client_data, XPointer call_data) { 1309 JNIEnv* env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); 1310 1311 AWT_LOCK(); 1312 /* mark that XIM server was destroyed */ 1313 X11im = NULL; 1314 1315 X11InputMethodGRefNode *pX11InputMethodGRef = x11InputMethodGRefListHead; 1316 while (pX11InputMethodGRef != NULL) { 1317 X11InputMethodGRefNode *next = pX11InputMethodGRef->next; 1318 /* free the old pX11IMData and set it to null. this also avoids 1319 * crashing the jvm if the XIM server reappears */ 1320 getX11InputMethodData(env, pX11InputMethodGRef->inputMethodGRef); 1321 pX11InputMethodGRef = next; 1322 } 1323 currentX11InputMethodInstance = NULL; 1324 currentFocusWindow = 0; 1325 1326 #if defined(__linux__) 1327 XRegisterIMInstantiateCallback(dpy, NULL, NULL, NULL, 1328 (XIDProc)OpenXIMCallback, NULL); 1329 #endif 1330 AWT_UNLOCK(); 1331 } 1332 1333 JNIEXPORT jboolean JNICALL 1334 Java_sun_awt_X11_XInputMethod_openXIMNative(JNIEnv *env, 1335 jobject this, 1336 jlong display) 1337 { 1338 Bool registered; 1339 1340 AWT_LOCK(); 1341 1342 dpy = (Display *)jlong_to_ptr(display); 1343 1344 /* Use IMInstantiate call back only on Linux, as there is a bug in Solaris 1345 (4768335) 1346 */ 1347 #if defined(__linux__) || defined(MACOSX) 1348 registered = XRegisterIMInstantiateCallback(dpy, NULL, NULL, 1349 NULL, (XIDProc)OpenXIMCallback, NULL); 1350 if (!registered) { 1376 AWT_UNLOCK(); 1377 return JNI_FALSE; 1378 } 1379 1380 pX11IMData = (X11InputMethodData *) calloc(1, sizeof(X11InputMethodData)); 1381 if (pX11IMData == NULL) { 1382 THROW_OUT_OF_MEMORY_ERROR(); 1383 AWT_UNLOCK(); 1384 return JNI_FALSE; 1385 } 1386 1387 globalRef = (*env)->NewGlobalRef(env, this); 1388 pX11IMData->x11inputmethod = globalRef; 1389 #if defined(__linux__) || defined(MACOSX) 1390 pX11IMData->statusWindow = NULL; 1391 #endif /* __linux__ || MACOSX */ 1392 1393 pX11IMData->lookup_buf = 0; 1394 pX11IMData->lookup_buf_len = 0; 1395 1396 setX11InputMethodData(env, this, pX11IMData); 1397 if (createXIC(env, pX11IMData, (Window)window) == False) { 1398 destroyX11InputMethodData((JNIEnv *) NULL, pX11IMData); 1399 pX11IMData = (X11InputMethodData *) NULL; 1400 setX11InputMethodData(env, this, pX11IMData); 1401 if ((*env)->ExceptionCheck(env)) { 1402 goto finally; 1403 } 1404 } 1405 1406 finally: 1407 AWT_UNLOCK(); 1408 return (pX11IMData != NULL); 1409 } 1410 1411 JNIEXPORT void JNICALL 1412 Java_sun_awt_X11_XInputMethod_setXICFocusNative(JNIEnv *env, 1413 jobject this, 1414 jlong w, 1415 jboolean req, 1416 jboolean active) 1417 { 1418 X11InputMethodData *pX11IMData; 1419 AWT_LOCK(); 1420 pX11IMData = getX11InputMethodData(env, this); 1421 if (pX11IMData == NULL) { 1422 AWT_UNLOCK(); 1423 return; 1424 } |