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 :
21 : #include <com/sun/star/lang/DisposedException.hpp>
22 :
23 : #include "cell.hxx"
24 : #include "tablerow.hxx"
25 : #include "tableundo.hxx"
26 : #include "svx/svdmodel.hxx"
27 : #include "svx/svdotable.hxx"
28 :
29 : // -----------------------------------------------------------------------------
30 :
31 : using ::rtl::OUString;
32 : using namespace ::com::sun::star::uno;
33 : using namespace ::com::sun::star::lang;
34 : using namespace ::com::sun::star::container;
35 : using namespace ::com::sun::star::table;
36 : using namespace ::com::sun::star::beans;
37 :
38 : // -----------------------------------------------------------------------------
39 :
40 : namespace sdr { namespace table {
41 :
42 : const sal_Int32 Property_Height = 0;
43 : const sal_Int32 Property_OptimalHeight = 1;
44 : const sal_Int32 Property_IsVisible = 2;
45 : const sal_Int32 Property_IsStartOfNewPage = 3;
46 :
47 : // -----------------------------------------------------------------------------
48 : // TableRow
49 : // -----------------------------------------------------------------------------
50 :
51 83 : TableRow::TableRow( const TableModelRef& xTableModel, sal_Int32 nRow, sal_Int32 nColumns )
52 : : TableRowBase( getStaticPropertySetInfo() )
53 : , mxTableModel( xTableModel )
54 : , mnRow( nRow )
55 : , mnHeight( 0 )
56 : , mbOptimalHeight( sal_True )
57 : , mbIsVisible( sal_True )
58 83 : , mbIsStartOfNewPage( sal_False )
59 : {
60 83 : if( nColumns < 20 )
61 83 : maCells.reserve( 20 );
62 :
63 83 : if( nColumns )
64 : {
65 83 : maCells.resize( nColumns );
66 249 : while( nColumns-- )
67 83 : maCells[ nColumns ] = mxTableModel->createCell();
68 : }
69 83 : }
70 :
71 : // -----------------------------------------------------------------------------
72 :
73 166 : TableRow::~TableRow()
74 : {
75 166 : }
76 :
77 : // -----------------------------------------------------------------------------
78 :
79 83 : void TableRow::dispose()
80 : {
81 83 : mxTableModel.clear();
82 83 : if( !maCells.empty() )
83 : {
84 83 : CellVector::iterator aIter( maCells.begin() );
85 573 : while( aIter != maCells.end() )
86 407 : (*aIter++)->dispose();
87 83 : CellVector().swap(maCells);
88 : }
89 83 : }
90 :
91 : // -----------------------------------------------------------------------------
92 :
93 74 : void TableRow::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException)
94 : {
95 74 : if( !mxTableModel.is() )
96 0 : throw DisposedException();
97 74 : }
98 :
99 : // -----------------------------------------------------------------------------
100 :
101 0 : TableRow& TableRow::operator=( const TableRow& r )
102 : {
103 0 : mnHeight = r.mnHeight;
104 0 : mbOptimalHeight = r.mbOptimalHeight;
105 0 : mbIsVisible = r.mbIsVisible;
106 0 : mbIsStartOfNewPage = r.mbIsStartOfNewPage;
107 0 : maName = r.maName;
108 0 : mnRow = r.mnRow;
109 :
110 0 : return *this;
111 : }
112 :
113 : // -----------------------------------------------------------------------------
114 :
115 74 : void TableRow::insertColumns( sal_Int32 nIndex, sal_Int32 nCount, CellVector::iterator* pIter /* = 0 */ )
116 : {
117 74 : throwIfDisposed();
118 74 : if( nCount )
119 : {
120 74 : if( nIndex >= static_cast< sal_Int32 >( maCells.size() ) )
121 1 : nIndex = static_cast< sal_Int32 >( maCells.size() );
122 74 : if ( pIter )
123 0 : maCells.insert( maCells.begin() + nIndex, *pIter, (*pIter) + nCount );
124 : else
125 : {
126 74 : maCells.reserve( maCells.size() + nCount );
127 398 : for ( sal_Int32 i = 0; i < nCount; i++ )
128 324 : maCells.insert( maCells.begin() + nIndex + i, mxTableModel->createCell() );
129 : }
130 : }
131 74 : }
132 :
133 : // -----------------------------------------------------------------------------
134 :
135 0 : void TableRow::removeColumns( sal_Int32 nIndex, sal_Int32 nCount )
136 : {
137 0 : throwIfDisposed();
138 0 : if( (nCount >= 0) && ( nIndex >= 0) )
139 : {
140 0 : if( (nIndex + nCount) < static_cast< sal_Int32 >( maCells.size() ) )
141 : {
142 0 : CellVector::iterator aBegin( maCells.begin() );
143 0 : while( nIndex-- && (aBegin != maCells.end()) )
144 0 : aBegin++;
145 :
146 0 : if( nCount > 1 )
147 : {
148 0 : CellVector::iterator aEnd( aBegin );
149 0 : while( nCount-- && (aEnd != maCells.end()) )
150 0 : aEnd++;
151 0 : maCells.erase( aBegin, aEnd );
152 : }
153 : else
154 : {
155 0 : maCells.erase( aBegin );
156 : }
157 : }
158 : else
159 : {
160 0 : maCells.resize( nIndex );
161 : }
162 : }
163 0 : }
164 :
165 : // -----------------------------------------------------------------------------
166 : // XCellRange
167 : // -----------------------------------------------------------------------------
168 :
169 0 : Reference< XCell > SAL_CALL TableRow::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException)
170 : {
171 0 : throwIfDisposed();
172 0 : if( nRow != 0 )
173 0 : throw IndexOutOfBoundsException();
174 :
175 0 : return mxTableModel->getCellByPosition( nColumn, mnRow );
176 : }
177 :
178 : // -----------------------------------------------------------------------------
179 :
180 0 : Reference< XCellRange > SAL_CALL TableRow::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (IndexOutOfBoundsException, RuntimeException)
181 : {
182 0 : throwIfDisposed();
183 0 : if( (nLeft >= 0 ) && (nTop == 0) && (nRight >= nLeft) && (nBottom == 0) )
184 : {
185 0 : return mxTableModel->getCellRangeByPosition( nLeft, mnRow, nRight, mnRow );
186 : }
187 0 : throw IndexOutOfBoundsException();
188 : }
189 :
190 : // -----------------------------------------------------------------------------
191 :
192 0 : Reference< XCellRange > SAL_CALL TableRow::getCellRangeByName( const OUString& /*aRange*/ ) throw (RuntimeException)
193 : {
194 0 : throwIfDisposed();
195 0 : return Reference< XCellRange >();
196 : }
197 :
198 : // -----------------------------------------------------------------------------
199 : // XNamed
200 : // -----------------------------------------------------------------------------
201 :
202 0 : OUString SAL_CALL TableRow::getName() throw (RuntimeException)
203 : {
204 0 : return maName;
205 : }
206 :
207 : // -----------------------------------------------------------------------------
208 :
209 0 : void SAL_CALL TableRow::setName( const OUString& aName ) throw (RuntimeException)
210 : {
211 0 : maName = aName;
212 0 : }
213 :
214 : // -----------------------------------------------------------------------------
215 : // XFastPropertySet
216 : // -----------------------------------------------------------------------------
217 :
218 195 : void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException)
219 : {
220 195 : bool bOk = false;
221 195 : bool bChange = false;
222 :
223 195 : TableRowUndo* pUndo = 0;
224 :
225 195 : SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();
226 :
227 195 : const bool bUndo = mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled();
228 :
229 195 : if( bUndo )
230 : {
231 0 : TableRowRef xThis( this );
232 0 : pUndo = new TableRowUndo( xThis );
233 : }
234 :
235 195 : switch( nHandle )
236 : {
237 : case Property_Height:
238 : {
239 195 : sal_Int32 nHeight = mnHeight;
240 195 : bOk = aValue >>= nHeight;
241 195 : if( bOk && (mnHeight != nHeight) )
242 : {
243 167 : mnHeight = nHeight;
244 167 : mbOptimalHeight = mnHeight == 0;
245 167 : bChange = true;
246 : }
247 : break;
248 : }
249 :
250 : case Property_OptimalHeight:
251 : {
252 0 : sal_Bool bOptimalHeight = mbOptimalHeight;
253 0 : bOk = aValue >>= bOptimalHeight;
254 0 : if( bOk && (mbOptimalHeight != bOptimalHeight) )
255 : {
256 0 : mbOptimalHeight = bOptimalHeight;
257 0 : if( bOptimalHeight )
258 0 : mnHeight = 0;
259 0 : bChange = true;
260 : }
261 : break;
262 : }
263 : case Property_IsVisible:
264 : {
265 0 : sal_Bool bIsVisible = mbIsVisible;
266 0 : bOk = aValue >>= bIsVisible;
267 0 : if( bOk && (mbIsVisible != bIsVisible) )
268 : {
269 0 : mbIsVisible = bIsVisible;
270 0 : bChange = true;
271 : }
272 : break;
273 : }
274 :
275 : case Property_IsStartOfNewPage:
276 : {
277 0 : sal_Bool bIsStartOfNewPage = mbIsStartOfNewPage;
278 0 : bOk = aValue >>= bIsStartOfNewPage;
279 0 : if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
280 : {
281 0 : mbIsStartOfNewPage = bIsStartOfNewPage;
282 0 : bChange = true;
283 : }
284 : break;
285 : }
286 : default:
287 0 : throw UnknownPropertyException();
288 : }
289 195 : if( !bOk )
290 0 : throw IllegalArgumentException();
291 :
292 195 : if( bChange )
293 : {
294 167 : if( pUndo )
295 : {
296 0 : pModel->AddUndo( pUndo );
297 0 : pUndo = 0;
298 : }
299 167 : mxTableModel->setModified(sal_True);
300 : }
301 :
302 195 : if( pUndo )
303 0 : delete pUndo;
304 195 : }
305 :
306 : // -----------------------------------------------------------------------------
307 :
308 591 : Any SAL_CALL TableRow::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
309 : {
310 591 : switch( nHandle )
311 : {
312 278 : case Property_Height: return Any( mnHeight );
313 313 : case Property_OptimalHeight: return Any( mbOptimalHeight );
314 0 : case Property_IsVisible: return Any( mbIsVisible );
315 0 : case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
316 0 : default: throw UnknownPropertyException();
317 : }
318 : }
319 :
320 : // -----------------------------------------------------------------------------
321 :
322 83 : rtl::Reference< FastPropertySetInfo > TableRow::getStaticPropertySetInfo()
323 : {
324 83 : static rtl::Reference< FastPropertySetInfo > xInfo;
325 83 : if( !xInfo.is() )
326 : {
327 2 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
328 2 : if( !xInfo.is() )
329 : {
330 2 : PropertyVector aProperties(6);
331 :
332 2 : aProperties[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" ) );
333 2 : aProperties[0].Handle = Property_Height;
334 2 : aProperties[0].Type = ::getCppuType((const sal_Int32*)0);
335 2 : aProperties[0].Attributes = 0;
336 :
337 2 : aProperties[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalHeight" ) );
338 2 : aProperties[1].Handle = Property_OptimalHeight;
339 2 : aProperties[1].Type = ::getBooleanCppuType();
340 2 : aProperties[1].Attributes = 0;
341 :
342 2 : aProperties[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) );
343 2 : aProperties[2].Handle = Property_IsVisible;
344 2 : aProperties[2].Type = ::getBooleanCppuType();
345 2 : aProperties[2].Attributes = 0;
346 :
347 2 : aProperties[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" ) );
348 2 : aProperties[3].Handle = Property_IsStartOfNewPage;
349 2 : aProperties[3].Type = ::getBooleanCppuType();
350 2 : aProperties[3].Attributes = 0;
351 :
352 2 : aProperties[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) );
353 2 : aProperties[4].Handle = Property_Height;
354 2 : aProperties[4].Type = ::getCppuType((const sal_Int32*)0);
355 2 : aProperties[4].Attributes = 0;
356 :
357 2 : aProperties[5].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalSize" ) );
358 2 : aProperties[5].Handle = Property_OptimalHeight;
359 2 : aProperties[5].Type = ::getBooleanCppuType();
360 2 : aProperties[5].Attributes = 0;
361 :
362 2 : xInfo.set( new FastPropertySetInfo(aProperties) );
363 2 : }
364 : }
365 :
366 83 : return xInfo;
367 : }
368 :
369 : // -----------------------------------------------------------------------------
370 :
371 :
372 : } }
373 :
374 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|