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>
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::lang
;
33 using namespace ::com::sun::star::container
;
34 using namespace ::com::sun::star::table
;
35 using namespace ::com::sun::star::beans
;
38 namespace sdr
{ namespace table
{
40 const sal_Int32 Property_Height
= 0;
41 const sal_Int32 Property_OptimalHeight
= 1;
42 const sal_Int32 Property_IsVisible
= 2;
43 const sal_Int32 Property_IsStartOfNewPage
= 3;
45 TableRow::TableRow( const TableModelRef
& xTableModel
, sal_Int32 nRow
, sal_Int32 nColumns
)
46 : TableRowBase( getStaticPropertySetInfo() )
47 , mxTableModel( xTableModel
)
50 , mbOptimalHeight( true )
52 , mbIsStartOfNewPage( false )
55 maCells
.reserve( 20 );
59 maCells
.resize( nColumns
);
61 maCells
[ nColumns
] = mxTableModel
->createCell();
71 void TableRow::dispose()
74 if( !maCells
.empty() )
76 for( auto& rpCell
: maCells
)
78 CellVector().swap(maCells
);
83 void TableRow::throwIfDisposed() const
85 if( !mxTableModel
.is() )
86 throw DisposedException();
90 TableRow
& TableRow::operator=( const TableRow
& r
)
92 mnHeight
= r
.mnHeight
;
93 mbOptimalHeight
= r
.mbOptimalHeight
;
94 mbIsVisible
= r
.mbIsVisible
;
95 mbIsStartOfNewPage
= r
.mbIsStartOfNewPage
;
103 void TableRow::insertColumns( sal_Int32 nIndex
, sal_Int32 nCount
, CellVector::iterator
const * pIter
/* = 0 */ )
108 if( nIndex
>= static_cast< sal_Int32
>( maCells
.size() ) )
109 nIndex
= static_cast< sal_Int32
>( maCells
.size() );
111 maCells
.insert( maCells
.begin() + nIndex
, *pIter
, (*pIter
) + nCount
);
114 maCells
.reserve( maCells
.size() + nCount
);
115 for ( sal_Int32 i
= 0; i
< nCount
; i
++ )
116 maCells
.insert( maCells
.begin() + nIndex
+ i
, mxTableModel
->createCell() );
122 void TableRow::removeColumns( sal_Int32 nIndex
, sal_Int32 nCount
)
125 if( (nCount
>= 0) && ( nIndex
>= 0) )
127 if( (nIndex
+ nCount
) < static_cast< sal_Int32
>( maCells
.size() ) )
129 CellVector::iterator
aBegin( maCells
.begin() );
130 std::advance(aBegin
, nIndex
);
134 CellVector::iterator
aEnd( aBegin
);
135 while( nCount
-- && (aEnd
!= maCells
.end()) )
137 maCells
.erase( aBegin
, aEnd
);
141 maCells
.erase( aBegin
);
146 maCells
.resize( nIndex
);
151 const TableModelRef
& TableRow::getModel() const
159 Reference
< XCell
> SAL_CALL
TableRow::getCellByPosition( sal_Int32 nColumn
, sal_Int32 nRow
)
163 throw IndexOutOfBoundsException();
165 return mxTableModel
->getCellByPosition( nColumn
, mnRow
);
169 Reference
< XCellRange
> SAL_CALL
TableRow::getCellRangeByPosition( sal_Int32 nLeft
, sal_Int32 nTop
, sal_Int32 nRight
, sal_Int32 nBottom
)
172 if( (nLeft
>= 0 ) && (nTop
== 0) && (nRight
>= nLeft
) && (nBottom
== 0) )
174 return mxTableModel
->getCellRangeByPosition( nLeft
, mnRow
, nRight
, mnRow
);
176 throw IndexOutOfBoundsException();
180 Reference
< XCellRange
> SAL_CALL
TableRow::getCellRangeByName( const OUString
& /*aRange*/ )
183 return Reference
< XCellRange
>();
190 OUString SAL_CALL
TableRow::getName()
196 void SAL_CALL
TableRow::setName( const OUString
& aName
)
205 void SAL_CALL
TableRow::setFastPropertyValue( sal_Int32 nHandle
, const Any
& aValue
)
207 if(!mxTableModel
.is() || nullptr == mxTableModel
->getSdrTableObj())
210 SdrTableObj
& rTableObj(*mxTableModel
->getSdrTableObj());
211 SdrModel
& rModel(rTableObj
.getSdrModelFromSdrObject());
214 std::unique_ptr
<TableRowUndo
> pUndo
;
215 const bool bUndo(rTableObj
.IsInserted() && rModel
.IsUndoEnabled());
219 TableRowRef
xThis( this );
220 pUndo
.reset(new TableRowUndo( xThis
));
225 case Property_Height
:
227 sal_Int32 nHeight
= mnHeight
;
228 bOk
= aValue
>>= nHeight
;
229 if( bOk
&& (mnHeight
!= nHeight
) )
232 mbOptimalHeight
= mnHeight
== 0;
238 case Property_OptimalHeight
:
240 bool bOptimalHeight
= mbOptimalHeight
;
241 bOk
= aValue
>>= bOptimalHeight
;
242 if( bOk
&& (mbOptimalHeight
!= bOptimalHeight
) )
244 mbOptimalHeight
= bOptimalHeight
;
251 case Property_IsVisible
:
253 bool bIsVisible
= mbIsVisible
;
254 bOk
= aValue
>>= bIsVisible
;
255 if( bOk
&& (mbIsVisible
!= bIsVisible
) )
257 mbIsVisible
= bIsVisible
;
263 case Property_IsStartOfNewPage
:
265 bool bIsStartOfNewPage
= mbIsStartOfNewPage
;
266 bOk
= aValue
>>= bIsStartOfNewPage
;
267 if( bOk
&& (mbIsStartOfNewPage
!= bIsStartOfNewPage
) )
269 mbIsStartOfNewPage
= bIsStartOfNewPage
;
275 throw UnknownPropertyException( OUString::number(nHandle
), static_cast<cppu::OWeakObject
*>(this));
280 throw IllegalArgumentException();
287 rModel
.AddUndo( std::move(pUndo
) );
289 mxTableModel
->setModified(true);
294 Any SAL_CALL
TableRow::getFastPropertyValue( sal_Int32 nHandle
)
298 case Property_Height
: return Any( mnHeight
);
299 case Property_OptimalHeight
: return Any( mbOptimalHeight
);
300 case Property_IsVisible
: return Any( mbIsVisible
);
301 case Property_IsStartOfNewPage
: return Any( mbIsStartOfNewPage
);
302 default: throw UnknownPropertyException( OUString::number(nHandle
), static_cast<cppu::OWeakObject
*>(this));
307 rtl::Reference
< FastPropertySetInfo
> TableRow::getStaticPropertySetInfo()
309 static rtl::Reference
<FastPropertySetInfo
> xInfo
= []() {
310 PropertyVector
aProperties(6);
312 aProperties
[0].Name
= "Height";
313 aProperties
[0].Handle
= Property_Height
;
314 aProperties
[0].Type
= ::cppu::UnoType
<sal_Int32
>::get();
315 aProperties
[0].Attributes
= 0;
317 aProperties
[1].Name
= "OptimalHeight";
318 aProperties
[1].Handle
= Property_OptimalHeight
;
319 aProperties
[1].Type
= cppu::UnoType
<bool>::get();
320 aProperties
[1].Attributes
= 0;
322 aProperties
[2].Name
= "IsVisible";
323 aProperties
[2].Handle
= Property_IsVisible
;
324 aProperties
[2].Type
= cppu::UnoType
<bool>::get();
325 aProperties
[2].Attributes
= 0;
327 aProperties
[3].Name
= "IsStartOfNewPage";
328 aProperties
[3].Handle
= Property_IsStartOfNewPage
;
329 aProperties
[3].Type
= cppu::UnoType
<bool>::get();
330 aProperties
[3].Attributes
= 0;
332 aProperties
[4].Name
= "Size";
333 aProperties
[4].Handle
= Property_Height
;
334 aProperties
[4].Type
= ::cppu::UnoType
<sal_Int32
>::get();
335 aProperties
[4].Attributes
= 0;
337 aProperties
[5].Name
= "OptimalSize";
338 aProperties
[5].Handle
= Property_OptimalHeight
;
339 aProperties
[5].Type
= cppu::UnoType
<bool>::get();
340 aProperties
[5].Attributes
= 0;
342 return rtl::Reference
<FastPropertySetInfo
>(new FastPropertySetInfo(aProperties
));
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */