1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tablerow.cxx,v $
10 * $Revision: 1.3.148.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <com/sun/star/lang/DisposedException.hpp>
37 #include "tablerow.hxx"
38 #include "tableundo.hxx"
39 #include "svx/svdmodel.hxx"
40 #include "svx/svdotable.hxx"
42 // -----------------------------------------------------------------------------
44 using ::rtl::OUString
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::lang
;
47 using namespace ::com::sun::star::container
;
48 using namespace ::com::sun::star::table
;
49 using namespace ::com::sun::star::beans
;
51 // -----------------------------------------------------------------------------
53 namespace sdr
{ namespace table
{
55 const sal_Int32 Property_Height
= 0;
56 const sal_Int32 Property_OptimalHeight
= 1;
57 const sal_Int32 Property_IsVisible
= 2;
58 const sal_Int32 Property_IsStartOfNewPage
= 3;
60 // -----------------------------------------------------------------------------
62 // -----------------------------------------------------------------------------
64 TableRow::TableRow( const TableModelRef
& xTableModel
, sal_Int32 nRow
, sal_Int32 nColumns
)
65 : TableRowBase( getStaticPropertySetInfo() )
66 , mxTableModel( xTableModel
)
69 , mbOptimalHeight( sal_True
)
70 , mbIsVisible( sal_True
)
71 , mbIsStartOfNewPage( sal_False
)
74 maCells
.reserve( 20 );
78 maCells
.resize( nColumns
);
80 maCells
[ nColumns
] = mxTableModel
->createCell();
84 // -----------------------------------------------------------------------------
90 // -----------------------------------------------------------------------------
92 void TableRow::dispose()
95 if( !maCells
.empty() )
97 CellVector::iterator
aIter( maCells
.begin() );
98 while( aIter
!= maCells
.end() )
99 (*aIter
++)->dispose();
100 CellVector().swap(maCells
);
104 // -----------------------------------------------------------------------------
106 void TableRow::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException
)
108 if( !mxTableModel
.is() )
109 throw DisposedException();
112 // -----------------------------------------------------------------------------
114 TableRow
& TableRow::operator=( const TableRow
& r
)
116 mnHeight
= r
.mnHeight
;
117 mbOptimalHeight
= r
.mbOptimalHeight
;
118 mbIsVisible
= r
.mbIsVisible
;
119 mbIsStartOfNewPage
= r
.mbIsStartOfNewPage
;
125 // -----------------------------------------------------------------------------
127 void TableRow::insertColumns( sal_Int32 nIndex
, sal_Int32 nCount
, CellVector::iterator
* pIter
/* = 0 */ )
132 if( nIndex
>= static_cast< sal_Int32
>( maCells
.size() ) )
133 nIndex
= static_cast< sal_Int32
>( maCells
.size() );
135 maCells
.insert( maCells
.begin() + nIndex
, *pIter
, (*pIter
) + nCount
);
138 maCells
.reserve( maCells
.size() + nCount
);
139 for ( sal_Int32 i
= 0; i
< nCount
; i
++ )
140 maCells
.insert( maCells
.begin() + nIndex
+ i
, mxTableModel
->createCell() );
145 // -----------------------------------------------------------------------------
147 void TableRow::removeColumns( sal_Int32 nIndex
, sal_Int32 nCount
)
150 if( (nCount
>= 0) && ( nIndex
>= 0) )
152 if( (nIndex
+ nCount
) < static_cast< sal_Int32
>( maCells
.size() ) )
154 CellVector::iterator
aBegin( maCells
.begin() );
155 while( nIndex
-- && (aBegin
!= maCells
.end()) )
160 CellVector::iterator
aEnd( aBegin
);
161 while( nCount
-- && (aEnd
!= maCells
.end()) )
163 maCells
.erase( aBegin
, aEnd
);
167 maCells
.erase( aBegin
);
172 maCells
.resize( nIndex
);
177 // -----------------------------------------------------------------------------
179 // -----------------------------------------------------------------------------
181 Reference
< XCell
> SAL_CALL
TableRow::getCellByPosition( sal_Int32 nColumn
, sal_Int32 nRow
) throw (IndexOutOfBoundsException
, RuntimeException
)
185 throw IndexOutOfBoundsException();
187 return mxTableModel
->getCellByPosition( nColumn
, mnRow
);
190 // -----------------------------------------------------------------------------
192 Reference
< XCellRange
> SAL_CALL
TableRow::getCellRangeByPosition( sal_Int32 nLeft
, sal_Int32 nTop
, sal_Int32 nRight
, sal_Int32 nBottom
) throw (IndexOutOfBoundsException
, RuntimeException
)
195 if( (nLeft
>= 0 ) && (nTop
== 0) && (nRight
>= nLeft
) && (nBottom
== 0) )
197 return mxTableModel
->getCellRangeByPosition( nLeft
, mnRow
, nRight
, mnRow
);
199 throw IndexOutOfBoundsException();
202 // -----------------------------------------------------------------------------
204 Reference
< XCellRange
> SAL_CALL
TableRow::getCellRangeByName( const OUString
& /*aRange*/ ) throw (RuntimeException
)
207 return Reference
< XCellRange
>();
210 // -----------------------------------------------------------------------------
212 // -----------------------------------------------------------------------------
214 OUString SAL_CALL
TableRow::getName() throw (RuntimeException
)
219 // -----------------------------------------------------------------------------
221 void SAL_CALL
TableRow::setName( const OUString
& aName
) throw (RuntimeException
)
226 // -----------------------------------------------------------------------------
228 // -----------------------------------------------------------------------------
230 void SAL_CALL
TableRow::setFastPropertyValue( sal_Int32 nHandle
, const Any
& aValue
) throw (UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
, RuntimeException
)
233 bool bChange
= false;
235 TableRowUndo
* pUndo
= 0;
237 SdrModel
* pModel
= mxTableModel
->getSdrTableObj()->GetModel();
239 const bool bUndo
= mxTableModel
.is() && mxTableModel
->getSdrTableObj() && mxTableModel
->getSdrTableObj()->IsInserted() && pModel
&& pModel
->IsUndoEnabled();
243 TableRowRef
xThis( this );
244 pUndo
= new TableRowUndo( xThis
);
249 case Property_Height
:
251 sal_Int32 nHeight
= mnHeight
;
252 bOk
= aValue
>>= nHeight
;
253 if( bOk
&& (mnHeight
!= nHeight
) )
256 mbOptimalHeight
= mnHeight
== 0;
262 case Property_OptimalHeight
:
264 sal_Bool bOptimalHeight
= mbOptimalHeight
;
265 bOk
= aValue
>>= bOptimalHeight
;
266 if( bOk
&& (mbOptimalHeight
!= bOptimalHeight
) )
268 mbOptimalHeight
= bOptimalHeight
;
275 case Property_IsVisible
:
277 sal_Bool bIsVisible
= mbIsVisible
;
278 bOk
= aValue
>>= bIsVisible
;
279 if( bOk
&& (mbIsVisible
!= bIsVisible
) )
281 mbIsVisible
= bIsVisible
;
287 case Property_IsStartOfNewPage
:
289 sal_Bool bIsStartOfNewPage
= mbIsStartOfNewPage
;
290 bOk
= aValue
>>= bIsStartOfNewPage
;
291 if( bOk
&& (mbIsStartOfNewPage
!= bIsStartOfNewPage
) )
293 mbIsStartOfNewPage
= bIsStartOfNewPage
;
299 throw UnknownPropertyException();
302 throw IllegalArgumentException();
308 pModel
->AddUndo( pUndo
);
311 mxTableModel
->setModified(sal_True
);
318 // -----------------------------------------------------------------------------
320 Any SAL_CALL
TableRow::getFastPropertyValue( sal_Int32 nHandle
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
324 case Property_Height
: return Any( mnHeight
);
325 case Property_OptimalHeight
: return Any( mbOptimalHeight
);
326 case Property_IsVisible
: return Any( mbIsVisible
);
327 case Property_IsStartOfNewPage
: return Any( mbIsStartOfNewPage
);
328 default: throw UnknownPropertyException();
332 // -----------------------------------------------------------------------------
334 rtl::Reference
< ::comphelper::FastPropertySetInfo
> TableRow::getStaticPropertySetInfo()
336 static rtl::Reference
< ::comphelper::FastPropertySetInfo
> xInfo
;
339 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
342 comphelper::PropertyVector
aProperties(6);
344 aProperties
[0].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" ) );
345 aProperties
[0].Handle
= Property_Height
;
346 aProperties
[0].Type
= ::getCppuType((const sal_Int32
*)0);
347 aProperties
[0].Attributes
= 0;
349 aProperties
[1].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalHeight" ) );
350 aProperties
[1].Handle
= Property_OptimalHeight
;
351 aProperties
[1].Type
= ::getBooleanCppuType();
352 aProperties
[1].Attributes
= 0;
354 aProperties
[2].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) );
355 aProperties
[2].Handle
= Property_IsVisible
;
356 aProperties
[2].Type
= ::getBooleanCppuType();
357 aProperties
[2].Attributes
= 0;
359 aProperties
[3].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" ) );
360 aProperties
[3].Handle
= Property_IsStartOfNewPage
;
361 aProperties
[3].Type
= ::getBooleanCppuType();
362 aProperties
[3].Attributes
= 0;
364 aProperties
[4].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) );
365 aProperties
[4].Handle
= Property_Height
;
366 aProperties
[4].Type
= ::getCppuType((const sal_Int32
*)0);
367 aProperties
[4].Attributes
= 0;
369 aProperties
[5].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalSize" ) );
370 aProperties
[5].Handle
= Property_OptimalHeight
;
371 aProperties
[5].Type
= ::getBooleanCppuType();
372 aProperties
[5].Attributes
= 0;
374 xInfo
.set( new ::comphelper::FastPropertySetInfo(aProperties
) );
381 // -----------------------------------------------------------------------------