Skip to content

Commit a5871ee

Browse files
authored
Merge branch 'eclipse-platform:master' into master
2 parents 197f9a8 + 2ddc1ad commit a5871ee

File tree

12 files changed

+83
-122
lines changed

12 files changed

+83
-122
lines changed

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,6 +3547,9 @@ void setBackground () {
35473547
* <p>
35483548
* Note: This operation is a hint and may be overridden by the platform.
35493549
* </p>
3550+
* <p>
3551+
* Note: The background color can be overridden by setting a background image.
3552+
* </p>
35503553
* @param color the new color (or null)
35513554
*
35523555
* @exception IllegalArgumentException <ul>
@@ -3587,6 +3590,9 @@ private void _setBackground (Color color) {
35873590
* Note: This operation is a hint and may be overridden by the platform.
35883591
* For example, on Windows the background of a Button cannot be changed.
35893592
* </p>
3593+
* <p>
3594+
* Note: Setting a background image overrides a set background color.
3595+
* </p>
35903596
* @param image the new image (or null)
35913597
*
35923598
* @exception IllegalArgumentException <ul>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,9 @@ long gtk_draw (long widget, long cairo) {
499499
int height = (state & ZERO_HEIGHT) != 0 ? 0 : allocation.height;
500500
// We specify a 0 value for x & y as we want the whole widget to be
501501
// colored, not some portion of it.
502-
GTK.gtk_render_background(context, cairo, 0, 0, width, height);
502+
if (backgroundImage == null) {
503+
GTK.gtk_render_background(context, cairo, 0, 0, width, height);
504+
}
503505
// If fixClipHandle is set: iterate through the children of widget
504506
// and set their clips to be that of their allocation
505507
if (widget == fixClipHandle) fixClippings();

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,7 @@ void drawBackground (Control control, long gdkResource, long cr, int x, int y, i
194194
cairo_rectangle_int_t regionRect = new cairo_rectangle_int_t ();
195195
int [] fetchedHeight = new int [1];
196196
int [] fetchedWidth = new int [1];
197-
if (GTK.GTK4) {
198-
gdk_surface_get_size(gdkResource, fetchedWidth, fetchedHeight);
199-
} else {
200-
gdk_window_get_size(gdkResource, fetchedWidth, fetchedHeight);
201-
}
197+
gdk_surface_get_size(gdkResource, fetchedWidth, fetchedHeight);
202198
regionRect.x = 0;
203199
regionRect.y = 0;
204200
regionRect.width = fetchedWidth[0];
@@ -3432,8 +3428,15 @@ int gtk_gesture_press_event (long gesture, int n_press, double x, double y, long
34323428
}
34333429
}
34343430
}
3435-
} else if (n_press == 2) {
3431+
} else if (n_press >= 2) {
34363432
boolean cancelled = sendMouseEvent(SWT.MouseDoubleClick, eventButton, n_press, 0, false, eventTime, x, y, false, eventState);
3433+
3434+
//Issue 344, DoubleClick event currently unsupported below sendMouseEvent(). Until DoubleClickSupport is
3435+
//added this will catch failed events and try MouseDown instead.
3436+
if (cancelled) {
3437+
cancelled = sendMouseEvent(SWT.MouseDown, eventButton, n_press, 0, false, eventTime, x, y, false, eventState);
3438+
}
3439+
34373440
if (!cancelled) {
34383441
result = GTK4.GTK_EVENT_SEQUENCE_CLAIMED;
34393442
}
@@ -3456,7 +3459,7 @@ int gtk_gesture_release_event (long gesture, int n_press, double x, double y, lo
34563459
lastInput.x = (int) eventX[0];
34573460
lastInput.y = (int) eventY[0];
34583461
if (containedInRegion(lastInput.x, lastInput.y)) return GTK4.GTK_EVENT_SEQUENCE_NONE;
3459-
boolean cancelled = sendMouseEvent(SWT.MouseUp, eventButton, display.clickCount, 0, false, eventTime, 0, 0, false, eventState);
3462+
boolean cancelled = sendMouseEvent(SWT.MouseUp, eventButton, display.clickCount, 0, false, eventTime, x, y, false, eventState);
34603463
int result = GTK4.GTK_EVENT_SEQUENCE_NONE;
34613464
if (!cancelled) {
34623465
result = GTK4.GTK_EVENT_SEQUENCE_CLAIMED;
@@ -5176,6 +5179,9 @@ void setBackground () {
51765179
* <p>
51775180
* Note: This operation is a hint and may be overridden by the platform.
51785181
* </p>
5182+
* <p>
5183+
* Note: The background color can be overridden by setting a background image.
5184+
* </p>
51795185
* @param color the new color (or null)
51805186
*
51815187
* @exception IllegalArgumentException <ul>
@@ -5281,6 +5287,9 @@ void setBackgroundGdkRGBA (long handle, GdkRGBA rgba) {
52815287
* Note: This operation is a hint and may be overridden by the platform.
52825288
* For example, on Windows the background of a Button cannot be changed.
52835289
* </p>
5290+
* <p>
5291+
* Note: Setting a background image overrides a set background color.
5292+
* </p>
52845293
* @param image the new image (or null)
52855294
*
52865295
* @exception IllegalArgumentException <ul>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3072,6 +3072,9 @@ void setBackground () {
30723072
* <p>
30733073
* Note: This operation is a hint and may be overridden by the platform.
30743074
* </p>
3075+
* <p>
3076+
* Note: The background color can be overridden by setting a background image.
3077+
* </p>
30753078
* @param color the new color (or null)
30763079
*
30773080
* @exception IllegalArgumentException <ul>
@@ -3114,6 +3117,9 @@ private void _setBackground (Color color) {
31143117
* Note: This operation is a hint and may be overridden by the platform.
31153118
* For example, on Windows the background of a Button cannot be changed.
31163119
* </p>
3120+
* <p>
3121+
* Note: Setting a background image overrides a set background color.
3122+
* </p>
31173123
* @param image the new image (or null)
31183124
*
31193125
* @exception IllegalArgumentException <ul>

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/BrowserTab.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2018 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -16,10 +16,9 @@
1616

1717
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
1818

19-
import java.io.BufferedReader;
2019
import java.io.IOException;
2120
import java.io.InputStream;
22-
import java.io.InputStreamReader;
21+
import java.nio.charset.StandardCharsets;
2322

2423
import org.eclipse.swt.SWT;
2524
import org.eclipse.swt.SWTError;
@@ -118,18 +117,12 @@ void createExampleWidgets () {
118117
} else if (lastText != null) {
119118
browser.setText(lastText);
120119
} else {
121-
StringBuilder sb= new StringBuilder(300);
122-
123-
try (InputStream htmlStream = ControlExample.class.getResourceAsStream("browser-content.html");
124-
BufferedReader br = new BufferedReader(new InputStreamReader(htmlStream))) {
125-
int read = 0;
126-
while ((read = br.read()) != -1)
127-
sb.append((char) read);
120+
try (InputStream htmlStream = ControlExample.class.getResourceAsStream("browser-content.html")) {
121+
browser.setText( new String (htmlStream.readAllBytes(), StandardCharsets.UTF_8));
128122
} catch (IOException e) {
129123
log(e.getMessage());
124+
browser.setText("Loading failed, see log for details!");
130125
}
131-
String text= sb.toString();
132-
browser.setText(text);
133126
}
134127
lastText = lastUrl = null;
135128
}
@@ -229,16 +222,6 @@ void disposeExampleWidgets () {
229222
super.disposeExampleWidgets();
230223
}
231224

232-
public static String getContents(InputStream in) throws IOException {
233-
StringBuilder sb= new StringBuilder(300);
234-
try (BufferedReader br= new BufferedReader(new InputStreamReader(in))) {
235-
int read= 0;
236-
while ((read= br.read()) != -1)
237-
sb.append((char) read);
238-
}
239-
return sb.toString();
240-
}
241-
242225
/**
243226
* Gets the list of custom event names.
244227
*

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/browser-content.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<title>SWT Browser</title>
45
</head>
56

67
<h3>About SWT Browser</h3>
7-
<p>You are looking at HTML content in a <b>Browser</b> widget.
8+
<p>You are looking at HTML content in a <b>Browser</b> widget.</p>
89
<ul>
910
<li>For a definition of the Browser widget, see:
1011
<a href="http://www.eclipse.org/swt/faq.php#whatisbrowser">http://www.eclipse.org/swt/faq.php#whatisbrowser</a></li>
@@ -14,7 +15,7 @@ <h3>About SWT Browser</h3>
1415
<a href="http://www.eclipse.org/swt/faq.php#howusewebkit">http://www.eclipse.org/swt/faq.php#howusewebkit</a></li>
1516
<li>For more examples that use a Browser widget, see BrowserExample, BrowserDemo, and WebBrowser:
1617
<a href="http://www.eclipse.org/swt/examples.php">http://www.eclipse.org/swt/examples.php</a></li>
17-
</ul></p>
18+
</ul>
1819

1920
<h3>About SWT</h3>
2021
<p>For more information on SWT, including the Widget Gallery, Snippets, Examples, FAQ, Tools, Documentation

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet62.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -40,12 +40,12 @@ public static void main (String [] args) {
4040
final Shell shell = new Shell (display);
4141
shell.setText("Snippet 62");
4242
Listener listener = e -> {
43-
String string = "Unknown";
44-
switch (e.type) {
45-
case SWT.MouseDown: string = "DOWN"; break;
46-
case SWT.MouseMove: string = "MOVE"; break;
47-
case SWT.MouseUp: string = "UP"; break;
48-
}
43+
String string = switch (e.type) {
44+
case SWT.MouseDown -> "DOWN";
45+
case SWT.MouseMove -> "MOVE";
46+
case SWT.MouseUp -> "UP";
47+
default -> "Unknown";
48+
};
4949
string +=": button: " + e.button + ", ";
5050
string += "stateMask=0x" + Integer.toHexString (e.stateMask) + stateMask (e.stateMask) + ", x=" + e.x + ", y=" + e.y;
5151
if ((e.stateMask & SWT.BUTTON1) != 0) string += " BUTTON1";

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/SnippetLauncher.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
import java.io.*;
2626
import java.lang.reflect.*;
27+
import java.nio.charset.*;
28+
import java.nio.file.*;
2729

2830
import org.eclipse.swt.*;
2931

@@ -47,15 +49,13 @@ public static void main (String [] args) {
4749
if (clazz != null) {
4850
System.out.println("\n" + clazz.getName());
4951
if (hasSource) {
50-
File sourceFile = new File(sourceDir, className + ".java");
51-
try (FileReader reader = new FileReader(sourceFile);){
52-
char [] buffer = new char [(int)sourceFile.length()];
53-
reader.read(buffer);
54-
String source = String.valueOf(buffer);
52+
Path sourceFile = Path.of(sourceDir.getPath(), className + ".java");
53+
try {
54+
String source = Files.readString(sourceFile, StandardCharsets.UTF_8);
5555
int start = source.indexOf("package");
5656
start = source.indexOf("/*", start);
5757
int end = source.indexOf("* For a list of all");
58-
System.out.println(source.substring(start, end-3));
58+
System.out.println(source.substring(start+3, end-3));
5959
boolean skip = false;
6060
String platform = SWT.getPlatform();
6161
if (source.contains("OpenGL")) {

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_SWT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.eclipse.swt.SWTError;
3232
import org.eclipse.swt.SWTException;
3333
import org.junit.jupiter.api.Test;
34-
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
34+
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
3535

3636
/**
3737
* Automated Test Suite for class {@link org.eclipse.swt.SWT}.
@@ -114,7 +114,7 @@ private List<String> signersFromClass(Class<?> classValue) {
114114
* GitHub Pull Requests.
115115
*/
116116
@Test
117-
@EnabledIfSystemProperty(named = "org.eclipse.swt.tests.junit.disable.test_isLocal", matches = "true")
117+
@DisabledIfSystemProperty(named = "org.eclipse.swt.tests.junit.disable.test_isLocal", matches = "true")
118118
public void test_isLocal() {
119119
String swtPath = pathFromClass(SWT.class);
120120
String tstPath = pathFromClass(Test_org_eclipse_swt_SWT.class);

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Control.java

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.junit.Assert.assertNotEquals;
2020
import static org.junit.Assert.assertNotNull;
2121
import static org.junit.Assert.assertNull;
22+
import static org.junit.Assert.assertThrows;
2223
import static org.junit.Assert.assertTrue;
2324
import static org.junit.Assert.fail;
2425
import static org.junit.Assume.assumeTrue;
@@ -640,12 +641,8 @@ public void test_setBackgroundAlphaLorg_eclipse_swt_graphics_Color() {
640641
public void test_setBackgroundDisposedColorLorg_eclipse_swt_graphics_Color() {
641642
Color color = new Color(255, 0, 0);
642643
color.dispose();
643-
try {
644-
control.setBackground(color);
645-
fail("setting a disposed color object with Control.setBackground(Color) should throw an exception");
646-
} catch (IllegalArgumentException e) {
647-
// expected, since the color is disposed
648-
}
644+
assertThrows("setting a disposed color object with Control.setBackground(Color) should throw an exception",
645+
IllegalArgumentException.class, () -> control.setBackground(color));
649646
}
650647
@Test
651648
public void test_setBoundsIIII() {
@@ -665,12 +662,8 @@ public void test_setBoundsLorg_eclipse_swt_graphics_Rectangle() {
665662
control.setBounds(new Rectangle(20, 30, 40, 50));
666663
assertNotEquals(new Rectangle(10, 20, 30, 40), control.getBounds());
667664

668-
try {
669-
control.setBounds(null);
670-
fail("No exception thrown for rectangle == null");
671-
}
672-
catch (IllegalArgumentException e) {
673-
}
665+
assertThrows("No exception thrown for rectangle == null", IllegalArgumentException.class,
666+
() -> control.setBounds(null));
674667

675668
control.setBounds(new Rectangle(10, 20, 30, 40));
676669
}
@@ -735,12 +728,9 @@ public void test_setFontLorg_eclipse_swt_graphics_Font() {
735728

736729
control.setFont(null);
737730
font.dispose();
738-
try {
739-
control.setFont(font);
740-
control.setFont(null);
741-
fail("No exception thrown for disposed font");
742-
} catch (IllegalArgumentException e) {
743-
}
731+
Font f = font;
732+
assertThrows("No exception thrown for disposed font", IllegalArgumentException.class, () -> control.setFont(f));
733+
control.setFont(null);
744734
}
745735
@Test
746736
public void test_setForegroundLorg_eclipse_swt_graphics_Color() {
@@ -775,12 +765,8 @@ public void test_setForegroundAlphaLorg_eclipse_swt_graphics_Color() {
775765
public void test_setForegroundDisposedColorLorg_eclipse_swt_graphics_Color() {
776766
Color color = new Color(255, 0, 0);
777767
color.dispose();
778-
try {
779-
control.setForeground(color);
780-
fail("setting a disposed color object with Control.setForeground(Color) should throw an exception");
781-
} catch (IllegalArgumentException e) {
782-
// expected, since the color is disposed
783-
}
768+
assertThrows("setting a disposed color object with Control.setForeground(Color) should throw an exception",
769+
IllegalArgumentException.class, () -> control.setForeground(color));
784770
}
785771
@Test
786772
public void test_setLayoutDataLjava_lang_Object() {
@@ -808,12 +794,8 @@ public void test_setLocationII() {
808794
}
809795
@Test
810796
public void test_setLocationLorg_eclipse_swt_graphics_Point() {
811-
try {
812-
control.setLocation(null);
813-
fail("No exception thrown for location == null");
814-
}
815-
catch (IllegalArgumentException e) {
816-
}
797+
assertThrows("No exception thrown for location == null", IllegalArgumentException.class,
798+
() -> control.setLocation(null));
817799

818800
Point loc = new Point(30, 40);
819801
control.setLocation(loc);
@@ -881,12 +863,7 @@ public void test_setSizeLorg_eclipse_swt_graphics_Point() {
881863
control.setSize(new Point(30, 40));
882864
assertEquals(new Point(30, 40), control.getSize());
883865

884-
try {
885-
control.setSize(null);
886-
fail("No exception thrown for size == null");
887-
}
888-
catch (IllegalArgumentException e) {
889-
}
866+
assertThrows("No exception thrown for size == null", IllegalArgumentException.class, () -> control.setSize(null));
890867

891868
control.setSize(new Point(0, 0));
892869

@@ -921,12 +898,8 @@ public void test_toControlII() {
921898
public void test_toControlLorg_eclipse_swt_graphics_Point() {
922899
Point controlCoords = control.toControl(new Point(0, 0));
923900
assertEquals(new Point(0, 0), control.toDisplay(controlCoords));
924-
try {
925-
control.toControl(null);
926-
fail("No exception thrown for size == null");
927-
}
928-
catch (IllegalArgumentException e) {
929-
}
901+
assertThrows("No exception thrown for point == null", IllegalArgumentException.class,
902+
() -> control.toControl(null));
930903
}
931904
@Test
932905
public void test_toDisplayII() {
@@ -937,12 +910,8 @@ public void test_toDisplayII() {
937910
public void test_toDisplayLorg_eclipse_swt_graphics_Point() {
938911
Point displayCoords = control.toDisplay(new Point(0, 0));
939912
assertEquals(new Point(0, 0), control.toControl(displayCoords));
940-
try {
941-
control.toDisplay(null);
942-
fail("No exception thrown for size == null");
943-
}
944-
catch (IllegalArgumentException e) {
945-
}
913+
assertThrows("No exception thrown for display == null", IllegalArgumentException.class,
914+
() -> control.toDisplay(null));
946915
}
947916
@Test
948917
public void test_traverseI() {

0 commit comments

Comments
 (0)