Skip to content

Commit

Permalink
Formatting Issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahzaibIbrahim committed Aug 28, 2024
1 parent 7c89f31 commit b43e9c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,34 +348,12 @@ 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));
}
/*
Expand Down Expand Up @@ -438,22 +416,6 @@ private void setFocusOnMnemonic(TraverseEvent e, MenuItem 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 ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1140,30 +1140,26 @@ 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);
Rectangle bounds = this.getBounds();
gc.setForeground(isInactive? display.getSystemColor(SWT.COLOR_GRAY) : display.getSystemColor(SWT.COLOR_WHITE));
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);
Rectangle bounds = this.getBounds();
gc.setForeground(isInactive ? display.getSystemColor(SWT.COLOR_GRAY) : display.getSystemColor(SWT.COLOR_WHITE));
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.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) {
/*
* Bug in Windows. When a bitmap is included in the menu bar, the HDC seems to
* already include the left coordinate. The fix is to ignore this value when the
* 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 + LEFT_TEXT_MARGIN, zoom) , DPIUtil.scaleDown(struct.top + MARGIN_HEIGHT, zoom));
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();
}
if (parent.foreground != -1) OS.SetTextColor(struct.hDC, parent.foreground);
if (parent.foreground != -1)
OS.SetTextColor(struct.hDC, parent.foreground);
return null;
}

Expand Down

0 comments on commit b43e9c5

Please sign in to comment.