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>
24 #include "tablerow.hxx"
25 #include "tableundo.hxx"
26 #include "svx/svdmodel.hxx"
27 #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
;
39 namespace sdr
{ namespace 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;
50 TableRow::TableRow( const TableModelRef
& xTableModel
, sal_Int32 nRow
, sal_Int32 nColumns
)
51 : TableRowBase( getStaticPropertySetInfo() )
52 , mxTableModel( xTableModel
)
55 , mbOptimalHeight( true )
57 , mbIsStartOfNewPage( false )
60 maCells
.reserve( 20 );
64 maCells
.resize( nColumns
);
66 maCells
[ nColumns
] = mxTableModel
->createCell();
78 void TableRow::dispose()
81 if( !maCells
.empty() )
83 CellVector::iterator
aIter( maCells
.begin() );
84 while( aIter
!= maCells
.end() )
85 (*aIter
++)->dispose();
86 CellVector().swap(maCells
);
92 void TableRow::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException
)
94 if( !mxTableModel
.is() )
95 throw DisposedException();
100 TableRow
& TableRow::operator=( const TableRow
& r
)
102 mnHeight
= r
.mnHeight
;
103 mbOptimalHeight
= r
.mbOptimalHeight
;
104 mbIsVisible
= r
.mbIsVisible
;
105 mbIsStartOfNewPage
= r
.mbIsStartOfNewPage
;
114 void TableRow::insertColumns( sal_Int32 nIndex
, sal_Int32 nCount
, CellVector::iterator
* pIter
/* = 0 */ )
119 if( nIndex
>= static_cast< sal_Int32
>( maCells
.size() ) )
120 nIndex
= static_cast< sal_Int32
>( maCells
.size() );
122 maCells
.insert( maCells
.begin() + nIndex
, *pIter
, (*pIter
) + nCount
);
125 maCells
.reserve( maCells
.size() + nCount
);
126 for ( sal_Int32 i
= 0; i
< nCount
; i
++ )
127 maCells
.insert( maCells
.begin() + nIndex
+ i
, mxTableModel
->createCell() );
134 void TableRow::removeColumns( sal_Int32 nIndex
, sal_Int32 nCount
)
137 if( (nCount
>= 0) && ( nIndex
>= 0) )
139 if( (nIndex
+ nCount
) < static_cast< sal_Int32
>( maCells
.size() ) )
141 CellVector::iterator
aBegin( maCells
.begin() );
142 while( nIndex
-- && (aBegin
!= maCells
.end()) )
147 CellVector::iterator
aEnd( aBegin
);
148 while( nCount
-- && (aEnd
!= maCells
.end()) )
150 maCells
.erase( aBegin
, aEnd
);
154 maCells
.erase( aBegin
);
159 maCells
.resize( nIndex
);
168 Reference
< XCell
> SAL_CALL
TableRow::getCellByPosition( sal_Int32 nColumn
, sal_Int32 nRow
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
172 throw IndexOutOfBoundsException();
174 return mxTableModel
->getCellByPosition( nColumn
, mnRow
);
179 Reference
< XCellRange
> SAL_CALL
TableRow::getCellRangeByPosition( sal_Int32 nLeft
, sal_Int32 nTop
, sal_Int32 nRight
, sal_Int32 nBottom
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
182 if( (nLeft
>= 0 ) && (nTop
== 0) && (nRight
>= nLeft
) && (nBottom
== 0) )
184 return mxTableModel
->getCellRangeByPosition( nLeft
, mnRow
, nRight
, mnRow
);
186 throw IndexOutOfBoundsException();
191 Reference
< XCellRange
> SAL_CALL
TableRow::getCellRangeByName( const OUString
& /*aRange*/ ) throw (RuntimeException
, std::exception
)
194 return Reference
< XCellRange
>();
201 OUString SAL_CALL
TableRow::getName() throw (RuntimeException
, std::exception
)
208 void SAL_CALL
TableRow::setName( const OUString
& aName
) throw (RuntimeException
, std::exception
)
217 void SAL_CALL
TableRow::setFastPropertyValue( sal_Int32 nHandle
, const Any
& aValue
) throw (UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
, RuntimeException
, std::exception
)
220 bool bChange
= false;
222 TableRowUndo
* pUndo
= 0;
224 SdrModel
* pModel
= mxTableModel
->getSdrTableObj()->GetModel();
226 const bool bUndo
= mxTableModel
.is() && mxTableModel
->getSdrTableObj() && mxTableModel
->getSdrTableObj()->IsInserted() && pModel
&& pModel
->IsUndoEnabled();
230 TableRowRef
xThis( this );
231 pUndo
= new TableRowUndo( xThis
);
236 case Property_Height
:
238 sal_Int32 nHeight
= mnHeight
;
239 bOk
= aValue
>>= nHeight
;
240 if( bOk
&& (mnHeight
!= nHeight
) )
243 mbOptimalHeight
= mnHeight
== 0;
249 case Property_OptimalHeight
:
251 bool bOptimalHeight
= mbOptimalHeight
;
252 bOk
= aValue
>>= bOptimalHeight
;
253 if( bOk
&& (mbOptimalHeight
!= bOptimalHeight
) )
255 mbOptimalHeight
= bOptimalHeight
;
262 case Property_IsVisible
:
264 bool bIsVisible
= mbIsVisible
;
265 bOk
= aValue
>>= bIsVisible
;
266 if( bOk
&& (mbIsVisible
!= bIsVisible
) )
268 mbIsVisible
= bIsVisible
;
274 case Property_IsStartOfNewPage
:
276 bool bIsStartOfNewPage
= mbIsStartOfNewPage
;
277 bOk
= aValue
>>= bIsStartOfNewPage
;
278 if( bOk
&& (mbIsStartOfNewPage
!= bIsStartOfNewPage
) )
280 mbIsStartOfNewPage
= bIsStartOfNewPage
;
286 throw UnknownPropertyException();
289 throw IllegalArgumentException();
295 pModel
->AddUndo( pUndo
);
298 mxTableModel
->setModified(sal_True
);
306 Any SAL_CALL
TableRow::getFastPropertyValue( sal_Int32 nHandle
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
310 case Property_Height
: return Any( mnHeight
);
311 case Property_OptimalHeight
: return Any( mbOptimalHeight
);
312 case Property_IsVisible
: return Any( mbIsVisible
);
313 case Property_IsStartOfNewPage
: return Any( mbIsStartOfNewPage
);
314 default: throw UnknownPropertyException();
320 rtl::Reference
< FastPropertySetInfo
> TableRow::getStaticPropertySetInfo()
322 static rtl::Reference
< FastPropertySetInfo
> xInfo
;
325 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
328 PropertyVector
aProperties(6);
330 aProperties
[0].Name
= "Height";
331 aProperties
[0].Handle
= Property_Height
;
332 aProperties
[0].Type
= ::cppu::UnoType
<sal_Int32
>::get();
333 aProperties
[0].Attributes
= 0;
335 aProperties
[1].Name
= "OptimalHeight";
336 aProperties
[1].Handle
= Property_OptimalHeight
;
337 aProperties
[1].Type
= ::getBooleanCppuType();
338 aProperties
[1].Attributes
= 0;
340 aProperties
[2].Name
= "IsVisible";
341 aProperties
[2].Handle
= Property_IsVisible
;
342 aProperties
[2].Type
= ::getBooleanCppuType();
343 aProperties
[2].Attributes
= 0;
345 aProperties
[3].Name
= "IsStartOfNewPage";
346 aProperties
[3].Handle
= Property_IsStartOfNewPage
;
347 aProperties
[3].Type
= ::getBooleanCppuType();
348 aProperties
[3].Attributes
= 0;
350 aProperties
[4].Name
= "Size";
351 aProperties
[4].Handle
= Property_Height
;
352 aProperties
[4].Type
= ::cppu::UnoType
<sal_Int32
>::get();
353 aProperties
[4].Attributes
= 0;
355 aProperties
[5].Name
= "OptimalSize";
356 aProperties
[5].Handle
= Property_OptimalHeight
;
357 aProperties
[5].Type
= ::getBooleanCppuType();
358 aProperties
[5].Attributes
= 0;
360 xInfo
.set( new FastPropertySetInfo(aProperties
) );
372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */