< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m

Print this page




 282  * Signature: ();
 283  */
 284 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethodDescriptor_nativeInit
 285 (JNIEnv *env, jclass klass)
 286 {
 287     initializeInputMethodController();
 288 }
 289 
 290 /*
 291  * Class:     sun_lwawt_macosx_CInputMethodDescriptor
 292  * Method:    nativeGetAvailableLocales
 293  * Signature: ()[Ljava/util/Locale;
 294      */
 295 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CInputMethodDescriptor_nativeGetAvailableLocales
 296 (JNIEnv *env, jclass klass)
 297 {
 298     if (!inputMethodController) return NULL;
 299     jobject returnValue = 0;
 300 
 301     __block NSArray *selectableArray = nil;

 302 JNF_COCOA_ENTER(env);
 303 
 304     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 305         selectableArray = (NSArray *)[inputMethodController performSelector:@selector(availableInputMethodLocales)];











 306         [selectableArray retain];
 307     }];
 308 
 309     if (selectableArray == nil) return NULL;
 310 
 311      // Create an ArrayList to return back to the caller.
 312     returnValue = JNFNewObject(env, jm_arrayListCons);
 313 
 314     for(NSString *locale in selectableArray) {
 315         jobject localeObj = CreateLocaleObjectFromNSString(env, locale);
 316         if (localeObj == NULL) {
 317             break;
 318         }
 319 
 320         if (JNFCallBooleanMethod(env, returnValue, jm_listContains, localeObj) == JNI_FALSE) {
 321             JNFCallBooleanMethod(env, returnValue, jm_listAdd, localeObj);
 322         }
 323 
 324         (*env)->DeleteLocalRef(env, localeObj);
 325     }

 326     [selectableArray release];
 327 JNF_COCOA_EXIT(env);
 328     return returnValue;
 329 }
 330 


 282  * Signature: ();
 283  */
 284 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethodDescriptor_nativeInit
 285 (JNIEnv *env, jclass klass)
 286 {
 287     initializeInputMethodController();
 288 }
 289 
 290 /*
 291  * Class:     sun_lwawt_macosx_CInputMethodDescriptor
 292  * Method:    nativeGetAvailableLocales
 293  * Signature: ()[Ljava/util/Locale;
 294      */
 295 JNIEXPORT jobject JNICALL Java_sun_lwawt_macosx_CInputMethodDescriptor_nativeGetAvailableLocales
 296 (JNIEnv *env, jclass klass)
 297 {
 298     if (!inputMethodController) return NULL;
 299     jobject returnValue = 0;
 300 
 301     __block NSArray *selectableArray = nil;
 302     __block NSString *currentLocale = nil;
 303 JNF_COCOA_ENTER(env);
 304 
 305     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 306         selectableArray = (NSArray *)[inputMethodController performSelector:@selector(availableInputMethodLocales)];
 307         // If it is impossible to retirieve the list of available input method locales from
 308         // the platform for some reason, we will return the array contained only current locale.
 309         if ([selectableArray count] == 0) {
 310             currentLocale = (NSString *) [inputMethodController performSelector:@selector(currentInputMethodLocale)];
 311             if ([currentLocale length] != 0) {
 312                 selectableArray = [NSArray arrayWithObjects:currentLocale, nil];
 313                 [currentLocale retain];
 314             } else {
 315                 [currentLocale release];
 316             }
 317         }
 318         [selectableArray retain];
 319     }];
 320 
 321     if (selectableArray == nil) return NULL;
 322 
 323      // Create an ArrayList to return back to the caller.
 324     returnValue = JNFNewObject(env, jm_arrayListCons);
 325 
 326     for(NSString *locale in selectableArray) {
 327         jobject localeObj = CreateLocaleObjectFromNSString(env, locale);
 328         if (localeObj == NULL) {
 329             break;
 330         }
 331 
 332         if (JNFCallBooleanMethod(env, returnValue, jm_listContains, localeObj) == JNI_FALSE) {
 333             JNFCallBooleanMethod(env, returnValue, jm_listAdd, localeObj);
 334         }
 335 
 336         (*env)->DeleteLocalRef(env, localeObj);
 337     }
 338     [currentLocale release];
 339     [selectableArray release];
 340 JNF_COCOA_EXIT(env);
 341     return returnValue;
 342 }
 343 
< prev index next >