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