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