Skip to content

Commit 0a11834

Browse files
amartya4256HeikoKlare
authored andcommitted
Replaced Image::getBoundsInPixels with getBounds #62
This commit replaces Image::getBoundsInPixels calls with Image::getBounds since it is deprecated for win32. For all those consumers who can't access the getBounds(int zoom) method, a simple DPIUtil::scaleUp call is used in combination with the public API Image::getBounds. contributes to #62 and #127
1 parent 7d86f5c commit 0a11834

File tree

8 files changed

+13
-13
lines changed

8 files changed

+13
-13
lines changed

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ private void drag(Event dragEvent) {
504504
int offsetX = event.offsetX;
505505
hwndDrag = topControl.handle;
506506
if ((topControl.getStyle() & SWT.RIGHT_TO_LEFT) != 0) {
507-
offsetX = image.getBoundsInPixels().width - offsetX;
507+
offsetX = DPIUtil.scaleUp(image.getBounds(), zoom).width - offsetX;
508508
RECT rect = new RECT ();
509509
OS.GetClientRect (topControl.handle, rect);
510510
hwndDrag = OS.CreateWindowEx (

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ void copyAreaInPixels(Image image, int x, int y) {
487487
if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
488488
if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
489489
/* Copy the bitmap area */
490-
Rectangle rect = image.getBoundsInPixels();
490+
Rectangle rect = image.getBounds(getZoom());
491491
long memHdc = OS.CreateCompatibleDC(handle);
492492
long hOldBitmap = OS.SelectObject(memHdc, Image.win32_getHandle(image, getZoom()));
493493
OS.BitBlt(memHdc, 0, 0, rect.width, rect.height, handle, x, y, OS.SRCCOPY);

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ public Image(Device device, Image srcImage, int flag) {
228228
ImageHandle imageMetadata;
229229
if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
230230
if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
231-
Rectangle rect = srcImage.getBoundsInPixels();
231+
initialNativeZoom = srcImage.initialNativeZoom;
232+
Rectangle rect = srcImage.getBounds(getZoom());
232233
this.type = srcImage.type;
233234
if(srcImage.imageProvider != null) {
234235
this.imageProvider = srcImage.imageProvider.createCopy(this);
235236
}
236237
this.styleFlag = srcImage.styleFlag | flag;
237-
initialNativeZoom = srcImage.initialNativeZoom;
238238
long srcImageHandle = win32_getHandle(srcImage, getZoom());
239239
switch (flag) {
240240
case SWT.IMAGE_COPY: {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public Rectangle getBounds () {
126126

127127
Rectangle getBoundsInPixels () {
128128
if (image != null) {
129-
Rectangle rect = image.getBoundsInPixels ();
129+
Rectangle rect = DPIUtil.scaleUp(image.getBounds(), getZoom());
130130
return new Rectangle (getXInPixels(), getYInPixels(), rect.width, rect.height);
131131
}
132132
if (width == 0) {
@@ -220,7 +220,7 @@ public Point getSize () {
220220

221221
Point getSizeInPixels () {
222222
if (image != null) {
223-
Rectangle rect = image.getBoundsInPixels ();
223+
Rectangle rect = DPIUtil.scaleUp(image.getBounds(), getZoom());
224224
return new Point (rect.width, rect.height);
225225
}
226226
if (width == 0) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ LRESULT wmMeasureChild (long wParam, long lParam) {
12251225

12261226
int width = 0, height = 0;
12271227
if (image != null) {
1228-
Rectangle rect = image.getBoundsInPixels ();
1228+
Rectangle rect = DPIUtil.scaleUp(image.getBounds(), getZoom());
12291229
width = rect.width;
12301230
height = rect.height;
12311231
} else {
@@ -1247,7 +1247,7 @@ LRESULT wmMeasureChild (long wParam, long lParam) {
12471247
if ((lpcmi.dwStyle & OS.MNS_CHECKORBMP) == 0) {
12481248
for (MenuItem item : parent.getItems ()) {
12491249
if (item.image != null) {
1250-
Rectangle rect = item.image.getBoundsInPixels ();
1250+
Rectangle rect = DPIUtil.scaleUp(item.image.getBounds(), getZoom());
12511251
width = Math.max (width, rect.width);
12521252
}
12531253
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6966,10 +6966,10 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) {
69666966
GCData data = new GCData();
69676967
data.device = display;
69686968
GC gc = createNewGC(nmcd.hdc, data);
6969-
int y = Math.max (0, (nmcd.bottom - columns[i].image.getBoundsInPixels().height) / 2);
6969+
int y = Math.max (0, (nmcd.bottom - DPIUtil.scaleUp(columns[i].image.getBounds(), getZoom()).height) / 2);
69706970
int zoom = getZoom();
69716971
gc.drawImage (columns[i].image, DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(y, zoom));
6972-
x += columns[i].image.getBoundsInPixels().width + 12;
6972+
x += DPIUtil.scaleUp(columns[i].image.getBounds(), getZoom()).width + 12;
69736973
gc.dispose ();
69746974
}
69756975

@@ -7293,7 +7293,7 @@ LRESULT wmNotifyToolTip (NMTTCUSTOMDRAW nmcd, long lParam) {
72937293
if (pinfo.iSubItem != 0) x -= gridWidth;
72947294
Image image = item.getImage (pinfo.iSubItem);
72957295
if (image != null) {
7296-
Rectangle rect = image.getBoundsInPixels ();
7296+
Rectangle rect = DPIUtil.scaleUp(image.getBounds(), getZoom());
72977297
RECT imageRect = item.getBounds (pinfo.iItem, pinfo.iSubItem, false, true, false, false, hDC);
72987298
Point size = imageList == null ? new Point (rect.width, rect.height) : imageList.getImageSize ();
72997299
int y = imageRect.top + Math.max (0, (imageRect.bottom - imageRect.top - size.y) / 2);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ public void pack () {
413413
if (parent.sortColumn == this && parent.sortDirection != SWT.NONE) {
414414
headerWidth += Table.SORT_WIDTH;
415415
} else if (image != null) {
416-
Rectangle bounds = image.getBoundsInPixels ();
416+
Rectangle bounds = DPIUtil.scaleUp(image.getBounds(), getZoom());
417417
headerWidth += bounds.width;
418418
}
419419
long hwndHeader = OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public void pack () {
385385
headerImage = image;
386386
}
387387
if (headerImage != null) {
388-
Rectangle bounds = headerImage.getBoundsInPixels ();
388+
Rectangle bounds = DPIUtil.scaleUp(headerImage.getBounds(), getZoom());
389389
headerWidth += bounds.width;
390390
}
391391
int margin = 0;

0 commit comments

Comments
 (0)