Mercurial > hg > release > icedtea7-forest-2.6 > jdk
changeset 8999:0c8e1772278f
8158993: Service Menu services
Reviewed-by: prr, mschoene
author | ssadetsky |
---|---|
date | Tue, 18 Oct 2016 05:00:54 +0100 |
parents | e12f4af19806 |
children | 0b55ddd61757 |
files | src/windows/classes/sun/awt/windows/WMenuItemPeer.java src/windows/classes/sun/awt/windows/WMenuPeer.java src/windows/classes/sun/awt/windows/WObjectPeer.java src/windows/classes/sun/awt/windows/WPopupMenuPeer.java src/windows/native/sun/windows/awt_Frame.cpp src/windows/native/sun/windows/awt_MenuBar.cpp src/windows/native/sun/windows/awt_MenuBar.h |
diffstat | 7 files changed, 62 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/windows/classes/sun/awt/windows/WMenuItemPeer.java Tue Jul 05 19:03:39 2016 +0300 +++ b/src/windows/classes/sun/awt/windows/WMenuItemPeer.java Tue Oct 18 05:00:54 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2016, 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 @@ -107,6 +107,7 @@ this.target = target; this.parent = (WMenuPeer) WToolkit.targetToPeer(target.getParent()); this.isCheckbox = isCheckbox; + parent.addChildPeer(this); create(parent); // fix for 5088782: check if menu object is created successfully checkMenuCreation();
--- a/src/windows/classes/sun/awt/windows/WMenuPeer.java Tue Jul 05 19:03:39 2016 +0300 +++ b/src/windows/classes/sun/awt/windows/WMenuPeer.java Tue Oct 18 05:00:54 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2016, 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 @@ -48,10 +48,12 @@ if (parent instanceof MenuBar) { WMenuBarPeer mbPeer = (WMenuBarPeer) WToolkit.targetToPeer(parent); this.parent = mbPeer; + mbPeer.addChildPeer(this); createMenu(mbPeer); } else if (parent instanceof Menu) { this.parent = (WMenuPeer) WToolkit.targetToPeer(parent); + this.parent.addChildPeer(this); createSubMenu(this.parent); } else {
--- a/src/windows/classes/sun/awt/windows/WObjectPeer.java Tue Jul 05 19:03:39 2016 +0300 +++ b/src/windows/classes/sun/awt/windows/WObjectPeer.java Tue Oct 18 05:00:54 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2006, 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 @@ -24,6 +24,9 @@ */ package sun.awt.windows; +import java.util.Map; +import java.util.WeakHashMap; + abstract class WObjectPeer { static { @@ -45,6 +48,8 @@ // used to synchronize the state of this peer private final Object stateLock = new Object(); + private volatile Map<WObjectPeer, WObjectPeer> childPeers; + public static WObjectPeer getPeerForTarget(Object t) { WObjectPeer peer = (WObjectPeer) WToolkit.targetToPeer(t); return peer; @@ -77,6 +82,9 @@ } if (call_disposeImpl) { + if (childPeers != null) { + disposeChildPeers(); + } disposeImpl(); } } @@ -88,4 +96,33 @@ * Initialize JNI field and method IDs */ private static native void initIDs(); + + // if a child peer existence depends on this peer, add it to this collection + final void addChildPeer(WObjectPeer child) { + synchronized (getStateLock()) { + if (childPeers == null) { + childPeers = new WeakHashMap<>(); + } + if (isDisposed()) { + throw new IllegalStateException("Parent peer is disposed"); + } + childPeers.put(child, this); + } + } + + // called to dispose dependent child peers + private void disposeChildPeers() { + synchronized (getStateLock()) { + for (WObjectPeer child : childPeers.keySet()) { + if (child != null) { + try { + child.dispose(); + } + catch (Exception e) { + // ignored + } + } + } + } + } }
--- a/src/windows/classes/sun/awt/windows/WPopupMenuPeer.java Tue Jul 05 19:03:39 2016 +0300 +++ b/src/windows/classes/sun/awt/windows/WPopupMenuPeer.java Tue Oct 18 05:00:54 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2016, 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 @@ -58,6 +58,7 @@ parent = WToolkit.getNativeContainer((Component)parent); parentPeer = (WComponentPeer) WToolkit.targetToPeer(parent); } + parentPeer.addChildPeer(this); createMenu(parentPeer); // fix for 5088782: check if menu object is created successfully checkMenuCreation();
--- a/src/windows/native/sun/windows/awt_Frame.cpp Tue Jul 05 19:03:39 2016 +0300 +++ b/src/windows/native/sun/windows/awt_Frame.cpp Tue Oct 18 05:00:54 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2016, 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 @@ -1022,11 +1022,19 @@ void AwtFrame::SetMenuBar(AwtMenuBar* mb) { + if (menuBar) { + menuBar->SetFrame(NULL); + } menuBar = mb; if (mb == NULL) { // Remove existing menu bar, if any. ::SetMenu(GetHWnd(), NULL); } else { + AwtFrame* oldFrame = menuBar->GetFrame(); + if (oldFrame && oldFrame != this) { + oldFrame->SetMenuBar(NULL); + } + menuBar->SetFrame(this); if (menuBar->GetHMenu() != NULL) { ::SetMenu(GetHWnd(), menuBar->GetHMenu()); }
--- a/src/windows/native/sun/windows/awt_MenuBar.cpp Tue Jul 05 19:03:39 2016 +0300 +++ b/src/windows/native/sun/windows/awt_MenuBar.cpp Tue Oct 18 05:00:54 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2016, 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 @@ -58,6 +58,9 @@ void AwtMenuBar::Dispose() { + if (m_frame != NULL && m_frame->GetMenuBar() == this) { + m_frame->SetMenuBar(NULL); + } m_frame = NULL; AwtMenu::Dispose();
--- a/src/windows/native/sun/windows/awt_MenuBar.h Tue Jul 05 19:03:39 2016 +0300 +++ b/src/windows/native/sun/windows/awt_MenuBar.h Tue Oct 18 05:00:54 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2016, 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 @@ -63,6 +63,9 @@ virtual AwtMenuBar* GetMenuBar() { return this; } INLINE AwtFrame* GetFrame() { return m_frame; } + INLINE void SetFrame(AwtFrame* frame) { + m_frame = frame; + } virtual HWND GetOwnerHWnd();