Adjust includes
[LibreOffice.git] / svx / source / table / tablerow.cxx
blob43010ad698fe8905a6640a063534716ae468c8a0
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>
22 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24 #include <cell.hxx>
25 #include "tablerow.hxx"
26 #include "tableundo.hxx"
27 #include <svx/svdmodel.hxx>
28 #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;
38 namespace sdr { namespace table {
40 const sal_Int32 Property_Height = 0;
41 const sal_Int32 Property_OptimalHeight = 1;
42 const sal_Int32 Property_IsVisible = 2;
43 const sal_Int32 Property_IsStartOfNewPage = 3;
45 TableRow::TableRow( const TableModelRef& xTableModel, sal_Int32 nRow, sal_Int32 nColumns )
46 : TableRowBase( getStaticPropertySetInfo() )
47 , mxTableModel( xTableModel )
48 , mnRow( nRow )
49 , mnHeight( 0 )
50 , mbOptimalHeight( true )
51 , mbIsVisible( true )
52 , mbIsStartOfNewPage( false )
54 if( nColumns < 20 )
55 maCells.reserve( 20 );
57 if( nColumns )
59 maCells.resize( nColumns );
60 while( nColumns-- )
61 maCells[ nColumns ] = mxTableModel->createCell();
66 TableRow::~TableRow()
71 void TableRow::dispose()
73 mxTableModel.clear();
74 if( !maCells.empty() )
76 CellVector::iterator aIter( maCells.begin() );
77 while( aIter != maCells.end() )
78 (*aIter++)->dispose();
79 CellVector().swap(maCells);
84 void TableRow::throwIfDisposed() const
86 if( !mxTableModel.is() )
87 throw DisposedException();
91 TableRow& TableRow::operator=( const TableRow& r )
93 mnHeight = r.mnHeight;
94 mbOptimalHeight = r.mbOptimalHeight;
95 mbIsVisible = r.mbIsVisible;
96 mbIsStartOfNewPage = r.mbIsStartOfNewPage;
97 maName = r.maName;
98 mnRow = r.mnRow;
100 return *this;
104 void TableRow::insertColumns( sal_Int32 nIndex, sal_Int32 nCount, CellVector::iterator const * pIter /* = 0 */ )
106 throwIfDisposed();
107 if( nCount )
109 if( nIndex >= static_cast< sal_Int32 >( maCells.size() ) )
110 nIndex = static_cast< sal_Int32 >( maCells.size() );
111 if ( pIter )
112 maCells.insert( maCells.begin() + nIndex, *pIter, (*pIter) + nCount );
113 else
115 maCells.reserve( maCells.size() + nCount );
116 for ( sal_Int32 i = 0; i < nCount; i++ )
117 maCells.insert( maCells.begin() + nIndex + i, mxTableModel->createCell() );
123 void TableRow::removeColumns( sal_Int32 nIndex, sal_Int32 nCount )
125 throwIfDisposed();
126 if( (nCount >= 0) && ( nIndex >= 0) )
128 if( (nIndex + nCount) < static_cast< sal_Int32 >( maCells.size() ) )
130 CellVector::iterator aBegin( maCells.begin() );
131 while( nIndex-- && (aBegin != maCells.end()) )
132 ++aBegin;
134 if( nCount > 1 )
136 CellVector::iterator aEnd( aBegin );
137 while( nCount-- && (aEnd != maCells.end()) )
138 ++aEnd;
139 maCells.erase( aBegin, aEnd );
141 else
143 maCells.erase( aBegin );
146 else
148 maCells.resize( nIndex );
153 const TableModelRef& TableRow::getModel() const
155 return mxTableModel;
158 // XCellRange
161 Reference< XCell > SAL_CALL TableRow::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow )
163 throwIfDisposed();
164 if( nRow != 0 )
165 throw IndexOutOfBoundsException();
167 return mxTableModel->getCellByPosition( nColumn, mnRow );
171 Reference< XCellRange > SAL_CALL TableRow::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
173 throwIfDisposed();
174 if( (nLeft >= 0 ) && (nTop == 0) && (nRight >= nLeft) && (nBottom == 0) )
176 return mxTableModel->getCellRangeByPosition( nLeft, mnRow, nRight, mnRow );
178 throw IndexOutOfBoundsException();
182 Reference< XCellRange > SAL_CALL TableRow::getCellRangeByName( const OUString& /*aRange*/ )
184 throwIfDisposed();
185 return Reference< XCellRange >();
189 // XNamed
192 OUString SAL_CALL TableRow::getName()
194 return maName;
198 void SAL_CALL TableRow::setName( const OUString& aName )
200 maName = aName;
204 // XFastPropertySet
207 void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue )
209 bool bOk = false;
210 bool bChange = false;
212 TableRowUndo* pUndo = nullptr;
214 SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();
216 const bool bUndo = mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled();
218 if( bUndo )
220 TableRowRef xThis( this );
221 pUndo = new TableRowUndo( xThis );
224 switch( nHandle )
226 case Property_Height:
228 sal_Int32 nHeight = mnHeight;
229 bOk = aValue >>= nHeight;
230 if( bOk && (mnHeight != nHeight) )
232 mnHeight = nHeight;
233 mbOptimalHeight = mnHeight == 0;
234 bChange = true;
236 break;
239 case Property_OptimalHeight:
241 bool bOptimalHeight = mbOptimalHeight;
242 bOk = aValue >>= bOptimalHeight;
243 if( bOk && (mbOptimalHeight != bOptimalHeight) )
245 mbOptimalHeight = bOptimalHeight;
246 if( bOptimalHeight )
247 mnHeight = 0;
248 bChange = true;
250 break;
252 case Property_IsVisible:
254 bool bIsVisible = mbIsVisible;
255 bOk = aValue >>= bIsVisible;
256 if( bOk && (mbIsVisible != bIsVisible) )
258 mbIsVisible = bIsVisible;
259 bChange = true;
261 break;
264 case Property_IsStartOfNewPage:
266 bool bIsStartOfNewPage = mbIsStartOfNewPage;
267 bOk = aValue >>= bIsStartOfNewPage;
268 if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
270 mbIsStartOfNewPage = bIsStartOfNewPage;
271 bChange = true;
273 break;
275 default:
276 delete pUndo;
277 throw UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
279 if( !bOk )
281 delete pUndo;
282 throw IllegalArgumentException();
285 if( bChange )
287 if( pUndo )
289 pModel->AddUndo( pUndo );
290 pUndo = nullptr;
292 mxTableModel->setModified(true);
295 delete pUndo;
299 Any SAL_CALL TableRow::getFastPropertyValue( sal_Int32 nHandle )
301 switch( nHandle )
303 case Property_Height: return Any( mnHeight );
304 case Property_OptimalHeight: return Any( mbOptimalHeight );
305 case Property_IsVisible: return Any( mbIsVisible );
306 case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
307 default: throw UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
312 rtl::Reference< FastPropertySetInfo > TableRow::getStaticPropertySetInfo()
314 static rtl::Reference< FastPropertySetInfo > xInfo;
315 if( !xInfo.is() )
317 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
318 if( !xInfo.is() )
320 PropertyVector aProperties(6);
322 aProperties[0].Name = "Height";
323 aProperties[0].Handle = Property_Height;
324 aProperties[0].Type = ::cppu::UnoType<sal_Int32>::get();
325 aProperties[0].Attributes = 0;
327 aProperties[1].Name = "OptimalHeight";
328 aProperties[1].Handle = Property_OptimalHeight;
329 aProperties[1].Type = cppu::UnoType<bool>::get();
330 aProperties[1].Attributes = 0;
332 aProperties[2].Name = "IsVisible";
333 aProperties[2].Handle = Property_IsVisible;
334 aProperties[2].Type = cppu::UnoType<bool>::get();
335 aProperties[2].Attributes = 0;
337 aProperties[3].Name = "IsStartOfNewPage";
338 aProperties[3].Handle = Property_IsStartOfNewPage;
339 aProperties[3].Type = cppu::UnoType<bool>::get();
340 aProperties[3].Attributes = 0;
342 aProperties[4].Name = "Size";
343 aProperties[4].Handle = Property_Height;
344 aProperties[4].Type = ::cppu::UnoType<sal_Int32>::get();
345 aProperties[4].Attributes = 0;
347 aProperties[5].Name = "OptimalSize";
348 aProperties[5].Handle = Property_OptimalHeight;
349 aProperties[5].Type = cppu::UnoType<bool>::get();
350 aProperties[5].Attributes = 0;
352 xInfo.set( new FastPropertySetInfo(aProperties) );
356 return xInfo;
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */