1*b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b0724fc6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b0724fc6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b0724fc6SAndrew Rist  * distributed with this work for additional information
6*b0724fc6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b0724fc6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b0724fc6SAndrew Rist  * "License"); you may not use this file except in compliance
9*b0724fc6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b0724fc6SAndrew Rist  *
11*b0724fc6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b0724fc6SAndrew Rist  *
13*b0724fc6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b0724fc6SAndrew Rist  * software distributed under the License is distributed on an
15*b0724fc6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0724fc6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b0724fc6SAndrew Rist  * specific language governing permissions and limitations
18*b0724fc6SAndrew Rist  * under the License.
19*b0724fc6SAndrew Rist  *
20*b0724fc6SAndrew Rist  *************************************************************/
21*b0724fc6SAndrew Rist 
22*b0724fc6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_toolkit.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "defaultgriddatamodel.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <comphelper/stlunosequence.hxx>
30cdf0e10cSrcweir #include <comphelper/componentguard.hxx>
31cdf0e10cSrcweir #include <toolkit/helper/servicenames.hxx>
32cdf0e10cSrcweir #include <tools/diagnose_ex.h>
33cdf0e10cSrcweir #include <rtl/ref.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <algorithm>
36cdf0e10cSrcweir #include <functional>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //......................................................................................................................
39cdf0e10cSrcweir namespace toolkit
40cdf0e10cSrcweir //......................................................................................................................
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     /** === begin UNO using === **/
43cdf0e10cSrcweir     using ::com::sun::star::uno::Reference;
44cdf0e10cSrcweir     using ::com::sun::star::uno::RuntimeException;
45cdf0e10cSrcweir     using ::com::sun::star::uno::Sequence;
46cdf0e10cSrcweir     using ::com::sun::star::uno::UNO_QUERY_THROW;
47cdf0e10cSrcweir     using ::com::sun::star::uno::UNO_QUERY;
48cdf0e10cSrcweir     using ::com::sun::star::uno::XInterface;
49cdf0e10cSrcweir     using ::com::sun::star::lang::XComponent;
50cdf0e10cSrcweir     using ::com::sun::star::lang::EventObject;
51cdf0e10cSrcweir     using ::com::sun::star::uno::Exception;
52cdf0e10cSrcweir     using ::com::sun::star::util::XCloneable;
53cdf0e10cSrcweir     /** === end UNO using === **/
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     using ::comphelper::stl_begin;
56cdf0e10cSrcweir     using ::comphelper::stl_end;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     //==================================================================================================================
59cdf0e10cSrcweir     //= DefaultGridDataModel
60cdf0e10cSrcweir     //==================================================================================================================
61cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
DefaultGridDataModel()62cdf0e10cSrcweir     DefaultGridDataModel::DefaultGridDataModel()
63cdf0e10cSrcweir         :DefaultGridDataModel_Base( m_aMutex )
64cdf0e10cSrcweir         ,m_aRowHeaders()
65cdf0e10cSrcweir         ,m_nColumnCount(0)
66cdf0e10cSrcweir     {
67cdf0e10cSrcweir     }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
DefaultGridDataModel(DefaultGridDataModel const & i_copySource)70cdf0e10cSrcweir     DefaultGridDataModel::DefaultGridDataModel( DefaultGridDataModel const & i_copySource )
71cdf0e10cSrcweir         :cppu::BaseMutex()
72cdf0e10cSrcweir         ,DefaultGridDataModel_Base( m_aMutex )
73cdf0e10cSrcweir         ,m_aData( i_copySource.m_aData )
74cdf0e10cSrcweir         ,m_aRowHeaders( i_copySource.m_aRowHeaders )
75cdf0e10cSrcweir         ,m_nColumnCount( i_copySource.m_nColumnCount )
76cdf0e10cSrcweir     {
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
~DefaultGridDataModel()80cdf0e10cSrcweir     DefaultGridDataModel::~DefaultGridDataModel()
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir     }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
broadcast(GridDataEvent const & i_event,void (SAL_CALL XGridDataListener::* i_listenerMethod)(GridDataEvent const &),::comphelper::ComponentGuard & i_instanceLock)85cdf0e10cSrcweir     void DefaultGridDataModel::broadcast( GridDataEvent const & i_event,
86cdf0e10cSrcweir         void ( SAL_CALL XGridDataListener::*i_listenerMethod )( GridDataEvent const & ), ::comphelper::ComponentGuard & i_instanceLock )
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir 	    ::cppu::OInterfaceContainerHelper* pListeners = rBHelper.getContainer( XGridDataListener::static_type() );
89cdf0e10cSrcweir 	    if ( !pListeners )
90cdf0e10cSrcweir             return;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         i_instanceLock.clear();
93cdf0e10cSrcweir         pListeners->notifyEach( i_listenerMethod, i_event );
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getRowCount()97cdf0e10cSrcweir     ::sal_Int32 SAL_CALL DefaultGridDataModel::getRowCount() throw (::com::sun::star::uno::RuntimeException)
98cdf0e10cSrcweir     {
99cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
100cdf0e10cSrcweir 	    return impl_getRowCount_nolck();
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getColumnCount()104cdf0e10cSrcweir 	::sal_Int32 SAL_CALL DefaultGridDataModel::getColumnCount() throw (::com::sun::star::uno::RuntimeException)
105cdf0e10cSrcweir     {
106cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
107cdf0e10cSrcweir         return m_nColumnCount;
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
impl_getCellData_throw(sal_Int32 const i_column,sal_Int32 const i_row) const111cdf0e10cSrcweir     DefaultGridDataModel::CellData const & DefaultGridDataModel::impl_getCellData_throw( sal_Int32 const i_column, sal_Int32 const i_row ) const
112cdf0e10cSrcweir     {
113cdf0e10cSrcweir         if  (   ( i_row < 0 ) || ( size_t( i_row ) > m_aData.size() )
114cdf0e10cSrcweir             ||  ( i_column < 0 ) || ( i_column > m_nColumnCount )
115cdf0e10cSrcweir             )
116cdf0e10cSrcweir             throw IndexOutOfBoundsException( ::rtl::OUString(), *const_cast< DefaultGridDataModel* >( this ) );
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         RowData const & rRow( m_aData[ i_row ] );
119cdf0e10cSrcweir         if ( size_t( i_column ) < rRow.size() )
120cdf0e10cSrcweir             return rRow[ i_column ];
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         static CellData s_aEmpty;
123cdf0e10cSrcweir         return s_aEmpty;
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
impl_getRowDataAccess_throw(sal_Int32 const i_rowIndex,size_t const i_requiredColumnCount)127cdf0e10cSrcweir     DefaultGridDataModel::RowData& DefaultGridDataModel::impl_getRowDataAccess_throw( sal_Int32 const i_rowIndex, size_t const i_requiredColumnCount )
128cdf0e10cSrcweir     {
129cdf0e10cSrcweir         OSL_ENSURE( i_requiredColumnCount <= size_t( m_nColumnCount ), "DefaultGridDataModel::impl_getRowDataAccess_throw: invalid column count!" );
130cdf0e10cSrcweir         if  ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
131cdf0e10cSrcweir             throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         RowData& rRowData( m_aData[ i_rowIndex ] );
134cdf0e10cSrcweir         if ( rRowData.size() < i_requiredColumnCount )
135cdf0e10cSrcweir             rRowData.resize( i_requiredColumnCount );
136cdf0e10cSrcweir         return rRowData;
137cdf0e10cSrcweir     }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
impl_getCellDataAccess_throw(sal_Int32 const i_columnIndex,sal_Int32 const i_rowIndex)140cdf0e10cSrcweir     DefaultGridDataModel::CellData& DefaultGridDataModel::impl_getCellDataAccess_throw( sal_Int32 const i_columnIndex, sal_Int32 const i_rowIndex )
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         if  ( ( i_columnIndex < 0 ) || ( i_columnIndex >= m_nColumnCount ) )
143cdf0e10cSrcweir             throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         RowData& rRowData( impl_getRowDataAccess_throw( i_rowIndex, size_t( i_columnIndex + 1 ) ) );
146cdf0e10cSrcweir         return rRowData[ i_columnIndex ];
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getCellData(::sal_Int32 i_column,::sal_Int32 i_row)150cdf0e10cSrcweir     Any SAL_CALL DefaultGridDataModel::getCellData( ::sal_Int32 i_column, ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException)
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
153cdf0e10cSrcweir         return impl_getCellData_throw( i_column, i_row ).first;
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getCellToolTip(::sal_Int32 i_column,::sal_Int32 i_row)157cdf0e10cSrcweir     Any SAL_CALL DefaultGridDataModel::getCellToolTip( ::sal_Int32 i_column, ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException)
158cdf0e10cSrcweir     {
159cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
160cdf0e10cSrcweir         return impl_getCellData_throw( i_column, i_row ).second;
161cdf0e10cSrcweir     }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getRowHeading(::sal_Int32 i_row)164cdf0e10cSrcweir     Any SAL_CALL DefaultGridDataModel::getRowHeading( ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException)
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         if ( ( i_row < 0 ) || ( size_t( i_row ) >= m_aRowHeaders.size() ) )
169cdf0e10cSrcweir             throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         return m_aRowHeaders[ i_row ];
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getRowData(::sal_Int32 i_rowIndex)175cdf0e10cSrcweir     Sequence< Any > SAL_CALL DefaultGridDataModel::getRowData( ::sal_Int32 i_rowIndex ) throw (IndexOutOfBoundsException, RuntimeException)
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir         Sequence< Any > resultData( m_nColumnCount );
180cdf0e10cSrcweir         RowData& rRowData = impl_getRowDataAccess_throw( i_rowIndex, m_nColumnCount );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         ::std::transform( rRowData.begin(), rRowData.end(), resultData.getArray(), ::std::select1st< CellData >() );
183cdf0e10cSrcweir         return resultData;
184cdf0e10cSrcweir     }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
impl_insertRow(sal_Int32 const i_position,Any const & i_heading,Sequence<Any> const & i_rowData,sal_Int32 const i_assumedColCount)187cdf0e10cSrcweir     void DefaultGridDataModel::impl_insertRow( sal_Int32 const i_position, Any const & i_heading, Sequence< Any > const & i_rowData, sal_Int32 const i_assumedColCount )
188cdf0e10cSrcweir     {
189cdf0e10cSrcweir         OSL_PRECOND( ( i_assumedColCount <= 0 ) || ( i_assumedColCount >= i_rowData.getLength() ),
190cdf0e10cSrcweir             "DefaultGridDataModel::impl_insertRow: invalid column count!" );
191cdf0e10cSrcweir 
192cdf0e10cSrcweir         // insert heading
193cdf0e10cSrcweir         m_aRowHeaders.insert( m_aRowHeaders.begin() + i_position, i_heading );
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         // create new data row
196cdf0e10cSrcweir         RowData newRow( i_assumedColCount > 0 ? i_assumedColCount : i_rowData.getLength() );
197cdf0e10cSrcweir         RowData::iterator cellData = newRow.begin();
198cdf0e10cSrcweir         for ( const Any* pData = stl_begin( i_rowData ); pData != stl_end( i_rowData ); ++pData, ++cellData )
199cdf0e10cSrcweir             cellData->first = *pData;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         // insert data row
202cdf0e10cSrcweir         m_aData.insert( m_aData.begin() + i_position, newRow );
203cdf0e10cSrcweir     }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
addRow(const Any & i_heading,const Sequence<Any> & i_data)206cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::addRow( const Any& i_heading, const Sequence< Any >& i_data ) throw (RuntimeException)
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir         insertRow( getRowCount(), i_heading, i_data );
209cdf0e10cSrcweir     }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
addRows(const Sequence<Any> & i_headings,const Sequence<Sequence<Any>> & i_data)212cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::addRows( const Sequence< Any >& i_headings, const Sequence< Sequence< Any > >& i_data ) throw (IllegalArgumentException, RuntimeException)
213cdf0e10cSrcweir     {
214cdf0e10cSrcweir         insertRows( getRowCount(), i_headings, i_data );
215cdf0e10cSrcweir     }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
insertRow(::sal_Int32 i_index,const Any & i_heading,const Sequence<Any> & i_data)218cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::insertRow( ::sal_Int32 i_index, const Any& i_heading, const Sequence< Any >& i_data ) throw (RuntimeException, IndexOutOfBoundsException)
219cdf0e10cSrcweir     {
220cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
221cdf0e10cSrcweir 
222cdf0e10cSrcweir         if ( ( i_index < 0 ) || ( i_index > impl_getRowCount_nolck() ) )
223cdf0e10cSrcweir             throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         // actually insert the row
226cdf0e10cSrcweir         impl_insertRow( i_index, i_heading, i_data );
227cdf0e10cSrcweir 
228cdf0e10cSrcweir         // update column count
229cdf0e10cSrcweir         sal_Int32 const columnCount = i_data.getLength();
230cdf0e10cSrcweir         if ( columnCount > m_nColumnCount )
231cdf0e10cSrcweir             m_nColumnCount = columnCount;
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         broadcast(
234cdf0e10cSrcweir             GridDataEvent( *this, -1, -1, i_index, i_index ),
235cdf0e10cSrcweir             &XGridDataListener::rowsInserted,
236cdf0e10cSrcweir             aGuard
237cdf0e10cSrcweir         );
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
insertRows(::sal_Int32 i_index,const Sequence<Any> & i_headings,const Sequence<Sequence<Any>> & i_data)241cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::insertRows( ::sal_Int32 i_index, const Sequence< Any>& i_headings, const Sequence< Sequence< Any > >& i_data ) throw (IllegalArgumentException, IndexOutOfBoundsException, RuntimeException)
242cdf0e10cSrcweir     {
243cdf0e10cSrcweir         if ( i_headings.getLength() != i_data.getLength() )
244cdf0e10cSrcweir             throw IllegalArgumentException( ::rtl::OUString(), *this, -1 );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
247cdf0e10cSrcweir 
248cdf0e10cSrcweir         if ( ( i_index < 0 ) || ( i_index > impl_getRowCount_nolck() ) )
249cdf0e10cSrcweir             throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
250cdf0e10cSrcweir 
251cdf0e10cSrcweir         sal_Int32 const rowCount = i_headings.getLength();
252cdf0e10cSrcweir         if ( rowCount == 0 )
253cdf0e10cSrcweir             return;
254cdf0e10cSrcweir 
255cdf0e10cSrcweir         // determine max col count in the new data
256cdf0e10cSrcweir         sal_Int32 maxColCount = 0;
257cdf0e10cSrcweir         for ( sal_Int32 row=0; row<rowCount; ++row )
258cdf0e10cSrcweir             if ( i_data[row].getLength() > maxColCount )
259cdf0e10cSrcweir                 maxColCount = i_data[row].getLength();
260cdf0e10cSrcweir 
261cdf0e10cSrcweir         if ( maxColCount < m_nColumnCount )
262cdf0e10cSrcweir             maxColCount = m_nColumnCount;
263cdf0e10cSrcweir 
264cdf0e10cSrcweir         for ( sal_Int32 row=0; row<rowCount;  ++row )
265cdf0e10cSrcweir         {
266cdf0e10cSrcweir             impl_insertRow( i_index + row, i_headings[row], i_data[row], maxColCount );
267cdf0e10cSrcweir         }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir         if ( maxColCount > m_nColumnCount )
270cdf0e10cSrcweir             m_nColumnCount = maxColCount;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir         broadcast(
273cdf0e10cSrcweir             GridDataEvent( *this, -1, -1, i_index, i_index + rowCount - 1 ),
274cdf0e10cSrcweir             &XGridDataListener::rowsInserted,
275cdf0e10cSrcweir             aGuard
276cdf0e10cSrcweir         );
277cdf0e10cSrcweir     }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
removeRow(::sal_Int32 i_rowIndex)280cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::removeRow( ::sal_Int32 i_rowIndex ) throw (IndexOutOfBoundsException, RuntimeException)
281cdf0e10cSrcweir     {
282cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 	    if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
285cdf0e10cSrcweir             throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
286cdf0e10cSrcweir 
287cdf0e10cSrcweir         m_aRowHeaders.erase( m_aRowHeaders.begin() + i_rowIndex );
288cdf0e10cSrcweir 	    m_aData.erase( m_aData.begin() + i_rowIndex );
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 	    broadcast(
291cdf0e10cSrcweir             GridDataEvent( *this, -1, -1, i_rowIndex, i_rowIndex ),
292cdf0e10cSrcweir             &XGridDataListener::rowsRemoved,
293cdf0e10cSrcweir             aGuard
294cdf0e10cSrcweir         );
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
removeAllRows()298cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::removeAllRows(  ) throw (RuntimeException)
299cdf0e10cSrcweir     {
300cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
301cdf0e10cSrcweir 
302cdf0e10cSrcweir         m_aRowHeaders.clear();
303cdf0e10cSrcweir         m_aData.clear();
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 	    broadcast(
306cdf0e10cSrcweir             GridDataEvent( *this, -1, -1, -1, -1 ),
307cdf0e10cSrcweir             &XGridDataListener::rowsRemoved,
308cdf0e10cSrcweir             aGuard
309cdf0e10cSrcweir         );
310cdf0e10cSrcweir     }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
updateCellData(::sal_Int32 i_columnIndex,::sal_Int32 i_rowIndex,const Any & i_value)313cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::updateCellData( ::sal_Int32 i_columnIndex, ::sal_Int32 i_rowIndex, const Any& i_value ) throw (IndexOutOfBoundsException, RuntimeException)
314cdf0e10cSrcweir     {
315cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
316cdf0e10cSrcweir 
317cdf0e10cSrcweir         impl_getCellDataAccess_throw( i_columnIndex, i_rowIndex ).first = i_value;
318cdf0e10cSrcweir 
319cdf0e10cSrcweir         broadcast(
320cdf0e10cSrcweir             GridDataEvent( *this, i_columnIndex, i_columnIndex, i_rowIndex, i_rowIndex ),
321cdf0e10cSrcweir             &XGridDataListener::dataChanged,
322cdf0e10cSrcweir             aGuard
323cdf0e10cSrcweir         );
324cdf0e10cSrcweir     }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
updateRowData(const Sequence<::sal_Int32> & i_columnIndexes,::sal_Int32 i_rowIndex,const Sequence<Any> & i_values)327cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::updateRowData( const Sequence< ::sal_Int32 >& i_columnIndexes, ::sal_Int32 i_rowIndex, const Sequence< Any >& i_values ) throw (IndexOutOfBoundsException, IllegalArgumentException, RuntimeException)
328cdf0e10cSrcweir     {
329cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
330cdf0e10cSrcweir 
331cdf0e10cSrcweir         if  ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
332cdf0e10cSrcweir             throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
333cdf0e10cSrcweir 
334cdf0e10cSrcweir         if ( i_columnIndexes.getLength() != i_values.getLength() )
335cdf0e10cSrcweir             throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
336cdf0e10cSrcweir 
337cdf0e10cSrcweir         sal_Int32 const columnCount = i_columnIndexes.getLength();
338cdf0e10cSrcweir         if ( columnCount == 0 )
339cdf0e10cSrcweir             return;
340cdf0e10cSrcweir 
341cdf0e10cSrcweir         for ( sal_Int32 col = 0; col < columnCount; ++col )
342cdf0e10cSrcweir         {
343cdf0e10cSrcweir             if ( ( i_columnIndexes[col] < 0 ) || ( i_columnIndexes[col] > m_nColumnCount ) )
344cdf0e10cSrcweir                 throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
345cdf0e10cSrcweir         }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir         RowData& rDataRow = m_aData[ i_rowIndex ];
348cdf0e10cSrcweir         for ( sal_Int32 col = 0; col < columnCount; ++col )
349cdf0e10cSrcweir         {
350cdf0e10cSrcweir             sal_Int32 const columnIndex = i_columnIndexes[ col ];
351cdf0e10cSrcweir             if ( size_t( columnIndex ) >= rDataRow.size() )
352cdf0e10cSrcweir                 rDataRow.resize( columnIndex + 1 );
353cdf0e10cSrcweir 
354cdf0e10cSrcweir             rDataRow[ columnIndex ].first = i_values[ col ];
355cdf0e10cSrcweir         }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir         sal_Int32 const firstAffectedColumn = *::std::min_element( stl_begin( i_columnIndexes ), stl_end( i_columnIndexes ) );
358cdf0e10cSrcweir         sal_Int32 const lastAffectedColumn = *::std::max_element( stl_begin( i_columnIndexes ), stl_end( i_columnIndexes ) );
359cdf0e10cSrcweir         broadcast(
360cdf0e10cSrcweir             GridDataEvent( *this, firstAffectedColumn, lastAffectedColumn, i_rowIndex, i_rowIndex ),
361cdf0e10cSrcweir             &XGridDataListener::dataChanged,
362cdf0e10cSrcweir             aGuard
363cdf0e10cSrcweir         );
364cdf0e10cSrcweir     }
365cdf0e10cSrcweir 
366cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
updateRowHeading(::sal_Int32 i_rowIndex,const Any & i_heading)367cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::updateRowHeading( ::sal_Int32 i_rowIndex, const Any& i_heading ) throw (IndexOutOfBoundsException, RuntimeException)
368cdf0e10cSrcweir     {
369cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
370cdf0e10cSrcweir 
371cdf0e10cSrcweir         if  ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aRowHeaders.size() ) )
372cdf0e10cSrcweir             throw IndexOutOfBoundsException( ::rtl::OUString(), *this );
373cdf0e10cSrcweir 
374cdf0e10cSrcweir         m_aRowHeaders[ i_rowIndex ] = i_heading;
375cdf0e10cSrcweir 
376cdf0e10cSrcweir         broadcast(
377cdf0e10cSrcweir             GridDataEvent( *this, -1, -1, i_rowIndex, i_rowIndex ),
378cdf0e10cSrcweir             &XGridDataListener::rowHeadingChanged,
379cdf0e10cSrcweir             aGuard
380cdf0e10cSrcweir         );
381cdf0e10cSrcweir     }
382cdf0e10cSrcweir 
383cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
updateCellToolTip(::sal_Int32 i_columnIndex,::sal_Int32 i_rowIndex,const Any & i_value)384cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::updateCellToolTip( ::sal_Int32 i_columnIndex, ::sal_Int32 i_rowIndex, const Any& i_value ) throw (IndexOutOfBoundsException, RuntimeException)
385cdf0e10cSrcweir     {
386cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
387cdf0e10cSrcweir         impl_getCellDataAccess_throw( i_columnIndex, i_rowIndex ).second = i_value;
388cdf0e10cSrcweir     }
389cdf0e10cSrcweir 
390cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
updateRowToolTip(::sal_Int32 i_rowIndex,const Any & i_value)391cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::updateRowToolTip( ::sal_Int32 i_rowIndex, const Any& i_value ) throw (IndexOutOfBoundsException, RuntimeException)
392cdf0e10cSrcweir     {
393cdf0e10cSrcweir         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir         RowData& rRowData = impl_getRowDataAccess_throw( i_rowIndex, m_nColumnCount );
396cdf0e10cSrcweir         for ( RowData::iterator cell = rRowData.begin(); cell != rRowData.end(); ++cell )
397cdf0e10cSrcweir             cell->second = i_value;
398cdf0e10cSrcweir     }
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
addGridDataListener(const Reference<grid::XGridDataListener> & i_listener)401cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::addGridDataListener( const Reference< grid::XGridDataListener >& i_listener ) throw (RuntimeException)
402cdf0e10cSrcweir     {
403cdf0e10cSrcweir 	    rBHelper.addListener( XGridDataListener::static_type(), i_listener );
404cdf0e10cSrcweir     }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
removeGridDataListener(const Reference<grid::XGridDataListener> & i_listener)407cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::removeGridDataListener( const Reference< grid::XGridDataListener >& i_listener ) throw (RuntimeException)
408cdf0e10cSrcweir     {
409cdf0e10cSrcweir 	    rBHelper.removeListener( XGridDataListener::static_type(), i_listener );
410cdf0e10cSrcweir     }
411cdf0e10cSrcweir 
412cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
disposing()413cdf0e10cSrcweir     void SAL_CALL DefaultGridDataModel::disposing()
414cdf0e10cSrcweir     {
415cdf0e10cSrcweir 	    ::com::sun::star::lang::EventObject aEvent;
416cdf0e10cSrcweir 	    aEvent.Source.set( *this );
417cdf0e10cSrcweir 	    rBHelper.aLC.disposeAndClear( aEvent );
418cdf0e10cSrcweir 
419cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
420cdf0e10cSrcweir         GridData aEmptyData;
421cdf0e10cSrcweir         m_aData.swap( aEmptyData );
422cdf0e10cSrcweir 
423cdf0e10cSrcweir         ::std::vector< Any > aEmptyRowHeaders;
424cdf0e10cSrcweir         m_aRowHeaders.swap( aEmptyRowHeaders );
425cdf0e10cSrcweir 
426cdf0e10cSrcweir         m_nColumnCount = 0;
427cdf0e10cSrcweir     }
428cdf0e10cSrcweir 
429cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getImplementationName()430cdf0e10cSrcweir     ::rtl::OUString SAL_CALL DefaultGridDataModel::getImplementationName(  ) throw (RuntimeException)
431cdf0e10cSrcweir     {
432cdf0e10cSrcweir         static const ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "toolkit.DefaultGridDataModel" ) );
433cdf0e10cSrcweir 	    return aImplName;
434cdf0e10cSrcweir     }
435cdf0e10cSrcweir 
436cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
supportsService(const::rtl::OUString & ServiceName)437cdf0e10cSrcweir     sal_Bool SAL_CALL DefaultGridDataModel::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException)
438cdf0e10cSrcweir     {
439cdf0e10cSrcweir 	    return ServiceName.equalsAscii( szServiceName_DefaultGridDataModel );
440cdf0e10cSrcweir     }
441cdf0e10cSrcweir 
442cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
getSupportedServiceNames()443cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL DefaultGridDataModel::getSupportedServiceNames(  ) throw (RuntimeException)
444cdf0e10cSrcweir     {
445cdf0e10cSrcweir 	    static const ::rtl::OUString aServiceName( ::rtl::OUString::createFromAscii( szServiceName_DefaultGridDataModel ) );
446cdf0e10cSrcweir 	    static const Sequence< ::rtl::OUString > aSeq( &aServiceName, 1 );
447cdf0e10cSrcweir 	    return aSeq;
448cdf0e10cSrcweir     }
449cdf0e10cSrcweir 
450cdf0e10cSrcweir     //------------------------------------------------------------------------------------------------------------------
createClone()451cdf0e10cSrcweir     Reference< XCloneable > SAL_CALL DefaultGridDataModel::createClone(  ) throw (RuntimeException)
452cdf0e10cSrcweir     {
453cdf0e10cSrcweir         return new DefaultGridDataModel( *this );
454cdf0e10cSrcweir     }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir //......................................................................................................................
457cdf0e10cSrcweir }   // namespace toolkit
458cdf0e10cSrcweir //......................................................................................................................
459cdf0e10cSrcweir 
DefaultGridDataModel_CreateInstance(const Reference<XMultiServiceFactory> &)460cdf0e10cSrcweir Reference< XInterface > SAL_CALL DefaultGridDataModel_CreateInstance( const Reference< XMultiServiceFactory >& )
461cdf0e10cSrcweir {
462cdf0e10cSrcweir 	return Reference < XInterface >( ( ::cppu::OWeakObject* ) new ::toolkit::DefaultGridDataModel() );
463cdf0e10cSrcweir }
464