8234706: MenuPeer cleanup
Reviewed-by: prr
This commit is contained in:
parent
8f8f43999c
commit
e8fdc9408e
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -93,13 +93,6 @@ public class CMenu extends CMenuItem implements MenuPeer {
|
||||
super.setLabel(label);
|
||||
}
|
||||
|
||||
// Note that addSeparator is never called directly from java.awt.Menu,
|
||||
// though it is required in the MenuPeer interface.
|
||||
@Override
|
||||
public final void addSeparator() {
|
||||
execute(this::nativeAddSeparator);
|
||||
}
|
||||
|
||||
// Used by ScreenMenuBar to get to the native menu for event handling.
|
||||
public final long getNativeMenu() {
|
||||
return executeGet(this::nativeGetNSMenu);
|
||||
@ -110,7 +103,6 @@ public class CMenu extends CMenuItem implements MenuPeer {
|
||||
int insertionLocation);
|
||||
private native long nativeCreateSubMenu(long parentMenuPtr);
|
||||
private native void nativeSetMenuTitle(long menuPtr, String title);
|
||||
private native void nativeAddSeparator(long menuPtr);
|
||||
private native void nativeDeleteItem(long menuPtr, int index);
|
||||
|
||||
// Returns a retained NSMenu object! We have to explicitly
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -45,7 +45,6 @@ extern NSString *JAVA_MENU_NAME;
|
||||
- (void)setJavaMenuTitle:(NSString *)title;
|
||||
- (void)deleteJavaItem:(jint)index;
|
||||
- (void)addNSMenuItemToMenu:(NSMenu *)inMenu;
|
||||
- (void)addSeparator;
|
||||
|
||||
// Accessors
|
||||
- (NSMenu *)menu;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -86,10 +86,6 @@ AWT_ASSERT_APPKIT_THREAD;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)addSeparator {
|
||||
// Nothing calls this, which is good because we need a CMenuItem here.
|
||||
}
|
||||
|
||||
- (void)deleteJavaItem:(jint)index {
|
||||
|
||||
[ThreadUtilities performOnMainThread:@selector(deleteNativeJavaItem_OnAppKitThread:) on:self withObject:[NSNumber numberWithInt:index] waitUntilDone:YES];
|
||||
@ -223,21 +219,6 @@ JNF_COCOA_ENTER(env);
|
||||
JNF_COCOA_EXIT(env);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: sun_lwawt_macosx_CMenu
|
||||
* Method: nativeAddSeparator
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_lwawt_macosx_CMenu_nativeAddSeparator
|
||||
(JNIEnv *env, jobject peer, jlong menuObject)
|
||||
{
|
||||
JNF_COCOA_ENTER(env);
|
||||
// Add a separator item.
|
||||
[((CMenu *)jlong_to_ptr(menuObject))addSeparator];
|
||||
JNF_COCOA_EXIT(env);
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: sun_lwawt_macosx_CMenu
|
||||
* Method: nativeDeleteItem
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 1998, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -38,13 +38,6 @@ import java.awt.MenuItem;
|
||||
*/
|
||||
public interface MenuPeer extends MenuItemPeer {
|
||||
|
||||
/**
|
||||
* Adds a separator (e.g. a horizontal line or similar) to the menu.
|
||||
*
|
||||
* @see Menu#addSeparator()
|
||||
*/
|
||||
void addSeparator();
|
||||
|
||||
/**
|
||||
* Adds the specified menu item to the menu.
|
||||
*
|
||||
|
@ -59,6 +59,7 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
|
||||
* to its container window. Creates submenu window
|
||||
* that fills its items vector while construction
|
||||
*/
|
||||
@Override
|
||||
void setContainer(XBaseMenuWindow container) {
|
||||
super.setContainer(container);
|
||||
menuWindow = new XMenuWindow(this);
|
||||
@ -78,6 +79,7 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
|
||||
/**
|
||||
* Disposes menu window if needed
|
||||
*/
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (menuWindow != null) {
|
||||
menuWindow.dispose();
|
||||
@ -89,6 +91,7 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
|
||||
* Resets text metrics for this item, for its menu window
|
||||
* and for all descendant menu windows
|
||||
*/
|
||||
@Override
|
||||
public void setFont(Font font) {
|
||||
//TODO:We can decrease count of repaints here
|
||||
//and get rid of recursion
|
||||
@ -105,17 +108,7 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
|
||||
/*
|
||||
* From MenuPeer
|
||||
*/
|
||||
/**
|
||||
* addSeparator routines are not used
|
||||
* in peers. Shared code invokes addItem("-")
|
||||
* for adding separators
|
||||
*/
|
||||
public void addSeparator() {
|
||||
if (log.isLoggable(PlatformLogger.Level.FINER)) {
|
||||
log.finer("addSeparator is not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItem(MenuItem item) {
|
||||
XMenuWindow menuWindow = getMenuWindow();
|
||||
if (menuWindow != null) {
|
||||
@ -127,6 +120,7 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delItem(int index) {
|
||||
XMenuWindow menuWindow = getMenuWindow();
|
||||
if (menuWindow != null) {
|
||||
@ -152,12 +146,14 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
|
||||
* Overriden behaviour
|
||||
*
|
||||
************************************************/
|
||||
@Override
|
||||
boolean isSeparator() {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Fix for 6180416: Shortcut keys are displayed against Menus on XToolkit
|
||||
//Menu should always return null as shortcutText
|
||||
@Override
|
||||
String getShortcutText() {
|
||||
return null;
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
|
||||
/*
|
||||
* From MenuComponentPeer
|
||||
*/
|
||||
@Override
|
||||
public void setFont(Font f) {
|
||||
resetMapping();
|
||||
setItemsFont(f);
|
||||
@ -88,33 +89,22 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
|
||||
/*
|
||||
* From MenuItemPeer
|
||||
*/
|
||||
@Override
|
||||
public void setLabel(String label) {
|
||||
resetMapping();
|
||||
postPaintEvent();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
postPaintEvent();
|
||||
}
|
||||
|
||||
/*
|
||||
* From MenuPeer
|
||||
*/
|
||||
/**
|
||||
* addSeparator routines are not used
|
||||
* in peers. Shared code invokes addItem("-")
|
||||
* for adding separators
|
||||
*/
|
||||
public void addSeparator() {
|
||||
if (log.isLoggable(PlatformLogger.Level.FINER)) {
|
||||
log.finer("addSeparator is not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* From PopupMenuPeer
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void show(Event e) {
|
||||
target = (Component)e.target;
|
||||
@ -173,6 +163,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
|
||||
return AWTAccessor.getMenuItemAccessor().isEnabled(popupMenuTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
Vector<MenuItem> getMenuTargetItems() {
|
||||
if (popupMenuTarget == null) {
|
||||
return null;
|
||||
@ -231,6 +222,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
|
||||
* Returns height of menu window's caption.
|
||||
* Can be overriden for popup menus and tear-off menus
|
||||
*/
|
||||
@Override
|
||||
protected Dimension getCaptionSize() {
|
||||
String s = getTargetLabel();
|
||||
if (s.isEmpty()) {
|
||||
@ -258,6 +250,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
|
||||
* Can be overriden for popup menus and tear-off menus.
|
||||
* Default implementation does nothing
|
||||
*/
|
||||
@Override
|
||||
protected void paintCaption(Graphics g, Rectangle rect) {
|
||||
String s = getTargetLabel();
|
||||
if (s.isEmpty()) {
|
||||
@ -280,11 +273,13 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
|
||||
* Overriden XBaseMenuWindow functions
|
||||
*
|
||||
************************************************/
|
||||
@Override
|
||||
protected void doDispose() {
|
||||
super.doDispose();
|
||||
XToolkit.targetDisposedPeer(popupMenuTarget, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleEvent(AWTEvent event) {
|
||||
switch(event.getID()) {
|
||||
case MouseEvent.MOUSE_PRESSED:
|
||||
@ -311,6 +306,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
|
||||
* Overriden XWindow general-purpose functions
|
||||
*
|
||||
************************************************/
|
||||
@Override
|
||||
void ungrabInputImpl() {
|
||||
hide();
|
||||
}
|
||||
@ -326,6 +322,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
|
||||
* Now we override this function do disable F10 explicit
|
||||
* processing. All processing is done using KeyEvent.
|
||||
*/
|
||||
@Override
|
||||
public void handleKeyPress(XEvent xev) {
|
||||
XKeyEvent xkey = xev.get_xkey();
|
||||
if (log.isLoggable(PlatformLogger.Level.FINE)) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -30,12 +30,8 @@ import java.awt.peer.*;
|
||||
class WMenuPeer extends WMenuItemPeer implements MenuPeer {
|
||||
|
||||
// MenuPeer implementation
|
||||
|
||||
@Override
|
||||
public native void addSeparator();
|
||||
@Override
|
||||
public void addItem(MenuItem item) {
|
||||
WMenuItemPeer itemPeer = (WMenuItemPeer) WToolkit.targetToPeer(item);
|
||||
}
|
||||
@Override
|
||||
public native void delItem(int index);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -128,24 +128,6 @@ done:
|
||||
return menu;
|
||||
}
|
||||
|
||||
void AwtMenu::_AddSeparator(void *param)
|
||||
{
|
||||
if (AwtToolkit::IsMainThread()) {
|
||||
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
|
||||
|
||||
jobject self = (jobject)param;
|
||||
AwtMenu *m = NULL;
|
||||
PDATA pData;
|
||||
JNI_CHECK_PEER_GOTO(self, ret);
|
||||
m = (AwtMenu *)pData;
|
||||
m->AddSeparator();
|
||||
ret:
|
||||
env->DeleteGlobalRef(self);
|
||||
} else {
|
||||
AwtToolkit::GetInstance().InvokeFunction(AwtMenu::_AddSeparator, param);
|
||||
}
|
||||
}
|
||||
|
||||
void AwtMenu::_DelItem(void *param)
|
||||
{
|
||||
if (AwtToolkit::IsMainThread()) {
|
||||
@ -211,10 +193,6 @@ HWND AwtMenu::GetOwnerHWnd() {
|
||||
return (GetMenuContainer() == NULL) ? NULL : GetMenuContainer()->GetOwnerHWnd();
|
||||
}
|
||||
|
||||
void AwtMenu::AddSeparator() {
|
||||
VERIFY(::AppendMenu(GetHMenu(), MF_SEPARATOR, 0, 0));
|
||||
}
|
||||
|
||||
void AwtMenu::AddItem(AwtMenuItem* item)
|
||||
{
|
||||
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
|
||||
@ -223,7 +201,7 @@ void AwtMenu::AddItem(AwtMenuItem* item)
|
||||
}
|
||||
|
||||
if (item->IsSeparator()) {
|
||||
AddSeparator();
|
||||
VERIFY(::AppendMenu(GetHMenu(), MF_SEPARATOR, 0, 0));
|
||||
} else {
|
||||
/* jitem is a java.awt.MenuItem */
|
||||
jobject jitem = item->GetTarget(env);
|
||||
@ -403,24 +381,6 @@ Java_java_awt_Menu_initIDs(JNIEnv *env, jclass cls)
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
* Class: sun_awt_windows_WMenuPeer
|
||||
* Method: addSeparator
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_awt_windows_WMenuPeer_addSeparator(JNIEnv *env, jobject self)
|
||||
{
|
||||
TRY;
|
||||
|
||||
jobject selfGlobalRef = env->NewGlobalRef(self);
|
||||
|
||||
AwtToolkit::GetInstance().SyncCall(AwtMenu::_AddSeparator, selfGlobalRef);
|
||||
// selfGlobalRef is deleted in _AddSeparator
|
||||
|
||||
CATCH_BAD_ALLOC;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: sun_awt_windows_WMenuPeer
|
||||
* Method: delItem
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -64,7 +64,6 @@ public:
|
||||
|
||||
virtual AwtMenuBar* GetMenuBar();
|
||||
|
||||
void AddSeparator();
|
||||
virtual void UpdateContainerLayout();
|
||||
void UpdateLayout();
|
||||
virtual void AddItem(AwtMenuItem *item);
|
||||
@ -88,7 +87,6 @@ public:
|
||||
void MeasureItems(HDC hDC, MEASUREITEMSTRUCT& measureInfo);
|
||||
|
||||
// invoked on Toolkit thread
|
||||
static void _AddSeparator(void *param);
|
||||
static void _DelItem(void *param);
|
||||
static void _CreateMenu(void *param);
|
||||
static void _CreateSubMenu(void *param);
|
||||
|
Loading…
Reference in New Issue
Block a user