diff options
author | Sven Gothel <[email protected]> | 2020-01-05 23:00:16 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-01-05 23:00:16 +0100 |
commit | 1216aa7bc4284e5568d7dd7bbd7f6d9fed27d25b (patch) | |
tree | 7327585c3608772e9063f6372657ddb6d70b4a15 /src/nativewindow | |
parent | 9512a4bbda02002d06fcbb34504c3bea9c7abdc8 (diff) |
Bug 1421, Bug 1358, Bug 969, Bug 672: SWTAccessor: Add get[Location|Size]InPixels(..) and getLocationOnScreen()
Diffstat (limited to 'src/nativewindow')
-rw-r--r-- | src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java index d99519878..97ffde5ee 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/swt/SWTAccessor.java @@ -28,12 +28,14 @@ package com.jogamp.nativewindow.swt; import com.jogamp.common.os.Platform; + import java.lang.reflect.Field; import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; import org.eclipse.swt.graphics.GCData; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.internal.DPIUtil; import org.eclipse.swt.widgets.Control; @@ -59,6 +61,8 @@ public class SWTAccessor { private static final boolean DEBUG = Debug.debug("SWT"); private static final Method swt_scrollable_clientAreaInPixels; + private static final Method swt_control_locationInPixels; + private static final Method swt_control_sizeInPixels; private static final Field swt_control_handle; private static final boolean swt_uses_long_handles; @@ -145,6 +149,30 @@ public class SWTAccessor { Method m = null; try { + m = Control.class.getDeclaredMethod("getLocationInPixels"); + m.setAccessible(true); + } catch (final Exception ex) { + m = null; + if( DEBUG ) { + System.err.println("getLocationInPixels not implemented: "+ex.getMessage()); + } + } + swt_control_locationInPixels = m; + + m = null; + try { + m = Control.class.getDeclaredMethod("getSizeInPixels"); + m.setAccessible(true); + } catch (final Exception ex) { + m = null; + if( DEBUG ) { + System.err.println("getSizeInPixels not implemented: "+ex.getMessage()); + } + } + swt_control_sizeInPixels = m; + + m = null; + try { m = Scrollable.class.getDeclaredMethod("getClientAreaInPixels"); m.setAccessible(true); } catch (final Exception ex) { @@ -262,7 +290,8 @@ public class SWTAccessor { isX11GTK = isX11 && null != OS_gtk_class; if(DEBUG) { - System.err.println("SWTAccessor.<init>: GTK Version: "+OS_gtk_version); + System.err.println("SWTAccessor.<init>: isX11 "+isX11+", isX11GTK "+isX11GTK+" (GTK Version: "+OS_gtk_version+")"); + System.err.println("SWTAccessor.<init>: isOSX "+isOSX+", isWindows "+isWindows); } } @@ -403,6 +432,27 @@ public class SWTAccessor { } } + public static Point getLocationInPixels(final Control c) throws NativeWindowException { + if( null == swt_control_locationInPixels ) { + return DPIUtil.autoScaleUp(c.getLocation()); + } + try { + return (Point) swt_control_locationInPixels.invoke(c); + } catch (final Throwable e) { + throw new NativeWindowException(e); + } + } + public static Point getSizeInPixels(final Control c) throws NativeWindowException { + if( null == swt_control_sizeInPixels ) { + return DPIUtil.autoScaleUp(c.getSize()); + } + try { + return (Point) swt_control_sizeInPixels.invoke(c); + } catch (final Throwable e) { + throw new NativeWindowException(e); + } + } + /** * @param swtControl the SWT Control to retrieve the native widget-handle from * @return the native widget-handle @@ -671,4 +721,27 @@ public class SWTAccessor { public static void destroyGDKWindow(final long gdkWindow) { // OS.gdk_window_destroy (gdkWindow); } + + public static com.jogamp.nativewindow.util.Point getLocationOnScreen(final com.jogamp.nativewindow.util.Point storage, + Control comp) + { + while(null != comp) { + final org.eclipse.swt.graphics.Point p = comp.getLocation(); + final int dx = p.x; + final int dy = p.y; + storage.translate(dx, dy); + comp = comp.getParent(); + } + return storage; + } + public static Control getTopControl(Control comp) + { + Control last = null; + while(null != comp) { + last = comp; + comp = comp.getParent(); + } + return last; + } + } |