|
14 | 14 | package org.eclipse.swt.dnd;
|
15 | 15 |
|
16 | 16 | import org.eclipse.swt.*;
|
| 17 | +import org.eclipse.swt.graphics.*; |
17 | 18 | import org.eclipse.swt.internal.*;
|
18 | 19 | import org.eclipse.swt.internal.ole.win32.*;
|
19 | 20 | import org.eclipse.swt.internal.win32.*;
|
@@ -281,16 +282,14 @@ int DragEnter_64(long pDataObject, int grfKeyState, long pt, long pdwEffect) {
|
281 | 282 | }
|
282 | 283 |
|
283 | 284 | int DragEnter(long pDataObject, int grfKeyState, int pt_x, int pt_y, long pdwEffect) {
|
284 |
| - int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom); |
285 |
| - pt_x = DPIUtil.scaleDown(pt_x, zoom);// To Points |
286 |
| - pt_y = DPIUtil.scaleDown(pt_y, zoom);// To Points |
| 285 | + Point location = convertPixelToPoint(pt_x, pt_y); |
287 | 286 | selectedDataType = null;
|
288 | 287 | selectedOperation = DND.DROP_NONE;
|
289 | 288 | if (iDataObject != null) iDataObject.Release();
|
290 | 289 | iDataObject = null;
|
291 | 290 |
|
292 | 291 | DNDEvent event = new DNDEvent();
|
293 |
| - if (!setEventData(event, pDataObject, grfKeyState, pt_x, pt_y, pdwEffect)) { |
| 292 | + if (!setEventData(event, pDataObject, grfKeyState, location.x, location.y, pdwEffect)) { |
294 | 293 | OS.MoveMemory(pdwEffect, new int[] {COM.DROPEFFECT_NONE}, 4);
|
295 | 294 | return COM.S_FALSE;
|
296 | 295 | }
|
@@ -349,14 +348,12 @@ int DragOver_64(int grfKeyState, long pt, long pdwEffect) {
|
349 | 348 | }
|
350 | 349 |
|
351 | 350 | int DragOver(int grfKeyState, int pt_x, int pt_y, long pdwEffect) {
|
352 |
| - int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom); |
353 |
| - pt_x = DPIUtil.scaleDown(pt_x, zoom);// To Points |
354 |
| - pt_y = DPIUtil.scaleDown(pt_y, zoom);// To Points |
| 351 | + Point location = convertPixelToPoint(pt_x, pt_y); |
355 | 352 | if (iDataObject == null) return COM.S_FALSE;
|
356 | 353 | int oldKeyOperation = keyOperation;
|
357 | 354 |
|
358 | 355 | DNDEvent event = new DNDEvent();
|
359 |
| - if (!setEventData(event, iDataObject.getAddress(), grfKeyState, pt_x, pt_y, pdwEffect)) { |
| 356 | + if (!setEventData(event, iDataObject.getAddress(), grfKeyState, location.x, location.y, pdwEffect)) { |
360 | 357 | keyOperation = -1;
|
361 | 358 | OS.MoveMemory(pdwEffect, new int[] {COM.DROPEFFECT_NONE}, 4);
|
362 | 359 | return COM.S_FALSE;
|
@@ -403,23 +400,38 @@ int Drop_64(long pDataObject, int grfKeyState, long pt, long pdwEffect) {
|
403 | 400 | return Drop(pDataObject, grfKeyState, point.x, point.y, pdwEffect);
|
404 | 401 | }
|
405 | 402 |
|
| 403 | +private Point convertPixelToPoint(int xInPixels, int yInPixels) { |
| 404 | + if (this.control == null) { |
| 405 | + // If there is no control for context, the behavior remains as before |
| 406 | + int zoom = DPIUtil.getZoomForAutoscaleProperty(this.nativeZoom); |
| 407 | + return DPIUtil.scaleDown(new Point(xInPixels, yInPixels), zoom); |
| 408 | + } |
| 409 | + int zoom = DPIUtil.getZoomForAutoscaleProperty(this.control.nativeZoom); |
| 410 | + // There is no API to convert absolute values in pixels to display relative |
| 411 | + // points. Therefor, the display relative pixel values are converted to control |
| 412 | + // relative pixel values via Windows API. These values can be scaled down to points |
| 413 | + POINT pt = new POINT (); |
| 414 | + pt.x = xInPixels; pt.y = yInPixels; |
| 415 | + OS.ScreenToClient (this.control.handle, pt); |
| 416 | + Point p = DPIUtil.scaleDown(new Point (pt.x, pt.y), zoom); |
| 417 | + return this.control.toDisplay(p); |
| 418 | +} |
| 419 | + |
406 | 420 | int Drop(long pDataObject, int grfKeyState, int pt_x, int pt_y, long pdwEffect) {
|
407 | 421 | try {
|
408 |
| - int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom); |
409 |
| - pt_x = DPIUtil.scaleDown(pt_x, zoom);// To Points |
410 |
| - pt_y = DPIUtil.scaleDown(pt_y, zoom);// To Points |
| 422 | + Point location = convertPixelToPoint(pt_x, pt_y); |
411 | 423 | DNDEvent event = new DNDEvent();
|
412 | 424 | event.widget = this;
|
413 | 425 | event.time = OS.GetMessageTime();
|
414 | 426 | if (dropEffect != null) {
|
415 |
| - event.item = dropEffect.getItem(pt_x, pt_y); |
| 427 | + event.item = dropEffect.getItem(location.x, location.y); |
416 | 428 | }
|
417 | 429 | event.detail = DND.DROP_NONE;
|
418 | 430 | notifyListeners(DND.DragLeave, event);
|
419 | 431 | refresh();
|
420 | 432 |
|
421 | 433 | event = new DNDEvent();
|
422 |
| - if (!setEventData(event, pDataObject, grfKeyState, pt_x, pt_y, pdwEffect)) { |
| 434 | + if (!setEventData(event, pDataObject, grfKeyState, location.x, location.y, pdwEffect)) { |
423 | 435 | keyOperation = -1;
|
424 | 436 | OS.MoveMemory(pdwEffect, new int[] {COM.DROPEFFECT_NONE}, 4);
|
425 | 437 | return COM.S_FALSE;
|
|
0 commit comments