Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSravan Kumar Lakkimsetti2016-01-29 19:05:21 +0000
committerSravan Kumar Lakkimsetti2016-01-29 19:05:21 +0000
commit9f0d27a5a961888318ff49408bd593a70f320eaa (patch)
tree8eda5df1d316c38794005f72cc2ef8b0fd9653cd
parentca687380ff330e57e8ac427873f374c56e594a35 (diff)
downloadeclipse.platform.swt-9f0d27a5a961888318ff49408bd593a70f320eaa.tar.gz
eclipse.platform.swt-9f0d27a5a961888318ff49408bd593a70f320eaa.tar.xz
eclipse.platform.swt-9f0d27a5a961888318ff49408bd593a70f320eaa.zip
Bug 399786 updated link Label and control classes
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java84
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java26
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java4
6 files changed, 72 insertions, 54 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java
index 7ce60357f6..79aa20a5a9 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java
@@ -146,7 +146,7 @@ static ImageData getImageData (Image image, int zoom) {
public static float getScalingFactor (Device device) {
float scalingFactor = 1;
if (getAutoScale ()) {
- scalingFactor = (device.getScalingFactor ()/100f);
+ scalingFactor = (device.getDeviceZoom ()/100f);
}
return scalingFactor;
}
@@ -155,7 +155,7 @@ public static boolean getAutoScale () {
return autoScale;
}
-public static void setAutoScale(boolean autoScale) {
+public static void setAutoScale (boolean autoScale) {
DPIUtil.autoScale = autoScale;
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java
index 4367d0c305..a775f639bf 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java
@@ -119,8 +119,8 @@ public abstract boolean isDisposed();
/**
* @since 3.105
*/
-public int getDeviceZoom() {
- return DPIUtil.mapDPIToZoom(device._getDPIx());
+public int getDeviceZoom () {
+ return device.getDeviceZoom ();
}
} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
index babb34b6f9..fd879e5de1 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
@@ -219,13 +219,11 @@ Image(Device device) {
*/
public Image(Device device, int width, int height) {
super(device);
- if (this.getEnableAutoScaling ()) {
- currentDeviceZoom = getDeviceZoom();
- float scaleFactor = ((float)currentDeviceZoom) / 100;
- width = (int)(width * scaleFactor);
- height = (int)(height * scaleFactor);
- autoScaled = true;
- }
+ float scaleFactor = DPIUtil.getScalingFactor(getDevice());
+ currentDeviceZoom = (int) (scaleFactor *100);
+ width = (int)(width * scaleFactor);
+ height = (int)(height * scaleFactor);
+ autoScaled = true;
init(width, height);
init();
}
@@ -551,14 +549,11 @@ public Image(Device device, Image srcImage, int flag) {
public Image(Device device, Rectangle bounds) {
super(device);
if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (getEnableAutoScaling ()) {
- currentDeviceZoom = getDeviceZoom();
- Rectangle bounds1 = DPIUtil.scale(bounds, currentDeviceZoom, 100);
- init(bounds1.width, bounds1.height);
- autoScaled = true;
- } else {
- init(bounds.width, bounds.height);
- }
+ float scaleFactor = DPIUtil.getScalingFactor(getDevice());
+ currentDeviceZoom = (int) (scaleFactor *100);
+ Rectangle bounds1 = DPIUtil.scale(bounds, currentDeviceZoom, 100);
+ init(bounds1.width, bounds1.height);
+ autoScaled = true;
init();
}
@@ -588,13 +583,12 @@ public Image(Device device, Rectangle bounds) {
public Image(Device device, ImageData data) {
super(device);
if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (this.getEnableAutoScaling()) {
- currentDeviceZoom = getDeviceZoom();
- if (!data.scaled) {
- data = DPIUtil.autoScaleImageData(data, currentDeviceZoom, 100);
- }
- autoScaled = true;
+ float scaleFactor = DPIUtil.getScalingFactor(getDevice());
+ currentDeviceZoom = (int) (scaleFactor *100);
+ if (!data.scaled) {
+ data = DPIUtil.autoScaleImageData(data, currentDeviceZoom, 100);
}
+ autoScaled = true;
init(data);
init();
}
@@ -636,16 +630,15 @@ public Image(Device device, ImageData source, ImageData mask) {
if (source.width != mask.width || source.height != mask.height) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
- if (getEnableAutoScaling()){
- currentDeviceZoom = getDeviceZoom();
- if (!source.scaled) {
- source = DPIUtil.autoScaleImageData(source, currentDeviceZoom, 100);
- }
- if (!mask.scaled) {
- mask = DPIUtil.autoScaleImageData(mask, currentDeviceZoom, 100);
- }
- autoScaled = true;
+ float scaleFactor = DPIUtil.getScalingFactor(getDevice());
+ currentDeviceZoom = (int) (scaleFactor *100);
+ if (!source.scaled) {
+ source = DPIUtil.autoScaleImageData(source, currentDeviceZoom, 100);
}
+ if (!mask.scaled) {
+ mask = DPIUtil.autoScaleImageData(mask, currentDeviceZoom, 100);
+ }
+ autoScaled = true;
mask = ImageData.convertMask (mask);
ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data);
image.maskPad = mask.scanlinePad;
@@ -710,11 +703,10 @@ public Image(Device device, ImageData source, ImageData mask) {
public Image(Device device, InputStream stream) {
super(device);
ImageData data = new ImageData(stream);
- if (this.getEnableAutoScaling()) {
- currentDeviceZoom = getDeviceZoom();
- data = DPIUtil.autoScaleImageData(data, currentDeviceZoom, 100);
- autoScaled = true;
- }
+ float scaleFactor = DPIUtil.getScalingFactor(getDevice());
+ currentDeviceZoom = (int) (scaleFactor *100);
+ data = DPIUtil.autoScaleImageData(data, currentDeviceZoom, 100);
+ autoScaled = true;
init(data);
init();
}
@@ -756,11 +748,11 @@ public Image(Device device, String filename) {
if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
ImageData data = new ImageData(filename);
- if (this.getEnableAutoScaling()) {
- currentDeviceZoom = getDeviceZoom();
- data = DPIUtil.autoScaleImageData(data, currentDeviceZoom, 100);
- autoScaled = true;
- }
+ float scaleFactor = DPIUtil.getScalingFactor(getDevice());
+ currentDeviceZoom = (int) (scaleFactor *100);
+ data = DPIUtil.autoScaleImageData(data, currentDeviceZoom, 100);
+ autoScaled = true;
+
init(data);
// initNative(filename);
@@ -805,7 +797,8 @@ public Image(Device device, String filename) {
public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
super(device);
this.imageFileNameProvider = imageFileNameProvider;
- currentDeviceZoom = getDeviceZoom ();
+ float scaleFactor = DPIUtil.getScalingFactor(getDevice());
+ currentDeviceZoom = (int) (scaleFactor *100);
boolean[] found = new boolean[1];
String filename = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, currentDeviceZoom, found);
if (found[0]) {
@@ -853,7 +846,8 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
public Image(Device device, ImageDataProvider imageDataProvider) {
super(device);
this.imageDataProvider = imageDataProvider;
- currentDeviceZoom = getDeviceZoom ();
+ float scaleFactor = DPIUtil.getScalingFactor(getDevice());
+ currentDeviceZoom = (int) (scaleFactor *100);
boolean[] found = new boolean[1];
ImageData data = DPIUtil.validateAndGetImageDataAtZoom(imageDataProvider, currentDeviceZoom, found);
if (found[0]) {
@@ -1342,9 +1336,9 @@ public Color getBackground() {
public Rectangle getBounds() {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Rectangle bounds = _getBounds();
- if (getEnableAutoScaling()) {
- bounds = DPIUtil.scale(bounds, 100, currentDeviceZoom);
- }
+ float scaleFactor = DPIUtil.getScalingFactor(getDevice());
+ currentDeviceZoom = (int) (scaleFactor *100);
+ bounds = DPIUtil.scale(bounds, 100, currentDeviceZoom);
return bounds;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
index e6b9b6f9be..ffe9a92247 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
@@ -465,6 +465,10 @@ void printWidget (GC gc, long /*int*/ drawable, int depth, int x, int y) {
state &= ~OBSCURED;
long /*int*/ topHandle = topHandle ();
long /*int*/ window = gtk_widget_get_window (topHandle);
+ float scaleFactor = DPIUtil.getScalingFactor(getDisplay());
+ x = (int) (x * scaleFactor);
+ y = (int) (y * scaleFactor);
+
printWindow (true, this, gc, drawable, depth, window, x, y);
if (obscured) state |= OBSCURED;
}
@@ -842,6 +846,12 @@ public Rectangle getBounds () {
int width = (state & ZERO_WIDTH) != 0 ? 0 : allocation.width;
int height = (state & ZERO_HEIGHT) != 0 ? 0 :allocation.height;
if ((parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - width - x;
+ float scaleFactor = DPIUtil.getScalingFactor(getDisplay());
+ x = (int) (x / scaleFactor);
+ y = (int) (y / scaleFactor);
+ width = (int) (width / scaleFactor);
+ height = (int) (height / scaleFactor);
+
return new Rectangle (x, y, width, height);
}
@@ -1110,6 +1120,9 @@ public Point getLocation () {
int width = (state & ZERO_WIDTH) != 0 ? 0 : allocation.width;
x = parent.getClientWidth () - width - x;
}
+ float scaleFactor = DPIUtil.getScalingFactor(getDisplay());
+ x = (int) (x / scaleFactor);
+ y = (int) (y / scaleFactor);
return new Point (x, y);
}
@@ -1173,11 +1186,9 @@ public Point getSize () {
OS.gtk_widget_get_allocation (topHandle, allocation);
int width = (state & ZERO_WIDTH) != 0 ? 0 : allocation.width;
int height = (state & ZERO_HEIGHT) != 0 ? 0 : allocation.height;
- if (this.getLayoutData() instanceof GridData) {
- float scalingFactor = display.getDeviceZoom ()/100f;
- width = (int) (width / scalingFactor);
- height = (int) (height / scalingFactor);
- }
+ float scaleFactor = DPIUtil.getScalingFactor(getDisplay());
+ width = (int) (width / scaleFactor);
+ height = (int) (height / scaleFactor);
return new Point (width, height);
}
@@ -3853,6 +3864,11 @@ void redrawChildren () {
void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean all, boolean trim) {
if (!gtk_widget_get_realized(handle)) return;
+ float scaleFactor = DPIUtil.getScalingFactor(getDisplay());
+ x = (int) (x * scaleFactor);
+ y = (int) (y * scaleFactor);
+ width = (int) (width * scaleFactor);
+ height = (int) (height * scaleFactor);
long /*int*/ window = paintWindow ();
GdkRectangle rect = new GdkRectangle ();
if (redrawAll) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
index 073c88bdd1..231c980349 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
@@ -125,6 +125,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
if (hHint == SWT.DEFAULT) hHint = DEFAULT_HEIGHT;
}
}
+ float scaleFactor = DPIUtil.getScalingFactor(getDisplay());
Point size;
/*
* Feature in GTK. GTK has a predetermined maximum width for wrapping text.
@@ -157,6 +158,8 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
}
size.x += wHint == SWT.DEFAULT ? w [0] : wHint;
size.y += hHint == SWT.DEFAULT ? h [0] : hHint;
+ size.x = (int) (size.x / scaleFactor);
+ size.y = (int) (size.y /scaleFactor);
} else {
if (frameHandle != 0) {
int [] reqWidth = new int [1], reqHeight = new int [1];
@@ -202,6 +205,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
fontHeight += 2 * getThickness (frameHandle).y;
fontHeight += 2 * OS.gtk_container_get_border_width (frameHandle);
}
+ fontHeight = (int) (fontHeight / scaleFactor);
size.y = Math.max (size.y, fontHeight);
}
return size;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java
index 08d7c5cc3a..7f1c6798af 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java
@@ -138,6 +138,10 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
int border = getBorderWidth ();
width += border * 2;
height += border * 2;
+ float scaleFactor = DPIUtil.getScalingFactor(getDisplay());
+ width = (int) (width / scaleFactor);
+ height = (int) (height / scaleFactor);
+
return new Point (width, height);
}

Back to the top