8234706: MenuPeer cleanup

Reviewed-by: prr
This commit is contained in:
Sergey Bylokhov 2019-12-26 22:38:38 +03:00
parent 8f8f43999c
commit e8fdc9408e
9 changed files with 26 additions and 114 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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); 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. // Used by ScreenMenuBar to get to the native menu for event handling.
public final long getNativeMenu() { public final long getNativeMenu() {
return executeGet(this::nativeGetNSMenu); return executeGet(this::nativeGetNSMenu);
@ -110,7 +103,6 @@ public class CMenu extends CMenuItem implements MenuPeer {
int insertionLocation); int insertionLocation);
private native long nativeCreateSubMenu(long parentMenuPtr); private native long nativeCreateSubMenu(long parentMenuPtr);
private native void nativeSetMenuTitle(long menuPtr, String title); private native void nativeSetMenuTitle(long menuPtr, String title);
private native void nativeAddSeparator(long menuPtr);
private native void nativeDeleteItem(long menuPtr, int index); private native void nativeDeleteItem(long menuPtr, int index);
// Returns a retained NSMenu object! We have to explicitly // Returns a retained NSMenu object! We have to explicitly

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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)setJavaMenuTitle:(NSString *)title;
- (void)deleteJavaItem:(jint)index; - (void)deleteJavaItem:(jint)index;
- (void)addNSMenuItemToMenu:(NSMenu *)inMenu; - (void)addNSMenuItemToMenu:(NSMenu *)inMenu;
- (void)addSeparator;
// Accessors // Accessors
- (NSMenu *)menu; - (NSMenu *)menu;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 { - (void)deleteJavaItem:(jint)index {
[ThreadUtilities performOnMainThread:@selector(deleteNativeJavaItem_OnAppKitThread:) on:self withObject:[NSNumber numberWithInt:index] waitUntilDone:YES]; [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); 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 * Class: sun_lwawt_macosx_CMenu
* Method: nativeDeleteItem * Method: nativeDeleteItem

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 { 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. * Adds the specified menu item to the menu.
* *

View File

@ -59,6 +59,7 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
* to its container window. Creates submenu window * to its container window. Creates submenu window
* that fills its items vector while construction * that fills its items vector while construction
*/ */
@Override
void setContainer(XBaseMenuWindow container) { void setContainer(XBaseMenuWindow container) {
super.setContainer(container); super.setContainer(container);
menuWindow = new XMenuWindow(this); menuWindow = new XMenuWindow(this);
@ -78,6 +79,7 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
/** /**
* Disposes menu window if needed * Disposes menu window if needed
*/ */
@Override
public void dispose() { public void dispose() {
if (menuWindow != null) { if (menuWindow != null) {
menuWindow.dispose(); menuWindow.dispose();
@ -89,6 +91,7 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
* Resets text metrics for this item, for its menu window * Resets text metrics for this item, for its menu window
* and for all descendant menu windows * and for all descendant menu windows
*/ */
@Override
public void setFont(Font font) { public void setFont(Font font) {
//TODO:We can decrease count of repaints here //TODO:We can decrease count of repaints here
//and get rid of recursion //and get rid of recursion
@ -105,17 +108,7 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
/* /*
* From MenuPeer * From MenuPeer
*/ */
/** @Override
* 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");
}
}
public void addItem(MenuItem item) { public void addItem(MenuItem item) {
XMenuWindow menuWindow = getMenuWindow(); XMenuWindow menuWindow = getMenuWindow();
if (menuWindow != null) { if (menuWindow != null) {
@ -127,6 +120,7 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
} }
} }
@Override
public void delItem(int index) { public void delItem(int index) {
XMenuWindow menuWindow = getMenuWindow(); XMenuWindow menuWindow = getMenuWindow();
if (menuWindow != null) { if (menuWindow != null) {
@ -152,12 +146,14 @@ public class XMenuPeer extends XMenuItemPeer implements MenuPeer {
* Overriden behaviour * Overriden behaviour
* *
************************************************/ ************************************************/
@Override
boolean isSeparator() { boolean isSeparator() {
return false; return false;
} }
//Fix for 6180416: Shortcut keys are displayed against Menus on XToolkit //Fix for 6180416: Shortcut keys are displayed against Menus on XToolkit
//Menu should always return null as shortcutText //Menu should always return null as shortcutText
@Override
String getShortcutText() { String getShortcutText() {
return null; return null;
} }

View File

@ -79,6 +79,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
/* /*
* From MenuComponentPeer * From MenuComponentPeer
*/ */
@Override
public void setFont(Font f) { public void setFont(Font f) {
resetMapping(); resetMapping();
setItemsFont(f); setItemsFont(f);
@ -88,33 +89,22 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
/* /*
* From MenuItemPeer * From MenuItemPeer
*/ */
@Override
public void setLabel(String label) { public void setLabel(String label) {
resetMapping(); resetMapping();
postPaintEvent(); postPaintEvent();
} }
@Override
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
postPaintEvent(); 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 * From PopupMenuPeer
*/ */
@Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void show(Event e) { public void show(Event e) {
target = (Component)e.target; target = (Component)e.target;
@ -173,6 +163,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
return AWTAccessor.getMenuItemAccessor().isEnabled(popupMenuTarget); return AWTAccessor.getMenuItemAccessor().isEnabled(popupMenuTarget);
} }
@Override
Vector<MenuItem> getMenuTargetItems() { Vector<MenuItem> getMenuTargetItems() {
if (popupMenuTarget == null) { if (popupMenuTarget == null) {
return null; return null;
@ -231,6 +222,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
* Returns height of menu window's caption. * Returns height of menu window's caption.
* Can be overriden for popup menus and tear-off menus * Can be overriden for popup menus and tear-off menus
*/ */
@Override
protected Dimension getCaptionSize() { protected Dimension getCaptionSize() {
String s = getTargetLabel(); String s = getTargetLabel();
if (s.isEmpty()) { if (s.isEmpty()) {
@ -258,6 +250,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
* Can be overriden for popup menus and tear-off menus. * Can be overriden for popup menus and tear-off menus.
* Default implementation does nothing * Default implementation does nothing
*/ */
@Override
protected void paintCaption(Graphics g, Rectangle rect) { protected void paintCaption(Graphics g, Rectangle rect) {
String s = getTargetLabel(); String s = getTargetLabel();
if (s.isEmpty()) { if (s.isEmpty()) {
@ -280,11 +273,13 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
* Overriden XBaseMenuWindow functions * Overriden XBaseMenuWindow functions
* *
************************************************/ ************************************************/
@Override
protected void doDispose() { protected void doDispose() {
super.doDispose(); super.doDispose();
XToolkit.targetDisposedPeer(popupMenuTarget, this); XToolkit.targetDisposedPeer(popupMenuTarget, this);
} }
@Override
protected void handleEvent(AWTEvent event) { protected void handleEvent(AWTEvent event) {
switch(event.getID()) { switch(event.getID()) {
case MouseEvent.MOUSE_PRESSED: case MouseEvent.MOUSE_PRESSED:
@ -311,6 +306,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
* Overriden XWindow general-purpose functions * Overriden XWindow general-purpose functions
* *
************************************************/ ************************************************/
@Override
void ungrabInputImpl() { void ungrabInputImpl() {
hide(); hide();
} }
@ -326,6 +322,7 @@ public class XPopupMenuPeer extends XMenuWindow implements PopupMenuPeer {
* Now we override this function do disable F10 explicit * Now we override this function do disable F10 explicit
* processing. All processing is done using KeyEvent. * processing. All processing is done using KeyEvent.
*/ */
@Override
public void handleKeyPress(XEvent xev) { public void handleKeyPress(XEvent xev) {
XKeyEvent xkey = xev.get_xkey(); XKeyEvent xkey = xev.get_xkey();
if (log.isLoggable(PlatformLogger.Level.FINE)) { if (log.isLoggable(PlatformLogger.Level.FINE)) {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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 { class WMenuPeer extends WMenuItemPeer implements MenuPeer {
// MenuPeer implementation // MenuPeer implementation
@Override
public native void addSeparator();
@Override @Override
public void addItem(MenuItem item) { public void addItem(MenuItem item) {
WMenuItemPeer itemPeer = (WMenuItemPeer) WToolkit.targetToPeer(item);
} }
@Override @Override
public native void delItem(int index); public native void delItem(int index);

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -128,24 +128,6 @@ done:
return menu; 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) void AwtMenu::_DelItem(void *param)
{ {
if (AwtToolkit::IsMainThread()) { if (AwtToolkit::IsMainThread()) {
@ -211,10 +193,6 @@ HWND AwtMenu::GetOwnerHWnd() {
return (GetMenuContainer() == NULL) ? NULL : GetMenuContainer()->GetOwnerHWnd(); return (GetMenuContainer() == NULL) ? NULL : GetMenuContainer()->GetOwnerHWnd();
} }
void AwtMenu::AddSeparator() {
VERIFY(::AppendMenu(GetHMenu(), MF_SEPARATOR, 0, 0));
}
void AwtMenu::AddItem(AwtMenuItem* item) void AwtMenu::AddItem(AwtMenuItem* item)
{ {
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
@ -223,7 +201,7 @@ void AwtMenu::AddItem(AwtMenuItem* item)
} }
if (item->IsSeparator()) { if (item->IsSeparator()) {
AddSeparator(); VERIFY(::AppendMenu(GetHMenu(), MF_SEPARATOR, 0, 0));
} else { } else {
/* jitem is a java.awt.MenuItem */ /* jitem is a java.awt.MenuItem */
jobject jitem = item->GetTarget(env); jobject jitem = item->GetTarget(env);
@ -403,24 +381,6 @@ Java_java_awt_Menu_initIDs(JNIEnv *env, jclass cls)
extern "C" { 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 * Class: sun_awt_windows_WMenuPeer
* Method: delItem * Method: delItem

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -64,7 +64,6 @@ public:
virtual AwtMenuBar* GetMenuBar(); virtual AwtMenuBar* GetMenuBar();
void AddSeparator();
virtual void UpdateContainerLayout(); virtual void UpdateContainerLayout();
void UpdateLayout(); void UpdateLayout();
virtual void AddItem(AwtMenuItem *item); virtual void AddItem(AwtMenuItem *item);
@ -88,7 +87,6 @@ public:
void MeasureItems(HDC hDC, MEASUREITEMSTRUCT& measureInfo); void MeasureItems(HDC hDC, MEASUREITEMSTRUCT& measureInfo);
// invoked on Toolkit thread // invoked on Toolkit thread
static void _AddSeparator(void *param);
static void _DelItem(void *param); static void _DelItem(void *param);
static void _CreateMenu(void *param); static void _CreateMenu(void *param);
static void _CreateSubMenu(void *param); static void _CreateSubMenu(void *param);