1 11 package org.eclipse.ui.internal.dnd; 12 13 import org.eclipse.jface.util.Geometry; 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.graphics.Point; 16 import org.eclipse.swt.graphics.Rectangle; 17 import org.eclipse.swt.widgets.Control; 18 19 24 public class CompatibilityDragTarget { 25 26 private final static int MARGIN = 30; 28 29 38 public static int getRelativePosition(Control c, Point toTest) { 39 Point p = c.toControl(toTest); 40 Point e = c.getSize(); 41 42 if (p.x > e.x || p.y > e.y || p.x < 0 || p.y < 0) { 43 return SWT.DEFAULT; 44 } 45 46 int hmargin = Math.min(e.x / 3, MARGIN); 48 int vmargin = Math.min(e.y / 3, MARGIN); 49 50 Rectangle inner = new Rectangle(hmargin, vmargin, e.x - (hmargin * 2), 51 e.y - (vmargin * 2)); 52 if (inner.contains(p)) { 53 return SWT.CENTER; 54 } else { 55 return Geometry.getClosestSide(inner, p); 56 } 57 } 58 59 } 60 | Popular Tags |