Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXi Yan2018-06-12 15:34:22 +0000
committerXi Yan2018-06-12 18:04:00 +0000
commit394f4e7e26c263b24531e4e9007b110e0f35929d (patch)
treea24ddc53b7ce952f4ab2314fc894dda2f9e2ed06
parenta5612364d1fa3182b7ff9b1b022c78385ee383ae (diff)
downloadeclipse.platform.swt-394f4e7e26c263b24531e4e9007b110e0f35929d.tar.gz
eclipse.platform.swt-394f4e7e26c263b24531e4e9007b110e0f35929d.tar.xz
eclipse.platform.swt-394f4e7e26c263b24531e4e9007b110e0f35929d.zip
Bug 305864 - [GTK] getItemHeight method of org.eclipse.swt.widgets.List
returns a wrong Item height Added padding of cell when calculating item height in getItemHeight method of List, Table, and Tree for GTK3. Change-Id: I59c7163f46e2df3a31958ba9235038de7e58280f Signed-off-by: Xi Yan <xixiyan@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c17
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java14
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java13
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java11
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java11
-rw-r--r--tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug305864_ListItemHeight.java137
8 files changed, 199 insertions, 6 deletions
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 cd4875fa87..5145a2d507 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
@@ -4846,6 +4846,23 @@ fail:
}
#endif
+#ifndef NO__1gtk_1cell_1renderer_1get_1padding
+JNIEXPORT void JNICALL GTK_NATIVE(_1gtk_1cell_1renderer_1get_1padding)
+ (JNIEnv *env, jclass that, jintLong arg0, jintArray arg1, jintArray arg2)
+{
+ jint *lparg1=NULL;
+ jint *lparg2=NULL;
+ GTK_NATIVE_ENTER(env, that, _1gtk_1cell_1renderer_1get_1padding_FUNC);
+ if (arg1) if ((lparg1 = (*env)->GetIntArrayElements(env, arg1, NULL)) == NULL) goto fail;
+ if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail;
+ gtk_cell_renderer_get_padding((GtkCellRenderer *)arg0, (gint *)lparg1, (gint *)lparg2);
+fail:
+ if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0);
+ if (arg1 && lparg1) (*env)->ReleaseIntArrayElements(env, arg1, lparg1, 0);
+ GTK_NATIVE_EXIT(env, that, _1gtk_1cell_1renderer_1get_1padding_FUNC);
+}
+#endif
+
#ifndef NO__1gtk_1cell_1renderer_1get_1preferred_1height_1for_1width
JNIEXPORT void JNICALL GTK_NATIVE(_1gtk_1cell_1renderer_1get_1preferred_1height_1for_1width)
(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jint arg2, jintArray arg3, jintArray arg4)
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 c4c943401b..967e5ef5fe 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
@@ -370,6 +370,7 @@ char * GTK_nativeFunctionNames[] = {
"_1gtk_1cell_1layout_1pack_1start",
"_1gtk_1cell_1layout_1set_1attributes",
"_1gtk_1cell_1renderer_1get_1fixed_1size",
+ "_1gtk_1cell_1renderer_1get_1padding",
"_1gtk_1cell_1renderer_1get_1preferred_1height_1for_1width",
"_1gtk_1cell_1renderer_1get_1preferred_1size",
"_1gtk_1cell_1renderer_1get_1size",
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 9bd4eb22c9..a9dfc1f899 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
@@ -368,6 +368,7 @@ typedef enum {
_1gtk_1cell_1layout_1pack_1start_FUNC,
_1gtk_1cell_1layout_1set_1attributes_FUNC,
_1gtk_1cell_1renderer_1get_1fixed_1size_FUNC,
+ _1gtk_1cell_1renderer_1get_1padding_FUNC,
_1gtk_1cell_1renderer_1get_1preferred_1height_1for_1width_FUNC,
_1gtk_1cell_1renderer_1get_1preferred_1size_FUNC,
_1gtk_1cell_1renderer_1get_1size_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
index 855d78da93..be9272fa69 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
@@ -1082,6 +1082,20 @@ public class GTK extends OS {
}
}
/**
+ * @param cell cast=(GtkCellRenderer *)
+ * @param xpad cast=(gint *)
+ * @param ypad cast=(gint *)
+ */
+ public static final native void _gtk_cell_renderer_get_padding(long /*int*/ cell, int [] xpad, int [] ypad);
+ public static final void gtk_cell_renderer_get_padding(long /*int*/ cell, int [] xpad, int [] ypad) {
+ lock.lock();
+ try {
+ _gtk_cell_renderer_get_padding(cell, xpad, ypad);
+ } finally {
+ lock.unlock();
+ }
+ }
+ /**
* @method flags=dynamic
* @param cell cast=(GtkCellRenderer *)
*/
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 34aa82efa3..af893d3e15 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
@@ -552,18 +552,27 @@ int getItemHeightInPixels () {
int height = h [0];
if (GTK.GTK3) {
long /*int*/ textRenderer = getTextRenderer (column);
- GTK.gtk_cell_renderer_get_preferred_height_for_width (textRenderer, handle, 0, h, null);
+ if (textRenderer != 0) GTK.gtk_cell_renderer_get_preferred_height_for_width (textRenderer, handle, 0, h, null);
height += h [0];
}
return height;
} else {
+ int height = 0;
long /*int*/ iter = OS.g_malloc (GTK.GtkTreeIter_sizeof ());
GTK.gtk_tree_model_get_iter_first (modelHandle, iter);
GTK.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false);
int [] w = new int [1], h = new int [1];
GTK.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h);
+ if (GTK.GTK3) {
+ long /*int*/ textRenderer = getTextRenderer (column);
+ int [] ypad = new int[1];
+ if (textRenderer != 0) GTK.gtk_cell_renderer_get_padding(textRenderer, null, ypad);
+ height = h [0] + ypad [0];
+ } else {
+ height = h [0];
+ }
OS.g_free (iter);
- return h [0];
+ return height;
}
}
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 bc65f91694..f532ca6746 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
@@ -1704,7 +1704,7 @@ int getItemHeightInPixels () {
int height = h [0];
if (GTK.GTK3) {
long /*int*/ textRenderer = getTextRenderer (column);
- GTK.gtk_cell_renderer_get_preferred_height_for_width (textRenderer, handle, 0, h, null);
+ if (textRenderer != 0) GTK.gtk_cell_renderer_get_preferred_height_for_width (textRenderer, handle, 0, h, null);
height += h [0];
}
ignoreSize = false;
@@ -1719,7 +1719,14 @@ int getItemHeightInPixels () {
GTK.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false);
int [] w = new int [1], h = new int [1];
GTK.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h);
- height = Math.max (height, h [0]);
+ if (GTK.GTK3) {
+ long /*int*/ textRenderer = getTextRenderer (column);
+ int [] ypad = new int[1];
+ if (textRenderer != 0) GTK.gtk_cell_renderer_get_padding(textRenderer, null, ypad);
+ height = Math.max(height, h [0] + ypad [0]);
+ } else {
+ height = Math.max (height, h [0]);
+ }
}
OS.g_free (iter);
return 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 04be6d1a34..7865e488fb 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
@@ -1722,7 +1722,7 @@ int getItemHeightInPixels () {
int height = h [0];
if (GTK.GTK3) {
long /*int*/ textRenderer = getTextRenderer (column);
- GTK.gtk_cell_renderer_get_preferred_height_for_width (textRenderer, handle, 0, h, null);
+ if (textRenderer != 0) GTK.gtk_cell_renderer_get_preferred_height_for_width (textRenderer, handle, 0, h, null);
height += h [0];
}
ignoreSize = false;
@@ -1737,7 +1737,14 @@ int getItemHeightInPixels () {
GTK.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false);
int [] w = new int [1], h = new int [1];
GTK.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h);
- height = Math.max (height, h [0]);
+ if (GTK.GTK3) {
+ long /*int*/ textRenderer = getTextRenderer(column);
+ int [] ypad = new int[1];
+ if (textRenderer != 0) GTK.gtk_cell_renderer_get_padding(textRenderer, null, ypad);
+ height = Math.max(height, h [0] + ypad [0]);
+ } else {
+ height = Math.max (height, h [0]);
+ }
}
OS.g_free (iter);
return height;
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug305864_ListItemHeight.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug305864_ListItemHeight.java
new file mode 100644
index 0000000000..c50b04933a
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug305864_ListItemHeight.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Red Hat 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:
+ * Red Hat - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+
+public class Bug305864_ListItemHeight {
+
+ public static void main(String[] args) {
+ testTree();
+ testList();
+ testTable();
+ }
+
+ private static void testTree() {
+ final Display display = new Display();
+ final Shell shell = new Shell(display);
+ FillLayout layout = new FillLayout(SWT.VERTICAL);
+ shell.setLayout(layout);
+
+ final Tree tree = new Tree(shell, SWT.BORDER);
+
+ for (int i=0; i<32; i++) {
+ TreeItem iItem = new TreeItem (tree, 0);
+ iItem.setText ("TreeItem (1) -" + (i+1));
+ for (int j=0; j<4; j++) {
+ TreeItem jItem = new TreeItem (iItem, 0);
+ jItem.setText ("TreeItem (2) -" + (j+1));
+ for (int k=0; k<4; k++) {
+ TreeItem kItem = new TreeItem (jItem, 0);
+ kItem.setText ("TreeItem (3) -" + (k+1));
+ for (int l=0; l<4; l++) {
+ TreeItem lItem = new TreeItem (kItem, 0);
+ lItem.setText ("TreeItem (4) -" + (l+1));
+ }
+ }
+ }
+ }
+
+ final Button button = new Button (shell, SWT.PUSH);
+ button.setText("Visible Items []");
+ button.addListener(SWT.Selection, e -> {
+ Rectangle rect = tree.getClientArea();
+ int itemHeight = tree.getItemHeight();
+ double visibleCount = ((double) rect.height) / itemHeight;
+ button.setText("Visible Items [" + Math.round(visibleCount) + "]");
+ });
+ shell.setSize(200, 250);
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ display.dispose();
+
+
+ }
+ private static void testList() {
+ final Display display = new Display();
+ final Shell shell = new Shell(display);
+ FillLayout layout = new FillLayout(SWT.VERTICAL);
+ shell.setLayout(layout);
+
+ final List list = new List(shell, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL);
+ list.setData("name", "list");
+
+ for (int i = 0; i < 100; i++) {
+ list.add("Item " + (i + 1) + " is quite long");
+ }
+
+ final Button button = new Button (shell, SWT.PUSH);
+ button.setText("Visible Items []");
+ button.addListener(SWT.Selection, e -> {
+ Rectangle rect = list.getClientArea();
+ int itemHeight = list.getItemHeight();
+ double visibleCount = ((double) rect.height) / itemHeight;
+ button.setText("Visible Items [" + Math.round(visibleCount) + "]");
+ });
+ shell.setSize(200, 250);
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ display.dispose();
+ }
+
+ private static void testTable() {
+ final Display display = new Display();
+ final Shell shell = new Shell(display);
+ FillLayout layout = new FillLayout(SWT.VERTICAL);
+ shell.setLayout(layout);
+ final Table table = new Table(shell, SWT.NONE);
+ for (int i = 0; i < 32; i++) {
+ TableItem item = new TableItem(table, SWT.NONE);
+ item.setText("Item " + (i + 1) + " is quite long");
+ }
+ final Button button = new Button (shell, SWT.PUSH);
+ button.setText("Visible Items []");
+ button.addListener(SWT.Selection, e -> {
+ Rectangle rect = table.getClientArea();
+ int itemHeight = table.getItemHeight();
+ int headerHeight = table.getHeaderHeight();
+ double visibleCount = ((double) (rect.height - headerHeight)) / itemHeight;
+ button.setText("Visible Items [" + Math.round(visibleCount) + "]");
+ });
+ shell.setSize(200, 250);
+ shell.open();
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ display.dispose();
+ }
+
+}

Back to the top