jdk/src/macosx/native/sun/awt/LWCToolkit.m
changeset 23301 618f7a6142c0
parent 18274 7c4289125569
child 23328 4c53a6ebc779
equal deleted inserted replaced
23300:a7b5e8ad5786 23301:618f7a6142c0
   198     });
   198     });
   199 
   199 
   200     gNumberOfButtons = sun_lwawt_macosx_LWCToolkit_BUTTONS;
   200     gNumberOfButtons = sun_lwawt_macosx_LWCToolkit_BUTTONS;
   201 
   201 
   202     jclass inputEventClazz = (*env)->FindClass(env, "java/awt/event/InputEvent");
   202     jclass inputEventClazz = (*env)->FindClass(env, "java/awt/event/InputEvent");
       
   203     CHECK_NULL(inputEventClazz);
   203     jmethodID getButtonDownMasksID = (*env)->GetStaticMethodID(env, inputEventClazz, "getButtonDownMasks", "()[I");
   204     jmethodID getButtonDownMasksID = (*env)->GetStaticMethodID(env, inputEventClazz, "getButtonDownMasks", "()[I");
       
   205     CHECK_NULL(getButtonDownMasksID);
   204     jintArray obj = (jintArray)(*env)->CallStaticObjectMethod(env, inputEventClazz, getButtonDownMasksID);
   206     jintArray obj = (jintArray)(*env)->CallStaticObjectMethod(env, inputEventClazz, getButtonDownMasksID);
   205     jint * tmp = (*env)->GetIntArrayElements(env, obj, JNI_FALSE);
   207     jint * tmp = (*env)->GetIntArrayElements(env, obj, JNI_FALSE);
       
   208     CHECK_NULL(tmp);
   206 
   209 
   207     gButtonDownMasks = (jint*)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(jint), gNumberOfButtons);
   210     gButtonDownMasks = (jint*)SAFE_SIZE_ARRAY_ALLOC(malloc, sizeof(jint), gNumberOfButtons);
   208     if (gButtonDownMasks == NULL) {
   211     if (gButtonDownMasks == NULL) {
   209         gNumberOfButtons = 0;
   212         gNumberOfButtons = 0;
       
   213         (*env)->ReleaseIntArrayElements(env, obj, tmp, JNI_ABORT);
   210         JNU_ThrowOutOfMemoryError(env, NULL);
   214         JNU_ThrowOutOfMemoryError(env, NULL);
   211         return;
   215         return;
   212     }
   216     }
   213 
   217 
   214     int i;
   218     int i;
   238     //    NSLog(@"%@ %d, %d, %d", c, ir, ig, ib);
   242     //    NSLog(@"%@ %d, %d, %d", c, ir, ig, ib);
   239 
   243 
   240     return ((ia & 0xFF) << 24) | ((ir & 0xFF) << 16) | ((ig & 0xFF) << 8) | ((ib & 0xFF) << 0);
   244     return ((ia & 0xFF) << 24) | ((ir & 0xFF) << 16) | ((ig & 0xFF) << 8) | ((ib & 0xFF) << 0);
   241 }
   245 }
   242 
   246 
   243 void doLoadNativeColors(JNIEnv *env, jintArray jColors, BOOL useAppleColors) {
   247 BOOL doLoadNativeColors(JNIEnv *env, jintArray jColors, BOOL useAppleColors) {
   244     jint len = (*env)->GetArrayLength(env, jColors);
   248     jint len = (*env)->GetArrayLength(env, jColors);
   245 
   249 
   246     UInt32 colorsArray[len];
   250     UInt32 colorsArray[len];
   247     UInt32 *colors = colorsArray;
   251     UInt32 *colors = colorsArray;
   248 
   252 
   252             colors[i] = RGB([CSystemColors getColor:i useAppleColor:useAppleColors]);
   256             colors[i] = RGB([CSystemColors getColor:i useAppleColor:useAppleColors]);
   253         }
   257         }
   254     }];
   258     }];
   255 
   259 
   256     jint *_colors = (*env)->GetPrimitiveArrayCritical(env, jColors, 0);
   260     jint *_colors = (*env)->GetPrimitiveArrayCritical(env, jColors, 0);
       
   261     if (_colors == NULL) {
       
   262         return NO;
       
   263     }
   257     memcpy(_colors, colors, len * sizeof(UInt32));
   264     memcpy(_colors, colors, len * sizeof(UInt32));
   258     (*env)->ReleasePrimitiveArrayCritical(env, jColors, _colors, 0);
   265     (*env)->ReleasePrimitiveArrayCritical(env, jColors, _colors, 0);
       
   266     return YES;
   259 }
   267 }
   260 
   268 
   261 /**
   269 /**
   262  * Class:     sun_lwawt_macosx_LWCToolkit
   270  * Class:     sun_lwawt_macosx_LWCToolkit
   263  * Method:    loadNativeColors
   271  * Method:    loadNativeColors
   265  */
   273  */
   266 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_loadNativeColors
   274 JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_loadNativeColors
   267 (JNIEnv *env, jobject peer, jintArray jSystemColors, jintArray jAppleColors)
   275 (JNIEnv *env, jobject peer, jintArray jSystemColors, jintArray jAppleColors)
   268 {
   276 {
   269 JNF_COCOA_ENTER(env);
   277 JNF_COCOA_ENTER(env);
   270     doLoadNativeColors(env, jSystemColors, NO);
   278     if (doLoadNativeColors(env, jSystemColors, NO)) {
   271     doLoadNativeColors(env, jAppleColors, YES);
   279         doLoadNativeColors(env, jAppleColors, YES);
       
   280     }
   272 JNF_COCOA_EXIT(env);
   281 JNF_COCOA_EXIT(env);
   273 }
   282 }
   274 
   283 
   275 /*
   284 /*
   276  * Class:     sun_lwawt_macosx_LWCToolkit
   285  * Class:     sun_lwawt_macosx_LWCToolkit