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 @@ -322,8 +322,11 @@ else if ((style & SWT.RIGHT) != 0) {
return margin;
}

@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
@Override
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
checkWidget ();
int zoom = getZoom();
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
int width = 0, height = 0, border = getBorderWidthInPixels ();
if ((style & SWT.ARROW) != 0) {
if ((style & (SWT.UP | SWT.DOWN)) != 0) {
Expand All @@ -336,8 +339,8 @@ else if ((style & SWT.RIGHT) != 0) {
} else {
if ((style & SWT.COMMAND) != 0) {
SIZE size = new SIZE ();
if (wHint != SWT.DEFAULT) {
size.cx = wHint;
if (hintInPoints.x != SWT.DEFAULT) {
size.cx = hintInPixels.x;
OS.SendMessage (handle, OS.BCM_GETIDEALSIZE, 0, size);
width = size.cx;
height = size.cy;
Expand Down Expand Up @@ -381,9 +384,9 @@ else if ((style & SWT.RIGHT) != 0) {
char [] buffer = text.toCharArray ();
RECT rect = new RECT ();
int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE;
if ((style & SWT.WRAP) != 0 && wHint != SWT.DEFAULT) {
if ((style & SWT.WRAP) != 0 && hintInPoints.x != SWT.DEFAULT) {
flags = OS.DT_CALCRECT | OS.DT_WORDBREAK;
rect.right = wHint - width - 2 * border;
rect.right = hintInPixels.x - width - 2 * border;
if (isRadioOrCheck()) {
rect.right -= checkWidth + 3;
} else {
Expand Down Expand Up @@ -412,8 +415,8 @@ else if ((style & SWT.RIGHT) != 0) {
}
}
}
if (wHint != SWT.DEFAULT) width = wHint;
if (hHint != SWT.DEFAULT) height = hHint;
if (hintInPoints.x != SWT.DEFAULT) width = hintInPixels.x;
if (hintInPoints.y != SWT.DEFAULT) height = hintInPixels.y;
width += border * 2;
height += border * 2;
return new Point (width, height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,13 @@ public void clearSelection () {
OS.SendMessage (handle, OS.CB_SETEDITSEL, 0, -1);
}

@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
@Override
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
checkWidget ();
int zoom = getZoom();
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
int width = 0, height = 0;
if (wHint == SWT.DEFAULT) {
if (hintInPoints.x == SWT.DEFAULT) {
long newFont, oldFont = 0;
long hDC = OS.GetDC (handle);
newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
Expand Down Expand Up @@ -627,7 +630,7 @@ public void clearSelection () {
if (newFont != 0) OS.SelectObject (hDC, oldFont);
OS.ReleaseDC (handle, hDC);
}
if (hHint == SWT.DEFAULT) {
if (hintInPoints.y == SWT.DEFAULT) {
if ((style & SWT.SIMPLE) != 0) {
int count = (int)OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
int itemHeight = (int)OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, 0, 0);
Expand All @@ -636,8 +639,8 @@ public void clearSelection () {
}
if (width == 0) width = DEFAULT_WIDTH;
if (height == 0) height = DEFAULT_HEIGHT;
if (wHint != SWT.DEFAULT) width = wHint;
if (hHint != SWT.DEFAULT) height = hHint;
if (hintInPoints.x != SWT.DEFAULT) width = hintInPixels.x;
if (hintInPoints.y != SWT.DEFAULT) height = hintInPixels.y;
if ((style & SWT.READ_ONLY) != 0) {
width += 8;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,31 +207,29 @@ protected void checkSubclass () {
}

@Override
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
display.runSkin ();
Point size;
Point sizeInPoints;
if (layout != null) {
if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
if (hintInPoints.x == SWT.DEFAULT || hintInPoints.y == SWT.DEFAULT) {
changed |= (state & LAYOUT_CHANGED) != 0;
state &= ~LAYOUT_CHANGED;
int zoom = getZoom();
size = Win32DPIUtils.pointToPixelAsSize(layout.computeSize (this, DPIUtil.pixelToPoint(wHint, zoom), DPIUtil.pixelToPoint(hHint, zoom), changed), zoom);
sizeInPoints = layout.computeSize (this, hintInPoints.x, hintInPoints.y, changed);
} else {
size = new Point (wHint, hHint);
sizeInPoints = hintInPoints;
}
} else {
size = minimumSize (wHint, hHint, changed);
if (size.x == 0) size.x = DEFAULT_WIDTH;
if (size.y == 0) size.y = DEFAULT_HEIGHT;
sizeInPoints = minimumSize (hintInPoints, changed);
if (sizeInPoints.x == 0) sizeInPoints.x = DEFAULT_WIDTH;
if (sizeInPoints.y == 0) sizeInPoints.y = DEFAULT_HEIGHT;
}
if (wHint != SWT.DEFAULT) size.x = wHint;
if (hHint != SWT.DEFAULT) size.y = hHint;
if (hintInPoints.x != SWT.DEFAULT) sizeInPoints.x = hintInPoints.x;
if (hintInPoints.y != SWT.DEFAULT) sizeInPoints.y = hintInPoints.y;
/*
* Since computeTrim can be overridden by subclasses, we cannot
* call computeTrimInPixels directly.
*/
int zoom = getZoom();
Rectangle trim = Win32DPIUtils.pointToPixel(computeTrim (0, 0, DPIUtil.pixelToPoint(size.x, zoom), DPIUtil.pixelToPoint(size.y, zoom)), zoom);
Rectangle trim = Win32DPIUtils.pointToPixel(computeTrim (0, 0, sizeInPoints.x, sizeInPoints.y), getZoom());
return new Point (trim.width, trim.height);
}

Expand Down Expand Up @@ -869,16 +867,15 @@ void markLayout (boolean changed, boolean all) {
}
}

Point minimumSize (int wHint, int hHint, boolean changed) {
Point minimumSize (Point hintInPoints, boolean changed) {
/*
* Since getClientArea can be overridden by subclasses, we cannot
* call getClientAreaInPixels directly.
*/
int zoom = getZoom();
Rectangle clientArea = Win32DPIUtils.pointToPixel(getClientArea (), zoom);
Rectangle clientArea = getClientArea ();
int width = 0, height = 0;
for (Control element : _getChildren ()) {
Rectangle rect = Win32DPIUtils.pointToPixel(element.getBounds (), zoom);
Rectangle rect = element.getBounds ();
width = Math.max (width, rect.x - clientArea.x + rect.width);
height = Math.max (height, rect.y - clientArea.y + rect.height);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,18 +619,18 @@ public Point computeSize (int wHint, int hHint) {
public Point computeSize (int wHint, int hHint, boolean changed){
checkWidget ();
int zoom = getZoom();
wHint = (wHint != SWT.DEFAULT ? DPIUtil.pointToPixel(wHint, zoom) : wHint);
hHint = (hHint != SWT.DEFAULT ? DPIUtil.pointToPixel(hHint, zoom) : hHint);
//We should never return a size that is to small, RoundingMode.UP ensures we at worst case report
//a size that is a bit too large by half a point
return Win32DPIUtils.pixelToPointAsConservativeSize(computeSizeInPixels(wHint, hHint, changed), zoom);
return Win32DPIUtils.pixelToPointAsConservativeSize(computeSizeInPixels(new Point.OfFloat(wHint, hHint, RoundingMode.UP), changed), zoom);
}

Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
int width = DEFAULT_WIDTH;
int height = DEFAULT_HEIGHT;
if (wHint != SWT.DEFAULT) width = wHint;
if (hHint != SWT.DEFAULT) height = hHint;
int zoom = getZoom();
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
if (hintInPoints.x != SWT.DEFAULT) width = hintInPixels.x;
if (hintInPoints.y != SWT.DEFAULT) height = hintInPixels.y;
int border = getBorderWidthInPixels ();
width += border * 2;
height += border * 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,14 @@ protected void checkSubclass () {
if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
}

@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
@Override
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
int zoom = getZoom();
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
int width = 0, height = 0;
int border = getBorderWidthInPixels ();
int newWidth = wHint == SWT.DEFAULT ? 0x3FFF : wHint + (border * 2);
int newHeight = hHint == SWT.DEFAULT ? 0x3FFF : hHint + (border * 2);
int newWidth = hintInPoints.x == SWT.DEFAULT ? 0x3FFF : hintInPixels.x + (border * 2);
int newHeight = hintInPoints.y == SWT.DEFAULT ? 0x3FFF : hintInPixels.y + (border * 2);
int count = (int)OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
if (count != 0) {
ignoreResize = true;
Expand Down Expand Up @@ -189,8 +192,8 @@ protected void checkSubclass () {
width = height;
height = tmp;
}
if (wHint != SWT.DEFAULT) width = wHint;
if (hHint != SWT.DEFAULT) height = hHint;
if (hintInPoints.x != SWT.DEFAULT) width = hintInPixels.x;
if (hintInPoints.y != SWT.DEFAULT) height = hintInPixels.y;
height += border * 2;
width += border * 2;
return new Point (width, height);
Expand Down Expand Up @@ -1225,7 +1228,7 @@ void handleDPIChange(Event event, float scalingFactor) {
item.setControl(control);
}

Point preferredControlSize = item.getControl().computeSizeInPixels(SWT.DEFAULT, SWT.DEFAULT, true);
Point preferredControlSize = item.getControl().computeSizeInPixels(new Point(SWT.DEFAULT, SWT.DEFAULT), true);
int controlWidth = preferredControlSize.x;
int controlHeight = preferredControlSize.y;
if (((style & SWT.VERTICAL) != 0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,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.win32.*;

/**
Expand Down Expand Up @@ -217,10 +218,13 @@ protected void checkSubclass () {
if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
}

@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
@Override
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
checkWidget ();
int zoom = getZoom();
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
int width = 0, height = 0;
if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
if (hintInPoints.x == SWT.DEFAULT || hintInPoints.y == SWT.DEFAULT) {
if ((style & SWT.CALENDAR) != 0) {
RECT rect = new RECT ();
OS.SendMessage(handle, OS.MCM_GETMINREQRECT, 0, rect);
Expand All @@ -244,8 +248,8 @@ protected void checkSubclass () {
}
if (width == 0) width = DEFAULT_WIDTH;
if (height == 0) height = DEFAULT_HEIGHT;
if (wHint != SWT.DEFAULT) width = wHint;
if (hHint != SWT.DEFAULT) height = hHint;
if (hintInPoints.x != SWT.DEFAULT) width = hintInPixels.x;
if (hintInPoints.y != SWT.DEFAULT) height = hintInPixels.y;
int border = getBorderWidthInPixels ();
width += border * 2;
height += border * 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,12 @@ static int checkStyle (int style) {
return style | SWT.NO_BACKGROUND;
}

@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
@Override
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
int zoom = getZoom();
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
int height = 0, width = 0;
if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
if (hintInPoints.x == SWT.DEFAULT || hintInPoints.y == SWT.DEFAULT) {
if (itemCount > 0) {
long hDC = OS.GetDC (handle);
long hTheme = 0;
Expand Down Expand Up @@ -168,8 +171,8 @@ static int checkStyle (int style) {
}
if (width == 0) width = DEFAULT_WIDTH;
if (height == 0) height = DEFAULT_HEIGHT;
if (wHint != SWT.DEFAULT) width = wHint;
if (hHint != SWT.DEFAULT) height = hHint;
if (hintInPoints.x != SWT.DEFAULT) width = hintInPixels.x;
if (hintInPoints.y != SWT.DEFAULT) height = hintInPixels.y;
Rectangle trim = computeTrimInPixels (0, 0, width, height);
return new Point (trim.width, trim.height);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ protected void checkSubclass () {
if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
}

@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
@Override
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
checkWidget ();
Point size = super.computeSizeInPixels (wHint, hHint, changed);
Point size = super.computeSizeInPixels (hintInPoints, changed);
int length = text.length ();
if (length != 0) {
String string = fixText (false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ static int checkStyle (int style) {
return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
}

@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
@Override
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
checkWidget ();
int zoom = getZoom();
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
int width = 0, height = 0, border = getBorderWidthInPixels ();
if ((style & SWT.SEPARATOR) != 0) {
int lineWidth = getSystemMetrics (OS.SM_CXBORDER);
Expand All @@ -140,8 +143,8 @@ static int checkStyle (int style) {
} else {
width = lineWidth * 2; height = DEFAULT_HEIGHT;
}
if (wHint != SWT.DEFAULT) width = wHint;
if (hHint != SWT.DEFAULT) height = hHint;
if (hintInPoints.x != SWT.DEFAULT) width = hintInPixels.x;
if (hintInPoints.y != SWT.DEFAULT) height = hintInPixels.y;
width += border * 2; height += border * 2;
return new Point (width, height);
}
Expand All @@ -161,9 +164,9 @@ static int checkStyle (int style) {
} else {
RECT rect = new RECT ();
int flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_EXPANDTABS;
if ((style & SWT.WRAP) != 0 && wHint != SWT.DEFAULT) {
if ((style & SWT.WRAP) != 0 && hintInPoints.x != SWT.DEFAULT) {
flags |= OS.DT_WORDBREAK;
rect.right = Math.max (0, wHint - width);
rect.right = Math.max (0, hintInPixels.x - width);
}
char [] buffer = new char [length + 1];
OS.GetWindowText (handle, buffer, length + 1);
Expand All @@ -174,8 +177,8 @@ static int checkStyle (int style) {
if (newFont != 0) OS.SelectObject (hDC, oldFont);
OS.ReleaseDC (handle, hDC);
}
if (wHint != SWT.DEFAULT) width = wHint;
if (hHint != SWT.DEFAULT) height = hHint;
if (hintInPoints.x != SWT.DEFAULT) width = hintInPixels.x;
if (hintInPoints.y != SWT.DEFAULT) height = hintInPixels.y;
width += border * 2;
height += border * 2;
return new Point (width, height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ long callWindowProc (long hwnd, int msg, long wParam, long lParam) {
}

@Override
Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
checkWidget ();
int zoom = getZoom();
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
int width, height;
/*
* When the text is empty, LM_GETIDEALSIZE returns zero width and height,
Expand All @@ -178,13 +180,13 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
OS.ReleaseDC (handle, hDC);
} else {
SIZE size = new SIZE ();
int maxWidth = (wHint == SWT.DEFAULT) ? 0x7fffffff : wHint;
int maxWidth = (hintInPoints.x == SWT.DEFAULT) ? 0x7fffffff : hintInPixels.x;
OS.SendMessage (handle, OS.LM_GETIDEALSIZE, maxWidth, size);
width = size.cx;
height = size.cy;
}
if (wHint != SWT.DEFAULT) width = wHint;
if (hHint != SWT.DEFAULT) height = hHint;
if (hintInPoints.x != SWT.DEFAULT) width = hintInPixels.x;
if (hintInPoints.y != SWT.DEFAULT) height = hintInPixels.y;
int border = getBorderWidthInPixels ();
width += border * 2;
height += border * 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,13 @@ static int checkStyle (int style) {
return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);
}

@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
@Override
Point computeSizeInPixels (Point hintInPoints, boolean changed) {
checkWidget ();
int zoom = getZoom();
Point hintInPixels = Win32DPIUtils.pointToPixelAsSize(hintInPoints, zoom);
int width = 0, height = 0;
if (wHint == SWT.DEFAULT) {
if (hintInPoints.x == SWT.DEFAULT) {
if ((style & SWT.H_SCROLL) != 0) {
width = (int)OS.SendMessage (handle, OS.LB_GETHORIZONTALEXTENT, 0, 0);
width -= INSET;
Expand Down Expand Up @@ -246,15 +249,15 @@ static int checkStyle (int style) {
OS.ReleaseDC (handle, hDC);
}
}
if (hHint == SWT.DEFAULT) {
if (hintInPoints.y == SWT.DEFAULT) {
int count = (int)OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0);
int itemHeight = (int)OS.SendMessage (handle, OS.LB_GETITEMHEIGHT, 0, 0);
height = count * itemHeight;
}
if (width == 0) width = DEFAULT_WIDTH;
if (height == 0) height = DEFAULT_HEIGHT;
if (wHint != SWT.DEFAULT) width = wHint;
if (hHint != SWT.DEFAULT) height = hHint;
if (hintInPoints.x != SWT.DEFAULT) width = hintInPixels.x;
if (hintInPoints.y != SWT.DEFAULT) height = hintInPixels.y;
int border = getBorderWidthInPixels ();
width += border * 2 + INSET;
height += border * 2;
Expand Down
Loading
Loading