Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public void testWidgetZoomShouldChangeOnZoomLevelChange() {
button.setText("Widget Test");
button.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_CYAN));
shell.open();
assertEquals("The initial zoom is wrong", zoom, button.getZoom()); // pre-condition
assertEquals("The initial zoom is wrong", zoom, button.getAutoscalingZoom()); // pre-condition
DPITestUtil.changeDPIZoom(shell, scaledZoom);
assertEquals("The Zoom Level should be updated for button on zoom change event on its shell", scaledZoom,
button.getZoom());
button.getAutoscalingZoom());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.swt.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.cocoa.*;

/**
Expand Down Expand Up @@ -1992,6 +1993,21 @@ public void setModified (boolean modified) {
window.setDocumentEdited (modified);
}

/**
* Returns the zoom of the shell.
* <p>
* Hint: The returned value is the zoom of the shell as originally considered by
* the OS and not an adjusted zoom value as considered by SWT autoscaling capabilities.
* </p>
*
* @return the zoom for this shell
*
* @since 3.133
*/
public int getZoom() {
return DPIUtil.getNativeDeviceZoom();
}

/**
* Sets the shape of the shell to the region specified
* by the argument. When the argument is null, the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2786,6 +2786,21 @@ public void setModified (boolean modified) {
this.modified = modified;
}

/**
* Returns the zoom of the shell.
* <p>
* Hint: The returned value is the zoom of the shell as originally considered by
* the OS and not an adjusted zoom value as considered by SWT autoscaling capabilities.
* </p>
*
* @return the zoom for this shell
*
* @since 3.133
*/
public int getZoom() {
return DPIUtil.getNativeDeviceZoom();
}

