Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / table / tablerow.cxx
blobc213e495ab402c9a0f38eccb9320a9b558793081
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
23 #include "cell.hxx"
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;
47 // TableRow
50 TableRow::TableRow( const TableModelRef& xTableModel, sal_Int32 nRow, sal_Int32 nColumns )
51 : TableRowBase( getStaticPropertySetInfo() )
52 , mxTableModel( xTableModel )
53 , mnRow( nRow )
54 , mnHeight( 0 )
55 , mbOptimalHeight( true )
56 , mbIsVisible( true )
57 , mbIsStartOfNewPage( false )
59 if( nColumns < 20 )
60 maCells.reserve( 20 );
62 if( nColumns )
64 maCells.resize( nColumns );
65 while( nColumns-- )
66 maCells[ nColumns ] = mxTableModel->createCell();
72 TableRow::~TableRow()
78 void TableRow::dispose()
80 mxTableModel.clear();
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;
106 maName = r.maName;
107 mnRow = r.mnRow;
109 return *this;
114 void TableRow::insertColumns( sal_Int32 nIndex, sal_Int32 nCount, CellVector::iterator* pIter /* = 0 */ )
116 throwIfDisposed();
117 if( nCount )
119 if( nIndex >= static_cast< sal_Int32 >( maCells.size() ) )
120 nIndex = static_cast< sal_Int32 >( maCells.size() );
121 if ( pIter )
122 maCells.insert( maCells.begin() + nIndex, *pIter, (*pIter) + nCount );
123 else
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 )
136 throwIfDisposed();
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()) )
143 ++aBegin;
145 if( nCount > 1 )
147 CellVector::iterator aEnd( aBegin );
148 while( nCount-- && (aEnd != maCells.end()) )
149 ++aEnd;
150 maCells.erase( aBegin, aEnd );
152 else
154 maCells.erase( aBegin );
157 else
159 maCells.resize( nIndex );
165 // XCellRange
168 Reference< XCell > SAL_CALL TableRow::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
170 throwIfDisposed();
171 if( nRow != 0 )
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)
181 throwIfDisposed();
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)
193 throwIfDisposed();
194 return Reference< XCellRange >();
198 // XNamed
201 OUString SAL_CALL TableRow::getName() throw (RuntimeException, std::exception)
203 return maName;
208 void SAL_CALL TableRow::setName( const OUString& aName ) throw (RuntimeException, std::exception)
210 maName = aName;
214 // XFastPropertySet
217 void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException, std::exception)
219 bool bOk = false;
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();
228 if( bUndo )
230 TableRowRef xThis( this );
231 pUndo = new TableRowUndo( xThis );
234 switch( nHandle )
236 case Property_Height:
238 sal_Int32 nHeight = mnHeight;
239 bOk = aValue >>= nHeight;
240 if( bOk && (mnHeight != nHeight) )
242 mnHeight = nHeight;
243 mbOptimalHeight = mnHeight == 0;
244 bChange = true;
246 break;
249 case Property_OptimalHeight:
251 bool bOptimalHeight = mbOptimalHeight;
252 bOk = aValue >>= bOptimalHeight;
253 if( bOk && (mbOptimalHeight != bOptimalHeight) )
255 mbOptimalHeight = bOptimalHeight;
256 if( bOptimalHeight )
257 mnHeight = 0;
258 bChange = true;
260 break;
262 case Property_IsVisible:
264 bool bIsVisible = mbIsVisible;
265 bOk = aValue >>= bIsVisible;
266 if( bOk && (mbIsVisible != bIsVisible) )
268 mbIsVisible = bIsVisible;
269 bChange = true;
271 break;
274 case Property_IsStartOfNewPage:
276 bool bIsStartOfNewPage = mbIsStartOfNewPage;
277 bOk = aValue >>= bIsStartOfNewPage;
278 if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
280 mbIsStartOfNewPage = bIsStartOfNewPage;
281 bChange = true;
283 break;
285 default:
286 throw UnknownPropertyException();
288 if( !bOk )
289 throw IllegalArgumentException();
291 if( bChange )
293 if( pUndo )
295 pModel->AddUndo( pUndo );
296 pUndo = 0;
298 mxTableModel->setModified(sal_True);
301 delete pUndo;
306 Any SAL_CALL TableRow::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
308 switch( nHandle )
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;
323 if( !xInfo.is() )
325 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
326 if( !xInfo.is() )
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) );
364 return xInfo;
372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */