Skip to content

Commit fa9970d

Browse files
committed
MenuItem Image Scaling with DPI aware metrics #62
This commit contributes to scaling of the MenuItem::hBitmap with the DPI Aware System Metrics for the size of the SM_CYMENUCHECK since the expected size of the Context menu images can differ from the size specific to the zoom level of the monitor. contributes to #62 and #127
1 parent 2bcfb45 commit fa9970d

File tree

2 files changed

+12
-2
lines changed
  • bundles/org.eclipse.swt
    • Eclipse SWT PI/win32/org/eclipse/swt/internal/win32
    • Eclipse SWT/win32/org/eclipse/swt/widgets

2 files changed

+12
-2
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,7 @@ public class OS extends C {
12481248
public static final int SM_CYFOCUSBORDER = 84;
12491249
public static final int SM_CYHSCROLL = 0x3;
12501250
public static final int SM_CYMENU = 0xf;
1251+
public static final int SM_CYMENUCHECK = 72;
12511252
public static final int SM_CXMINTRACK = 34;
12521253
public static final int SM_CYMINTRACK = 35;
12531254
public static final int SM_CXMAXTRACK = 59;

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,7 @@ public void setImage (Image image) {
781781
info.hbmpItem = OS.HBMMENU_CALLBACK;
782782
} else {
783783
if (OS.IsAppThemed ()) {
784-
if (hBitmap != 0) OS.DeleteObject (hBitmap);
785-
info.hbmpItem = hBitmap = image != null ? Display.create32bitDIB (image, getZoom()) : 0;
784+
info.hbmpItem = hBitmap = getMenuItemIconBitmapHandle(image);
786785
} else {
787786
info.hbmpItem = image != null ? OS.HBMMENU_CALLBACK : 0;
788787
}
@@ -792,6 +791,16 @@ public void setImage (Image image) {
792791
parent.redraw ();
793792
}
794793

794+
private long getMenuItemIconBitmapHandle(Image image) {
795+
if(image == null) {
796+
return 0;
797+
}
798+
if (hBitmap != 0) OS.DeleteObject (hBitmap);
799+
int desiredSize = getSystemMetrics(OS.SM_CYMENUCHECK);
800+
int zoom = (int) (((double) desiredSize / image.getBounds().height) * 100);
801+
return Display.create32bitDIB (image, zoom);
802+
}
803+
795804
/**
796805
* Sets the receiver's pull down menu to the argument.
797806
* Only <code>CASCADE</code> menu items can have a

0 commit comments

Comments
 (0)