src/macosx/native/sun/awt/CInputMethod.m

Print this page




 136  */
 137 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeInit
 138 (JNIEnv *env, jclass klass)
 139 {
 140     initializeInputMethodController();
 141 }
 142 
 143 /*
 144  * Class:     sun_lwawt_macosx_CInputMethod
 145  * Method:    nativeGetCurrentInputMethodInfo
 146  * Signature: ()Ljava/lang/String;
 147  */
 148 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeGetCurrentInputMethodInfo
 149 (JNIEnv *env, jclass klass)
 150 {
 151     if (!inputMethodController) return NULL;
 152     jobject returnValue = 0;
 153     __block NSString *keyboardInfo = NULL;
 154 JNF_COCOA_ENTER(env);
 155 
 156     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 157         keyboardInfo = [inputMethodController performSelector:@selector(currentInputMethodName)];
 158         [keyboardInfo retain];
 159     }];
 160 
 161     if (keyboardInfo == nil) return NULL;
 162     returnValue = JNFNSToJavaString(env, keyboardInfo);
 163     [keyboardInfo release];
 164 
 165 JNF_COCOA_EXIT(env);
 166     return returnValue;
 167 }
 168 
 169 /*
 170  * Class:     sun_lwawt_macosx_CInputMethod
 171  * Method:    nativeActivate
 172  * Signature: (JLsun/lwawt/macosx/CInputMethod;)V
 173  */
 174 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeNotifyPeer
 175 (JNIEnv *env, jobject this, jlong nativePeer, jobject inputMethod)
 176 {
 177 JNF_COCOA_ENTER(env);
 178     AWTView *view = (AWTView *)jlong_to_ptr(nativePeer);
 179     JNFJObjectWrapper *inputMethodWrapper = [[JNFJObjectWrapper alloc] initWithJObject:inputMethod withEnv:env];
 180     [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 181         [CInputMethod _nativeNotifyPeerWithView:view inputMethod:inputMethodWrapper];
 182     }];
 183 
 184 JNF_COCOA_EXIT(env);
 185 
 186 }
 187 
 188 /*
 189  * Class:     sun_lwawt_macosx_CInputMethod
 190  * Method:    nativeEndComposition
 191  * Signature: (J)V
 192  */
 193 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeEndComposition
 194 (JNIEnv *env, jobject this, jlong nativePeer)
 195 {
 196 JNF_COCOA_ENTER(env);
 197    AWTView *view = (AWTView *)jlong_to_ptr(nativePeer);
 198 
 199    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
 200         [CInputMethod _nativeEndComposition:view];
 201     }];
 202 
 203 JNF_COCOA_EXIT(env);
 204 }
 205 
 206 /*
 207  * Class:     sun_lwawt_macosx_CInputMethod
 208  * Method:    getNativeLocale
 209  * Signature: ()Ljava/util/Locale;
 210  */
 211 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CInputMethod_getNativeLocale
 212 (JNIEnv *env, jobject this)
 213 {
 214     if (!inputMethodController) return NULL;
 215     jobject returnValue = 0;
 216     __block NSString *isoAbbreviation;
 217 JNF_COCOA_ENTER(env);
 218 
 219     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 220         isoAbbreviation = (NSString *) [inputMethodController performSelector:@selector(currentInputMethodLocale)];
 221         [isoAbbreviation retain];
 222     }];
 223 
 224     if (isoAbbreviation == nil) return NULL;
 225 
 226     static NSString *sLastKeyboardStr = nil;
 227     static jobject sLastKeyboardLocaleObj = NULL;
 228 
 229     if (![isoAbbreviation isEqualTo:sLastKeyboardStr]) {
 230         [sLastKeyboardStr release];
 231         sLastKeyboardStr = [isoAbbreviation retain];
 232         jobject localObj = CreateLocaleObjectFromNSString(env, isoAbbreviation);
 233         [isoAbbreviation release];
 234 
 235         if (sLastKeyboardLocaleObj) {
 236             JNFDeleteGlobalRef(env, sLastKeyboardLocaleObj);
 237         }
 238 
 239         sLastKeyboardLocaleObj = JNFNewGlobalRef(env, localObj);


 242 
 243     returnValue = sLastKeyboardLocaleObj;
 244 
 245 JNF_COCOA_EXIT(env);
 246     return returnValue;
 247 }
 248 
 249 
 250 /*
 251  * Class:     sun_lwawt_macosx_CInputMethod
 252  * Method:    setNativeLocale
 253  * Signature: (Ljava/lang/String;Z)Z
 254  */
 255 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CInputMethod_setNativeLocale
 256 (JNIEnv *env, jobject this, jstring locale, jboolean isActivating)
 257 {
 258 JNF_COCOA_ENTER(env);
 259     NSString *localeStr = JNFJavaToNSString(env, locale);
 260     [localeStr retain];
 261 
 262     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 263         [CInputMethod setKeyboardLayout:localeStr];
 264     }];
 265 
 266     [localeStr release];
 267 JNF_COCOA_EXIT(env);
 268     return JNI_TRUE;
 269 }
 270 
 271 /*
 272  * Class:     sun_lwawt_macosx_CInputMethodDescriptor
 273  * Method:    nativeInit
 274  * Signature: ();
 275  */
 276 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethodDescriptor_nativeInit
 277 (JNIEnv *env, jclass klass)
 278 {
 279     initializeInputMethodController();
 280 }
 281 
 282 /*
 283  * Class:     sun_lwawt_macosx_CInputMethodDescriptor
 284  * Method:    nativeGetAvailableLocales
 285  * Signature: ()[Ljava/util/Locale;
 286      */
 287 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CInputMethodDescriptor_nativeGetAvailableLocales
 288 (JNIEnv *env, jclass klass)
 289 {
 290     if (!inputMethodController) return NULL;
 291     jobject returnValue = 0;
 292 
 293     __block NSArray *selectableArray = nil;
 294 JNF_COCOA_ENTER(env);
 295 
 296     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
 297         selectableArray = (NSArray *)[inputMethodController performSelector:@selector(availableInputMethodLocales)];
 298         [selectableArray retain];
 299     }];
 300 
 301     if (selectableArray == nil) return NULL;
 302 
 303      // Create an ArrayList to return back to the caller.
 304     returnValue = JNFNewObject(env, jm_arrayListCons);
 305 
 306     for(NSString *locale in selectableArray) {
 307         jobject localeObj = CreateLocaleObjectFromNSString(env, locale);
 308 
 309         if (JNFCallBooleanMethod(env, returnValue, jm_listContains, localeObj) == JNI_FALSE) { // AWT_THREADING Safe (known object)
 310             JNFCallBooleanMethod(env, returnValue, jm_listAdd, localeObj); // AWT_THREADING Safe (known object)
 311         }
 312 
 313         (*env)->DeleteLocalRef(env, localeObj);
 314     }
 315     [selectableArray release];
 316 JNF_COCOA_EXIT(env);


 136  */
 137 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeInit
 138 (JNIEnv *env, jclass klass)
 139 {
 140     initializeInputMethodController();
 141 }
 142 
 143 /*
 144  * Class:     sun_lwawt_macosx_CInputMethod
 145  * Method:    nativeGetCurrentInputMethodInfo
 146  * Signature: ()Ljava/lang/String;
 147  */
 148 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeGetCurrentInputMethodInfo
 149 (JNIEnv *env, jclass klass)
 150 {
 151     if (!inputMethodController) return NULL;
 152     jobject returnValue = 0;
 153     __block NSString *keyboardInfo = NULL;
 154 JNF_COCOA_ENTER(env);
 155 
 156     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 157         keyboardInfo = [inputMethodController performSelector:@selector(currentInputMethodName)];
 158         [keyboardInfo retain];
 159     }];
 160 
 161     if (keyboardInfo == nil) return NULL;
 162     returnValue = JNFNSToJavaString(env, keyboardInfo);
 163     [keyboardInfo release];
 164 
 165 JNF_COCOA_EXIT(env);
 166     return returnValue;
 167 }
 168 
 169 /*
 170  * Class:     sun_lwawt_macosx_CInputMethod
 171  * Method:    nativeActivate
 172  * Signature: (JLsun/lwawt/macosx/CInputMethod;)V
 173  */
 174 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeNotifyPeer
 175 (JNIEnv *env, jobject this, jlong nativePeer, jobject inputMethod)
 176 {
 177 JNF_COCOA_ENTER(env);
 178     AWTView *view = (AWTView *)jlong_to_ptr(nativePeer);
 179     JNFJObjectWrapper *inputMethodWrapper = [[JNFJObjectWrapper alloc] initWithJObject:inputMethod withEnv:env];
 180     [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 181         [CInputMethod _nativeNotifyPeerWithView:view inputMethod:inputMethodWrapper];
 182     }];
 183 
 184 JNF_COCOA_EXIT(env);
 185 
 186 }
 187 
 188 /*
 189  * Class:     sun_lwawt_macosx_CInputMethod
 190  * Method:    nativeEndComposition
 191  * Signature: (J)V
 192  */
 193 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeEndComposition
 194 (JNIEnv *env, jobject this, jlong nativePeer)
 195 {
 196 JNF_COCOA_ENTER(env);
 197    AWTView *view = (AWTView *)jlong_to_ptr(nativePeer);
 198 
 199    [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
 200         [CInputMethod _nativeEndComposition:view];
 201     }];
 202 
 203 JNF_COCOA_EXIT(env);
 204 }
 205 
 206 /*
 207  * Class:     sun_lwawt_macosx_CInputMethod
 208  * Method:    getNativeLocale
 209  * Signature: ()Ljava/util/Locale;
 210  */
 211 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CInputMethod_getNativeLocale
 212 (JNIEnv *env, jobject this)
 213 {
 214     if (!inputMethodController) return NULL;
 215     jobject returnValue = 0;
 216     __block NSString *isoAbbreviation;
 217 JNF_COCOA_ENTER(env);
 218 
 219     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 220         isoAbbreviation = (NSString *) [inputMethodController performSelector:@selector(currentInputMethodLocale)];
 221         [isoAbbreviation retain];
 222     }];
 223 
 224     if (isoAbbreviation == nil) return NULL;
 225 
 226     static NSString *sLastKeyboardStr = nil;
 227     static jobject sLastKeyboardLocaleObj = NULL;
 228 
 229     if (![isoAbbreviation isEqualTo:sLastKeyboardStr]) {
 230         [sLastKeyboardStr release];
 231         sLastKeyboardStr = [isoAbbreviation retain];
 232         jobject localObj = CreateLocaleObjectFromNSString(env, isoAbbreviation);
 233         [isoAbbreviation release];
 234 
 235         if (sLastKeyboardLocaleObj) {
 236             JNFDeleteGlobalRef(env, sLastKeyboardLocaleObj);
 237         }
 238 
 239         sLastKeyboardLocaleObj = JNFNewGlobalRef(env, localObj);


 242 
 243     returnValue = sLastKeyboardLocaleObj;
 244 
 245 JNF_COCOA_EXIT(env);
 246     return returnValue;
 247 }
 248 
 249 
 250 /*
 251  * Class:     sun_lwawt_macosx_CInputMethod
 252  * Method:    setNativeLocale
 253  * Signature: (Ljava/lang/String;Z)Z
 254  */
 255 JNIEXPORT jboolean JNICALL Java_sun_lwawt_macosx_CInputMethod_setNativeLocale
 256 (JNIEnv *env, jobject this, jstring locale, jboolean isActivating)
 257 {
 258 JNF_COCOA_ENTER(env);
 259     NSString *localeStr = JNFJavaToNSString(env, locale);
 260     [localeStr retain];
 261 
 262     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 263         [CInputMethod setKeyboardLayout:localeStr];
 264     }];
 265 
 266     [localeStr release];
 267 JNF_COCOA_EXIT(env);
 268     return JNI_TRUE;
 269 }
 270 
 271 /*
 272  * Class:     sun_lwawt_macosx_CInputMethodDescriptor
 273  * Method:    nativeInit
 274  * Signature: ();
 275  */
 276 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethodDescriptor_nativeInit
 277 (JNIEnv *env, jclass klass)
 278 {
 279     initializeInputMethodController();
 280 }
 281 
 282 /*
 283  * Class:     sun_lwawt_macosx_CInputMethodDescriptor
 284  * Method:    nativeGetAvailableLocales
 285  * Signature: ()[Ljava/util/Locale;
 286      */
 287 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CInputMethodDescriptor_nativeGetAvailableLocales
 288 (JNIEnv *env, jclass klass)
 289 {
 290     if (!inputMethodController) return NULL;
 291     jobject returnValue = 0;
 292 
 293     __block NSArray *selectableArray = nil;
 294 JNF_COCOA_ENTER(env);
 295 
 296     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 297         selectableArray = (NSArray *)[inputMethodController performSelector:@selector(availableInputMethodLocales)];
 298         [selectableArray retain];
 299     }];
 300 
 301     if (selectableArray == nil) return NULL;
 302 
 303      // Create an ArrayList to return back to the caller.
 304     returnValue = JNFNewObject(env, jm_arrayListCons);
 305 
 306     for(NSString *locale in selectableArray) {
 307         jobject localeObj = CreateLocaleObjectFromNSString(env, locale);
 308 
 309         if (JNFCallBooleanMethod(env, returnValue, jm_listContains, localeObj) == JNI_FALSE) { // AWT_THREADING Safe (known object)
 310             JNFCallBooleanMethod(env, returnValue, jm_listAdd, localeObj); // AWT_THREADING Safe (known object)
 311         }
 312 
 313         (*env)->DeleteLocalRef(env, localeObj);
 314     }
 315     [selectableArray release];
 316 JNF_COCOA_EXIT(env);