diff options
| author | Sravan Kumar Lakkimsetti | 2016-02-11 11:51:54 +0000 |
|---|---|---|
| committer | Sravan Kumar Lakkimsetti | 2016-02-22 11:00:57 +0000 |
| commit | acc3aad22de4e9ad78274eb6e8ec760f1ee4c7c2 (patch) | |
| tree | fd84265b018a1a2a7b566e3a01a444719a1b3e7f | |
| parent | 0cc28848a42b0c7116a7152ca9afae53c20146ef (diff) | |
| download | eclipse.platform.swt-acc3aad22de4e9ad78274eb6e8ec760f1ee4c7c2.tar.gz eclipse.platform.swt-acc3aad22de4e9ad78274eb6e8ec760f1ee4c7c2.tar.xz eclipse.platform.swt-acc3aad22de4e9ad78274eb6e8ec760f1ee4c7c2.zip | |
Bug 399786 - GC#draw*(..) needs to support
high-DPI
Change-Id: Ibf39177432c1c29506d9226cabf65a6a16d39931
Signed-off-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
66 files changed, 5428 insertions, 583 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/org/eclipse/swt/awt/SWT_AWT.java b/bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/org/eclipse/swt/awt/SWT_AWT.java index 9852f995f3..b3b0d42c97 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/org/eclipse/swt/awt/SWT_AWT.java +++ b/bundles/org.eclipse.swt/Eclipse SWT AWT/gtk/org/eclipse/swt/awt/SWT_AWT.java @@ -19,6 +19,7 @@ import java.lang.reflect.*; /* SWT Imports */ import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; @@ -249,7 +250,7 @@ public static Frame new_Frame (final Composite parent) { }); break; case SWT.Resize: - final Rectangle clientArea = parent.getClientArea(); + final Rectangle clientArea = DPIUtil.autoScaleUp(parent.getClientArea()); EventQueue.invokeLater(new Runnable () { @Override public void run () { @@ -267,7 +268,7 @@ public static Frame new_Frame (final Composite parent) { @Override public void run () { if (parent.isDisposed()) return; - final Rectangle clientArea = parent.getClientArea(); + final Rectangle clientArea = DPIUtil.autoScaleUp(parent.getClientArea()); EventQueue.invokeLater(new Runnable () { @Override public void run () { @@ -317,7 +318,7 @@ public static Shell new_Shell (final Display display, final Canvas parent) { public void run () { if (shell.isDisposed()) return; Dimension dim = parent.getSize (); - shell.setSize (dim.width, dim.height); + shell.setSize (DPIUtil.autoScaleDown(new Point(dim.width, dim.height))); } }); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ImageTransfer.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ImageTransfer.java index aa3c1f6059..04cf42ccb0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ImageTransfer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/ImageTransfer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,7 +10,7 @@ *******************************************************************************/ package org.eclipse.swt.dnd; -import org.eclipse.swt.SWT; +import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDropTargetEffect.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDropTargetEffect.java index db76bb35c0..7dbb5dfc6b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDropTargetEffect.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/gtk/org/eclipse/swt/dnd/TableDropTargetEffect.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,6 +11,7 @@ package org.eclipse.swt.dnd; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; import org.eclipse.swt.widgets.*; @@ -152,7 +153,7 @@ public class TableDropTargetEffect extends DropTargetEffect { } else { if (index != -1 && scrollIndex == index && scrollBeginTime != 0) { if (System.currentTimeMillis() >= scrollBeginTime) { - if (coordinates.y < table.getItemHeight()) { + if (coordinates.y < DPIUtil.autoScaleUp(table.getItemHeight())) { OS.gtk_tree_path_prev(path[0]); } else { OS.gtk_tree_path_next(path[0]); diff --git a/bundles/org.eclipse.swt/Eclipse SWT OpenGL/gtk/org/eclipse/swt/opengl/GLCanvas.java b/bundles/org.eclipse.swt/Eclipse SWT OpenGL/gtk/org/eclipse/swt/opengl/GLCanvas.java index acf9111c84..247aa7f6b5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT OpenGL/gtk/org/eclipse/swt/opengl/GLCanvas.java +++ b/bundles/org.eclipse.swt/Eclipse SWT OpenGL/gtk/org/eclipse/swt/opengl/GLCanvas.java @@ -12,6 +12,7 @@ package org.eclipse.swt.opengl; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; import org.eclipse.swt.internal.opengl.glx.*; import org.eclipse.swt.widgets.*; @@ -161,7 +162,7 @@ public GLCanvas (Composite parent, int style, GLData data) { GLX.glViewport (viewport [0],viewport [1],viewport [2],viewport [3]); break; case SWT.Resize: - Rectangle clientArea = getClientArea(); + Rectangle clientArea = DPIUtil.autoScaleUp(getClientArea()); OS.gdk_window_move (glWindow, clientArea.x, clientArea.y); OS.gdk_window_resize (glWindow, clientArea.width, clientArea.height); break; diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/common/library/c.c b/bundles/org.eclipse.swt/Eclipse SWT PI/common/library/c.c index 67018e9a64..7aeca2a702 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/common/library/c.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/common/library/c.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -101,10 +101,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove__J_3BJ)(JNIEnv *env, jclass that, jintLo #else C_NATIVE_ENTER(env, that, memmove__J_3BJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1) if ((lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; + } memmove((void *)arg0, (const void *)lparg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1 && lparg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, JNI_ABORT); + } else +#endif + { + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, JNI_ABORT); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove__I_3BI_FUNC); #else @@ -126,10 +140,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove__J_3CJ)(JNIEnv *env, jclass that, jintLo #else C_NATIVE_ENTER(env, that, memmove__J_3CJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1) if ((lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg1) if ((lparg1 = (*env)->GetCharArrayElements(env, arg1, NULL)) == NULL) goto fail; + } memmove((void *)arg0, (const void *)lparg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1 && lparg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, JNI_ABORT); + } else +#endif + { + if (arg1 && lparg1) (*env)->ReleaseCharArrayElements(env, arg1, lparg1, JNI_ABORT); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove__I_3CI_FUNC); #else @@ -151,10 +179,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove__J_3DJ)(JNIEnv *env, jclass that, jintLo #else C_NATIVE_ENTER(env, that, memmove__J_3DJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1) if ((lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg1) if ((lparg1 = (*env)->GetDoubleArrayElements(env, arg1, NULL)) == NULL) goto fail; + } memmove((void *)arg0, (const void *)lparg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1 && lparg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, JNI_ABORT); + } else +#endif + { + if (arg1 && lparg1) (*env)->ReleaseDoubleArrayElements(env, arg1, lparg1, JNI_ABORT); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove__I_3DI_FUNC); #else @@ -176,10 +218,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove__J_3FJ)(JNIEnv *env, jclass that, jintLo #else C_NATIVE_ENTER(env, that, memmove__J_3FJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1) if ((lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg1) if ((lparg1 = (*env)->GetFloatArrayElements(env, arg1, NULL)) == NULL) goto fail; + } memmove((void *)arg0, (const void *)lparg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1 && lparg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, JNI_ABORT); + } else +#endif + { + if (arg1 && lparg1) (*env)->ReleaseFloatArrayElements(env, arg1, lparg1, JNI_ABORT); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove__I_3FI_FUNC); #else @@ -201,10 +257,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove__J_3IJ)(JNIEnv *env, jclass that, jintLo #else C_NATIVE_ENTER(env, that, memmove__J_3IJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1) if ((lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg1) if ((lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL)) == NULL) goto fail; + } memmove((void *)arg0, (const void *)lparg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1 && lparg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, JNI_ABORT); + } else +#endif + { + if (arg1 && lparg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, JNI_ABORT); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove__I_3II_FUNC); #else @@ -226,10 +296,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove__J_3JJ)(JNIEnv *env, jclass that, jintLo #else C_NATIVE_ENTER(env, that, memmove__J_3JJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1) if ((lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg1) if ((lparg1 = (*env)->GetLongArrayElements(env, arg1, NULL)) == NULL) goto fail; + } memmove((void *)arg0, (const void *)lparg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1 && lparg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, JNI_ABORT); + } else +#endif + { + if (arg1 && lparg1) (*env)->ReleaseLongArrayElements(env, arg1, lparg1, JNI_ABORT); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove__I_3JI_FUNC); #else @@ -251,10 +335,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove__J_3SJ)(JNIEnv *env, jclass that, jintLo #else C_NATIVE_ENTER(env, that, memmove__J_3SJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1) if ((lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg1) if ((lparg1 = (*env)->GetShortArrayElements(env, arg1, NULL)) == NULL) goto fail; + } memmove((void *)arg0, (const void *)lparg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1 && lparg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, JNI_ABORT); + } else +#endif + { + if (arg1 && lparg1) (*env)->ReleaseShortArrayElements(env, arg1, lparg1, JNI_ABORT); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove__I_3SI_FUNC); #else @@ -276,10 +374,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove___3BJJ)(JNIEnv *env, jclass that, jbyteA #else C_NATIVE_ENTER(env, that, memmove___3BJJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0) if ((lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; + } memmove((void *)lparg0, (const void *)arg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0 && lparg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, 0); + } else +#endif + { + if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove___3BII_FUNC); #else @@ -302,12 +414,28 @@ JNIEXPORT void JNICALL C_NATIVE(memmove___3B_3CJ)(JNIEnv *env, jclass that, jbyt #else C_NATIVE_ENTER(env, that, memmove___3B_3CJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0) if ((lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL)) == NULL) goto fail; if (arg1) if ((lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; + if (arg1) if ((lparg1 = (*env)->GetCharArrayElements(env, arg1, NULL)) == NULL) goto fail; + } memmove((void *)lparg0, (const void *)lparg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1 && lparg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, JNI_ABORT); if (arg0 && lparg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, 0); + } else +#endif + { + if (arg1 && lparg1) (*env)->ReleaseCharArrayElements(env, arg1, lparg1, JNI_ABORT); + if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove___3B_3CI_FUNC); #else @@ -329,10 +457,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove___3CJJ)(JNIEnv *env, jclass that, jcharA #else C_NATIVE_ENTER(env, that, memmove___3CJJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0) if ((lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg0) if ((lparg0 = (*env)->GetCharArrayElements(env, arg0, NULL)) == NULL) goto fail; + } memmove((void *)lparg0, (const void *)arg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0 && lparg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, 0); + } else +#endif + { + if (arg0 && lparg0) (*env)->ReleaseCharArrayElements(env, arg0, lparg0, 0); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove___3CII_FUNC); #else @@ -354,10 +496,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove___3DJJ)(JNIEnv *env, jclass that, jdoubl #else C_NATIVE_ENTER(env, that, memmove___3DJJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0) if ((lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg0) if ((lparg0 = (*env)->GetDoubleArrayElements(env, arg0, NULL)) == NULL) goto fail; + } memmove((void *)lparg0, (const void *)arg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0 && lparg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, 0); + } else +#endif + { + if (arg0 && lparg0) (*env)->ReleaseDoubleArrayElements(env, arg0, lparg0, 0); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove___3DII_FUNC); #else @@ -379,10 +535,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove___3FJJ)(JNIEnv *env, jclass that, jfloat #else C_NATIVE_ENTER(env, that, memmove___3FJJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0) if ((lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg0) if ((lparg0 = (*env)->GetFloatArrayElements(env, arg0, NULL)) == NULL) goto fail; + } memmove((void *)lparg0, (const void *)arg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0 && lparg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, 0); + } else +#endif + { + if (arg0 && lparg0) (*env)->ReleaseFloatArrayElements(env, arg0, lparg0, 0); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove___3FII_FUNC); #else @@ -404,10 +574,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove___3IJJ)(JNIEnv *env, jclass that, jintAr #else C_NATIVE_ENTER(env, that, memmove___3IJJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0) if ((lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg0) if ((lparg0 = (*env)->GetIntArrayElements(env, arg0, NULL)) == NULL) goto fail; + } memmove((void *)lparg0, (const void *)arg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0 && lparg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, 0); + } else +#endif + { + if (arg0 && lparg0) (*env)->ReleaseIntArrayElements(env, arg0, lparg0, 0); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove___3III_FUNC); #else @@ -431,10 +615,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove___3I_3BJ)(JNIEnv *env, jclass that, jint C_NATIVE_ENTER(env, that, memmove___3I_3BJ_FUNC); #endif if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0) if ((lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg0) if ((lparg0 = (*env)->GetIntArrayElements(env, arg0, NULL)) == NULL) goto fail; + } memmove((void *)lparg0, (const void *)lparg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0 && lparg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, 0); + } else +#endif + { + if (arg0 && lparg0) (*env)->ReleaseIntArrayElements(env, arg0, lparg0, 0); + } if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove___3I_3BI_FUNC); @@ -457,10 +655,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove___3JJJ)(JNIEnv *env, jclass that, jlongA #else C_NATIVE_ENTER(env, that, memmove___3JJJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0) if ((lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg0) if ((lparg0 = (*env)->GetLongArrayElements(env, arg0, NULL)) == NULL) goto fail; + } memmove((void *)lparg0, (const void *)arg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0 && lparg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, 0); + } else +#endif + { + if (arg0 && lparg0) (*env)->ReleaseLongArrayElements(env, arg0, lparg0, 0); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove___3JII_FUNC); #else @@ -482,10 +694,24 @@ JNIEXPORT void JNICALL C_NATIVE(memmove___3SJJ)(JNIEnv *env, jclass that, jshort #else C_NATIVE_ENTER(env, that, memmove___3SJJ_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0) if ((lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg0) if ((lparg0 = (*env)->GetShortArrayElements(env, arg0, NULL)) == NULL) goto fail; + } memmove((void *)lparg0, (const void *)arg1, (size_t)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0 && lparg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, 0); + } else +#endif + { + if (arg0 && lparg0) (*env)->ReleaseShortArrayElements(env, arg0, lparg0, 0); + } #ifndef JNI64 C_NATIVE_EXIT(env, that, memmove___3SII_FUNC); #else @@ -506,6 +732,25 @@ JNIEXPORT jintLong JNICALL C_NATIVE(memset) } #endif +#ifndef NO_setenv +JNIEXPORT jint JNICALL C_NATIVE(setenv) + (JNIEnv *env, jclass that, jbyteArray arg0, jbyteArray arg1, jint arg2) +{ + jbyte *lparg0=NULL; + jbyte *lparg1=NULL; + jint rc = 0; + C_NATIVE_ENTER(env, that, setenv_FUNC); + if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; + rc = (jint)setenv((const char *)lparg0, (const char *)lparg1, arg2); +fail: + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); + C_NATIVE_EXIT(env, that, setenv_FUNC); + return rc; +} +#endif + #ifndef NO_strlen JNIEXPORT jint JNICALL C_NATIVE(strlen) (JNIEnv *env, jclass that, jintLong arg0) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/common/library/c_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/common/library/c_stats.c index 932c91cfbd..d763ed6ea0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/common/library/c_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/common/library/c_stats.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -105,6 +105,7 @@ char * C_nativeFunctionNames[] = { "memmove___3SJJ", #endif "memset", + "setenv", "strlen", }; #define NATIVE_FUNCTION_COUNT sizeof(C_nativeFunctionNames) / sizeof(char*) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/common/library/c_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/common/library/c_stats.h index cc34b1cb8b..e0da1090fd 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/common/library/c_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/common/library/c_stats.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -115,5 +115,6 @@ typedef enum { memmove___3SJJ_FUNC, #endif memset_FUNC, + setenv_FUNC, strlen_FUNC, } C_FUNCS; diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/C.java b/bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/C.java index dcafafe853..c511494c22 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/C.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/C.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -22,6 +22,11 @@ public class C extends Platform { public static final native void free (long /*int*/ ptr); /** @param env cast=(const char *) */ public static final native long /*int*/ getenv (byte[] env); +/** + * @param env cast=(const char *) + * @param value cast=(const char *) + */ +public static final native int setenv (byte[] env, byte[] value, int overwrite); public static final native long /*int*/ malloc (long /*int*/ size); /** * @param dest cast=(void *) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh index 020c87eb18..62fee7823c 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/build.sh @@ -145,7 +145,7 @@ case $SWT_OS.$SWT_ARCH in export CC=gcc fi if [ "${JAVA_HOME}" = "" ]; then - export JAVA_HOME="/bluebird/teamswt/swt-builddir/JDKs/x86_64/jdk1.5.0" + export JAVA_HOME="/home/sravanl/EclipseDev/jdk1.8.0_71" fi if [ "${PKG_CONFIG_PATH}" = "" ]; then export PKG_CONFIG_PATH="/usr/lib64/pkgconfig" @@ -566,5 +566,5 @@ fi if [ "x${1}" = "xclean" ]; then ${MAKE_TYPE} -f $MAKEFILE clean else - ${MAKE_TYPE} -f $MAKEFILE all $MAKE_GNOME $MAKE_CAIRO $MAKE_AWT $MAKE_MOZILLA ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} + ${MAKE_TYPE} -f $MAKEFILE all ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} fi diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_linux.mak b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_linux.mak index 9d3aa874e7..b63febddb5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_linux.mak +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_linux.mak @@ -131,7 +131,7 @@ ifndef NO_STRIP LFLAGS := $(LFLAGS) -s endif -all: make_swt make_atk make_glx make_webkit +all: make_swt # # SWT libs diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c index 64e39f39c8..75020cd5dd 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c @@ -3861,6 +3861,129 @@ fail: } #endif +#ifndef NO__1g_1settings_1get +JNIEXPORT void JNICALL OS_NATIVE(_1g_1settings_1get) + (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1, jbyteArray arg2, jbyteArray arg3, jintArray arg4) +{ + jbyte *lparg1=NULL; + jbyte *lparg2=NULL; + jbyte *lparg3=NULL; + jint *lparg4=NULL; + OS_NATIVE_ENTER(env, that, _1g_1settings_1get_FUNC); + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; + if (arg2) if ((lparg2 = (*env)->GetByteArrayElements(env, arg2, NULL)) == NULL) goto fail; + if (arg3) if ((lparg3 = (*env)->GetByteArrayElements(env, arg3, NULL)) == NULL) goto fail; + if (arg4) if ((lparg4 = (*env)->GetIntArrayElements(env, arg4, NULL)) == NULL) goto fail; +/* + g_settings_get((GSettings *)arg0, (const gchar *)lparg1, lparg2, lparg3, lparg4); +*/ + { + OS_LOAD_FUNCTION(fp, g_settings_get) + if (fp) { + ((void (CALLING_CONVENTION*)(GSettings *, const gchar *, jbyte *, jbyte *, jint *))fp)((GSettings *)arg0, (const gchar *)lparg1, lparg2, lparg3, lparg4); + } + } +fail: + if (arg4 && lparg4) (*env)->ReleaseIntArrayElements(env, arg4, lparg4, 0); + if (arg3 && lparg3) (*env)->ReleaseByteArrayElements(env, arg3, lparg3, 0); + if (arg2 && lparg2) (*env)->ReleaseByteArrayElements(env, arg2, lparg2, 0); + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + OS_NATIVE_EXIT(env, that, _1g_1settings_1get_FUNC); +} +#endif + +#ifndef NO__1g_1settings_1get_1value +JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1settings_1get_1value) + (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1) +{ + jbyte *lparg1=NULL; + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1g_1settings_1get_1value_FUNC); + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; +/* + rc = (jintLong)g_settings_get_value((GSettings *)arg0, (const gchar *)lparg1); +*/ + { + OS_LOAD_FUNCTION(fp, g_settings_get_value) + if (fp) { + rc = (jintLong)((jintLong (CALLING_CONVENTION*)(GSettings *, const gchar *))fp)((GSettings *)arg0, (const gchar *)lparg1); + } + } +fail: + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + OS_NATIVE_EXIT(env, that, _1g_1settings_1get_1value_FUNC); + return rc; +} +#endif + +#ifndef NO__1g_1settings_1new +JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1settings_1new) + (JNIEnv *env, jclass that, jbyteArray arg0) +{ + jbyte *lparg0=NULL; + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1g_1settings_1new_FUNC); + if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; +/* + rc = (jintLong)g_settings_new((const gchar *)lparg0); +*/ + { + OS_LOAD_FUNCTION(fp, g_settings_new) + if (fp) { + rc = (jintLong)((jintLong (CALLING_CONVENTION*)(const gchar *))fp)((const gchar *)lparg0); + } + } +fail: + if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); + OS_NATIVE_EXIT(env, that, _1g_1settings_1new_FUNC); + return rc; +} +#endif + +#ifndef NO__1g_1settings_1schema_1source_1get_1default +JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1settings_1schema_1source_1get_1default) + (JNIEnv *env, jclass that) +{ + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1g_1settings_1schema_1source_1get_1default_FUNC); +/* + rc = (jintLong)g_settings_schema_source_get_default(); +*/ + { + OS_LOAD_FUNCTION(fp, g_settings_schema_source_get_default) + if (fp) { + rc = (jintLong)((jintLong (CALLING_CONVENTION*)())fp)(); + } + } + OS_NATIVE_EXIT(env, that, _1g_1settings_1schema_1source_1get_1default_FUNC); + return rc; +} +#endif + +#ifndef NO__1g_1settings_1schema_1source_1lookup +JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1settings_1schema_1source_1lookup) + (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1, jboolean arg2) +{ + jbyte *lparg1=NULL; + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1g_1settings_1schema_1source_1lookup_FUNC); + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; +/* + rc = (jintLong)g_settings_schema_source_lookup((GSettingsSchemaSource *)arg0, (const gchar *)lparg1, (gboolean)arg2); +*/ + { + OS_LOAD_FUNCTION(fp, g_settings_schema_source_lookup) + if (fp) { + rc = (jintLong)((jintLong (CALLING_CONVENTION*)(GSettingsSchemaSource *, const gchar *, gboolean))fp)((GSettingsSchemaSource *)arg0, (const gchar *)lparg1, (gboolean)arg2); + } + } +fail: + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + OS_NATIVE_EXIT(env, that, _1g_1settings_1schema_1source_1lookup_FUNC); + return rc; +} +#endif + #ifndef NO__1g_1signal_1add_1emission_1hook JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1signal_1add_1emission_1hook) (JNIEnv *env, jclass that, jint arg0, jint arg1, jintLong arg2, jintLong arg3, jintLong arg4) @@ -4476,16 +4599,36 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf16_1to_1utf8) jintLong *lparg4=NULL; jintLong rc = 0; OS_NATIVE_ENTER(env, that, _1g_1utf16_1to_1utf8_FUNC); +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0) if ((lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL)) == NULL) goto fail; if (arg2) if ((lparg2 = (*env)->GetPrimitiveArrayCritical(env, arg2, NULL)) == NULL) goto fail; if (arg3) if ((lparg3 = (*env)->GetPrimitiveArrayCritical(env, arg3, NULL)) == NULL) goto fail; if (arg4) if ((lparg4 = (*env)->GetPrimitiveArrayCritical(env, arg4, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg0) if ((lparg0 = (*env)->GetCharArrayElements(env, arg0, NULL)) == NULL) goto fail; + if (arg2) if ((lparg2 = (*env)->GetIntLongArrayElements(env, arg2, NULL)) == NULL) goto fail; + if (arg3) if ((lparg3 = (*env)->GetIntLongArrayElements(env, arg3, NULL)) == NULL) goto fail; + if (arg4) if ((lparg4 = (*env)->GetIntLongArrayElements(env, arg4, NULL)) == NULL) goto fail; + } rc = (jintLong)g_utf16_to_utf8((const gunichar2 *)lparg0, (glong)arg1, (glong *)lparg2, (glong *)lparg3, (GError **)lparg4); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg4 && lparg4) (*env)->ReleasePrimitiveArrayCritical(env, arg4, lparg4, 0); if (arg3 && lparg3) (*env)->ReleasePrimitiveArrayCritical(env, arg3, lparg3, 0); if (arg2 && lparg2) (*env)->ReleasePrimitiveArrayCritical(env, arg2, lparg2, 0); if (arg0 && lparg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, JNI_ABORT); + } else +#endif + { + if (arg4 && lparg4) (*env)->ReleaseIntLongArrayElements(env, arg4, lparg4, 0); + if (arg3 && lparg3) (*env)->ReleaseIntLongArrayElements(env, arg3, lparg3, 0); + if (arg2 && lparg2) (*env)->ReleaseIntLongArrayElements(env, arg2, lparg2, 0); + if (arg0 && lparg0) (*env)->ReleaseCharArrayElements(env, arg0, lparg0, JNI_ABORT); + } OS_NATIVE_EXIT(env, that, _1g_1utf16_1to_1utf8_FUNC); return rc; } @@ -4543,14 +4686,32 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf8_1to_1utf16__JJ_3J_3J_3J)(JNIEnv * #else OS_NATIVE_ENTER(env, that, _1g_1utf8_1to_1utf16__JJ_3J_3J_3J_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg2) if ((lparg2 = (*env)->GetPrimitiveArrayCritical(env, arg2, NULL)) == NULL) goto fail; if (arg3) if ((lparg3 = (*env)->GetPrimitiveArrayCritical(env, arg3, NULL)) == NULL) goto fail; if (arg4) if ((lparg4 = (*env)->GetPrimitiveArrayCritical(env, arg4, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg2) if ((lparg2 = (*env)->GetIntLongArrayElements(env, arg2, NULL)) == NULL) goto fail; + if (arg3) if ((lparg3 = (*env)->GetIntLongArrayElements(env, arg3, NULL)) == NULL) goto fail; + if (arg4) if ((lparg4 = (*env)->GetIntLongArrayElements(env, arg4, NULL)) == NULL) goto fail; + } rc = (jintLong)g_utf8_to_utf16((const gchar *)arg0, (glong)arg1, (glong *)lparg2, (glong *)lparg3, (GError **)lparg4); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg4 && lparg4) (*env)->ReleasePrimitiveArrayCritical(env, arg4, lparg4, 0); if (arg3 && lparg3) (*env)->ReleasePrimitiveArrayCritical(env, arg3, lparg3, 0); if (arg2 && lparg2) (*env)->ReleasePrimitiveArrayCritical(env, arg2, lparg2, 0); + } else +#endif + { + if (arg4 && lparg4) (*env)->ReleaseIntLongArrayElements(env, arg4, lparg4, 0); + if (arg3 && lparg3) (*env)->ReleaseIntLongArrayElements(env, arg3, lparg3, 0); + if (arg2 && lparg2) (*env)->ReleaseIntLongArrayElements(env, arg2, lparg2, 0); + } #ifndef JNI64 OS_NATIVE_EXIT(env, that, _1g_1utf8_1to_1utf16__II_3I_3I_3I_FUNC); #else @@ -4577,16 +4738,36 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1utf8_1to_1utf16___3BJ_3J_3J_3J)(JNIEnv #else OS_NATIVE_ENTER(env, that, _1g_1utf8_1to_1utf16___3BJ_3J_3J_3J_FUNC); #endif +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0) if ((lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL)) == NULL) goto fail; if (arg2) if ((lparg2 = (*env)->GetPrimitiveArrayCritical(env, arg2, NULL)) == NULL) goto fail; if (arg3) if ((lparg3 = (*env)->GetPrimitiveArrayCritical(env, arg3, NULL)) == NULL) goto fail; if (arg4) if ((lparg4 = (*env)->GetPrimitiveArrayCritical(env, arg4, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; + if (arg2) if ((lparg2 = (*env)->GetIntLongArrayElements(env, arg2, NULL)) == NULL) goto fail; + if (arg3) if ((lparg3 = (*env)->GetIntLongArrayElements(env, arg3, NULL)) == NULL) goto fail; + if (arg4) if ((lparg4 = (*env)->GetIntLongArrayElements(env, arg4, NULL)) == NULL) goto fail; + } rc = (jintLong)g_utf8_to_utf16((const gchar *)lparg0, (glong)arg1, (glong *)lparg2, (glong *)lparg3, (GError **)lparg4); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg4 && lparg4) (*env)->ReleasePrimitiveArrayCritical(env, arg4, lparg4, 0); if (arg3 && lparg3) (*env)->ReleasePrimitiveArrayCritical(env, arg3, lparg3, 0); if (arg2 && lparg2) (*env)->ReleasePrimitiveArrayCritical(env, arg2, lparg2, 0); if (arg0 && lparg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, JNI_ABORT); + } else +#endif + { + if (arg4 && lparg4) (*env)->ReleaseIntLongArrayElements(env, arg4, lparg4, 0); + if (arg3 && lparg3) (*env)->ReleaseIntLongArrayElements(env, arg3, lparg3, 0); + if (arg2 && lparg2) (*env)->ReleaseIntLongArrayElements(env, arg2, lparg2, 0); + if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, JNI_ABORT); + } #ifndef JNI64 OS_NATIVE_EXIT(env, that, _1g_1utf8_1to_1utf16___3BI_3I_3I_3I_FUNC); #else @@ -4608,6 +4789,30 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1value_1peek_1pointer) } #endif +#ifndef NO__1g_1variant_1dict_1lookup_1value +JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1variant_1dict_1lookup_1value) + (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1, jintLong arg2) +{ + jbyte *lparg1=NULL; + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1g_1variant_1dict_1lookup_1value_FUNC); + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; +/* + rc = (jintLong)g_variant_dict_lookup_value((GVariant *)arg0, (const gchar *)lparg1, (const GVariantType *)arg2); +*/ + { + OS_LOAD_FUNCTION(fp, g_variant_dict_lookup_value) + if (fp) { + rc = (jintLong)((jintLong (CALLING_CONVENTION*)(GVariant *, const gchar *, const GVariantType *))fp)((GVariant *)arg0, (const gchar *)lparg1, (const GVariantType *)arg2); + } + } +fail: + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + OS_NATIVE_EXIT(env, that, _1g_1variant_1dict_1lookup_1value_FUNC); + return rc; +} +#endif + #ifndef NO__1g_1variant_1get_1boolean JNIEXPORT jboolean JNICALL OS_NATIVE(_1g_1variant_1get_1boolean) (JNIEnv *env, jclass that, jintLong arg0) @@ -4776,6 +4981,108 @@ fail: } #endif +#ifndef NO__1g_1variant_1iter_1free +JNIEXPORT void JNICALL OS_NATIVE(_1g_1variant_1iter_1free) + (JNIEnv *env, jclass that, jintLong arg0) +{ + OS_NATIVE_ENTER(env, that, _1g_1variant_1iter_1free_FUNC); +/* + g_variant_iter_free((GVariantIter *)arg0); +*/ + { + OS_LOAD_FUNCTION(fp, g_variant_iter_free) + if (fp) { + ((void (CALLING_CONVENTION*)(GVariantIter *))fp)((GVariantIter *)arg0); + } + } + OS_NATIVE_EXIT(env, that, _1g_1variant_1iter_1free_FUNC); +} +#endif + +#ifndef NO__1g_1variant_1iter_1init +JNIEXPORT jint JNICALL OS_NATIVE(_1g_1variant_1iter_1init) + (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1) +{ + jint rc = 0; + OS_NATIVE_ENTER(env, that, _1g_1variant_1iter_1init_FUNC); +/* + rc = (jint)g_variant_iter_init((GVariantIter *)arg0, (GVariant *)arg1); +*/ + { + OS_LOAD_FUNCTION(fp, g_variant_iter_init) + if (fp) { + rc = (jint)((jint (CALLING_CONVENTION*)(GVariantIter *, GVariant *))fp)((GVariantIter *)arg0, (GVariant *)arg1); + } + } + OS_NATIVE_EXIT(env, that, _1g_1variant_1iter_1init_FUNC); + return rc; +} +#endif + +#ifndef NO__1g_1variant_1iter_1new +JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1variant_1iter_1new) + (JNIEnv *env, jclass that, jintLong arg0) +{ + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1g_1variant_1iter_1new_FUNC); +/* + rc = (jintLong)g_variant_iter_new((GVariant *)arg0); +*/ + { + OS_LOAD_FUNCTION(fp, g_variant_iter_new) + if (fp) { + rc = (jintLong)((jintLong (CALLING_CONVENTION*)(GVariant *))fp)((GVariant *)arg0); + } + } + OS_NATIVE_EXIT(env, that, _1g_1variant_1iter_1new_FUNC); + return rc; +} +#endif + +#ifndef NO__1g_1variant_1iter_1next +JNIEXPORT jboolean JNICALL OS_NATIVE(_1g_1variant_1iter_1next) + (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1, jintLong arg2, jintLong arg3) +{ + jbyte *lparg1=NULL; + jboolean rc = 0; + OS_NATIVE_ENTER(env, that, _1g_1variant_1iter_1next_FUNC); + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; +/* + rc = (jboolean)g_variant_iter_next((const GVariantIter *)arg0, lparg1, (gchar *)arg2, arg3); +*/ + { + OS_LOAD_FUNCTION(fp, g_variant_iter_next) + if (fp) { + rc = (jboolean)((jboolean (CALLING_CONVENTION*)(const GVariantIter *, jbyte *, gchar *, jintLong))fp)((const GVariantIter *)arg0, lparg1, (gchar *)arg2, arg3); + } + } +fail: + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + OS_NATIVE_EXIT(env, that, _1g_1variant_1iter_1next_FUNC); + return rc; +} +#endif + +#ifndef NO__1g_1variant_1iter_1next_1value +JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1variant_1iter_1next_1value) + (JNIEnv *env, jclass that, jintLong arg0) +{ + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1g_1variant_1iter_1next_1value_FUNC); +/* + rc = (jintLong)g_variant_iter_next_value((const GVariantIter *)arg0); +*/ + { + OS_LOAD_FUNCTION(fp, g_variant_iter_next_value) + if (fp) { + rc = (jintLong)((jintLong (CALLING_CONVENTION*)(const GVariantIter *))fp)((const GVariantIter *)arg0); + } + } + OS_NATIVE_EXIT(env, that, _1g_1variant_1iter_1next_1value_FUNC); + return rc; +} +#endif + #ifndef NO__1g_1variant_1n_1children JNIEXPORT jlong JNICALL OS_NATIVE(_1g_1variant_1n_1children) (JNIEnv *env, jclass that, jlong arg0) @@ -4968,6 +5275,44 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1variant_1new_1uint64) } #endif +#ifndef NO__1g_1variant_1print +JNIEXPORT jintLong JNICALL OS_NATIVE(_1g_1variant_1print) + (JNIEnv *env, jclass that, jintLong arg0) +{ + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1g_1variant_1print_FUNC); +/* + rc = (jintLong)g_variant_print((const GVariant *)arg0); +*/ + { + OS_LOAD_FUNCTION(fp, g_variant_print) + if (fp) { + rc = (jintLong)((jintLong (CALLING_CONVENTION*)(const GVariant *))fp)((const GVariant *)arg0); + } + } + OS_NATIVE_EXIT(env, that, _1g_1variant_1print_FUNC); + return rc; +} +#endif + +#ifndef NO__1g_1variant_1unref +JNIEXPORT void JNICALL OS_NATIVE(_1g_1variant_1unref) + (JNIEnv *env, jclass that, jintLong arg0) +{ + OS_NATIVE_ENTER(env, that, _1g_1variant_1unref_FUNC); +/* + g_variant_unref((GVariant *)arg0); +*/ + { + OS_LOAD_FUNCTION(fp, g_variant_unref) + if (fp) { + ((void (CALLING_CONVENTION*)(GVariant *))fp)((GVariant *)arg0); + } + } + OS_NATIVE_EXIT(env, that, _1g_1variant_1unref_FUNC); +} +#endif + #ifndef NO__1gdk_1atom_1intern JNIEXPORT jintLong JNICALL OS_NATIVE(_1gdk_1atom_1intern) (JNIEnv *env, jclass that, jbyteArray arg0, jboolean arg1) @@ -4975,10 +5320,24 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1gdk_1atom_1intern) jbyte *lparg0=NULL; jintLong rc = 0; OS_NATIVE_ENTER(env, that, _1gdk_1atom_1intern_FUNC); +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0) if ((lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; + } rc = (jintLong)gdk_atom_intern((const gchar *)lparg0, arg1); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0 && lparg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, JNI_ABORT); + } else +#endif + { + if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, JNI_ABORT); + } OS_NATIVE_EXIT(env, that, _1gdk_1atom_1intern_FUNC); return rc; } @@ -5013,7 +5372,14 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1gdk_1bitmap_1create_1from_1data) jbyte *lparg1=NULL; jintLong rc = 0; OS_NATIVE_ENTER(env, that, _1gdk_1bitmap_1create_1from_1data_FUNC); +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1) if ((lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; + } /* rc = (jintLong)gdk_bitmap_create_from_data((GdkWindow *)arg0, (const gchar *)lparg1, (gint)arg2, (gint)arg3); */ @@ -5024,7 +5390,14 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1gdk_1bitmap_1create_1from_1data) } } fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1 && lparg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, JNI_ABORT); + } else +#endif + { + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, JNI_ABORT); + } OS_NATIVE_EXIT(env, that, _1gdk_1bitmap_1create_1from_1data_FUNC); return rc; } @@ -5773,7 +6146,14 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1draw_1lines) { jint *lparg2=NULL; OS_NATIVE_ENTER(env, that, _1gdk_1draw_1lines_FUNC); +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg2) if ((lparg2 = (*env)->GetPrimitiveArrayCritical(env, arg2, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail; + } /* gdk_draw_lines(arg0, arg1, (GdkPoint *)lparg2, (gint)arg3); */ @@ -5784,7 +6164,14 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1draw_1lines) } } fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg2 && lparg2) (*env)->ReleasePrimitiveArrayCritical(env, arg2, lparg2, JNI_ABORT); + } else +#endif + { + if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, JNI_ABORT); + } OS_NATIVE_EXIT(env, that, _1gdk_1draw_1lines_FUNC); } #endif @@ -5831,7 +6218,14 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1draw_1polygon) { jint *lparg3=NULL; OS_NATIVE_ENTER(env, that, _1gdk_1draw_1polygon_FUNC); +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg3) if ((lparg3 = (*env)->GetPrimitiveArrayCritical(env, arg3, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg3) if ((lparg3 = (*env)->GetIntArrayElements(env, arg3, NULL)) == NULL) goto fail; + } /* gdk_draw_polygon(arg0, arg1, arg2, lparg3, arg4); */ @@ -5842,7 +6236,14 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1draw_1polygon) } } fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg3 && lparg3) (*env)->ReleasePrimitiveArrayCritical(env, arg3, lparg3, JNI_ABORT); + } else +#endif + { + if (arg3 && lparg3) (*env)->ReleaseIntArrayElements(env, arg3, lparg3, JNI_ABORT); + } OS_NATIVE_EXIT(env, that, _1gdk_1draw_1polygon_FUNC); } #endif @@ -5912,8 +6313,16 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1drawable_1get_1size) jint *lparg1=NULL; jint *lparg2=NULL; OS_NATIVE_ENTER(env, that, _1gdk_1drawable_1get_1size_FUNC); +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1) if ((lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL)) == NULL) goto fail; if (arg2) if ((lparg2 = (*env)->GetPrimitiveArrayCritical(env, arg2, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg1) if ((lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL)) == NULL) goto fail; + if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail; + } /* gdk_drawable_get_size(arg0, (gint *)lparg1, (gint *)lparg2); */ @@ -5924,8 +6333,16 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1drawable_1get_1size) } } fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg2 && lparg2) (*env)->ReleasePrimitiveArrayCritical(env, arg2, lparg2, 0); if (arg1 && lparg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, 0); + } else +#endif + { + if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); + if (arg1 && lparg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0); + } OS_NATIVE_EXIT(env, that, _1gdk_1drawable_1get_1size_FUNC); } #endif @@ -6257,7 +6674,14 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1gc_1set_1dashes) { jbyte *lparg2=NULL; OS_NATIVE_ENTER(env, that, _1gdk_1gc_1set_1dashes_FUNC); +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg2) if ((lparg2 = (*env)->GetPrimitiveArrayCritical(env, arg2, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg2) if ((lparg2 = (*env)->GetByteArrayElements(env, arg2, NULL)) == NULL) goto fail; + } /* gdk_gc_set_dashes(arg0, (gint)arg1, (gint8 *)lparg2, (gint)arg3); */ @@ -6268,7 +6692,14 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1gc_1set_1dashes) } } fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg2 && lparg2) (*env)->ReleasePrimitiveArrayCritical(env, arg2, lparg2, JNI_ABORT); + } else +#endif + { + if (arg2 && lparg2) (*env)->ReleaseByteArrayElements(env, arg2, lparg2, JNI_ABORT); + } OS_NATIVE_EXIT(env, that, _1gdk_1gc_1set_1dashes_FUNC); } #endif @@ -6876,8 +7307,16 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1pixmap_1get_1size) jint *lparg1=NULL; jint *lparg2=NULL; OS_NATIVE_ENTER(env, that, _1gdk_1pixmap_1get_1size_FUNC); +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1) if ((lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL)) == NULL) goto fail; if (arg2) if ((lparg2 = (*env)->GetPrimitiveArrayCritical(env, arg2, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg1) if ((lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL)) == NULL) goto fail; + if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail; + } /* gdk_pixmap_get_size(arg0, (gint *)lparg1, (gint *)lparg2); */ @@ -6888,8 +7327,16 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1pixmap_1get_1size) } } fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg2 && lparg2) (*env)->ReleasePrimitiveArrayCritical(env, arg2, lparg2, 0); if (arg1 && lparg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, 0); + } else +#endif + { + if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0); + if (arg1 && lparg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0); + } OS_NATIVE_EXIT(env, that, _1gdk_1pixmap_1get_1size_FUNC); } #endif @@ -20276,10 +20723,24 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1pango_1font_1description_1from_1string) jbyte *lparg0=NULL; jintLong rc = 0; OS_NATIVE_ENTER(env, that, _1pango_1font_1description_1from_1string_FUNC); +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0) if ((lparg0 = (*env)->GetPrimitiveArrayCritical(env, arg0, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; + } rc = (jintLong)pango_font_description_from_string((const char *)lparg0); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg0 && lparg0) (*env)->ReleasePrimitiveArrayCritical(env, arg0, lparg0, JNI_ABORT); + } else +#endif + { + if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, JNI_ABORT); + } OS_NATIVE_EXIT(env, that, _1pango_1font_1description_1from_1string_FUNC); return rc; } @@ -20375,10 +20836,24 @@ JNIEXPORT void JNICALL OS_NATIVE(_1pango_1font_1description_1set_1family) { jbyte *lparg1=NULL; OS_NATIVE_ENTER(env, that, _1pango_1font_1description_1set_1family_FUNC); +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1) if ((lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; + } pango_font_description_set_family((PangoFontDescription *)arg0, (const char *)lparg1); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1 && lparg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, JNI_ABORT); + } else +#endif + { + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, JNI_ABORT); + } OS_NATIVE_EXIT(env, that, _1pango_1font_1description_1set_1family_FUNC); } #endif @@ -21086,10 +21561,24 @@ JNIEXPORT void JNICALL OS_NATIVE(_1pango_1layout_1set_1text) { jbyte *lparg1=NULL; OS_NATIVE_ENTER(env, that, _1pango_1layout_1set_1text_FUNC); +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1) if ((lparg1 = (*env)->GetPrimitiveArrayCritical(env, arg1, NULL)) == NULL) goto fail; + } else +#endif + { + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; + } pango_layout_set_text((PangoLayout *)arg0, (const char *)lparg1, (int)arg2); fail: +#ifdef JNI_VERSION_1_2 + if (IS_JNI_1_2) { if (arg1 && lparg1) (*env)->ReleasePrimitiveArrayCritical(env, arg1, lparg1, JNI_ABORT); + } else +#endif + { + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, JNI_ABORT); + } OS_NATIVE_EXIT(env, that, _1pango_1layout_1set_1text_FUNC); } #endif diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h index 7a27475a96..9b3b2b421e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2000, 2015 IBM Corporation and others. All rights reserved. +* Copyright (c) 2000, 2016 IBM Corporation and others. All rights reserved. * The contents of this file are made available under the terms * of the GNU Lesser General Public License (LGPL) Version 2.1 that * accompanies this distribution (lgpl-v21.txt). The LGPL is also @@ -500,6 +500,19 @@ #define g_icon_to_string_LIB LIB_GIO #define g_icon_new_for_string_LIB LIB_GIO #define g_file_query_info_LIB LIB_GIO +#define g_settings_get_LIB LIB_GIO +#define g_settings_new_LIB LIB_GIO +#define g_settings_get_value_LIB LIB_GIO +#define g_variant_dict_lookup_value_LIB LIB_GIO +#define g_variant_iter_next_LIB LIB_GIO +#define g_variant_iter_next_value_LIB LIB_GIO +#define g_variant_iter_init_LIB LIB_GIO +#define g_variant_iter_free_LIB LIB_GIO +#define g_variant_iter_new_LIB LIB_GIO +#define g_variant_unref_LIB LIB_GIO +#define g_variant_print_LIB LIB_GIO +#define g_settings_schema_source_get_default_LIB LIB_GIO +#define g_settings_schema_source_lookup_LIB LIB_GIO // GTK3 only #define gtk_widget_draw_LIB LIB_GTK diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c index 5d77479bbe..03567a00ff 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c @@ -331,6 +331,11 @@ char * OS_nativeFunctionNames[] = { "_1g_1object_1unref", "_1g_1quark_1from_1string", "_1g_1set_1prgname", + "_1g_1settings_1get", + "_1g_1settings_1get_1value", + "_1g_1settings_1new", + "_1g_1settings_1schema_1source_1get_1default", + "_1g_1settings_1schema_1source_1lookup", "_1g_1signal_1add_1emission_1hook", "_1g_1signal_1connect", "_1g_1signal_1connect_1closure", @@ -409,6 +414,7 @@ char * OS_nativeFunctionNames[] = { "_1g_1utf8_1to_1utf16___3BJ_3J_3J_3J", #endif "_1g_1value_1peek_1pointer", + "_1g_1variant_1dict_1lookup_1value", "_1g_1variant_1get_1boolean", "_1g_1variant_1get_1child_1value", "_1g_1variant_1get_1double", @@ -417,6 +423,11 @@ char * OS_nativeFunctionNames[] = { "_1g_1variant_1get_1type_1string", "_1g_1variant_1get_1uint64", "_1g_1variant_1is_1of_1type", + "_1g_1variant_1iter_1free", + "_1g_1variant_1iter_1init", + "_1g_1variant_1iter_1new", + "_1g_1variant_1iter_1next", + "_1g_1variant_1iter_1next_1value", "_1g_1variant_1n_1children", "_1g_1variant_1new_1boolean", "_1g_1variant_1new_1byte", @@ -426,6 +437,8 @@ char * OS_nativeFunctionNames[] = { "_1g_1variant_1new_1string", "_1g_1variant_1new_1tuple", "_1g_1variant_1new_1uint64", + "_1g_1variant_1print", + "_1g_1variant_1unref", "_1gdk_1atom_1intern", "_1gdk_1atom_1name", "_1gdk_1beep", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h index a0a30b7684..08f75daf3c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h @@ -341,6 +341,11 @@ typedef enum { _1g_1object_1unref_FUNC, _1g_1quark_1from_1string_FUNC, _1g_1set_1prgname_FUNC, + _1g_1settings_1get_FUNC, + _1g_1settings_1get_1value_FUNC, + _1g_1settings_1new_FUNC, + _1g_1settings_1schema_1source_1get_1default_FUNC, + _1g_1settings_1schema_1source_1lookup_FUNC, _1g_1signal_1add_1emission_1hook_FUNC, _1g_1signal_1connect_FUNC, _1g_1signal_1connect_1closure_FUNC, @@ -419,6 +424,7 @@ typedef enum { _1g_1utf8_1to_1utf16___3BJ_3J_3J_3J_FUNC, #endif _1g_1value_1peek_1pointer_FUNC, + _1g_1variant_1dict_1lookup_1value_FUNC, _1g_1variant_1get_1boolean_FUNC, _1g_1variant_1get_1child_1value_FUNC, _1g_1variant_1get_1double_FUNC, @@ -427,6 +433,11 @@ typedef enum { _1g_1variant_1get_1type_1string_FUNC, _1g_1variant_1get_1uint64_FUNC, _1g_1variant_1is_1of_1type_FUNC, + _1g_1variant_1iter_1free_FUNC, + _1g_1variant_1iter_1init_FUNC, + _1g_1variant_1iter_1new_FUNC, + _1g_1variant_1iter_1next_FUNC, + _1g_1variant_1iter_1next_1value_FUNC, _1g_1variant_1n_1children_FUNC, _1g_1variant_1new_1boolean_FUNC, _1g_1variant_1new_1byte_FUNC, @@ -436,6 +447,8 @@ typedef enum { _1g_1variant_1new_1string_FUNC, _1g_1variant_1new_1tuple_FUNC, _1g_1variant_1new_1uint64_FUNC, + _1g_1variant_1print_FUNC, + _1g_1variant_1unref_FUNC, _1gdk_1atom_1intern_FUNC, _1gdk_1atom_1name_FUNC, _1gdk_1beep_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java index d3e52c338c..521b6a82c3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. All rights reserved. + * Copyright (c) 2000, 2016 IBM Corporation and others. All rights reserved. * The contents of this file are made available under the terms * of the GNU Lesser General Public License (LGPL) Version 2.1 that * accompanies this distribution (lgpl-v21.txt). The LGPL is also @@ -20,6 +20,8 @@ import org.eclipse.swt.internal.cairo.*; public class OS extends C { static { + String scalingProperty = "GDK_SCALE"; + OS.setenv(ascii(scalingProperty), ascii("1"), 1); String propertyName = "SWT_GTK3"; String gtk3 = getEnvironmentalVariable (propertyName); if (gtk3 != null && gtk3.equals("0")) { @@ -17059,4 +17061,189 @@ public static final void setDarkThemePreferred(boolean preferred){ g_object_notify(gtk_settings_get_default(), gtk_application_prefer_dark_theme); } + +/** + * @method flags=dynamic + * @param schema_id cast=(const gchar *) + */ +public static final native long /*int*/ _g_settings_new (byte[] schema_id); +public static final long /*int*/ g_settings_new (byte[] schema_id) { + lock.lock(); + try { + return _g_settings_new (schema_id); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + * @param settings cast=(GSettings *) + * @param key cast=(const gchar *) + * @param format = (const gchar *) + * @param monitorId = (const gchar *) + * @param scalingfactor = (gint *) + */ +public static final native void _g_settings_get (long /*int*/ settings, byte[] key, byte[] format, byte[] monitorId, int[] scalingfactor); +public static final void g_settings_get (long /*int*/ settings, byte[] key, byte[] format, byte[] monitorId, int[] scalingfactor) { + lock.lock(); + try { + _g_settings_get (settings, key, format, monitorId, scalingfactor); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + * @param settings cast=(GSettings *) + * @param key cast=(const gchar *) + */ +public static final native long /*int*/ _g_settings_get_value (long /*int*/ settings, byte[] key); +public static final long /*int*/ g_settings_get_value (long /*int*/ settings, byte[] key) { + lock.lock(); + try { + return _g_settings_get_value (settings, key); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + * @param variant cast=(GVariant *) + * @param key cast=(const gchar *) + * @param expectedType cast=(const GVariantType *) + */ +public static final native long /*int*/ _g_variant_dict_lookup_value (long /*int*/ variant, byte[] key, long /*int*/ expectedType); +public static final long /*int*/ g_variant_dict_lookup_value (long /*int*/ variant, byte[] key, long /*int*/ expectedType) { + lock.lock(); + try { + return _g_variant_dict_lookup_value (variant, key, expectedType); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + * @param variant cast=(GVariant *) + */ +public static final native long /*int*/ _g_variant_iter_new (long /*int*/ variant); +public static final long /*int*/ g_variant_iter_new (long /*int*/ variant) { + lock.lock(); + try { + return _g_variant_iter_new (variant); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + * @param variant cast=(GVariantIter *) + */ +public static final native void _g_variant_iter_free (long /*int*/ variant); +public static final void g_variant_iter_free (long /*int*/ variant) { + lock.lock(); + try { + _g_variant_iter_free (variant); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + * @param iter cast=(GVariantIter *) + * @param variant cast=(GVariant *) + */ +public static final native int _g_variant_iter_init (long /*int*/ iter, long /*int*/ variant); +public static final int g_variant_iter_init (long /*int*/ iter, long /*int*/ variant) { + lock.lock(); + try { + return _g_variant_iter_init (iter, variant); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + * @param iter cast=(const GVariantIter *) + * @param key cast = (gchar *) + * @param format = (const gchar *) + * @param value = (GVariant *) + */ +public static final native boolean _g_variant_iter_next (long /*int*/ iter, byte[] format, long /*int*/ key, long /*int*/ value); +public static final boolean g_variant_iter_next (long /*int*/ iter, byte[] format, long /*int*/ key, long /*int*/ value) { + lock.lock(); + try { + return _g_variant_iter_next (iter, format, key, value); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + * @param iter cast=(const GVariantIter *) + */ +public static final native long /*int*/ _g_variant_iter_next_value (long /*int*/ iter); +public static final long /*int*/ g_variant_iter_next_value (long /*int*/ iter) { + lock.lock(); + try { + return _g_variant_iter_next_value (iter); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + * @param value cast=(const GVariant *) + */ +public static final native long /*int*/ _g_variant_print (long /*int*/ value); +public static final long /*int*/ g_variant_print (long /*int*/ value) { + lock.lock(); + try { + return _g_variant_print (value); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + * @param variant cast=(GVariant *) + */ +public static final native void _g_variant_unref (long /*int*/ variant); +public static final void g_variant_unref (long /*int*/ variant) { + lock.lock(); + try { + _g_variant_unref (variant); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + */ +public static final native long /*int*/ _g_settings_schema_source_get_default (); +public static final long /*int*/ g_settings_schema_source_get_default () { + lock.lock(); + try { + return _g_settings_schema_source_get_default (); + } finally { + lock.unlock(); + } +} +/** + * @method flags=dynamic + * @param schemaSource cast = (GSettingsSchemaSource *) + * @param schema_id cast = (const gchar *) + * @param recursive cast = (gboolean) + */ +public static final native long /*int*/ _g_settings_schema_source_lookup (long /*int*/ schemaSource, byte[] schema_id, boolean recursive); +public static final long /*int*/ g_settings_schema_source_lookup (long /*int*/ schemaSource, byte[] schema_id, boolean recursive) { + lock.lock(); + try { + return _g_settings_schema_source_lookup (schemaSource, schema_id, recursive); + } finally { + lock.unlock(); + } +} + + + } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Path.java b/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Path.java index 63ee440475..ca51247900 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Path.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Path.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,6 +11,7 @@ package org.eclipse.swt.graphics; import org.eclipse.swt.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.cairo.*; /** @@ -214,6 +215,43 @@ public Path (Device device, PathData data) { * </ul> */ public void addArc(float x, float y, float width, float height, float startAngle, float arcAngle) { + x = DPIUtil.autoScaleUp(x); + y = DPIUtil.autoScaleUp(y); + width = DPIUtil.autoScaleUp(width); + height = DPIUtil.autoScaleUp(height); + addArcInPixels(x, y, width, height, startAngle, arcAngle); +} +/** + * Adds to the receiver a circular or elliptical arc that lies within + * the specified rectangular area. + * <p> + * The resulting arc begins at <code>startAngle</code> and extends + * for <code>arcAngle</code> degrees. + * Angles are interpreted such that 0 degrees is at the 3 o'clock + * position. A positive value indicates a counter-clockwise rotation + * while a negative value indicates a clockwise rotation. + * </p><p> + * The center of the arc is the center of the rectangle whose origin + * is (<code>x</code>, <code>y</code>) and whose size is specified by the + * <code>width</code> and <code>height</code> arguments. + * </p><p> + * The resulting arc covers an area <code>width + 1</code> pixels wide + * by <code>height + 1</code> pixels tall. + * </p> + * + * @param x the x coordinate of the upper-left corner of the arc + * @param y the y coordinate of the upper-left corner of the arc + * @param width the width of the arc + * @param height the height of the arc + * @param startAngle the beginning angle + * @param arcAngle the angular extent of the arc, relative to the start angle + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void addArcInPixels(float x, float y, float width, float height, float startAngle, float arcAngle) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); moved = true; if (width == height) { @@ -279,6 +317,26 @@ public void addPath(Path path) { * </ul> */ public void addRectangle(float x, float y, float width, float height) { + x = DPIUtil.autoScaleUp(x); + y = DPIUtil.autoScaleUp(y); + width = DPIUtil.autoScaleUp(width); + height = DPIUtil.autoScaleUp(height); + addRectangleInPixels(x, y, width, height); +} +/** + * Adds to the receiver the rectangle specified by x, y, width and height. + * + * @param x the x coordinate of the rectangle to add + * @param y the y coordinate of the rectangle to add + * @param width the width of the rectangle to add + * @param height the height of the rectangle to add + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void addRectangleInPixels(float x, float y, float width, float height) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); moved = false; Cairo.cairo_rectangle(handle, x, y, width, height); @@ -303,6 +361,29 @@ public void addRectangle(float x, float y, float width, float height) { * </ul> */ public void addString(String string, float x, float y, Font font) { + x = DPIUtil.autoScaleUp(x); + y = DPIUtil.autoScaleUp(y); + addStringInPixels(string, x, y, font); +} +/** + * Adds to the receiver the pattern of glyphs generated by drawing + * the given string using the given font starting at the point (x, y). + * + * @param string the text to use + * @param x the x coordinate of the starting point + * @param y the y coordinate of the starting point + * @param font the font to use + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the font is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void addStringInPixels(String string, float x, float y, Font font) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (font == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); @@ -351,6 +432,35 @@ public void close() { * </ul> */ public boolean contains(float x, float y, GC gc, boolean outline) { + x = DPIUtil.autoScaleUp(x); + y = DPIUtil.autoScaleUp(y); + return containsInPixels(x, y, gc, outline); +} +/** + * Returns <code>true</code> if the specified point is contained by + * the receiver and false otherwise. + * <p> + * If outline is <code>true</code>, the point (x, y) checked for containment in + * the receiver's outline. If outline is <code>false</code>, the point is + * checked to see if it is contained within the bounds of the (closed) area + * covered by the receiver. + * + * @param x the x coordinate of the point to test for containment + * @param y the y coordinate of the point to test for containment + * @param gc the GC to use when testing for containment + * @param outline controls whether to check the outline or contained area of the path + * @return <code>true</code> if the path contains the point and <code>false</code> otherwise + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +boolean containsInPixels(float x, float y, GC gc, boolean outline) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); @@ -387,6 +497,27 @@ public boolean contains(float x, float y, GC gc, boolean outline) { * </ul> */ public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) { + cx1 = DPIUtil.autoScaleUp(cx1); + cy1 = DPIUtil.autoScaleUp(cy1); + cx2 = DPIUtil.autoScaleUp(cx2); + cy2 = DPIUtil.autoScaleUp(cy2); +} +/** + * Adds to the receiver a cubic bezier curve based on the parameters. + * + * @param cx1 the x coordinate of the first control point of the spline + * @param cy1 the y coordinate of the first control of the spline + * @param cx2 the x coordinate of the second control of the spline + * @param cy2 the y coordinate of the second control of the spline + * @param x the x coordinate of the end point of the spline + * @param y the y coordinate of the end point of the spline + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void cubicToInPixels(float cx1, float cy1, float cx2, float cy2, float x, float y) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (!moved) { double[] currentX = new double[1], currentY = new double[1]; @@ -414,6 +545,28 @@ public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y * </ul> */ public void getBounds(float[] bounds) { + getBoundsInPixels(bounds); + for (int i = 0; i < bounds.length; i++) { + bounds [i] = DPIUtil.autoScaleDown(bounds[i]); + } +} +/** + * Replaces the first four elements in the parameter with values that + * describe the smallest rectangle that will completely contain the + * receiver (i.e. the bounding box). + * + * @param bounds the array to hold the result + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the bounding box</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void getBoundsInPixels(float[] bounds) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (bounds.length < 4) SWT.error(SWT.ERROR_INVALID_ARGUMENT); @@ -488,6 +641,27 @@ public void getBounds(float[] bounds) { * </ul> */ public void getCurrentPoint(float[] point) { + getCurrentPointInPixels(point); + for (int i = 0; i < point.length; i++) { + point [i] = DPIUtil.autoScaleDown(point[i]); + } +} +/** + * Replaces the first two elements in the parameter with values that + * describe the current point of the path. + * + * @param point the array to hold the result + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the end point</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void getCurrentPointInPixels(float[] point) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (point == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (point.length < 2) SWT.error(SWT.ERROR_INVALID_ARGUMENT); @@ -583,6 +757,23 @@ public PathData getPathData() { * </ul> */ public void lineTo(float x, float y) { + x = DPIUtil.autoScaleUp(x); + y = DPIUtil.autoScaleUp(y); + lineToInPixels(x, y); +} +/** + * Adds to the receiver a line from the current point to + * the point specified by (x, y). + * + * @param x the x coordinate of the end of the line to add + * @param y the y coordinate of the end of the line to add + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void lineToInPixels(float x, float y) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (!moved) { double[] currentX = new double[1], currentY = new double[1]; @@ -607,6 +798,24 @@ public void lineTo(float x, float y) { * </ul> */ public void moveTo(float x, float y) { + x = DPIUtil.autoScaleUp(x); + y = DPIUtil.autoScaleUp(y); + moveToInPixels(x, y); +} +/** + * Sets the current point of the receiver to the point + * specified by (x, y). Note that this starts a new + * sub path. + * + * @param x the x coordinate of the new end point + * @param y the y coordinate of the new end point + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void moveToInPixels(float x, float y) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); /* * Bug in Cairo. If cairo_move_to() is not called at the @@ -633,6 +842,27 @@ public void moveTo(float x, float y) { * </ul> */ public void quadTo(float cx, float cy, float x, float y) { + x = DPIUtil.autoScaleUp(x); + y = DPIUtil.autoScaleUp(y); + cx = DPIUtil.autoScaleUp(cx); + cy = DPIUtil.autoScaleUp(cy); + quadToInPixels(cx, cy, x, y); +} + +/** + * Adds to the receiver a quadratic curve based on the parameters. + * + * @param cx the x coordinate of the control point of the spline + * @param cy the y coordinate of the control point of the spline + * @param x the x coordinate of the end point of the spline + * @param y the y coordinate of the end point of the spline + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void quadToInPixels(float cx, float cy, float x, float y) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); double[] currentX = new double[1], currentY = new double[1]; Cairo.cairo_get_current_point(handle, currentX, currentY); @@ -662,16 +892,16 @@ void init(PathData data) { for (int i = 0, j = 0; i < types.length; i++) { switch (types[i]) { case SWT.PATH_MOVE_TO: - moveTo(points[j++], points[j++]); + moveToInPixels(points[j++], points[j++]); break; case SWT.PATH_LINE_TO: - lineTo(points[j++], points[j++]); + lineToInPixels(points[j++], points[j++]); break; case SWT.PATH_CUBIC_TO: - cubicTo(points[j++], points[j++], points[j++], points[j++], points[j++], points[j++]); + cubicToInPixels(points[j++], points[j++], points[j++], points[j++], points[j++], points[j++]); break; case SWT.PATH_QUAD_TO: - quadTo(points[j++], points[j++], points[j++], points[j++]); + quadToInPixels(points[j++], points[j++], points[j++], points[j++]); break; case SWT.PATH_CLOSE: close(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java deleted file mode 100644 index 016e1a01a0..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - -import org.eclipse.swt.*; - -/** - * This class hold common constants and utility functions w.r.t. to SWT high DPI - * functionality. - * - * @since 3.104 - */ -class DPIUtil { - - /* DPI Constants */ - static final int DPI_ZOOM_200 = 192; - static final int DPI_ZOOM_150 = 144; - - /** - * Compute the zoom value based on the DPI value. - * - * @return zoom - */ - static int mapDPIToZoom (int dpi) { - int zoom; - if (dpi >= DPI_ZOOM_200) { - zoom = 200; - } else if (dpi >= DPI_ZOOM_150) { - zoom = 150; - } else { - zoom = 100; - } - return zoom; - } - - /** - * Gets Image file path at specified zoom level, if image is missing then - * fall-back to 100% image. If provider or fall-back image is not available, - * throw error. - */ - static String validateAndGetImagePathAtZoom (ImageFileNameProvider provider, int zoom, boolean[] found) { - if (provider == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - String filename = provider.getImagePath (zoom); - found [0] = (filename != null); - /* If image is null when (zoom != 100%), fall-back to image at 100% zoom */ - if (zoom != 100 && !found [0]) filename = provider.getImagePath (100); - if (filename == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - return filename; - } - - /** - * Gets Image data at specified zoom level, if image is missing then - * fall-back to 100% image. If provider or fall-back image is not available, - * throw error. - */ - static ImageData validateAndGetImageDataAtZoom (ImageDataProvider provider, int zoom, boolean[] found) { - if (provider == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - ImageData data = provider.getImageData (zoom); - found [0] = (data != null); - /* If image is null when (zoom != 100%), fall-back to image at 100% zoom */ - if (zoom != 100 && !found [0]) data = provider.getImageData (100); - if (data == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - return data; - } -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java new file mode 100644 index 0000000000..b79517da99 --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java @@ -0,0 +1,264 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.internal; + +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; + +/** + * This class hold common constants and utility functions w.r.t. to SWT high DPI + * functionality. + * + * @since 3.105 + */ +public class DPIUtil { + + /* DPI Constants */ + static final int DPI_ZOOM_200 = 192; + static final int DPI_ZOOM_150 = 144; + static final int DPI_ZOOM_100 = 96; + + private static boolean autoScale = true; + private static int deviceZoom = 100; + +/** + * Auto-scale down ImageData + */ +public static ImageData autoScaleDown (ImageData imageData) { + if (!getAutoScale () || imageData == null) return imageData; + float scaleFactor = getScalingFactor (); + return scaleFactor == 1 ? imageData + : imageData.scaledTo (Math.round ((float)imageData.width / scaleFactor), Math.round ((float)imageData.height / scaleFactor)); +} + +public static int[] autoScaleUp(int[] pointArray) { + if (!getAutoScale ()) return pointArray; + float scaleFactor = getScalingFactor (); + int [] returnArray = new int[pointArray.length]; + for (int i = 0; i < pointArray.length; i++) { + returnArray [i] = Math.round (pointArray [i] * scaleFactor); + } + return returnArray; +} +public static int[] autoScaleDown(int[] pointArray) { + if (!getAutoScale ()) return pointArray; + float scaleFactor = getScalingFactor (); + int [] returnArray = new int[pointArray.length]; + for (int i = 0; i < pointArray.length; i++) { + returnArray [i] = Math.round (pointArray [i] / scaleFactor); + } + return returnArray; +} +/** + * Auto-scale down int dimensions. + */ +public static int autoScaleDown (int size) { + if (!getAutoScale ()) return size; + float scaleFactor = getScalingFactor (); + return Math.round (size / scaleFactor); +} +/** + * Auto-scale down float dimensions. + */ +public static float autoScaleDown (float size) { + if (!getAutoScale ()) return size; + float scaleFactor = getScalingFactor (); + return (size / scaleFactor); +} + +/** + * Returns a new scaled down Point. + */ +public static Point autoScaleDown (Point point) { + if (!getAutoScale () || point == null) return point; + float scaleFactor = getScalingFactor (); + if (scaleFactor == 1) return point; + Point scaledPoint = new Point (0,0); + scaledPoint.x = Math.round (point.x / scaleFactor); + scaledPoint.y = Math.round (point.y / scaleFactor); + return scaledPoint; +} + +/** + * Returns a new scaled down Rectangle. + */ +public static Rectangle autoScaleDown (Rectangle rect) { + if (!getAutoScale () || rect == null) return rect; + float scaleFactor = getScalingFactor (); + if (scaleFactor == 1) return rect; + Rectangle scaledRect = new Rectangle (0,0,0,0); + scaledRect.x = Math.round (rect.x / scaleFactor); + scaledRect.y = Math.round (rect.y / scaleFactor); + scaledRect.width = Math.round (rect.width / scaleFactor); + scaledRect.height = Math.round (rect.height / scaleFactor); + return scaledRect; +} + +/** + * Auto-scale image with ImageData + */ +public static ImageData autoScaleImageData (ImageData imageData, int targetZoom, int currentZoom) { + if (!getAutoScale () || imageData == null || targetZoom == currentZoom) return imageData; + float scaleFactor = ((float) targetZoom)/((float) currentZoom); + return imageData.scaledTo (Math.round ((float)imageData.width * scaleFactor), Math.round ((float)imageData.height * scaleFactor)); +} + +/** + * Auto-scale up ImageData + */ +public static ImageData autoScaleUp (ImageData imageData) { + if (!getAutoScale () || imageData == null) return imageData; + float scaleFactor = getScalingFactor (); + return scaleFactor == 1 ? imageData + : imageData.scaledTo (Math.round ((float)imageData.width * scaleFactor), Math.round ((float)imageData.height * scaleFactor)); +} + +/** + * Auto-scale up int dimensions. + */ +public static int autoScaleUp (int size) { + if (!getAutoScale ()||size == SWT.DEFAULT) return size; + float scaleFactor = getScalingFactor (); + return Math.round (size * scaleFactor); +} + +/** + * Returns a new scaled up Point. + */ +public static Point autoScaleUp (Point point) { + if (!getAutoScale () || point == null) return point; + float scaleFactor = getScalingFactor (); + if (scaleFactor == 1) return point; + Point scaledPoint = new Point (0,0); + scaledPoint.x = Math.round (point.x * scaleFactor); + scaledPoint.y = Math.round (point.y * scaleFactor); + return scaledPoint; +} + +/** + * Returns a new scaled up Rectangle. + */ +public static Rectangle autoScaleUp (Rectangle rect) { + if (!getAutoScale () || rect == null) return rect; + float scaleFactor = getScalingFactor (); + if (scaleFactor == 1) return rect; + Rectangle scaledRect = new Rectangle (0,0,0,0); + scaledRect.x = Math.round (rect.x * scaleFactor); + scaledRect.y = Math.round (rect.y * scaleFactor); + scaledRect.width = Math.round (rect.width * scaleFactor); + scaledRect.height = Math.round (rect.height * scaleFactor); + return scaledRect; +} +public static boolean getAutoScale () { + return autoScale; +} + +/** + * Returns Scaling factor from the display + * @return float scaling factor + */ +private static float getScalingFactor () { + float scalingFactor = 1; + if (getAutoScale ()) { + scalingFactor = getDeviceZoom ()/100f; + } + return scalingFactor; +} + +/** + * Compute the zoom value based on the scaleFactor value. + * + * @return zoom + */ +public static int mapSFToZoom (float scaleFactor) { + return mapDPIToZoom ((int) (scaleFactor * DPI_ZOOM_100)); +} +/** + * Compute the zoom value based on the DPI value. + * + * @return zoom + */ +public static int mapDPIToZoom (int dpi) { + int zoom; + if (dpi >= DPI_ZOOM_200) { + zoom = 200; + } else if (dpi >= DPI_ZOOM_150) { + zoom = 150; + } else { + zoom = 100; + } + return zoom; +} +/** + * Returns a new rectangle as per the scaleFactor. + */ +static Rectangle scale (Rectangle rect, int targetZoom, int currentZoom) { + if (rect == null || targetZoom == currentZoom) return rect; + float scaleFactor = ((float)targetZoom) / (float)currentZoom; + Rectangle returnRect = new Rectangle (0,0,0,0); + returnRect.x = Math.round (rect.x * scaleFactor); + returnRect.y = Math.round (rect.y * scaleFactor); + returnRect.width = Math.round (rect.width * scaleFactor); + returnRect.height = Math.round (rect.height * scaleFactor); + return returnRect; +} + +/** + * Gets Image data at specified zoom level, if image is missing then + * fall-back to 100% image. If provider or fall-back image is not available, + * throw error. + */ +public static ImageData validateAndGetImageDataAtZoom (ImageDataProvider provider, int zoom, boolean[] found) { + if (provider == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + ImageData data = provider.getImageData (zoom); + found [0] = (data != null); + /* If image is null when (zoom != 100%), fall-back to image at 100% zoom */ + if (zoom != 100 && !found [0]) data = provider.getImageData (100); + if (data == null) SWT.error (SWT.ERROR_INVALID_ARGUMENT); + return data; +} + +/** + * Gets Image file path at specified zoom level, if image is missing then + * fall-back to 100% image. If provider or fall-back image is not available, + * throw error. + */ +public static String validateAndGetImagePathAtZoom (ImageFileNameProvider provider, int zoom, boolean[] found) { + if (provider == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + String filename = provider.getImagePath (zoom); + found [0] = (filename != null); + /* If image is null when (zoom != 100%), fall-back to image at 100% zoom */ + if (zoom != 100 && !found [0]) filename = provider.getImagePath (100); + if (filename == null) SWT.error (SWT.ERROR_INVALID_ARGUMENT); + return filename; +} + +public static float autoScaleUp(float size) { + if (!getAutoScale ()||size == SWT.DEFAULT) return size; + float scaleFactor = getScalingFactor (); + return (size * scaleFactor); +} + +/** + * @return the deviceZoom + */ +public static int getDeviceZoom() { + return deviceZoom; +} + +/** + * @param deviceZoom the deviceZoom to set + */ +public static void setDeviceZoom(int deviceZoom) { + DPIUtil.deviceZoom = deviceZoom; +} + +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java index ba73938a4b..71ae969c67 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java @@ -82,6 +82,9 @@ public abstract class Device implements Drawable { /* Device dpi */ Point dpi; + /*Device Scale Factor in percentage*/ + int scaleFactor; + long /*int*/ emptyTab; boolean useXRender; @@ -315,6 +318,20 @@ protected void destroy () { * </ul> */ public Rectangle getBounds () { + return DPIUtil.autoScaleDown (getBoundsInPixels ()); +} + +/** + * Returns a rectangle describing the receiver's size and location. + * + * @return the bounding rectangle + * + * @exception SWTException <ul> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +protected Rectangle getBoundsInPixels () { checkDevice (); return new Rectangle(0, 0, 0, 0); } @@ -374,8 +391,24 @@ public DeviceData getDeviceData () { * @see #getBounds */ public Rectangle getClientArea () { + return DPIUtil.autoScaleDown (getClientAreaInPixels ()); +} +/** + * Returns a rectangle which describes the area of the + * receiver which is capable of displaying data. + * + * @return the client area + * + * @exception SWTException <ul> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #getBounds + * @since 3.105 + */ +protected Rectangle getClientAreaInPixels () { checkDevice (); - return getBounds (); + return getBoundsInPixels (); } /** @@ -579,6 +612,8 @@ public boolean getWarnings () { */ protected void init () { this.dpi = getDPI(); + this.scaleFactor = getDeviceZoom (); + DPIUtil.setDeviceZoom (scaleFactor); if (xDisplay != 0 && !OS.USE_CAIRO) { int[] event_basep = new int[1], error_basep = new int [1]; @@ -979,13 +1014,56 @@ static long /*int*/ XIOErrorProc (long /*int*/ xDisplay) { * @return the horizontal DPI */ int _getDPIx () { + return scaleFactor * 96/100; +} +/** + * Gets the scaling factor from the device and calculates zoom level + * @return zoom in percentage. scaling factor 1 corresponds to 100% + * @since 3.105 + */ +private int getDeviceZoom() { + final String schemaId = "com.ubuntu.user-interface"; + final String key = "scale-factor"; + int fontHeight = 0; long /*int*/ screen = OS.gdk_screen_get_default(); int monitor = OS.gdk_screen_get_monitor_at_point(screen, 0, 0); - GdkRectangle dest = new GdkRectangle (); - OS.gdk_screen_get_monitor_geometry(screen, monitor, dest); - int widthMM = OS.gdk_screen_get_monitor_width_mm(screen, monitor); - return Compatibility.round (254 * dest.width, widthMM * 10); -} + byte[] schema_id = Converter.wcsToMbcs (null, schemaId, true); + long /*int*/ schemaSource = OS.g_settings_schema_source_get_default (); + if (OS.g_settings_schema_source_lookup(schemaSource, schema_id, false) != 0) { + long /*int*/ displaySettings = OS.g_settings_new (schema_id); + byte[] keyString = Converter.wcsToMbcs (null, key, true); + long /*int*/ settingsDict = OS.g_settings_get_value (displaySettings, keyString); + long /*int*/ keyArray = 0; + + long /*int*/ iter = OS.g_variant_iter_new (settingsDict); + int size = OS.g_variant_iter_init(iter, settingsDict); + for (int i =0; i<size; i++) { + long /*int*/ iterValue = OS.g_variant_iter_next_value(iter); + keyArray = OS.g_variant_print(iterValue); + int len = OS.strlen(keyArray); + byte[] buffer = new byte [len]; + OS.memmove (buffer, keyArray, len); + String type = new String(Converter.mbcsToWcs(null, buffer)); + if (i == monitor) { + int index = type.indexOf(","); + String height = type.substring((index + 1), (type.length() - 1)); + fontHeight = Integer.valueOf(height.trim()); + OS.g_free(keyArray); + OS.g_variant_unref(iterValue); + break; + } + OS.g_free(keyArray); + OS.g_variant_unref(iterValue); + } + OS.g_variant_iter_free(iter); + return DPIUtil.mapSFToZoom(fontHeight/ 8f); + } else { + GdkRectangle dest = new GdkRectangle (); + OS.gdk_screen_get_monitor_geometry(screen, monitor, dest); + int widthMM = OS.gdk_screen_get_monitor_width_mm(screen, monitor); + return (DPIUtil.mapDPIToZoom(Compatibility.round (254 * dest.width, widthMM * 10))); + } +} } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java index 555eebc983..c5426d2129 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.swt.graphics; +import org.eclipse.swt.internal.*; /** * Instances of this class provide measurement information @@ -56,7 +57,7 @@ public boolean equals (Object object) { * @return the ascent of the font */ public int getAscent() { - return ascent; + return DPIUtil.autoScaleDown(ascent); } /** @@ -66,7 +67,7 @@ public int getAscent() { * @return the average character width of the font */ public int getAverageCharWidth() { - return averageCharWidth; + return DPIUtil.autoScaleDown(averageCharWidth); } /** @@ -78,7 +79,7 @@ public int getAverageCharWidth() { * @return the descent of the font */ public int getDescent() { - return descent; + return DPIUtil.autoScaleDown(descent); } /** @@ -93,7 +94,7 @@ public int getDescent() { * @see #getLeading */ public int getHeight() { - return height; + return DPIUtil.autoScaleDown(height); } /** @@ -104,7 +105,7 @@ public int getHeight() { * @return the leading space of the font */ public int getLeading() { - return leading; + return DPIUtil.autoScaleDown(leading); } public static FontMetrics gtk_new(int ascent, int descent, int averageCharWidth, int leading, int height) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java index de06b27787..71dc1d4de4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -297,7 +297,7 @@ void checkGC (int mask) { Cairo.cairo_set_line_join(cairo, join_style); } if ((state & LINE_WIDTH) != 0) { - Cairo.cairo_set_line_width(cairo, data.lineWidth == 0 ? 1 : data.lineWidth); + Cairo.cairo_set_line_width(cairo, data.lineWidth == 0 ? DPIUtil.autoScaleUp(1) : data.lineWidth); switch (data.lineStyle) { case SWT.LINE_DOT: case SWT.LINE_DASH: @@ -474,6 +474,27 @@ long /*int*/ convertRgn(long /*int*/ rgn, double[] matrix) { * </ul> */ public void copyArea(Image image, int x, int y) { + Point loc = DPIUtil.autoScaleUp(new Point(x, y)); + copyAreaInPixels(image, loc.x, loc.y); +} +/** + * Copies a rectangular area of the receiver at the specified + * position into the image, which must be of type <code>SWT.BITMAP</code>. + * + * @param image the image to copy into + * @param x the x coordinate in the receiver of the area to be copied + * @param y the y coordinate in the receiver of the area to be copied + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the image is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the image is not a bitmap or has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void copyAreaInPixels(Image image, int x, int y) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); @@ -508,7 +529,7 @@ public void copyArea(Image image, int x, int y) { Cairo.cairo_destroy(cairo); return; } - Rectangle rect = image.getBounds(); + Rectangle rect = image.getBoundsInPixels(); long /*int*/ gdkGC = OS.gdk_gc_new(image.pixmap); if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES); OS.gdk_gc_set_subwindow(gdkGC, OS.GDK_INCLUDE_INFERIORS); @@ -532,7 +553,28 @@ public void copyArea(Image image, int x, int y) { * </ul> */ public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) { - copyArea(srcX, srcY, width, height, destX, destY, true); + Rectangle src = DPIUtil.autoScaleUp(new Rectangle(srcX, srcY, width, height)); + Point dest = DPIUtil.autoScaleUp(new Point(destX, destY)); + copyAreaInPixels(src.x, src.y, src.width, src.height, dest.x, dest.y); +} +/** + * Copies a rectangular area of the receiver at the source + * position onto the receiver at the destination position. + * + * @param srcX the x coordinate in the receiver of the area to be copied + * @param srcY the y coordinate in the receiver of the area to be copied + * @param width the width of the area to copy + * @param height the height of the area to copy + * @param destX the x coordinate in the receiver of the area to copy to + * @param destY the y coordinate in the receiver of the area to copy to + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void copyAreaInPixels(int srcX, int srcY, int width, int height, int destX, int destY) { + copyAreaInPixels(srcX, srcY, width, height, destX, destY, true); } /** * Copies a rectangular area of the receiver at the source @@ -553,6 +595,29 @@ public void copyArea(int srcX, int srcY, int width, int height, int destX, int d * @since 3.1 */ public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) { + Rectangle srcLoc = DPIUtil.autoScaleUp(new Rectangle(srcX, srcY, width, height)); + Point destLoc = DPIUtil.autoScaleUp(new Point(destX, destY)); + copyAreaInPixels(srcLoc.x, srcLoc.y, srcLoc.width, srcLoc.height, destLoc.x, destLoc.y, paint); +} +/** + * Copies a rectangular area of the receiver at the source + * position onto the receiver at the destination position. + * + * @param srcX the x coordinate in the receiver of the area to be copied + * @param srcY the y coordinate in the receiver of the area to be copied + * @param width the width of the area to copy + * @param height the height of the area to copy + * @param destX the x coordinate in the receiver of the area to copy to + * @param destY the y coordinate in the receiver of the area to copy to + * @param paint if <code>true</code> paint events will be generated for old and obscured areas + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +void copyAreaInPixels(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (width <= 0 || height <= 0) return; int deltaX = destX - srcX, deltaY = destY - srcY; @@ -721,6 +786,41 @@ void destroy() { * </ul> */ public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { + Rectangle loc = DPIUtil.autoScaleUp(new Rectangle(x, y, width, height)); + drawArcInPixels(loc.x, loc.y, loc.width, loc.height, startAngle, arcAngle); +} + +/** + * Draws the outline of a circular or elliptical arc + * within the specified rectangular area. + * <p> + * The resulting arc begins at <code>startAngle</code> and extends + * for <code>arcAngle</code> degrees, using the current color. + * Angles are interpreted such that 0 degrees is at the 3 o'clock + * position. A positive value indicates a counter-clockwise rotation + * while a negative value indicates a clockwise rotation. + * </p><p> + * The center of the arc is the center of the rectangle whose origin + * is (<code>x</code>, <code>y</code>) and whose size is specified by the + * <code>width</code> and <code>height</code> arguments. + * </p><p> + * The resulting arc covers an area <code>width + 1</code> pixels wide + * by <code>height + 1</code> pixels tall. + * </p> + * + * @param x the x coordinate of the upper-left corner of the arc to be drawn + * @param y the y coordinate of the upper-left corner of the arc to be drawn + * @param width the width of the arc to be drawn + * @param height the height of the arc to be drawn + * @param startAngle the beginning angle + * @param arcAngle the angular extent of the arc, relative to the start angle + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void drawArcInPixels(int x, int y, int width, int height, int startAngle, int arcAngle) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); if (width < 0) { @@ -776,6 +876,28 @@ public void drawArc(int x, int y, int width, int height, int startAngle, int arc * @see #drawRectangle(int, int, int, int) */ public void drawFocus(int x, int y, int width, int height) { + Rectangle loc = DPIUtil.autoScaleUp(new Rectangle(x, y, width, height)); + drawFocusInPixels(loc.x, loc.y, loc.width, loc.height); +} +/** + * Draws a rectangle, based on the specified arguments, which has + * the appearance of the platform's <em>focus rectangle</em> if the + * platform supports such a notion, and otherwise draws a simple + * rectangle in the receiver's foreground color. + * + * @param x the x coordinate of the rectangle + * @param y the y coordinate of the rectangle + * @param width the width of the rectangle + * @param height the height of the rectangle + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #drawRectangle(int, int, int, int) + * @since 3.105 + */ +void drawFocusInPixels(int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); long /*int*/ cairo = data.cairo; if (cairo != 0) { @@ -828,6 +950,30 @@ public void drawFocus(int x, int y, int width, int height) { * </ul> */ public void drawImage(Image image, int x, int y) { + Point loc = DPIUtil.autoScaleUp(new Point(x, y)); + drawImageInPixels(image, loc.x, loc.y); +} +/** + * Draws the given image in the receiver at the specified + * coordinates. + * + * @param image the image to draw + * @param x the x coordinate of where to draw + * @param y the y coordinate of where to draw + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the image is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> + * <li>ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of the image</li> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @exception SWTError <ul> + * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li> + * </ul> + * @since 3.105 + */ +void drawImageInPixels(Image image, int x, int y) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); @@ -846,6 +992,43 @@ public void drawImage(Image image, int x, int y) { * @param image the source image * @param srcX the x coordinate in the source image to copy from * @param srcY the y coordinate in the source image to copy from + * @param srcWidth the width in points to copy from the source + * @param srcHeight the height in points to copy from the source + * @param destX the x coordinate in the destination to copy to + * @param destY the y coordinate in the destination to copy to + * @param destWidth the width in points of the destination rectangle + * @param destHeight the height in points of the destination rectangle + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the image is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> + * <li>ERROR_INVALID_ARGUMENT - if any of the width or height arguments are negative. + * <li>ERROR_INVALID_ARGUMENT - if the source rectangle is not contained within the bounds of the source image</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @exception SWTError <ul> + * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li> + * </ul> + */ +public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) { + Rectangle srcRect = DPIUtil.autoScaleUp(new Rectangle(srcX, srcY, srcWidth, srcHeight)); + Rectangle destRect = DPIUtil.autoScaleUp(new Rectangle(destX, destY, destWidth, destHeight)); + drawImageInPixels(image, srcRect.x, srcRect.y, srcRect.width, srcRect.height, destRect.x, destRect.y, destRect.width, destRect.height); +} +/** + * Copies a rectangular area from the source image into a (potentially + * different sized) rectangular area in the receiver. If the source + * and destination areas are of differing sizes, then the source + * area will be stretched or shrunk to fit the destination area + * as it is copied. The copy fails if any part of the source rectangle + * lies outside the bounds of the source image, or if any of the width + * or height arguments are negative. + * + * @param image the source image + * @param srcX the x coordinate in the source image to copy from + * @param srcY the y coordinate in the source image to copy from * @param srcWidth the width in pixels to copy from the source * @param srcHeight the height in pixels to copy from the source * @param destX the x coordinate in the destination to copy to @@ -865,8 +1048,9 @@ public void drawImage(Image image, int x, int y) { * @exception SWTError <ul> * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li> * </ul> + * @since 3.105 */ -public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) { +void drawImageInPixels(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return; if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) { @@ -903,7 +1087,7 @@ void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, simple = srcX == 0 && srcY == 0 && srcWidth == destWidth && destWidth == imgWidth && srcHeight == destHeight && destHeight == imgHeight; - if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) { + if (srcX + srcWidth > imgWidth + 1 || srcY + srcHeight > imgHeight + 1) { //rounding error correction for hidpi SWT.error(SWT.ERROR_INVALID_ARGUMENT); } } @@ -1255,6 +1439,26 @@ long /*int*/ scale(long /*int*/ src, int srcX, int srcY, int srcWidth, int srcHe * </ul> */ public void drawLine(int x1, int y1, int x2, int y2) { + Point loc1 = DPIUtil.autoScaleUp(new Point(x1, y1)); + Point loc2 = DPIUtil.autoScaleUp(new Point(x2, y2)); + drawLineInPixels(loc1.x, loc1.y, loc2.x, loc2.y); +} + +/** + * Draws a line, using the foreground color, between the points + * (<code>x1</code>, <code>y1</code>) and (<code>x2</code>, <code>y2</code>). + * + * @param x1 the first point's x coordinate + * @param y1 the first point's y coordinate + * @param x2 the second point's x coordinate + * @param y2 the second point's y coordinate + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void drawLineInPixels(int x1, int y1, int x2, int y2) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); long /*int*/ cairo = data.cairo; @@ -1290,6 +1494,32 @@ public void drawLine(int x1, int y1, int x2, int y2) { * </ul> */ public void drawOval(int x, int y, int width, int height) { + Rectangle rect = DPIUtil.autoScaleUp(new Rectangle(x, y, width, height)); + drawOvalInPixels(rect.x, rect.y, rect.width, rect.height); +} +/** + * Draws the outline of an oval, using the foreground color, + * within the specified rectangular area. + * <p> + * The result is a circle or ellipse that fits within the + * rectangle specified by the <code>x</code>, <code>y</code>, + * <code>width</code>, and <code>height</code> arguments. + * </p><p> + * The oval covers an area that is <code>width + 1</code> + * pixels wide and <code>height + 1</code> pixels tall. + * </p> + * + * @param x the x coordinate of the upper left corner of the oval to be drawn + * @param y the y coordinate of the upper left corner of the oval to be drawn + * @param width the width of the oval to be drawn + * @param height the height of the oval to be drawn + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void drawOvalInPixels(int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); if (width < 0) { @@ -1377,6 +1607,27 @@ public void drawPath(Path path) { * @since 3.0 */ public void drawPoint (int x, int y) { + Point loc = DPIUtil.autoScaleUp(new Point(x, y)); + drawPointInPixels(loc.x, loc.y); +} +/** + * Draws a pixel, using the foreground color, at the specified + * point (<code>x</code>, <code>y</code>). + * <p> + * Note that the receiver's line attributes do not affect this + * operation. + * </p> + * + * @param x the point's x coordinate + * @param y the point's y coordinate + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +void drawPointInPixels (int x, int y) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); long /*int*/ cairo = data.cairo; @@ -1406,6 +1657,29 @@ public void drawPoint (int x, int y) { * </ul> */ public void drawPolygon(int[] pointArray) { + int [] scaledPointArray = DPIUtil.autoScaleUp(pointArray); + drawPolygonInPixels(scaledPointArray); +} + +/** + * Draws the closed polygon which is defined by the specified array + * of integer coordinates, using the receiver's foreground color. The array + * contains alternating x and y values which are considered to represent + * points which are the vertices of the polygon. Lines are drawn between + * each consecutive pair, and between the first pair and last pair in the + * array. + * + * @param pointArray an array of alternating x and y values which are the vertices of the polygon + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT if pointArray is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void drawPolygonInPixels(int[] pointArray) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); checkGC(DRAW); @@ -1436,6 +1710,28 @@ public void drawPolygon(int[] pointArray) { * </ul> */ public void drawPolyline(int[] pointArray) { + int [] scaledPointArray = DPIUtil.autoScaleUp(pointArray); + drawPolylineInPixels(scaledPointArray); +} +/** + * Draws the polyline which is defined by the specified array + * of integer coordinates, using the receiver's foreground color. The array + * contains alternating x and y values which are considered to represent + * points which are the corners of the polyline. Lines are drawn between + * each consecutive pair, but not between the first pair and last pair in + * the array. + * + * @param pointArray an array of alternating x and y values which are the corners of the polyline + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the point array is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void drawPolylineInPixels(int[] pointArray) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); checkGC(DRAW); @@ -1475,6 +1771,25 @@ void drawPolyline(long /*int*/ cairo, int[] pointArray, boolean close) { * </ul> */ public void drawRectangle(int x, int y, int width, int height) { + drawRectangle(new Rectangle(x, y, width, height)); +} +/** + * Draws the outline of the rectangle specified by the arguments, + * using the receiver's foreground color. The left and right edges + * of the rectangle are at <code>x</code> and <code>x + width</code>. + * The top and bottom edges are at <code>y</code> and <code>y + height</code>. + * + * @param x the x coordinate of the rectangle to be drawn + * @param y the y coordinate of the rectangle to be drawn + * @param width the width of the rectangle to be drawn + * @param height the height of the rectangle to be drawn + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void drawRectangleInPixels(int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); if (width < 0) { @@ -1512,8 +1827,28 @@ public void drawRectangle(int x, int y, int width, int height) { * </ul> */ public void drawRectangle(Rectangle rect) { + drawRectangleInPixels(DPIUtil.autoScaleUp(rect)); +} +/** + * Draws the outline of the specified rectangle, using the receiver's + * foreground color. The left and right edges of the rectangle are at + * <code>rect.x</code> and <code>rect.x + rect.width</code>. The top + * and bottom edges are at <code>rect.y</code> and + * <code>rect.y + rect.height</code>. + * + * @param rect the rectangle to draw + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void drawRectangleInPixels(Rectangle rect) { if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - drawRectangle (rect.x, rect.y, rect.width, rect.height); + drawRectangleInPixels (rect.x, rect.y, rect.width, rect.height); } /** * Draws the outline of the round-cornered rectangle specified by @@ -1537,6 +1872,33 @@ public void drawRectangle(Rectangle rect) { * </ul> */ public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) { + Rectangle rect = DPIUtil.autoScaleUp(new Rectangle(x, y, width, height)); + Point arcSize = DPIUtil.autoScaleUp(new Point(arcWidth, arcHeight)); + drawRoundRectangleInPixels(rect.x, rect.y, rect.width, rect.height, arcSize.x, arcSize.y); +} +/** + * Draws the outline of the round-cornered rectangle specified by + * the arguments, using the receiver's foreground color. The left and + * right edges of the rectangle are at <code>x</code> and <code>x + width</code>. + * The top and bottom edges are at <code>y</code> and <code>y + height</code>. + * The <em>roundness</em> of the corners is specified by the + * <code>arcWidth</code> and <code>arcHeight</code> arguments, which + * are respectively the width and height of the ellipse used to draw + * the corners. + * + * @param x the x coordinate of the rectangle to be drawn + * @param y the y coordinate of the rectangle to be drawn + * @param width the width of the rectangle to be drawn + * @param height the height of the rectangle to be drawn + * @param arcWidth the width of the arc + * @param arcHeight the height of the arc + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void drawRoundRectangleInPixels(int x, int y, int width, int height, int arcWidth, int arcHeight) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); int nx = x; @@ -1629,7 +1991,29 @@ public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth * </ul> */ public void drawString (String string, int x, int y) { - drawString(string, x, y, false); + drawString (string, x, y, false); +} +/** + * Draws the given string, using the receiver's current font and + * foreground color. No tab expansion or carriage return processing + * will be performed. The background of the rectangular area where + * the string is being drawn will be filled with the receiver's + * background color. + * + * @param string the string to be drawn + * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn + * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void drawStringInPixels (String string, int x, int y) { + drawStringInPixels(string, x, y, false); } /** * Draws the given string, using the receiver's current font and @@ -1652,7 +2036,32 @@ public void drawString (String string, int x, int y) { * </ul> */ public void drawString(String string, int x, int y, boolean isTransparent) { - drawText(string, x, y, isTransparent ? SWT.DRAW_TRANSPARENT : 0); + Point loc = DPIUtil.autoScaleUp(new Point(x, y)); + drawStringInPixels(string, loc.x, loc.y, isTransparent); +} +/** + * Draws the given string, using the receiver's current font and + * foreground color. No tab expansion or carriage return processing + * will be performed. If <code>isTransparent</code> is <code>true</code>, + * then the background of the rectangular area where the string is being + * drawn will not be modified, otherwise it will be filled with the + * receiver's background color. + * + * @param string the string to be drawn + * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn + * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn + * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void drawStringInPixels(String string, int x, int y, boolean isTransparent) { + drawTextInPixels(string, x, y, isTransparent ? SWT.DRAW_TRANSPARENT : 0); } /** @@ -1676,6 +2085,28 @@ public void drawString(String string, int x, int y, boolean isTransparent) { public void drawText(String string, int x, int y) { drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB); } +/** + * Draws the given string, using the receiver's current font and + * foreground color. Tab expansion and carriage return processing + * are performed. The background of the rectangular area where + * the text is being drawn will be filled with the receiver's + * background color. + * + * @param string the string to be drawn + * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn + * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void drawTextInPixels(String string, int x, int y) { + drawTextInPixels(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB); +} /** * Draws the given string, using the receiver's current font and @@ -1698,9 +2129,34 @@ public void drawText(String string, int x, int y) { * </ul> */ public void drawText(String string, int x, int y, boolean isTransparent) { + Point loc = DPIUtil.autoScaleUp(new Point (x, y)); + drawTextInPixels(string, loc.x, loc.y, isTransparent); +} +/** + * Draws the given string, using the receiver's current font and + * foreground color. Tab expansion and carriage return processing + * are performed. If <code>isTransparent</code> is <code>true</code>, + * then the background of the rectangular area where the text is being + * drawn will not be modified, otherwise it will be filled with the + * receiver's background color. + * + * @param string the string to be drawn + * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn + * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn + * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void drawTextInPixels(String string, int x, int y, boolean isTransparent) { int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB; if (isTransparent) flags |= SWT.DRAW_TRANSPARENT; - drawText(string, x, y, flags); + drawTextInPixels(string, x, y, flags); } /** @@ -1738,6 +2194,45 @@ public void drawText(String string, int x, int y, boolean isTransparent) { * </ul> */ public void drawText (String string, int x, int y, int flags) { + Point loc = DPIUtil.autoScaleUp(new Point (x, y)); + drawTextInPixels(string, loc.x, loc.y, flags); +} +/** + * Draws the given string, using the receiver's current font and + * foreground color. Tab expansion, line delimiter and mnemonic + * processing are performed according to the specified flags. If + * <code>flags</code> includes <code>DRAW_TRANSPARENT</code>, + * then the background of the rectangular area where the text is being + * drawn will not be modified, otherwise it will be filled with the + * receiver's background color. + * <p> + * The parameter <code>flags</code> may be a combination of: + * <dl> + * <dt><b>DRAW_DELIMITER</b></dt> + * <dd>draw multiple lines</dd> + * <dt><b>DRAW_TAB</b></dt> + * <dd>expand tabs</dd> + * <dt><b>DRAW_MNEMONIC</b></dt> + * <dd>underline the mnemonic character</dd> + * <dt><b>DRAW_TRANSPARENT</b></dt> + * <dd>transparent background</dd> + * </dl> + * </p> + * + * @param string the string to be drawn + * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn + * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn + * @param flags the flags specifying how to process the text + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void drawTextInPixels (String string, int x, int y, int flags) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (string.length() == 0) return; @@ -1845,6 +2340,43 @@ public boolean equals(Object object) { * @see #drawArc */ public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { + Rectangle rect = DPIUtil.autoScaleUp(new Rectangle(x, y, width, height)); + fillArcInPixels(rect.x, rect.y, rect.width, rect.height, startAngle, arcAngle); +} +/** + * Fills the interior of a circular or elliptical arc within + * the specified rectangular area, with the receiver's background + * color. + * <p> + * The resulting arc begins at <code>startAngle</code> and extends + * for <code>arcAngle</code> degrees, using the current color. + * Angles are interpreted such that 0 degrees is at the 3 o'clock + * position. A positive value indicates a counter-clockwise rotation + * while a negative value indicates a clockwise rotation. + * </p><p> + * The center of the arc is the center of the rectangle whose origin + * is (<code>x</code>, <code>y</code>) and whose size is specified by the + * <code>width</code> and <code>height</code> arguments. + * </p><p> + * The resulting arc covers an area <code>width + 1</code> pixels wide + * by <code>height + 1</code> pixels tall. + * </p> + * + * @param x the x coordinate of the upper-left corner of the arc to be filled + * @param y the y coordinate of the upper-left corner of the arc to be filled + * @param width the width of the arc to be filled + * @param height the height of the arc to be filled + * @param startAngle the beginning angle + * @param arcAngle the angular extent of the arc, relative to the start angle + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #drawArc + * @since 3.105 + */ +void fillArcInPixels(int x, int y, int width, int height, int startAngle, int arcAngle) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); if (width < 0) { @@ -1904,6 +2436,32 @@ public void fillArc(int x, int y, int width, int height, int startAngle, int arc * @see #drawRectangle(int, int, int, int) */ public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) { + Rectangle rect = DPIUtil.autoScaleUp(new Rectangle(x, y, width, height)); + fillGradientRectangleInPixels(rect.x, rect.y, rect.width, rect.height, vertical); +} + +/** + * Fills the interior of the specified rectangle with a gradient + * sweeping from left to right or top to bottom progressing + * from the receiver's foreground color to its background color. + * + * @param x the x coordinate of the rectangle to be filled + * @param y the y coordinate of the rectangle to be filled + * @param width the width of the rectangle to be filled, may be negative + * (inverts direction of gradient if horizontal) + * @param height the height of the rectangle to be filled, may be negative + * (inverts direction of gradient if vertical) + * @param vertical if true sweeps from top to bottom, else + * sweeps from left to right + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #drawRectangle(int, int, int, int) + * @since 3.105 + */ +void fillGradientRectangleInPixels(int x, int y, int width, int height, boolean vertical) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if ((width == 0) || (height == 0)) return; @@ -1930,7 +2488,7 @@ public void fillGradientRectangle(int x, int y, int width, int height, boolean v toRGB = foregroundRGB; } if (fromRGB.equals(toRGB)) { - fillRectangle(x, y, width, height); + fillRectangleInPixels(x, y, width, height); return; } long /*int*/ cairo = data.cairo; @@ -1975,6 +2533,28 @@ public void fillGradientRectangle(int x, int y, int width, int height, boolean v * @see #drawOval */ public void fillOval(int x, int y, int width, int height) { + Rectangle rect = DPIUtil.autoScaleUp(new Rectangle(x, y, width, height)); + fillOvalInPixels(rect.x, rect.y, rect.width, rect.height); +} + +/** + * Fills the interior of an oval, within the specified + * rectangular area, with the receiver's background + * color. + * + * @param x the x coordinate of the upper left corner of the oval to be filled + * @param y the y coordinate of the upper left corner of the oval to be filled + * @param width the width of the oval to be filled + * @param height the height of the oval to be filled + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #drawOval + * @since 3.105 + */ +void fillOvalInPixels(int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); if (width < 0) { @@ -2059,6 +2639,31 @@ public void fillPath (Path path) { * @see #drawPolygon */ public void fillPolygon(int[] pointArray) { + int [] scaledPointArray = DPIUtil.autoScaleUp(pointArray); + fillPolygonInPixels(scaledPointArray); +} + +/** + * Fills the interior of the closed polygon which is defined by the + * specified array of integer coordinates, using the receiver's + * background color. The array contains alternating x and y values + * which are considered to represent points which are the vertices of + * the polygon. Lines are drawn between each consecutive pair, and + * between the first pair and last pair in the array. + * + * @param pointArray an array of alternating x and y values which are the vertices of the polygon + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT if pointArray is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #drawPolygon + * @since 3.105 + */ +void fillPolygonInPixels(int[] pointArray) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); checkGC(FILL); @@ -2087,6 +2692,26 @@ public void fillPolygon(int[] pointArray) { * @see #drawRectangle(int, int, int, int) */ public void fillRectangle(int x, int y, int width, int height) { + fillRectangle(new Rectangle(x, y, width, height)); +} + +/** + * Fills the interior of the rectangle specified by the arguments, + * using the receiver's background color. + * + * @param x the x coordinate of the rectangle to be filled + * @param y the y coordinate of the rectangle to be filled + * @param width the width of the rectangle to be filled + * @param height the height of the rectangle to be filled + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #drawRectangle(int, int, int, int) + * @since 3.105 + */ +void fillRectangleInPixels(int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); if (width < 0) { @@ -2122,9 +2747,28 @@ public void fillRectangle(int x, int y, int width, int height) { * @see #drawRectangle(int, int, int, int) */ public void fillRectangle(Rectangle rect) { + fillRectangleInPixels(DPIUtil.autoScaleUp(rect)); +} +/** + * Fills the interior of the specified rectangle, using the receiver's + * background color. + * + * @param rect the rectangle to be filled + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #drawRectangle(int, int, int, int) + * @since 3.105 + */ +void fillRectangleInPixels(Rectangle rect) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - fillRectangle(rect.x, rect.y, rect.width, rect.height); + fillRectangleInPixels(rect.x, rect.y, rect.width, rect.height); } /** @@ -2145,6 +2789,29 @@ public void fillRectangle(Rectangle rect) { * @see #drawRoundRectangle */ public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) { + Rectangle rect = DPIUtil.autoScaleUp(new Rectangle(x, y, width, height)); + Point arcSize = DPIUtil.autoScaleUp(new Point(arcWidth, arcHeight)); + fillRoundRectangleInPixels(rect.x, rect.y, rect.width, rect.height, arcSize.x, arcSize.y); +} +/** + * Fills the interior of the round-cornered rectangle specified by + * the arguments, using the receiver's background color. + * + * @param x the x coordinate of the rectangle to be filled + * @param y the y coordinate of the rectangle to be filled + * @param width the width of the rectangle to be filled + * @param height the height of the rectangle to be filled + * @param arcWidth the width of the arc + * @param arcHeight the height of the arc + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #drawRoundRectangle + * @since 3.105 + */ +void fillRoundRectangleInPixels(int x, int y, int width, int height, int arcWidth, int arcHeight) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); int nx = x; @@ -2247,7 +2914,7 @@ int fixMnemonic (char [] buffer) { public int getAdvanceWidth(char ch) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); //BOGUS - return stringExtent(new String(new char[]{ch})).x; + return stringExtentInPixels(new String(new char[]{ch})).x; } /** @@ -2378,7 +3045,7 @@ public Pattern getBackgroundPattern() { public int getCharWidth(char ch) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); //BOGUS - return stringExtent(new String(new char[]{ch})).x; + return stringExtentInPixels(new String(new char[]{ch})).x; } /** @@ -2394,6 +3061,22 @@ public int getCharWidth(char ch) { * </ul> */ public Rectangle getClipping() { + return DPIUtil.autoScaleDown(getClippingInPixels()); +} +/** + * Returns the bounding rectangle of the receiver's clipping + * region. If no clipping region is set, the return value + * will be a rectangle which covers the entire bounds of the + * object the receiver is drawing on. + * + * @return the bounding rectangle of the clipping region + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +Rectangle getClippingInPixels() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); /* Calculate visible bounds in device space */ int x = 0, y = 0, width = 0, height = 0; @@ -2650,6 +3333,23 @@ public int getInterpolation() { * @since 3.3 */ public LineAttributes getLineAttributes() { + LineAttributes attributes = getLineAttributesInPixels(); + attributes.width = DPIUtil.autoScaleDown(attributes.width); + return attributes; +} + +/** + * Returns the receiver's line attributes. + * + * @return the line attributes used for drawing lines + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.3 + */ +LineAttributes getLineAttributesInPixels() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); float[] dashes = null; if (data.lineDashes != null) { @@ -2748,6 +3448,22 @@ public int getLineStyle() { */ public int getLineWidth() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return (int)DPIUtil.autoScaleDown(data.lineWidth); +} +/** + * Returns the width that will be used when drawing lines + * for all of the figure drawing operations (that is, + * <code>drawLine</code>, <code>drawRectangle</code>, + * <code>drawPolyline</code>, and so forth. + * + * @return the receiver's line width + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + */ +int getLineWidthInPixels() { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); return (int)data.lineWidth; } @@ -3329,6 +4045,25 @@ void setClipping(long /*int*/ clipRgn) { * </ul> */ public void setClipping(int x, int y, int width, int height) { + setClipping(new Rectangle(x, y, width, height)); +} + +/** + * Sets the area of the receiver which can be changed + * by drawing operations to the rectangular area specified + * by the arguments. + * + * @param x the x coordinate of the clipping rectangle + * @param y the y coordinate of the clipping rectangle + * @param width the width of the clipping rectangle + * @param height the height of the clipping rectangle + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void setClippingInPixels(int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (width < 0) { x = x + width; @@ -3404,6 +4139,23 @@ public void setClipping(Path path) { * </ul> */ public void setClipping(Rectangle rect) { + setClippingInPixels(DPIUtil.autoScaleUp(rect)); +} +/** + * Sets the area of the receiver which can be changed + * by drawing operations to the rectangular area specified + * by the argument. Specifying <code>null</code> for the + * rectangle reverts the receiver's clipping area to its + * original value. + * + * @param rect the clipping rectangle or <code>null</code> + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void setClippingInPixels(Rectangle rect) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (OS.GTK_VERSION >= OS.VERSION(3, 9, 0)) { return; @@ -3411,7 +4163,7 @@ public void setClipping(Rectangle rect) { if (rect == null) { setClipping(0); } else { - setClipping(rect.x, rect.y, rect.width, rect.height); + setClippingInPixels(rect.x, rect.y, rect.width, rect.height); } } /** @@ -3619,6 +4371,35 @@ public void setInterpolation(int interpolation) { public void setLineAttributes(LineAttributes attributes) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + attributes.width = DPIUtil.autoScaleUp(attributes.width); +} +/** + * Sets the receiver's line attributes. + * <p> + * This operation requires the operating system's advanced + * graphics subsystem which may not be available on some + * platforms. + * </p> + * @param attributes the line attributes + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the attributes is null</li> + * <li>ERROR_INVALID_ARGUMENT - if any of the line attributes is not valid</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> + * </ul> + * + * @see LineAttributes + * @see #getAdvanced + * @see #setAdvanced + * + * @since 3.3 + */ +void setLineAttributesInPixels(LineAttributes attributes) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); int mask = 0; float lineWidth = attributes.width; if (lineWidth != data.lineWidth) { @@ -3866,6 +4647,28 @@ public void setLineStyle(int lineStyle) { * </ul> */ public void setLineWidth(int lineWidth) { + setLineWidthInPixels(DPIUtil.autoScaleUp(lineWidth)); +} + +/** + * Sets the width that will be used when drawing lines + * for all of the figure drawing operations (that is, + * <code>drawLine</code>, <code>drawRectangle</code>, + * <code>drawPolyline</code>, and so forth. + * <p> + * Note that line width of zero is used as a hint to + * indicate that the fastest possible line drawing + * algorithms should be used. This means that the + * output may be different from line width one. + * </p> + * + * @param lineWidth the width of a line + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + */ +void setLineWidthInPixels(int lineWidth) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (data.lineWidth == lineWidth) return; data.lineWidth = lineWidth; @@ -4037,7 +4840,6 @@ public void setXORMode(boolean xor) { } data.xorMode = xor; } - /** * Returns the extent of the given string. No tab * expansion or carriage return processing will be performed. @@ -4058,7 +4860,30 @@ public void setXORMode(boolean xor) { * </ul> */ public Point stringExtent(String string) { - return textExtent(string, 0); + return DPIUtil.autoScaleDown(stringExtentInPixels(string)); +} +/** + * Returns the extent of the given string. No tab + * expansion or carriage return processing will be performed. + * <p> + * The <em>extent</em> of a string is the width and height of + * the rectangular area it would cover if drawn in a particular + * font (in this case, the current font in the receiver). + * </p> + * + * @param string the string to measure + * @return a point containing the extent of the string + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +Point stringExtentInPixels(String string) { + return textExtentInPixels(string, 0); } /** @@ -4081,7 +4906,30 @@ public Point stringExtent(String string) { * </ul> */ public Point textExtent(String string) { - return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB); + return DPIUtil.autoScaleDown(textExtentInPixels(string)); +} +/** + * Returns the extent of the given string. Tab expansion and + * carriage return processing are performed. + * <p> + * The <em>extent</em> of a string is the width and height of + * the rectangular area it would cover if drawn in a particular + * font (in this case, the current font in the receiver). + * </p> + * + * @param string the string to measure + * @return a point containing the extent of the string + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +Point textExtentInPixels(String string) { + return textExtentInPixels(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB); } /** @@ -4116,6 +4964,41 @@ public Point textExtent(String string) { * </ul> */ public Point textExtent(String string, int flags) { + return DPIUtil.autoScaleDown(textExtentInPixels(string, flags)); +} +/** + * Returns the extent of the given string. Tab expansion, line + * delimiter and mnemonic processing are performed according to + * the specified flags, which can be a combination of: + * <dl> + * <dt><b>DRAW_DELIMITER</b></dt> + * <dd>draw multiple lines</dd> + * <dt><b>DRAW_TAB</b></dt> + * <dd>expand tabs</dd> + * <dt><b>DRAW_MNEMONIC</b></dt> + * <dd>underline the mnemonic character</dd> + * <dt><b>DRAW_TRANSPARENT</b></dt> + * <dd>transparent background</dd> + * </dl> + * <p> + * The <em>extent</em> of a string is the width and height of + * the rectangular area it would cover if drawn in a particular + * font (in this case, the current font in the receiver). + * </p> + * + * @param string the string to measure + * @param flags the flags specifying how to process the text + * @return a point containing the extent of the string + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +Point textExtentInPixels(String string, int flags) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); setString(string, flags); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java index 7d2ca6b3e0..7d9b50ae4a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java @@ -164,20 +164,21 @@ public final class Image extends Resource implements Drawable { /** * ImageFileNameProvider to provide file names at various Zoom levels */ - ImageFileNameProvider imageFileNameProvider; + private ImageFileNameProvider imageFileNameProvider; /** * ImageDataProvider to provide ImageData at various Zoom levels */ - ImageDataProvider imageDataProvider; + private ImageDataProvider imageDataProvider; /** * Attribute to cache current device zoom level */ - int currentDeviceZoom = 100; + private int currentDeviceZoom = 100; Image(Device device) { super(device); + currentDeviceZoom = DPIUtil.getDeviceZoom(); } /** @@ -217,7 +218,9 @@ Image(Device device) { */ public Image(Device device, int width, int height) { super(device); - init(width, height); + Point size = DPIUtil.autoScaleUp(new Point(width, height)); + currentDeviceZoom = DPIUtil.getDeviceZoom(); + init(size.x, size.y); init(); } @@ -383,6 +386,7 @@ public Image(Device device, Image srcImage, int flag) { } } init(); + currentDeviceZoom = DPIUtil.getDeviceZoom(); return; } @@ -502,6 +506,7 @@ public Image(Device device, Image srcImage, int flag) { OS.g_object_unref(gdkGC); } init(); + currentDeviceZoom = DPIUtil.getDeviceZoom(); } /** @@ -542,7 +547,9 @@ public Image(Device device, Image srcImage, int flag) { public Image(Device device, Rectangle bounds) { super(device); if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - init(bounds.width, bounds.height); + currentDeviceZoom = DPIUtil.getDeviceZoom(); + Rectangle bounds1 = DPIUtil.autoScaleUp (bounds); + init(bounds1.width, bounds1.height); init(); } @@ -571,6 +578,9 @@ public Image(Device device, Rectangle bounds) { */ public Image(Device device, ImageData data) { super(device); + if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + currentDeviceZoom = DPIUtil.getDeviceZoom(); + data = DPIUtil.autoScaleUp (data); init(data); init(); } @@ -612,6 +622,9 @@ public Image(Device device, ImageData source, ImageData mask) { if (source.width != mask.width || source.height != mask.height) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } + currentDeviceZoom = DPIUtil.getDeviceZoom(); + source = DPIUtil.autoScaleUp (source); + mask = DPIUtil.autoScaleUp (mask); mask = ImageData.convertMask (mask); ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data); image.maskPad = mask.scanlinePad; @@ -675,7 +688,10 @@ public Image(Device device, ImageData source, ImageData mask) { */ public Image(Device device, InputStream stream) { super(device); - init(new ImageData(stream)); + ImageData data = new ImageData(stream); + currentDeviceZoom = DPIUtil.getDeviceZoom(); + data = DPIUtil.autoScaleUp (data); + init(data); init(); } @@ -714,8 +730,11 @@ public Image(Device device, InputStream stream) { public Image(Device device, String filename) { super(device); if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - initNative(filename); - if (this.pixmap == 0 && this.surface == 0) init(new ImageData(filename)); + + ImageData data = new ImageData(filename); + currentDeviceZoom = DPIUtil.getDeviceZoom(); + data = DPIUtil.autoScaleUp (data); + init(data); init(); } @@ -750,11 +769,21 @@ public Image(Device device, String filename) { */ public Image(Device device, ImageFileNameProvider imageFileNameProvider) { super(device); - this.imageFileNameProvider = imageFileNameProvider; - currentDeviceZoom = getDeviceZoom (); - String filename = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, currentDeviceZoom, new boolean[1]); - initNative (filename); - if (this.pixmap == 0 && this.surface == 0) init(new ImageData(filename)); + this.setImageFileNameProvider(imageFileNameProvider); + currentDeviceZoom = DPIUtil.getDeviceZoom(); + boolean[] found = new boolean[1]; + String filename = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, currentDeviceZoom, found); + if (found[0]) { + initNative (filename); + if (this.pixmap == 0 && this.surface == 0) { + ImageData data = new ImageData(filename); + init(data); + } + } else { + ImageData imageData = new ImageData (filename); + ImageData resizedData = DPIUtil.autoScaleUp (imageData); + init(resizedData); + } init (); } @@ -789,17 +818,19 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) { */ public Image(Device device, ImageDataProvider imageDataProvider) { super(device); - this.imageDataProvider = imageDataProvider; - currentDeviceZoom = getDeviceZoom (); - ImageData data = DPIUtil.validateAndGetImageDataAtZoom(imageDataProvider, currentDeviceZoom, new boolean[1]); - init (data); + this.setImageDataProvider(imageDataProvider); + currentDeviceZoom = DPIUtil.getDeviceZoom(); + boolean[] found = new boolean[1]; + ImageData data = DPIUtil.validateAndGetImageDataAtZoom(imageDataProvider, currentDeviceZoom, found); + if (found[0]) { + init (data); + } else { + ImageData resizedData = DPIUtil.autoScaleUp (data); + init (resizedData); + } init (); } -int getDeviceZoom () { - return DPIUtil.mapDPIToZoom (device._getDPIx ()); -} - /** * Refresh the Image based on the zoom level, if required. * @@ -807,27 +838,40 @@ int getDeviceZoom () { */ boolean refreshImageForZoom () { boolean refreshed = false; - if (imageFileNameProvider != null) { - int deviceZoomLevel = getDeviceZoom(); + int deviceZoom = DPIUtil.getDeviceZoom(); + if (getImageFileNameProvider() != null) { + int deviceZoomLevel = deviceZoom; if (deviceZoomLevel != currentDeviceZoom) { boolean[] found = new boolean[1]; - String filename = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, deviceZoomLevel, found); + String filename = DPIUtil.validateAndGetImagePathAtZoom (getImageFileNameProvider(), deviceZoomLevel, found); /* Avoid re-creating the fall-back image, when current zoom is already 100% */ if (found[0] || currentDeviceZoom != 100) { /* Release current native resources */ destroy (); initNative(filename); - if (this.pixmap == 0 && this.surface == 0) init(new ImageData(filename)); + if (this.pixmap == 0 && this.surface == 0) { + ImageData data = new ImageData(filename); + init(data); + } + init (); + refreshed = true; + } + if (!found[0]) { + /* Release current native resources */ + destroy (); + ImageData imageData = new ImageData (filename); + ImageData resizedData = DPIUtil.autoScaleUp (imageData); + init(resizedData); init (); refreshed = true; } currentDeviceZoom = deviceZoomLevel; } - } else if (imageDataProvider != null) { - int deviceZoomLevel = getDeviceZoom(); + } else if (getImageDataProvider() != null) { + int deviceZoomLevel = deviceZoom; if (deviceZoomLevel != currentDeviceZoom) { boolean[] found = new boolean[1]; - ImageData data = DPIUtil.validateAndGetImageDataAtZoom (imageDataProvider, deviceZoomLevel, found); + ImageData data = DPIUtil.validateAndGetImageDataAtZoom (getImageDataProvider(), deviceZoomLevel, found); /* Avoid re-creating the fall-back image, when current zoom is already 100% */ if (found[0] || currentDeviceZoom != 100) { /* Release current native resources */ @@ -836,6 +880,14 @@ boolean refreshImageForZoom () { init(); refreshed = true; } + if (!found[0]) { + /* Release current native resources */ + destroy (); + ImageData resizedData = DPIUtil.autoScaleImageData(data, deviceZoomLevel, 100); + init(resizedData); + init(); + refreshed = true; + } currentDeviceZoom = deviceZoomLevel; } } @@ -1023,7 +1075,7 @@ void createMask() { return; } if (mask != 0) return; - mask = createMask(getImageData(), false); + mask = createMask(getImageDataInPixels(), false); if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES); } @@ -1207,10 +1259,10 @@ public boolean equals (Object object) { if (!(object instanceof Image)) return false; Image image = (Image)object; if (device != image.device || transparentPixel != image.transparentPixel) return false; - if (imageDataProvider != null && image.imageDataProvider != null) { - return imageDataProvider.equals (image.imageDataProvider); - } else if (imageFileNameProvider != null && image.imageFileNameProvider != null) { - return imageFileNameProvider.equals (image.imageFileNameProvider); + if (getImageDataProvider() != null && image.getImageDataProvider() != null) { + return getImageDataProvider().equals (image.getImageDataProvider()); + } else if (getImageFileNameProvider() != null && image.getImageFileNameProvider() != null) { + return getImageFileNameProvider().equals (image.getImageFileNameProvider()); } else if (OS.USE_CAIRO) { return surface == image.surface; } else { @@ -1242,13 +1294,12 @@ public Color getBackground() { //NOT DONE return null; } - /** * Returns the bounds of the receiver. The rectangle will always * have x and y values of 0, and the width and height of the * image. * - * @return a rectangle specifying the image's bounds + * @return a rectangle specifying the image's bounds in points * * @exception SWTException <ul> * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> @@ -1257,6 +1308,24 @@ public Color getBackground() { */ public Rectangle getBounds() { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return DPIUtil.autoScaleDown (getBoundsInPixels()); +} + +/** + * Returns the bounds of the receiver. The rectangle will always + * have x and y values of 0, and the width and height of the + * image. + * + * @return a rectangle specifying the image's bounds in pixels + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li> + * </ul> + * @since 3.105 + */ +public Rectangle getBoundsInPixels() { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (width != -1 && height != -1) { return new Rectangle(0, 0, width, height); } @@ -1283,7 +1352,29 @@ public Rectangle getBounds() { * * @see ImageData */ -public ImageData getImageData() { +public ImageData getImageData () { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return getImageData(100); + +} + +/** + * Returns an <code>ImageData</code> based on the receiver + * Modifications made to this <code>ImageData</code> will not + * affect the Image. + * + * @return an <code>ImageData</code> containing the image's data + * and attributes at the current zoom level. + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li> + * </ul> + * + * @see ImageData + * @since 3.105 + */ +public ImageData getImageDataInPixels () { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (OS.USE_CAIRO) { @@ -1396,6 +1487,32 @@ public ImageData getImageData() { } /** + * Returns an <code>ImageData</code> for specified zoom, based on the receiver + * Modifications made to this <code>ImageData</code> will not affect the + * Image. + * + * @param zoom + * The zoom level in % of the standard resolution (which is 1 + * physical monitor pixel == 1 SWT logical pixel). Typically 100, + * 150, or 200. + * @return an <code>ImageData</code> containing the image's data and + * attributes at specified zoom if present else null is returned. + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li> + * </ul> + * + * @see ImageData + * + * @since 3.105 + */ +ImageData getImageData (int zoom) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return DPIUtil.autoScaleImageData (getImageDataInPixels (), zoom, currentDeviceZoom); +} + +/** * Invokes platform specific functionality to allocate a new image. * <p> * <b>IMPORTANT:</b> This method is <em>not</em> part of the public @@ -1460,10 +1577,10 @@ public static Image gtk_new_from_pixbuf(Device device, int type, long /*int*/ pi */ @Override public int hashCode () { - if (imageDataProvider != null) { - return imageDataProvider.hashCode(); - } else if (imageFileNameProvider != null) { - return imageFileNameProvider.hashCode(); + if (getImageDataProvider() != null) { + return getImageDataProvider().hashCode(); + } else if (getImageFileNameProvider() != null) { + return getImageFileNameProvider().hashCode(); } else if (OS.USE_CAIRO) { return (int)/*64*/surface; } else { @@ -1882,4 +1999,34 @@ public String toString () { } } +/** + * @return the imageDataProvider + * @since 3.105 + */ +public ImageDataProvider getImageDataProvider() { + return imageDataProvider; +} + +/** + * @param imageDataProvider the imageDataProvider to set + */ +void setImageDataProvider(ImageDataProvider imageDataProvider) { + this.imageDataProvider = imageDataProvider; +} + +/** + * @return the imageFileNameProvider + * @since 3.105 + */ +public ImageFileNameProvider getImageFileNameProvider() { + return imageFileNameProvider; +} + +/** + * @param imageFileNameProvider the imageFileNameProvider to set + */ +void setImageFileNameProvider(ImageFileNameProvider imageFileNameProvider) { + this.imageFileNameProvider = imageFileNameProvider; +} + } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java index 096cd33812..8656376105 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,9 +11,10 @@ package org.eclipse.swt.graphics; +import org.eclipse.swt.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.cairo.*; import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.*; /** * Instances of this class represent areas of an x-y coordinate @@ -160,6 +161,27 @@ static void gdk_region_get_rectangles(long /*int*/ region, long /*int*/[] rectan public void add (int[] pointArray) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + addInPixels(DPIUtil.autoScaleUp(pointArray)); +} +/** + * Adds the given polygon to the collection of polygons + * the receiver maintains to describe its area. + * + * @param pointArray points that describe the polygon to merge with the receiver + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 +* + */ +void addInPixels (int[] pointArray) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); /* * Bug in GTK. If gdk_region_polygon() is called with one point, * it segment faults. The fix is to make sure that it is called @@ -186,9 +208,27 @@ public void add (int[] pointArray) { * </ul> */ public void add(Rectangle rect) { + addInPixels(DPIUtil.autoScaleUp(rect)); +} +/** + * Adds the given rectangle to the collection of polygons + * the receiver maintains to describe its area. + * + * @param rect the rectangle to merge with the receiver + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void addInPixels(Rectangle rect) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - add (rect.x, rect.y, rect.width, rect.height); + addInPixels (rect.x, rect.y, rect.width, rect.height); } /** @@ -210,6 +250,27 @@ public void add(Rectangle rect) { * @since 3.1 */ public void add(int x, int y, int width, int height) { + add(new Rectangle(x, y, width, height)); +} +/** + * Adds the given rectangle to the collection of polygons + * the receiver maintains to describe its area. + * + * @param x the x coordinate of the rectangle + * @param y the y coordinate of the rectangle + * @param width the width coordinate of the rectangle + * @param height the height coordinate of the rectangle + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +void addInPixels(int x, int y, int width, int height) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); GdkRectangle gdkRect = new GdkRectangle(); @@ -256,6 +317,23 @@ public void add(Region region) { * </ul> */ public boolean contains(int x, int y) { + return contains(new Point(x, y)); +} +/** + * Returns <code>true</code> if the point specified by the + * arguments is inside the area specified by the receiver, + * and <code>false</code> otherwise. + * + * @param x the x coordinate of the point to test for containment + * @param y the y coordinate of the point to test for containment + * @return <code>true</code> if the region contains the point and <code>false</code> otherwise + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +boolean containsInPixels(int x, int y) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); return OS.gdk_region_point_in(handle, x, y); } @@ -276,8 +354,27 @@ public boolean contains(int x, int y) { * </ul> */ public boolean contains(Point pt) { + return containsInPixels(DPIUtil.autoScaleUp(pt)); +} +/** + * Returns <code>true</code> if the given point is inside the + * area specified by the receiver, and <code>false</code> + * otherwise. + * + * @param pt the point to test for containment + * @return <code>true</code> if the region contains the point and <code>false</code> otherwise + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +boolean containsInPixels(Point pt) { if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - return contains(pt.x, pt.y); + return containsInPixels(pt.x, pt.y); } @Override @@ -318,6 +415,23 @@ public boolean equals(Object object) { * @see Rectangle#union */ public Rectangle getBounds() { + return DPIUtil.autoScaleDown(getBoundsInPixels()); +} +/** + * Returns a rectangle which represents the rectangular + * union of the collection of polygons the receiver + * maintains to describe its area. + * + * @return a bounding rectangle for the region + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see Rectangle#union + * @since 3.105 + */ +Rectangle getBoundsInPixels() { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); GdkRectangle gdkRect = new GdkRectangle(); OS.gdk_region_get_clipbox(handle, gdkRect); @@ -376,9 +490,28 @@ public int hashCode() { * @since 3.0 */ public void intersect(Rectangle rect) { + intersectInPixels(DPIUtil.autoScaleUp(rect)); +} +/** + * Intersects the given rectangle to the collection of polygons + * the receiver maintains to describe its area. + * + * @param rect the rectangle to intersect with the receiver + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +void intersectInPixels(Rectangle rect) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - intersect (rect.x, rect.y, rect.width, rect.height); + intersectInPixels (rect.x, rect.y, rect.width, rect.height); } /** @@ -400,6 +533,27 @@ public void intersect(Rectangle rect) { * @since 3.1 */ public void intersect(int x, int y, int width, int height) { + intersect(new Rectangle(x, y, width, height)); +} +/** + * Intersects the given rectangle to the collection of polygons + * the receiver maintains to describe its area. + * + * @param x the x coordinate of the rectangle + * @param y the y coordinate of the rectangle + * @param width the width coordinate of the rectangle + * @param height the height coordinate of the rectangle + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +void intersectInPixels(int x, int y, int width, int height) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); GdkRectangle gdkRect = new GdkRectangle(); @@ -454,6 +608,28 @@ public void intersect(Region region) { * @see Rectangle#intersects(Rectangle) */ public boolean intersects (int x, int y, int width, int height) { + return intersects(new Rectangle(x, y, width, height)); +} + +/** + * Returns <code>true</code> if the rectangle described by the + * arguments intersects with any of the polygons the receiver + * maintains to describe its area, and <code>false</code> otherwise. + * + * @param x the x coordinate of the origin of the rectangle + * @param y the y coordinate of the origin of the rectangle + * @param width the width of the rectangle + * @param height the height of the rectangle + * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see Rectangle#intersects(Rectangle) + * @since 3.105 + */ +boolean intersectsInPixels (int x, int y, int width, int height) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); GdkRectangle gdkRect = new GdkRectangle(); gdkRect.x = x; @@ -480,8 +656,29 @@ public boolean intersects (int x, int y, int width, int height) { * @see Rectangle#intersects(Rectangle) */ public boolean intersects(Rectangle rect) { + return intersectsInPixels(DPIUtil.autoScaleUp(rect)); +} +/** + * Returns <code>true</code> if the given rectangle intersects + * with any of the polygons the receiver maintains to describe + * its area and <code>false</code> otherwise. + * + * @param rect the rectangle to test for intersection + * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see Rectangle#intersects(Rectangle) + * @since 3.105 + */ +boolean intersectsInPixels(Rectangle rect) { if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - return intersects(rect.x, rect.y, rect.width, rect.height); + return intersectsInPixels(rect.x, rect.y, rect.width, rect.height); } /** @@ -533,6 +730,27 @@ public boolean isEmpty() { public void subtract (int[] pointArray) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + subtractInPixels(DPIUtil.autoScaleUp(pointArray)); +} + +/** + * Subtracts the given polygon from the collection of polygons + * the receiver maintains to describe its area. + * + * @param pointArray points that describe the polygon to merge with the receiver + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +void subtractInPixels (int[] pointArray) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); /* * Bug in GTK. If gdk_region_polygon() is called with one point, * it segment faults. The fix is to make sure that it is called @@ -543,7 +761,6 @@ public void subtract (int[] pointArray) { OS.gdk_region_subtract(handle, polyRgn); OS.gdk_region_destroy(polyRgn); } - /** * Subtracts the given rectangle from the collection of polygons * the receiver maintains to describe its area. @@ -561,9 +778,29 @@ public void subtract (int[] pointArray) { * @since 3.0 */ public void subtract(Rectangle rect) { + subtractInPixels(DPIUtil.autoScaleUp(rect)); +} + +/** + * Subtracts the given rectangle from the collection of polygons + * the receiver maintains to describe its area. + * + * @param rect the rectangle to subtract from the receiver + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +void subtractInPixels(Rectangle rect) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - subtract (rect.x, rect.y, rect.width, rect.height); + subtractInPixels (rect.x, rect.y, rect.width, rect.height); } /** @@ -585,6 +822,28 @@ public void subtract(Rectangle rect) { * @since 3.1 */ public void subtract(int x, int y, int width, int height) { + subtract(new Rectangle(x, y, width, height)); +} + +/** + * Subtracts the given rectangle from the collection of polygons + * the receiver maintains to describe its area. + * + * @param x the x coordinate of the rectangle + * @param y the y coordinate of the rectangle + * @param width the width coordinate of the rectangle + * @param height the height coordinate of the rectangle + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +void subtractInPixels(int x, int y, int width, int height) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); GdkRectangle gdkRect = new GdkRectangle(); @@ -635,6 +894,23 @@ public void subtract(Region region) { * @since 3.1 */ public void translate (int x, int y) { + translate(new Point(x, y)); +} + +/** + * Translate all of the polygons the receiver maintains to describe + * its area by the specified point. + * + * @param x the x coordinate of the point to translate + * @param y the y coordinate of the point to translate + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +void translateInPixels (int x, int y) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); OS.gdk_region_offset (handle, x, y); } @@ -655,9 +931,28 @@ public void translate (int x, int y) { * @since 3.1 */ public void translate (Point pt) { + translate(DPIUtil.autoScaleUp(pt)); +} + +/** + * Translate all of the polygons the receiver maintains to describe + * its area by the specified point. + * + * @param pt the point to translate + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +void translateInPixels (Point pt) { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - translate (pt.x, pt.y); + translateInPixels (pt.x, pt.y); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java index 2c11cb88fb..186742caae 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,10 +10,10 @@ *******************************************************************************/ package org.eclipse.swt.graphics; +import org.eclipse.swt.*; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.cairo.*; import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.*; /** * <code>TextLayout</code> is a graphic object that represents @@ -367,7 +367,29 @@ void destroy() { * </ul> */ public void draw(GC gc, int x, int y) { - draw(gc, x, y, -1, -1, null, null); + x = DPIUtil.autoScaleUp(x); + y = DPIUtil.autoScaleUp(y); + drawInPixels(gc, x, y); +} + +/** + * Draws the receiver's text using the specified GC at the specified + * point. + * + * @param gc the GC to draw + * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn + * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> + * </ul> + * @since 3.105 + */ +void drawInPixels(GC gc, int x, int y) { + drawInPixels(gc, x, y, -1, -1, null, null); } /** @@ -390,7 +412,32 @@ public void draw(GC gc, int x, int y) { * </ul> */ public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) { - draw(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground, 0); + x = DPIUtil.autoScaleUp(x); + y = DPIUtil.autoScaleUp(y); + drawInPixels(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground); +} +/** + * Draws the receiver's text using the specified GC at the specified + * point. + * + * @param gc the GC to draw + * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn + * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn + * @param selectionStart the offset where the selections starts, or -1 indicating no selection + * @param selectionEnd the offset where the selections ends, or -1 indicating no selection + * @param selectionForeground selection foreground, or NULL to use the system default color + * @param selectionBackground selection background, or NULL to use the system default color + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> + * </ul> + * @since 3.105 + */ +void drawInPixels(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) { + drawInPixels(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground, 0); } /** @@ -421,6 +468,38 @@ public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Colo * @since 3.3 */ public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) { + x = DPIUtil.autoScaleUp(x); + y = DPIUtil.autoScaleUp(y); + drawInPixels(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground, flags); +} +/** + * Draws the receiver's text using the specified GC at the specified + * point. + * <p> + * The parameter <code>flags</code> can include one of <code>SWT.DELIMITER_SELECTION</code> + * or <code>SWT.FULL_SELECTION</code> to specify the selection behavior on all lines except + * for the last line, and can also include <code>SWT.LAST_LINE_SELECTION</code> to extend + * the specified selection behavior to the last line. + * </p> + * @param gc the GC to draw + * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn + * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn + * @param selectionStart the offset where the selections starts, or -1 indicating no selection + * @param selectionEnd the offset where the selections ends, or -1 indicating no selection + * @param selectionForeground selection foreground, or NULL to use the system default color + * @param selectionBackground selection background, or NULL to use the system default color + * @param flags drawing options + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> + * </ul> + * + * @since 3.105 + */ +void drawInPixels(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) { checkLayout (); computeRuns(); if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); @@ -775,6 +854,24 @@ public int getAscent () { * @see #getLineBounds(int) */ public Rectangle getBounds() { + return DPIUtil.autoScaleDown(getBoundsInPixels()); +} +/** + * Returns the bounds of the receiver. The width returned is either the + * width of the longest line or the width set using {@link TextLayout#setWidth(int)}. + * To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}. + * + * @return the bounds of the receiver + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #setWidth(int) + * @see #getLineBounds(int) + * @since 3.105 + */ +Rectangle getBoundsInPixels() { checkLayout(); computeRuns(); int[] w = new int[1], h = new int[1]; @@ -805,6 +902,24 @@ public Rectangle getBounds() { * </ul> */ public Rectangle getBounds(int start, int end) { + return DPIUtil.autoScaleDown(getBoundsInPixels(start, end)); +} +/** + * Returns the bounds for the specified range of characters. The + * bounds is the smallest rectangle that encompasses all characters + * in the range. The start and end offsets are inclusive and will be + * clamped if out of range. + * + * @param start the start offset + * @param end the end offset + * @return the bounds of the character range + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +Rectangle getBoundsInPixels(int start, int end) { checkLayout(); computeRuns(); int length = text.length(); @@ -909,6 +1024,21 @@ public Font getFont () { * @since 3.2 */ public int getIndent () { + return DPIUtil.autoScaleDown(getIndentInPixels()); +} + +/** +* Returns the receiver's indent. +* +* @return the receiver's indent +* +* @exception SWTException <ul> +* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> +* </ul> +* +* @since 3.105 +*/ +int getIndentInPixels () { checkLayout(); return indent; } @@ -987,6 +1117,23 @@ public int getLevel(int offset) { * </ul> */ public Rectangle getLineBounds(int lineIndex) { + return DPIUtil.autoScaleDown(getLineBoundsInPixels(lineIndex)); +} +/** + * Returns the bounds of the line for the specified line index. + * + * @param lineIndex the line index + * @return the line bounds + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +Rectangle getLineBoundsInPixels(int lineIndex) { checkLayout(); computeRuns(); int lineCount = OS.pango_layout_get_line_count(layout); @@ -1146,6 +1293,27 @@ public int[] getLineOffsets() { * @see #getOffset(int, int, int[]) */ public Point getLocation(int offset, boolean trailing) { + return DPIUtil.autoScaleDown(getLocationInPixels(offset, trailing)); +} + +/** + * Returns the location for the specified character offset. The + * <code>trailing</code> argument indicates whether the offset + * corresponds to the leading or trailing edge of the cluster. + * + * @param offset the character offset + * @param trailing the trailing flag + * @return the location of the character offset + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #getOffset(Point, int[]) + * @see #getOffset(int, int, int[]) + * @since 3.105 + */ +Point getLocationInPixels(int offset, boolean trailing) { checkLayout(); computeRuns(); int length = text.length(); @@ -1281,9 +1449,36 @@ int _getOffset (int offset, int movement, boolean forward) { * @see #getLocation(int, boolean) */ public int getOffset(Point point, int[] trailing) { + return getOffsetInPixels(DPIUtil.autoScaleUp(point), trailing); +} +/** + * Returns the character offset for the specified point. + * For a typical character, the trailing argument will be filled in to + * indicate whether the point is closer to the leading edge (0) or + * the trailing edge (1). When the point is over a cluster composed + * of multiple characters, the trailing argument will be filled with the + * position of the character in the cluster that is closest to + * the point. + * + * @param point the point + * @param trailing the trailing buffer + * @return the character offset + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li> + * <li>ERROR_NULL_ARGUMENT - if the point is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #getLocation(int, boolean) + * @since 3.105 + */ +int getOffsetInPixels(Point point, int[] trailing) { checkLayout(); if (point == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - return getOffset(point.x, point.y, trailing); + return getOffsetInPixels(point.x, point.y, trailing); } /** @@ -1310,6 +1505,33 @@ public int getOffset(Point point, int[] trailing) { * @see #getLocation(int, boolean) */ public int getOffset(int x, int y, int[] trailing) { + return getOffset(new Point(x, y), trailing); +} +/** + * Returns the character offset for the specified point. + * For a typical character, the trailing argument will be filled in to + * indicate whether the point is closer to the leading edge (0) or + * the trailing edge (1). When the point is over a cluster composed + * of multiple characters, the trailing argument will be filled with the + * position of the character in the cluster that is closest to + * the point. + * + * @param x the x coordinate of the point + * @param y the y coordinate of the point + * @param trailing the trailing buffer + * @return the character offset + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #getLocation(int, boolean) + * @since 3.105 + */ +int getOffsetInPixels(int x, int y, int[] trailing) { checkLayout(); computeRuns(); if (trailing != null && trailing.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); @@ -1499,6 +1721,20 @@ String getSegmentsText() { * </ul> */ public int getSpacing () { + return DPIUtil.autoScaleDown(getSpacingInPixels()); +} + +/** + * Returns the line spacing of the receiver. + * + * @return the line spacing + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +int getSpacingInPixels () { checkLayout(); return OS.PANGO_PIXELS(OS.pango_layout_get_spacing(layout)); } @@ -1612,6 +1848,20 @@ public int getTextDirection () { * </ul> */ public int getWidth () { + return DPIUtil.autoScaleDown(getWidthInPixels()); +} + +/** + * Returns the width of the receiver. + * + * @return the width + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +protected int getWidthInPixels () { checkLayout (); return wrapWidth; } @@ -1628,6 +1878,20 @@ public int getWidth () { * @since 3.6 */ public int getWrapIndent () { + return DPIUtil.autoScaleDown(getWrapIndentInPixels()); +} +/** +* Returns the receiver's wrap indent. +* +* @return the receiver's wrap indent +* +* @exception SWTException <ul> +* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> +* </ul> +* +* @since 3.105 +*/ +int getWrapIndentInPixels () { checkLayout (); return wrapIndent; } @@ -1780,6 +2044,24 @@ public void setFont (Font font) { * @since 3.2 */ public void setIndent (int indent) { + setIndentInPixels(DPIUtil.autoScaleUp(indent)); +} + +/** + * Sets the indent of the receiver. This indent is applied to the first line of + * each paragraph. + * + * @param indent new indent + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #setWrapIndent(int) + * + * @since 3.105 + */ +void setIndentInPixels (int indent) { checkLayout(); if (indent < 0) return; if (this.indent == indent) return; @@ -1847,6 +2129,24 @@ public void setOrientation(int orientation) { * </ul> */ public void setSpacing (int spacing) { + setSpacingInPixels(DPIUtil.autoScaleUp(spacing)); +} + +/** + * Sets the line spacing of the receiver. The line spacing + * is the space left between lines. + * + * @param spacing the new line spacing + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the spacing is negative</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +void setSpacingInPixels (int spacing) { checkLayout(); if (spacing < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); OS.pango_layout_set_spacing(layout, spacing * OS.PANGO_SCALE); @@ -2144,6 +2444,27 @@ public void setTextDirection (int textDirection) { * @see #setAlignment(int) */ public void setWidth (int width) { + setWidthInPixels(DPIUtil.autoScaleUp(width)); +} + +/** + * Sets the line width of the receiver, which determines how + * text should be wrapped and aligned. The default value is + * <code>-1</code> which means wrapping is disabled. + * + * @param width the new width + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the width is <code>0</code> or less than <code>-1</code></li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #setAlignment(int) + * @since 3.105 + */ +void setWidthInPixels (int width) { checkLayout (); if (width < -1 || width == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); if (wrapWidth == width) return; @@ -2178,6 +2499,24 @@ void setWidth () { * @since 3.6 */ public void setWrapIndent (int wrapIndent) { + setWrapIndentInPixels(DPIUtil.autoScaleUp(wrapIndent)); +} + +/** + * Sets the wrap indent of the receiver. This indent is applied to all lines + * in the paragraph except the first line. + * + * @param wrapIndent new wrap indent + * + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @see #setIndent(int) + * + * @since 3.105 + */ +void setWrapIndentInPixels (int wrapIndent) { checkLayout(); if (wrapIndent < 0) return; if (this.wrapIndent == wrapIndent) return; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java index 60c30d1bc3..a2964efcf9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/ImageList.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,10 +11,10 @@ package org.eclipse.swt.internal; -import org.eclipse.swt.SWT; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.cairo.*; import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; public class ImageList { long /*int*/ [] pixbufs; @@ -30,7 +30,7 @@ public static long /*int*/ convertSurface(Image image) { long /*int*/ newSurface = image.surface; int type = Cairo.cairo_surface_get_type(newSurface); if (type != Cairo.CAIRO_SURFACE_TYPE_IMAGE) { - Rectangle bounds = image.getBounds(); + Rectangle bounds = image.getBoundsInPixels(); int format = Cairo.cairo_surface_get_content(newSurface) == Cairo.CAIRO_CONTENT_COLOR ? Cairo.CAIRO_FORMAT_RGB24 : Cairo.CAIRO_FORMAT_ARGB32; newSurface = Cairo.cairo_image_surface_create(format, bounds.width, bounds.height); if (newSurface == 0) SWT.error(SWT.ERROR_NO_HANDLES); @@ -136,7 +136,7 @@ public static long /*int*/ createPixbuf(Image image) { } OS.g_object_unref(maskPixbuf); } else { - ImageData data = image.getImageData (); + ImageData data = image.getImageDataInPixels (); boolean hasAlpha = data.getTransparencyType () == SWT.TRANSPARENCY_ALPHA; pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, hasAlpha, 8, w [0], h [0]); if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java index 7fef8617d2..42474ec319 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -165,8 +165,7 @@ public void addSelectionListener (SelectionListener listener) { addListener (SWT.DefaultSelection,typedListener); } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java index 86119022e3..9a5ced729d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,6 +13,7 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.cairo.*; import org.eclipse.swt.internal.gtk.*; @@ -257,6 +258,35 @@ void reskinChildren (int flags) { * </ul> */ public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) { + Point destination = DPIUtil.autoScaleUp (new Point (destX, destY)); + Rectangle srcRect = DPIUtil.autoScaleUp (new Rectangle (x, y, width, height)); + scrollInPixels(destination.x, destination.y, srcRect.x, srcRect.y, srcRect.width, srcRect.height, all); +} + +/** + * Scrolls a rectangular area of the receiver by first copying + * the source area to the destination and then causing the area + * of the source which is not covered by the destination to + * be repainted. Children that intersect the rectangle are + * optionally moved during the operation. In addition, all outstanding + * paint events are flushed before the source area is copied to + * ensure that the contents of the canvas are drawn correctly. + * + * @param destX the x coordinate of the destination + * @param destY the y coordinate of the destination + * @param x the x coordinate of the source + * @param y the y coordinate of the source + * @param width the width of the area + * @param height the height of the area + * @param all <code>true</code>if children should be scrolled, and <code>false</code> otherwise + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void scrollInPixels (int destX, int destY, int x, int y, int width, int height, boolean all) { checkWidget(); if (width <= 0 || height <= 0) return; if ((style & SWT.MIRRORED) != 0) { @@ -357,10 +387,10 @@ public void scroll (int destX, int destY, int x, int y, int width, int height, b Control [] children = _getChildren (); for (int i=0; i<children.length; i++) { Control child = children [i]; - Rectangle rect = child.getBounds (); + Rectangle rect = child.getBoundsInPixels (); if (Math.min(x + width, rect.x + rect.width) >= Math.max (x, rect.x) && Math.min(y + height, rect.y + rect.height) >= Math.max (y, rect.y)) { - child.setLocation (rect.x + deltaX, rect.y + deltaY); + child.setLocationInPixels (rect.x + deltaX, rect.y + deltaY); } } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java index aca785f36a..131062285c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,9 +12,10 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.cairo.*; import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; /** * Instances of this class provide an i-beam that is typically used @@ -171,8 +172,25 @@ boolean drawCaret () { */ public Rectangle getBounds () { checkWidget(); + return DPIUtil.autoScaleDown(getBoundsInPixels()); +} + +/** + * Returns a rectangle describing the receiver's size and location + * relative to its parent (or its display if its parent is null). + * + * @return the receiver's bounding rectangle + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Rectangle getBoundsInPixels () { + checkWidget(); if (image != null) { - Rectangle rect = image.getBounds (); + Rectangle rect = image.getBoundsInPixels (); return new Rectangle (x, y, rect.width, rect.height); } else { if (width == 0) { @@ -226,6 +244,23 @@ public Image getImage () { */ public Point getLocation () { checkWidget(); + return DPIUtil.autoScaleDown(getLocationInPixels()); +} + +/** + * Returns a point describing the receiver's location relative + * to its parent (or its display if its parent is null). + * + * @return the receiver's location + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Point getLocationInPixels () { + checkWidget(); return new Point (x, y); } @@ -255,9 +290,24 @@ public Canvas getParent () { * </ul> */ public Point getSize () { + return DPIUtil.autoScaleDown(getSizeInPixels()); +} + +/** + * Returns a point describing the receiver's size. + * + * @return the receiver's size + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Point getSizeInPixels () { checkWidget(); if (image != null) { - Rectangle rect = image.getBounds (); + Rectangle rect = image.getBoundsInPixels (); return new Point (rect.width, rect.height); } else { if (width == 0) { @@ -358,6 +408,26 @@ void releaseWidget () { * </ul> */ public void setBounds (int x, int y, int width, int height) { + setBounds (new Rectangle (x, y, width, height)); +} +/** + * Sets the receiver's size and location to the rectangular + * area specified by the arguments. The <code>x</code> and + * <code>y</code> arguments are relative to the receiver's + * parent (or its display if its parent is null). + * + * @param x the new x coordinate for the receiver + * @param y the new y coordinate for the receiver + * @param width the new width for the receiver + * @param height the new height for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setBoundsInPixels (int x, int y, int width, int height) { checkWidget(); if (this.x == x && this.y == y && this.width == width && this.height == height) return; boolean isFocus = isFocusCaret (); @@ -382,9 +452,27 @@ public void setBounds (int x, int y, int width, int height) { * </ul> */ public void setBounds (Rectangle rect) { + rect = DPIUtil.autoScaleUp(rect); + setBoundsInPixels(rect); +} +/** + * Sets the receiver's size and location to the rectangular + * area specified by the argument. The <code>x</code> and + * <code>y</code> fields of the rectangle are relative to + * the receiver's parent (or its display if its parent is null). + * + * @param rect the new bounds for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setBoundsInPixels (Rectangle rect) { checkWidget(); if (rect == null) error (SWT.ERROR_NULL_ARGUMENT); - setBounds (rect.x, rect.y, rect.width, rect.height); + setBoundsInPixels (rect.x, rect.y, rect.width, rect.height); } void setFocus () { @@ -456,8 +544,25 @@ public void setImage (Image image) { * </ul> */ public void setLocation (int x, int y) { + setLocation (new Point (x, y)); +} +/** + * Sets the receiver's location to the point specified by + * the arguments which are relative to the receiver's + * parent (or its display if its parent is null). + * + * @param x the new x coordinate for the receiver + * @param y the new y coordinate for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setLocationInPixels (int x, int y) { checkWidget(); - setBounds (x, y, width, height); + setBoundsInPixels (x, y, width, height); } /** @@ -473,9 +578,26 @@ public void setLocation (int x, int y) { * </ul> */ public void setLocation (Point location) { + setLocationInPixels (DPIUtil.autoScaleUp (location)); +} + +/** + * Sets the receiver's location to the point specified by + * the argument which is relative to the receiver's + * parent (or its display if its parent is null). + * + * @param location the new location for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +protected void setLocationInPixels (Point location) { checkWidget(); if (location == null) error (SWT.ERROR_NULL_ARGUMENT); - setLocation (location.x, location.y); + setLocationInPixels (location.x, location.y); } /** @@ -490,8 +612,24 @@ public void setLocation (Point location) { * </ul> */ public void setSize (int width, int height) { + setSize (new Point (width,height)); +} + +/** + * Sets the receiver's size to the point specified by the arguments. + * + * @param width the new width for the receiver + * @param height the new height for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setSizeInPixels (int width, int height) { checkWidget(); - setBounds (x, y, width, height); + setBoundsInPixels (x, y, width, height); } /** @@ -508,9 +646,27 @@ public void setSize (int width, int height) { * </ul> */ public void setSize (Point size) { + setSizeInPixels(DPIUtil.autoScaleUp (size)); +} + +/** + * Sets the receiver's size to the point specified by the argument. + * + * @param size the new extent for the receiver + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the point is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setSizeInPixels (Point size) { checkWidget(); if (size == null) error (SWT.ERROR_NULL_ARGUMENT); - setSize (size.x, size.y); + setSizeInPixels (size.x, size.y); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java index b6a5e02ac8..321d0165be 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -393,8 +393,7 @@ void clearText () { OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); if ((style & SWT.READ_ONLY) != 0 || OS.GTK3) { return computeNativeSize (handle, wHint, hHint, changed); @@ -850,6 +849,23 @@ GdkColor getBackgroundColor () { */ public Point getCaretLocation () { checkWidget (); + return DPIUtil.autoScaleDown(getCaretLocationInPixels()); +} +/** + * Returns a point describing the location of the caret relative + * to the receiver. + * + * @return a point, the location of the caret + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +Point getCaretLocationInPixels () { + checkWidget (); if ((style & SWT.READ_ONLY) != 0) { return new Point (0, 0); } @@ -860,7 +876,7 @@ public Point getCaretLocation () { long /*int*/ layout = OS.gtk_entry_get_layout (entryHandle); PangoRectangle pos = new PangoRectangle (); OS.pango_layout_index_to_pos (layout, index, pos); - int x = offset_x [0] + OS.PANGO_PIXELS (pos.x) - getBorderWidth (); + int x = offset_x [0] + OS.PANGO_PIXELS (pos.x) - getBorderWidthInPixels (); int y = offset_y [0] + OS.PANGO_PIXELS (pos.y); return new Point (x, y); } @@ -1137,6 +1153,22 @@ String getText (int start, int stop) { */ public int getTextHeight () { checkWidget(); + return DPIUtil.autoScaleDown(getTextHeightInPixels()); +} + +/** + * Returns the height of the receivers's text field. + * + * @return the text height + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +int getTextHeightInPixels () { + checkWidget(); GtkRequisition requisition = new GtkRequisition (); gtk_widget_size_request (handle, requisition); if (OS.GTK3) { @@ -1915,7 +1947,7 @@ void setBackgroundColor (GdkColor color) { @Override int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { int newHeight = height; - if (resize) newHeight = Math.max (getTextHeight (), height); + if (resize) newHeight = Math.max (getTextHeightInPixels (), height); return super.setBounds (x, y, width, newHeight, move, resize); } @@ -2151,6 +2183,27 @@ public void setOrientation (int orientation) { * </ul> */ public void setSelection (Point selection) { + selection = DPIUtil.autoScaleUp(selection); +} + +/** + * Sets the selection in the receiver's text field to the + * range specified by the argument whose x coordinate is the + * start of the selection and whose y coordinate is the end + * of the selection. + * + * @param selection a point representing the new selection start and end + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the point is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setSelectionInPixels (Point selection) { checkWidget(); if (selection == null) error (SWT.ERROR_NULL_ARGUMENT); if ((style & SWT.READ_ONLY) != 0) return; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java index 463fab0d94..a6c546da9b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,6 +13,7 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.cairo.*; import org.eclipse.swt.internal.gtk.*; @@ -64,6 +65,7 @@ public class Composite extends Scrollable { Layout layout; Control[] tabList; int layoutCount, backgroundMode; + GdkRGBA background; static final String NO_INPUT_METHOD = "org.eclipse.swt.internal.gtk.noInputMethod"; //$NON-NLS-1$ @@ -226,8 +228,7 @@ long /*int*/ childStyle () { return super.childStyle (); } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); display.runSkin(); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; @@ -236,7 +237,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { if (layout != null) { if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { changed |= (state & LAYOUT_CHANGED) != 0; - size = layout.computeSize (this, wHint, hHint, changed); + size = DPIUtil.autoScaleUp(layout.computeSize (this, wHint, hHint, changed)); state &= ~LAYOUT_CHANGED; } else { size = new Point (wHint, hHint); @@ -248,7 +249,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { } if (wHint != SWT.DEFAULT) size.x = wHint; if (hHint != SWT.DEFAULT) size.y = hHint; - Rectangle trim = computeTrim (0, 0, size.x, size.y); + Rectangle trim = computeTrimInPixels (0, 0, size.x, size.y); return new Point (trim.width, trim.height); } @@ -400,6 +401,40 @@ void deregister () { * @since 3.6 */ public void drawBackground (GC gc, int x, int y, int width, int height, int offsetX, int offsetY) { + Rectangle rect = DPIUtil.autoScaleUp(new Rectangle (x, y, width, height)); + offsetX = DPIUtil.autoScaleUp(offsetX); + offsetY = DPIUtil.autoScaleUp(offsetY); + drawBackgroundInPixels(gc, rect.x, rect.y, rect.width, rect.height, offsetX, offsetY); +} + +/** + * Fills the interior of the rectangle specified by the arguments, + * with the receiver's background. + * + * <p>The <code>offsetX</code> and <code>offsetY</code> are used to map from + * the <code>gc</code> origin to the origin of the parent image background. This is useful + * to ensure proper alignment of the image background.</p> + * + * @param gc the gc where the rectangle is to be filled + * @param x the x coordinate of the rectangle to be filled + * @param y the y coordinate of the rectangle to be filled + * @param width the width of the rectangle to be filled + * @param height the height of the rectangle to be filled + * @param offsetX the image background x offset + * @param offsetY the image background y offset + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +void drawBackgroundInPixels (GC gc, int x, int y, int width, int height, int offsetX, int offsetY) { checkWidget (); if (gc == null) error (SWT.ERROR_NULL_ARGUMENT); if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); @@ -410,7 +445,7 @@ public void drawBackground (GC gc, int x, int y, int width, int height, int offs if (cairo != 0) { Cairo.cairo_save (cairo); if (control.backgroundImage != null) { - Point pt = display.map (this, control, 0, 0); + Point pt = display.mapInPixels (this, control, 0, 0); Cairo.cairo_translate (cairo, -pt.x - offsetX, -pt.y - offsetY); x += pt.x + offsetX; y += pt.y + offsetY; @@ -453,7 +488,7 @@ public void drawBackground (GC gc, int x, int y, int width, int height, int offs GdkGCValues values = new GdkGCValues (); OS.gdk_gc_get_values (gdkGC, values); if (control.backgroundImage != null) { - Point pt = display.map (this, control, 0, 0); + Point pt = display.mapInPixels (this, control, 0, 0); OS.gdk_gc_set_fill (gdkGC, OS.GDK_TILED); OS.gdk_gc_set_ts_origin (gdkGC, -pt.x - offsetX, -pt.y - offsetY); OS.gdk_gc_set_tile (gdkGC, control.backgroundImage.pixmap); @@ -469,7 +504,8 @@ public void drawBackground (GC gc, int x, int y, int width, int height, int offs } } } else { - gc.fillRectangle (x, y, width, height); + gc.fillRectangle(DPIUtil.autoScaleDown(new Rectangle(x, y, width, height))); + } } @@ -648,7 +684,7 @@ int getChildrenCount () { } @Override -public Rectangle getClientArea () { +Rectangle getClientAreaInPixels () { checkWidget(); if ((state & CANVAS) != 0) { if ((state & ZERO_WIDTH) != 0 && (state & ZERO_HEIGHT) != 0) { @@ -662,7 +698,24 @@ public Rectangle getClientArea () { int height = (state & ZERO_HEIGHT) != 0 ? 0 : allocation.height; return new Rectangle (0, 0, width, height); } - return super.getClientArea(); + return super.getClientAreaInPixels(); +} + +@Override +GdkColor getContextBackground () { + if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) { + if (background != null) { + GdkColor color = new GdkColor (); + color.red = (short)(background.red * 0xFFFF); + color.green = (short)(background.green * 0xFFFF); + color.blue = (short)(background.blue * 0xFFFF); + return color; + } else { + return display.COLOR_WIDGET_BACKGROUND; + } + } else { + return super.getContextBackground(); + } } /** @@ -769,11 +822,8 @@ long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ eventPtr) { for (int i=0; i<n_rectangles[0]; i++) { Event event = new Event (); OS.memmove (rect, rectangles [0] + i * GdkRectangle.sizeof, GdkRectangle.sizeof); - event.x = rect.x; - event.y = rect.y; - event.width = rect.width; - event.height = rect.height; - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x; + event.setBounds (DPIUtil.autoScaleDown (new Rectangle(rect.x, rect.y, rect.width, rect.height))); + if ((style & SWT.MIRRORED) != 0) event.x = DPIUtil.autoScaleDown (getClientWidth ()) - event.width - event.x; long /*int*/ damageRgn = OS.gdk_region_new (); OS.gdk_region_union_with_rect (damageRgn, rect); GCData data = new GCData (); @@ -1339,10 +1389,10 @@ void moveChildren(int oldWidth) { Point minimumSize (int wHint, int hHint, boolean changed) { Control [] children = _getChildren (); - Rectangle clientArea = getClientArea (); + Rectangle clientArea = getClientAreaInPixels (); int width = 0, height = 0; for (int i=0; i<children.length; i++) { - Rectangle rect = children [i].getBounds (); + Rectangle rect = children [i].getBoundsInPixels (); width = Math.max (width, rect.x - clientArea.x + rect.width); height = Math.max (height, rect.y - clientArea.y + rect.height); } @@ -1358,23 +1408,24 @@ long /*int*/ parentingHandle () { void printWidget (GC gc, long /*int*/ drawable, int depth, int x, int y) { Region oldClip = new Region (gc.getDevice ()); Region newClip = new Region (gc.getDevice ()); + Point loc = DPIUtil.autoScaleDown(new Point (x, y)); gc.getClipping (oldClip); Rectangle rect = getBounds (); newClip.add (oldClip); - newClip.intersect (x, y, rect.width, rect.height); + newClip.intersect (loc.x, loc.y, rect.width, rect.height); gc.setClipping (newClip); super.printWidget (gc, drawable, depth, x, y); - Rectangle clientRect = getClientArea (); - Point pt = display.map (this, parent, clientRect.x, clientRect.y); + Rectangle clientRect = getClientAreaInPixels (); + Point pt = display.mapInPixels (this, parent, clientRect.x, clientRect.y); clientRect.x = x + pt.x - rect.x; clientRect.y = y + pt.y - rect.y; - newClip.intersect (clientRect); + newClip.intersect (DPIUtil.autoScaleDown(clientRect)); gc.setClipping (newClip); Control [] children = _getChildren (); for (int i=children.length-1; i>=0; --i) { Control child = children [i]; if (child.getVisible ()) { - Point location = child.getLocation (); + Point location = child.getLocationInPixels (); child.printWidget (gc, drawable, depth, x + location.x, y + location.y); } } @@ -1482,6 +1533,18 @@ public void setBackgroundMode (int mode) { } @Override +void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) { + if (OS.GTK_VERSION >= OS.VERSION(3, 16, 0)) { + background = rgba; + String color = gtk_rgba_to_css_string(background); + String css = "SwtFixed {background-color: " + color + "}"; + gtk_css_provider_load_from_css(context, css); + } else { + super.setBackgroundColor(context, handle, rgba); + } +} + +@Override int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { int result = super.setBounds (x, y, width, height, move, resize); if ((result & RESIZED) != 0 && layout != null) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java index ecf93e6018..84b91cc594 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java @@ -130,7 +130,7 @@ void drawBackground (Control control, long /*int*/ window, long /*int*/ cr, long Cairo.cairo_clip(cairo); } if (control.backgroundImage != null) { - Point pt = display.map (this, control, 0, 0); + Point pt = display.mapInPixels (this, control, 0, 0); Cairo.cairo_translate (cairo, -pt.x, -pt.y); x += pt.x; y += pt.y; @@ -155,7 +155,7 @@ void drawBackground (Control control, long /*int*/ window, long /*int*/ cr, long long /*int*/ gdkGC = OS.gdk_gc_new (window); if (region != 0) OS.gdk_gc_set_clip_region (gdkGC, region); if (control.backgroundImage != null) { - Point pt = display.map (this, control, 0, 0); + Point pt = display.mapInPixels (this, control, 0, 0); OS.gdk_gc_set_fill (gdkGC, OS.GDK_TILED); OS.gdk_gc_set_ts_origin (gdkGC, -pt.x, -pt.y); OS.gdk_gc_set_tile (gdkGC, control.backgroundImage.pixmap); @@ -560,7 +560,7 @@ void printWindow (boolean first, Control control, GC gc, long /*int*/ drawable, } /** - * Returns the preferred size of the receiver. + * Returns the preferred size(in Points) of the receiver. * <p> * The <em>preferred size</em> of a control is the size that it would * best be displayed at. The width hint and height hint arguments @@ -590,6 +590,38 @@ public Point computeSize (int wHint, int hHint) { return computeSize (wHint, hHint, true); } +/** + * Returns the preferred size(in pixels) of the receiver. + * <p> + * The <em>preferred size</em> of a control is the size that it would + * best be displayed at. The width hint and height hint arguments + * allow the caller to ask a control questions such as "Given a particular + * width, how high does the control need to be to show all of the contents?" + * To indicate that the caller does not wish to constrain a particular + * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint. + * </p> + * + * @param wHint the width hint (can be <code>SWT.DEFAULT</code>) + * @param hHint the height hint (can be <code>SWT.DEFAULT</code>) + * @return the preferred size of the control + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see Layout + * @see #getBorderWidth + * @see #getBounds + * @see #getSize + * @see #pack(boolean) + * @see "computeTrim, getClientArea for controls that implement them" + * @since 3.105 + */ +Point computeSizeInPixels (int wHint, int hHint) { + return computeSizeInPixels (wHint, hHint, true); +} + Widget computeTabGroup () { if (isTabGroup()) return this; return parent.computeTabGroup (); @@ -660,7 +692,7 @@ void checkForeground () { } void checkBorder () { - if (getBorderWidth () == 0) style &= ~SWT.BORDER; + if (getBorderWidthInPixels () == 0) style &= ~SWT.BORDER; } void checkMirrored () { @@ -689,7 +721,7 @@ void createWidget (int index) { } /** - * Returns the preferred size of the receiver. + * Returns the preferred size (in points) of the receiver. * <p> * The <em>preferred size</em> of a control is the size that it would * best be displayed at. The width hint and height hint arguments @@ -726,6 +758,50 @@ public Point computeSize (int wHint, int hHint, boolean changed) { checkWidget(); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; + wHint = DPIUtil.autoScaleUp(wHint); + hHint = DPIUtil.autoScaleUp(hHint); + return DPIUtil.autoScaleDown (computeSizeInPixels (wHint, hHint, changed)); +} + +/** + * Returns the preferred size (in pixels) of the receiver. + * <p> + * The <em>preferred size</em> of a control is the size that it would + * best be displayed at. The width hint and height hint arguments + * allow the caller to ask a control questions such as "Given a particular + * width, how high does the control need to be to show all of the contents?" + * To indicate that the caller does not wish to constrain a particular + * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint. + * </p><p> + * If the changed flag is <code>true</code>, it indicates that the receiver's + * <em>contents</em> have changed, therefore any caches that a layout manager + * containing the control may have been keeping need to be flushed. When the + * control is resized, the changed flag will be <code>false</code>, so layout + * manager caches can be retained. + * </p> + * + * @param wHint the width hint (can be <code>SWT.DEFAULT</code>) + * @param hHint the height hint (can be <code>SWT.DEFAULT</code>) + * @param changed <code>true</code> if the control's contents have changed, and <code>false</code> otherwise + * @return the preferred size of the control. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see Layout + * @see #getBorderWidth + * @see #getBounds + * @see #getSize + * @see #pack(boolean) + * @see "computeTrim, getClientArea for controls that implement them" + * @since 3.105 + */ +Point computeSizeInPixels (int wHint, int hHint, boolean changed) { + checkWidget(); + if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; + if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; return computeNativeSize (handle, wHint, hHint, changed); } @@ -814,7 +890,7 @@ Accessible _getAccessible () { } /** - * Returns a rectangle describing the receiver's size and location + * Returns a rectangle describing the receiver's size and location in points * relative to its parent (or its display if its parent is null), * unless the receiver is a shell. In this case, the location is * relative to the display. @@ -827,6 +903,24 @@ Accessible _getAccessible () { * </ul> */ public Rectangle getBounds () { + return DPIUtil.autoScaleDown(getBoundsInPixels()); +} + +/** + * Returns a rectangle describing the receiver's size and location in points + * relative to its parent (or its display if its parent is null), + * unless the receiver is a shell. In this case, the location is + * relative to the display. + * + * @return the receiver's bounding rectangle + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Rectangle getBoundsInPixels () { checkWidget(); long /*int*/ topHandle = topHandle (); GtkAllocation allocation = new GtkAllocation (); @@ -840,7 +934,7 @@ public Rectangle getBounds () { } /** - * Sets the receiver's size and location to the rectangular + * Sets the receiver's size and location in points to the rectangular * area specified by the argument. The <code>x</code> and * <code>y</code> fields of the rectangle are relative to * the receiver's parent (or its display if its parent is null). @@ -865,11 +959,42 @@ public Rectangle getBounds () { public void setBounds (Rectangle rect) { checkWidget (); if (rect == null) error (SWT.ERROR_NULL_ARGUMENT); + rect = DPIUtil.autoScaleUp(rect); + setBounds (rect.x, rect.y, Math.max (0, rect.width), Math.max (0, rect.height), true, true); +} + +/** + * Sets the receiver's size and location in pixels to the rectangular + * area specified by the argument. The <code>x</code> and + * <code>y</code> fields of the rectangle are relative to + * the receiver's parent (or its display if its parent is null). + * <p> + * Note: Attempting to set the width or height of the + * receiver to a negative number will cause that + * value to be set to zero instead. + * </p> + *<p> + * Note: Attempting to set the width or height of the + * receiver to a number higher or equal 2^14 will cause them to be + * set to (2^14)-1 instead. + * </p> + * + * @param rect the new bounds for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setBoundsInPixels (Rectangle rect) { + checkWidget (); + if (rect == null) error (SWT.ERROR_NULL_ARGUMENT); setBounds (rect.x, rect.y, Math.max (0, rect.width), Math.max (0, rect.height), true, true); } /** - * Sets the receiver's size and location to the rectangular + * Sets the receiver's size and location in points to the rectangular * area specified by the arguments. The <code>x</code> and * <code>y</code> arguments are relative to the receiver's * parent (or its display if its parent is null), unless @@ -898,6 +1023,41 @@ public void setBounds (Rectangle rect) { */ public void setBounds (int x, int y, int width, int height) { checkWidget(); + Rectangle rect = DPIUtil.autoScaleUp(new Rectangle (x, y, width, height)); + setBounds (rect.x, rect.y, Math.max (0, rect.width), Math.max (0, rect.height), true, true); +} + +/** + * Sets the receiver's size and location in pixels to the rectangular + * area specified by the arguments. The <code>x</code> and + * <code>y</code> arguments are relative to the receiver's + * parent (or its display if its parent is null), unless + * the receiver is a shell. In this case, the <code>x</code> + * and <code>y</code> arguments are relative to the display. + * <p> + * Note: Attempting to set the width or height of the + * receiver to a negative number will cause that + * value to be set to zero instead. + * </p> + *<p> + * Note: Attempting to set the width or height of the + * receiver to a number higher or equal 2^14 will cause them to be + * set to (2^14)-1 instead. + * </p> + * + * @param x the new x coordinate for the receiver + * @param y the new y coordinate for the receiver + * @param width the new width for the receiver + * @param height the new height for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setBoundsInPixels (int x, int y, int width, int height) { + checkWidget(); setBounds (x, y, Math.max (0, width), Math.max (0, height), true, true); } @@ -1074,7 +1234,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize /** * Returns a point describing the receiver's location relative - * to its parent (or its display if its parent is null), unless + * to its parent in points (or its display if its parent is null), unless * the receiver is a shell. In this case, the point is * relative to the display. * @@ -1086,6 +1246,24 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize * </ul> */ public Point getLocation () { + return DPIUtil.autoScaleDown(getLocationInPixels()); +} + +/** + * Returns a point describing the receiver's location relative + * to its parent in pixels (or its display if its parent is null), unless + * the receiver is a shell. In this case, the point is + * relative to the display. + * + * @return the receiver's location + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Point getLocationInPixels () { checkWidget(); long /*int*/ topHandle = topHandle (); GtkAllocation allocation = new GtkAllocation (); @@ -1116,6 +1294,7 @@ public Point getLocation () { public void setLocation (Point location) { checkWidget (); if (location == null) error (SWT.ERROR_NULL_ARGUMENT); + location = DPIUtil.autoScaleUp(location); setBounds (location.x, location.y, 0, 0, true, false); } @@ -1126,7 +1305,28 @@ public void setLocation (Point location) { * the receiver is a shell. In this case, the point is * relative to the display. * - * @param x the new x coordinate for the receiver + * @param location the new location for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setLocationInPixels (Point location) { + checkWidget (); + if (location == null) error (SWT.ERROR_NULL_ARGUMENT); + setBounds (location.x, location.y, 0, 0, true, false); +} + +/** + * Sets the receiver's location to the point specified by + * the arguments which are relative to the receiver's + * parent (or its display if its parent is null), unless + * the receiver is a shell. In this case, the point is + * relative to the display. + * + * @param x the new x coordinate in for the receiver * @param y the new y coordinate for the receiver * * @exception SWTException <ul> @@ -1136,11 +1336,33 @@ public void setLocation (Point location) { */ public void setLocation(int x, int y) { checkWidget(); + Point loc = DPIUtil.autoScaleUp(new Point (x, y)); + setBounds (loc.x, loc.y, 0, 0, true, false); +} + +/** + * Sets the receiver's location to the point specified by + * the arguments which are relative to the receiver's + * parent (or its display if its parent is null), unless + * the receiver is a shell. In this case, the point is + * relative to the display. + * + * @param x the new x coordinate in for the receiver + * @param y the new y coordinate for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setLocationInPixels(int x, int y) { + checkWidget(); setBounds (x, y, 0, 0, true, false); } /** - * Returns a point describing the receiver's size. The + * Returns a point describing the receiver's size in points. The * x coordinate of the result is the width of the receiver. * The y coordinate of the result is the height of the * receiver. @@ -1153,6 +1375,24 @@ public void setLocation(int x, int y) { * </ul> */ public Point getSize () { + return DPIUtil.autoScaleDown(getSizeInPixels()); +} + +/** + * Returns a point describing the receiver's size in pixels. The + * x coordinate of the result is the width of the receiver. + * The y coordinate of the result is the height of the + * receiver. + * + * @return the receiver's size + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Point getSizeInPixels () { checkWidget(); long /*int*/ topHandle = topHandle (); GtkAllocation allocation = new GtkAllocation (); @@ -1175,7 +1415,7 @@ public Point getSize () { * set to (2^14)-1 instead. * </p> * - * @param size the new size for the receiver + * @param size the new size in points for the receiver * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the point is null</li> @@ -1184,10 +1424,42 @@ public Point getSize () { * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> + * @since 3.105 */ public void setSize (Point size) { checkWidget (); if (size == null) error (SWT.ERROR_NULL_ARGUMENT); + size = DPIUtil.autoScaleUp(size); + setBounds (0, 0, Math.max (0, size.x), Math.max (0, size.y), false, true); +} + +/** + * Sets the receiver's size to the point specified by the argument. + * <p> + * Note: Attempting to set the width or height of the + * receiver to a negative number will cause them to be + * set to zero instead. + * </p> + *<p> + * Note: Attempting to set the width or height of the + * receiver to a number higher or equal 2^14 will cause them to be + * set to (2^14)-1 instead. + * </p> + * + * @param size the new size in pixels for the receiver + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the point is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setSizeInPixels (Point size) { + checkWidget (); + if (size == null) error (SWT.ERROR_NULL_ARGUMENT); setBounds (0, 0, Math.max (0, size.x), Math.max (0, size.y), false, true); } @@ -1254,8 +1526,8 @@ void setRelations () { * set to (2^14)-1 instead. * </p> * - * @param width the new width for the receiver - * @param height the new height for the receiver + * @param width the new width in points for the receiver + * @param height the new height in points for the receiver * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> @@ -1264,6 +1536,34 @@ void setRelations () { */ public void setSize (int width, int height) { checkWidget(); + Point size = DPIUtil.autoScaleUp(new Point (width, height)); + setBounds (0, 0, Math.max (0, size.x), Math.max (0, size.y), false, true); +} + +/** + * Sets the receiver's size to the point specified by the arguments. + * <p> + * Note: Attempting to set the width or height of the + * receiver to a negative number will cause that + * value to be set to zero instead. + * </p> + *<p> + * Note: Attempting to set the width or height of the + * receiver to a number higher or equal 2^14 will cause them to be + * set to (2^14)-1 instead. + * </p> + * + * @param width the new width in pixels for the receiver + * @param height the new height in pixels for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setSizeInPixels (int width, int height) { + checkWidget(); setBounds (0, 0, Math.max (0, width), Math.max (0, height), false, true); } @@ -1386,7 +1686,7 @@ public void pack () { * @see #computeSize(int, int, boolean) */ public void pack (boolean changed) { - setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed)); + setSizeInPixels (computeSizeInPixels (SWT.DEFAULT, SWT.DEFAULT, changed)); } /** @@ -1413,8 +1713,8 @@ public void setLayoutData (Object layoutData) { * {@link Display#map(Control, Control, Rectangle)}. * </p> * - * @param x the x coordinate to be translated - * @param y the y coordinate to be translated + * @param x the x coordinate in points to be translated + * @param y the y coordinate in points to be translated * @return the translated coordinates * * @exception SWTException <ul> @@ -1426,6 +1726,31 @@ public void setLayoutData (Object layoutData) { */ public Point toControl (int x, int y) { checkWidget (); + return toControl (new Point (x, y)); +} + +/** + * Returns a point which is the result of converting the + * argument, which is specified in display relative coordinates, + * to coordinates relative to the receiver. + * <p> + * NOTE: To properly map a rectangle or a corner of a rectangle on a right-to-left platform, use + * {@link Display#map(Control, Control, Rectangle)}. + * </p> + * + * @param x the x coordinate in pixels to be translated + * @param y the y coordinate in pixels to be translated + * @return the translated coordinates + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +Point toControlInPixels (int x, int y) { + checkWidget (); long /*int*/ window = eventWindow (); int [] origin_x = new int [1], origin_y = new int [1]; OS.gdk_window_get_origin (window, origin_x, origin_y); @@ -1458,7 +1783,35 @@ public Point toControl (int x, int y) { public Point toControl (Point point) { checkWidget (); if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - return toControl (point.x, point.y); + point = DPIUtil.autoScaleUp(point); + return DPIUtil.autoScaleDown(toControlInPixels (point.x, point.y)); +} + +/** + * Returns a point which is the result of converting the + * argument, which is specified in display relative coordinates, + * to coordinates relative to the receiver. + * <p> + * NOTE: To properly map a rectangle or a corner of a rectangle on a right-to-left platform, use + * {@link Display#map(Control, Control, Rectangle)}. + * </p> + * + * @param point the point to be translated (must not be null) + * @return the translated coordinates + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the point is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Point toControlInPixels (Point point) { + checkWidget (); + if (point == null) error (SWT.ERROR_NULL_ARGUMENT); + return toControlInPixels (point.x, point.y); } /** @@ -1483,6 +1836,31 @@ public Point toControl (Point point) { */ public Point toDisplay (int x, int y) { checkWidget(); + return toDisplay (new Point (x, y)); +} + +/** + * Returns a point which is the result of converting the + * argument, which is specified in coordinates relative to + * the receiver, to display relative coordinates. + * <p> + * NOTE: To properly map a rectangle or a corner of a rectangle on a right-to-left platform, use + * {@link Display#map(Control, Control, Rectangle)}. + * </p> + * + * @param x the x coordinate to be translated + * @param y the y coordinate to be translated + * @return the translated coordinates + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +Point toDisplayInPixels (int x, int y) { + checkWidget(); long /*int*/ window = eventWindow (); int [] origin_x = new int [1], origin_y = new int [1]; OS.gdk_window_get_origin (window, origin_x, origin_y); @@ -1515,10 +1893,37 @@ public Point toDisplay (int x, int y) { public Point toDisplay (Point point) { checkWidget(); if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - return toDisplay (point.x, point.y); + point = DPIUtil.autoScaleUp(point); + return DPIUtil.autoScaleDown(toDisplayInPixels (point.x, point.y)); } /** + * Returns a point which is the result of converting the + * argument, which is specified in coordinates relative to + * the receiver, to display relative coordinates. + * <p> + * NOTE: To properly map a rectangle or a corner of a rectangle on a right-to-left platform, use + * {@link Display#map(Control, Control, Rectangle)}. + * </p> + * + * @param point the point to be translated (must not be null) + * @return the translated coordinates + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the point is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Point toDisplayInPixels (Point point) { + checkWidget(); + if (point == null) error (SWT.ERROR_NULL_ARGUMENT); + return toDisplayInPixels (point.x, point.y); +} +/** * Adds the listener to the collection of listeners who will * be notified when the control is moved or resized, by sending * it one of the messages defined in the <code>ControlListener</code> @@ -2394,7 +2799,7 @@ boolean dragDetect (int x, int y, boolean filter, boolean dragOnTimeout, boolean Point startPos = null; Point currPos = null; if (OS.GTK3) { - startPos = display.getCursorLocation(); + startPos = display.getCursorLocationInPixels(); } while (!quit) { @@ -2412,7 +2817,7 @@ boolean dragDetect (int x, int y, boolean filter, boolean dragOnTimeout, boolean break; } else { if (OS.GTK3) { //428852 - currPos = display.getCursorLocation(); + currPos = display.getCursorLocationInPixels(); dragging = OS.gtk_drag_check_threshold (handle, startPos.x, startPos.y, currPos.x, currPos.y); if (dragging) break; @@ -2674,7 +3079,7 @@ GdkColor getBaseColor () { } /** - * Returns the receiver's border width. + * Returns the receiver's border width in points. * * @return the border width * @@ -2684,6 +3089,21 @@ GdkColor getBaseColor () { * </ul> */ public int getBorderWidth () { + return DPIUtil.autoScaleDown(getBorderWidthInPixels()); +} + +/** + * Returns the receiver's border width in pixels. + * + * @return the border width + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +int getBorderWidthInPixels () { checkWidget(); return 0; } @@ -3249,18 +3669,16 @@ long /*int*/ gtk_draw (long /*int*/ widget, long /*int*/ cairo) { OS.gdk_cairo_get_clip_rectangle (cairo, rect); Event event = new Event (); event.count = 1; - event.x = rect.x; - event.y = rect.y; - event.width = rect.width; - event.height = rect.height; - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x; + Rectangle eventRect = new Rectangle (rect.x, rect.y, rect.width, rect.height); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); + if ((style & SWT.MIRRORED) != 0) event.x = DPIUtil.autoScaleDown (getClientWidth ()) - event.width - event.x; GCData data = new GCData (); // data.damageRgn = gdkEvent.region; if (OS.GTK_VERSION <= OS.VERSION (3, 9, 0)) { data.cairo = cairo; } GC gc = event.gc = GC.gtk_new (this, data); - gc.setClipping (rect.x, rect.y, rect.width, rect.height); + gc.setClipping (DPIUtil.autoScaleDown(new Rectangle(rect.x, rect.y, rect.width, rect.height))); drawWidget (gc); sendEvent (SWT.Paint, event); gc.dispose (); @@ -3276,11 +3694,9 @@ long /*int*/ gtk_expose_event (long /*int*/ widget, long /*int*/ eventPtr) { OS.memmove(gdkEvent, eventPtr, GdkEventExpose.sizeof); Event event = new Event (); event.count = gdkEvent.count; - event.x = gdkEvent.area_x; - event.y = gdkEvent.area_y; - event.width = gdkEvent.area_width; - event.height = gdkEvent.area_height; - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x; + Rectangle eventRect = new Rectangle (gdkEvent.area_x, gdkEvent.area_y, gdkEvent.area_width, gdkEvent.area_height); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); + if ((style & SWT.MIRRORED) != 0) event.x = DPIUtil.autoScaleDown (getClientWidth ()) - event.width - event.x; GCData data = new GCData (); data.damageRgn = gdkEvent.region; GC gc = event.gc = GC.gtk_new (this, data); @@ -3627,7 +4043,7 @@ boolean isShowing () { if (!isVisible ()) return false; Control control = this; while (control != null) { - Point size = control.getSize (); + Point size = control.getSizeInPixels (); if (size.x == 0 || size.y == 0) { return false; } @@ -3824,6 +4240,42 @@ void redraw (boolean all) { * @see SWT#DOUBLE_BUFFERED */ public void redraw (int x, int y, int width, int height, boolean all) { + Rectangle rect = DPIUtil.autoScaleUp(new Rectangle(x, y, width, height)); + redrawInPixels(rect.x, rect.y, rect.width, rect.height, all); +} + +/** + * Causes the rectangular area of the receiver specified by + * the arguments to be marked as needing to be redrawn. + * The next time a paint request is processed, that area of + * the receiver will be painted, including the background. + * If the <code>all</code> flag is <code>true</code>, any + * children of the receiver which intersect with the specified + * area will also paint their intersecting areas. If the + * <code>all</code> flag is <code>false</code>, the children + * will not be painted. + * + * @param x the x coordinate of the area to draw + * @param y the y coordinate of the area to draw + * @param width the width of the area to draw + * @param height the height of the area to draw + * @param all <code>true</code> if children should redraw, and <code>false</code> otherwise + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #update() + * @see PaintListener + * @see SWT#Paint + * @see SWT#NO_BACKGROUND + * @see SWT#NO_REDRAW_RESIZE + * @see SWT#NO_MERGE_PAINTS + * @see SWT#DOUBLE_BUFFERED + * @since 3.105 + */ +void redrawInPixels (int x, int y, int width, int height, boolean all) { checkWidget(); if (!OS.gtk_widget_get_visible (topHandle ())) return; if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - width - x; @@ -3925,9 +4377,9 @@ void restackWindow (long /*int*/ window, long /*int*/ sibling, boolean above) { boolean sendDragEvent (int button, int stateMask, int x, int y, boolean isStateMask) { Event event = new Event (); event.button = button; - event.x = x; - event.y = y; - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.x; + Rectangle eventRect = new Rectangle (x, y, 0, 0); + event.setBounds (eventRect); + if ((style & SWT.MIRRORED) != 0) event.x = DPIUtil.autoScaleDown(getClientWidth ()) - event.x; if (isStateMask) { event.stateMask = stateMask; } else { @@ -3994,16 +4446,16 @@ boolean sendMouseEvent (int type, int button, int count, int detail, boolean sen event.detail = detail; event.count = count; if (is_hint) { - event.x = (int)x; - event.y = (int)y; + Rectangle eventRect = new Rectangle ((int)x, (int)y, 0, 0); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); } else { long /*int*/ window = eventWindow (); int [] origin_x = new int [1], origin_y = new int [1]; OS.gdk_window_get_origin (window, origin_x, origin_y); - event.x = (int)x - origin_x [0]; - event.y = (int)y - origin_y [0]; + Rectangle eventRect = new Rectangle ((int)x - origin_x [0], (int)y - origin_y [0], 0, 0); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); } - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.x; + if ((style & SWT.MIRRORED) != 0) event.x = DPIUtil.autoScaleDown (getClientWidth ()) - event.x; setInputState (event, state); if (send) { sendEvent (type, event); @@ -4891,7 +5343,7 @@ public void setRedraw (boolean redraw) { if (drawCount++ == 0) { if (gtk_widget_get_realized (handle)) { long /*int*/ window = paintWindow (); - Rectangle rect = getBounds (); + Rectangle rect = getBoundsInPixels (); GdkWindowAttr attributes = new GdkWindowAttr (); attributes.width = rect.width; attributes.height = rect.height; @@ -5214,8 +5666,8 @@ boolean showMenu (int x, int y) { boolean showMenu (int x, int y, int detail) { Event event = new Event (); - event.x = x; - event.y = y; + Rectangle eventRect = new Rectangle (x, y, 0, 0); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); event.detail = detail; sendEvent (SWT.MenuDetect, event); //widget could be disposed at this point @@ -5224,8 +5676,9 @@ boolean showMenu (int x, int y, int detail) { if (menu != null && !menu.isDisposed ()) { boolean hooksKeys = hooks (SWT.KeyDown) || hooks (SWT.KeyUp); menu.createIMMenu (hooksKeys ? imHandle() : 0); - if (event.x != x || event.y != y) { - menu.setLocation (event.x, event.y); + Rectangle rect = DPIUtil.autoScaleUp (event.getBounds ()); + if (rect.x != x || rect.y != y) { + menu.setLocationInPixels (rect.x, rect.y); } menu.setVisible (true); return true; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java index 41481a4c65..a5122ecff0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java @@ -159,8 +159,8 @@ public DateTime (Composite parent, int style) { if (isDateWithDropDownButton ()) { //Date w/ drop down button is in containers. //first time round we set the bounds manually for correct Right_to_left behaviour - Point size = computeSize (SWT.DEFAULT, SWT.DEFAULT); - setBounds (0, 0, size.x, size.y); + Point size = computeSizeInPixels (SWT.DEFAULT, SWT.DEFAULT); + setBoundsInPixels (0, 0, size.x, size.y); } } @@ -235,8 +235,7 @@ protected void checkSubclass () { if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); int width = 0, height = 0; @@ -254,9 +253,9 @@ public Point computeSize (int wHint, int hHint, boolean changed) { height = size.y; } else { Point textSize = computeNativeSize (textEntryHandle, wHint, hHint, changed); - Rectangle trim = computeTrim (0,0, textSize.x,textSize.y); + Rectangle trim = computeTrimInPixels (0,0, textSize.x,textSize.y); if (isDateWithDropDownButton ()){ - Point buttonSize = down.computeSize (SWT.DEFAULT, SWT.DEFAULT, changed); + Point buttonSize = down.computeSizeInPixels (SWT.DEFAULT, SWT.DEFAULT, changed); width = trim.width + buttonSize.x; height = Math.max (trim.height, buttonSize.y); } else if (isDate () || isTime ()) { @@ -275,7 +274,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { if (height == 0) height = DEFAULT_HEIGHT; if (wHint != SWT.DEFAULT) width = wHint; if (hHint != SWT.DEFAULT) height = hHint; - int borderWidth = getBorderWidth (); + int borderWidth = getBorderWidthInPixels (); if (prefferedSize == null && (isDateWithDropDownButton () && OS.GTK3)) { prefferedSize = new Point (width + 2*borderWidth, height+ 2*borderWidth); @@ -285,14 +284,13 @@ public Point computeSize (int wHint, int hHint, boolean changed) { } } -@Override -public Rectangle computeTrim (int x, int y, int width, int height) { +@Override Rectangle computeTrimInPixels (int x, int y, int width, int height) { if (isCalendar ()) { - return super.computeTrim (x, y, width, height); + return super.computeTrimInPixels (x, y, width, height); } checkWidget (); - Rectangle trim = super.computeTrim (x, y, width, height); + Rectangle trim = super.computeTrimInPixels (x, y, width, height); int xborder = 0, yborder = 0; if (OS.GTK3) { GtkBorder tmp = new GtkBorder (); @@ -552,11 +550,11 @@ void dropDownCalendar (boolean drop) { } //This is the x/y/width/height of the container of DateTime - Point containerBounds = getSize (); - Point calendarSize = popupCalendar.computeSize (SWT.DEFAULT, SWT.DEFAULT, false); + Point containerBounds = getSizeInPixels (); + Point calendarSize = popupCalendar.computeSizeInPixels (SWT.DEFAULT, SWT.DEFAULT, false); //Set the inner calendar pos/size. (not the popup shell pos/size) - popupCalendar.setBounds (1, 1, Math.max (containerBounds.x - 2, calendarSize.x), calendarSize.y); + popupCalendar.setBoundsInPixels (1, 1, Math.max (containerBounds.x - 2, calendarSize.x), calendarSize.y); //Set Date & focus current day popupCalendar.setDate (savedYear, savedMonth, savedDay); @@ -565,7 +563,7 @@ void dropDownCalendar (boolean drop) { Display display = getDisplay (); //To display popup calendar, we need to know where the parent is relative to the whole screen. - Rectangle coordsRelativeToScreen = display.map (getParent (), null, getBounds ()); + Rectangle coordsRelativeToScreen = display.mapInPixels (getParent (), null, getBoundsInPixels ()); Rectangle displayRect = getMonitor ().getClientArea (); showPopupShell (containerBounds, calendarSize, coordsRelativeToScreen, displayRect); @@ -580,7 +578,7 @@ private void showPopupShell (Point containerBounds, Point calendarSize, Rectangl int y = calculateCalendarYpos (containerBounds, coordsRelativeToScreen, height, displayRect); int x = calculateCalendarXpos (calendarSize, coordsRelativeToScreen, displayRect, width); - popupShell.setBounds (x, y, width, height); + popupShell.setBoundsInPixels (x, y, width, height); popupShell.setVisible (true); if (isFocusControl ()) { popupCalendar.setFocus (); @@ -1064,7 +1062,7 @@ void initAccessible () { @Override public void getLocation (AccessibleControlEvent e) { - Rectangle rect = display.map (getParent (), null, getBounds ()); + Rectangle rect = display.mapInPixels (getParent (), null, getBoundsInPixels ()); e.x = rect.x; e.y = rect.y; e.width = rect.width; @@ -1683,8 +1681,7 @@ public void setYear (int year) { } } -@Override -public void setBounds (int x, int y, int width, int height) { +@Override void setBoundsInPixels (int x, int y, int width, int height) { //Date with Drop down is in container. Needs extra handling. if (isDateWithDropDownButton () && OS.GTK3) { @@ -1692,7 +1689,7 @@ public void setBounds (int x, int y, int width, int height) { OS.gtk_widget_get_preferred_size (textEntryHandle, null, requisition); int oldHeight = requisition.height; //Entry should not expand vertically. It is single liner. - int newWidth = width - (down.getSize ().x + getGtkBorderPadding ().right); + int newWidth = width - (down.getSizeInPixels ().x + getGtkBorderPadding ().right); OS.gtk_widget_set_size_request (textEntryHandle, (newWidth >= 0) ? newWidth : 0, oldHeight); } @@ -1711,12 +1708,12 @@ public void setBounds (int x, int y, int width, int height) { */ int fixedGtkVersion = OS.VERSION (3, 14, 2); if (isCalendar () && OS.GTK3 && (OS.GTK_VERSION < fixedGtkVersion)) { - int calendarPrefferedVerticalSize = computeSize (SWT.DEFAULT, SWT.DEFAULT, true).y; + int calendarPrefferedVerticalSize = computeSizeInPixels (SWT.DEFAULT, SWT.DEFAULT, true).y; if (height > calendarPrefferedVerticalSize) { height = calendarPrefferedVerticalSize; } } - super.setBounds (x, y, width, height); + super.setBoundsInPixels (x, y, width, height); } @@ -1724,10 +1721,10 @@ public void setBounds (int x, int y, int width, int height) { * Usually called when control is resized or first initialized. */ private void setDropDownButtonSize () { - Rectangle rect = getClientArea (); + Rectangle rect = getClientAreaInPixels (); int parentWidth = rect.width; int parentHeight = rect.height; - Point buttonSize = down.computeSize (SWT.DEFAULT, parentHeight); + Point buttonSize = down.computeSizeInPixels (SWT.DEFAULT, parentHeight); //TAG_GTK3__NO_VERTICAL_FILL_ADJUSTMENT int dateEntryHeight = computeNativeSize (textEntryHandle, SWT.DEFAULT, SWT.DEFAULT, false).y; @@ -1737,7 +1734,7 @@ private void setDropDownButtonSize () { int newXpos = parentWidth - buttonSize.x; int newYPos = parentHeight/2 - dateEntryHeight/2; - down.setBounds (newXpos, newYPos, buttonSize.x, newHeight); + down.setBoundsInPixels (newXpos, newYPos, buttonSize.x, newHeight); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index 31652947ad..e97f0cc482 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -1414,7 +1414,7 @@ public Shell getActiveShell () { * </ul> */ @Override -public Rectangle getBounds () { +protected Rectangle getBoundsInPixels () { checkDevice (); return new Rectangle (0, 0, OS.gdk_screen_width (), OS.gdk_screen_height ()); } @@ -1579,6 +1579,22 @@ long /*int*/ filterProc (long /*int*/ xEvent, long /*int*/ gdkEvent, long /*int* * </ul> */ public Point getCursorLocation () { + return DPIUtil.autoScaleDown(getCursorLocationInPixels()); +} + +/** + * Returns the location of the on-screen pointer relative + * to the top left corner of the screen. + * + * @return the cursor location + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * @since 3.105 + */ +Point getCursorLocationInPixels () { checkDevice (); int [] x = new int [1], y = new int [1]; gdk_window_get_device_position (0, x, y, null); @@ -1989,7 +2005,7 @@ public Monitor [] getMonitors () { if (monitors == null) { /* No multimonitor support detected, default to one monitor */ Monitor monitor = new Monitor (); - Rectangle bounds = getBounds (); + Rectangle bounds = getBoundsInPixels (); monitor.x = bounds.x; monitor.y = bounds.y; monitor.width = bounds.width; @@ -3029,9 +3045,49 @@ boolean isValidThread () { * @since 2.1.2 */ public Point map (Control from, Control to, Point point) { + return DPIUtil.autoScaleDown(mapInPixels(from, to, DPIUtil.autoScaleUp(point))); +} + +/** + * Maps a point from one coordinate system to another. + * When the control is null, coordinates are mapped to + * the display. + * <p> + * NOTE: On right-to-left platforms where the coordinate + * systems are mirrored, special care needs to be taken + * when mapping coordinates from one control to another + * to ensure the result is correctly mirrored. + * + * Mapping a point that is the origin of a rectangle and + * then adding the width and height is not equivalent to + * mapping the rectangle. When one control is mirrored + * and the other is not, adding the width and height to a + * point that was mapped causes the rectangle to extend + * in the wrong direction. Mapping the entire rectangle + * instead of just one point causes both the origin and + * the corner of the rectangle to be mapped. + * </p> + * + * @param from the source <code>Control</code> or <code>null</code> + * @param to the destination <code>Control</code> or <code>null</code> + * @param point to be mapped + * @return point with mapped coordinates + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the point is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +Point mapInPixels (Control from, Control to, Point point) { checkDevice (); if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - return map (from, to, point.x, point.y); + return mapInPixels (from, to, point.x, point.y); } /** @@ -3071,6 +3127,46 @@ public Point map (Control from, Control to, Point point) { * @since 2.1.2 */ public Point map (Control from, Control to, int x, int y) { + return map(from, to, new Point(x, y)); +} + +/** + * Maps a point from one coordinate system to another. + * When the control is null, coordinates are mapped to + * the display. + * <p> + * NOTE: On right-to-left platforms where the coordinate + * systems are mirrored, special care needs to be taken + * when mapping coordinates from one control to another + * to ensure the result is correctly mirrored. + * + * Mapping a point that is the origin of a rectangle and + * then adding the width and height is not equivalent to + * mapping the rectangle. When one control is mirrored + * and the other is not, adding the width and height to a + * point that was mapped causes the rectangle to extend + * in the wrong direction. Mapping the entire rectangle + * instead of just one point causes both the origin and + * the corner of the rectangle to be mapped. + * </p> + * + * @param from the source <code>Control</code> or <code>null</code> + * @param to the destination <code>Control</code> or <code>null</code> + * @param x coordinates to be mapped + * @param y coordinates to be mapped + * @return point with mapped coordinates + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +Point mapInPixels (Control from, Control to, int x, int y) { checkDevice (); if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); @@ -3128,9 +3224,49 @@ public Point map (Control from, Control to, int x, int y) { * @since 2.1.2 */ public Rectangle map (Control from, Control to, Rectangle rectangle) { + return DPIUtil.autoScaleDown(mapInPixels(from, to, DPIUtil.autoScaleUp(rectangle))); +} + +/** + * Maps a point from one coordinate system to another. + * When the control is null, coordinates are mapped to + * the display. + * <p> + * NOTE: On right-to-left platforms where the coordinate + * systems are mirrored, special care needs to be taken + * when mapping coordinates from one control to another + * to ensure the result is correctly mirrored. + * + * Mapping a point that is the origin of a rectangle and + * then adding the width and height is not equivalent to + * mapping the rectangle. When one control is mirrored + * and the other is not, adding the width and height to a + * point that was mapped causes the rectangle to extend + * in the wrong direction. Mapping the entire rectangle + * instead of just one point causes both the origin and + * the corner of the rectangle to be mapped. + * </p> + * + * @param from the source <code>Control</code> or <code>null</code> + * @param to the destination <code>Control</code> or <code>null</code> + * @param rectangle to be mapped + * @return rectangle with mapped coordinates + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +Rectangle mapInPixels (Control from, Control to, Rectangle rectangle) { checkDevice(); if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT); - return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height); + return mapInPixels (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height); } static char mbcsToWcs (char ch) { @@ -3195,6 +3331,48 @@ long /*int*/ menuPositionProc (long /*int*/ menu, long /*int*/ x, long /*int*/ y * @since 2.1.2 */ public Rectangle map (Control from, Control to, int x, int y, int width, int height) { + return map(from, to, new Rectangle(x, y, width, height)); +} + +/** + * Maps a point from one coordinate system to another. + * When the control is null, coordinates are mapped to + * the display. + * <p> + * NOTE: On right-to-left platforms where the coordinate + * systems are mirrored, special care needs to be taken + * when mapping coordinates from one control to another + * to ensure the result is correctly mirrored. + * + * Mapping a point that is the origin of a rectangle and + * then adding the width and height is not equivalent to + * mapping the rectangle. When one control is mirrored + * and the other is not, adding the width and height to a + * point that was mapped causes the rectangle to extend + * in the wrong direction. Mapping the entire rectangle + * instead of just one point causes both the origin and + * the corner of the rectangle to be mapped. + * </p> + * + * @param from the source <code>Control</code> or <code>null</code> + * @param to the destination <code>Control</code> or <code>null</code> + * @param x coordinates to be mapped + * @param y coordinates to be mapped + * @param width coordinates to be mapped + * @param height coordinates to be mapped + * @return rectangle with mapped coordinates + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> + * </ul> + * + * @since 3.105 + */ +Rectangle mapInPixels (Control from, Control to, int x, int y, int width, int height) { checkDevice(); if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); @@ -3330,7 +3508,8 @@ public boolean post (Event event) { case SWT.MouseMove: case SWT.MouseUp: { if (type == SWT.MouseMove) { - OS.XTestFakeMotionEvent (xDisplay, -1, event.x, event.y, 0); + Rectangle loc = DPIUtil.autoScaleUp(event.getBounds ()); + OS.XTestFakeMotionEvent (xDisplay, -1, loc.x, loc.y, 0); } else { int button = event.button; switch (button) { @@ -4255,7 +4434,7 @@ void showIMWindow (Control control) { widget.setFontDescription (preeditLabel, control.getFontDescription ()); if (pangoAttrs [0] != 0) OS.gtk_label_set_attributes (preeditLabel, pangoAttrs[0]); OS.gtk_label_set_text (preeditLabel, preeditString [0]); - Point point = control.toDisplay (control.getIMCaretPos ()); + Point point = control.toDisplayInPixels (control.getIMCaretPos ()); OS.gtk_window_move (preeditWindow, point.x, point.y); GtkRequisition requisition = new GtkRequisition (); if (OS.GTK3) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java index 1d11275f1b..d359567512 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,6 +13,7 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; /** @@ -114,8 +115,7 @@ protected void checkSubclass () { if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; Point size = computeNativeSize (handle, wHint, hHint, changed); @@ -168,7 +168,7 @@ void createItem (ExpandItem item, int style, int index) { System.arraycopy (items, index, items, index + 1, itemCount - index); items [index] = item; itemCount++; - item.width = Math.max (0, getClientArea ().width - spacing * 2); + item.width = Math.max (0, getClientAreaInPixels ().width - spacing * 2); layoutItems (index, true); } @@ -302,6 +302,22 @@ public ExpandItem [] getItems () { */ public int getSpacing () { checkWidget (); + return DPIUtil.autoScaleDown(spacing); +} + +/** + * Returns the receiver's spacing. + * + * @return the spacing + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +int getSpacingInPixels () { + checkWidget (); return spacing; } @@ -466,7 +482,7 @@ void setOrientation (boolean create) { void setScrollbar () { if (itemCount == 0) return; if ((style & SWT.V_SCROLL) == 0) return; - int height = getClientArea ().height; + int height = getClientAreaInPixels ().height; ExpandItem item = items [itemCount - 1]; int maxHeight = item.y + getBandHeight () + spacing; if (item.expanded) maxHeight += item.height; @@ -517,6 +533,21 @@ void setScrollbar () { * </ul> */ public void setSpacing (int spacing) { + setSpacingInPixels(DPIUtil.autoScaleUp(spacing)); +} +/** + * Sets the receiver's spacing. Spacing specifies the number of pixels allocated around + * each item. + * + * @param spacing the spacing around each item + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setSpacingInPixels (int spacing) { checkWidget (); if (spacing < 0) return; if (spacing == this.spacing) return; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java index e67abedd6e..1d44ba7410 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -200,8 +200,8 @@ void drawChevron (GC gc, int x, int y) { px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+6,py}; } gc.setForeground (display.getSystemColor (SWT.COLOR_TITLE_FOREGROUND)); - gc.drawPolyline (polyline1); - gc.drawPolyline (polyline2); + gc.drawPolyline (DPIUtil.autoScaleDown(polyline1)); + gc.drawPolyline (DPIUtil.autoScaleDown(polyline2)); } void drawItem (GC gc, boolean drawFocus) { @@ -282,12 +282,25 @@ public boolean getExpanded () { * </ul> */ public int getHeaderHeight () { + return DPIUtil.autoScaleDown (getHeaderHeightInPixels ()); +} +/** + * Returns the height of the receiver's header + * + * @return the height of the header + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +int getHeaderHeightInPixels () { checkWidget (); GtkAllocation allocation = new GtkAllocation (); OS.gtk_widget_get_allocation (handle, allocation); return allocation.height - (expanded ? height : 0); } - /** * Gets the height of the receiver. * @@ -299,6 +312,20 @@ public int getHeaderHeight () { * </ul> */ public int getHeight () { + return DPIUtil.autoScaleDown(getHeightInPixels()); +} +/** + * Gets the height of the receiver. + * + * @return the height + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +int getHeightInPixels () { checkWidget (); return height; } @@ -472,8 +499,8 @@ void setBounds (int x, int y, int width, int height, boolean move, boolean size) redraw (); } if (control != null && !control.isDisposed ()) { - if (move) control.setLocation (x + BORDER, y + headerHeight); - if (size) control.setSize (Math.max (0, width - 2 * BORDER), Math.max (0, height - BORDER)); + if (move) control.setLocationInPixels (x + BORDER, y + headerHeight); + if (size) control.setSizeInPixels (Math.max (0, width - 2 * BORDER), Math.max (0, height - BORDER)); } } @@ -573,6 +600,22 @@ void setForegroundColor (GdkColor color) { * </ul> */ public void setHeight (int height) { + setHeightInPixels(DPIUtil.autoScaleUp(height)); +} + +/** + * Sets the height of the receiver. This is height of the item when it is expanded, + * excluding the height of the header. + * + * @param height the new height + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setHeightInPixels (int height) { checkWidget (); if (height < 0) return; this.height = height; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java index 9eb61201cd..a1e4171118 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -102,15 +102,13 @@ long /*int*/ clientHandle () { return clientHandle; } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { - Point size = super.computeSize(wHint, hHint, changed); +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { + Point size = super.computeSizeInPixels(wHint, hHint, changed); int width = computeNativeSize (handle, SWT.DEFAULT, SWT.DEFAULT, false).x; size.x = Math.max (size.x, width); return size; } -@Override -public Rectangle computeTrim (int x, int y, int width, int height) { +@Override Rectangle computeTrimInPixels (int x, int y, int width, int height) { checkWidget(); forceResize (); GtkAllocation allocation = new GtkAllocation(); @@ -124,9 +122,8 @@ public Rectangle computeTrim (int x, int y, int width, int height) { return new Rectangle (x, y, width, height); } -@Override -public Rectangle getClientArea () { - Rectangle clientRectangle = super.getClientArea (); +@Override Rectangle getClientAreaInPixels () { + Rectangle clientRectangle = super.getClientAreaInPixels (); /* * Bug 453827 Child position fix. * SWT's calls to gtk_widget_size_allocate and gtk_widget_set_allocation diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java index e9dbbe8269..c0e214fa73 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -113,8 +113,7 @@ void addRelation (Control control) { control.labelRelation = this; } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; @@ -296,8 +295,7 @@ public int getAlignment () { return SWT.LEFT; } -@Override -public int getBorderWidth () { +@Override int getBorderWidthInPixels () { checkWidget(); if (frameHandle != 0) { return getThickness (frameHandle).x; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java index d558dea7f6..7fb4adcef1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,6 +14,7 @@ import org.eclipse.swt.*; import org.eclipse.swt.accessibility.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; /** @@ -113,8 +114,7 @@ public void addSelectionListener (SelectionListener listener) { addListener (SWT.DefaultSelection, typedListener); } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; @@ -123,19 +123,19 @@ public Point computeSize (int wHint, int hHint, boolean changed) { //TEMPORARY CODE if (wHint == 0) { layout.setWidth (1); - Rectangle rect = layout.getBounds (); + Rectangle rect = DPIUtil.autoScaleUp(layout.getBounds ()); width = 0; height = rect.height; } else { layout.setWidth (wHint); - Rectangle rect = layout.getBounds (); + Rectangle rect = DPIUtil.autoScaleUp(layout.getBounds ()); width = rect.width; height = rect.height; } layout.setWidth (layoutWidth); if (wHint != SWT.DEFAULT) width = wHint; if (hHint != SWT.DEFAULT) height = hHint; - int border = getBorderWidth (); + int border = getBorderWidthInPixels (); width += border * 2; height += border * 2; return new Point (width, height); @@ -222,7 +222,7 @@ void initAccessible () { @Override public void getLocation (AccessibleControlEvent e) { - Rectangle rect = display.map (getParent (), null, getBounds ()); + Rectangle rect = display.mapInPixels (getParent (), null, getBoundsInPixels ()); e.x = rect.x; e.y = rect.y; e.width = rect.width; @@ -323,7 +323,7 @@ long /*int*/ gtk_button_press_event (long /*int*/ widget, long /*int*/ event) { int x = (int) gdkEvent.x; int y = (int) gdkEvent.y; if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x; - int offset = layout.getOffset (x, y, null); + int offset = DPIUtil.autoScaleUp(layout.getOffset (x, y, null)); int oldSelectionX = selection.x; int oldSelectionY = selection.y; selection.x = offset; @@ -335,7 +335,7 @@ long /*int*/ gtk_button_press_event (long /*int*/ widget, long /*int*/ event) { oldSelectionY = temp; } Rectangle rect = layout.getBounds (oldSelectionX, oldSelectionY); - redraw (rect.x, rect.y, rect.width, rect.height, false); + redrawInPixels (rect.x, rect.y, rect.width, rect.height, false); } for (int j = 0; j < offsets.length; j++) { Rectangle [] rects = getRectangles (j); @@ -447,7 +447,7 @@ long /*int*/ gtk_motion_notify_event (long /*int*/ widget, long /*int*/ event) { if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x; if ((gdkEvent.state & OS.GDK_BUTTON1_MASK) != 0) { int oldSelection = selection.y; - selection.y = layout.getOffset (x, y, null); + selection.y = DPIUtil.autoScaleUp(layout.getOffset (x, y, null)); if (selection.y != oldSelection) { int newSelection = selection.y; if (oldSelection > newSelection) { @@ -456,7 +456,7 @@ long /*int*/ gtk_motion_notify_event (long /*int*/ widget, long /*int*/ event) { newSelection = temp; } Rectangle rect = layout.getBounds (oldSelection, newSelection); - redraw (rect.x, rect.y, rect.width, rect.height, false); + redrawInPixels (rect.x, rect.y, rect.width, rect.height, false); } } else { for (int j = 0; j < offsets.length; j++) { @@ -705,7 +705,7 @@ int parseMnemonics (char[] buffer, int start, int end, StringBuffer result) { int setBounds(int x, int y, int width, int height, boolean move, boolean resize) { int result = super.setBounds (x, y, width,height, move, resize); if ((result & RESIZED) != 0) { - layout.setWidth (width > 0 ? width : -1); + layout.setWidth (DPIUtil.autoScaleDown((width > 0 ? width : -1))); redraw (); } return result; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java index 53bb002f1a..fd7d7f6b0b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -250,8 +250,7 @@ int applyThemeBackground () { return -1; /* No Change */ } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; @@ -264,7 +263,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { * based on the number of items in the table */ if (OS.GTK3 && size.y == 0 && hHint == SWT.DEFAULT) { - size.y = getItemCount() * getItemHeight(); + size.y = getItemCount() * getItemHeightInPixels(); } /* @@ -273,7 +272,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { * so need to assign default height */ if (size.y == 0 && hHint == SWT.DEFAULT) size.y = DEFAULT_HEIGHT; - Rectangle trim = computeTrim (0, 0, size.x, size.y); + Rectangle trim = computeTrimInPixels (0, 0, size.x, size.y); size.x = trim.width; size.y = trim.height; return size; @@ -511,6 +510,23 @@ public int getItemCount () { */ public int getItemHeight () { checkWidget(); + return DPIUtil.autoScaleDown(getItemHeightInPixels()); +} + +/** + * Returns the height of the area which would be used to + * display <em>one</em> of the items in the list. + * + * @return the height of one item + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +int getItemHeightInPixels () { + checkWidget(); int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, 0); long /*int*/ column = OS.gtk_tree_view_get_column (handle, 0); if (itemCount == 0) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java index 458c2e27a6..8660604617 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1012,6 +1012,30 @@ public void setEnabled (boolean enabled) { * </ul> */ public void setLocation (int x, int y) { + setLocation (new Point (x, y)); +} +/** + * Sets the location of the receiver, which must be a popup, + * to the point specified by the arguments which are relative + * to the display. + * <p> + * Note that this is different from most widgets where the + * location of the widget is relative to the parent. + * </p><p> + * Note that the platform window manager ultimately has control + * over the location of popup menus. + * </p> + * + * @param x the new x coordinate for the receiver + * @param y the new y coordinate for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setLocationInPixels (int x, int y) { checkWidget(); if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return; this.x = x; @@ -1044,9 +1068,37 @@ public void setLocation (int x, int y) { * @since 2.1 */ public void setLocation (Point location) { + setLocationInPixels (DPIUtil.autoScaleUp (location)); +} + +/** + * Sets the location of the receiver, which must be a popup, + * to the point specified by the argument which is relative + * to the display. + * <p> + * Note that this is different from most widgets where the + * location of the widget is relative to the parent. + * </p><p> + * Note that the platform window manager ultimately has control + * over the location of popup menus. + * </p> + * + * @param location the new location for the receiver + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the point is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +void setLocationInPixels (Point location) { checkWidget(); if (location == null) error (SWT.ERROR_NULL_ARGUMENT); - setLocation (location.x, location.y); + setLocationInPixels (location.x, location.y); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java index 58406f749a..cff5a66f49 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,6 +14,7 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; /** @@ -119,12 +120,11 @@ static int checkStyle (int style) { return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - int border = getBorderWidth (); + int border = getBorderWidthInPixels (); int width = border * 2, height = border * 2; if ((style & SWT.HORIZONTAL) != 0) { width += DEFAULT_WIDTH; height += 3; @@ -192,25 +192,24 @@ long /*int*/ gtk_button_press_event (long /*int*/ widget, long /*int*/ eventPtr) lastY = y; Event event = new Event (); event.time = gdkEvent.time; - event.x = lastX; - event.y = lastY; - event.width = width; - event.height = height; + Rectangle eventRect = new Rectangle (lastX, lastY, width, height); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); if ((style & SWT.SMOOTH) == 0) { event.detail = SWT.DRAG; } - if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth () - width - event.x; + if ((parent.style & SWT.MIRRORED) != 0) event.x = DPIUtil.autoScaleDown (parent.getClientWidth () - width) - event.x; sendSelectionEvent (SWT.Selection, event, true); if (isDisposed ()) return 0; if (event.doit) { dragging = true; - lastX = event.x; - lastY = event.y; - if ((parent.style & SWT.MIRRORED) != 0) lastX = parent.getClientWidth () - width - lastX; + Rectangle rect = DPIUtil.autoScaleUp (event.getBounds ()); + lastX = rect.x; + lastY = rect.y; + if ((parent.style & SWT.MIRRORED) != 0) lastX = parent.getClientWidth () - width - lastX; parent.update (true, (style & SWT.SMOOTH) == 0); - drawBand (lastX, event.y, width, height); + drawBand (lastX, rect.y, width, height); if ((style & SWT.SMOOTH) != 0) { - setBounds (event.x, event.y, width, height); + setBoundsInPixels (rect.x, rect.y, width, height); // widget could be disposed at this point } } @@ -233,17 +232,16 @@ long /*int*/ gtk_button_release_event (long /*int*/ widget, long /*int*/ eventPt int height = allocation.height; Event event = new Event (); event.time = gdkEvent.time; - event.x = lastX; - event.y = lastY; - event.width = width; - event.height = height; + Rectangle eventRect = new Rectangle (lastX, lastY, width, height); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); drawBand (lastX, lastY, width, height); - if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth () - width - event.x; + if ((parent.style & SWT.MIRRORED) != 0) event.x = DPIUtil.autoScaleDown (parent.getClientWidth () - width) - event.x; sendSelectionEvent (SWT.Selection, event, true); if (isDisposed ()) return result; if (event.doit) { if ((style & SWT.SMOOTH) != 0) { - setBounds (event.x, event.y, width, height); + Rectangle rect = DPIUtil.autoScaleUp (event.getBounds ()); + setBoundsInPixels (rect.x, rect.y, width, height); // widget could be disposed at this point } } @@ -326,30 +324,29 @@ long /*int*/ gtk_key_press_event (long /*int*/ widget, long /*int*/ eventPtr) { /* The event must be sent because its doit flag is used. */ Event event = new Event (); event.time = gdkEvent.time; - event.x = newX; - event.y = newY; - event.width = width; - event.height = height; - if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth () - width - event.x; + Rectangle eventRect = new Rectangle (newX, newY, width, height); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); + if ((parent.style & SWT.MIRRORED) != 0) event.x = DPIUtil.autoScaleDown (parent.getClientWidth () - width) - event.x; sendSelectionEvent (SWT.Selection, event, true); if (ptrGrabResult == OS.GDK_GRAB_SUCCESS) gdk_pointer_ungrab (window, OS.GDK_CURRENT_TIME); if (isDisposed ()) break; if (event.doit) { - lastX = event.x; - lastY = event.y; + Rectangle rect = DPIUtil.autoScaleUp (event.getBounds ()); + lastX = rect.x; + lastY = rect.y; if ((parent.style & SWT.MIRRORED) != 0) lastX = parent.getClientWidth () - width - lastX; if ((style & SWT.SMOOTH) != 0) { - setBounds (event.x, event.y, width, height); + setBoundsInPixels (rect.x, rect.y, width, height); if (isDisposed ()) break; } - int cursorX = event.x, cursorY = event.y; + int cursorX = rect.x, cursorY = rect.y; if ((style & SWT.VERTICAL) != 0) { cursorY += height / 2; } else { cursorX += width / 2; } - display.setCursorLocation (parent.toDisplay (cursorX, cursorY)); + display.setCursorLocation (parent.toDisplayInPixels (cursorX, cursorY)); } break; } @@ -400,25 +397,24 @@ long /*int*/ gtk_motion_notify_event (long /*int*/ widget, long /*int*/ eventPtr Event event = new Event (); event.time = gdkEvent.time; - event.x = newX; - event.y = newY; - event.width = width; - event.height = height; + Rectangle eventRect = new Rectangle (newX, newY, width, height); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); if ((style & SWT.SMOOTH) == 0) { event.detail = SWT.DRAG; } - if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth() - width - event.x; + if ((parent.style & SWT.MIRRORED) != 0) event.x = DPIUtil.autoScaleDown (parent.getClientWidth () - width) - event.x; sendSelectionEvent (SWT.Selection, event, true); if (isDisposed ()) return 0; + Rectangle rect = DPIUtil.autoScaleUp (event.getBounds ()); if (event.doit) { - lastX = event.x; - lastY = event.y; + lastX = rect.x; + lastY = rect.y; if ((parent.style & SWT.MIRRORED) != 0) lastX = parent.getClientWidth () - width - lastX; } parent.update (true, (style & SWT.SMOOTH) == 0); drawBand (lastX, lastY, width, height); if ((style & SWT.SMOOTH) != 0) { - setBounds (event.x, lastY, width, height); + setBoundsInPixels (rect.x, lastY, width, height); // widget could be disposed at this point } return result; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java index 464bb490d8..085a830ea5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -108,8 +108,7 @@ static int checkStyle (int style) { return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget(); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java index 015b969800..45cda598a0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,6 +14,7 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; /** @@ -276,6 +277,7 @@ public int getSelection () { return (int) OS.gtk_adjustment_get_value (adjustmentHandle); } + /** * Returns a point describing the receiver's size. The * x coordinate of the result is the width of the receiver. @@ -290,6 +292,23 @@ public int getSelection () { * </ul> */ public Point getSize () { + return DPIUtil.autoScaleDown (getSizeInPixels ()); +} +/** + * Returns a point describing the receiver's size. The + * x coordinate of the result is the width of the receiver. + * The y coordinate of the result is the height of the + * receiver. + * + * @return the receiver's size + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Point getSizeInPixels () { checkWidget (); if (handle == 0) return new Point (0,0); GtkRequisition requisition = new GtkRequisition (); @@ -328,6 +347,23 @@ public int getThumb () { * @since 3.6 */ public Rectangle getThumbBounds () { + return DPIUtil.autoScaleDown(getThumbBoundsInPixels()); +} + +/** + * Returns a rectangle describing the size and location of the + * receiver's thumb relative to its parent. + * + * @return the thumb bounds, relative to the {@link #getParent() parent} + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +Rectangle getThumbBoundsInPixels () { checkWidget(); int [] slider_start = new int [1], slider_end = new int [1]; gtk_range_get_slider_range (handle, slider_start, slider_end); @@ -373,6 +409,24 @@ public Rectangle getThumbBounds () { * @since 3.6 */ public Rectangle getThumbTrackBounds () { + return DPIUtil.autoScaleDown(getThumbTrackBoundsInPixels()); +} + +/** + * Returns a rectangle describing the size and location of the + * receiver's thumb track relative to its parent. This rectangle + * comprises the areas 2, 3, and 4 as described in {@link ScrollBar}. + * + * @return the thumb track bounds, relative to the {@link #getParent() parent} + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +Rectangle getThumbTrackBoundsInPixels () { checkWidget(); int x = 0, y = 0, width, height; int[] has_stepper = new int[1]; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java index c336798959..bc45693a21 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,6 +13,7 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; /** @@ -107,6 +108,40 @@ long /*int*/ clientHandle () { */ public Rectangle computeTrim (int x, int y, int width, int height) { checkWidget(); + Rectangle rect = DPIUtil.autoScaleUp(new Rectangle (x, y, width, height)); + return DPIUtil.autoScaleDown(computeTrimInPixels(rect.x, rect.y, rect.width, rect.height)); +} + +/** + * Given a desired <em>client area</em> for the receiver + * (as described by the arguments), returns the bounding + * rectangle which would be required to produce that client + * area. + * <p> + * In other words, it returns a rectangle such that, if the + * receiver's bounds were set to that rectangle, the area + * of the receiver which is capable of displaying data + * (that is, not covered by the "trimmings") would be the + * rectangle described by the arguments (relative to the + * receiver's parent). + * </p> + * + * @param x the desired x coordinate of the client area + * @param y the desired y coordinate of the client area + * @param width the desired width of the client area + * @param height the desired height of the client area + * @return the required bounds to produce the given client area + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #getClientArea + * @since 3.105 + */ +Rectangle computeTrimInPixels (int x, int y, int width, int height) { + checkWidget(); int border = 0; if (fixedHandle != 0) border += OS.gtk_container_get_border_width (fixedHandle); if (scrolledHandle != 0) border += OS.gtk_container_get_border_width (scrolledHandle); @@ -188,8 +223,7 @@ void destroyScrollBar (ScrollBar bar) { //bar.destroyHandle (); } -@Override -public int getBorderWidth () { +@Override int getBorderWidthInPixels () { checkWidget(); int border = 0; if (fixedHandle != 0) border += OS.gtk_container_get_border_width (fixedHandle); @@ -201,7 +235,6 @@ public int getBorderWidth () { } return border; } - /** * Returns a rectangle which describes the area of the * receiver which is capable of displaying data (that is, @@ -218,6 +251,26 @@ public int getBorderWidth () { */ public Rectangle getClientArea () { checkWidget (); + return DPIUtil.autoScaleDown(getClientAreaInPixels()); +} + +/** + * Returns a rectangle which describes the area of the + * receiver which is capable of displaying data (that is, + * not covered by the "trimmings"). + * + * @return the client area + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #computeTrim + * @since 3.105 + */ +Rectangle getClientAreaInPixels () { + checkWidget (); forceResize (); long /*int*/ clientHandle = clientHandle (); GtkAllocation allocation = new GtkAllocation (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java index 0a5f9fee5d..2d5bf1f1ab 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -600,8 +600,8 @@ void bringToTop (boolean force) { void center () { if (parent == null) return; - Rectangle rect = getBounds (); - Rectangle parentRect = display.map (parent, null, parent.getClientArea()); + Rectangle rect = getBoundsInPixels (); + Rectangle parentRect = display.mapInPixels (parent, null, parent.getClientAreaInPixels()); int x = Math.max (parentRect.x, parentRect.x + (parentRect.width - rect.width) / 2); int y = Math.max (parentRect.y, parentRect.y + (parentRect.height - rect.height) / 2); Rectangle monitorRect = parent.getMonitor ().getClientArea(); @@ -615,7 +615,7 @@ void center () { } else { y = Math.max (y, monitorRect.y); } - setLocation (x, y); + setLocationInPixels (x, y); } @Override @@ -658,10 +658,9 @@ void closeWidget () { if (event.doit && !isDisposed ()) dispose (); } -@Override -public Rectangle computeTrim (int x, int y, int width, int height) { +@Override Rectangle computeTrimInPixels (int x, int y, int width, int height) { checkWidget(); - Rectangle trim = super.computeTrim (x, y, width, height); + Rectangle trim = super.computeTrimInPixels (x, y, width, height); int border = 0; if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) { border = OS.gtk_container_get_border_width (shellHandle); @@ -1052,8 +1051,7 @@ public boolean getFullScreen () { return fullScreen; } -@Override -public Point getLocation () { +@Override Point getLocationInPixels () { checkWidget (); int [] x = new int [1], y = new int [1]; OS.gtk_window_get_position (shellHandle, x,y); @@ -1079,9 +1077,27 @@ public boolean getMaximized () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * - * @since 3.1 + * @since 3.105 */ public Point getMinimumSize () { + return DPIUtil.autoScaleDown (getMinimumSizeInPixels ()); +} +/** + * Returns a point describing the minimum receiver's size. The + * x coordinate of the result is the minimum width of the receiver. + * The y coordinate of the result is the minimum height of the + * receiver. + * + * @return the receiver's size + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +Point getMinimumSizeInPixels () { checkWidget (); int width = Math.max (1, minWidth + trimWidth ()); int height = Math.max (1, minHeight + trimHeight ()); @@ -1133,8 +1149,7 @@ public boolean getModified () { return modified; } -@Override -public Point getSize () { +@Override Point getSizeInPixels () { checkWidget (); GtkAllocation allocation = new GtkAllocation (); OS.gtk_widget_get_allocation (vboxHandle, allocation); @@ -1869,7 +1884,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize * anything different from the current bounds. */ if (getMaximized ()) { - Rectangle rect = getBounds (); + Rectangle rect = getBoundsInPixels (); boolean sameOrigin = !move || (rect.x == x && rect.y == y); boolean sameExtent = !resize || (rect.width == width && rect.height == height); if (sameOrigin && sameExtent) return 0; @@ -1950,7 +1965,7 @@ public void setEnabled (boolean enabled) { long /*int*/ parentHandle = shellHandle; OS.gtk_widget_realize (parentHandle); long /*int*/ window = gtk_widget_get_window (parentHandle); - Rectangle rect = getBounds (); + Rectangle rect = getBoundsInPixels (); GdkWindowAttr attributes = new GdkWindowAttr (); attributes.width = rect.width; attributes.height = rect.height; @@ -2137,6 +2152,25 @@ public void setMinimized (boolean minimized) { * @since 3.1 */ public void setMinimumSize (int width, int height) { + setMinimumSize (new Point (width, height)); +} + +/** + * Sets the receiver's minimum size to the size specified by the arguments. + * If the new minimum size is larger than the current size of the receiver, + * the receiver is resized to the new minimum size. + * + * @param width the new minimum width for the receiver + * @param height the new minimum height for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +void setMinimumSizeInPixels (int width, int height) { checkWidget (); GdkGeometry geometry = new GdkGeometry (); minWidth = geometry.min_width = Math.max (width, trimWidth ()) - trimWidth (); @@ -2162,9 +2196,30 @@ public void setMinimumSize (int width, int height) { * @since 3.1 */ public void setMinimumSize (Point size) { + setMinimumSizeInPixels (DPIUtil.autoScaleUp (size)); +} + +/** + * Sets the receiver's minimum size to the size specified by the argument. + * If the new minimum size is larger than the current size of the receiver, + * the receiver is resized to the new minimum size. + * + * @param size the new minimum size for the receiver + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the point is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +void setMinimumSizeInPixels (Point size) { checkWidget (); if (size == null) error (SWT.ERROR_NULL_ARGUMENT); - setMinimumSize (size.x, size.y); + setMinimumSizeInPixels (size.x, size.y); } /** @@ -2254,7 +2309,7 @@ static Region mirrorRegion (Region region) { int [] nRects = new int [1]; long /*int*/ [] rects = new long /*int*/ [1]; gdk_region_get_rectangles (rgn, rects, nRects); - Rectangle bounds = region.getBounds (); + Rectangle bounds = DPIUtil.autoScaleUp(region.getBounds ()); GdkRectangle rect = new GdkRectangle (); for (int i = 0; i < nRects [0]; i++) { OS.memmove (rect, rects[0] + (i * GdkRectangle.sizeof), GdkRectangle.sizeof); @@ -2296,7 +2351,7 @@ public void setVisible (boolean visible) { checkWidget(); if (moved) { //fix shell location if it was moved. - setLocation(oldX, oldY); + setLocationInPixels(oldX, oldY); } int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL; if ((style & mask) != 0) { @@ -2377,7 +2432,7 @@ public void setVisible (boolean visible) { opened = true; if (!moved) { moved = true; - Point location = getLocation(); + Point location = getLocationInPixels(); oldX = location.x; oldY = location.y; sendEvent (SWT.Move); @@ -2385,7 +2440,7 @@ public void setVisible (boolean visible) { } if (!resized) { resized = true; - Point size = getSize (); + Point size = getSizeInPixels (); oldWidth = size.x - trimWidth (); oldHeight = size.y - trimHeight (); sendEvent (SWT.Resize); @@ -2653,8 +2708,7 @@ public void forceActive () { bringToTop (true); } -@Override -public Rectangle getBounds () { +@Override Rectangle getBoundsInPixels () { checkWidget (); int [] x = new int [1], y = new int [1]; OS.gtk_window_get_position (shellHandle, x, y); @@ -2751,7 +2805,7 @@ Point getWindowOrigin () { * window trims etc. from the window manager. That's why getLocation () * is not safe to use for coordinate mappings after the shell has been made visible. */ - return getLocation (); + return getLocationInPixels (); } return super.getWindowOrigin( ); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java index 3089ecd965..a3f56e8ece 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -263,8 +263,7 @@ void deregister () { display.removeWidget (hAdjustment); } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget(); OS.gtk_widget_realize(handle); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java index 8930061bcb..48a556bd15 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -203,8 +203,7 @@ protected void checkSubclass () { if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; @@ -247,15 +246,14 @@ public Point computeSize (int wHint, int hHint, boolean changed) { width = wHint == SWT.DEFAULT ? w [0] : wHint; height = hHint == SWT.DEFAULT ? h [0] : hHint; } - Rectangle trim = computeTrim (0, 0, width, height); + Rectangle trim = computeTrimInPixels (0, 0, width, height); return new Point (trim.width, trim.height); } -@Override -public Rectangle computeTrim (int x, int y, int width, int height) { +@Override Rectangle computeTrimInPixels (int x, int y, int width, int height) { checkWidget (); int xborder = 0, yborder = 0; - Rectangle trim = super.computeTrim (x, y, width, height); + Rectangle trim = super.computeTrimInPixels (x, y, width, height); if (OS.GTK3) { GtkBorder tmp = new GtkBorder(); long /*int*/ context = OS.gtk_widget_get_style_context (handle); @@ -412,8 +410,7 @@ GdkColor getBackgroundColor () { return getBaseColor (); } -@Override -public int getBorderWidth () { +@Override int getBorderWidthInPixels () { checkWidget(); if ((this.style & SWT.BORDER) != 0) { return getThickness (handle).x; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java index 00e157cf6b..0dd6359cb4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -188,10 +188,9 @@ long /*int*/ clientHandle () { return handle; } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); - Point size = super.computeSize (wHint, hHint, changed); + Point size = super.computeSizeInPixels (wHint, hHint, changed); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; boolean scrollable = OS.gtk_notebook_get_scrollable (handle); @@ -208,8 +207,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { return size; } -@Override -public Rectangle computeTrim (int x, int y, int width, int height) { +@Override Rectangle computeTrimInPixels (int x, int y, int width, int height) { checkWidget(); forceResize (); long /*int*/ clientHandle = clientHandle (); @@ -231,9 +229,8 @@ public Rectangle computeTrim (int x, int y, int width, int height) { return new Rectangle (x, y, width, height); } -@Override -public Rectangle getClientArea () { - Rectangle clientRectangle = super.getClientArea (); +@Override Rectangle getClientAreaInPixels () { + Rectangle clientRectangle = super.getClientAreaInPixels (); if (OS.GTK3) { /* @@ -352,7 +349,7 @@ void destroyItem (TabItem item) { if (newIndex != -1) { Control control = items [newIndex].getControl (); if (control != null && !control.isDisposed ()) { - control.setBounds (getClientArea()); + control.setBoundsInPixels (getClientAreaInPixels()); control.setVisible (true); } Event event = new Event (); @@ -571,7 +568,7 @@ long /*int*/ gtk_switch_page (long /*int*/ widget, long /*int*/ page, long /*int TabItem item = items [(int)/*64*/page_num]; Control control = item.getControl (); if (control != null && !control.isDisposed ()) { - control.setBounds(getClientArea()); + control.setBoundsInPixels(getClientAreaInPixels()); control.setVisible (true); } Event event = new Event(); @@ -634,11 +631,11 @@ Point minimumSize (int wHint, int hHint, boolean flushCache) { index++; } if (index == count) { - Rectangle rect = child.getBounds (); + Rectangle rect = child.getBoundsInPixels (); width = Math.max (width, rect.x + rect.width); height = Math.max (height, rect.y + rect.height); } else { - Point size = child.computeSize (wHint, hHint, flushCache); + Point size = child.computeSizeInPixels (wHint, hHint, flushCache); width = Math.max (width, size.x); height = Math.max (height, size.y); } @@ -747,7 +744,7 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize TabItem item = items [index]; Control control = item.control; if (control != null && !control.isDisposed ()) { - control.setBounds (getClientArea ()); + control.setBoundsInPixels (getClientAreaInPixels ()); } } } @@ -824,7 +821,7 @@ void setSelection (int index, boolean notify) { TabItem item = items [newIndex]; Control control = item.control; if (control != null && !control.isDisposed ()) { - control.setBounds (getClientArea ()); + control.setBoundsInPixels (getClientAreaInPixels ()); control.setVisible (true); } if (notify) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java index 90e28ee79f..b26af815e0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -153,6 +153,22 @@ void destroyWidget () { * @since 3.4 */ public Rectangle getBounds () { + return DPIUtil.autoScaleDown (getBoundsInPixels ()); +} +/** + * Returns a rectangle describing the receiver's size and location + * relative to its parent. + * + * @return the receiver's bounding rectangle + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +Rectangle getBoundsInPixels () { checkWidget(); GtkAllocation allocation = new GtkAllocation (); OS.gtk_widget_get_allocation (handle, allocation); @@ -306,7 +322,7 @@ public void setControl (Control control) { } } if (newControl != null) { - newControl.setBounds (parent.getClientArea ()); + newControl.setBoundsInPixels (parent.getClientAreaInPixels ()); newControl.setVisible (true); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java index db66729d34..254abbeade 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java @@ -495,8 +495,7 @@ public void clearAll () { } } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; @@ -509,7 +508,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { * based on the number of items in the table */ if (OS.GTK3 && size.y == 0 && hHint == SWT.DEFAULT) { - size.y = getItemCount() * getItemHeight(); + size.y = getItemCount() * getItemHeightInPixels(); } /* @@ -518,7 +517,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { * so need to assign default height */ if (size.y == 0 && hHint == SWT.DEFAULT) size.y = DEFAULT_HEIGHT; - Rectangle trim = computeTrim (0, 0, size.x, size.y); + Rectangle trim = computeTrimInPixels (0, 0, size.x, size.y); size.x = trim.width; size.y = trim.height; return size; @@ -1150,8 +1149,7 @@ GdkColor getBackgroundColor () { return getBaseColor (); } -@Override -public Rectangle getClientArea () { +@Override Rectangle getClientAreaInPixels () { checkWidget (); forceResize (); OS.gtk_widget_realize (handle); @@ -1168,7 +1166,7 @@ public Rectangle getClientArea () { int height = (state & ZERO_HEIGHT) != 0 ? 0 : allocation.height; Rectangle rect = new Rectangle (fixedX [0] - binX [0], fixedY [0] - binY [0], width, height); if (getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) { - rect.y += getHeaderHeight(); + rect.y += getHeaderHeightInPixels(); } return rect; } @@ -1388,6 +1386,21 @@ GdkColor getForegroundColor () { * </ul> */ public int getGridLineWidth () { + return DPIUtil.autoScaleDown (getGridLineWidthInPixels ()); +} + +/** + * Returns the width in pixels of a grid line. + * + * @return the width of a grid line in pixels + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +int getGridLineWidthInPixels () { checkWidget(); return 0; } @@ -1405,6 +1418,22 @@ public int getGridLineWidth () { * @since 2.0 */ public int getHeaderHeight () { + return DPIUtil.autoScaleDown (getHeaderHeightInPixels ()); +} + +/** + * Returns the height of the receiver's header + * + * @return the height of the header or zero if the header is not visible + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +int getHeaderHeightInPixels () { checkWidget (); if (!OS.gtk_tree_view_get_headers_visible (handle)) return 0; if (columnCount > 0) { @@ -1502,7 +1531,7 @@ public TableItem getItem (Point point) { OS.gtk_widget_realize (handle); int y = point.y; if (getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) { - y -= getHeaderHeight(); + y -= getHeaderHeightInPixels(); } if (!OS.gtk_tree_view_get_path_at_pos (handle, point.x, y, path, null, null, null)) return null; if (path [0] == 0) return null; @@ -1544,6 +1573,22 @@ public int getItemCount () { * </ul> */ public int getItemHeight () { + return DPIUtil.autoScaleDown (getItemHeightInPixels ()); +} + +/** + * Returns the height of the area which would be used to + * display <em>one</em> of the items in the receiver. + * + * @return the height of one item + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +int getItemHeightInPixels () { checkWidget(); if (itemCount == 0) { long /*int*/ column = OS.gtk_tree_view_get_column (handle, 0); @@ -2611,7 +2656,7 @@ void sendMeasureEvent (long /*int*/ cell, long /*int*/ width, long /*int*/ heigh Image image = item.getImage (columnIndex); int imageWidth = 0; if (image != null) { - Rectangle bounds = image.getBounds (); + Rectangle bounds = image.getBoundsInPixels (); imageWidth = bounds.width; } contentWidth [0] += imageWidth; @@ -2621,13 +2666,14 @@ void sendMeasureEvent (long /*int*/ cell, long /*int*/ width, long /*int*/ heigh event.item = item; event.index = columnIndex; event.gc = gc; - event.width = contentWidth [0]; - event.height = contentHeight [0]; + Rectangle eventRect = new Rectangle (0, 0, contentWidth [0], contentHeight [0]); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); if (isSelected) event.detail = SWT.SELECTED; sendEvent (SWT.MeasureItem, event); gc.dispose (); - contentWidth [0] = event.width - imageWidth; - if (contentHeight [0] < event.height) contentHeight [0] = event.height; + Rectangle rect = DPIUtil.autoScaleUp (event.getBounds ()); + contentWidth [0] = rect.width - imageWidth; + if (contentHeight [0] < rect.height) contentHeight [0] = rect.height; if (width != 0) OS.memmove (width, contentWidth, 4); if (height != 0) OS.memmove (height, contentHeight, 4); if (OS.GTK3) { @@ -2774,22 +2820,21 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo if (OS.GTK_VERSION >= OS.VERSION(3, 9, 0) && cr != 0) { GdkRectangle r = new GdkRectangle(); OS.gdk_cairo_get_clip_rectangle(cr, r); - gc.setClipping(rect.x, r.y, r.width, r.height); + gc.setClipping(DPIUtil.autoScaleDown(new Rectangle(rect.x, r.y, r.width, r.height))); + if (OS.GTK_VERSION <= OS.VERSION(3, 14, 8)) { rect.width = r.width; } } else { - gc.setClipping (rect.x, rect.y, rect.width, rect.height); + gc.setClipping(DPIUtil.autoScaleDown(new Rectangle(rect.x, rect.y, rect.width, rect.height))); + } Event event = new Event (); event.item = item; event.index = columnIndex; event.gc = gc; - event.x = rect.x; - event.y = rect.y; - event.width = rect.width; - event.height = rect.height; - event.detail = drawState; + Rectangle eventRect = new Rectangle (rect.x, rect.y, rect.width, rect.height); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); sendEvent (SWT.EraseItem, event); drawForeground = null; drawState = event.doit ? event.detail : 0; @@ -2825,7 +2870,7 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo gc.setBackground (item.getBackground (columnIndex)); GdkRectangle rect = new GdkRectangle (); OS.memmove (rect, background_area, GdkRectangle.sizeof); - gc.fillRectangle (rect.x, rect.y, rect.width, rect.height); + gc.fillRectangle(DPIUtil.autoScaleDown(new Rectangle(rect.x, rect.y, rect.width, rect.height))); gc.dispose (); } if ((drawState & SWT.FOREGROUND) != 0 || OS.GTK_IS_CELL_RENDERER_TOGGLE (cell)) { @@ -2863,7 +2908,7 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo Image image = item.getImage (columnIndex); int imageWidth = 0; if (image != null) { - Rectangle bounds = image.getBounds (); + Rectangle bounds = image.getBoundsInPixels (); imageWidth = bounds.width; } // On gtk >3.9 and <3.14.8 the clip rectangle does not have image area into clip rectangle @@ -2898,15 +2943,13 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo } gc.setFont (item.getFont (columnIndex)); if ((style & SWT.MIRRORED) != 0) rect.x = getClientWidth () - rect.width - rect.x; - gc.setClipping (rect.x, rect.y, rect.width, rect.height); + gc.setClipping(DPIUtil.autoScaleDown(new Rectangle(rect.x, rect.y, rect.width, rect.height))); Event event = new Event (); event.item = item; event.index = columnIndex; event.gc = gc; - event.x = rect.x + contentX [0]; - event.y = rect.y; - event.width = contentWidth [0]; - event.height = rect.height; + Rectangle eventRect = new Rectangle (rect.x + contentX [0], rect.y, contentWidth [0], rect.height); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); event.detail = drawState; sendEvent (SWT.PaintItem, event); gc.dispose(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java index 47ab2110cd..32594bc850 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,10 +12,10 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; /** * Instances of this class represent a column in a table widget. @@ -320,6 +320,21 @@ public String getToolTipText () { * </ul> */ public int getWidth () { + return DPIUtil.autoScaleDown(getWidthInPixels()); +} + +/** + * Gets the width of the receiver. + * + * @return the width + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +int getWidthInPixels () { checkWidget(); if (!OS.gtk_tree_view_column_get_visible (handle)) { return 0; @@ -447,7 +462,7 @@ public void pack () { } OS.g_free (iter); } - setWidth(width); + setWidthInPixels(width); } @Override @@ -689,6 +704,21 @@ void setToolTipText (Shell shell, String newString) { * </ul> */ public void setWidth (int width) { + setWidthInPixels (DPIUtil.autoScaleUp (width)); +} + +/** + * Sets the width of the receiver. + * + * @param width the new width + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setWidthInPixels (int width) { checkWidget(); if (width < 0) return; if (width == lastWidth) return; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java index 025f8e6688..1db47bbf2b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -266,6 +266,23 @@ public Color getBackground () { * @since 3.2 */ public Rectangle getBounds () { + return DPIUtil.autoScaleDown (getBoundsinPixels ()); +} + +/** + * Returns a rectangle describing the size and location of the receiver's + * text relative to its parent. + * + * @return the bounding rectangle of the receiver's text + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +Rectangle getBoundsinPixels () { // TODO fully test on early and later versions of GTK // shifted a bit too far right on later versions of GTK - however, old Tree also had this problem checkWidget (); @@ -315,7 +332,7 @@ public Rectangle getBounds () { int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; Rectangle r = new Rectangle (rect.x, rect.y, width, rect.height + 1); if (parent.getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) { - r.y += parent.getHeaderHeight(); + r.y += parent.getHeaderHeightInPixels(); } return r; } @@ -352,6 +369,23 @@ public Color getBackground (int index) { * </ul> */ public Rectangle getBounds (int index) { + return DPIUtil.autoScaleDown (getBoundsInPixels (index)); +} + +/** + * Returns a rectangle describing the receiver's size and location + * relative to its parent at a column in the table. + * + * @param index the index that specifies the column + * @return the receiver's bounding column rectangle + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Rectangle getBoundsInPixels (int index) { checkWidget(); if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); long /*int*/ parentHandle = parent.handle; @@ -378,7 +412,7 @@ public Rectangle getBounds (int index) { int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; Rectangle r = new Rectangle (rect.x, rect.y, width, rect.height + 1); if (parent.getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) { - r.y += parent.getHeaderHeight(); + r.y += parent.getHeaderHeightInPixels(); } return r; } @@ -540,6 +574,25 @@ public Image getImage (int index) { * </ul> */ public Rectangle getImageBounds (int index) { + return DPIUtil.autoScaleDown (getImageBoundsInPixels (index)); +} + +/** + * Returns a rectangle describing the size and location + * relative to its parent of an image at a column in the + * table. An empty rectangle is returned if index exceeds + * the index of the table's last column. + * + * @param index the index that specifies the column + * @return the receiver's bounding image rectangle + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Rectangle getImageBoundsInPixels (int index) { checkWidget (); if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); long /*int*/ parentHandle = parent.handle; @@ -648,6 +701,25 @@ public String getText (int index) { * @since 3.3 */ public Rectangle getTextBounds (int index) { + return DPIUtil.autoScaleDown (getTextBoundsInPixels (index)); +} +/** + * Returns a rectangle describing the size and location + * relative to its parent of the text at a column in the + * table. An empty rectangle is returned if index exceeds + * the index of the table's last column. + * + * @param index the index that specifies the column + * @return the receiver's bounding text rectangle + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +Rectangle getTextBoundsInPixels (int index) { checkWidget (); if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); int count = Math.max (1, parent.getColumnCount ()); @@ -1082,7 +1154,7 @@ public void setImage (int index, Image image) { int [] w = new int [1]; long /*int*/ pixbufRenderer = parent.getPixbufRenderer(column); OS.gtk_tree_view_column_cell_get_position (column, pixbufRenderer, null, w); - if (w[0] < image.getBounds().width) { + if (w[0] < image.getBoundsInPixels().width) { /* * There is no direct way to clear the cell renderer width so we * are relying on the fact that it is done as part of modifying diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java index cb47fc6ce5..c1682b2b34 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -548,8 +548,7 @@ public void clearSelection () { } } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; @@ -582,14 +581,13 @@ public Point computeSize (int wHint, int hHint, boolean changed) { if (height == 0) height = DEFAULT_HEIGHT; width = wHint == SWT.DEFAULT ? width : wHint; height = hHint == SWT.DEFAULT ? height : hHint; - Rectangle trim = computeTrim (0, 0, width, height); + Rectangle trim = computeTrimInPixels (0, 0, width, height); return new Point (trim.width, trim.height); } -@Override -public Rectangle computeTrim (int x, int y, int width, int height) { +@Override Rectangle computeTrimInPixels (int x, int y, int width, int height) { checkWidget (); - Rectangle trim = super.computeTrim (x, y, width, height); + Rectangle trim = super.computeTrimInPixels (x, y, width, height); int xborder = 0, yborder = 0; if ((style & SWT.SINGLE) != 0) { if (OS.GTK3) { @@ -820,10 +818,9 @@ GdkColor getBackgroundColor () { return getBaseColor (); } -@Override -public int getBorderWidth () { +@Override int getBorderWidthInPixels () { checkWidget(); - if ((style & SWT.MULTI) != 0) return super.getBorderWidth (); + if ((style & SWT.MULTI) != 0) return super.getBorderWidthInPixels (); if ((this.style & SWT.BORDER) != 0) { return getThickness (handle).x; } @@ -865,6 +862,23 @@ public int getCaretLineNumber () { */ public Point getCaretLocation () { checkWidget (); + return DPIUtil.autoScaleDown(getCaretLocationInPixels()); +} + +/** + * Returns a point describing the location of the caret relative + * to the receiver. + * + * @return a point, the location of the caret + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Point getCaretLocationInPixels () { + checkWidget (); if ((style & SWT.SINGLE) != 0) { int index = OS.gtk_editable_get_position (handle); index = OS.gtk_entry_text_index_to_layout_index (handle, index); @@ -873,7 +887,7 @@ public Point getCaretLocation () { long /*int*/ layout = OS.gtk_entry_get_layout (handle); PangoRectangle pos = new PangoRectangle (); OS.pango_layout_index_to_pos (layout, index, pos); - int x = offset_x [0] + OS.PANGO_PIXELS (pos.x) - getBorderWidth (); + int x = offset_x [0] + OS.PANGO_PIXELS (pos.x) - getBorderWidthInPixels (); int y = offset_y [0] + OS.PANGO_PIXELS (pos.y); return new Point (x, y); } @@ -1397,7 +1411,7 @@ public int getTopIndex () { * The top pixel does not include the widget trimming. * </p> * - * @return the pixel position of the top line + * @return the point position of the top line * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> @@ -1406,6 +1420,32 @@ public int getTopIndex () { */ public int getTopPixel () { checkWidget (); + return DPIUtil.autoScaleDown(getTopPixelInPixels()); +} + +/** + * Returns the top pixel. + * <p> + * The top pixel is the pixel position of the line + * that is currently at the top of the widget. On + * some platforms, a text widget can be scrolled by + * pixels instead of lines so that a partial line + * is displayed at the top of the widget. + * </p><p> + * The top pixel changes when the widget is scrolled. + * The top pixel does not include the widget trimming. + * </p> + * + * @return the pixel position of the top line + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +int getTopPixelInPixels () { + checkWidget (); if ((style & SWT.SINGLE) != 0) return 0; byte [] position = new byte [ITER_SIZEOF]; GdkRectangle rect = new GdkRectangle (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java index fa5807ba6a..37b13c5d96 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -161,8 +161,7 @@ int applyThemeBackground () { return -1; /* No Change */ } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; @@ -302,7 +301,7 @@ public ToolItem getItem (Point point) { if (point == null) error (SWT.ERROR_NULL_ARGUMENT); ToolItem[] items = getItems(); for (int i=0; i<items.length; i++) { - if (items[i].getBounds().contains(point)) return items[i]; + if (items[i].getBoundsInPixels().contains(point)) return items[i]; } return null; } @@ -475,9 +474,9 @@ long /*int*/ menuItemSelected (long /*int*/ widget, ToolItem item) { event.detail = SWT.ARROW; GtkAllocation allocation = new GtkAllocation (); OS.gtk_widget_get_allocation (widget, allocation); - event.x = allocation.x; - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - allocation.width - event.x; - event.y = allocation.y + allocation.height; + event.x = DPIUtil.autoScaleDown(allocation.x); + if ((style & SWT.MIRRORED) != 0) event.x = DPIUtil.autoScaleDown (getClientWidth () - allocation.width) - event.x; + event.y = DPIUtil.autoScaleDown(allocation.y + allocation.height); break; case SWT.RADIO : if ((style & SWT.NO_RADIO_GROUP) == 0) item.selectRadio (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java index 0c03576edd..0bfa98dd64 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -299,6 +299,22 @@ public void dispose () { * </ul> */ public Rectangle getBounds () { + return DPIUtil.autoScaleDown (getBoundsInPixels ()); +} + +/** + * Returns a rectangle describing the receiver's size and location + * relative to its parent. + * + * @return the receiver's bounding rectangle + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Rectangle getBoundsInPixels () { checkWidget(); parent.forceResize (); long /*int*/ topHandle = topHandle (); @@ -453,6 +469,20 @@ public String getToolTipText () { * </ul> */ public int getWidth () { + return DPIUtil.autoScaleDown (getWidthInPixels ()); +} +/** + * Gets the width of the receiver. + * + * @return the width + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +int getWidthInPixels () { checkWidget(); parent.forceResize (); long /*int*/ topHandle = topHandle (); @@ -523,9 +553,9 @@ long /*int*/ gtk_clicked (long /*int*/ widget) { event.detail = SWT.ARROW; GtkAllocation allocation = new GtkAllocation (); OS.gtk_widget_get_allocation (topHandle, allocation); - event.x = allocation.x; - if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth () - allocation.width - event.x; - event.y = allocation.y + allocation.height; + event.x = DPIUtil.autoScaleDown(allocation.x); + if ((style & SWT.MIRRORED) != 0) event.x = DPIUtil.autoScaleDown (parent.getClientWidth ()- allocation.width) - event.x; + event.y = DPIUtil.autoScaleDown(allocation.y + allocation.height); } break; } @@ -869,13 +899,13 @@ void resizeControl () { * case can occur when the control is a * combo box. */ - Rectangle itemRect = getBounds (); - control.setSize (itemRect.width, itemRect.height); + Rectangle itemRect = getBoundsInPixels (); + control.setSizeInPixels (itemRect.width, itemRect.height); resizeHandle(itemRect.width, itemRect.height); - Rectangle rect = control.getBounds (); + Rectangle rect = control.getBoundsInPixels (); rect.x = itemRect.x + (itemRect.width - rect.width) / 2; rect.y = itemRect.y + (itemRect.height - rect.height) / 2; - control.setLocation (rect.x, rect.y); + control.setLocationInPixels (rect.x, rect.y); } } @@ -988,7 +1018,7 @@ public void setEnabled (boolean enabled) { */ int [] x = new int [1], y = new int [1]; gdk_window_get_device_position (parent.paintWindow (), x, y, null); - if (getBounds ().contains (x [0], y [0])) { + if (getBoundsInPixels ().contains (x [0], y [0])) { OS.gtk_widget_hide (handle); OS.gtk_widget_show (handle); } @@ -1249,6 +1279,28 @@ void setToolTipText (Shell shell, String newString) { * </ul> */ public void setWidth (int width) { + setWidthInPixels(DPIUtil.autoScaleUp(width)); +} + +/** + * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems. + * + * @param width the new width. If the new value is <code>SWT.DEFAULT</code>, + * the width is a fixed-width area whose amount is determined by the platform. + * If the new value is 0 a vertical or horizontal line will be drawn, depending + * on the setting of the corresponding style bit (<code>SWT.VERTICAL</code> or + * <code>SWT.HORIZONTAL</code>). If the new value is <code>SWT.SEPARATOR_FILL</code> + * a variable-width space is inserted that acts as a spring between the two adjoining + * items which will push them out to the extent of the containing ToolBar. + * + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setWidthInPixels (int width) { checkWidget(); if ((style & SWT.SEPARATOR) == 0) return; if (width < 0) return; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java index 8ad085a5e9..0eaa3081ef 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -252,7 +252,7 @@ void configure () { } OS.gtk_widget_realize(handle); Region region = new Region (display); - region.add(polyline); + region.add(DPIUtil.autoScaleDown(polyline)); if (OS.GTK3) { OS.gtk_widget_shape_combine_region (handle, region.handle); } else { @@ -710,6 +710,28 @@ public void setAutoHide (boolean autoHide) { * </ul> */ public void setLocation (int x, int y) { + setLocation (new Point (x, y)); +} + +/** + * Sets the location of the receiver, which must be a tooltip, + * to the point specified by the arguments which are relative + * to the display. + * <p> + * Note that this is different from most widgets where the + * location of the widget is relative to the parent. + * </p> + * + * @param x the new x coordinate for the receiver + * @param y the new y coordinate for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setLocationInPixels (int x, int y) { checkWidget (); this.x = x; this.y = y; @@ -717,7 +739,6 @@ public void setLocation (int x, int y) { if (OS.gtk_widget_get_visible (handle)) configure (); } } - /** * Sets the location of the receiver, which must be a tooltip, * to the point specified by the argument which is relative @@ -741,9 +762,36 @@ public void setLocation (int x, int y) { * </ul> */ public void setLocation (Point location) { + setLocationInPixels(DPIUtil.autoScaleUp(location)); +} + +/** + * Sets the location of the receiver, which must be a tooltip, + * to the point specified by the argument which is relative + * to the display. + * <p> + * Note that this is different from most widgets where the + * location of the widget is relative to the parent. + * </p><p> + * Note that the platform window manager ultimately has control + * over the location of tooltips. + * </p> + * + * @param location the new location for the receiver + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the point is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setLocationInPixels (Point location) { checkWidget (); if (location == null) error (SWT.ERROR_NULL_ARGUMENT); - setLocation (location.x, location.y); + setLocationInPixels (location.x, location.y); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java index 1870a87315..43905e94cd 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -195,7 +195,7 @@ Point adjustMoveCursor () { int newX = bounds.x + bounds.width / 2; int newY = bounds.y; - Point point = display.map (parent, null, newX, newY); + Point point = display.mapInPixels (parent, null, newX, newY); display.setCursorLocation (point); /* @@ -228,7 +228,7 @@ Point adjustResizeCursor () { newY = bounds.y + bounds.height / 2; } - Point point = display.map (parent, null, newX, newY); + Point point = display.mapInPixels (parent, null, newX, newY); display.setCursorLocation (point); /* @@ -318,7 +318,7 @@ void drawRectangles (Rectangle [] rects) { long /*int*/ region = OS.gdk_region_new (); GdkRectangle rect = new GdkRectangle(); for (int i = 0; i < rects.length; i++) { - Rectangle r = parent != null ? display.map(parent, null, rects[i]) : rects[i]; + Rectangle r = parent != null ? display.mapInPixels(parent, null, rects[i]) : rects[i]; rect.x = r.x; rect.y = r.y; rect.width = r.width + 1; @@ -376,6 +376,29 @@ public Rectangle [] getRectangles () { Rectangle [] result = new Rectangle [rectangles.length]; for (int i = 0; i < rectangles.length; i++) { Rectangle current = rectangles [i]; + result [i] = DPIUtil.autoScaleDown (new Rectangle (current.x, current.y, current.width, current.height)); + } + return result; +} + +/** + * Returns the bounds that are being drawn, expressed relative to the parent + * widget. If the parent is a <code>Display</code> then these are screen + * coordinates. + * + * @return the bounds of the Rectangles being drawn + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Rectangle [] getRectanglesInPixels () { + checkWidget(); + Rectangle [] result = new Rectangle [rectangles.length]; + for (int i = 0; i < rectangles.length; i++) { + Rectangle current = rectangles [i]; result [i] = new Rectangle (current.x, current.y, current.width, current.height); } return result; @@ -443,10 +466,10 @@ long /*int*/ gtk_key_press_event (long /*int*/ widget, long /*int*/ eventPtr) { rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height); } Event event = new Event (); - event.x = oldX + xChange; - event.y = oldY + yChange; + Rectangle eventRect = new Rectangle (oldX + xChange, oldY + yChange, 0, 0); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); if (parent != null && (parent.style & SWT.MIRRORED) != 0) { - event.x = parent.getClientWidth () - event.width - event.x; + event.x = DPIUtil.autoScaleDown (parent.getClientWidth ()) - event.width - event.x; } if ((style & SWT.RESIZE) != 0) { resizeRectangles (xChange, yChange); @@ -568,12 +591,12 @@ long /*int*/ gtk_mouse (int eventType, long /*int*/ widget, long /*int*/ eventPt } Event event = new Event (); if (parent == null) { - event.x = newX [0]; - event.y = newY [0]; + Rectangle eventRect = new Rectangle (newX [0], newY [0], 0, 0); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); } else { - Point screenCoord = display.map (parent, null, newX [0], newY [0]); - event.x = screenCoord.x; - event.y = screenCoord.y; + Point screenCoord = display.mapInPixels (parent, null, newX [0], newY [0]); + Rectangle eventRect = new Rectangle (screenCoord.x, screenCoord.y, 0, 0); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); } if ((style & SWT.RESIZE) != 0) { resizeRectangles (newX [0] - oldX, newY [0] - oldY); @@ -772,7 +795,7 @@ public boolean open () { OS.gtk_widget_shape_combine_region (overlay, region); OS.gtk_widget_input_shape_combine_region (overlay, region); OS.gdk_region_destroy (region); - Rectangle bounds = display.getBounds(); + Rectangle bounds = display.getBoundsInPixels(); OS.gtk_window_move (overlay, bounds.x, bounds.y); OS.gtk_window_resize (overlay, bounds.width, bounds.height); OS.gtk_widget_show (overlay); @@ -1050,6 +1073,31 @@ public void setRectangles (Rectangle [] rectangles) { checkWidget(); if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT); int length = rectangles.length; + for (int i = 0; i < length; i++) { + rectangles [i] = DPIUtil.autoScaleUp (rectangles [i]); + } + setRectanglesInPixels (rectangles); +} + +/** + * Specifies the rectangles that should be drawn, expressed relative to the parent + * widget. If the parent is a Display then these are screen coordinates. + * + * @param rectangles the bounds of the rectangles to be drawn + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the set of rectangles is null or contains a null rectangle</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setRectanglesInPixels (Rectangle [] rectangles) { + checkWidget(); + if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT); + int length = rectangles.length; this.rectangles = new Rectangle [length]; for (int i = 0; i < length; i++) { Rectangle current = rectangles [i]; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java index 6d8ede3ad2..36b8edc874 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -293,7 +293,7 @@ long /*int*/ gtk_size_allocate (long /*int*/ widget, long /*int*/ allocation) { OS.gtk_widget_get_allocation (widget, widgetAllocation); int xoffset = (int) Math.floor (widgetAllocation.x + ((widgetAllocation.width -OS.GTK_WIDGET_REQUISITION_WIDTH (widget)) * 0.5) + 0.5); int yoffset = (int) Math.floor (widgetAllocation.y + ((widgetAllocation.height - OS.GTK_WIDGET_REQUISITION_HEIGHT (widget)) * 0.5) + 0.5); - Rectangle b = image.getBounds(); + Rectangle b = image.getBoundsInPixels(); long /*int*/ gdkImagePtr = OS.gdk_drawable_get_image (image.mask, 0, 0, b.width, b.height); if (gdkImagePtr == 0) error(SWT.ERROR_NO_HANDLES); GdkImage gdkImage = new GdkImage(); @@ -308,7 +308,8 @@ long /*int*/ gtk_size_allocate (long /*int*/ widget, long /*int*/ allocation) { int theByte = maskData [index] & 0xFF; int mask = 1 << (x & 0x7); if ((theByte & mask) != 0) { - region.add (xoffset + x, yoffset + y, 1, 1); + Rectangle rect = DPIUtil.autoScaleDown(new Rectangle(xoffset + x, yoffset + y, 1, 1)); + region.add(rect.x, rect.y, rect.width, rect.height); } } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java index 30e7b1b666..ced41c87c5 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -536,8 +536,7 @@ void clearAll (boolean all, long /*int*/ parentIter) { OS.g_free (iter); } -@Override -public Point computeSize (int wHint, int hHint, boolean changed) { +@Override Point computeSizeInPixels (int wHint, int hHint, boolean changed) { checkWidget (); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; @@ -551,7 +550,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { * based on the number of items in the table */ if (OS.GTK3 && size.y == 0 && hHint == SWT.DEFAULT) { - size.y = getItemCount() * getItemHeight(); + size.y = getItemCount() * getItemHeightInPixels(); } /* @@ -560,7 +559,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) { * so need to assign default height */ if (size.y == 0 && hHint == SWT.DEFAULT) size.y = DEFAULT_HEIGHT; - Rectangle trim = computeTrim (0, 0, size.x, size.y); + Rectangle trim = computeTrimInPixels (0, 0, size.x, size.y); size.x = trim.width; size.y = trim.height; return size; @@ -1139,8 +1138,7 @@ GdkColor getBackgroundColor () { return getBaseColor (); } -@Override -public Rectangle getClientArea () { +@Override Rectangle getClientAreaInPixels () { checkWidget (); forceResize (); OS.gtk_widget_realize (handle); @@ -1157,7 +1155,7 @@ public Rectangle getClientArea () { int height = (state & ZERO_HEIGHT) != 0 ? 0 : allocation.height; Rectangle rect = new Rectangle (fixedX [0] - binX [0], fixedY [0] - binY [0], width, height); if (getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) { - rect.y += getHeaderHeight(); + rect.y += getHeaderHeightInPixels(); } return rect; } @@ -1387,6 +1385,21 @@ GdkColor getForegroundColor () { * @since 3.1 */ public int getGridLineWidth () { + return DPIUtil.autoScaleDown (getGridLineWidthInPixels ()); +} +/** + * Returns the width in pixels of a grid line. + * + * @return the width of a grid line in pixels + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +protected int getGridLineWidthInPixels () { checkWidget(); return 0; } @@ -1404,6 +1417,22 @@ public int getGridLineWidth () { * @since 3.1 */ public int getHeaderHeight () { + return DPIUtil.autoScaleDown (getHeaderHeightInPixels ()); +} + +/** + * Returns the height of the receiver's header + * + * @return the height of the header or zero if the header is not visible + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +int getHeaderHeightInPixels () { checkWidget (); if (!OS.gtk_tree_view_get_headers_visible (handle)) return 0; if (columnCount > 0) { @@ -1508,7 +1537,7 @@ public TreeItem getItem (Point point) { int x = point.x; int y = point.y; if (getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) { - y -= getHeaderHeight(); + y -= getHeaderHeightInPixels(); } if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x; long /*int*/ [] columnHandle = new long /*int*/ [1]; @@ -1566,6 +1595,22 @@ public int getItemCount () { * </ul> */ public int getItemHeight () { + return DPIUtil.autoScaleDown (getItemHeightInPixels ()); +} + +/** + * Returns the height of the area which would be used to + * display <em>one</em> of the items in the tree. + * + * @return the height of one item + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +int getItemHeightInPixels () { checkWidget (); int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, 0); if (itemCount == 0) { @@ -2624,7 +2669,7 @@ void sendMeasureEvent (long /*int*/ cell, long /*int*/ width, long /*int*/ heigh Image image = item.getImage (columnIndex); int imageWidth = 0; if (image != null) { - Rectangle bounds = image.getBounds (); + Rectangle bounds = image.getBoundsInPixels (); imageWidth = bounds.width; } contentWidth [0] += imageWidth; @@ -2634,8 +2679,8 @@ void sendMeasureEvent (long /*int*/ cell, long /*int*/ width, long /*int*/ heigh event.item = item; event.index = columnIndex; event.gc = gc; - event.width = contentWidth [0]; - event.height = contentHeight [0]; + Rectangle eventRect = new Rectangle (0, 0, contentWidth [0], contentHeight [0]); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); long /*int*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); long /*int*/ selection = OS.gtk_tree_view_get_selection (handle); if (OS.gtk_tree_selection_path_is_selected (selection, path)) { @@ -2644,8 +2689,9 @@ void sendMeasureEvent (long /*int*/ cell, long /*int*/ width, long /*int*/ heigh OS.gtk_tree_path_free (path); sendEvent (SWT.MeasureItem, event); gc.dispose (); - contentWidth [0] = event.width - imageWidth; - if (contentHeight [0] < event.height) contentHeight [0] = event.height; + Rectangle rect = DPIUtil.autoScaleUp (event.getBounds ()); + contentWidth [0] = rect.width - imageWidth; + if (contentHeight [0] < rect.height) contentHeight [0] = rect.height; if (width != 0) OS.memmove (width, contentWidth, 4); if (height != 0) OS.memmove (height, contentHeight, 4); if (OS.GTK3) { @@ -2784,21 +2830,19 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo if (OS.GTK_VERSION >= OS.VERSION(3, 9, 0) && cr != 0) { GdkRectangle r = new GdkRectangle(); OS.gdk_cairo_get_clip_rectangle(cr, r); - gc.setClipping(rect.x, r.y, r.width, r.height); + gc.setClipping(DPIUtil.autoScaleDown(new Rectangle(rect.x, r.y, r.width, r.height))); if (OS.GTK_VERSION <= OS.VERSION(3, 14, 8)) { rect.width = r.width; } } else { - gc.setClipping (rect.x, rect.y, rect.width, rect.height); + gc.setClipping(DPIUtil.autoScaleDown(new Rectangle(rect.x, rect.y, rect.width, rect.height))); } Event event = new Event (); event.item = item; event.index = columnIndex; event.gc = gc; - event.x = rect.x; - event.y = rect.y; - event.width = rect.width; - event.height = rect.height; + Rectangle eventRect = new Rectangle (rect.x, rect.y, rect.width, rect.height); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); event.detail = drawState; sendEvent (SWT.EraseItem, event); drawForeground = null; @@ -2826,7 +2870,7 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo gc.setBackground (item.getBackground (columnIndex)); GdkRectangle rect = new GdkRectangle (); OS.memmove (rect, background_area, GdkRectangle.sizeof); - gc.fillRectangle (rect.x, rect.y, rect.width, rect.height); + gc.fillRectangle(DPIUtil.autoScaleDown(new Rectangle(rect.x, rect.y, rect.width, rect.height))); gc.dispose (); } if ((drawState & SWT.FOREGROUND) != 0 || OS.GTK_IS_CELL_RENDERER_TOGGLE (cell)) { @@ -2864,7 +2908,7 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo Image image = item.getImage (columnIndex); int imageWidth = 0; if (image != null) { - Rectangle bounds = image.getBounds (); + Rectangle bounds = image.getBoundsInPixels (); imageWidth = bounds.width; } // On gtk >3.9 and <3.14.8 the clip rectangle does not have image area into clip rectangle @@ -2902,16 +2946,14 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo rect.x = getClientWidth () - rect.width - rect.x; } - gc.setClipping (rect.x, rect.y, rect.width, rect.height); + gc.setClipping(DPIUtil.autoScaleDown(new Rectangle(rect.x, rect.y, rect.width, rect.height))); Event event = new Event (); event.item = item; event.index = columnIndex; event.gc = gc; - event.x = rect.x + contentX [0]; - event.y = rect.y; - event.width = contentWidth [0]; - event.height = rect.height; + Rectangle eventRect = new Rectangle (rect.x + contentX [0], rect.y, contentWidth [0], rect.height); + event.setBounds (DPIUtil.autoScaleDown (eventRect)); event.detail = drawState; sendEvent(SWT.PaintItem, event); gc.dispose(); @@ -2993,7 +3035,7 @@ public void setInsertMark (TreeItem item, boolean before) { } if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); if (item.parent != this) return; - Rectangle rect = item.getBounds(); + Rectangle rect = item.getBoundsInPixels(); long /*int*/ [] path = new long /*int*/ [1]; OS.gtk_widget_realize (handle); if (!OS.gtk_tree_view_get_path_at_pos(handle, rect.x, rect.y, path, null, null, null)) return; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java index 4457e6b916..f7f8ae0d77 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,10 +12,10 @@ package org.eclipse.swt.widgets; import org.eclipse.swt.*; +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; /** * Instances of this class represent a column in a tree widget. @@ -322,6 +322,21 @@ public String getToolTipText () { * </ul> */ public int getWidth () { + return DPIUtil.autoScaleDown (getWidthInPixels ()); +} + +/** + * Gets the width of the receiver. + * + * @return the width + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +int getWidthInPixels () { checkWidget(); if (!OS.gtk_tree_view_column_get_visible (handle)) { return 0; @@ -449,7 +464,7 @@ public void pack () { } OS.g_free (iter); } - setWidth(width); + setWidthInPixels(width); } @Override @@ -689,6 +704,21 @@ void setToolTipText (Shell shell, String newString) { * </ul> */ public void setWidth (int width) { + setWidthInPixels (DPIUtil.autoScaleUp (width)); +} + +/** + * Sets the width of the receiver. + * + * @param width the new width + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +void setWidthInPixels (int width) { checkWidget(); if (width < 0) return; if (width == lastWidth) return; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java index dcc5701020..8546f1b268 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -422,6 +422,24 @@ public Color getBackground (int index) { * @since 3.1 */ public Rectangle getBounds (int index) { + return DPIUtil.autoScaleDown (getBoundsInPixels (index)); +} + +/** + * Returns a rectangle describing the receiver's size and location + * relative to its parent at a column in the tree. + * + * @param index the index that specifies the column + * @return the receiver's bounding column rectangle + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +Rectangle getBoundsInPixels (int index) { // TODO fully test on early and later versions of GTK checkWidget(); if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); @@ -450,7 +468,7 @@ public Rectangle getBounds (int index) { int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; Rectangle r = new Rectangle (rect.x, rect.y, width, rect.height + 1); if (parent.getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) { - r.y += parent.getHeaderHeight(); + r.y += parent.getHeaderHeightInPixels(); } return r; } @@ -467,6 +485,21 @@ public Rectangle getBounds (int index) { * </ul> */ public Rectangle getBounds () { + return DPIUtil.autoScaleDown (getBoundsInPixels ()); +} +/** + * Returns a rectangle describing the size and location of the receiver's + * text relative to its parent. + * + * @return the bounding rectangle of the receiver's text + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @since 3.105 + */ +Rectangle getBoundsInPixels () { // TODO fully test on early and later versions of GTK // shifted a bit too far right on later versions of GTK - however, old Tree also had this problem checkWidget (); @@ -512,7 +545,7 @@ public Rectangle getBounds () { int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; Rectangle r = new Rectangle (rect.x, rect.y, width, rect.height + 1); if (parent.getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) { - r.y += parent.getHeaderHeight(); + r.y += parent.getHeaderHeightInPixels(); } return r; } @@ -701,6 +734,24 @@ public Image getImage (int index) { * @since 3.1 */ public Rectangle getImageBounds (int index) { + return DPIUtil.autoScaleDown(getImageBoundsInPixels(index)); +} +/** + * Returns a rectangle describing the size and location + * relative to its parent of an image at a column in the + * tree. + * + * @param index the index that specifies the column + * @return the receiver's bounding image rectangle + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +Rectangle getImageBoundsInPixels (int index) { // TODO fully test on early and later versions of GTK checkWidget (); if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); @@ -910,6 +961,25 @@ public String getText (int index) { * @since 3.3 */ public Rectangle getTextBounds (int index) { + return DPIUtil.autoScaleDown(getTextBoundsInPixels(index)); +} + +/** + * Returns a rectangle describing the size and location + * relative to its parent of the text at a column in the + * tree. + * + * @param index the index that specifies the column + * @return the receiver's bounding text rectangle + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 3.105 + */ +Rectangle getTextBoundsInPixels (int index) { checkWidget (); if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); int count = Math.max (1, parent.getColumnCount ()); @@ -958,7 +1028,7 @@ public Rectangle getTextBounds (int index) { Image image = _getImage(index); int imageWidth = 0; if (image != null) { - imageWidth = image.getBounds ().width; + imageWidth = image.getBoundsInPixels ().width; } if (x [0] < imageWidth) { rect.x += imageWidth; @@ -1492,8 +1562,8 @@ public void setImage (int index, Image image) { OS.gtk_cell_renderer_get_fixed_size (pixbufRenderer, currentWidth, currentHeight); if (!parent.pixbufSizeSet) { if (image != null) { - int iWidth = image.getBounds ().width; - int iHeight = image.getBounds ().height; + int iWidth = image.getBoundsInPixels ().width; + int iHeight = image.getBoundsInPixels ().height; if (iWidth > currentWidth [0] || iHeight > currentHeight [0]) { OS.gtk_cell_renderer_set_fixed_size (pixbufRenderer, iWidth, iHeight); parent.pixbufSizeSet = true; @@ -1525,7 +1595,7 @@ public void setImage (int index, Image image) { int [] w = new int [1]; long /*int*/ pixbufRenderer = parent.getPixbufRenderer(column); OS.gtk_tree_view_column_cell_get_position (column, pixbufRenderer, null, w); - if (w[0] < image.getBounds().width) { + if (w[0] < image.getBoundsInPixels().width) { /* * There is no direct way to clear the cell renderer width so we * are relying on the fact that it is done as part of modifying diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java index 801445c904..07e7f54ce3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1352,7 +1352,9 @@ void sendEvent (int eventType, Event event, boolean send) { if (eventTable == null && !display.filters (eventType)) { return; } - if (event == null) event = new Event (); + if (event == null) { + event = new Event(); + } event.type = eventType; event.display = display; event.widget = this; diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet367.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet367.java index 3b807a808f..5d5d4f3700 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet367.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet367.java @@ -12,6 +12,7 @@ package org.eclipse.swt.snippets; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; @@ -32,6 +33,7 @@ public class Snippet367 { private static final String IMAGE_PATH_150 = IMAGES_ROOT + IMAGE_150; private static final String IMAGE_PATH_200 = IMAGES_ROOT + IMAGE_200; + @SuppressWarnings("restriction") public static void main (String [] args) { final ImageFileNameProvider filenameProvider = zoom -> { switch (zoom) { @@ -157,7 +159,7 @@ public class Snippet367 { new Label (shell, SWT.NONE).setText ("5. 50x50 box\n(Display#getDPI(): " + display.getDPI().x + ")"); Label box= new Label (shell, SWT.NONE); box.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); - box.setLayoutData (new GridData (50, 50)); + box.setLayoutData (new GridData (DPIUtil.autoScaleDown(50), DPIUtil.autoScaleDown(50))); shell.pack (); shell.open (); diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java index 6e69e0bfcd..6c6dbdf1c1 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_GC.java @@ -139,11 +139,11 @@ public void test_copyAreaIIIIII() { PaletteData palette = imageData.palette; int pixel = imageData.getPixel(destX + 4, destY); assertEquals(":a:", whiteRGB, palette.getRGB(pixel)); - pixel = imageData.getPixel(destX + 5, destY); + pixel = imageData.getPixel(destX + 6 , destY); assertEquals(":b:", blueRGB, palette.getRGB(pixel)); pixel = imageData.getPixel(destX + 10, destY); assertEquals(":c:", blueRGB, palette.getRGB(pixel)); - pixel = imageData.getPixel(destX + 11, destY); + pixel = imageData.getPixel(destX + 12, destY); assertEquals(":d:", whiteRGB, palette.getRGB(pixel)); } diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Region.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Region.java index 0dc9fcb37f..078e94527f 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Region.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Region.java @@ -382,11 +382,11 @@ public void test_hashCode() { @Test public void test_intersectLorg_eclipse_swt_graphics_Rectangle() { - Rectangle rect1 = new Rectangle(0,0,50,25); - Rectangle rect2 = new Rectangle(0,0,50,25); + Rectangle rect1 = new Rectangle(0,0,48,24); + Rectangle rect2 = new Rectangle(0,0,48,24); Rectangle rect3 = new Rectangle(10,10,10,10); - Rectangle rect4 = new Rectangle(50,25,10,10); - Rectangle rect5 = new Rectangle(25,20,25,10); + Rectangle rect4 = new Rectangle(48,24,10,10); + Rectangle rect5 = new Rectangle(24,20,24,10); Region reg = new Region(display); reg.dispose(); @@ -435,7 +435,7 @@ public void test_intersectLorg_eclipse_swt_graphics_Rectangle() { reg.add(rect4); reg.intersect(rect5); box = reg.getBounds(); - if (!box.equals(new Rectangle(25,20,25,5))) { + if (!box.equals(new Rectangle(24,20,24,4))) { reg.dispose(); fail("intersect failed 5"); } @@ -446,7 +446,7 @@ public void test_intersectLorg_eclipse_swt_graphics_Rectangle() { public void test_intersectLorg_eclipse_swt_graphics_Region() { Region reg = new Region(display); Region reg1 = new Region(display); - reg1.add(new Rectangle(0,0,50,25)); + reg1.add(new Rectangle(0,0,48,24)); reg.dispose(); try { @@ -466,7 +466,7 @@ public void test_intersectLorg_eclipse_swt_graphics_Region() { } Region reg2 = new Region(display); - reg2.add(new Rectangle(0,0,50,25)); + reg2.add(new Rectangle(0,0,48,24)); reg.add(reg1); reg.intersect(reg2); @@ -493,7 +493,7 @@ public void test_intersectLorg_eclipse_swt_graphics_Region() { reg3.dispose(); Region reg4 = new Region(display); - reg4.add(new Rectangle(50,25,10,10)); + reg4.add(new Rectangle(48,24,10,10)); reg.intersect(reg4); if (!reg.isEmpty()) { @@ -504,7 +504,7 @@ public void test_intersectLorg_eclipse_swt_graphics_Region() { } Region reg5 = new Region(display); - reg5.add(new Rectangle(25,20,25,10)); + reg5.add(new Rectangle(24,20,24,10)); reg.add(reg1.getBounds().union(reg4.getBounds())); reg.intersect(reg5); @@ -522,7 +522,7 @@ public void test_intersectLorg_eclipse_swt_graphics_Region() { reg.add(reg4); reg.intersect(reg5); box = reg.getBounds(); - if (!box.equals(new Rectangle(25,20,25,5))) { + if (!box.equals(new Rectangle(24,20,24,4))) { reg.dispose(); reg1.dispose(); reg4.dispose(); diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java index ad6e9cd480..73d2d12ddb 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java @@ -520,7 +520,7 @@ public void test_mapLorg_eclipse_swt_widgets_ControlLorg_eclipse_swt_widgets_Con result = display.map(button2, null, 0, 0); assertEquals(new Point(shellOffset.x + 200,shellOffset.y + 100), result); result = display.map(button2, null, -3, -6); - assertEquals(new Point(shellOffset.x + 197,shellOffset.y + 94), result); + assertEquals(new Point(shellOffset.x + 197, shellOffset.y + 94), result); result = display.map(button2, null, 9, 12); assertEquals(new Point(shellOffset.x + 209,shellOffset.y + 112), result); |
