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