summaryrefslogtreecommitdiff
path: root/toolkit
diff options
context:
space:
mode:
authorNorbert Thiebaud <nthiebaud@gmail.com>2012-09-03 19:05:27 -0500
committerMiklos Vajna <vmiklos@suse.cz>2012-09-14 07:54:39 +0000
commitc1c12bd160099bb4061aad814368192e396adc3d (patch)
tree90e4f8f4a84f6985e28b568c91d2414e73b92f48 /toolkit
parenta6754e5a09afd62ae431a279fa30be5e0506ad39 (diff)
gridfixes: ensure removal of a column in grid control adjusts the cursor
Change-Id: I99be214bf12d340cc5e9330d1c21046dd366b07a Reviewed-on: https://gerrit.libreoffice.org/554 Reviewed-by: Miklos Vajna <vmiklos@suse.cz> Tested-by: Miklos Vajna <vmiklos@suse.cz>
Diffstat (limited to 'toolkit')
-rw-r--r--toolkit/qa/complex/toolkit/GridControl.java155
-rw-r--r--toolkit/source/controls/grid/gridcontrol.cxx8
-rw-r--r--toolkit/source/controls/grid/gridcontrol.hxx1
3 files changed, 108 insertions, 56 deletions
diff --git a/toolkit/qa/complex/toolkit/GridControl.java b/toolkit/qa/complex/toolkit/GridControl.java
index 62ebdd0954f4..fc2c444226b1 100644
--- a/toolkit/qa/complex/toolkit/GridControl.java
+++ b/toolkit/qa/complex/toolkit/GridControl.java
@@ -33,6 +33,7 @@ import com.sun.star.awt.XToolkit;
import com.sun.star.awt.grid.DefaultGridDataModel;
import com.sun.star.awt.grid.XGridColumn;
import com.sun.star.awt.grid.XGridColumnModel;
+import com.sun.star.awt.grid.XGridControl;
import com.sun.star.awt.grid.XGridDataModel;
import com.sun.star.awt.grid.XMutableGridDataModel;
import com.sun.star.awt.grid.XSortableMutableGridDataModel;
@@ -59,6 +60,8 @@ import java.util.List;
import java.util.Random;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import org.openoffice.test.OfficeConnection;
@@ -432,63 +435,88 @@ public class GridControl
// -----------------------------------------------------------------------------------------------------------------
@Test
- public void testModelViewInteraction() throws Exception
+ public void testView() throws Exception
{
- final List< Object > disposables = new ArrayList< Object >();
- try
- {
- // create a simple dialog model/control/peer trinity
- final XControlModel dialogModel = createInstance( XControlModel.class, "com.sun.star.awt.UnoControlDialogModel" );
- disposables.add( dialogModel );
- final XPropertySet dialogProps = UnoRuntime.queryInterface( XPropertySet.class, dialogModel );
- dialogProps.setPropertyValue( "Width", 200 );
- dialogProps.setPropertyValue( "Height", 100 );
- dialogProps.setPropertyValue( "Title", "Grid Control Unit Test" );
- final XControl dialogControl = createInstance( XControl.class, "com.sun.star.awt.UnoControlDialog" );
- disposables.add( dialogControl );
- dialogControl.setModel( dialogModel );
- dialogControl.createPeer( createInstance( XToolkit.class, "com.sun.star.awt.Toolkit" ), null );
-
- // insert a grid control model
- final XMultiServiceFactory controlModelFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class,
- dialogModel );
- XPropertySet gridModelProps = UnoRuntime.queryInterface( XPropertySet.class,
- controlModelFactory.createInstance( "com.sun.star.awt.grid.UnoControlGridModel" ) );
- disposables.add( gridModelProps );
- gridModelProps.setPropertyValue( "PositionX", 6 );
- gridModelProps.setPropertyValue( "PositionY", 6 );
- gridModelProps.setPropertyValue( "Width", 188 );
- gridModelProps.setPropertyValue( "Height", 88 );
- final XNameContainer modelContainer = UnoRuntime.queryInterface( XNameContainer.class, dialogModel );
- modelContainer.insertByName( "grid", gridModelProps );
-
- // check the respective control has been created
- final XControlContainer controlContainer = UnoRuntime.queryInterface( XControlContainer.class, dialogControl );
- final XControl gridControl = controlContainer.getControl( "grid" );
- assertNotNull( "no grid control created in the dialog", gridControl );
-
- // in the current implementation (not sure this is a good idea at all), the control (more precise: the peer)
- // ensures that if there are no columns in the column model, but in the data model, then the column model
- // will implicitly have the needed columns added.
- // To ensure that clients which rely on this do not break in the future, check this here.
- final XMutableGridDataModel dataModel = UnoRuntime.queryInterface( XMutableGridDataModel.class,
- gridModelProps.getPropertyValue( "GridDataModel" ) );
- assertNotNull( dataModel );
- assertEquals( 0, dataModel.getColumnCount() );
-
- final XGridColumnModel columnModel = UnoRuntime.queryInterface( XGridColumnModel.class,
- gridModelProps.getPropertyValue( "ColumnModel" ) );
- assertNotNull( columnModel );
- assertEquals( 0, columnModel.getColumnCount() );
-
- dataModel.addRow( null, new Object[] { 1, 2, 3 } );
- assertEquals( 3, dataModel.getColumnCount() );
- assertEquals( 3, columnModel.getColumnCount() );
- }
- finally
- {
- impl_dispose( disposables.toArray());
- }
+ final XControl control = impl_createDialogWithGridControl();
+ final XPropertySet gridModelProps =
+ UnoRuntime.queryInterface( XPropertySet.class, control.getModel() );
+
+ // in the current implementation (not sure this is a good idea at all), the control (more precise: the peer)
+ // ensures that if there are no columns in the column model, but in the data model, then the column model
+ // will implicitly have the needed columns added.
+ // To ensure that clients which rely on this do not break in the future, check this here.
+ final XMutableGridDataModel dataModel = UnoRuntime.queryInterface( XMutableGridDataModel.class,
+ gridModelProps.getPropertyValue( "GridDataModel" ) );
+ assertNotNull( dataModel );
+ assertEquals( 0, dataModel.getColumnCount() );
+
+ final XGridColumnModel columnModel = UnoRuntime.queryInterface( XGridColumnModel.class,
+ gridModelProps.getPropertyValue( "ColumnModel" ) );
+ assertNotNull( columnModel );
+ assertEquals( 0, columnModel.getColumnCount() );
+
+ final int columnCount = 3;
+ final int rowCount = 2;
+ dataModel.addRow( null, new Object[] { 1, 2, 3 } );
+ dataModel.addRow( null, new Object[] { 6, 5, 4 } );
+
+ assertEquals( columnCount, dataModel.getColumnCount() );
+ assertEquals( columnCount, columnModel.getColumnCount() );
+
+ // some cursor traveling
+ final XGridControl gridControl = UnoRuntime.queryInterface( XGridControl.class, control );
+ gridControl.goToCell( 0, 0 );
+ assertEquals( "wrong 'current column' (1)", 0, gridControl.getCurrentColumn() );
+ assertEquals( "wrong 'current row' (1)", 0, gridControl.getCurrentRow() );
+ gridControl.goToCell( columnCount - 1, rowCount - 1 );
+ assertEquals( "wrong 'current column' (2)", dataModel.getColumnCount() - 1, gridControl.getCurrentColumn() );
+ assertEquals( "wrong 'current row' (2)", dataModel.getRowCount() - 1, gridControl.getCurrentRow() );
+
+ // removing the last column, while the active cell is in this very last column, is expected to adjust
+ // the active cell
+ columnModel.removeColumn( columnCount - 1 );
+ assertEquals( "removed the last and active column, active column was not adjusted!",
+ columnCount - 2, gridControl.getCurrentColumn() );
+ // same holds for rows
+ dataModel.removeRow( rowCount - 1 );
+ assertEquals( "removed the last and active row, active row was not adjusted!",
+ rowCount - 2, gridControl.getCurrentRow() );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ private XControl impl_createDialogWithGridControl() throws Exception
+ {
+ // create a simple dialog model/control/peer trinity
+ final XControlModel dialogModel = createInstance( XControlModel.class, "com.sun.star.awt.UnoControlDialogModel" );
+ m_disposables.add( dialogModel );
+ final XPropertySet dialogProps = UnoRuntime.queryInterface( XPropertySet.class, dialogModel );
+ dialogProps.setPropertyValue( "Width", 200 );
+ dialogProps.setPropertyValue( "Height", 100 );
+ dialogProps.setPropertyValue( "Title", "Grid Control Unit Test" );
+ final XControl dialogControl = createInstance( XControl.class, "com.sun.star.awt.UnoControlDialog" );
+ m_disposables.add( dialogControl );
+ dialogControl.setModel( dialogModel );
+ dialogControl.createPeer( createInstance( XToolkit.class, "com.sun.star.awt.Toolkit" ), null );
+
+ // insert a grid control model
+ final XMultiServiceFactory controlModelFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class,
+ dialogModel );
+ final XPropertySet gridModelProps = UnoRuntime.queryInterface( XPropertySet.class,
+ controlModelFactory.createInstance( "com.sun.star.awt.grid.UnoControlGridModel" ) );
+ m_disposables.add( gridModelProps );
+ gridModelProps.setPropertyValue( "PositionX", 6 );
+ gridModelProps.setPropertyValue( "PositionY", 6 );
+ gridModelProps.setPropertyValue( "Width", 188 );
+ gridModelProps.setPropertyValue( "Height", 88 );
+ final XNameContainer modelContainer = UnoRuntime.queryInterface( XNameContainer.class, dialogModel );
+ modelContainer.insertByName( "grid", gridModelProps );
+
+ // check the respective control has been created
+ final XControlContainer controlContainer = UnoRuntime.queryInterface( XControlContainer.class, dialogControl );
+ final XControl gridControl = controlContainer.getControl( "grid" );
+ assertNotNull( "no grid control created in the dialog", gridControl );
+
+ return gridControl;
}
// -----------------------------------------------------------------------------------------------------------------
@@ -583,6 +611,20 @@ public class GridControl
}
// -----------------------------------------------------------------------------------------------------------------
+ @Before
+ public void initTestCase()
+ {
+ m_disposables.clear();
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ @After
+ public void cleanupTestCase()
+ {
+ impl_dispose( m_disposables.toArray() );
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
@BeforeClass
public static void setUpConnection() throws java.lang.Exception
{
@@ -709,4 +751,5 @@ public class GridControl
private XPropertySet m_gridControlModel;
private XGridColumnModel m_columnModel;
private XSortableMutableGridDataModel m_dataModel;
+ private final List< Object > m_disposables = new ArrayList< Object >();
}
diff --git a/toolkit/source/controls/grid/gridcontrol.cxx b/toolkit/source/controls/grid/gridcontrol.cxx
index fdd33ff82c08..7efcbb10d0c2 100644
--- a/toolkit/source/controls/grid/gridcontrol.cxx
+++ b/toolkit/source/controls/grid/gridcontrol.cxx
@@ -53,6 +53,7 @@ using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::view;
+using namespace ::com::sun::star::util;
namespace toolkit
{
@@ -393,6 +394,13 @@ sal_Bool SAL_CALL UnoGridControl::setModel( const Reference< XControlModel >& i_
}
//----------------------------------------------------------------------------------------------------------------------
+void SAL_CALL UnoGridControl::goToCell( ::sal_Int32 i_columnIndex, ::sal_Int32 i_rowIndex ) throw (RuntimeException, IndexOutOfBoundsException, VetoException)
+{
+ Reference< XGridControl > const xGrid ( getPeer(), UNO_QUERY_THROW );
+ xGrid->goToCell( i_columnIndex, i_rowIndex );
+}
+
+//----------------------------------------------------------------------------------------------------------------------
void SAL_CALL UnoGridControl::selectRow( ::sal_Int32 i_rowIndex ) throw (RuntimeException, IndexOutOfBoundsException )
{
Reference< XGridRowSelection >( getPeer(), UNO_QUERY_THROW )->selectRow( i_rowIndex );
diff --git a/toolkit/source/controls/grid/gridcontrol.hxx b/toolkit/source/controls/grid/gridcontrol.hxx
index 450e248a3977..f5088b1357e5 100644
--- a/toolkit/source/controls/grid/gridcontrol.hxx
+++ b/toolkit/source/controls/grid/gridcontrol.hxx
@@ -103,6 +103,7 @@ public:
virtual ::sal_Int32 SAL_CALL getRowAtPoint(::sal_Int32 x, ::sal_Int32 y) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int32 SAL_CALL getCurrentColumn( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Int32 SAL_CALL getCurrentRow( ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL goToCell( ::sal_Int32 i_columnIndex, ::sal_Int32 i_rowIndex ) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::util::VetoException);
// ::com::sun::star::awt::grid::XGridRowSelection
virtual void SAL_CALL selectRow( ::sal_Int32 i_rowIndex ) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IndexOutOfBoundsException );