tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / svx / source / table / tablerow.cxx
blobd755f587af209dba08987db8be334029575f36a6
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>
29 #include <utility>
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;
39 namespace sdr::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( TableModelRef xTableModel, sal_Int32 nRow, sal_Int32 nColumns )
47 : TableRowBase( getStaticPropertySetInfo() )
48 , mxTableModel(std::move( 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();
67 TableRow::~TableRow()
72 void TableRow::dispose()
74 mxTableModel.clear();
75 if( !maCells.empty() )
77 for( auto& rpCell : maCells )
78 rpCell->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 )
108 return;
110 if( nIndex >= static_cast< sal_Int32 >( maCells.size() ) )
111 nIndex = static_cast< sal_Int32 >( maCells.size() );
112 if ( pIter )
113 maCells.insert( maCells.begin() + nIndex, *pIter, (*pIter) + nCount );
114 else
116 maCells.reserve( std::max<size_t>(maCells.size() + nCount, maCells.size() * 2) );
117 for ( sal_Int32 i = 0; i < nCount; i++ )
118 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))
127 return;
129 if( (nIndex + nCount) < static_cast< sal_Int32 >( maCells.size() ) )
131 CellVector::iterator aBegin( maCells.begin() );
132 std::advance(aBegin, nIndex);
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 );
152 const TableModelRef& TableRow::getModel() const
154 return mxTableModel;
157 // XCellRange
160 Reference< XCell > SAL_CALL TableRow::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow )
162 throwIfDisposed();
163 if( nRow != 0 )
164 throw IndexOutOfBoundsException();
166 return mxTableModel->getCellByPosition( nColumn, mnRow );
170 Reference< XCellRange > SAL_CALL TableRow::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
172 throwIfDisposed();
173 if( (nLeft >= 0 ) && (nTop == 0) && (nRight >= nLeft) && (nBottom == 0) )
175 return mxTableModel->getCellRangeByPosition( nLeft, mnRow, nRight, mnRow );
177 throw IndexOutOfBoundsException();
181 Reference< XCellRange > SAL_CALL TableRow::getCellRangeByName( const OUString& /*aRange*/ )
183 throwIfDisposed();
184 return Reference< XCellRange >();
188 // XNamed
191 OUString SAL_CALL TableRow::getName()
193 return maName;
197 void SAL_CALL TableRow::setName( const OUString& aName )
199 maName = aName;
203 // XFastPropertySet
206 void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue )
208 if(!mxTableModel.is() || nullptr == mxTableModel->getSdrTableObj())
209 return;
211 SdrTableObj& rTableObj(*mxTableModel->getSdrTableObj());
212 SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
213 bool bOk(false);
214 bool bChange(false);
215 std::unique_ptr<TableRowUndo> pUndo;
216 const bool bUndo(rTableObj.IsInserted() && rModel.IsUndoEnabled());
218 if( bUndo )
220 TableRowRef xThis( this );
221 pUndo.reset(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 throw UnknownPropertyException( OUString::number(nHandle), getXWeak());
279 if( !bOk )
281 throw IllegalArgumentException();
284 if( bChange )
286 if( pUndo )
288 rModel.AddUndo( std::move(pUndo) );
290 mxTableModel->setModified(true);
295 Any SAL_CALL TableRow::getFastPropertyValue( sal_Int32 nHandle )
297 switch( nHandle )
299 case Property_Height: return Any( mnHeight );
300 case Property_OptimalHeight: return Any( mbOptimalHeight );
301 case Property_IsVisible: return Any( mbIsVisible );
302 case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
303 default: throw UnknownPropertyException( OUString::number(nHandle), getXWeak());
308 rtl::Reference< FastPropertySetInfo > TableRow::getStaticPropertySetInfo()
310 static rtl::Reference<FastPropertySetInfo> xInfo = []() {
311 PropertyVector aProperties(6);
313 aProperties[0].Name = "Height";
314 aProperties[0].Handle = Property_Height;
315 aProperties[0].Type = ::cppu::UnoType<sal_Int32>::get();
316 aProperties[0].Attributes = 0;
318 aProperties[1].Name = "OptimalHeight";
319 aProperties[1].Handle = Property_OptimalHeight;
320 aProperties[1].Type = cppu::UnoType<bool>::get();
321 aProperties[1].Attributes = 0;
323 aProperties[2].Name = "IsVisible";
324 aProperties[2].Handle = Property_IsVisible;
325 aProperties[2].Type = cppu::UnoType<bool>::get();
326 aProperties[2].Attributes = 0;
328 aProperties[3].Name = "IsStartOfNewPage";
329 aProperties[3].Handle = Property_IsStartOfNewPage;
330 aProperties[3].Type = cppu::UnoType<bool>::get();
331 aProperties[3].Attributes = 0;
333 aProperties[4].Name = "Size";
334 aProperties[4].Handle = Property_Height;
335 aProperties[4].Type = ::cppu::UnoType<sal_Int32>::get();
336 aProperties[4].Attributes = 0;
338 aProperties[5].Name = "OptimalSize";
339 aProperties[5].Handle = Property_OptimalHeight;
340 aProperties[5].Type = cppu::UnoType<bool>::get();
341 aProperties[5].Attributes = 0;
343 return rtl::Reference<FastPropertySetInfo>(new FastPropertySetInfo(aProperties));
344 }();
346 return xInfo;
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */