Skip to content

Commit bf08e16

Browse files
authored
Merge branch 'master' into clipboard-test-assume-gtk
2 parents 7c3476a + 4d72e87 commit bf08e16

File tree

4 files changed

+35
-7
lines changed

4 files changed

+35
-7
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,31 @@ void translateRectangleInPixelsForZeroSize(CoordinateSystemMapper mapper) {
218218
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs));
219219
}
220220

221+
@ParameterizedTest
222+
@MethodSource("provideCoordinateSystemMappers")
223+
void translateBoundsToSecondMonitor(CoordinateSystemMapper mapper) {
224+
final int OFFSET = 30;
225+
final int SIZE = OFFSET * 3;
226+
setupMonitors(mapper);
227+
Rectangle currentPosition = new Rectangle.WithMonitor(monitors[1].getClientArea().x - OFFSET, 0, SIZE, SIZE,
228+
monitors[1]);
229+
Rectangle result = mapper.translateFromDisplayCoordinates(currentPosition);
230+
assertTrue(monitors[1].getClientArea().intersects(result));
231+
}
232+
233+
@ParameterizedTest
234+
@MethodSource("provideCoordinateSystemMappers")
235+
void translatePointsToSecondMonitor(CoordinateSystemMapper mapper) {
236+
final int OFFSET = 30;
237+
final int SIZE = OFFSET * 3;
238+
setupMonitors(mapper);
239+
Point currentPosition = new Point.WithMonitor(monitors[1].getClientArea().x - OFFSET, 0, monitors[1]);
240+
Point size = new Point(SIZE, SIZE);
241+
Point result = mapper.translateFromDisplayCoordinates(currentPosition);
242+
Rectangle resultRect = new Rectangle(result.x, result.y, size.x, size.y);
243+
assertTrue(monitors[1].getClientArea().intersects(resultRect));
244+
}
245+
221246
private Point createExpectedPoint(CoordinateSystemMapper mapper, int x, int y, Monitor monitor) {
222247
if (mapper instanceof SingleZoomCoordinateSystemMapper) {
223248
return new Point(x, y);

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
@@ -1148,7 +1148,7 @@ private int calculateZoomForImage(int gcZoom, int srcWidth, int srcHeight, int d
11481148
// unscaled images can use the GC zoom
11491149
return gcZoom;
11501150
}
1151-
if (!drawable.isAutoScalable()) {
1151+
if (drawable != null && !drawable.isAutoScalable()) {
11521152
return gcZoom;
11531153
}
11541154

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public Rectangle mapMonitorBounds(Rectangle rect, int zoom) {
9393

9494
@Override
9595
public Point translateFromDisplayCoordinates(Point point) {
96-
return translateLocationInPixelsToPoints(point.x, point.y);
96+
Monitor monitor = point instanceof Point.WithMonitor pointWithMonitor ? pointWithMonitor.getMonitor() : null;
97+
return translateLocationInPixelsToPoints(point.x, point.y, monitor);
9798
}
9899

99100
@Override
@@ -117,7 +118,7 @@ public Rectangle translateToDisplayCoordinates(Rectangle rect) {
117118
@Override
118119
public Point getCursorLocation() {
119120
Point cursorLocationInPixels = display.getCursorLocationInPixels();
120-
return translateLocationInPixelsToPoints(cursorLocationInPixels.x, cursorLocationInPixels.y);
121+
return translateLocationInPixelsToPoints(cursorLocationInPixels.x, cursorLocationInPixels.y, null);
121122
}
122123

123124
@Override
@@ -131,8 +132,10 @@ private Point translateLocationInPointsToPixels(int x, int y, Monitor monitor) {
131132
return getPixelsFromPoint(monitor, x, y);
132133
}
133134

134-
private Point translateLocationInPixelsToPoints(int x, int y) {
135-
Monitor monitor = getContainingMonitorForPixels(x, y);
135+
private Point translateLocationInPixelsToPoints(int x, int y, Monitor monitor) {
136+
if (monitor == null) {
137+
monitor = getContainingMonitorForPixels(x, y);
138+
}
136139
return getPointFromPixels(monitor, x, y);
137140
}
138141

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ public int getAlpha () {
924924
OS.GetWindowRect (handle, rect);
925925
int width = rect.right - rect.left;
926926
int height = rect.bottom - rect.top;
927-
return new Rectangle (rect.left, rect.top, width, height);
927+
return new Rectangle.WithMonitor (rect.left, rect.top, width, height, getMonitor());
928928
}
929929

930930
ToolTip getCurrentToolTip () {
@@ -1017,7 +1017,7 @@ public int getImeInputMode () {
10171017
if (OS.IsIconic (handle)) return super.getLocationInPixels ();
10181018
RECT rect = new RECT ();
10191019
OS.GetWindowRect (handle, rect);
1020-
return new Point (rect.left, rect.top);
1020+
return new Point.WithMonitor (rect.left, rect.top, getMonitor());
10211021
}
10221022

10231023
@Override

0 commit comments

Comments
 (0)