diff -r 37ccf830c76b glass-mat-lib-macosx/src/com/sun/mat/ui/GlassStatics.h --- a/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassStatics.h Wed Nov 23 11:07:52 2011 -0800 +++ b/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassStatics.h Mon Nov 28 14:22:10 2011 -0500 @@ -36,6 +36,7 @@ extern jmethodID jViewNotifyResize; extern jmethodID jViewNotifyKey; extern jmethodID jViewNotifyMouse; +extern jmethodID jViewNotifyMenu; extern jmethodID jViewNotifyScroll; extern jmethodID jViewNotifyInputMethod; extern jmethodID jViewNotifyDragEnter; diff -r 37ccf830c76b glass-mat-lib-macosx/src/com/sun/mat/ui/GlassStatics.m --- a/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassStatics.m Wed Nov 23 11:07:52 2011 -0800 +++ b/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassStatics.m Mon Nov 28 14:22:10 2011 -0500 @@ -36,6 +36,7 @@ jmethodID jViewNotifyResize = NULL; jmethodID jViewNotifyKey = NULL; jmethodID jViewNotifyMouse = NULL; +jmethodID jViewNotifyMenu = NULL; jmethodID jViewNotifyScroll = NULL; jmethodID jViewNotifyInputMethod = NULL; jmethodID jViewNotifyDragEnter = NULL; diff -r 37ccf830c76b glass-mat-lib-macosx/src/com/sun/mat/ui/GlassView.m --- a/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassView.m Wed Nov 23 11:07:52 2011 -0800 +++ b/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassView.m Mon Nov 28 14:22:10 2011 -0500 @@ -235,6 +235,11 @@ { jViewNotifyKey = (*env)->GetMethodID(env, jViewClass, "notifyKey", "(II[CI)V"); } + + if (jViewNotifyMenu == NULL) + { + jViewNotifyMenu = (*env)->GetMethodID(env, jViewClass, "notifyMenu", "(IIIIZ)V"); + } if (jViewNotifyMouse == NULL) { diff -r 37ccf830c76b glass-mat-lib-macosx/src/com/sun/mat/ui/GlassView2D.m --- a/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassView2D.m Wed Nov 23 11:07:52 2011 -0800 +++ b/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassView2D.m Mon Nov 28 14:22:10 2011 -0500 @@ -123,6 +123,13 @@ [self->delegate updateTrackingAreas]; } +- (NSMenu *)menuForEvent:(NSEvent *)theEvent +{ +// NSLog(@"menuForEvent"); + [self->delegate sendJavaMenuEvent:theEvent]; + return [super menuForEvent: theEvent]; +} + - (void)mouseEntered:(NSEvent *)theEvent { [self->delegate sendJavaMouseEvent:theEvent type:com_sun_glass_events_MouseEvent_ENTER button:com_sun_glass_events_MouseEvent_BUTTON_NONE]; @@ -156,6 +163,9 @@ - (void)rightMouseDown:(NSEvent *)theEvent { [self->delegate sendJavaMouseEvent:theEvent type:com_sun_glass_events_MouseEvent_DOWN button:com_sun_glass_events_MouseEvent_BUTTON_RIGHT]; + //Need to call the super here or menuForEvent: does not get sent (why? we don't need to call the super to get Control+Left_Click to show a menu) + return [super rightMouseDown: theEvent]; + } - (void)rightMouseDragged:(NSEvent *)theEvent diff -r 37ccf830c76b glass-mat-lib-macosx/src/com/sun/mat/ui/GlassView3D.m --- a/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassView3D.m Wed Nov 23 11:07:52 2011 -0800 +++ b/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassView3D.m Mon Nov 28 14:22:10 2011 -0500 @@ -185,6 +185,13 @@ [self->delegate updateTrackingAreas]; } +- (NSMenu *)menuForEvent:(NSEvent *)theEvent +{ +// NSLog("menuForEvent"); + [self->delegate sendJavaMenuEvent:theEvent]; + return [super menuForEvent: theEvent]; +} + - (void)mouseEntered:(NSEvent *)theEvent { MOUSELOG("mouseEntered"); @@ -225,6 +232,8 @@ { MOUSELOG("rightMouseDown"); [self->delegate sendJavaMouseEvent:theEvent type:com_sun_glass_events_MouseEvent_DOWN button:com_sun_glass_events_MouseEvent_BUTTON_RIGHT]; + //Need to call the super here or menuForEvent: does not get sent (why? we don't need to call the super to get Control+Left_Click to show a menu) + return [super rightMouseDown: theEvent]; } - (void)rightMouseDragged:(NSEvent *)theEvent diff -r 37ccf830c76b glass-mat-lib-macosx/src/com/sun/mat/ui/GlassViewDelegate.h --- a/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassViewDelegate.h Wed Nov 23 11:07:52 2011 -0800 +++ b/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassViewDelegate.h Mon Nov 28 14:22:10 2011 -0500 @@ -40,6 +40,7 @@ - (void)drawRect:(NSRect)dirtyRect; - (void)sendJavaMouseEvent:(NSEvent *)theEvent type:(int)type button:(int)button; +- (void)sendJavaMenuEvent:(NSEvent *)theEvent; - (void)sendJavaKeyEvent:(NSEvent *)event isDown:(BOOL)isDown; - (void)sendJavaModifierKeyEvent:(NSEvent *)theEvent; diff -r 37ccf830c76b glass-mat-lib-macosx/src/com/sun/mat/ui/GlassViewDelegate.m --- a/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassViewDelegate.m Wed Nov 23 11:07:52 2011 -0800 +++ b/glass-mat-lib-macosx/src/com/sun/mat/ui/GlassViewDelegate.m Mon Nov 28 14:22:10 2011 -0500 @@ -176,6 +176,26 @@ //NSLog(@"END drawRect"); } +- (void)sendJavaMenuEvent:(NSEvent *)theEvent +{ +// NSLog(@"sendJavaMenuEvent"); + NSWindow * nswindow = [nsView window]; + if (nswindow && [nswindow isKindOfClass: [GlassWindow class]]) { + GlassWindow *window = (GlassWindow*)nswindow; + if (!window->isEnabled) { + return; + } + } + NSPoint viewPoint = [nsView convertPoint:[theEvent locationInWindow] fromView:nil]; // convert from window coordinates to view coordinates + CGPoint basePoint = CGEventGetLocation([theEvent CGEvent]); + + GET_MAIN_JENV; + jboolean isKeyboardTrigger = JNI_FALSE; + (*env)->CallVoidMethod(env, self->jView, jViewNotifyMenu, + (jint)viewPoint.x, (jint)viewPoint.y, (jint)basePoint.x, (jint)basePoint.y, isKeyboardTrigger); + GLASS_CHECK_EXCEPTION(env); +} + - (void)sendJavaMouseEvent:(NSEvent *)theEvent type:(int)type button:(int)button { NSWindow * nswindow = [nsView window]; diff -r 37ccf830c76b glass-mat-lib-windows/src/GlassView.cpp --- a/glass-mat-lib-windows/src/GlassView.cpp Wed Nov 23 11:07:52 2011 -0800 +++ b/glass-mat-lib-windows/src/GlassView.cpp Mon Nov 28 14:22:10 2011 -0500 @@ -130,6 +130,9 @@ javaIDs.View.notifyMouse = env->GetMethodID(cls, "notifyMouse", "(IIIIIIIZ)V"); ASSERT(javaIDs.View.notifyMouse); + javaIDs.View.notifyMenu = env->GetMethodID(cls, "notifyMenu", "(IIIIZ)V"); + ASSERT(javaIDs.View.notifyMenu); + javaIDs.View.notifyScroll = env->GetMethodID(cls, "notifyScroll", "(IIIIDDIIIIIDD)V"); ASSERT(javaIDs.View.notifyScroll); diff -r 37ccf830c76b glass-mat-lib-windows/src/GlassWindow.cpp --- a/glass-mat-lib-windows/src/GlassWindow.cpp Wed Nov 23 11:07:52 2011 -0800 +++ b/glass-mat-lib-windows/src/GlassWindow.cpp Mon Nov 28 14:22:10 2011 -0500 @@ -327,6 +327,9 @@ case WM_PAINT: HandleViewPaintEvent(GetHWND(), msg, wParam, lParam); break; + case WM_CONTEXTMENU: + HandleViewMenuEvent(GetHWND(), msg, wParam, lParam); + break; case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: @@ -351,7 +354,8 @@ return 0; } if (HandleViewMouseEvent(GetHWND(), msg, wParam, lParam)) { - return 0; + // Run the default window proc to get WM_CONTEXTMENU + break; } } else { HandleFocusDisabledEvent(); diff -r 37ccf830c76b glass-mat-lib-windows/src/Utils.h --- a/glass-mat-lib-windows/src/Utils.h Wed Nov 23 11:07:52 2011 -0800 +++ b/glass-mat-lib-windows/src/Utils.h Mon Nov 28 14:22:10 2011 -0500 @@ -389,6 +389,7 @@ jmethodID notifyRepaint; jmethodID notifyKey; jmethodID notifyMouse; + jmethodID notifyMenu; jmethodID notifyScroll; jmethodID notifyInputMethod; jmethodID notifyInputMethodCandidatePosRequest; diff -r 37ccf830c76b glass-mat-lib-windows/src/ViewContainer.cpp --- a/glass-mat-lib-windows/src/ViewContainer.cpp Wed Nov 23 11:07:52 2011 -0800 +++ b/glass-mat-lib-windows/src/ViewContainer.cpp Mon Nov 28 14:22:10 2011 -0500 @@ -141,6 +141,24 @@ NotifyViewSize(hwnd); } + +void ViewContainer::HandleViewMenuEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (!GetGlassView()) { + return; + } + if ((HWND)wParam != hwnd) return; + jboolean isKeyboardTrigger = lParam == (LPARAM)-1; + if (isKeyboardTrigger) lParam = ::GetMessagePos (); + POINT pt; + int absX = pt.x = GET_X_LPARAM(lParam); + int absY = pt.y = GET_Y_LPARAM(lParam); + ::ScreenToClient (hwnd, &pt); + JNIEnv* env = GetEnv(); + env->CallVoidMethod(GetView(), javaIDs.View.notifyMenu, pt.x, pt.y, absX, absY, isKeyboardTrigger); + CheckAndClearException(env); +} + void ViewContainer::HandleViewKeyEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (!GetGlassView()) { diff -r 37ccf830c76b glass-mat-lib-windows/src/ViewContainer.h --- a/glass-mat-lib-windows/src/ViewContainer.h Wed Nov 23 11:07:52 2011 -0800 +++ b/glass-mat-lib-windows/src/ViewContainer.h Mon Nov 28 14:22:10 2011 -0500 @@ -28,6 +28,7 @@ void GetCandidatePos(RECT* curPos); protected: + void HandleViewMenuEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); void HandleViewInputLangChange(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); void HandleViewPaintEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); void HandleViewSizeEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); diff -r 37ccf830c76b glass-mat/src/com/sun/glass/ui/View.java --- a/glass-mat/src/com/sun/glass/ui/View.java Wed Nov 23 11:07:52 2011 -0800 +++ b/glass-mat/src/com/sun/glass/ui/View.java Mon Nov 28 14:22:10 2011 -0500 @@ -18,7 +18,9 @@ public void handleKeyEvent(View view, long time, int action, int keyCode, char[] keyChars, int modifiers) { } - + public void handleMenuEvent(View view, int x, int y, int xAbs, + int yAbs, boolean isKeyboardTrigger) { + } public void handleMouseEvent(View view, long time, int type, int button, int x, int y, int xAbs, int yAbs, int clickCount, int modifiers, boolean isPopupTrigger) @@ -289,7 +291,12 @@ } } - + private void handleMenuEvent(int x, int y, int xAbs, int yAbs, boolean isKeyboardTrigger) { + if (this.eventHandler != null) { + this.eventHandler.handleMenuEvent(this, x, y, xAbs, yAbs, isKeyboardTrigger); + } + } + private void handleInputMethodEvent(long time, String text, int[] clauseBoundary, int[] attrBoundary, byte[] attrValue, int commitCount, int cursorPos) { @@ -508,6 +515,13 @@ } + // ------------ MENU EVENT HANDLING ----------------- +// protected void notifyMenu(int type, int button, int x, int y, int xAbs, int yAbs, int keyCode, char[] keyChars, int modifiers) { + protected void notifyMenu(int x, int y, int xAbs, int yAbs, boolean isKeyboardTrigger) { + System.out.println("menuEvent"); + handleMenuEvent(x, y, xAbs, yAbs, isKeyboardTrigger); + } + // ------------ MOUSE EVENTS HANDLING ----------------- // Synchronized on the Main thread of the underlying native system