1*f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f6e50924SAndrew Rist * distributed with this work for additional information 6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f6e50924SAndrew Rist * software distributed under the License is distributed on an 15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17*f6e50924SAndrew Rist * specific language governing permissions and limitations 18*f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*f6e50924SAndrew Rist *************************************************************/ 21*f6e50924SAndrew Rist 22*f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "cell.hxx" 30cdf0e10cSrcweir #include "tablerow.hxx" 31cdf0e10cSrcweir #include "tableundo.hxx" 32cdf0e10cSrcweir #include "svx/svdmodel.hxx" 33cdf0e10cSrcweir #include "svx/svdotable.hxx" 34cdf0e10cSrcweir 35cdf0e10cSrcweir // ----------------------------------------------------------------------------- 36cdf0e10cSrcweir 37cdf0e10cSrcweir using ::rtl::OUString; 38cdf0e10cSrcweir using namespace ::com::sun::star::uno; 39cdf0e10cSrcweir using namespace ::com::sun::star::lang; 40cdf0e10cSrcweir using namespace ::com::sun::star::container; 41cdf0e10cSrcweir using namespace ::com::sun::star::table; 42cdf0e10cSrcweir using namespace ::com::sun::star::beans; 43cdf0e10cSrcweir 44cdf0e10cSrcweir // ----------------------------------------------------------------------------- 45cdf0e10cSrcweir 46cdf0e10cSrcweir namespace sdr { namespace table { 47cdf0e10cSrcweir 48cdf0e10cSrcweir const sal_Int32 Property_Height = 0; 49cdf0e10cSrcweir const sal_Int32 Property_OptimalHeight = 1; 50cdf0e10cSrcweir const sal_Int32 Property_IsVisible = 2; 51cdf0e10cSrcweir const sal_Int32 Property_IsStartOfNewPage = 3; 52cdf0e10cSrcweir 53cdf0e10cSrcweir // ----------------------------------------------------------------------------- 54cdf0e10cSrcweir // TableRow 55cdf0e10cSrcweir // ----------------------------------------------------------------------------- 56cdf0e10cSrcweir 57cdf0e10cSrcweir TableRow::TableRow( const TableModelRef& xTableModel, sal_Int32 nRow, sal_Int32 nColumns ) 58cdf0e10cSrcweir : TableRowBase( getStaticPropertySetInfo() ) 59cdf0e10cSrcweir , mxTableModel( xTableModel ) 60cdf0e10cSrcweir , mnRow( nRow ) 61cdf0e10cSrcweir , mnHeight( 0 ) 62cdf0e10cSrcweir , mbOptimalHeight( sal_True ) 63cdf0e10cSrcweir , mbIsVisible( sal_True ) 64cdf0e10cSrcweir , mbIsStartOfNewPage( sal_False ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir if( nColumns < 20 ) 67cdf0e10cSrcweir maCells.reserve( 20 ); 68cdf0e10cSrcweir 69cdf0e10cSrcweir if( nColumns ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir maCells.resize( nColumns ); 72cdf0e10cSrcweir while( nColumns-- ) 73cdf0e10cSrcweir maCells[ nColumns ] = mxTableModel->createCell(); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir // ----------------------------------------------------------------------------- 78cdf0e10cSrcweir 79cdf0e10cSrcweir TableRow::~TableRow() 80cdf0e10cSrcweir { 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir // ----------------------------------------------------------------------------- 84cdf0e10cSrcweir 85cdf0e10cSrcweir void TableRow::dispose() 86cdf0e10cSrcweir { 87cdf0e10cSrcweir mxTableModel.clear(); 88cdf0e10cSrcweir if( !maCells.empty() ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir CellVector::iterator aIter( maCells.begin() ); 91cdf0e10cSrcweir while( aIter != maCells.end() ) 92cdf0e10cSrcweir (*aIter++)->dispose(); 93cdf0e10cSrcweir CellVector().swap(maCells); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir // ----------------------------------------------------------------------------- 98cdf0e10cSrcweir 99cdf0e10cSrcweir void TableRow::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir if( !mxTableModel.is() ) 102cdf0e10cSrcweir throw DisposedException(); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir // ----------------------------------------------------------------------------- 106cdf0e10cSrcweir 107cdf0e10cSrcweir TableRow& TableRow::operator=( const TableRow& r ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir mnHeight = r.mnHeight; 110cdf0e10cSrcweir mbOptimalHeight = r.mbOptimalHeight; 111cdf0e10cSrcweir mbIsVisible = r.mbIsVisible; 112cdf0e10cSrcweir mbIsStartOfNewPage = r.mbIsStartOfNewPage; 113cdf0e10cSrcweir maName = r.maName; 114cdf0e10cSrcweir 115cdf0e10cSrcweir return *this; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir // ----------------------------------------------------------------------------- 119cdf0e10cSrcweir 120cdf0e10cSrcweir void TableRow::insertColumns( sal_Int32 nIndex, sal_Int32 nCount, CellVector::iterator* pIter /* = 0 */ ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir throwIfDisposed(); 123cdf0e10cSrcweir if( nCount ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir if( nIndex >= static_cast< sal_Int32 >( maCells.size() ) ) 126cdf0e10cSrcweir nIndex = static_cast< sal_Int32 >( maCells.size() ); 127cdf0e10cSrcweir if ( pIter ) 128cdf0e10cSrcweir maCells.insert( maCells.begin() + nIndex, *pIter, (*pIter) + nCount ); 129cdf0e10cSrcweir else 130cdf0e10cSrcweir { 131cdf0e10cSrcweir maCells.reserve( maCells.size() + nCount ); 132cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; i++ ) 133cdf0e10cSrcweir maCells.insert( maCells.begin() + nIndex + i, mxTableModel->createCell() ); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir // ----------------------------------------------------------------------------- 139cdf0e10cSrcweir 140cdf0e10cSrcweir void TableRow::removeColumns( sal_Int32 nIndex, sal_Int32 nCount ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir throwIfDisposed(); 143cdf0e10cSrcweir if( (nCount >= 0) && ( nIndex >= 0) ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir if( (nIndex + nCount) < static_cast< sal_Int32 >( maCells.size() ) ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir CellVector::iterator aBegin( maCells.begin() ); 148cdf0e10cSrcweir while( nIndex-- && (aBegin != maCells.end()) ) 149cdf0e10cSrcweir aBegin++; 150cdf0e10cSrcweir 151cdf0e10cSrcweir if( nCount > 1 ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir CellVector::iterator aEnd( aBegin ); 154cdf0e10cSrcweir while( nCount-- && (aEnd != maCells.end()) ) 155cdf0e10cSrcweir aEnd++; 156cdf0e10cSrcweir maCells.erase( aBegin, aEnd ); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir else 159cdf0e10cSrcweir { 160cdf0e10cSrcweir maCells.erase( aBegin ); 161cdf0e10cSrcweir } 162cdf0e10cSrcweir } 163cdf0e10cSrcweir else 164cdf0e10cSrcweir { 165cdf0e10cSrcweir maCells.resize( nIndex ); 166cdf0e10cSrcweir } 167cdf0e10cSrcweir } 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir // ----------------------------------------------------------------------------- 171cdf0e10cSrcweir // XCellRange 172cdf0e10cSrcweir // ----------------------------------------------------------------------------- 173cdf0e10cSrcweir 174cdf0e10cSrcweir Reference< XCell > SAL_CALL TableRow::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir throwIfDisposed(); 177cdf0e10cSrcweir if( nRow != 0 ) 178cdf0e10cSrcweir throw IndexOutOfBoundsException(); 179cdf0e10cSrcweir 180cdf0e10cSrcweir return mxTableModel->getCellByPosition( nColumn, mnRow ); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir // ----------------------------------------------------------------------------- 184cdf0e10cSrcweir 185cdf0e10cSrcweir Reference< XCellRange > SAL_CALL TableRow::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (IndexOutOfBoundsException, RuntimeException) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir throwIfDisposed(); 188cdf0e10cSrcweir if( (nLeft >= 0 ) && (nTop == 0) && (nRight >= nLeft) && (nBottom == 0) ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir return mxTableModel->getCellRangeByPosition( nLeft, mnRow, nRight, mnRow ); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir throw IndexOutOfBoundsException(); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir // ----------------------------------------------------------------------------- 196cdf0e10cSrcweir 197cdf0e10cSrcweir Reference< XCellRange > SAL_CALL TableRow::getCellRangeByName( const OUString& /*aRange*/ ) throw (RuntimeException) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir throwIfDisposed(); 200cdf0e10cSrcweir return Reference< XCellRange >(); 201cdf0e10cSrcweir } 202cdf0e10cSrcweir 203cdf0e10cSrcweir // ----------------------------------------------------------------------------- 204cdf0e10cSrcweir // XNamed 205cdf0e10cSrcweir // ----------------------------------------------------------------------------- 206cdf0e10cSrcweir 207cdf0e10cSrcweir OUString SAL_CALL TableRow::getName() throw (RuntimeException) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir return maName; 210cdf0e10cSrcweir } 211cdf0e10cSrcweir 212cdf0e10cSrcweir // ----------------------------------------------------------------------------- 213cdf0e10cSrcweir 214cdf0e10cSrcweir void SAL_CALL TableRow::setName( const OUString& aName ) throw (RuntimeException) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir maName = aName; 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir // ----------------------------------------------------------------------------- 220cdf0e10cSrcweir // XFastPropertySet 221cdf0e10cSrcweir // ----------------------------------------------------------------------------- 222cdf0e10cSrcweir 223cdf0e10cSrcweir void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir bool bOk = false; 226cdf0e10cSrcweir bool bChange = false; 227cdf0e10cSrcweir 228cdf0e10cSrcweir TableRowUndo* pUndo = 0; 229cdf0e10cSrcweir 230cdf0e10cSrcweir SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel(); 231cdf0e10cSrcweir 232cdf0e10cSrcweir const bool bUndo = mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled(); 233cdf0e10cSrcweir 234cdf0e10cSrcweir if( bUndo ) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir TableRowRef xThis( this ); 237cdf0e10cSrcweir pUndo = new TableRowUndo( xThis ); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir switch( nHandle ) 241cdf0e10cSrcweir { 242cdf0e10cSrcweir case Property_Height: 243cdf0e10cSrcweir { 244cdf0e10cSrcweir sal_Int32 nHeight = mnHeight; 245cdf0e10cSrcweir bOk = aValue >>= nHeight; 246cdf0e10cSrcweir if( bOk && (mnHeight != nHeight) ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir mnHeight = nHeight; 249cdf0e10cSrcweir mbOptimalHeight = mnHeight == 0; 250cdf0e10cSrcweir bChange = true; 251cdf0e10cSrcweir } 252cdf0e10cSrcweir break; 253cdf0e10cSrcweir } 254cdf0e10cSrcweir 255cdf0e10cSrcweir case Property_OptimalHeight: 256cdf0e10cSrcweir { 257cdf0e10cSrcweir sal_Bool bOptimalHeight = mbOptimalHeight; 258cdf0e10cSrcweir bOk = aValue >>= bOptimalHeight; 259cdf0e10cSrcweir if( bOk && (mbOptimalHeight != bOptimalHeight) ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir mbOptimalHeight = bOptimalHeight; 262cdf0e10cSrcweir if( bOptimalHeight ) 263cdf0e10cSrcweir mnHeight = 0; 264cdf0e10cSrcweir bChange = true; 265cdf0e10cSrcweir } 266cdf0e10cSrcweir break; 267cdf0e10cSrcweir } 268cdf0e10cSrcweir case Property_IsVisible: 269cdf0e10cSrcweir { 270cdf0e10cSrcweir sal_Bool bIsVisible = mbIsVisible; 271cdf0e10cSrcweir bOk = aValue >>= bIsVisible; 272cdf0e10cSrcweir if( bOk && (mbIsVisible != bIsVisible) ) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir mbIsVisible = bIsVisible; 275cdf0e10cSrcweir bChange = true; 276cdf0e10cSrcweir } 277cdf0e10cSrcweir break; 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir case Property_IsStartOfNewPage: 281cdf0e10cSrcweir { 282cdf0e10cSrcweir sal_Bool bIsStartOfNewPage = mbIsStartOfNewPage; 283cdf0e10cSrcweir bOk = aValue >>= bIsStartOfNewPage; 284cdf0e10cSrcweir if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) ) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir mbIsStartOfNewPage = bIsStartOfNewPage; 287cdf0e10cSrcweir bChange = true; 288cdf0e10cSrcweir } 289cdf0e10cSrcweir break; 290cdf0e10cSrcweir } 291cdf0e10cSrcweir default: 292cdf0e10cSrcweir throw UnknownPropertyException(); 293cdf0e10cSrcweir } 294cdf0e10cSrcweir if( !bOk ) 295cdf0e10cSrcweir throw IllegalArgumentException(); 296cdf0e10cSrcweir 297cdf0e10cSrcweir if( bChange ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir if( pUndo ) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir pModel->AddUndo( pUndo ); 302cdf0e10cSrcweir pUndo = 0; 303cdf0e10cSrcweir } 304cdf0e10cSrcweir mxTableModel->setModified(sal_True); 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir if( pUndo ) 308cdf0e10cSrcweir delete pUndo; 309cdf0e10cSrcweir } 310cdf0e10cSrcweir 311cdf0e10cSrcweir // ----------------------------------------------------------------------------- 312cdf0e10cSrcweir 313cdf0e10cSrcweir Any SAL_CALL TableRow::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) 314cdf0e10cSrcweir { 315cdf0e10cSrcweir switch( nHandle ) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir case Property_Height: return Any( mnHeight ); 318cdf0e10cSrcweir case Property_OptimalHeight: return Any( mbOptimalHeight ); 319cdf0e10cSrcweir case Property_IsVisible: return Any( mbIsVisible ); 320cdf0e10cSrcweir case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage ); 321cdf0e10cSrcweir default: throw UnknownPropertyException(); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir // ----------------------------------------------------------------------------- 326cdf0e10cSrcweir 327cdf0e10cSrcweir rtl::Reference< ::comphelper::FastPropertySetInfo > TableRow::getStaticPropertySetInfo() 328cdf0e10cSrcweir { 329cdf0e10cSrcweir static rtl::Reference< ::comphelper::FastPropertySetInfo > xInfo; 330cdf0e10cSrcweir if( !xInfo.is() ) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 333cdf0e10cSrcweir if( !xInfo.is() ) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir comphelper::PropertyVector aProperties(6); 336cdf0e10cSrcweir 337cdf0e10cSrcweir aProperties[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" ) ); 338cdf0e10cSrcweir aProperties[0].Handle = Property_Height; 339cdf0e10cSrcweir aProperties[0].Type = ::getCppuType((const sal_Int32*)0); 340cdf0e10cSrcweir aProperties[0].Attributes = 0; 341cdf0e10cSrcweir 342cdf0e10cSrcweir aProperties[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalHeight" ) ); 343cdf0e10cSrcweir aProperties[1].Handle = Property_OptimalHeight; 344cdf0e10cSrcweir aProperties[1].Type = ::getBooleanCppuType(); 345cdf0e10cSrcweir aProperties[1].Attributes = 0; 346cdf0e10cSrcweir 347cdf0e10cSrcweir aProperties[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) ); 348cdf0e10cSrcweir aProperties[2].Handle = Property_IsVisible; 349cdf0e10cSrcweir aProperties[2].Type = ::getBooleanCppuType(); 350cdf0e10cSrcweir aProperties[2].Attributes = 0; 351cdf0e10cSrcweir 352cdf0e10cSrcweir aProperties[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" ) ); 353cdf0e10cSrcweir aProperties[3].Handle = Property_IsStartOfNewPage; 354cdf0e10cSrcweir aProperties[3].Type = ::getBooleanCppuType(); 355cdf0e10cSrcweir aProperties[3].Attributes = 0; 356cdf0e10cSrcweir 357cdf0e10cSrcweir aProperties[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ); 358cdf0e10cSrcweir aProperties[4].Handle = Property_Height; 359cdf0e10cSrcweir aProperties[4].Type = ::getCppuType((const sal_Int32*)0); 360cdf0e10cSrcweir aProperties[4].Attributes = 0; 361cdf0e10cSrcweir 362cdf0e10cSrcweir aProperties[5].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalSize" ) ); 363cdf0e10cSrcweir aProperties[5].Handle = Property_OptimalHeight; 364cdf0e10cSrcweir aProperties[5].Type = ::getBooleanCppuType(); 365cdf0e10cSrcweir aProperties[5].Attributes = 0; 366cdf0e10cSrcweir 367cdf0e10cSrcweir xInfo.set( new ::comphelper::FastPropertySetInfo(aProperties) ); 368cdf0e10cSrcweir } 369cdf0e10cSrcweir } 370cdf0e10cSrcweir 371cdf0e10cSrcweir return xInfo; 372cdf0e10cSrcweir } 373cdf0e10cSrcweir 374cdf0e10cSrcweir // ----------------------------------------------------------------------------- 375cdf0e10cSrcweir 376cdf0e10cSrcweir 377cdf0e10cSrcweir } } 378