Tree/Table#getVisibleItemCount now respects border width
402611: [Tree][Table] Wrong item bounds under some constellation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=402611
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/Table.java
index 23446e2..898df8f 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/Table.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/Table.java
@@ -2515,7 +2515,7 @@
final int getVisibleItemCount( boolean includePartlyVisible ) {
- int clientHeight = getBounds().height - getHeaderHeight() - getHScrollBarHeight();
+ int clientHeight = getClientArea().height - getHeaderHeight();
int result = 0;
if( clientHeight >= 0 ) {
int itemHeight = getItemHeight();
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/Tree.java
index 21407f9..71ac7aa 100644
--- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/Tree.java
+++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/Tree.java
@@ -2077,8 +2077,8 @@
}
}
- private int getVisibleRowCount( boolean includePartlyVisible ) {
- int clientHeight = getBounds().height - getHeaderHeight() - getHScrollBarHeight();
+ final int getVisibleRowCount( boolean includePartlyVisible ) {
+ int clientHeight = getClientArea().height - getHeaderHeight();
int result = 0;
if( clientHeight >= 0 ) {
int itemHeight = getItemHeight();
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/Table_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/Table_Test.java
index e9cab8c..c46d0f2 100644
--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/Table_Test.java
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/Table_Test.java
@@ -1907,11 +1907,12 @@
assertEquals( expected, actual );
}
- public void testGetVisibleItemCount() {
- Table table = new Table( shell, SWT.NO_SCROLL );
+ public void testGetVisibleItemCount_WithBorder() {
+ Table table = new Table( shell, SWT.NO_SCROLL | SWT.BORDER );
createTableItems( table, 10 );
int itemHeight = table.getItemHeight();
- table.setSize( 100, 5 * itemHeight );
+ int borderWidth = table.getBorderWidth();
+ table.setSize( 100, 5 * itemHeight + 2 * borderWidth );
assertEquals( 5, table.getVisibleItemCount( true ) );
assertEquals( 5, table.getVisibleItemCount( false ) );
}
@@ -1921,8 +1922,8 @@
createTableItems( table, 10 );
int itemHeight = table.getItemHeight();
table.setSize( 100, ( 5 * itemHeight ) + ( itemHeight / 2 ) );
- assertEquals( 5, table.getVisibleItemCount( false ) );
assertEquals( 6, table.getVisibleItemCount( true ) );
+ assertEquals( 5, table.getVisibleItemCount( false ) );
}
public void testGetItemHeight() throws IOException {
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/Tree_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/Tree_Test.java
index 8f8db62..5e519f2 100644
--- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/Tree_Test.java
+++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/Tree_Test.java
@@ -1854,6 +1854,34 @@
assertEquals( 100, adapter.getScrollLeft() );
}
+ public void testGetVisibleRowCount() {
+ Tree tree = new Tree( composite, SWT.NO_SCROLL );
+ createTreeItems( tree, 10 );
+ int itemHeight = tree.getItemHeight();
+ tree.setSize( 100, 5 * itemHeight );
+ assertEquals( 5, tree.getVisibleRowCount( true ) );
+ assertEquals( 5, tree.getVisibleRowCount( false ) );
+ }
+
+ public void testGetVisibleRowCount_WithBorder() {
+ Tree tree = new Tree( composite, SWT.NO_SCROLL | SWT.BORDER );
+ createTreeItems( tree, 10 );
+ int itemHeight = tree.getItemHeight();
+ int borderWidth = tree.getBorderWidth();
+ tree.setSize( 100, 5 * itemHeight + 2 * borderWidth );
+ assertEquals( 5, tree.getVisibleRowCount( true ) );
+ assertEquals( 5, tree.getVisibleRowCount( false ) );
+ }
+
+ public void testGetVisibleItemCountWithPartiallyVisibleItem() {
+ Tree tree = new Tree( composite, SWT.NO_SCROLL );
+ createTreeItems( tree, 10 );
+ int itemHeight = tree.getItemHeight();
+ tree.setSize( 100, ( 5 * itemHeight ) + ( itemHeight / 2 ) );
+ assertEquals( 6, tree.getVisibleRowCount( true ) );
+ assertEquals( 5, tree.getVisibleRowCount( false ) );
+ }
+
/////////
// Helper