< prev index next >

src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c

Print this page

        

*** 173,182 **** --- 173,185 ---- static X11InputMethodData * getX11InputMethodData(JNIEnv *, jobject); static void setX11InputMethodData(JNIEnv *, jobject, X11InputMethodData *); static void destroyX11InputMethodData(JNIEnv *, X11InputMethodData *); static void freeX11InputMethodData(JNIEnv *, X11InputMethodData *); + #if defined(__linux__) || defined(MACOSX) + static Window getParentWindow(Window); + #endif #ifdef __solaris__ /* Prototype for this function is missing in Solaris X11R6 Xlib.h */ extern char *XSetIMValues( #if NeedVarargsPrototypes
*** 1016,1028 **** --- 1019,1050 ---- if (pX11IMData->ic_active != pX11IMData->ic_passive) { XSetICValues (pX11IMData->ic_passive, XNCommitStringCallback, &cb, NULL); } } + // The code set the IC mode that the preedit state is not initialied + // at XmbResetIC. This attribute can be set at XCreateIC. I separately + // set the attribute to avoid the failure of XCreateIC at some platform + // which does not support the attribute. + if (pX11IMData->ic_active != 0) + XSetICValues(pX11IMData->ic_active, + XNResetState, XIMInitialState, + NULL); + if (pX11IMData->ic_passive != 0 + && pX11IMData->ic_active != pX11IMData->ic_passive) + XSetICValues(pX11IMData->ic_passive, + XNResetState, XIMInitialState, + NULL); + /* Add the global reference object to X11InputMethod to the list. */ addToX11InputMethodGRefList(pX11IMData->x11inputmethod); + /* Unset focus to avoid unexpected IM on */ + setXICFocus(pX11IMData->ic_active, False); + if (pX11IMData->ic_active != pX11IMData->ic_passive) + setXICFocus(pX11IMData->ic_passive, False); + return True; err: if (preedit) XFree((void *)preedit);
*** 1159,1168 **** --- 1181,1213 ---- static void StatusDoneCallback(XIC ic, XPointer client_data, XPointer call_data) { /*ARGSUSED*/ /*printf("StatusDoneCallback:\n"); */ + JNIEnv *env = GetJNIEnv(); + X11InputMethodData *pX11IMData = NULL; + StatusWindow *statusWindow; + + AWT_LOCK(); + + if (!isX11InputMethodGRefInList((jobject)client_data)) { + if ((jobject)client_data == currentX11InputMethodInstance) { + currentX11InputMethodInstance = NULL; + } + goto finally; + } + + if (NULL == (pX11IMData = getX11InputMethodData(env, (jobject)client_data)) + || NULL == (statusWindow = pX11IMData->statusWindow)){ + goto finally; + } + currentX11InputMethodInstance = (jobject)client_data; + + onoffStatusWindow(pX11IMData, 0, False); + + finally: + AWT_UNLOCK(); } static void StatusDrawCallback(XIC ic, XPointer client_data, XIMStatusDrawCallbackStruct *status_draw)
*** 1543,1566 **** JNIEXPORT jboolean JNICALL Java_sun_awt_X11InputMethodBase_setCompositionEnabledNative (JNIEnv *env, jobject this, jboolean enable) { X11InputMethodData *pX11IMData; char * ret = NULL; AWT_LOCK(); pX11IMData = getX11InputMethodData(env, this); if ((pX11IMData == NULL) || (pX11IMData->current_ic == NULL)) { AWT_UNLOCK(); return JNI_FALSE; } ! ret = XSetICValues(pX11IMData->current_ic, XNPreeditState, ! (enable ? XIMPreeditEnable : XIMPreeditDisable), NULL); AWT_UNLOCK(); ! if ((ret != 0) && (strcmp(ret, XNPreeditState) == 0)) { JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", ""); } return (jboolean)(ret == 0); } --- 1588,1643 ---- JNIEXPORT jboolean JNICALL Java_sun_awt_X11InputMethodBase_setCompositionEnabledNative (JNIEnv *env, jobject this, jboolean enable) { X11InputMethodData *pX11IMData; char * ret = NULL; + XVaNestedList pr_atrb; + #if defined(__linux__) || defined(MACOSX) + Boolean calledXSetICFocus = False; + #endif AWT_LOCK(); pX11IMData = getX11InputMethodData(env, this); if ((pX11IMData == NULL) || (pX11IMData->current_ic == NULL)) { AWT_UNLOCK(); return JNI_FALSE; } ! #if defined(__linux__) || defined(MACOSX) ! if (NULL != pX11IMData->statusWindow) { ! Window focus = 0; ! int revert_to; ! Window w = 0; ! XGetInputFocus(awt_display, &focus, &revert_to); ! XGetICValues(pX11IMData->current_ic, XNFocusWindow, &w, NULL); ! if (RevertToPointerRoot == revert_to ! && pX11IMData->ic_active != pX11IMData->ic_passive) { ! if (pX11IMData->current_ic == pX11IMData->ic_active) { ! if (getParentWindow(focus) == getParentWindow(w)) { ! XUnsetICFocus(pX11IMData->ic_active); ! calledXSetICFocus = True; ! } ! } ! } ! } ! #endif ! pr_atrb = XVaCreateNestedList(0, ! XNPreeditState, (enable ? XIMPreeditEnable : XIMPreeditDisable), ! NULL); ! ret = XSetICValues(pX11IMData->current_ic, XNPreeditAttributes, pr_atrb, NULL); ! XFree((void *)pr_atrb); ! #if defined(__linux__) || defined(MACOSX) ! if (calledXSetICFocus) { ! XSetICFocus(pX11IMData->ic_active); ! } ! #endif AWT_UNLOCK(); ! if ((ret != 0) ! && ((strcmp(ret, XNPreeditAttributes) == 0) ! || (strcmp(ret, XNPreeditState) == 0))) { JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", ""); } return (jboolean)(ret == 0); }
*** 1579,1602 **** JNIEXPORT jboolean JNICALL Java_sun_awt_X11InputMethodBase_isCompositionEnabledNative (JNIEnv *env, jobject this) { X11InputMethodData *pX11IMData = NULL; char * ret = NULL; ! XIMPreeditState state; AWT_LOCK(); pX11IMData = getX11InputMethodData(env, this); if ((pX11IMData == NULL) || (pX11IMData->current_ic == NULL)) { AWT_UNLOCK(); return JNI_FALSE; } ! ret = XGetICValues(pX11IMData->current_ic, XNPreeditState, &state, NULL); AWT_UNLOCK(); ! if ((ret != 0) && (strcmp(ret, XNPreeditState) == 0)) { JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", ""); return JNI_FALSE; } return (jboolean)(state == XIMPreeditEnable); --- 1656,1684 ---- JNIEXPORT jboolean JNICALL Java_sun_awt_X11InputMethodBase_isCompositionEnabledNative (JNIEnv *env, jobject this) { X11InputMethodData *pX11IMData = NULL; char * ret = NULL; ! XIMPreeditState state = XIMPreeditUnKnown; ! XVaNestedList pr_atrb; AWT_LOCK(); pX11IMData = getX11InputMethodData(env, this); if ((pX11IMData == NULL) || (pX11IMData->current_ic == NULL)) { AWT_UNLOCK(); return JNI_FALSE; } ! pr_atrb = XVaCreateNestedList(0, XNPreeditState, &state, NULL); ! ret = XGetICValues(pX11IMData->current_ic, XNPreeditAttributes, pr_atrb, NULL); ! XFree((void *)pr_atrb); AWT_UNLOCK(); ! if ((ret != 0) ! && ((strcmp(ret, XNPreeditAttributes) == 0) ! || (strcmp(ret, XNPreeditState) == 0))) { JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", ""); return JNI_FALSE; } return (jboolean)(state == XIMPreeditEnable);
*** 1609,1613 **** --- 1691,1712 ---- AWT_LOCK(); adjustStatusWindow(window); AWT_UNLOCK(); #endif } + + #if defined(__linux__) || defined(MACOSX) + static Window getParentWindow(Window w) + { + Window root=None, parent=None, *ignore_children=NULL; + unsigned int ignore_uint=0; + Status status = 0; + + if (w == None) + return None; + status = XQueryTree(dpy, w, &root, &parent, &ignore_children, &ignore_uint); + XFree(ignore_children); + if (status == 0) + return None; + return parent; + } + #endif
< prev index next >