LibreOffice Module svx (master) 1
tablerow.cxx
Go to the documentation of this file.
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#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23
24#include <cell.hxx>
25#include "tablerow.hxx"
26#include "tableundo.hxx"
28#include <svx/svdmodel.hxx>
29#include <svx/svdotable.hxx>
30#include <utility>
31
32
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::lang;
35using namespace ::com::sun::star::container;
36using namespace ::com::sun::star::table;
37using namespace ::com::sun::star::beans;
38
39
40namespace sdr::table {
41
42const sal_Int32 Property_Height = 0;
43const sal_Int32 Property_OptimalHeight = 1;
44const sal_Int32 Property_IsVisible = 2;
45const sal_Int32 Property_IsStartOfNewPage = 3;
46
47TableRow::TableRow( TableModelRef xTableModel, sal_Int32 nRow, sal_Int32 nColumns )
48: TableRowBase( getStaticPropertySetInfo() )
49, mxTableModel(std::move( xTableModel ))
50, mnRow( nRow )
51, mnHeight( 0 )
52, mbOptimalHeight( true )
53, mbIsVisible( true )
54, mbIsStartOfNewPage( false )
55{
56 if( nColumns < 20 )
57 maCells.reserve( 20 );
58
59 if( nColumns )
60 {
61 maCells.resize( nColumns );
62 while( nColumns-- )
63 maCells[ nColumns ] = mxTableModel->createCell();
64 }
65}
66
67
69{
70}
71
72
74{
75 mxTableModel.clear();
76 if( !maCells.empty() )
77 {
78 for( auto& rpCell : maCells )
79 rpCell->dispose();
80 CellVector().swap(maCells);
81 }
82}
83
84
86{
87 if( !mxTableModel.is() )
88 throw DisposedException();
89}
90
91
93{
98 maName = r.maName;
99 mnRow = r.mnRow;
100
101 return *this;
102}
103
104
105void TableRow::insertColumns( sal_Int32 nIndex, sal_Int32 nCount, CellVector::iterator const * pIter /* = 0 */ )
106{
108 if( !nCount )
109 return;
110
111 if( nIndex >= static_cast< sal_Int32 >( maCells.size() ) )
112 nIndex = static_cast< sal_Int32 >( maCells.size() );
113 if ( pIter )
114 maCells.insert( maCells.begin() + nIndex, *pIter, (*pIter) + nCount );
115 else
116 {
117 maCells.reserve( std::max<size_t>(maCells.size() + nCount, maCells.size() * 2) );
118 for ( sal_Int32 i = 0; i < nCount; i++ )
119 maCells.insert( maCells.begin() + nIndex + i, mxTableModel->createCell() );
120 }
121}
122
123
124void TableRow::removeColumns( sal_Int32 nIndex, sal_Int32 nCount )
125{
127 if( (nCount < 0) || ( nIndex < 0))
128 return;
129
130 if( (nIndex + nCount) < static_cast< sal_Int32 >( maCells.size() ) )
131 {
132 CellVector::iterator aBegin( maCells.begin() );
133 std::advance(aBegin, nIndex);
134
135 if( nCount > 1 )
136 {
137 CellVector::iterator aEnd( aBegin );
138 while( nCount-- && (aEnd != maCells.end()) )
139 ++aEnd;
140 maCells.erase( aBegin, aEnd );
141 }
142 else
143 {
144 maCells.erase( aBegin );
145 }
146 }
147 else
148 {
149 maCells.resize( nIndex );
150 }
151}
152
154{
155 return mxTableModel;
156}
157
158// XCellRange
159
160
161Reference< XCell > SAL_CALL TableRow::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow )
162{
164 if( nRow != 0 )
165 throw IndexOutOfBoundsException();
166
167 return mxTableModel->getCellByPosition( nColumn, mnRow );
168}
169
170
171Reference< XCellRange > SAL_CALL TableRow::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
172{
174 if( (nLeft >= 0 ) && (nTop == 0) && (nRight >= nLeft) && (nBottom == 0) )
175 {
176 return mxTableModel->getCellRangeByPosition( nLeft, mnRow, nRight, mnRow );
177 }
178 throw IndexOutOfBoundsException();
179}
180
181
182Reference< XCellRange > SAL_CALL TableRow::getCellRangeByName( const OUString& /*aRange*/ )
183{
185 return Reference< XCellRange >();
186}
187
188
189// XNamed
190
191
192OUString SAL_CALL TableRow::getName()
193{
194 return maName;
195}
196
197
198void SAL_CALL TableRow::setName( const OUString& aName )
199{
200 maName = aName;
201}
202
203
204// XFastPropertySet
205
206
207void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue )
208{
209 if(!mxTableModel.is() || nullptr == mxTableModel->getSdrTableObj())
210 return;
211
212 SdrTableObj& rTableObj(*mxTableModel->getSdrTableObj());
213 SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
214 bool bOk(false);
215 bool bChange(false);
216 std::unique_ptr<TableRowUndo> pUndo;
217 const bool bUndo(rTableObj.IsInserted() && rModel.IsUndoEnabled());
218
219 if( bUndo )
220 {
221 TableRowRef xThis( this );
222 pUndo.reset(new TableRowUndo( xThis ));
223 }
224
225 switch( nHandle )
226 {
227 case Property_Height:
228 {
229 sal_Int32 nHeight = mnHeight;
230 bOk = aValue >>= nHeight;
231 if( bOk && (mnHeight != nHeight) )
232 {
233 mnHeight = nHeight;
235 bChange = true;
236 }
237 break;
238 }
239
241 {
242 bool bOptimalHeight = mbOptimalHeight;
243 bOk = aValue >>= bOptimalHeight;
244 if( bOk && (mbOptimalHeight != bOptimalHeight) )
245 {
246 mbOptimalHeight = bOptimalHeight;
247 if( bOptimalHeight )
248 mnHeight = 0;
249 bChange = true;
250 }
251 break;
252 }
254 {
255 bool bIsVisible = mbIsVisible;
256 bOk = aValue >>= bIsVisible;
257 if( bOk && (mbIsVisible != bIsVisible) )
258 {
259 mbIsVisible = bIsVisible;
260 bChange = true;
261 }
262 break;
263 }
264
266 {
267 bool bIsStartOfNewPage = mbIsStartOfNewPage;
268 bOk = aValue >>= bIsStartOfNewPage;
269 if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
270 {
271 mbIsStartOfNewPage = bIsStartOfNewPage;
272 bChange = true;
273 }
274 break;
275 }
276 default:
277 throw UnknownPropertyException( OUString::number(nHandle), getXWeak());
278 }
279
280 if( !bOk )
281 {
282 throw IllegalArgumentException();
283 }
284
285 if( bChange )
286 {
287 if( pUndo )
288 {
289 rModel.AddUndo( std::move(pUndo) );
290 }
291 mxTableModel->setModified(true);
292 }
293}
294
295
296Any SAL_CALL TableRow::getFastPropertyValue( sal_Int32 nHandle )
297{
298 switch( nHandle )
299 {
300 case Property_Height: return Any( mnHeight );
302 case Property_IsVisible: return Any( mbIsVisible );
304 default: throw UnknownPropertyException( OUString::number(nHandle), getXWeak());
305 }
306}
307
308
310{
311 static rtl::Reference<FastPropertySetInfo> xInfo = []() {
313
314 aProperties[0].Name = "Height";
315 aProperties[0].Handle = Property_Height;
317 aProperties[0].Attributes = 0;
318
319 aProperties[1].Name = "OptimalHeight";
322 aProperties[1].Attributes = 0;
323
324 aProperties[2].Name = "IsVisible";
327 aProperties[2].Attributes = 0;
328
329 aProperties[3].Name = "IsStartOfNewPage";
332 aProperties[3].Attributes = 0;
333
334 aProperties[4].Name = "Size";
335 aProperties[4].Handle = Property_Height;
337 aProperties[4].Attributes = 0;
338
339 aProperties[5].Name = "OptimalSize";
342 aProperties[5].Attributes = 0;
343
345 }();
346
347 return xInfo;
348}
349
350
351}
352
353/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
Definition: svdmodel.cxx:516
bool IsUndoEnabled() const
returns true if undo is currently enabled This returns false if undo was disabled using EnableUndo( f...
Definition: svdmodel.cxx:547
SdrModel & getSdrModelFromSdrObject() const
Definition: svdobj.cxx:289
bool IsInserted() const
Definition: svdobj.hxx:750
css::uno::Type const & get()
TableRow & operator=(const TableRow &)
Definition: tablerow.cxx:92
virtual void SAL_CALL setName(const OUString &aName) override
Definition: tablerow.cxx:198
virtual OUString SAL_CALL getName() override
Definition: tablerow.cxx:192
virtual css::uno::Any SAL_CALL getFastPropertyValue(::sal_Int32 nHandle) override
Definition: tablerow.cxx:296
virtual ~TableRow() override
Definition: tablerow.cxx:68
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByPosition(sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom) override
Definition: tablerow.cxx:171
sal_Int32 mnHeight
Definition: tablerow.hxx:73
static rtl::Reference< FastPropertySetInfo > getStaticPropertySetInfo()
Definition: tablerow.cxx:309
CellVector maCells
Definition: tablerow.hxx:71
void throwIfDisposed() const
Definition: tablerow.cxx:85
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByName(const OUString &aRange) override
Definition: tablerow.cxx:182
virtual css::uno::Reference< css::table::XCell > SAL_CALL getCellByPosition(sal_Int32 nColumn, sal_Int32 nRow) override
Definition: tablerow.cxx:161
friend class TableRowUndo
Definition: tablerow.hxx:38
TableModelRef mxTableModel
Definition: tablerow.hxx:70
TableRow(TableModelRef xTableModel, sal_Int32 nRow, sal_Int32 nColumns)
Definition: tablerow.cxx:47
void insertColumns(sal_Int32 nIndex, sal_Int32 nCount, CellVector::iterator const *pIter)
Definition: tablerow.cxx:105
const TableModelRef & getModel() const
Reference to the table model containing this row.
Definition: tablerow.cxx:153
void removeColumns(sal_Int32 nIndex, sal_Int32 nCount)
Definition: tablerow.cxx:124
virtual void SAL_CALL setFastPropertyValue(::sal_Int32 nHandle, const css::uno::Any &aValue) override
Definition: tablerow.cxx:207
int nCount
sal_Int32 mnRow
sal_Int32 nIndex
OUString aName
int i
std::vector< css::beans::Property > PropertyVector
Definition: propertyset.hxx:35
std::vector< CellRef > CellVector
Definition: celltypes.hxx:38
const sal_Int32 Property_OptimalHeight
Definition: tablerow.cxx:43
const sal_Int32 Property_IsStartOfNewPage
Definition: tablecolumn.cxx:45
const sal_Int32 Property_Height
Definition: tablerow.cxx:42
const sal_Int32 Property_IsVisible
Definition: tablecolumn.cxx:44
sal_Int32 nHandle
double mnHeight