180
181 -(void) deactivate {
182 AWT_ASSERT_APPKIT_THREAD;
183
184 @synchronized([CMenuBar class]) {
185 sActiveMenuBar = nil;
186 }
187
188 @synchronized(self) {
189 fModallyDisabled = NO;
190 }
191 }
192
193 -(void) javaAddMenu: (CMenu *)theMenu {
194 @synchronized(self) {
195 [fMenuList addObject: theMenu];
196 }
197
198 if (self == sActiveMenuBar) {
199 NSArray *args = [[NSArray alloc] initWithObjects:theMenu, [NSNumber numberWithInt:-1], nil];
200 [ThreadUtilities performOnMainThread:@selector(nativeAddMenuAtIndex_OnAppKitThread:) onObject:self withObject:args waitUntilDone:YES awtMode:YES];
201 [args release];
202 }
203 }
204
205 // This method is a special case for use by the screen menu bar.
206 // See ScreenMenuBar.java -- used to implement setVisible(boolean) by
207 // removing or adding the menu from the current menu bar's list.
208 -(void) javaAddMenu: (CMenu *)theMenu atIndex:(jint)index {
209 @synchronized(self) {
210 if (index == -1){
211 [fMenuList addObject:theMenu];
212 }else{
213 [fMenuList insertObject:theMenu atIndex:index];
214 }
215 }
216
217 if (self == sActiveMenuBar) {
218 NSArray *args = [[NSArray alloc] initWithObjects:theMenu, [NSNumber numberWithInt:index], nil];
219 [ThreadUtilities performOnMainThread:@selector(nativeAddMenuAtIndex_OnAppKitThread:) onObject:self withObject:args waitUntilDone:YES awtMode:YES];
220 [args release];
221 }
222 }
223
224 - (NSInteger) javaIndexToNSMenuIndex_OnAppKitThread:(jint)javaIndex {
225 AWT_ASSERT_APPKIT_THREAD;
226 NSInteger returnValue = -1;
227 NSMenu *theMainMenu = [NSApp mainMenu];
228
229 if (javaIndex == -1) {
230 if (fHelpMenu) {
231 returnValue = [theMainMenu indexOfItemWithSubmenu:[fHelpMenu menu]];
232 }
233 } else {
234 CMenu *requestedMenu = [fMenuList objectAtIndex:javaIndex];
235
236 if (requestedMenu == fHelpMenu) {
237 returnValue = [theMainMenu indexOfItemWithSubmenu:[fHelpMenu menu]];
238 } else {
239 NSUInteger i, menuCount = [theMainMenu numberOfItems];
269 NSMenuItem *newItem = [[NSMenuItem alloc] init];
270 [newItem setSubmenu:[theNewMenu menu]];
271 [newItem setTitle:[[theNewMenu menu] title]];
272
273 NSInteger nsMenuIndex = [self javaIndexToNSMenuIndex_OnAppKitThread:index];
274
275 if (nsMenuIndex == -1) {
276 [theMainMenu addItem:newItem];
277 } else {
278 [theMainMenu insertItem:newItem atIndex:nsMenuIndex];
279 }
280
281 BOOL newEnabledState = [theNewMenu isEnabled] && !fModallyDisabled;
282 [newItem setEnabled:newEnabledState];
283 [newItem release];
284 }
285 }
286
287 - (void) javaDeleteMenu: (jint)index {
288 if (self == sActiveMenuBar) {
289 [ThreadUtilities performOnMainThread:@selector(nativeDeleteMenu_OnAppKitThread:) onObject:self withObject:[NSNumber numberWithInt:index] waitUntilDone:YES awtMode:YES];
290 }
291
292 @synchronized(self) {
293 CMenu *menuToRemove = [fMenuList objectAtIndex:index];
294
295 if (menuToRemove == fHelpMenu) {
296 [fHelpMenu release];
297 fHelpMenu = nil;
298 }
299
300 [fMenuList removeObjectAtIndex:index];
301 }
302 }
303
304 - (void) nativeDeleteMenu_OnAppKitThread:(id)indexObj {
305 AWT_ASSERT_APPKIT_THREAD;
306 NSApplication *theApp = [NSApplication sharedApplication];
307 NSMenu *theMainMenu = [theApp mainMenu];
308 jint menuToRemove = [(NSNumber *)indexObj intValue];
309 NSInteger nsMenuToRemove = [self javaIndexToNSMenuIndex_OnAppKitThread:menuToRemove];
371
372 @end
373
374 /*
375 * Class: sun_lwawt_macosx_CMenuBar
376 * Method: nativeCreateMenuBar
377 * Signature: ()J
378 */
379 JNIEXPORT jlong JNICALL
380 Java_sun_lwawt_macosx_CMenuBar_nativeCreateMenuBar
381 (JNIEnv *env, jobject peer)
382 {
383 CMenuBar *aCMenuBar = nil;
384 JNF_COCOA_ENTER(env);
385
386 jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
387
388 // We use an array here only to be able to get a return value
389 NSMutableArray *args = [[NSMutableArray alloc] initWithObjects:[NSValue valueWithBytes:&cPeerObjGlobal objCType:@encode(jobject)], nil];
390
391 [ThreadUtilities performOnMainThread:@selector(_create_OnAppKitThread:) onObject:[CMenuBar alloc] withObject:args waitUntilDone:YES awtMode:YES];
392
393 aCMenuBar = (CMenuBar *)[args objectAtIndex: 0];
394
395 if (aCMenuBar == nil) {
396 return 0L;
397 }
398
399 // [args release];
400
401 // A strange memory managment after that.
402
403
404 JNF_COCOA_EXIT(env);
405 if (aCMenuBar) {
406 CFRetain(aCMenuBar); // GC
407 [aCMenuBar release];
408 }
409 return ptr_to_jlong(aCMenuBar);
410 }
411
|
180
181 -(void) deactivate {
182 AWT_ASSERT_APPKIT_THREAD;
183
184 @synchronized([CMenuBar class]) {
185 sActiveMenuBar = nil;
186 }
187
188 @synchronized(self) {
189 fModallyDisabled = NO;
190 }
191 }
192
193 -(void) javaAddMenu: (CMenu *)theMenu {
194 @synchronized(self) {
195 [fMenuList addObject: theMenu];
196 }
197
198 if (self == sActiveMenuBar) {
199 NSArray *args = [[NSArray alloc] initWithObjects:theMenu, [NSNumber numberWithInt:-1], nil];
200 [ThreadUtilities performOnMainThread:@selector(nativeAddMenuAtIndex_OnAppKitThread:) on:self withObject:args waitUntilDone:YES];
201 [args release];
202 }
203 }
204
205 // This method is a special case for use by the screen menu bar.
206 // See ScreenMenuBar.java -- used to implement setVisible(boolean) by
207 // removing or adding the menu from the current menu bar's list.
208 -(void) javaAddMenu: (CMenu *)theMenu atIndex:(jint)index {
209 @synchronized(self) {
210 if (index == -1){
211 [fMenuList addObject:theMenu];
212 }else{
213 [fMenuList insertObject:theMenu atIndex:index];
214 }
215 }
216
217 if (self == sActiveMenuBar) {
218 NSArray *args = [[NSArray alloc] initWithObjects:theMenu, [NSNumber numberWithInt:index], nil];
219 [ThreadUtilities performOnMainThread:@selector(nativeAddMenuAtIndex_OnAppKitThread:) on:self withObject:args waitUntilDone:YES];
220 [args release];
221 }
222 }
223
224 - (NSInteger) javaIndexToNSMenuIndex_OnAppKitThread:(jint)javaIndex {
225 AWT_ASSERT_APPKIT_THREAD;
226 NSInteger returnValue = -1;
227 NSMenu *theMainMenu = [NSApp mainMenu];
228
229 if (javaIndex == -1) {
230 if (fHelpMenu) {
231 returnValue = [theMainMenu indexOfItemWithSubmenu:[fHelpMenu menu]];
232 }
233 } else {
234 CMenu *requestedMenu = [fMenuList objectAtIndex:javaIndex];
235
236 if (requestedMenu == fHelpMenu) {
237 returnValue = [theMainMenu indexOfItemWithSubmenu:[fHelpMenu menu]];
238 } else {
239 NSUInteger i, menuCount = [theMainMenu numberOfItems];
269 NSMenuItem *newItem = [[NSMenuItem alloc] init];
270 [newItem setSubmenu:[theNewMenu menu]];
271 [newItem setTitle:[[theNewMenu menu] title]];
272
273 NSInteger nsMenuIndex = [self javaIndexToNSMenuIndex_OnAppKitThread:index];
274
275 if (nsMenuIndex == -1) {
276 [theMainMenu addItem:newItem];
277 } else {
278 [theMainMenu insertItem:newItem atIndex:nsMenuIndex];
279 }
280
281 BOOL newEnabledState = [theNewMenu isEnabled] && !fModallyDisabled;
282 [newItem setEnabled:newEnabledState];
283 [newItem release];
284 }
285 }
286
287 - (void) javaDeleteMenu: (jint)index {
288 if (self == sActiveMenuBar) {
289 [ThreadUtilities performOnMainThread:@selector(nativeDeleteMenu_OnAppKitThread:) on:self withObject:[NSNumber numberWithInt:index] waitUntilDone:YES];
290 }
291
292 @synchronized(self) {
293 CMenu *menuToRemove = [fMenuList objectAtIndex:index];
294
295 if (menuToRemove == fHelpMenu) {
296 [fHelpMenu release];
297 fHelpMenu = nil;
298 }
299
300 [fMenuList removeObjectAtIndex:index];
301 }
302 }
303
304 - (void) nativeDeleteMenu_OnAppKitThread:(id)indexObj {
305 AWT_ASSERT_APPKIT_THREAD;
306 NSApplication *theApp = [NSApplication sharedApplication];
307 NSMenu *theMainMenu = [theApp mainMenu];
308 jint menuToRemove = [(NSNumber *)indexObj intValue];
309 NSInteger nsMenuToRemove = [self javaIndexToNSMenuIndex_OnAppKitThread:menuToRemove];
371
372 @end
373
374 /*
375 * Class: sun_lwawt_macosx_CMenuBar
376 * Method: nativeCreateMenuBar
377 * Signature: ()J
378 */
379 JNIEXPORT jlong JNICALL
380 Java_sun_lwawt_macosx_CMenuBar_nativeCreateMenuBar
381 (JNIEnv *env, jobject peer)
382 {
383 CMenuBar *aCMenuBar = nil;
384 JNF_COCOA_ENTER(env);
385
386 jobject cPeerObjGlobal = (*env)->NewGlobalRef(env, peer);
387
388 // We use an array here only to be able to get a return value
389 NSMutableArray *args = [[NSMutableArray alloc] initWithObjects:[NSValue valueWithBytes:&cPeerObjGlobal objCType:@encode(jobject)], nil];
390
391 [ThreadUtilities performOnMainThread:@selector(_create_OnAppKitThread:) on:[CMenuBar alloc] withObject:args waitUntilDone:YES];
392
393 aCMenuBar = (CMenuBar *)[args objectAtIndex: 0];
394
395 if (aCMenuBar == nil) {
396 return 0L;
397 }
398
399 // [args release];
400
401 // A strange memory managment after that.
402
403
404 JNF_COCOA_EXIT(env);
405 if (aCMenuBar) {
406 CFRetain(aCMenuBar); // GC
407 [aCMenuBar release];
408 }
409 return ptr_to_jlong(aCMenuBar);
410 }
411
|