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

Print this page

        

@@ -37,15 +37,15 @@
 #define NOT_A_CHECKBOXMENU -2
 
 
 @implementation CMenuItem
 
-- (id) initWithPeer:(jobject)peer asSeparator: (NSNumber *) asSeparator{
+- (id) initWithPeer:(jobject)peer asSeparator:(BOOL)asSeparator{
 AWT_ASSERT_APPKIT_THREAD;
     self = [super initWithPeer:peer];
     if (self) {
-        if ([asSeparator boolValue]) {
+        if (asSeparator) {
             fMenuItem = (NSMenuItem*)[NSMenuItem separatorItem];
             [fMenuItem retain];
         } else {
             fMenuItem = [[NSMenuItem alloc] init];
             [fMenuItem setAction:@selector(handleAction:)];

@@ -221,18 +221,10 @@
 
 - (void)setIsCheckbox {
     fIsCheckbox = YES;
 }
 
-- (void) _createMenuItem_OnAppKitThread: (NSMutableArray *)argValue {
-    jobject cPeerObjGlobal = (jobject)[[argValue objectAtIndex: 0] pointerValue];
-    NSNumber * asSeparator = (NSNumber *)[argValue objectAtIndex: 1];
-    CMenuItem *aCMenuItem = [self initWithPeer: cPeerObjGlobal asSeparator: asSeparator];
-    [argValue removeAllObjects];
-    [argValue addObject: aCMenuItem];
-}
-
 - (NSString *)description {
     return [NSString stringWithFormat:@"CMenuItem[ %@ ]", fMenuItem];
 }
 
 @end

@@ -389,40 +381,24 @@
  */
 JNIEXPORT jlong JNICALL
 Java_sun_lwawt_macosx_CMenuItem_nativeCreate
     (JNIEnv *env, jobject peer, jlong parentCMenuObj, jboolean isSeparator)
 {
-
-    CMenuItem *aCMenuItem = nil;
+    __block CMenuItem *aCMenuItem = nil;
     CMenu *parentCMenu = (CMenu *)jlong_to_ptr(parentCMenuObj);
+
 JNF_COCOA_ENTER(env);
 
     jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
 
-    NSMutableArray *args = nil;
-
-    // Create a new item....
-    if (isSeparator == JNI_TRUE) {
-        args = [[NSMutableArray alloc] initWithObjects:[NSValue valueWithBytes:&cPeerObjGlobal objCType:@encode(jobject)], [NSNumber numberWithBool:YES],  nil];
-    } else {
-        args = [[NSMutableArray alloc] initWithObjects:[NSValue valueWithBytes:&cPeerObjGlobal objCType:@encode(jobject)], [NSNumber numberWithBool:NO],  nil];
-    }
-
-    [ThreadUtilities performOnMainThread:@selector(_createMenuItem_OnAppKitThread:) on:[CMenuItem alloc] withObject:args waitUntilDone:YES];
-
-    aCMenuItem = (CMenuItem *)[args objectAtIndex: 0];
-
-    if (aCMenuItem == nil) {
-        return 0L;
-    }
-
-    // and add it to the parent item.
-    [parentCMenu addJavaMenuItem: aCMenuItem];
-
-    // setLabel will be called after creation completes.
+    [ThreadUtilities performOnMainThreadWaiting:YES block:^() {
+        aCMenuItem = [[CMenuItem alloc] initWithPeer:cPeerObjGlobal asSeparator:isSeparator];
+        [aCMenuItem addNSMenuItemToMenu:[parentCMenu menu]];
+    }];
 
 JNF_COCOA_EXIT(env);
+
     return ptr_to_jlong(aCMenuItem);
 }
 
 /*
  * Class:     sun_lwawt_macosx_CMenuItem