diff options
author | Norbert Thiebaud <nthiebaud@gmail.com> | 2012-09-03 19:05:27 -0500 |
---|---|---|
committer | Miklos Vajna <vmiklos@suse.cz> | 2012-09-14 07:54:39 +0000 |
commit | c1c12bd160099bb4061aad814368192e396adc3d (patch) | |
tree | 90e4f8f4a84f6985e28b568c91d2414e73b92f48 /svtools | |
parent | a6754e5a09afd62ae431a279fa30be5e0506ad39 (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 'svtools')
-rw-r--r-- | svtools/inc/svtools/table/tablecontrol.hxx | 36 | ||||
-rw-r--r-- | svtools/source/table/tablecontrol.cxx | 6 | ||||
-rw-r--r-- | svtools/source/table/tablecontrol_impl.cxx | 10 | ||||
-rw-r--r-- | svtools/source/uno/svtxgridcontrol.cxx | 37 | ||||
-rwxr-xr-x | svtools/source/uno/svtxgridcontrol.hxx | 14 |
5 files changed, 94 insertions, 9 deletions
diff --git a/svtools/inc/svtools/table/tablecontrol.hxx b/svtools/inc/svtools/table/tablecontrol.hxx index 8f297ed5c963..bbf169a4e306 100644 --- a/svtools/inc/svtools/table/tablecontrol.hxx +++ b/svtools/inc/svtools/table/tablecontrol.hxx @@ -106,6 +106,42 @@ namespace svt { namespace table */ sal_Int32 GetCurrentColumn() const; + /** activates the cell at the given position + + @return + <sal_True/> if the move was successful, <FALSE/> otherwise. Usual + failure conditions include some other instance vetoing the move, + or impossibility to execute the move at all (for instance because + of invalid coordinates). + */ + bool GoTo( ColPos _nColumnPos, RowPos _nRow); + + /** moves the active cell to the given column, by keeping the active row + + @return + <sal_True/> if the move was successful, <FALSE/> otherwise. Usual + failure conditions include some other instance vetoing the move, + or impossibility to execute the move at all (for instance because + of invalid coordinates). + */ + inline bool GoToColumn( ColPos _nColumn ) + { + return GoTo( _nColumn, GetCurrentRow() ); + } + + /** moves the active cell to the given row, by keeping the active column + + @return + <sal_True/> if the move was successful, <FALSE/> otherwise. Usual + failure conditions include some other instance vetoing the move, + or impossibility to execute the move at all (for instance because + of invalid coordinates). + */ + bool GoToRow( RowPos _nRow ) + { + return GoTo( GetCurrentColumn(), _nRow ); + } + SVT_DLLPRIVATE virtual void Resize(); virtual void Select(); diff --git a/svtools/source/table/tablecontrol.cxx b/svtools/source/table/tablecontrol.cxx index 1d1129f8957f..1726ea2b0753 100644 --- a/svtools/source/table/tablecontrol.cxx +++ b/svtools/source/table/tablecontrol.cxx @@ -189,6 +189,12 @@ namespace svt { namespace table } // ----------------------------------------------------------------------------------------------------------------- + bool TableControl::GoTo( ColPos _nColumn, RowPos _nRow ) + { + return m_pImpl->goTo( _nColumn, _nRow ); + } + + // ----------------------------------------------------------------------------------------------------------------- sal_Bool TableControl::GoToCell(sal_Int32 _nColPos, sal_Int32 _nRowPos) { return m_pImpl->goTo( _nColPos, _nRowPos ); diff --git a/svtools/source/table/tablecontrol_impl.cxx b/svtools/source/table/tablecontrol_impl.cxx index aca789e97ad1..17bf7716a64d 100644 --- a/svtools/source/table/tablecontrol_impl.cxx +++ b/svtools/source/table/tablecontrol_impl.cxx @@ -651,6 +651,16 @@ namespace svt { namespace table void TableControl_Impl::columnRemoved( ColPos const i_colIndex ) { m_nColumnCount = m_pModel->getColumnCount(); + + // adjust the current column, if it is larger than the column count now + if ( m_nCurColumn >= m_nColumnCount ) + { + if ( m_nColumnCount > 0 ) + goTo( m_nCurColumn - 1, m_nCurRow ); + else + m_nCurColumn = COL_INVALID; + } + impl_ni_relayout(); m_rAntiImpl.Invalidate(); diff --git a/svtools/source/uno/svtxgridcontrol.cxx b/svtools/source/uno/svtxgridcontrol.cxx index df19233354d8..67a778b38222 100644 --- a/svtools/source/uno/svtxgridcontrol.cxx +++ b/svtools/source/uno/svtxgridcontrol.cxx @@ -76,12 +76,13 @@ using ::com::sun::star::awt::grid::XGridColumn; using ::com::sun::star::container::ContainerEvent; using ::com::sun::star::awt::grid::GridDataEvent; using ::com::sun::star::awt::grid::GridInvalidModelException; +using ::com::sun::star::util::VetoException; /** === end UNO using === **/ namespace AccessibleEventId = ::com::sun::star::accessibility::AccessibleEventId; namespace AccessibleStateType = ::com::sun::star::accessibility::AccessibleStateType; -using ::svt::table::TableControl; +using namespace ::svt::table; typedef ::com::sun::star::util::Color UnoColor; @@ -106,6 +107,20 @@ void SVTXGridControl::SetWindow( Window* pWindow ) } // --------------------------------------------------------------------------------------------------------------------- +void SVTXGridControl::impl_checkColumnIndex_throw( ::svt::table::TableControl const & i_table, sal_Int32 const i_columnIndex ) const +{ + if ( ( i_columnIndex < 0 ) || ( i_columnIndex >= i_table.GetColumnCount() ) ) + throw IndexOutOfBoundsException( ::rtl::OUString(), *const_cast< SVTXGridControl* >( this ) ); +} + +// --------------------------------------------------------------------------------------------------------------------- +void SVTXGridControl::impl_checkRowIndex_throw( ::svt::table::TableControl const & i_table, sal_Int32 const i_rowIndex ) const +{ + if ( ( i_rowIndex < 0 ) || ( i_rowIndex >= i_table.GetRowCount() ) ) + throw IndexOutOfBoundsException( ::rtl::OUString(), *const_cast< SVTXGridControl* >( this ) ); +} + +// --------------------------------------------------------------------------------------------------------------------- sal_Int32 SAL_CALL SVTXGridControl::getRowAtPoint(::sal_Int32 x, ::sal_Int32 y) throw (RuntimeException) { SolarMutexGuard aGuard; @@ -153,6 +168,20 @@ sal_Int32 SAL_CALL SVTXGridControl::getCurrentRow( ) throw (RuntimeException) return ( nRow >= 0 ) ? nRow : -1; } +//---------------------------------------------------------------------------------------------------------------------- +void SAL_CALL SVTXGridControl::goToCell( ::sal_Int32 i_columnIndex, ::sal_Int32 i_rowIndex ) throw (RuntimeException, IndexOutOfBoundsException, VetoException) +{ + SolarMutexGuard aGuard; + + TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); + ENSURE_OR_RETURN_VOID( pTable != NULL, "SVTXGridControl::getCurrentRow: no control (anymore)!" ); + + impl_checkColumnIndex_throw( *pTable, i_columnIndex ); + impl_checkRowIndex_throw( *pTable, i_rowIndex ); + + pTable->GoTo( i_columnIndex, i_rowIndex ); +} + // --------------------------------------------------------------------------------------------------------------------- void SAL_CALL SVTXGridControl::addSelectionListener(const Reference< XGridSelectionListener > & listener) throw (RuntimeException) { @@ -671,8 +700,7 @@ void SAL_CALL SVTXGridControl::selectRow( ::sal_Int32 i_rowIndex ) throw (Runtim TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::selectRow: no control (anymore)!" ); - if ( ( i_rowIndex < 0 ) || ( i_rowIndex >= pTable->GetRowCount() ) ) - throw IndexOutOfBoundsException( ::rtl::OUString(), *this ); + impl_checkRowIndex_throw( *pTable, i_rowIndex ); pTable->SelectRow( i_rowIndex, true ); } @@ -696,8 +724,7 @@ void SAL_CALL SVTXGridControl::deselectRow( ::sal_Int32 i_rowIndex ) throw (Runt TableControl* pTable = dynamic_cast< TableControl* >( GetWindow() ); ENSURE_OR_RETURN_VOID( pTable, "SVTXGridControl::deselectRow: no control (anymore)!" ); - if ( ( i_rowIndex < 0 ) || ( i_rowIndex >= pTable->GetRowCount() ) ) - throw IndexOutOfBoundsException( ::rtl::OUString(), *this ); + impl_checkRowIndex_throw( *pTable, i_rowIndex ); pTable->SelectRow( i_rowIndex, false ); } diff --git a/svtools/source/uno/svtxgridcontrol.hxx b/svtools/source/uno/svtxgridcontrol.hxx index 945b556dfa72..22c3c454ca48 100755 --- a/svtools/source/uno/svtxgridcontrol.hxx +++ b/svtools/source/uno/svtxgridcontrol.hxx @@ -47,7 +47,9 @@ #include <toolkit/helper/listenermultiplexer.hxx> -using namespace ::svt::table; +namespace svt { namespace table { + class TableControl; +} } typedef ::cppu::ImplInheritanceHelper4 < VCLXWindow , ::com::sun::star::awt::grid::XGridControl @@ -58,9 +60,9 @@ typedef ::cppu::ImplInheritanceHelper4 < VCLXWindow class SVTXGridControl : public SVTXGridControl_Base { private: - ::boost::shared_ptr< UnoControlTableModel > m_pTableModel; - bool m_bTableModelInitCompleted; - SelectionListenerMultiplexer m_aSelectionListeners; + ::boost::shared_ptr< ::svt::table::UnoControlTableModel > m_pTableModel; + bool m_bTableModelInitCompleted; + SelectionListenerMultiplexer m_aSelectionListeners; protected: virtual void ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ); @@ -89,6 +91,7 @@ public: virtual ::sal_Int32 SAL_CALL getColumnAtPoint(::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); // XGridRowSelection virtual void SAL_CALL selectRow( ::sal_Int32 i_rowIndex ) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IndexOutOfBoundsException ); @@ -114,6 +117,9 @@ protected: private: void impl_updateColumnsFromModel_nothrow(); void impl_checkTableModelInit(); + + void impl_checkColumnIndex_throw( ::svt::table::TableControl const & i_table, sal_Int32 const i_columnIndex ) const; + void impl_checkRowIndex_throw( ::svt::table::TableControl const & i_table, sal_Int32 const i_rowIndex ) const; }; #endif // _SVT_GRIDCONTROL_HXX_ |