changeset 57778:00eb693aee42

8234706: MenuPeer cleanup Reviewed-by: prr
author serb
date Thu, 26 Dec 2019 22:38:38 +0300
parents 6dbd8a434f44
children ed2db42aa14c
files src/java.desktop/macosx/classes/sun/lwawt/macosx/CMenu.java src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.h src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.m src/java.desktop/share/classes/java/awt/peer/MenuPeer.java src/java.desktop/unix/classes/sun/awt/X11/XMenuPeer.java src/java.desktop/unix/classes/sun/awt/X11/XPopupMenuPeer.java src/java.desktop/windows/classes/sun/awt/windows/WMenuPeer.java src/java.desktop/windows/native/libawt/windows/awt_Menu.cpp src/java.desktop/windows/native/libawt/windows/awt_Menu.h
diffstat 9 files changed, 26 insertions(+), 114 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CMenu.java	Wed Dec 25 14:17:57 2019 +0300
+++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CMenu.java	Thu Dec 26 22:38:38 2019 +0300
@@ -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 @@
         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 @@
                                          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
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.h	Wed Dec 25 14:17:57 2019 +0300
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.h	Thu Dec 26 22:38:38 2019 +0300
@@ -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 @@
 - (void)setJavaMenuTitle:(NSString *)title;
 - (void)deleteJavaItem:(jint)index;
 - (void)addNSMenuItemToMenu:(NSMenu *)inMenu;
-- (void)addSeparator;
 
 // Accessors
 - (NSMenu *)menu;
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.m	Wed Dec 25 14:17:57 2019 +0300
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CMenu.m	Thu Dec 26 22:38:38 2019 +0300
@@ -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 @@
     }
 }
 
-- (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];
@@ -225,21 +221,6 @@
 
 /*
  * 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
  * Signature: (JI)V
  */
--- a/src/java.desktop/share/classes/java/awt/peer/MenuPeer.java	Wed Dec 25 14:17:57 2019 +0300
+++ b/src/java.desktop/share/classes/java/awt/peer/MenuPeer.java	Thu Dec 26 22:38:38 2019 +0300
@@ -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
@@ -39,13 +39,6 @@
 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.
      *
      * @param item the menu item to add
--- a/src/java.desktop/unix/classes/sun/awt/X11/XMenuPeer.java	Wed Dec 25 14:17:57 2019 +0300
+++ b/src/java.desktop/unix/classes/sun/awt/X11/XMenuPeer.java	Thu Dec 26 22:38:38 2019 +0300
@@ -59,6 +59,7 @@
      * 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 @@
     /**
      * Disposes menu window if needed
      */
+    @Override
     public void dispose() {
         if (menuWindow != null) {
             menuWindow.dispose();
@@ -89,6 +91,7 @@
      * 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 @@
     /*
      * 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 @@
         }
     }
 
+    @Override
     public void delItem(int index) {
         XMenuWindow menuWindow = getMenuWindow();
         if (menuWindow != null) {
@@ -152,12 +146,14 @@
      * 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;
     }
--- a/src/java.desktop/unix/classes/sun/awt/X11/XPopupMenuPeer.java	Wed Dec 25 14:17:57 2019 +0300
+++ b/src/java.desktop/unix/classes/sun/awt/X11/XPopupMenuPeer.java	Thu Dec 26 22:38:38 2019 +0300
@@ -79,6 +79,7 @@
     /*
      * From MenuComponentPeer
      */
+    @Override
     public void setFont(Font f) {
         resetMapping();
         setItemsFont(f);
@@ -88,33 +89,22 @@
     /*
      * 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 @@
         return AWTAccessor.getMenuItemAccessor().isEnabled(popupMenuTarget);
     }
 
+    @Override
     Vector<MenuItem> getMenuTargetItems() {
         if (popupMenuTarget == null) {
             return null;
@@ -231,6 +222,7 @@
      * 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 @@
      * 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 @@
      * 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 @@
      * Overriden XWindow general-purpose functions
      *
      ************************************************/
+    @Override
     void ungrabInputImpl() {
         hide();
     }
@@ -326,6 +322,7 @@
      * 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)) {
--- a/src/java.desktop/windows/classes/sun/awt/windows/WMenuPeer.java	Wed Dec 25 14:17:57 2019 +0300
+++ b/src/java.desktop/windows/classes/sun/awt/windows/WMenuPeer.java	Thu Dec 26 22:38:38 2019 +0300
@@ -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 @@
 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);
--- a/src/java.desktop/windows/native/libawt/windows/awt_Menu.cpp	Wed Dec 25 14:17:57 2019 +0300
+++ b/src/java.desktop/windows/native/libawt/windows/awt_Menu.cpp	Thu Dec 26 22:38:38 2019 +0300
@@ -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 @@
     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 @@
     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 @@
     }
 
     if (item->IsSeparator()) {
-        AddSeparator();
+        VERIFY(::AppendMenu(GetHMenu(), MF_SEPARATOR, 0, 0));
     } else {
         /* jitem is a java.awt.MenuItem */
         jobject jitem = item->GetTarget(env);
@@ -405,24 +383,6 @@
 
 /*
  * 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
  * Signature: (I)V
  */
--- a/src/java.desktop/windows/native/libawt/windows/awt_Menu.h	Wed Dec 25 14:17:57 2019 +0300
+++ b/src/java.desktop/windows/native/libawt/windows/awt_Menu.h	Thu Dec 26 22:38:38 2019 +0300
@@ -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 @@
 
     virtual AwtMenuBar* GetMenuBar();
 
-    void AddSeparator();
     virtual void UpdateContainerLayout();
     void UpdateLayout();
     virtual void AddItem(AwtMenuItem *item);
@@ -88,7 +87,6 @@
     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);