changeset 4639:546eea5433b1

7124354: [macosx] PopipMenuTest is not functional in JCK-runtime-7 interactive Reviewed-by: anthony
author leonidr
date Thu, 29 Dec 2011 17:35:30 +0300
parents abae34c163a2
children c0b98811b1fc
files src/macosx/classes/sun/lwawt/macosx/CPopupMenu.java src/macosx/native/sun/awt/AWTView.h src/macosx/native/sun/awt/AWTView.m src/macosx/native/sun/awt/CPopupMenu.m
diffstat 4 files changed, 32 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/macosx/CPopupMenu.java	Thu Dec 29 15:42:04 2011 +0300
+++ b/src/macosx/classes/sun/lwawt/macosx/CPopupMenu.java	Thu Dec 29 17:35:30 2011 +0300
@@ -37,35 +37,20 @@
 
     @Override
     protected long createModel() {
-        // Find toplevel class to get access to delegate.
-        // We need windowManagerPtr from the delegate to assign PopupMenu to.
-        Component comp = (Component) getTarget().getParent();
-        while (comp != null && comp.getParent() != null) {
-            comp = comp.getParent();
-        }
-        Window toplevel = (Window) comp;
-        if (toplevel == null) {
-             //TrayIcon???
-             toplevel = new Frame("Fake frame");
-             toplevel.addNotify();
-        }
-        LWWindowPeer lwPeer = (LWWindowPeer) toplevel.getPeer();
-        CPlatformWindow pWindow = (CPlatformWindow)lwPeer.getPlatformWindow();
-
-        if (pWindow != null) {
-            return nativeCreatePopupMenu(pWindow.getNSWindowPtr());
-        }
-
-        throw new InternalError("Platform window for PopupMenu peer shouldn't be null.");
+        return nativeCreatePopupMenu();
     }
 
-    private native long nativeCreatePopupMenu(long managerPtr);
+    private native long nativeCreatePopupMenu();
+    private native long nativeShowPopupMenu(long modelPtr, int x, int y);
 
     @Override
     public void show(Event e) {
-        // TODO: should trigger popupmenu on right mouse click too.
-        // Only CMD+leftclick triggers popup menu now.
-        // Use this method is to be invoked on the popup-trigger Java event so
-        // might be used to show the menu on the screen with right-mouse click.
+        Component origin = (Component)e.target;
+        if (origin != null) {
+            Point loc = origin.getLocationOnScreen();
+            e.x += loc.x;
+            e.y += loc.y;
+            nativeShowPopupMenu(getModel(), e.x, e.y);
+        }
     }
 }
--- a/src/macosx/native/sun/awt/AWTView.h	Thu Dec 29 15:42:04 2011 +0300
+++ b/src/macosx/native/sun/awt/AWTView.h	Thu Dec 29 17:35:30 2011 +0300
@@ -32,7 +32,6 @@
 @interface AWTView : NSView<NSTextInputClient> {
 @private
     jobject m_cPlatformView;
-    NSMenu * popupMenu;
 
     // Handler for the tracking rect needed for Enter/Exit events management.
     NSTrackingRectTag rolloverTrackingRectTag;
@@ -61,7 +60,6 @@
 - (void) deliverJavaMouseEvent: (NSEvent *) event;
 - (void) resetTrackingRect;
 - (void) deliverJavaKeyEventHelper: (NSEvent *) event;
-- (void) setContextMenu:(NSMenu *)aMenu;
 - (jobject) awtComponent:(JNIEnv *)env;
 
 - (void) setDragSource:(CDragSource *)source;
--- a/src/macosx/native/sun/awt/AWTView.m	Thu Dec 29 15:42:04 2011 +0300
+++ b/src/macosx/native/sun/awt/AWTView.m	Thu Dec 29 17:35:30 2011 +0300
@@ -377,19 +377,6 @@
     DeliverJavaKeyEvent(env, event, m_cPlatformView);
 }
 
-- (void) setContextMenu:(NSMenu *)aMenu{
-    // TODO?: release the old reference before setting new one.
-    popupMenu = aMenu;
-}
-
-// a callback invoked by Cocoa
-- (NSMenu *)menuForEvent:(NSEvent *)theEvent {
-    if (popupMenu != nil) {
-        return popupMenu;
-    }
-    return nil;
-}
-
 - (void) drawRect:(NSRect)dirtyRect {
 AWT_ASSERT_APPKIT_THREAD;
 
--- a/src/macosx/native/sun/awt/CPopupMenu.m	Thu Dec 29 15:42:04 2011 +0300
+++ b/src/macosx/native/sun/awt/CPopupMenu.m	Thu Dec 29 17:35:30 2011 +0300
@@ -31,7 +31,7 @@
 #import "CPopupMenu.h"
 #import "ThreadUtilities.h"
 #import "LWCToolkit.h"
-
+#import "GeomUtilities.h"
 
 @implementation CPopupMenu
 
@@ -56,25 +56,41 @@
    * Signature: (JII)J
    */
 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPopupMenu_nativeCreatePopupMenu
-(JNIEnv *env, jobject peer, jlong awtWindowPtr, jint x, jint y) {
+(JNIEnv *env, jobject peer) {
 
     __block CPopupMenu *aCPopupMenu = nil;
 
 JNF_COCOA_ENTER(env);
 
-    AWTWindow *awtWindow = (AWTWindow *)jlong_to_ptr(awtWindowPtr);
-
     jobject cPeerObjGlobal = JNFNewGlobalRef(env, peer);
 
     [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
         aCPopupMenu = [[CPopupMenu alloc] initWithPeer:cPeerObjGlobal];
         CFRetain(aCPopupMenu);
         [aCPopupMenu release];
-
-        [((AWTView *)[awtWindow contentView]) setContextMenu:[aCPopupMenu menu]];
     }];
 
 JNF_COCOA_EXIT(env);
 
     return ptr_to_jlong(aCPopupMenu);
 }
+
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPopupMenu_nativeShowPopupMenu
+(JNIEnv *env, jobject peer, jlong menuPtr, jint x, jint y) {
+
+    JNF_COCOA_ENTER(env);
+
+    CPopupMenu* cPopupMenu = (CPopupMenu*)jlong_to_ptr(menuPtr);
+
+    [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
+        NSPoint loc = ConvertNSScreenPoint(env, NSMakePoint(x, y));
+
+        [[cPopupMenu menu] popUpMenuPositioningItem: nil
+                                         atLocation: loc
+                                             inView: nil];
+    }];
+
+    JNF_COCOA_EXIT(env);
+
+}
+