@@ -1704,11 +1704,7 @@ public Control getCursorControl () {
1704
1704
*/
1705
1705
public Point getCursorLocation () {
1706
1706
checkDevice ();
1707
- Point cursorLocationInPixels = getCursorLocationInPixels ();
1708
- if (isRescalingAtRuntime ()) {
1709
- return translateLocationInPointInDisplayCoordinateSystem (cursorLocationInPixels .x , cursorLocationInPixels .y );
1710
- }
1711
- return DPIUtil .autoScaleDown (cursorLocationInPixels );
1707
+ return DPIUtil .autoScaleDown (getCursorLocationInPixels ());
1712
1708
}
1713
1709
1714
1710
Point getCursorLocationInPixels () {
@@ -2187,21 +2183,14 @@ Monitor getMonitor (long hmonitor) {
2187
2183
OS .GetMonitorInfo (hmonitor , lpmi );
2188
2184
Monitor monitor = new Monitor ();
2189
2185
monitor .handle = hmonitor ;
2190
- Rectangle boundsInPixels = new Rectangle (lpmi .rcMonitor_left , lpmi .rcMonitor_top , lpmi .rcMonitor_right - lpmi .rcMonitor_left ,lpmi .rcMonitor_bottom - lpmi .rcMonitor_top );
2191
- Rectangle clientAreaInPixels = new Rectangle (lpmi .rcWork_left , lpmi .rcWork_top , lpmi .rcWork_right - lpmi .rcWork_left , lpmi .rcWork_bottom - lpmi .rcWork_top );
2186
+ Rectangle boundsInPixels = new Rectangle (lpmi .rcMonitor_left , lpmi .rcMonitor_top , lpmi .rcMonitor_right - lpmi .rcMonitor_left ,lpmi .rcMonitor_bottom - lpmi .rcMonitor_top );
2187
+ monitor .setBounds (DPIUtil .autoScaleDown (boundsInPixels ));
2188
+ Rectangle clientAreaInPixels = new Rectangle (lpmi .rcWork_left , lpmi .rcWork_top , lpmi .rcWork_right - lpmi .rcWork_left , lpmi .rcWork_bottom - lpmi .rcWork_top );
2189
+ monitor .setClientArea (DPIUtil .autoScaleDown (clientAreaInPixels ));
2192
2190
int [] dpiX = new int [1 ];
2193
2191
int [] dpiY = new int [1 ];
2194
2192
int result = OS .GetDpiForMonitor (monitor .handle , OS .MDT_EFFECTIVE_DPI , dpiX , dpiY );
2195
2193
result = (result == OS .S_OK ) ? DPIUtil .mapDPIToZoom (dpiX [0 ]) : 100 ;
2196
-
2197
- if (DPIUtil .isAutoScaleOnRuntimeActive ()) {
2198
- int autoscaleZoom = DPIUtil .getZoomForAutoscaleProperty (result );
2199
- monitor .setBounds (getMonitorBoundsInPointsInDisplayCoordinateSystem (boundsInPixels , autoscaleZoom ));
2200
- monitor .setClientArea (getMonitorBoundsInPointsInDisplayCoordinateSystem (clientAreaInPixels , autoscaleZoom ));
2201
- } else {
2202
- monitor .setBounds (DPIUtil .autoScaleDown (boundsInPixels ));
2203
- monitor .setClientArea (DPIUtil .autoScaleDown (clientAreaInPixels ));
2204
- }
2205
2194
if (result == 0 ) {
2206
2195
System .err .println ("***WARNING: GetDpiForMonitor: SWT could not get valid monitor scaling factor." );
2207
2196
result = 100 ;
@@ -2214,13 +2203,6 @@ Monitor getMonitor (long hmonitor) {
2214
2203
return monitor ;
2215
2204
}
2216
2205
2217
- private Rectangle getMonitorBoundsInPointsInDisplayCoordinateSystem (Rectangle boundsInPixels , int zoom ) {
2218
- Rectangle bounds = DPIUtil .scaleDown (boundsInPixels , zoom );
2219
- bounds .x = boundsInPixels .x ;
2220
- bounds .y = boundsInPixels .y ;
2221
- return bounds ;
2222
- }
2223
-
2224
2206
/**
2225
2207
* Returns an array of monitors attached to the device.
2226
2208
*
@@ -2962,9 +2944,6 @@ boolean isValidThread () {
2962
2944
public Point map (Control from , Control to , Point point ) {
2963
2945
checkDevice ();
2964
2946
if (point == null ) error (SWT .ERROR_NULL_ARGUMENT );
2965
- if (isRescalingAtRuntime ()) {
2966
- return map (from , to , point .x , point .y );
2967
- }
2968
2947
int zoom = getZoomLevelForMapping (from , to );
2969
2948
point = DPIUtil .scaleUp (point , zoom );
2970
2949
return DPIUtil .scaleDown (mapInPixels (from , to , point ), zoom );
@@ -3012,20 +2991,6 @@ Point mapInPixels (Control from, Control to, Point point) {
3012
2991
*/
3013
2992
public Point map (Control from , Control to , int x , int y ) {
3014
2993
checkDevice ();
3015
- if (isRescalingAtRuntime ()) {
3016
- Point mappedPointInPoints ;
3017
- if (from == null ) {
3018
- Point mappedPointInpixels = mapInPixels (from , to , getPixelsFromPoint (to .getShell ().getMonitor (), x , y ));
3019
- mappedPointInPoints = DPIUtil .scaleDown (mappedPointInpixels , to .getZoom ());
3020
- } else if (to == null ) {
3021
- Point mappedPointInpixels = mapInPixels (from , to , DPIUtil .scaleUp (new Point (x , y ), from .getZoom ()));
3022
- mappedPointInPoints = getPointFromPixels (from .getShell ().getMonitor (), mappedPointInpixels .x , mappedPointInpixels .y );
3023
- } else {
3024
- Point mappedPointInpixels = mapInPixels (from , to , DPIUtil .scaleUp (new Point (x , y ), from .getZoom ()));
3025
- mappedPointInPoints = DPIUtil .scaleDown (mappedPointInpixels , to .getZoom ());
3026
- }
3027
- return mappedPointInPoints ;
3028
- }
3029
2994
int zoom = getZoomLevelForMapping (from , to );
3030
2995
x = DPIUtil .scaleUp (x , zoom );
3031
2996
y = DPIUtil .scaleUp (y , zoom );
@@ -3093,9 +3058,6 @@ private int getZoomLevelForMapping(Control from, Control to) {
3093
3058
public Rectangle map (Control from , Control to , Rectangle rectangle ) {
3094
3059
checkDevice ();
3095
3060
if (rectangle == null ) error (SWT .ERROR_NULL_ARGUMENT );
3096
- if (isRescalingAtRuntime ()) {
3097
- return map (from , to , rectangle .x , rectangle .y , rectangle .width , rectangle .height );
3098
- }
3099
3061
int zoom = getZoomLevelForMapping (from , to );
3100
3062
rectangle = DPIUtil .scaleUp (rectangle , zoom );
3101
3063
return DPIUtil .scaleDown (mapInPixels (from , to , rectangle ), zoom );
@@ -3145,20 +3107,6 @@ Rectangle mapInPixels (Control from, Control to, Rectangle rectangle) {
3145
3107
*/
3146
3108
public Rectangle map (Control from , Control to , int x , int y , int width , int height ) {
3147
3109
checkDevice ();
3148
- if (isRescalingAtRuntime ()) {
3149
- Rectangle mappedRectangleInPoints ;
3150
- if (from == null ) {
3151
- Rectangle mappedRectangleInPixels = mapInPixels (from , to , translateRectangleInPixelsInDisplayCoordinateSystem (x , y , width , height , to .getShell ().getMonitor ()));
3152
- mappedRectangleInPoints = DPIUtil .scaleDown (mappedRectangleInPixels , to .getZoom ());
3153
- } else if (to == null ) {
3154
- Rectangle mappedRectangleInPixels = mapInPixels (from , to , DPIUtil .scaleUp (new Rectangle (x , y , width , height ), from .getZoom ()));
3155
- mappedRectangleInPoints = translateRectangleInPointsInDisplayCoordinateSystem (mappedRectangleInPixels .x , mappedRectangleInPixels .y , mappedRectangleInPixels .width , mappedRectangleInPixels .height , from .getShell ().getMonitor ());
3156
- } else {
3157
- Rectangle mappedRectangleInPixels = mapInPixels (from , to , DPIUtil .scaleUp (new Rectangle (x , y , width , height ), from .getZoom ()));
3158
- mappedRectangleInPoints = DPIUtil .scaleDown (mappedRectangleInPixels , to .getZoom ());
3159
- }
3160
- return mappedRectangleInPoints ;
3161
- }
3162
3110
int zoom = getZoomLevelForMapping (from , to );
3163
3111
x = DPIUtil .scaleUp (x , zoom );
3164
3112
y = DPIUtil .scaleUp (y , zoom );
@@ -3182,57 +3130,6 @@ Rectangle mapInPixels (Control from, Control to, int x, int y, int width, int he
3182
3130
return new Rectangle (rect .left , rect .top , rect .right - rect .left , rect .bottom - rect .top );
3183
3131
}
3184
3132
3185
- Point translateLocationInPixelsInDisplayCoordinateSystem (int x , int y ) {
3186
- Monitor monitor = getContainingMonitor (x , y );
3187
- return getPixelsFromPoint (monitor , x , y );
3188
- }
3189
-
3190
- Point translateLocationInPointInDisplayCoordinateSystem (int x , int y ) {
3191
- Monitor monitor = getContainingMonitorInPixelsCoordinate (x , y );
3192
- return getPointFromPixels (monitor , x , y );
3193
- }
3194
-
3195
- Rectangle translateRectangleInPixelsInDisplayCoordinateSystemByContainment (int x , int y , int width , int height ) {
3196
- Monitor monitorByLocation = getContainingMonitor (x , y );
3197
- Monitor monitorByContainment = getContainingMonitor (x , y , width , height );
3198
- return translateRectangleInPixelsInDisplayCoordinateSystem (x , y , width , height , monitorByLocation , monitorByContainment );
3199
- }
3200
-
3201
- private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem (int x , int y , int width , int height , Monitor monitor ) {
3202
- return translateRectangleInPixelsInDisplayCoordinateSystem (x , y , width , height , monitor , monitor );
3203
- }
3204
-
3205
- private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem (int x , int y , int width , int height , Monitor monitorOfLocation , Monitor monitorOfArea ) {
3206
- Point topLeft = getPixelsFromPoint (monitorOfLocation , x , y );
3207
- int zoom = getApplicableMonitorZoom (monitorOfArea );
3208
- int widthInPixels = DPIUtil .scaleUp (width , zoom );
3209
- int heightInPixels = DPIUtil .scaleUp (height , zoom );
3210
- return new Rectangle (topLeft .x , topLeft .y , widthInPixels , heightInPixels );
3211
- }
3212
-
3213
- Rectangle translateRectangleInPointsInDisplayCoordinateSystemByContainment (int x , int y , int widthInPixels , int heightInPixels ) {
3214
- Monitor monitorByLocation = getContainingMonitor (x , y );
3215
- Monitor monitorByContainment = getContainingMonitor (x , y , widthInPixels , heightInPixels );
3216
- return translateRectangleInPointsInDisplayCoordinateSystem (x , y , widthInPixels , heightInPixels , monitorByLocation , monitorByContainment );
3217
- }
3218
-
3219
- private Rectangle translateRectangleInPointsInDisplayCoordinateSystem (int x , int y , int widthInPixels , int heightInPixels , Monitor monitor ) {
3220
- return translateRectangleInPointsInDisplayCoordinateSystem (x , y , widthInPixels , heightInPixels , monitor , monitor );
3221
- }
3222
-
3223
-
3224
- private Rectangle translateRectangleInPointsInDisplayCoordinateSystem (int x , int y , int widthInPixels , int heightInPixels , Monitor monitorOfLocation , Monitor monitorOfArea ) {
3225
- Point topLeft = getPointFromPixels (monitorOfLocation , x , y );
3226
- int zoom = getApplicableMonitorZoom (monitorOfArea );
3227
- int width = DPIUtil .scaleDown (widthInPixels , zoom );
3228
- int height = DPIUtil .scaleDown (heightInPixels , zoom );
3229
- return new Rectangle (topLeft .x , topLeft .y , width , height );
3230
- }
3231
-
3232
- private int getApplicableMonitorZoom (Monitor monitor ) {
3233
- return DPIUtil .getZoomForAutoscaleProperty (isRescalingAtRuntime () ? monitor .zoom : getDeviceZoom ());
3234
- }
3235
-
3236
3133
long messageProc (long hwnd , long msg , long wParam , long lParam ) {
3237
3134
switch ((int )msg ) {
3238
3135
case SWT_RUNASYNC : {
@@ -4458,12 +4355,7 @@ public void sendPostExternalEventDispatchEvent () {
4458
4355
*/
4459
4356
public void setCursorLocation (int x , int y ) {
4460
4357
checkDevice ();
4461
- if (isRescalingAtRuntime ()) {
4462
- Point cursorLocationInPixels = translateLocationInPixelsInDisplayCoordinateSystem (x , y );
4463
- setCursorLocationInPixels (cursorLocationInPixels .x , cursorLocationInPixels .y );
4464
- } else {
4465
- setCursorLocationInPixels (DPIUtil .autoScaleUp (x ), DPIUtil .autoScaleUp (y ));
4466
- }
4358
+ setCursorLocationInPixels (DPIUtil .autoScaleUp (x ), DPIUtil .autoScaleUp (y ));
4467
4359
}
4468
4360
4469
4361
void setCursorLocationInPixels (int x , int y ) {
@@ -5498,63 +5390,4 @@ private boolean setDPIAwareness(int desiredDpiAwareness) {
5498
5390
return true ;
5499
5391
}
5500
5392
5501
- private Monitor getContainingMonitor (int x , int y ) {
5502
- Monitor [] monitors = getMonitors ();
5503
- for (Monitor currentMonitor : monitors ) {
5504
- Rectangle clientArea = currentMonitor .getClientArea ();
5505
- if (clientArea .contains (x , y )) {
5506
- return currentMonitor ;
5507
- }
5508
- }
5509
- return getPrimaryMonitor ();
5510
- }
5511
-
5512
- private Monitor getContainingMonitor (int x , int y , int width , int height ) {
5513
- Rectangle rectangle = new Rectangle (x , y , width , height );
5514
- Monitor [] monitors = getMonitors ();
5515
- Monitor selectedMonitor = getPrimaryMonitor ();
5516
- int highestArea = 0 ;
5517
- for (Monitor currentMonitor : monitors ) {
5518
- Rectangle clientArea = currentMonitor .getClientArea ();
5519
- Rectangle intersection = clientArea .intersection (rectangle );
5520
- int area = intersection .width * intersection .height ;
5521
- if (area > highestArea ) {
5522
- selectedMonitor = currentMonitor ;
5523
- highestArea = area ;
5524
- }
5525
- }
5526
- return selectedMonitor ;
5527
- }
5528
-
5529
- private Monitor getContainingMonitorInPixelsCoordinate (int xInPixels , int yInPixels ) {
5530
- Monitor [] monitors = getMonitors ();
5531
- for (Monitor current : monitors ) {
5532
- Rectangle clientArea = getMonitorClientAreaInPixels (current );
5533
- if (clientArea .contains (xInPixels , yInPixels )) {
5534
- return current ;
5535
- }
5536
- }
5537
- return getPrimaryMonitor ();
5538
- }
5539
-
5540
- private Rectangle getMonitorClientAreaInPixels (Monitor monitor ) {
5541
- int zoom = getApplicableMonitorZoom (monitor );
5542
- int widthInPixels = DPIUtil .scaleUp (monitor .clientWidth , zoom );
5543
- int heightInPixels = DPIUtil .scaleUp (monitor .clientHeight , zoom );
5544
- return new Rectangle (monitor .clientX , monitor .clientY , widthInPixels , heightInPixels );
5545
- }
5546
-
5547
- private Point getPixelsFromPoint (Monitor monitor , int x , int y ) {
5548
- int zoom = getApplicableMonitorZoom (monitor );
5549
- int mappedX = DPIUtil .scaleUp (x - monitor .clientX , zoom ) + monitor .clientX ;
5550
- int mappedY = DPIUtil .scaleUp (y - monitor .clientY , zoom ) + monitor .clientY ;
5551
- return new Point (mappedX , mappedY );
5552
- }
5553
-
5554
- private Point getPointFromPixels (Monitor monitor , int x , int y ) {
5555
- int zoom = getApplicableMonitorZoom (monitor );
5556
- int mappedX = DPIUtil .scaleDown (x - monitor .clientX , zoom ) + monitor .clientX ;
5557
- int mappedY = DPIUtil .scaleDown (y - monitor .clientY , zoom ) + monitor .clientY ;
5558
- return new Point (mappedX , mappedY );
5559
- }
5560
5393
}
0 commit comments