1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
25 #include "tablerow.hxx"
26 #include "tableundo.hxx"
27 #include <svx/svdmodel.hxx>
28 #include <svx/svdotable.hxx>
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
))
51 , mbOptimalHeight( true )
53 , mbIsStartOfNewPage( false )
56 maCells
.reserve( 20 );
60 maCells
.resize( nColumns
);
62 maCells
[ nColumns
] = mxTableModel
->createCell();
72 void TableRow::dispose()
75 if( !maCells
.empty() )
77 for( auto& rpCell
: maCells
)
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
;
104 void TableRow::insertColumns( sal_Int32 nIndex
, sal_Int32 nCount
, CellVector::iterator
const * pIter
/* = 0 */ )
110 if( nIndex
>= static_cast< sal_Int32
>( maCells
.size() ) )
111 nIndex
= static_cast< sal_Int32
>( maCells
.size() );
113 maCells
.insert( maCells
.begin() + nIndex
, *pIter
, (*pIter
) + nCount
);
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
)
126 if( (nCount
< 0) || ( nIndex
< 0))
129 if( (nIndex
+ nCount
) < static_cast< sal_Int32
>( maCells
.size() ) )
131 CellVector::iterator
aBegin( maCells
.begin() );
132 std::advance(aBegin
, nIndex
);
136 CellVector::iterator
aEnd( aBegin
);
137 while( nCount
-- && (aEnd
!= maCells
.end()) )
139 maCells
.erase( aBegin
, aEnd
);
143 maCells
.erase( aBegin
);
148 maCells
.resize( nIndex
);
152 const TableModelRef
& TableRow::getModel() const
160 Reference
< XCell
> SAL_CALL
TableRow::getCellByPosition( sal_Int32 nColumn
, sal_Int32 nRow
)
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
)
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*/ )
184 return Reference
< XCellRange
>();
191 OUString SAL_CALL
TableRow::getName()
197 void SAL_CALL
TableRow::setName( const OUString
& aName
)
206 void SAL_CALL
TableRow::setFastPropertyValue( sal_Int32 nHandle
, const Any
& aValue
)
208 if(!mxTableModel
.is() || nullptr == mxTableModel
->getSdrTableObj())
211 SdrTableObj
& rTableObj(*mxTableModel
->getSdrTableObj());
212 SdrModel
& rModel(rTableObj
.getSdrModelFromSdrObject());
215 std::unique_ptr
<TableRowUndo
> pUndo
;
216 const bool bUndo(rTableObj
.IsInserted() && rModel
.IsUndoEnabled());
220 TableRowRef
xThis( this );
221 pUndo
.reset(new TableRowUndo( xThis
));
226 case Property_Height
:
228 sal_Int32 nHeight
= mnHeight
;
229 bOk
= aValue
>>= nHeight
;
230 if( bOk
&& (mnHeight
!= nHeight
) )
233 mbOptimalHeight
= mnHeight
== 0;
239 case Property_OptimalHeight
:
241 bool bOptimalHeight
= mbOptimalHeight
;
242 bOk
= aValue
>>= bOptimalHeight
;
243 if( bOk
&& (mbOptimalHeight
!= bOptimalHeight
) )
245 mbOptimalHeight
= bOptimalHeight
;
252 case Property_IsVisible
:
254 bool bIsVisible
= mbIsVisible
;
255 bOk
= aValue
>>= bIsVisible
;
256 if( bOk
&& (mbIsVisible
!= bIsVisible
) )
258 mbIsVisible
= bIsVisible
;
264 case Property_IsStartOfNewPage
:
266 bool bIsStartOfNewPage
= mbIsStartOfNewPage
;
267 bOk
= aValue
>>= bIsStartOfNewPage
;
268 if( bOk
&& (mbIsStartOfNewPage
!= bIsStartOfNewPage
) )
270 mbIsStartOfNewPage
= bIsStartOfNewPage
;
276 throw UnknownPropertyException( OUString::number(nHandle
), getXWeak());
281 throw IllegalArgumentException();
288 rModel
.AddUndo( std::move(pUndo
) );
290 mxTableModel
->setModified(true);
295 Any SAL_CALL
TableRow::getFastPropertyValue( sal_Int32 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
));
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */