[PATCH] 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar
Sergey Bylokhov
Sergey.Bylokhov at oracle.com
Tue Sep 4 07:11:31 PDT 2012
Hi, Marco.
After the changes, shortcuts in the simple awt menu(not swing) continue
to work?
Thanks.
04.09.2012 17:42, Marco Dinacci wrote:
> Hello,
>
> The following patch, based on changeset 0b236cc20500 (jdk7u8-b05 tag),
> fixes http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7160951
>
> The patch checks whether the NSEvent received in the NSMenuItem
> callback coincides with the NSMenuItem accelerator. If it does, it
> doesn't call the Java callback.
>
> # HG changeset patch
> # User Marco Dinacci <marco.dinacci at gmail.com>
> # Date 1346764262 -3600
> # Node ID c451e0ad537c9856ccc7be5488360070ba657142
> # Parent 57d81e01a61fb8be46ef792dce63b0aa2a88992d
> Fix bug #7160951
>
> diff --git a/src/macosx/native/sun/awt/CMenuItem.m
> b/src/macosx/native/sun/awt/CMenuItem.m
> --- a/src/macosx/native/sun/awt/CMenuItem.m
> +++ b/src/macosx/native/sun/awt/CMenuItem.m
> @@ -82,22 +82,36 @@ JNF_COCOA_ENTER(env);
> } else {
> static JNF_CLASS_CACHE(jc_CMenuItem, "sun/lwawt/macosx/CMenuItem");
> static JNF_MEMBER_CACHE(jm_handleAction, jc_CMenuItem,
> "handleAction", "(JI)V"); // AWT_THREADING Safe (event)
>
> NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent];
> NSUInteger modifiers = [currEvent modifierFlags];
> jint javaModifiers = 0;
>
> - if ((modifiers & NSCommandKeyMask) != 0) javaModifiers |=
> java_awt_Event_META_MASK;
> - if ((modifiers & NSShiftKeyMask) != 0) javaModifiers |=
> java_awt_Event_SHIFT_MASK;
> - if ((modifiers & NSControlKeyMask) != 0) javaModifiers |=
> java_awt_Event_CTRL_MASK;
> - if ((modifiers & NSAlternateKeyMask) != 0) javaModifiers |=
> java_awt_Event_ALT_MASK;
> + NSEventType type = [currEvent type];
> + if (type == NSKeyDown) {
> + NSString *menuKey = [sender keyEquivalent];
> + NSString *eventKey = [currEvent characters];
> +
> + if (![menuKey isEqualToString:eventKey]) {
> + // Only send the event if the NSEvent characters do not
> + // coincides with the NSMenuItem keyEquivalent.
>
> - JNFCallVoidMethod(env, fPeer, jm_handleAction,
> UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event)
> + if ((modifiers & NSCommandKeyMask) != 0)
> javaModifiers |= java_awt_Event_META_MASK;
> + if ((modifiers & NSShiftKeyMask) != 0)
> javaModifiers |= java_awt_Event_SHIFT_MASK;
> + if ((modifiers & NSControlKeyMask) != 0)
> javaModifiers |= java_awt_Event_CTRL_MASK;
> + if ((modifiers & NSAlternateKeyMask) != 0)
> javaModifiers |= java_awt_Event_ALT_MASK;
> +
> + JNFCallVoidMethod(env, fPeer, jm_handleAction,
> UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event)
> + }
> + } else {
> + JNFCallVoidMethod(env, fPeer, jm_handleAction,
> UTC(currEvent), javaModifiers); // AWT_THREADING Safe (event)
> + }
> +
> }
> JNF_COCOA_EXIT(env);
> }
>
> - (void) setJavaLabel:(NSString *)theLabel shortcut:(NSString
> *)theKeyEquivalent modifierMask:(jint)modifiers {
> AWT_ASSERT_NOT_APPKIT_THREAD;
>
> NSUInteger modifierMask = 0;
> exporting patch:
> <fdopen>
>
>
> Best,
> Marco
`
--
Best regards, Sergey.
More information about the macosx-port-dev
mailing list