Bump version to 6.4-15
[LibreOffice.git] / svx / source / table / tablerow.cxx
blobf7ca4d8d40d04ae77f40dc900b37de1b4676c401
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 for( auto& rpCell : maCells )
77 rpCell->dispose();
78 CellVector().swap(maCells);
83 void TableRow::throwIfDisposed() const
85 if( !mxTableModel.is() )
86 throw DisposedException();
90 TableRow& TableRow::operator=( const TableRow& r )
92 mnHeight = r.mnHeight;
93 mbOptimalHeight = r.mbOptimalHeight;
94 mbIsVisible = r.mbIsVisible;
95 mbIsStartOfNewPage = r.mbIsStartOfNewPage;
96 maName = r.maName;
97 mnRow = r.mnRow;
99 return *this;
103 void TableRow::insertColumns( sal_Int32 nIndex, sal_Int32 nCount, CellVector::iterator const * pIter /* = 0 */ )
105 throwIfDisposed();
106 if( nCount )
108 if( nIndex >= static_cast< sal_Int32 >( maCells.size() ) )
109 nIndex = static_cast< sal_Int32 >( maCells.size() );
110 if ( pIter )
111 maCells.insert( maCells.begin() + nIndex, *pIter, (*pIter) + nCount );
112 else
114 maCells.reserve( maCells.size() + nCount );
115 for ( sal_Int32 i = 0; i < nCount; i++ )
116 maCells.insert( maCells.begin() + nIndex + i, mxTableModel->createCell() );
122 void TableRow::removeColumns( sal_Int32 nIndex, sal_Int32 nCount )
124 throwIfDisposed();
125 if( (nCount >= 0) && ( nIndex >= 0) )
127 if( (nIndex + nCount) < static_cast< sal_Int32 >( maCells.size() ) )
129 CellVector::iterator aBegin( maCells.begin() );
130 std::advance(aBegin, nIndex);
132 if( nCount > 1 )
134 CellVector::iterator aEnd( aBegin );
135 while( nCount-- && (aEnd != maCells.end()) )
136 ++aEnd;
137 maCells.erase( aBegin, aEnd );
139 else
141 maCells.erase( aBegin );
144 else
146 maCells.resize( nIndex );
151 const TableModelRef& TableRow::getModel() const
153 return mxTableModel;
156 // XCellRange
159 Reference< XCell > SAL_CALL TableRow::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow )
161 throwIfDisposed();
162 if( nRow != 0 )
163 throw IndexOutOfBoundsException();
165 return mxTableModel->getCellByPosition( nColumn, mnRow );
169 Reference< XCellRange > SAL_CALL TableRow::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
171 throwIfDisposed();
172 if( (nLeft >= 0 ) && (nTop == 0) && (nRight >= nLeft) && (nBottom == 0) )
174 return mxTableModel->getCellRangeByPosition( nLeft, mnRow, nRight, mnRow );
176 throw IndexOutOfBoundsException();
180 Reference< XCellRange > SAL_CALL TableRow::getCellRangeByName( const OUString& /*aRange*/ )
182 throwIfDisposed();
183 return Reference< XCellRange >();
187 // XNamed
190 OUString SAL_CALL TableRow::getName()
192 return maName;
196 void SAL_CALL TableRow::setName( const OUString& aName )
198 maName = aName;
202 // XFastPropertySet
205 void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue )
207 if(!mxTableModel.is() || nullptr == mxTableModel->getSdrTableObj())
208 return;
210 SdrTableObj& rTableObj(*mxTableModel->getSdrTableObj());
211 SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
212 bool bOk(false);
213 bool bChange(false);
214 std::unique_ptr<TableRowUndo> pUndo;
215 const bool bUndo(rTableObj.IsInserted() && rModel.IsUndoEnabled());
217 if( bUndo )
219 TableRowRef xThis( this );
220 pUndo.reset(new TableRowUndo( xThis ));
223 switch( nHandle )
225 case Property_Height:
227 sal_Int32 nHeight = mnHeight;
228 bOk = aValue >>= nHeight;
229 if( bOk && (mnHeight != nHeight) )
231 mnHeight = nHeight;
232 mbOptimalHeight = mnHeight == 0;
233 bChange = true;
235 break;
238 case Property_OptimalHeight:
240 bool bOptimalHeight = mbOptimalHeight;
241 bOk = aValue >>= bOptimalHeight;
242 if( bOk && (mbOptimalHeight != bOptimalHeight) )
244 mbOptimalHeight = bOptimalHeight;
245 if( bOptimalHeight )
246 mnHeight = 0;
247 bChange = true;
249 break;
251 case Property_IsVisible:
253 bool bIsVisible = mbIsVisible;
254 bOk = aValue >>= bIsVisible;
255 if( bOk && (mbIsVisible != bIsVisible) )
257 mbIsVisible = bIsVisible;
258 bChange = true;
260 break;
263 case Property_IsStartOfNewPage:
265 bool bIsStartOfNewPage = mbIsStartOfNewPage;
266 bOk = aValue >>= bIsStartOfNewPage;
267 if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
269 mbIsStartOfNewPage = bIsStartOfNewPage;
270 bChange = true;
272 break;
274 default:
275 throw UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
278 if( !bOk )
280 throw IllegalArgumentException();
283 if( bChange )
285 if( pUndo )
287 rModel.AddUndo( std::move(pUndo) );
289 mxTableModel->setModified(true);
294 Any SAL_CALL TableRow::getFastPropertyValue( sal_Int32 nHandle )
296 switch( nHandle )
298 case Property_Height: return Any( mnHeight );
299 case Property_OptimalHeight: return Any( mbOptimalHeight );
300 case Property_IsVisible: return Any( mbIsVisible );
301 case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
302 default: throw UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
307 rtl::Reference< FastPropertySetInfo > TableRow::getStaticPropertySetInfo()
309 static rtl::Reference<FastPropertySetInfo> xInfo = []() {
310 PropertyVector aProperties(6);
312 aProperties[0].Name = "Height";
313 aProperties[0].Handle = Property_Height;
314 aProperties[0].Type = ::cppu::UnoType<sal_Int32>::get();
315 aProperties[0].Attributes = 0;
317 aProperties[1].Name = "OptimalHeight";
318 aProperties[1].Handle = Property_OptimalHeight;
319 aProperties[1].Type = cppu::UnoType<bool>::get();
320 aProperties[1].Attributes = 0;
322 aProperties[2].Name = "IsVisible";
323 aProperties[2].Handle = Property_IsVisible;
324 aProperties[2].Type = cppu::UnoType<bool>::get();
325 aProperties[2].Attributes = 0;
327 aProperties[3].Name = "IsStartOfNewPage";
328 aProperties[3].Handle = Property_IsStartOfNewPage;
329 aProperties[3].Type = cppu::UnoType<bool>::get();
330 aProperties[3].Attributes = 0;
332 aProperties[4].Name = "Size";
333 aProperties[4].Handle = Property_Height;
334 aProperties[4].Type = ::cppu::UnoType<sal_Int32>::get();
335 aProperties[4].Attributes = 0;
337 aProperties[5].Name = "OptimalSize";
338 aProperties[5].Handle = Property_OptimalHeight;
339 aProperties[5].Type = cppu::UnoType<bool>::get();
340 aProperties[5].Attributes = 0;
342 return rtl::Reference<FastPropertySetInfo>(new FastPropertySetInfo(aProperties));
343 }();
345 return xInfo;
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */