diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java index 5cfbf65b21f..a126b6735b6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java @@ -3694,13 +3694,6 @@ public class SWT { */ public static final int COLOR_WIDGET_DISABLED_FOREGROUND = 39; - /** - * Default color light blue (value is 40). - * - * @since 3.127 - */ - public static final int COLOR_LIGHT_BLUE = 40; - /** * Draw constant indicating whether the drawing operation * should fill the background (value is 1<<0). diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java index 1b10c050b2e..984d04dca9a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java @@ -645,7 +645,6 @@ public Color getSystemColor (int id) { case SWT.COLOR_DARK_GREEN: pixel = 0x00008000; break; case SWT.COLOR_YELLOW: pixel = 0x0000FFFF; break; case SWT.COLOR_DARK_YELLOW: pixel = 0x00008080; break; - case SWT.COLOR_LIGHT_BLUE: pixel = 0x00FF9933; break; case SWT.COLOR_BLUE: pixel = 0x00E6D8AD; break; case SWT.COLOR_DARK_BLUE: pixel = 0x00800000; break; case SWT.COLOR_MAGENTA: pixel = 0x00FF00FF; break; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java index b35939ef3d9..a0a47e15fc9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java @@ -258,6 +258,20 @@ void _setVisible (boolean visible) { } } +void _showMenu (boolean visible, MenuItem menuItem) { + long hwndParent = parent.handle; + if (visible) { + Rectangle r = menuItem.getBounds(); + Point p = getDisplay().map(parent, null, new Point(r.x, r.y)); + boolean success = OS.TrackPopupMenu (handle, 0, p.x, p.y, 0, hwndParent, null); + if (!success && OS.GetMenuItemCount (handle) == 0) { + OS.SendMessage (hwndParent, OS.WM_MENUSELECT, OS.MAKEWPARAM (0, 0xFFFF), 0); + } + } else { + OS.SendMessage (hwndParent, OS.WM_CANCELMODE, 0, 0); + } +} + /** * Adds the listener to the collection of listeners who will * be notified when help events are generated for the control, @@ -334,10 +348,36 @@ void createHandle () { updateBackground (); } +private static boolean altPressed = false; + void createItem (MenuItem item, int index) { int count = OS.GetMenuItemCount (handle); if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE); display.addMenuItem (item); + + if((style & SWT.BAR) != 0 && needsMenuCallback()) { +// this.getShell().addKeyListener(new KeyAdapter() { +// @Override +// public void keyPressed(KeyEvent e) { +// int mnemonicIndex = item.text.indexOf('&'); +// if (e.keyCode == SWT.ALT) { +// altPressed = true; +// } else if (altPressed && Character.toUpperCase(e.character) == Character.toUpperCase(item.text.charAt(mnemonicIndex + 1))) { +// // Open the menu item +// setFocusOnMnemonic(e, item); +// altPressed = false; // Reset altPressed state +// } +// } +// +// @Override +// public void keyReleased(KeyEvent e) { +// if (e.keyCode == SWT.ALT) { +// altPressed = false; +// } +// } +// }); + this.getShell().addTraverseListener(e -> setFocusOnMnemonic(e, item)); + } /* * Bug in Windows. For some reason, when InsertMenuItem() * is used to insert an item without text, it is not possible @@ -382,6 +422,38 @@ void createItem (MenuItem item, int index) { redraw (); } +private void setFocusOnMnemonic(TraverseEvent e, MenuItem menuItem) { + String text = menuItem.text; + if (text != null) { + int mnemonicIndex = text.indexOf('&'); + if (e.detail == SWT.TRAVERSE_MNEMONIC) { + char pressedMnemonic = e.character; + if (Character.toUpperCase(pressedMnemonic) == Character.toUpperCase(text.charAt(mnemonicIndex + 1))) { + this.notifyListeners(SWT.Selection, new org.eclipse.swt.widgets.Event()); + if (menuItem.getMenu() != null) { + menuItem.getMenu()._showMenu(true, menuItem); + } + } + } + } +} + +private void setFocusOnMnemonic(KeyEvent e, MenuItem menuItem) { + String text = menuItem.text; + if (text != null) { + int mnemonicIndex = text.indexOf('&'); + //if (e.detail == SWT.TRAVERSE_MNEMONIC) { + char pressedMnemonic = e.character; + if (Character.toUpperCase(pressedMnemonic) == Character.toUpperCase(text.charAt(mnemonicIndex + 1))) { + this.notifyListeners(SWT.Selection, new org.eclipse.swt.widgets.Event()); + if (menuItem.getMenu() != null) { + menuItem.getMenu()._showMenu(true, menuItem); + } + } + //} + } +} + void createWidget () { checkOrientation (parent); initThemeColors (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java index acfd180a75c..c0e5c7be287 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java @@ -47,7 +47,7 @@ public class MenuItem extends Item { /* Image margin. */ final static int MARGIN_WIDTH = 1; final static int MARGIN_HEIGHT = 1; - + final static int LEFT_TEXT_MARGIN = 20; static { DPIZoomChangeRegistry.registerHandler(MenuItem::handleDPIChange, MenuItem.class); } @@ -273,9 +273,11 @@ boolean fillAccel (ACCEL accel) { accel.key = (short) key; accel.cmd = (short) id; accel.fVirt = (byte) fVirt; - if ((accelerator & SWT.ALT) != 0) accel.fVirt |= OS.FALT; - if ((accelerator & SWT.SHIFT) != 0) accel.fVirt |= OS.FSHIFT; - if ((accelerator & SWT.CONTROL) != 0) accel.fVirt |= OS.FCONTROL; + if(!parent.needsMenuCallback()) { + if ((accelerator & SWT.ALT) != 0) accel.fVirt |= OS.FALT; + if ((accelerator & SWT.SHIFT) != 0) accel.fVirt |= OS.FSHIFT; + if ((accelerator & SWT.CONTROL) != 0) accel.fVirt |= OS.FCONTROL; + } return true; } @@ -1138,16 +1140,13 @@ LRESULT wmDrawChild(long wParam, long lParam) { int flags = SWT.DRAW_MNEMONIC | SWT.DRAW_DELIMITER; boolean isInactive = ((struct.itemState & OS.ODS_INACTIVE) != 0); boolean isSelected = ((struct.itemState & OS.ODS_SELECTED) != 0); - int textMargin = 10; // left margin for x-coordinate spacing - Rectangle bounds = this.getBounds(); gc.setForeground(isInactive? display.getSystemColor(SWT.COLOR_GRAY) : display.getSystemColor(SWT.COLOR_WHITE)); - gc.setBackground(isSelected? display.getSystemColor(SWT.COLOR_LIGHT_BLUE) : parent.getBackground()); - int xMargin = DPIUtil.scaleDown(x + textMargin , zoom) + (this.image != null? this.image.getBounds().width: 0); + gc.setBackground(isSelected? display.getSystemColor(SWT.COLOR_DARK_GRAY) : parent.getBackground()); + int xMargin = DPIUtil.scaleDown(x + LEFT_TEXT_MARGIN, zoom) + (this.image != null? this.image.getBounds().width: 0); int yMargin = DPIUtil.scaleDown(struct.top + MARGIN_HEIGHT, zoom); gc.fillRectangle( DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(struct.top + MARGIN_HEIGHT, zoom), DPIUtil.scaleDown(bounds.width + (image != null ? image.getBounds().width : 0), zoom), DPIUtil.scaleDown(bounds.height, zoom)); - gc.drawText(this.text, xMargin, yMargin, flags); } if (image != null) { @@ -1157,10 +1156,10 @@ LRESULT wmDrawChild(long wParam, long lParam) { * item is in a menu bar. */ Image image = getEnabled() ? this.image : new Image(display, this.image, SWT.IMAGE_DISABLE); - - gc.drawImage(image, DPIUtil.scaleDown(x, zoom) , DPIUtil.scaleDown(struct.top + MARGIN_HEIGHT, zoom)); - if (this.image != image) + gc.drawImage(image, DPIUtil.scaleDown(x + LEFT_TEXT_MARGIN, zoom) , DPIUtil.scaleDown(struct.top + MARGIN_HEIGHT, zoom)); + if (this.image != image) { image.dispose(); + } } gc.dispose(); }