Skip to content

Commit 23c8c11

Browse files
authored
Merge branch 'eclipse-platform:master' into master
2 parents e7868f7 + 7e6f2aa commit 23c8c11

File tree

12 files changed

+123
-53
lines changed

12 files changed

+123
-53
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ public static String getEnvironmentalVariable (String envVarName) {
338338
public static final byte[] mnemonic_activate = ascii("mnemonic-activate");
339339
public static final byte[] month_changed = ascii("month-changed");
340340
public static final byte[] next_month = ascii("next-month");
341+
public static final byte[] notify_gtk_theme = ascii("notify::gtk-theme-name");
341342
public static final byte[] prev_month = ascii("prev-month");
342343
public static final byte[] next_year = ascii("next-year");
343344
public static final byte[] prev_year = ascii("prev-year");

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/ControlWin32Tests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
package org.eclipse.swt.widgets;
1515

1616
import static org.junit.Assert.*;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
1718

1819
import org.eclipse.swt.*;
1920
import org.eclipse.swt.graphics.*;
2021
import org.eclipse.swt.internal.*;
2122
import org.junit.jupiter.api.*;
2223
import org.junit.jupiter.api.extension.*;
24+
import org.junit.jupiter.params.*;
25+
import org.junit.jupiter.params.provider.*;
2326

2427
/**
2528
* Automated Tests for class org.eclipse.swt.widgets.Control for Windows
@@ -107,6 +110,28 @@ public void testCorrectScaleUpUsingDifferentSetBoundsMethod() {
107110
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
108111
}
109112

113+
@ParameterizedTest
114+
@CsvSource({ "0.5, 100, true", "1.0, 200, true", "2.0, 200, true", "2.0, quarter, true", "0.5, 100, false",
115+
"1.0, 200, false", "2.0, 200, false", "2.0, quarter, false", })
116+
public void testAutoScaleImageData(float scaleFactor, String autoScale, boolean monitorSpecificScaling) {
117+
DPIUtil.setMonitorSpecificScaling(monitorSpecificScaling);
118+
DPIUtil.runWithAutoScaleValue(autoScale, () -> {
119+
Display display = new Display();
120+
try {
121+
ImageData imageData = new ImageData(100, 100, 1, new PaletteData(new RGB(0, 0, 0)));
122+
int width = imageData.width;
123+
int height = imageData.height;
124+
int scaledWidth = Math.round(width * scaleFactor);
125+
int scaledHeight = Math.round(height * scaleFactor);
126+
ImageData scaledImageData = DPIUtil.autoScaleImageData(display, imageData, scaleFactor);
127+
assertEquals(scaledWidth, scaledImageData.width);
128+
assertEquals(scaledHeight, scaledImageData.height);
129+
} finally {
130+
display.dispose();
131+
}
132+
});
133+
}
134+
110135
record FontComparison(int originalFontHeight, int currentFontHeight) {
111136
}
112137

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,22 +1811,24 @@ public String toString () {
18111811
* API for Image. It is marked public only so that it
18121812
* can be shared within the packages provided by SWT.
18131813
*
1814-
* Draws a scaled image using the GC by another image.
1814+
* Draws a scaled image using the GC for a given imageData.
18151815
*
18161816
* @param gc the GC to draw on the resulting image
1817-
* @param original the image which is supposed to be scaled and drawn on the resulting image
1817+
* @param imageData the imageData which is used to draw the scaled Image
18181818
* @param width the width of the original image
18191819
* @param height the height of the original image
18201820
* @param scaleFactor the factor with which the image is supposed to be scaled
18211821
*
18221822
* @noreference This method is not intended to be referenced by clients.
18231823
*/
1824-
public static void drawScaled(GC gc, Image original, int width, int height, float scaleFactor) {
1825-
gc.drawImage (original, 0, 0, CocoaDPIUtil.pixelToPoint (width), CocoaDPIUtil.pixelToPoint (height),
1824+
public static void drawScaled(GC gc, ImageData imageData, int width, int height, float scaleFactor) {
1825+
Image imageToDraw = new Image(gc.device, (ImageDataProvider) zoom -> imageData);
1826+
gc.drawImage (imageToDraw, 0, 0, CocoaDPIUtil.pixelToPoint (width), CocoaDPIUtil.pixelToPoint (height),
18261827
/* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
18271828
* Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
18281829
*/
18291830
0, 0, Math.round (CocoaDPIUtil.pixelToPoint (width * scaleFactor)), Math.round (CocoaDPIUtil.pixelToPoint (height * scaleFactor)));
1831+
imageToDraw.dispose();
18301832
}
18311833

18321834
private final class CocoaDPIUtil {

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,11 @@ public static ImageData autoScaleImageData (Device device, final ImageData image
153153
int defaultZoomLevel = 100;
154154
boolean useSmoothScaling = isSmoothScalingEnabled() && imageData.getTransparencyType() != SWT.TRANSPARENCY_MASK;
155155
if (useSmoothScaling) {
156-
Image original = new Image(device, (ImageDataProvider) zoom -> (zoom == defaultZoomLevel) ? imageData : null);
157156
ImageGcDrawer drawer = new ImageGcDrawer() {
158157
@Override
159158
public void drawOn(GC gc, int imageWidth, int imageHeight) {
160159
gc.setAntialias (SWT.ON);
161-
Image.drawScaled(gc, original, width, height, scaleFactor);
160+
Image.drawScaled(gc, imageData, width, height, scaleFactor);
162161
};
163162

164163
@Override
@@ -168,7 +167,6 @@ public int getGcStyle() {
168167
};
169168
Image resultImage = new Image (device, drawer, scaledWidth, scaledHeight);
170169
ImageData result = resultImage.getImageData (defaultZoomLevel);
171-
original.dispose ();
172170
resultImage.dispose ();
173171
return result;
174172
} else {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,22 +1572,24 @@ public String toString () {
15721572
* API for Image. It is marked public only so that it
15731573
* can be shared within the packages provided by SWT.
15741574
*
1575-
* Draws a scaled image using the GC by another image.
1575+
* Draws a scaled image using the GC for a given imageData.
15761576
*
15771577
* @param gc the GC to draw on the resulting image
1578-
* @param original the image which is supposed to be scaled and drawn on the resulting image
1578+
* @param imageData the imageData which is used to draw the scaled Image
15791579
* @param width the width of the original image
15801580
* @param height the height of the original image
15811581
* @param scaleFactor the factor with which the image is supposed to be scaled
15821582
*
15831583
* @noreference This method is not intended to be referenced by clients.
15841584
*/
1585-
public static void drawScaled(GC gc, Image original, int width, int height, float scaleFactor) {
1586-
gc.drawImage (original, 0, 0, width, height,
1585+
public static void drawScaled(GC gc, ImageData imageData, int width, int height, float scaleFactor) {
1586+
Image imageToDraw = new Image(gc.device, (ImageDataProvider) zoom -> imageData);
1587+
gc.drawImage (imageToDraw, 0, 0, width, height,
15871588
/* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
15881589
* Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
15891590
*/
15901591
0, 0, Math.round (width * scaleFactor), Math.round (height * scaleFactor));
1592+
imageToDraw.dispose();
15911593
}
15921594

15931595
private final class GtkDPIUtil {

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ public void stop() {
497497
long keysChangedProc;
498498
Callback keysChangedCallback;
499499

500+
/* Settings "changed" callback */
501+
long settingsChangedProc;
502+
Callback settingsChangedCallback;
503+
500504
/* Multiple Displays. */
501505
static Display Default;
502506
static Display [] Displays = new Display [1];
@@ -1323,7 +1327,11 @@ void createDisplay (DeviceData data) {
13231327
} else {
13241328
keymap = GDK.gdk_keymap_get_for_display(display);
13251329
OS.g_signal_connect (keymap, OS.keys_changed, keysChangedProc, 0);
1326-
}
1330+
}
1331+
1332+
settingsChangedCallback = new Callback (this, "settingsChangedProc", 3); //$NON-NLS-1$
1333+
settingsChangedProc = settingsChangedCallback.getAddress ();
1334+
OS.g_signal_connect (GTK.gtk_settings_get_default(), OS.notify_gtk_theme, settingsChangedProc, 0);
13271335
}
13281336

13291337
/**
@@ -1403,6 +1411,14 @@ long keysChangedProc (long keymap, long user_data) {
14031411
return 0;
14041412
}
14051413

1414+
/**
1415+
* GtkSettings 'changed' event handler.
1416+
*/
1417+
long settingsChangedProc (long settings, long key, long user_data) {
1418+
settingsChanged = true;
1419+
return 0;
1420+
}
1421+
14061422
Image createImage (String name) {
14071423
byte[] buffer = Converter.wcsToMbcs(name, true);
14081424

@@ -2519,6 +2535,10 @@ public Control getFocusControl () {
25192535
*/
25202536
public boolean getHighContrast () {
25212537
checkDevice ();
2538+
String gtkThemeName= OS.getThemeName();
2539+
if (gtkThemeName.contains("HighContrast") || gtkThemeName.contains("ContrastHigh")) {
2540+
return true;
2541+
}
25222542
return false;
25232543
}
25242544

@@ -4814,6 +4834,10 @@ void releaseDisplay () {
48144834
keysChangedCallback.dispose(); keysChangedCallback = null;
48154835
keysChangedProc = 0;
48164836

4837+
/* Dispose the settings "changed" callback */
4838+
settingsChangedCallback.dispose(); settingsChangedCallback = null;
4839+
settingsChangedProc = 0;
4840+
48174841
/* Dispose subclass */
48184842
if (!GTK.GTK4) {
48194843
long pangoLayoutType = OS.PANGO_TYPE_LAYOUT ();

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,12 @@ void createRenderers (long columnHandle, int modelIndex, boolean check, int colu
839839
GTK.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.cell_background_rgba, BACKGROUND_COLUMN);
840840
}
841841
}
842-
long pixbufRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_pixbuf_get_type (), 0) : GTK.gtk_cell_renderer_pixbuf_new ();
842+
long pixbufRenderer ;
843+
if (GTK.GTK4) {
844+
pixbufRenderer = GTK.gtk_cell_renderer_pixbuf_new ();
845+
} else {
846+
pixbufRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_pixbuf_get_type (), 0) : GTK.gtk_cell_renderer_pixbuf_new ();
847+
}
843848
if (pixbufRenderer == 0) {
844849
error (SWT.ERROR_NO_HANDLES);
845850
} else {
@@ -2547,7 +2552,11 @@ void recreateRenderers () {
25472552
if (checkRenderer != 0) {
25482553
display.removeWidget (checkRenderer);
25492554
OS.g_object_unref (checkRenderer);
2550-
checkRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_toggle_get_type(), 0) : GTK.gtk_cell_renderer_toggle_new ();
2555+
if (GTK.GTK4) {
2556+
checkRenderer = GTK.gtk_cell_renderer_toggle_new ();
2557+
} else {
2558+
checkRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_toggle_get_type(), 0) : GTK.gtk_cell_renderer_toggle_new ();
2559+
}
25512560
if (checkRenderer == 0) error (SWT.ERROR_NO_HANDLES);
25522561
OS.g_object_ref (checkRenderer);
25532562
display.addWidget (checkRenderer, this);

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2823,7 +2823,11 @@ void recreateRenderers () {
28232823
if (checkRenderer != 0) {
28242824
display.removeWidget (checkRenderer);
28252825
OS.g_object_unref (checkRenderer);
2826-
checkRenderer = isOwnerDrawn ? OS.g_object_new (display.gtk_cell_renderer_toggle_get_type(), 0) : GTK.gtk_cell_renderer_toggle_new ();
2826+
if (GTK.GTK4) {
2827+
checkRenderer = GTK.gtk_cell_renderer_toggle_new ();
2828+
} else {
2829+
checkRenderer = isOwnerDrawn ? OS.g_object_new (display.gtk_cell_renderer_toggle_get_type(), 0) : GTK.gtk_cell_renderer_toggle_new ();
2830+
}
28272831
if (checkRenderer == 0) error (SWT.ERROR_NO_HANDLES);
28282832
OS.g_object_ref (checkRenderer);
28292833
display.addWidget (checkRenderer, this);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,12 @@ public static Long win32_getHandle (Cursor cursor, int zoom) {
444444
source = DPIUtil.scaleImageData(cursor.device, cursor.source, zoom, DEFAULT_ZOOM);
445445
}
446446
if (cursor.isIcon) {
447-
Cursor newCursor = new Cursor(cursor.device, source, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom));
448-
cursor.setHandleForZoomLevel(newCursor.handle, zoom);
447+
long handle = setupCursorFromImageData(cursor.getDevice(), source, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom));
448+
cursor.setHandleForZoomLevel(handle, zoom);
449449
} else {
450-
ImageData mask = DPIUtil.scaleImageData(cursor.device, cursor.mask, zoom, DEFAULT_ZOOM);
451-
Cursor newCursor = new Cursor(cursor.device, source, mask, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom));
452-
cursor.setHandleForZoomLevel(newCursor.handle, zoom);
450+
ImageData mask = DPIUtil.scaleImageData(cursor.getDevice(), cursor.mask, zoom, DEFAULT_ZOOM);
451+
long handle = setupCursorFromImageData(source, mask, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom));
452+
cursor.setHandleForZoomLevel(handle, zoom);
453453
}
454454
}
455455
return cursor.zoomLevelToHandle.get(zoom);

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -839,19 +839,24 @@ public static long win32_getHandle (Image image, int zoom) {
839839
* API for Image. It is marked public only so that it
840840
* can be shared within the packages provided by SWT.
841841
*
842-
* Draws a scaled image using the GC by another image.
842+
* Draws a scaled image using the GC for a given imageData.
843843
*
844844
* @param gc the GC to draw on the resulting image
845-
* @param original the image which is supposed to be scaled and drawn on the resulting image
845+
* @param imageData the imageData which is used to draw the scaled Image
846846
* @param width the width of the original image
847847
* @param height the height of the original image
848848
* @param scaleFactor the factor with which the image is supposed to be scaled
849849
*
850850
* @noreference This method is not intended to be referenced by clients.
851851
*/
852-
public static void drawScaled(GC gc, Image original, int width, int height, float scaleFactor) {
853-
gc.drawImage (original, 0, 0, width, height,
852+
public static void drawScaled(GC gc, ImageData imageData, int width, int height, float scaleFactor) {
853+
boolean originalStrictChecks = Device.strictChecks;
854+
Device.strictChecks = false;
855+
Image imageToDraw = new Image(gc.device, (ImageDataProvider) zoom -> imageData);
856+
gc.drawImage (imageToDraw, 0, 0, width, height,
854857
0, 0, Math.round (width * scaleFactor), Math.round (height * scaleFactor), false);
858+
Device.strictChecks = originalStrictChecks;
859+
imageToDraw.dispose();
855860
}
856861

857862
long [] createGdipImage(Integer zoom) {

0 commit comments

Comments
 (0)