/**
* Sets the shape of the shell to the region specified
* by the argument. When the argument is null, the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void _setImage (Image image) {
if (imageList != null) imageList.dispose ();
imageList = null;
if (image != null) {
imageList = new ImageList (style & SWT.RIGHT_TO_LEFT, getZoom());
imageList = new ImageList (style & SWT.RIGHT_TO_LEFT, getAutoscalingZoom());
if (OS.IsWindowEnabled (handle)) {
imageList.add (image);
} else {
Expand All @@ -147,7 +147,7 @@ void _setImage (Image image) {
imageList.add (disabledImage);
}
BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST ();
buttonImageList.himl = imageList.getHandle(getZoom());
buttonImageList.himl = imageList.getHandle(getAutoscalingZoom());
int oldBits = OS.GetWindowLong (handle, OS.GWL_STYLE), newBits = oldBits;
newBits &= ~(OS.BS_LEFT | OS.BS_CENTER | OS.BS_RIGHT);
if ((style & SWT.LEFT) != 0) newBits |= OS.BS_LEFT;
Expand Down Expand Up @@ -188,7 +188,7 @@ void _setText (String text) {
if ((style & SWT.RIGHT) != 0) newBits |= OS.BS_RIGHT;
if (imageList != null) {
BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST ();
buttonImageList.himl = imageList.getHandle(getZoom());
buttonImageList.himl = imageList.getHandle(getAutoscalingZoom());
if (text.length () == 0) {
if ((style & SWT.LEFT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT;
if ((style & SWT.CENTER) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_CENTER;
Expand Down Expand Up @@ -295,7 +295,7 @@ int computeLeftMargin () {
if ((style & (SWT.PUSH | SWT.TOGGLE)) == 0) return MARGIN;
int margin = 0;
if (image != null && text.length () != 0) {
Rectangle bounds = Win32DPIUtils.scaleBounds(image.getBounds(), this.getZoom(), 100);
Rectangle bounds = Win32DPIUtils.scaleBounds(image.getBounds(), this.getAutoscalingZoom(), 100);
margin += bounds.width + MARGIN * 2;
long oldFont = 0;
long hDC = OS.GetDC (handle);
Expand Down Expand Up @@ -359,13 +359,13 @@ Point computeSizeInPixels (Point hintInPoints, int zoom, boolean changed) {
boolean hasImage = image != null, hasText = true;
if (hasImage) {
if (image != null) {
Rectangle rect = Win32DPIUtils.scaleBounds(image.getBounds(), this.getZoom(), 100);
Rectangle rect = Win32DPIUtils.scaleBounds(image.getBounds(), this.getAutoscalingZoom(), 100);
width = rect.width;
if (hasText && text.length () != 0) {
width += DPIUtil.pointToPixel(MARGIN * 2, getZoom());;
width += DPIUtil.pointToPixel(MARGIN * 2, getAutoscalingZoom());;
}
height = rect.height;
extra = DPIUtil.pointToPixel(MARGIN * 2, getZoom());;
extra = DPIUtil.pointToPixel(MARGIN * 2, getAutoscalingZoom());;
}
}
if (hasText) {
Expand All @@ -379,7 +379,7 @@ Point computeSizeInPixels (Point hintInPoints, int zoom, boolean changed) {
if (length == 0) {
height = Math.max (height, lptm.tmHeight);
} else {
extra = Math.max (DPIUtil.pointToPixel(MARGIN * 2, getZoom()), lptm.tmAveCharWidth);
extra = Math.max (DPIUtil.pointToPixel(MARGIN * 2, getAutoscalingZoom()), lptm.tmAveCharWidth);
char [] buffer = text.toCharArray ();
RECT rect = new RECT ();
int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE;
Expand Down Expand Up @@ -780,7 +780,7 @@ public void setAlignment (int alignment) {
if ((style & SWT.RIGHT) != 0) newBits |= OS.BS_RIGHT;
if (imageList != null) {
BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST ();
buttonImageList.himl = imageList.getHandle(getZoom());
buttonImageList.himl = imageList.getHandle(getAutoscalingZoom());
if (text.length () == 0) {
if ((style & SWT.LEFT) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_LEFT;
if ((style & SWT.CENTER) != 0) buttonImageList.uAlign = OS.BUTTON_IMAGELIST_ALIGN_CENTER;
Expand Down Expand Up @@ -1035,15 +1035,15 @@ void updateImageList () {
BUTTON_IMAGELIST buttonImageList = new BUTTON_IMAGELIST ();
OS.SendMessage (handle, OS.BCM_GETIMAGELIST, 0, buttonImageList);
if (imageList != null) imageList.dispose ();
imageList = new ImageList (style & SWT.RIGHT_TO_LEFT, getZoom());
imageList = new ImageList (style & SWT.RIGHT_TO_LEFT, getAutoscalingZoom());
if (OS.IsWindowEnabled (handle)) {
imageList.add (image);
} else {
if (disabledImage != null) disabledImage.dispose ();
disabledImage = new Image (display, image, SWT.IMAGE_DISABLE);
imageList.add (disabledImage);
}
buttonImageList.himl = imageList.getHandle(getZoom());
buttonImageList.himl = imageList.getHandle(getAutoscalingZoom());
OS.SendMessage (handle, OS.BCM_SETIMAGELIST, 0, buttonImageList);
/*
* Bug in Windows. Under certain cirumstances yet to be
Expand Down Expand Up @@ -1392,13 +1392,13 @@ LRESULT wmNotifyChild (NMHDR hdr, long wParam, long lParam) {
GC gc = createNewGC(nmcd.hdc, data);

int margin = computeLeftMargin();
Rectangle imageBounds = Win32DPIUtils.scaleBounds(image.getBounds(), this.getZoom(), 100);
Rectangle imageBounds = Win32DPIUtils.scaleBounds(image.getBounds(), this.getAutoscalingZoom(), 100);
int imageWidth = imageBounds.width;
left += (imageWidth + (isRadioOrCheck() ? 2 * MARGIN : MARGIN)); // for SWT.RIGHT_TO_LEFT right and left are inverted

int x = margin + (isRadioOrCheck() ? radioOrCheckTextPadding : 3);
int y = Math.max (0, (nmcd.bottom - imageBounds.height) / 2);
int zoom = getZoom();
int zoom = getAutoscalingZoom();
gc.drawImage (image, DPIUtil.pixelToPoint(x, zoom), DPIUtil.pixelToPoint(y, zoom));
gc.dispose ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Canvas (Composite parent, int style) {
* @since 3.2
*/
public void drawBackground (GC gc, int x, int y, int width, int height) {
int zoom = getZoom();
int zoom = getAutoscalingZoom();
Rectangle rectangle = Win32DPIUtils.pointToPixel(new Rectangle(x, y, width, height), zoom);
drawBackgroundInPixels(gc, rectangle.x, rectangle.y, rectangle.width, rectangle.height, 0, 0);
}
Expand Down Expand Up @@ -197,7 +197,7 @@ void reskinChildren (int flags) {
*/
public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) {
checkWidget ();
int zoom = getZoom();
int zoom = getAutoscalingZoom();
destX = DPIUtil.pointToPixel(destX, zoom);
destY = DPIUtil.pointToPixel(destY, zoom);
Rectangle rectangle = Win32DPIUtils.pointToPixel(new Rectangle(x, y, width, height), zoom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ long defaultFont () {
*/
public Rectangle getBounds () {
checkWidget();
return Win32DPIUtils.pixelToPoint(getBoundsInPixels(), getZoom());
return Win32DPIUtils.pixelToPoint(getBoundsInPixels(), getAutoscalingZoom());
}

Rectangle getBoundsInPixels () {
if (image != null) {
Rectangle rect = Win32DPIUtils.pointToPixel(image.getBounds(), getZoom());
Rectangle rect = Win32DPIUtils.pointToPixel(image.getBounds(), getAutoscalingZoom());
return new Rectangle (getXInPixels(), getYInPixels(), rect.width, rect.height);
}
if (width == 0) {
Expand Down Expand Up @@ -223,12 +223,12 @@ public Canvas getParent () {
*/
public Point getSize () {
checkWidget();
return Win32DPIUtils.pixelToPointAsSize(getSizeInPixels(), getZoom());
return Win32DPIUtils.pixelToPointAsSize(getSizeInPixels(), getAutoscalingZoom());
}

Point getSizeInPixels () {
if (image != null) {
Rectangle rect = Win32DPIUtils.pointToPixel(image.getBounds(), getZoom());
Rectangle rect = Win32DPIUtils.pointToPixel(image.getBounds(), getAutoscalingZoom());
return new Point (rect.width, rect.height);
}
if (width == 0) {
Expand All @@ -241,19 +241,19 @@ Point getSizeInPixels () {
}

private int getWidthInPixels() {
return DPIUtil.pointToPixel(width, getZoom());
return DPIUtil.pointToPixel(width, getAutoscalingZoom());
}

private int getHeightInPixels() {
return DPIUtil.pointToPixel(height, getZoom());
return DPIUtil.pointToPixel(height, getAutoscalingZoom());
}

private int getXInPixels() {
return DPIUtil.pointToPixel(x, getZoom());
return DPIUtil.pointToPixel(x, getAutoscalingZoom());
}

private int getYInPixels() {
return DPIUtil.pointToPixel(y, getZoom());
return DPIUtil.pointToPixel(y, getAutoscalingZoom());
}

/**
Expand Down Expand Up @@ -373,7 +373,7 @@ void resize () {
resized = false;
long hwnd = parent.handle;
OS.DestroyCaret ();
long hBitmap = image != null ? Image.win32_getHandle(image, getZoom()) : 0;
long hBitmap = image != null ? Image.win32_getHandle(image, getAutoscalingZoom()) : 0;
int widthInPixels = this.getWidthInPixels();
if (image == null && widthInPixels == 0) {
OptionalInt systemCaretWidthInPixelsForCurrentMonitor = getSystemCaretWidthInPixelsForCurrentMonitor();
Expand Down Expand Up @@ -452,7 +452,7 @@ public void setBounds (Rectangle rect) {
void setFocus () {
long hwnd = parent.handle;
long hBitmap = 0;
if (image != null) hBitmap = Image.win32_getHandle(image, getZoom());
if (image != null) hBitmap = Image.win32_getHandle(image, getAutoscalingZoom());
int widthInPixels = this.getWidthInPixels();
if (image == null && widthInPixels == 0) {
OptionalInt systemCaretWidthInPixelsForCurrentMonitor = getSystemCaretWidthInPixelsForCurrentMonitor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ boolean dragDetect (long hwnd, int x, int y, boolean filter, boolean [] detect,
*/
public Point getCaretLocation () {
checkWidget ();
return Win32DPIUtils.pixelToPointAsLocation(getCaretLocationInPixels(), getZoom());
return Win32DPIUtils.pixelToPointAsLocation(getCaretLocationInPixels(), getAutoscalingZoom());
}

Point getCaretLocationInPixels () {
Expand Down Expand Up @@ -1079,7 +1079,7 @@ public int getItemCount () {
*/
public int getItemHeight () {
checkWidget ();
return DPIUtil.pixelToPoint(getItemHeightInPixels(), getZoom());
return DPIUtil.pixelToPoint(getItemHeightInPixels(), getAutoscalingZoom());
}

int getItemHeightInPixels () {
Expand Down Expand Up @@ -1345,7 +1345,7 @@ public String getText () {
*/
public int getTextHeight () {
checkWidget ();
return DPIUtil.pixelToPoint(getTextHeightInPixels(), getZoom());
return DPIUtil.pixelToPoint(getTextHeightInPixels(), getAutoscalingZoom());
}

int getTextHeightInPixels () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Point computeSizeInPixels (Point hintInPoints, int zoom, boolean changed) {
* Since computeTrim can be overridden by subclasses, we cannot
* call computeTrimInPixels directly.
*/
Rectangle trim = Win32DPIUtils.pointToPixelWithSufficientlyLargeSize(computeTrim (0, 0, sizeInPoints.x, sizeInPoints.y), getZoom());
Rectangle trim = Win32DPIUtils.pointToPixelWithSufficientlyLargeSize(computeTrim (0, 0, sizeInPoints.x, sizeInPoints.y), getAutoscalingZoom());
return new Point (trim.width, trim.height);
}

Expand Down Expand Up @@ -349,7 +349,7 @@ int applyThemeBackground () {
*/
public void drawBackground (GC gc, int x, int y, int width, int height, int offsetX, int offsetY) {
checkWidget ();
int zoom = getZoom();
int zoom = getAutoscalingZoom();
Rectangle rectangle = Win32DPIUtils.pointToPixel(new Rectangle(x, y, width, height), zoom);
offsetX = DPIUtil.pointToPixel(offsetX, zoom);
offsetY = DPIUtil.pointToPixel(offsetY, zoom);
Expand Down Expand Up @@ -1532,7 +1532,7 @@ LRESULT WM_PAINT (long wParam, long lParam) {

Event event = new Event ();
event.gc = gc;
event.setBounds(Win32DPIUtils.pixelToPoint(new Rectangle.OfFloat(ps.left, ps.top, width, height), getZoom()));
event.setBounds(Win32DPIUtils.pixelToPoint(new Rectangle.OfFloat(ps.left, ps.top, width, height), getAutoscalingZoom()));
sendEvent (SWT.Paint, event);
if (data.focusDrawn && !isDisposed ()) updateUIState ();
gc.dispose ();
Expand Down Expand Up @@ -1603,7 +1603,7 @@ LRESULT WM_PAINT (long wParam, long lParam) {
Event event = new Event ();
event.gc = gc;
RECT rect = null;
int zoom = getZoom();
int zoom = getAutoscalingZoom();
if ((style & SWT.NO_MERGE_PAINTS) != 0 && OS.GetRgnBox (sysRgn, rect = new RECT ()) == OS.COMPLEXREGION) {
int nBytes = OS.GetRegionData (sysRgn, 0, null);
int [] lpRgnData = new int [nBytes / 4];
Expand Down Expand Up @@ -1700,7 +1700,7 @@ LRESULT WM_PRINTCLIENT (long wParam, long lParam) {
GC gc = createNewGC(wParam, data);
Event event = new Event ();
event.gc = gc;
event.setBounds(Win32DPIUtils.pixelToPoint(new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top), getZoom()));
event.setBounds(Win32DPIUtils.pixelToPoint(new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top), getAutoscalingZoom()));
sendEvent (SWT.Paint, event);
event.gc = null;
gc.dispose ();
Expand Down
Loading
Loading