fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svx / source / table / tablerow.cxx
blob195a895781e5eee2f64557c12e6f321cc48d2eea
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <com/sun/star/lang/DisposedException.hpp>
23 #include "cell.hxx"
24 #include "tablerow.hxx"
25 #include "tableundo.hxx"
26 #include "svx/svdmodel.hxx"
27 #include "svx/svdotable.hxx"
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::container;
34 using namespace ::com::sun::star::table;
35 using namespace ::com::sun::star::beans;
39 namespace sdr { namespace table {
41 const sal_Int32 Property_Height = 0;
42 const sal_Int32 Property_OptimalHeight = 1;
43 const sal_Int32 Property_IsVisible = 2;
44 const sal_Int32 Property_IsStartOfNewPage = 3;
46 TableRow::TableRow( const TableModelRef& xTableModel, sal_Int32 nRow, sal_Int32 nColumns )
47 : TableRowBase( getStaticPropertySetInfo() )
48 , mxTableModel( xTableModel )
49 , mnRow( nRow )
50 , mnHeight( 0 )
51 , mbOptimalHeight( true )
52 , mbIsVisible( true )
53 , mbIsStartOfNewPage( false )
55 if( nColumns < 20 )
56 maCells.reserve( 20 );
58 if( nColumns )
60 maCells.resize( nColumns );
61 while( nColumns-- )
62 maCells[ nColumns ] = mxTableModel->createCell();
68 TableRow::~TableRow()
74 void TableRow::dispose()
76 mxTableModel.clear();
77 if( !maCells.empty() )
79 CellVector::iterator aIter( maCells.begin() );
80 while( aIter != maCells.end() )
81 (*aIter++)->dispose();
82 CellVector().swap(maCells);
88 void TableRow::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException)
90 if( !mxTableModel.is() )
91 throw DisposedException();
96 TableRow& TableRow::operator=( const TableRow& r )
98 mnHeight = r.mnHeight;
99 mbOptimalHeight = r.mbOptimalHeight;
100 mbIsVisible = r.mbIsVisible;
101 mbIsStartOfNewPage = r.mbIsStartOfNewPage;
102 maName = r.maName;
103 mnRow = r.mnRow;
105 return *this;
110 void TableRow::insertColumns( sal_Int32 nIndex, sal_Int32 nCount, CellVector::iterator* pIter /* = 0 */ )
112 throwIfDisposed();
113 if( nCount )
115 if( nIndex >= static_cast< sal_Int32 >( maCells.size() ) )
116 nIndex = static_cast< sal_Int32 >( maCells.size() );
117 if ( pIter )
118 maCells.insert( maCells.begin() + nIndex, *pIter, (*pIter) + nCount );
119 else
121 maCells.reserve( maCells.size() + nCount );
122 for ( sal_Int32 i = 0; i < nCount; i++ )
123 maCells.insert( maCells.begin() + nIndex + i, mxTableModel->createCell() );
130 void TableRow::removeColumns( sal_Int32 nIndex, sal_Int32 nCount )
132 throwIfDisposed();
133 if( (nCount >= 0) && ( nIndex >= 0) )
135 if( (nIndex + nCount) < static_cast< sal_Int32 >( maCells.size() ) )
137 CellVector::iterator aBegin( maCells.begin() );
138 while( nIndex-- && (aBegin != maCells.end()) )
139 ++aBegin;
141 if( nCount > 1 )
143 CellVector::iterator aEnd( aBegin );
144 while( nCount-- && (aEnd != maCells.end()) )
145 ++aEnd;
146 maCells.erase( aBegin, aEnd );
148 else
150 maCells.erase( aBegin );
153 else
155 maCells.resize( nIndex );
161 // XCellRange
164 Reference< XCell > SAL_CALL TableRow::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
166 throwIfDisposed();
167 if( nRow != 0 )
168 throw IndexOutOfBoundsException();
170 return mxTableModel->getCellByPosition( nColumn, mnRow );
175 Reference< XCellRange > SAL_CALL TableRow::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
177 throwIfDisposed();
178 if( (nLeft >= 0 ) && (nTop == 0) && (nRight >= nLeft) && (nBottom == 0) )
180 return mxTableModel->getCellRangeByPosition( nLeft, mnRow, nRight, mnRow );
182 throw IndexOutOfBoundsException();
187 Reference< XCellRange > SAL_CALL TableRow::getCellRangeByName( const OUString& /*aRange*/ ) throw (RuntimeException, std::exception)
189 throwIfDisposed();
190 return Reference< XCellRange >();
194 // XNamed
197 OUString SAL_CALL TableRow::getName() throw (RuntimeException, std::exception)
199 return maName;
204 void SAL_CALL TableRow::setName( const OUString& aName ) throw (RuntimeException, std::exception)
206 maName = aName;
210 // XFastPropertySet
213 void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException, std::exception)
215 bool bOk = false;
216 bool bChange = false;
218 TableRowUndo* pUndo = 0;
220 SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();
222 const bool bUndo = mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled();
224 if( bUndo )
226 TableRowRef xThis( this );
227 pUndo = new TableRowUndo( xThis );
230 switch( nHandle )
232 case Property_Height:
234 sal_Int32 nHeight = mnHeight;
235 bOk = aValue >>= nHeight;
236 if( bOk && (mnHeight != nHeight) )
238 mnHeight = nHeight;
239 mbOptimalHeight = mnHeight == 0;
240 bChange = true;
242 break;
245 case Property_OptimalHeight:
247 bool bOptimalHeight = mbOptimalHeight;
248 bOk = aValue >>= bOptimalHeight;
249 if( bOk && (mbOptimalHeight != bOptimalHeight) )
251 mbOptimalHeight = bOptimalHeight;
252 if( bOptimalHeight )
253 mnHeight = 0;
254 bChange = true;
256 break;
258 case Property_IsVisible:
260 bool bIsVisible = mbIsVisible;
261 bOk = aValue >>= bIsVisible;
262 if( bOk && (mbIsVisible != bIsVisible) )
264 mbIsVisible = bIsVisible;
265 bChange = true;
267 break;
270 case Property_IsStartOfNewPage:
272 bool bIsStartOfNewPage = mbIsStartOfNewPage;
273 bOk = aValue >>= bIsStartOfNewPage;
274 if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
276 mbIsStartOfNewPage = bIsStartOfNewPage;
277 bChange = true;
279 break;
281 default:
282 delete pUndo;
283 throw UnknownPropertyException();
285 if( !bOk )
287 delete pUndo;
288 throw IllegalArgumentException();
291 if( bChange )
293 if( pUndo )
295 pModel->AddUndo( pUndo );
296 pUndo = 0;
298 mxTableModel->setModified(sal_True);
301 delete pUndo;
306 Any SAL_CALL TableRow::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
308 switch( nHandle )
310 case Property_Height: return Any( mnHeight );
311 case Property_OptimalHeight: return Any( mbOptimalHeight );
312 case Property_IsVisible: return Any( mbIsVisible );
313 case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
314 default: throw UnknownPropertyException();
320 rtl::Reference< FastPropertySetInfo > TableRow::getStaticPropertySetInfo()
322 static rtl::Reference< FastPropertySetInfo > xInfo;
323 if( !xInfo.is() )
325 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
326 if( !xInfo.is() )
328 PropertyVector aProperties(6);
330 aProperties[0].Name = "Height";
331 aProperties[0].Handle = Property_Height;
332 aProperties[0].Type = ::cppu::UnoType<sal_Int32>::get();
333 aProperties[0].Attributes = 0;
335 aProperties[1].Name = "OptimalHeight";
336 aProperties[1].Handle = Property_OptimalHeight;
337 aProperties[1].Type = cppu::UnoType<bool>::get();
338 aProperties[1].Attributes = 0;
340 aProperties[2].Name = "IsVisible";
341 aProperties[2].Handle = Property_IsVisible;
342 aProperties[2].Type = cppu::UnoType<bool>::get();
343 aProperties[2].Attributes = 0;
345 aProperties[3].Name = "IsStartOfNewPage";
346 aProperties[3].Handle = Property_IsStartOfNewPage;
347 aProperties[3].Type = cppu::UnoType<bool>::get();
348 aProperties[3].Attributes = 0;
350 aProperties[4].Name = "Size";
351 aProperties[4].Handle = Property_Height;
352 aProperties[4].Type = ::cppu::UnoType<sal_Int32>::get();
353 aProperties[4].Attributes = 0;
355 aProperties[5].Name = "OptimalSize";
356 aProperties[5].Handle = Property_OptimalHeight;
357 aProperties[5].Type = cppu::UnoType<bool>::get();
358 aProperties[5].Attributes = 0;
360 xInfo.set( new FastPropertySetInfo(aProperties) );
364 return xInfo;
372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */