1*50e6b072SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*50e6b072SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*50e6b072SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*50e6b072SAndrew Rist * distributed with this work for additional information 6*50e6b072SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*50e6b072SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*50e6b072SAndrew Rist * "License"); you may not use this file except in compliance 9*50e6b072SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*50e6b072SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*50e6b072SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*50e6b072SAndrew Rist * software distributed under the License is distributed on an 15*50e6b072SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*50e6b072SAndrew Rist * KIND, either express or implied. See the License for the 17*50e6b072SAndrew Rist * specific language governing permissions and limitations 18*50e6b072SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*50e6b072SAndrew Rist *************************************************************/ 21*50e6b072SAndrew Rist 22*50e6b072SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <com/sun/star/awt/grid/XMutableGridDataModel.hpp> 25cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx> 28cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx> 29cdf0e10cSrcweir #include <toolkit/helper/mutexandbroadcasthelper.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <vector> 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace ::com::sun::star; 34cdf0e10cSrcweir using namespace ::com::sun::star::uno; 35cdf0e10cSrcweir using namespace ::com::sun::star::awt; 36cdf0e10cSrcweir using namespace ::com::sun::star::awt::grid; 37cdf0e10cSrcweir using namespace ::com::sun::star::lang; 38cdf0e10cSrcweir 39cdf0e10cSrcweir namespace comphelper 40cdf0e10cSrcweir { 41cdf0e10cSrcweir class ComponentGuard; 42cdf0e10cSrcweir } 43cdf0e10cSrcweir 44cdf0e10cSrcweir namespace toolkit 45cdf0e10cSrcweir { 46cdf0e10cSrcweir 47cdf0e10cSrcweir enum broadcast_type { row_added, row_removed, data_changed}; 48cdf0e10cSrcweir 49cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper2 < XMutableGridDataModel 50cdf0e10cSrcweir , XServiceInfo 51cdf0e10cSrcweir > DefaultGridDataModel_Base; 52cdf0e10cSrcweir 53cdf0e10cSrcweir class DefaultGridDataModel :public ::cppu::BaseMutex 54cdf0e10cSrcweir ,public DefaultGridDataModel_Base 55cdf0e10cSrcweir { 56cdf0e10cSrcweir public: 57cdf0e10cSrcweir DefaultGridDataModel(); 58cdf0e10cSrcweir DefaultGridDataModel( DefaultGridDataModel const & i_copySource ); 59cdf0e10cSrcweir virtual ~DefaultGridDataModel(); 60cdf0e10cSrcweir 61cdf0e10cSrcweir // XMutableGridDataModel 62cdf0e10cSrcweir virtual void SAL_CALL addRow( const Any& i_heading, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Data ) throw (::com::sun::star::uno::RuntimeException); 63cdf0e10cSrcweir virtual void SAL_CALL addRows( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>& Headings, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& Data ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 64cdf0e10cSrcweir virtual void SAL_CALL insertRow( ::sal_Int32 i_index, const ::com::sun::star::uno::Any& i_heading, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Data ) throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IndexOutOfBoundsException); 65cdf0e10cSrcweir virtual void SAL_CALL insertRows( ::sal_Int32 i_index, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>& Headings, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& Data ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 66cdf0e10cSrcweir virtual void SAL_CALL removeRow( ::sal_Int32 RowIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 67cdf0e10cSrcweir virtual void SAL_CALL removeAllRows( ) throw (::com::sun::star::uno::RuntimeException); 68cdf0e10cSrcweir virtual void SAL_CALL updateCellData( ::sal_Int32 ColumnIndex, ::sal_Int32 RowIndex, const ::com::sun::star::uno::Any& Value ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 69cdf0e10cSrcweir virtual void SAL_CALL updateRowData( const ::com::sun::star::uno::Sequence< ::sal_Int32 >& ColumnIndexes, ::sal_Int32 RowIndex, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Values ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 70cdf0e10cSrcweir virtual void SAL_CALL updateRowHeading( ::sal_Int32 RowIndex, const ::com::sun::star::uno::Any& Heading ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 71cdf0e10cSrcweir virtual void SAL_CALL updateCellToolTip( ::sal_Int32 ColumnIndex, ::sal_Int32 RowIndex, const ::com::sun::star::uno::Any& Value ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 72cdf0e10cSrcweir virtual void SAL_CALL updateRowToolTip( ::sal_Int32 RowIndex, const ::com::sun::star::uno::Any& Value ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 73cdf0e10cSrcweir virtual void SAL_CALL addGridDataListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); 74cdf0e10cSrcweir virtual void SAL_CALL removeGridDataListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::grid::XGridDataListener >& Listener ) throw (::com::sun::star::uno::RuntimeException); 75cdf0e10cSrcweir 76cdf0e10cSrcweir // XGridDataModel 77cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getRowCount() throw (::com::sun::star::uno::RuntimeException); 78cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getColumnCount() throw (::com::sun::star::uno::RuntimeException); 79cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL getCellData( ::sal_Int32 Column, ::sal_Int32 Row ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 80cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL getCellToolTip( ::sal_Int32 Column, ::sal_Int32 Row ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 81cdf0e10cSrcweir virtual ::com::sun::star::uno::Any SAL_CALL getRowHeading( ::sal_Int32 RowIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 82cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > SAL_CALL getRowData( ::sal_Int32 RowIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 83cdf0e10cSrcweir 84cdf0e10cSrcweir // OComponentHelper 85cdf0e10cSrcweir virtual void SAL_CALL disposing(); 86cdf0e10cSrcweir 87cdf0e10cSrcweir // XCloneable 88cdf0e10cSrcweir virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone( ) throw (::com::sun::star::uno::RuntimeException); 89cdf0e10cSrcweir 90cdf0e10cSrcweir // XServiceInfo 91cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (RuntimeException); 92cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException); 93cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException); 94cdf0e10cSrcweir 95cdf0e10cSrcweir private: 96cdf0e10cSrcweir typedef ::std::pair< Any, Any > CellData; 97cdf0e10cSrcweir typedef ::std::vector< CellData > RowData; 98cdf0e10cSrcweir typedef ::std::vector< RowData > GridData; 99cdf0e10cSrcweir 100cdf0e10cSrcweir void broadcast( 101cdf0e10cSrcweir GridDataEvent const & i_event, 102cdf0e10cSrcweir void ( SAL_CALL ::com::sun::star::awt::grid::XGridDataListener::*i_listenerMethod )( ::com::sun::star::awt::grid::GridDataEvent const & ), 103cdf0e10cSrcweir ::comphelper::ComponentGuard & i_instanceLock 104cdf0e10cSrcweir ); 105cdf0e10cSrcweir 106cdf0e10cSrcweir void impl_insertRow( sal_Int32 const i_position, Any const & i_heading, Sequence< Any > const & i_rowData, sal_Int32 const i_assumedColCount = -1 ); 107cdf0e10cSrcweir impl_getRowCount_nolck() const108cdf0e10cSrcweir ::sal_Int32 impl_getRowCount_nolck() const { return sal_Int32( m_aData.size() ); } 109cdf0e10cSrcweir 110cdf0e10cSrcweir CellData const & impl_getCellData_throw( sal_Int32 const i_columnIndex, sal_Int32 const i_rowIndex ) const; 111cdf0e10cSrcweir CellData& impl_getCellDataAccess_throw( sal_Int32 const i_columnIndex, sal_Int32 const i_rowIndex ); 112cdf0e10cSrcweir RowData& impl_getRowDataAccess_throw( sal_Int32 const i_rowIndex, size_t const i_requiredColumnCount ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir GridData m_aData; 115cdf0e10cSrcweir ::std::vector< ::com::sun::star::uno::Any > m_aRowHeaders; 116cdf0e10cSrcweir sal_Int32 m_nColumnCount; 117cdf0e10cSrcweir }; 118cdf0e10cSrcweir 119cdf0e10cSrcweir } 120