Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <com/sun/star/awt/grid/XMutableGridDataModel.hpp>
21 : #include <com/sun/star/lang/XServiceInfo.hpp>
22 : #include <com/sun/star/uno/XComponentContext.hpp>
23 :
24 : #include <comphelper/componentguard.hxx>
25 : #include <cppuhelper/basemutex.hxx>
26 : #include <cppuhelper/compbase2.hxx>
27 : #include <cppuhelper/supportsservice.hxx>
28 : #include <toolkit/helper/servicenames.hxx>
29 : #include <tools/diagnose_ex.h>
30 : #include <toolkit/helper/mutexandbroadcasthelper.hxx>
31 :
32 : #include <algorithm>
33 : #include <functional>
34 : #include <vector>
35 : #include <boost/bind.hpp>
36 :
37 : using namespace ::com::sun::star;
38 : using namespace ::com::sun::star::uno;
39 : using namespace ::com::sun::star::awt;
40 : using namespace ::com::sun::star::awt::grid;
41 : using namespace ::com::sun::star::lang;
42 :
43 : namespace {
44 :
45 : enum broadcast_type { row_added, row_removed, data_changed};
46 :
47 : typedef ::cppu::WeakComponentImplHelper2 < XMutableGridDataModel
48 : , XServiceInfo
49 : > DefaultGridDataModel_Base;
50 :
51 : class DefaultGridDataModel :public ::cppu::BaseMutex
52 : ,public DefaultGridDataModel_Base
53 : {
54 : public:
55 : DefaultGridDataModel();
56 : DefaultGridDataModel( DefaultGridDataModel const & i_copySource );
57 : virtual ~DefaultGridDataModel();
58 :
59 : // XMutableGridDataModel
60 : virtual void SAL_CALL addRow( const Any& i_heading, const css::uno::Sequence< css::uno::Any >& Data ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
61 : virtual void SAL_CALL addRows( const css::uno::Sequence< css::uno::Any>& Headings, const css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& Data ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
62 : virtual void SAL_CALL insertRow( ::sal_Int32 i_index, const css::uno::Any& i_heading, const css::uno::Sequence< css::uno::Any >& Data ) throw (css::uno::RuntimeException, css::lang::IndexOutOfBoundsException, std::exception) SAL_OVERRIDE;
63 : virtual void SAL_CALL insertRows( ::sal_Int32 i_index, const css::uno::Sequence< css::uno::Any>& Headings, const css::uno::Sequence< css::uno::Sequence< css::uno::Any > >& Data ) throw (css::lang::IllegalArgumentException, css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
64 : virtual void SAL_CALL removeRow( ::sal_Int32 RowIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
65 : virtual void SAL_CALL removeAllRows( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
66 : virtual void SAL_CALL updateCellData( ::sal_Int32 ColumnIndex, ::sal_Int32 RowIndex, const css::uno::Any& Value ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
67 : virtual void SAL_CALL updateRowData( const css::uno::Sequence< ::sal_Int32 >& ColumnIndexes, ::sal_Int32 RowIndex, const css::uno::Sequence< css::uno::Any >& Values ) throw (css::lang::IndexOutOfBoundsException, css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
68 : virtual void SAL_CALL updateRowHeading( ::sal_Int32 RowIndex, const css::uno::Any& Heading ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
69 : virtual void SAL_CALL updateCellToolTip( ::sal_Int32 ColumnIndex, ::sal_Int32 RowIndex, const css::uno::Any& Value ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
70 : virtual void SAL_CALL updateRowToolTip( ::sal_Int32 RowIndex, const css::uno::Any& Value ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
71 : virtual void SAL_CALL addGridDataListener( const css::uno::Reference< css::awt::grid::XGridDataListener >& Listener ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
72 : virtual void SAL_CALL removeGridDataListener( const css::uno::Reference< css::awt::grid::XGridDataListener >& Listener ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
73 :
74 : // XGridDataModel
75 : virtual ::sal_Int32 SAL_CALL getRowCount() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
76 : virtual ::sal_Int32 SAL_CALL getColumnCount() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
77 : virtual css::uno::Any SAL_CALL getCellData( ::sal_Int32 Column, ::sal_Int32 Row ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
78 : virtual css::uno::Any SAL_CALL getCellToolTip( ::sal_Int32 Column, ::sal_Int32 Row ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
79 : virtual css::uno::Any SAL_CALL getRowHeading( ::sal_Int32 RowIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
80 : virtual css::uno::Sequence< css::uno::Any > SAL_CALL getRowData( ::sal_Int32 RowIndex ) throw (css::lang::IndexOutOfBoundsException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
81 :
82 : // OComponentHelper
83 : virtual void SAL_CALL disposing() SAL_OVERRIDE;
84 :
85 : // XCloneable
86 : virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone( ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
87 :
88 : // XServiceInfo
89 : virtual OUString SAL_CALL getImplementationName( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
90 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
91 : virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
92 :
93 : private:
94 : typedef ::std::pair< Any, Any > CellData;
95 : typedef ::std::vector< CellData > RowData;
96 : typedef ::std::vector< RowData > GridData;
97 :
98 : void broadcast(
99 : GridDataEvent const & i_event,
100 : void ( SAL_CALL css::awt::grid::XGridDataListener::*i_listenerMethod )( css::awt::grid::GridDataEvent const & ),
101 : ::comphelper::ComponentGuard & i_instanceLock
102 : );
103 :
104 : void impl_insertRow( sal_Int32 const i_position, Any const & i_heading, Sequence< Any > const & i_rowData, sal_Int32 const i_assumedColCount = -1 );
105 :
106 595 : ::sal_Int32 impl_getRowCount_nolck() const { return sal_Int32( m_aData.size() ); }
107 :
108 : CellData const & impl_getCellData_throw( sal_Int32 const i_columnIndex, sal_Int32 const i_rowIndex ) const;
109 : CellData& impl_getCellDataAccess_throw( sal_Int32 const i_columnIndex, sal_Int32 const i_rowIndex );
110 : RowData& impl_getRowDataAccess_throw( sal_Int32 const i_rowIndex, size_t const i_requiredColumnCount );
111 :
112 : GridData m_aData;
113 : ::std::vector< css::uno::Any > m_aRowHeaders;
114 : sal_Int32 m_nColumnCount;
115 : };
116 :
117 12 : DefaultGridDataModel::DefaultGridDataModel()
118 : :DefaultGridDataModel_Base( m_aMutex )
119 : ,m_aRowHeaders()
120 12 : ,m_nColumnCount(0)
121 : {
122 12 : }
123 :
124 :
125 1 : DefaultGridDataModel::DefaultGridDataModel( DefaultGridDataModel const & i_copySource )
126 : :cppu::BaseMutex()
127 : ,DefaultGridDataModel_Base( m_aMutex )
128 : ,m_aData( i_copySource.m_aData )
129 : ,m_aRowHeaders( i_copySource.m_aRowHeaders )
130 1 : ,m_nColumnCount( i_copySource.m_nColumnCount )
131 : {
132 1 : }
133 :
134 :
135 16 : DefaultGridDataModel::~DefaultGridDataModel()
136 : {
137 16 : }
138 :
139 :
140 24 : void DefaultGridDataModel::broadcast( GridDataEvent const & i_event,
141 : void ( SAL_CALL XGridDataListener::*i_listenerMethod )( GridDataEvent const & ), ::comphelper::ComponentGuard & i_instanceLock )
142 : {
143 24 : ::cppu::OInterfaceContainerHelper* pListeners = rBHelper.getContainer( cppu::UnoType<XGridDataListener>::get() );
144 24 : if ( !pListeners )
145 26 : return;
146 :
147 22 : i_instanceLock.clear();
148 22 : pListeners->notifyEach( i_listenerMethod, i_event );
149 : }
150 :
151 :
152 583 : ::sal_Int32 SAL_CALL DefaultGridDataModel::getRowCount() throw (::com::sun::star::uno::RuntimeException, std::exception)
153 : {
154 583 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
155 583 : return impl_getRowCount_nolck();
156 : }
157 :
158 :
159 34 : ::sal_Int32 SAL_CALL DefaultGridDataModel::getColumnCount() throw (::com::sun::star::uno::RuntimeException, std::exception)
160 : {
161 34 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
162 34 : return m_nColumnCount;
163 : }
164 :
165 :
166 456 : DefaultGridDataModel::CellData const & DefaultGridDataModel::impl_getCellData_throw( sal_Int32 const i_column, sal_Int32 const i_row ) const
167 : {
168 912 : if ( ( i_row < 0 ) || ( size_t( i_row ) > m_aData.size() )
169 912 : || ( i_column < 0 ) || ( i_column > m_nColumnCount )
170 : )
171 0 : throw IndexOutOfBoundsException( OUString(), *const_cast< DefaultGridDataModel* >( this ) );
172 :
173 456 : RowData const & rRow( m_aData[ i_row ] );
174 456 : if ( size_t( i_column ) < rRow.size() )
175 456 : return rRow[ i_column ];
176 :
177 0 : static CellData s_aEmpty;
178 0 : return s_aEmpty;
179 : }
180 :
181 :
182 22 : DefaultGridDataModel::RowData& DefaultGridDataModel::impl_getRowDataAccess_throw( sal_Int32 const i_rowIndex, size_t const i_requiredColumnCount )
183 : {
184 : OSL_ENSURE( i_requiredColumnCount <= size_t( m_nColumnCount ), "DefaultGridDataModel::impl_getRowDataAccess_throw: invalid column count!" );
185 22 : if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
186 0 : throw IndexOutOfBoundsException( OUString(), *this );
187 :
188 22 : RowData& rRowData( m_aData[ i_rowIndex ] );
189 22 : if ( rRowData.size() < i_requiredColumnCount )
190 0 : rRowData.resize( i_requiredColumnCount );
191 22 : return rRowData;
192 : }
193 :
194 :
195 4 : DefaultGridDataModel::CellData& DefaultGridDataModel::impl_getCellDataAccess_throw( sal_Int32 const i_columnIndex, sal_Int32 const i_rowIndex )
196 : {
197 4 : if ( ( i_columnIndex < 0 ) || ( i_columnIndex >= m_nColumnCount ) )
198 1 : throw IndexOutOfBoundsException( OUString(), *this );
199 :
200 3 : RowData& rRowData( impl_getRowDataAccess_throw( i_rowIndex, size_t( i_columnIndex + 1 ) ) );
201 3 : return rRowData[ i_columnIndex ];
202 : }
203 :
204 :
205 456 : Any SAL_CALL DefaultGridDataModel::getCellData( ::sal_Int32 i_column, ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException, std::exception)
206 : {
207 456 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
208 456 : return impl_getCellData_throw( i_column, i_row ).first;
209 : }
210 :
211 :
212 0 : Any SAL_CALL DefaultGridDataModel::getCellToolTip( ::sal_Int32 i_column, ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException, std::exception)
213 : {
214 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
215 0 : return impl_getCellData_throw( i_column, i_row ).second;
216 : }
217 :
218 :
219 78 : Any SAL_CALL DefaultGridDataModel::getRowHeading( ::sal_Int32 i_row ) throw (RuntimeException, IndexOutOfBoundsException, std::exception)
220 : {
221 78 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
222 :
223 78 : if ( ( i_row < 0 ) || ( size_t( i_row ) >= m_aRowHeaders.size() ) )
224 0 : throw IndexOutOfBoundsException( OUString(), *this );
225 :
226 78 : return m_aRowHeaders[ i_row ];
227 : }
228 :
229 :
230 19 : Sequence< Any > SAL_CALL DefaultGridDataModel::getRowData( ::sal_Int32 i_rowIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
231 : {
232 19 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
233 :
234 19 : Sequence< Any > resultData( m_nColumnCount );
235 19 : RowData& rRowData = impl_getRowDataAccess_throw( i_rowIndex, m_nColumnCount );
236 :
237 : ::std::transform( rRowData.begin(), rRowData.end(), resultData.getArray(),
238 19 : boost::bind(&CellData::first,_1));
239 19 : return resultData;
240 : }
241 :
242 :
243 33 : void DefaultGridDataModel::impl_insertRow( sal_Int32 const i_position, Any const & i_heading, Sequence< Any > const & i_rowData, sal_Int32 const i_assumedColCount )
244 : {
245 : OSL_PRECOND( ( i_assumedColCount <= 0 ) || ( i_assumedColCount >= i_rowData.getLength() ),
246 : "DefaultGridDataModel::impl_insertRow: invalid column count!" );
247 :
248 : // insert heading
249 33 : m_aRowHeaders.insert( m_aRowHeaders.begin() + i_position, i_heading );
250 :
251 : // create new data row
252 33 : RowData newRow( i_assumedColCount > 0 ? i_assumedColCount : i_rowData.getLength() );
253 33 : RowData::iterator cellData = newRow.begin();
254 157 : for ( const Any* pData = i_rowData.begin(); pData != i_rowData.end(); ++pData, ++cellData )
255 124 : cellData->first = *pData;
256 :
257 : // insert data row
258 33 : m_aData.insert( m_aData.begin() + i_position, newRow );
259 33 : }
260 :
261 :
262 6 : void SAL_CALL DefaultGridDataModel::addRow( const Any& i_heading, const Sequence< Any >& i_data ) throw (RuntimeException, std::exception)
263 : {
264 6 : insertRow( getRowCount(), i_heading, i_data );
265 6 : }
266 :
267 :
268 5 : void SAL_CALL DefaultGridDataModel::addRows( const Sequence< Any >& i_headings, const Sequence< Sequence< Any > >& i_data ) throw (IllegalArgumentException, RuntimeException, std::exception)
269 : {
270 5 : insertRows( getRowCount(), i_headings, i_data );
271 4 : }
272 :
273 :
274 7 : void SAL_CALL DefaultGridDataModel::insertRow( ::sal_Int32 i_index, const Any& i_heading, const Sequence< Any >& i_data ) throw (RuntimeException, IndexOutOfBoundsException, std::exception)
275 : {
276 7 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
277 :
278 7 : if ( ( i_index < 0 ) || ( i_index > impl_getRowCount_nolck() ) )
279 0 : throw IndexOutOfBoundsException( OUString(), *this );
280 :
281 : // actually insert the row
282 7 : impl_insertRow( i_index, i_heading, i_data );
283 :
284 : // update column count
285 7 : sal_Int32 const columnCount = i_data.getLength();
286 7 : if ( columnCount > m_nColumnCount )
287 4 : m_nColumnCount = columnCount;
288 :
289 : broadcast(
290 : GridDataEvent( *this, -1, -1, i_index, i_index ),
291 : &XGridDataListener::rowsInserted,
292 : aGuard
293 7 : );
294 7 : }
295 :
296 :
297 7 : void SAL_CALL DefaultGridDataModel::insertRows( ::sal_Int32 i_index, const Sequence< Any>& i_headings, const Sequence< Sequence< Any > >& i_data ) throw (IllegalArgumentException, IndexOutOfBoundsException, RuntimeException, std::exception)
298 : {
299 7 : if ( i_headings.getLength() != i_data.getLength() )
300 2 : throw IllegalArgumentException( OUString(), *this, -1 );
301 :
302 5 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
303 :
304 5 : if ( ( i_index < 0 ) || ( i_index > impl_getRowCount_nolck() ) )
305 0 : throw IndexOutOfBoundsException( OUString(), *this );
306 :
307 5 : sal_Int32 const rowCount = i_headings.getLength();
308 5 : if ( rowCount == 0 )
309 5 : return;
310 :
311 : // determine max col count in the new data
312 5 : sal_Int32 maxColCount = 0;
313 31 : for ( sal_Int32 row=0; row<rowCount; ++row )
314 26 : if ( i_data[row].getLength() > maxColCount )
315 5 : maxColCount = i_data[row].getLength();
316 :
317 5 : if ( maxColCount < m_nColumnCount )
318 0 : maxColCount = m_nColumnCount;
319 :
320 31 : for ( sal_Int32 row=0; row<rowCount; ++row )
321 : {
322 26 : impl_insertRow( i_index + row, i_headings[row], i_data[row], maxColCount );
323 : }
324 :
325 5 : if ( maxColCount > m_nColumnCount )
326 2 : m_nColumnCount = maxColCount;
327 :
328 : broadcast(
329 5 : GridDataEvent( *this, -1, -1, i_index, i_index + rowCount - 1 ),
330 : &XGridDataListener::rowsInserted,
331 : aGuard
332 10 : );
333 : }
334 :
335 :
336 6 : void SAL_CALL DefaultGridDataModel::removeRow( ::sal_Int32 i_rowIndex ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
337 : {
338 6 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
339 :
340 6 : if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
341 0 : throw IndexOutOfBoundsException( OUString(), *this );
342 :
343 6 : m_aRowHeaders.erase( m_aRowHeaders.begin() + i_rowIndex );
344 6 : m_aData.erase( m_aData.begin() + i_rowIndex );
345 :
346 : broadcast(
347 : GridDataEvent( *this, -1, -1, i_rowIndex, i_rowIndex ),
348 : &XGridDataListener::rowsRemoved,
349 : aGuard
350 6 : );
351 6 : }
352 :
353 :
354 1 : void SAL_CALL DefaultGridDataModel::removeAllRows( ) throw (RuntimeException, std::exception)
355 : {
356 1 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
357 :
358 1 : m_aRowHeaders.clear();
359 1 : m_aData.clear();
360 :
361 : broadcast(
362 : GridDataEvent( *this, -1, -1, -1, -1 ),
363 : &XGridDataListener::rowsRemoved,
364 : aGuard
365 1 : );
366 1 : }
367 :
368 :
369 4 : void SAL_CALL DefaultGridDataModel::updateCellData( ::sal_Int32 i_columnIndex, ::sal_Int32 i_rowIndex, const Any& i_value ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
370 : {
371 4 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
372 :
373 4 : impl_getCellDataAccess_throw( i_columnIndex, i_rowIndex ).first = i_value;
374 :
375 : broadcast(
376 : GridDataEvent( *this, i_columnIndex, i_columnIndex, i_rowIndex, i_rowIndex ),
377 : &XGridDataListener::dataChanged,
378 : aGuard
379 3 : );
380 3 : }
381 :
382 :
383 3 : void SAL_CALL DefaultGridDataModel::updateRowData( const Sequence< ::sal_Int32 >& i_columnIndexes, ::sal_Int32 i_rowIndex, const Sequence< Any >& i_values ) throw (IndexOutOfBoundsException, IllegalArgumentException, RuntimeException, std::exception)
384 : {
385 3 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
386 :
387 3 : if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
388 0 : throw IndexOutOfBoundsException( OUString(), *this );
389 :
390 3 : if ( i_columnIndexes.getLength() != i_values.getLength() )
391 1 : throw IllegalArgumentException( OUString(), *this, 1 );
392 :
393 2 : sal_Int32 const columnCount = i_columnIndexes.getLength();
394 2 : if ( columnCount == 0 )
395 1 : return;
396 :
397 5 : for ( sal_Int32 col = 0; col < columnCount; ++col )
398 : {
399 4 : if ( ( i_columnIndexes[col] < 0 ) || ( i_columnIndexes[col] > m_nColumnCount ) )
400 1 : throw IndexOutOfBoundsException( OUString(), *this );
401 : }
402 :
403 1 : RowData& rDataRow = m_aData[ i_rowIndex ];
404 4 : for ( sal_Int32 col = 0; col < columnCount; ++col )
405 : {
406 3 : sal_Int32 const columnIndex = i_columnIndexes[ col ];
407 3 : if ( size_t( columnIndex ) >= rDataRow.size() )
408 0 : rDataRow.resize( columnIndex + 1 );
409 :
410 3 : rDataRow[ columnIndex ].first = i_values[ col ];
411 : }
412 :
413 1 : sal_Int32 const firstAffectedColumn = *::std::min_element( i_columnIndexes.begin(), i_columnIndexes.end() );
414 1 : sal_Int32 const lastAffectedColumn = *::std::max_element( i_columnIndexes.begin(), i_columnIndexes.end() );
415 : broadcast(
416 : GridDataEvent( *this, firstAffectedColumn, lastAffectedColumn, i_rowIndex, i_rowIndex ),
417 : &XGridDataListener::dataChanged,
418 : aGuard
419 1 : );
420 : }
421 :
422 :
423 1 : void SAL_CALL DefaultGridDataModel::updateRowHeading( ::sal_Int32 i_rowIndex, const Any& i_heading ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
424 : {
425 1 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
426 :
427 1 : if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aRowHeaders.size() ) )
428 0 : throw IndexOutOfBoundsException( OUString(), *this );
429 :
430 1 : m_aRowHeaders[ i_rowIndex ] = i_heading;
431 :
432 : broadcast(
433 : GridDataEvent( *this, -1, -1, i_rowIndex, i_rowIndex ),
434 : &XGridDataListener::rowHeadingChanged,
435 : aGuard
436 1 : );
437 1 : }
438 :
439 :
440 0 : void SAL_CALL DefaultGridDataModel::updateCellToolTip( ::sal_Int32 i_columnIndex, ::sal_Int32 i_rowIndex, const Any& i_value ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
441 : {
442 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
443 0 : impl_getCellDataAccess_throw( i_columnIndex, i_rowIndex ).second = i_value;
444 0 : }
445 :
446 :
447 0 : void SAL_CALL DefaultGridDataModel::updateRowToolTip( ::sal_Int32 i_rowIndex, const Any& i_value ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
448 : {
449 0 : ::comphelper::ComponentGuard aGuard( *this, rBHelper );
450 :
451 0 : RowData& rRowData = impl_getRowDataAccess_throw( i_rowIndex, m_nColumnCount );
452 0 : for ( RowData::iterator cell = rRowData.begin(); cell != rRowData.end(); ++cell )
453 0 : cell->second = i_value;
454 0 : }
455 :
456 :
457 9 : void SAL_CALL DefaultGridDataModel::addGridDataListener( const Reference< grid::XGridDataListener >& i_listener ) throw (RuntimeException, std::exception)
458 : {
459 9 : rBHelper.addListener( cppu::UnoType<XGridDataListener>::get(), i_listener );
460 9 : }
461 :
462 :
463 5 : void SAL_CALL DefaultGridDataModel::removeGridDataListener( const Reference< grid::XGridDataListener >& i_listener ) throw (RuntimeException, std::exception)
464 : {
465 5 : rBHelper.removeListener( cppu::UnoType<XGridDataListener>::get(), i_listener );
466 5 : }
467 :
468 :
469 8 : void SAL_CALL DefaultGridDataModel::disposing()
470 : {
471 8 : ::com::sun::star::lang::EventObject aEvent;
472 8 : aEvent.Source.set( *this );
473 8 : rBHelper.aLC.disposeAndClear( aEvent );
474 :
475 16 : ::osl::MutexGuard aGuard( m_aMutex );
476 16 : GridData aEmptyData;
477 8 : m_aData.swap( aEmptyData );
478 :
479 16 : ::std::vector< Any > aEmptyRowHeaders;
480 8 : m_aRowHeaders.swap( aEmptyRowHeaders );
481 :
482 16 : m_nColumnCount = 0;
483 8 : }
484 :
485 :
486 1 : OUString SAL_CALL DefaultGridDataModel::getImplementationName( ) throw (RuntimeException, std::exception)
487 : {
488 1 : return OUString("stardiv.Toolkit.DefaultGridDataModel");
489 : }
490 :
491 0 : sal_Bool SAL_CALL DefaultGridDataModel::supportsService( const OUString& ServiceName ) throw (RuntimeException, std::exception)
492 : {
493 0 : return cppu::supportsService(this, ServiceName);
494 : }
495 :
496 1 : Sequence< OUString > SAL_CALL DefaultGridDataModel::getSupportedServiceNames( ) throw (RuntimeException, std::exception)
497 : {
498 1 : Sequence< OUString > aSeq( 1 );
499 1 : aSeq[0] = "com.sun.star.awt.grid.DefaultGridDataModel";
500 1 : return aSeq;
501 : }
502 :
503 :
504 1 : Reference< css::util::XCloneable > SAL_CALL DefaultGridDataModel::createClone( ) throw (RuntimeException, std::exception)
505 : {
506 1 : return new DefaultGridDataModel( *this );
507 : }
508 :
509 : }
510 :
511 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
512 12 : stardiv_Toolkit_DefaultGridDataModel_get_implementation(
513 : css::uno::XComponentContext *,
514 : css::uno::Sequence<css::uno::Any> const &)
515 : {
516 12 : return cppu::acquire(new DefaultGridDataModel());
517 798 : }
518 :
519 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|