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 <sdr/properties/cellproperties.hxx>
28 #include <svx/svdmodel.hxx>
29 #include <svx/svdotable.hxx>
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::com::sun::star::container
;
36 using namespace ::com::sun::star::table
;
37 using namespace ::com::sun::star::beans
;
40 namespace sdr::table
{
42 const sal_Int32 Property_Height
= 0;
43 const sal_Int32 Property_OptimalHeight
= 1;
44 const sal_Int32 Property_IsVisible
= 2;
45 const sal_Int32 Property_IsStartOfNewPage
= 3;
47 TableRow::TableRow( TableModelRef xTableModel
, sal_Int32 nRow
, sal_Int32 nColumns
)
48 : TableRowBase( getStaticPropertySetInfo() )
49 , mxTableModel(std::move( xTableModel
))
52 , mbOptimalHeight( true )
54 , mbIsStartOfNewPage( false )
57 maCells
.reserve( 20 );
61 maCells
.resize( nColumns
);
63 maCells
[ nColumns
] = mxTableModel
->createCell();
73 void TableRow::dispose()
76 if( !maCells
.empty() )
78 for( auto& rpCell
: maCells
)
80 CellVector().swap(maCells
);
85 void TableRow::throwIfDisposed() const
87 if( !mxTableModel
.is() )
88 throw DisposedException();
92 TableRow
& TableRow::operator=( const TableRow
& r
)
94 mnHeight
= r
.mnHeight
;
95 mbOptimalHeight
= r
.mbOptimalHeight
;
96 mbIsVisible
= r
.mbIsVisible
;
97 mbIsStartOfNewPage
= r
.mbIsStartOfNewPage
;
105 void TableRow::insertColumns( sal_Int32 nIndex
, sal_Int32 nCount
, CellVector::iterator
const * pIter
/* = 0 */ )
111 if( nIndex
>= static_cast< sal_Int32
>( maCells
.size() ) )
112 nIndex
= static_cast< sal_Int32
>( maCells
.size() );
114 maCells
.insert( maCells
.begin() + nIndex
, *pIter
, (*pIter
) + nCount
);
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() );
124 void TableRow::removeColumns( sal_Int32 nIndex
, sal_Int32 nCount
)
127 if( (nCount
< 0) || ( nIndex
< 0))
130 if( (nIndex
+ nCount
) < static_cast< sal_Int32
>( maCells
.size() ) )
132 CellVector::iterator
aBegin( maCells
.begin() );
133 std::advance(aBegin
, nIndex
);
137 CellVector::iterator
aEnd( aBegin
);
138 while( nCount
-- && (aEnd
!= maCells
.end()) )
140 maCells
.erase( aBegin
, aEnd
);
144 maCells
.erase( aBegin
);
149 maCells
.resize( nIndex
);
153 const TableModelRef
& TableRow::getModel() const
161 Reference
< XCell
> SAL_CALL
TableRow::getCellByPosition( sal_Int32 nColumn
, sal_Int32 nRow
)
165 throw IndexOutOfBoundsException();
167 return mxTableModel
->getCellByPosition( nColumn
, mnRow
);
171 Reference
< XCellRange
> SAL_CALL
TableRow::getCellRangeByPosition( sal_Int32 nLeft
, sal_Int32 nTop
, sal_Int32 nRight
, sal_Int32 nBottom
)
174 if( (nLeft
>= 0 ) && (nTop
== 0) && (nRight
>= nLeft
) && (nBottom
== 0) )
176 return mxTableModel
->getCellRangeByPosition( nLeft
, mnRow
, nRight
, mnRow
);
178 throw IndexOutOfBoundsException();
182 Reference
< XCellRange
> SAL_CALL
TableRow::getCellRangeByName( const OUString
& /*aRange*/ )
185 return Reference
< XCellRange
>();
192 OUString SAL_CALL
TableRow::getName()
198 void SAL_CALL
TableRow::setName( const OUString
& aName
)
207 void SAL_CALL
TableRow::setFastPropertyValue( sal_Int32 nHandle
, const Any
& aValue
)
209 if(!mxTableModel
.is() || nullptr == mxTableModel
->getSdrTableObj())
212 SdrTableObj
& rTableObj(*mxTableModel
->getSdrTableObj());
213 SdrModel
& rModel(rTableObj
.getSdrModelFromSdrObject());
216 std::unique_ptr
<TableRowUndo
> pUndo
;
217 const bool bUndo(rTableObj
.IsInserted() && rModel
.IsUndoEnabled());
221 TableRowRef
xThis( this );
222 pUndo
.reset(new TableRowUndo( xThis
));
227 case Property_Height
:
229 sal_Int32 nHeight
= mnHeight
;
230 bOk
= aValue
>>= nHeight
;
231 if( bOk
&& (mnHeight
!= nHeight
) )
234 mbOptimalHeight
= mnHeight
== 0;
240 case Property_OptimalHeight
:
242 bool bOptimalHeight
= mbOptimalHeight
;
243 bOk
= aValue
>>= bOptimalHeight
;
244 if( bOk
&& (mbOptimalHeight
!= bOptimalHeight
) )
246 mbOptimalHeight
= bOptimalHeight
;
253 case Property_IsVisible
:
255 bool bIsVisible
= mbIsVisible
;
256 bOk
= aValue
>>= bIsVisible
;
257 if( bOk
&& (mbIsVisible
!= bIsVisible
) )
259 mbIsVisible
= bIsVisible
;
265 case Property_IsStartOfNewPage
:
267 bool bIsStartOfNewPage
= mbIsStartOfNewPage
;
268 bOk
= aValue
>>= bIsStartOfNewPage
;
269 if( bOk
&& (mbIsStartOfNewPage
!= bIsStartOfNewPage
) )
271 mbIsStartOfNewPage
= bIsStartOfNewPage
;
277 throw UnknownPropertyException( OUString::number(nHandle
), static_cast<cppu::OWeakObject
*>(this));
282 throw IllegalArgumentException();
289 rModel
.AddUndo( std::move(pUndo
) );
291 mxTableModel
->setModified(true);
296 Any SAL_CALL
TableRow::getFastPropertyValue( sal_Int32 nHandle
)
300 case Property_Height
: return Any( mnHeight
);
301 case Property_OptimalHeight
: return Any( mbOptimalHeight
);
302 case Property_IsVisible
: return Any( mbIsVisible
);
303 case Property_IsStartOfNewPage
: return Any( mbIsStartOfNewPage
);
304 default: throw UnknownPropertyException( OUString::number(nHandle
), static_cast<cppu::OWeakObject
*>(this));
309 rtl::Reference
< FastPropertySetInfo
> TableRow::getStaticPropertySetInfo()
311 static rtl::Reference
<FastPropertySetInfo
> xInfo
= []() {
312 PropertyVector
aProperties(6);
314 aProperties
[0].Name
= "Height";
315 aProperties
[0].Handle
= Property_Height
;
316 aProperties
[0].Type
= ::cppu::UnoType
<sal_Int32
>::get();
317 aProperties
[0].Attributes
= 0;
319 aProperties
[1].Name
= "OptimalHeight";
320 aProperties
[1].Handle
= Property_OptimalHeight
;
321 aProperties
[1].Type
= cppu::UnoType
<bool>::get();
322 aProperties
[1].Attributes
= 0;
324 aProperties
[2].Name
= "IsVisible";
325 aProperties
[2].Handle
= Property_IsVisible
;
326 aProperties
[2].Type
= cppu::UnoType
<bool>::get();
327 aProperties
[2].Attributes
= 0;
329 aProperties
[3].Name
= "IsStartOfNewPage";
330 aProperties
[3].Handle
= Property_IsStartOfNewPage
;
331 aProperties
[3].Type
= cppu::UnoType
<bool>::get();
332 aProperties
[3].Attributes
= 0;
334 aProperties
[4].Name
= "Size";
335 aProperties
[4].Handle
= Property_Height
;
336 aProperties
[4].Type
= ::cppu::UnoType
<sal_Int32
>::get();
337 aProperties
[4].Attributes
= 0;
339 aProperties
[5].Name
= "OptimalSize";
340 aProperties
[5].Handle
= Property_OptimalHeight
;
341 aProperties
[5].Type
= cppu::UnoType
<bool>::get();
342 aProperties
[5].Attributes
= 0;
344 return rtl::Reference
<FastPropertySetInfo
>(new FastPropertySetInfo(aProperties
));
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */