4632N/A/*
4632N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation. Oracle designates this
4632N/A * particular file as subject to the "Classpath" exception as provided
4632N/A * by Oracle in the LICENSE file that accompanied this code.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/A#import "CMenuComponent.h"
4632N/A#import <JavaNativeFoundation/JavaNativeFoundation.h>
4632N/A
4632N/A#import "ThreadUtilities.h"
4632N/A
4632N/A@class CMenuItem;
4632N/A
4632N/A@implementation CMenuComponent
4632N/A
4632N/A-(id) initWithPeer:(jobject)peer {
4632N/A self = [super init];
4632N/A if (self) {
4632N/A // the peer has been made clobal ref before
4632N/A fPeer = peer;
4632N/A }
4632N/A return self;
4632N/A}
4632N/A
4632N/A-(void) cleanup {
4632N/A // Used by subclasses
4632N/A}
4632N/A
4632N/A-(void) disposer {
4632N/A JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
4632N/A JNFDeleteGlobalRef(env, fPeer);
4632N/A fPeer = NULL;
4632N/A
4632N/A [self cleanup];
4632N/A
4632N/A CFRelease(self); // GC
4632N/A}
4632N/A
4632N/A// The method is used by all subclasses, since the process of the creation
4632N/A// is the same. The only exception is the CMenuItem class.
4632N/A- (void) _create_OnAppKitThread: (NSMutableArray *)argValue {
4632N/A jobject cPeerObjGlobal = (jobject)[[argValue objectAtIndex: 0] pointerValue];
4632N/A CMenuItem *aCMenuItem = [self initWithPeer:cPeerObjGlobal];
4632N/A [argValue removeAllObjects];
4632N/A [argValue addObject: aCMenuItem];
4632N/A}
4632N/A
4632N/A//-(void) dealloc { [super dealloc]; }
4632N/A//- (void)finalize { [super finalize]; }
4632N/A
4632N/A@end
4632N/A
4632N/A/*
4632N/A * Class: sun_lwawt_macosx_CMenuComponent
4632N/A * Method: nativeDispose
4632N/A * Signature: (J)V
4632N/A */
4632N/AJNIEXPORT void JNICALL
4632N/AJava_sun_lwawt_macosx_CMenuComponent_nativeDispose
4632N/A(JNIEnv *env, jobject peer, jlong menuItemObj)
4632N/A{
4632N/AJNF_COCOA_ENTER(env);
4632N/A
6055N/A [ThreadUtilities performOnMainThread:@selector(disposer)
6055N/A on:((id)jlong_to_ptr(menuItemObj))
6055N/A withObject:nil
6055N/A waitUntilDone:NO];
4632N/A
4632N/AJNF_COCOA_EXIT(env);
4632N/A}