1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svx.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "tablecolumn.hxx" 34*cdf0e10cSrcweir #include "tableundo.hxx" 35*cdf0e10cSrcweir #include "svx/svdmodel.hxx" 36*cdf0e10cSrcweir #include "svx/svdotable.hxx" 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir using ::rtl::OUString; 41*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 42*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 43*cdf0e10cSrcweir using namespace ::com::sun::star::container; 44*cdf0e10cSrcweir using namespace ::com::sun::star::table; 45*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir namespace sdr { namespace table { 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir const sal_Int32 Property_Width = 0; 52*cdf0e10cSrcweir const sal_Int32 Property_OptimalWidth = 1; 53*cdf0e10cSrcweir const sal_Int32 Property_IsVisible = 2; 54*cdf0e10cSrcweir const sal_Int32 Property_IsStartOfNewPage = 3; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 57*cdf0e10cSrcweir // TableRow 58*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir TableColumn::TableColumn( const TableModelRef& xTableModel, sal_Int32 nColumn ) 61*cdf0e10cSrcweir : TableColumnBase( getStaticPropertySetInfo() ) 62*cdf0e10cSrcweir , mxTableModel( xTableModel ) 63*cdf0e10cSrcweir , mnColumn( nColumn ) 64*cdf0e10cSrcweir , mnWidth( 0 ) 65*cdf0e10cSrcweir , mbOptimalWidth( sal_True ) 66*cdf0e10cSrcweir , mbIsVisible( sal_True ) 67*cdf0e10cSrcweir , mbIsStartOfNewPage( sal_False ) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir TableColumn::~TableColumn() 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir void TableColumn::dispose() 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir mxTableModel.clear(); 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir void TableColumn::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir if( !mxTableModel.is() ) 89*cdf0e10cSrcweir throw DisposedException(); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir TableColumn& TableColumn::operator=( const TableColumn& r ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir mnWidth = r.mnWidth; 97*cdf0e10cSrcweir mbOptimalWidth = r.mbOptimalWidth; 98*cdf0e10cSrcweir mbIsVisible = r.mbIsVisible; 99*cdf0e10cSrcweir mbIsStartOfNewPage = r.mbIsStartOfNewPage; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir return *this; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 105*cdf0e10cSrcweir // XCellRange 106*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir Reference< XCell > SAL_CALL TableColumn::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir throwIfDisposed(); 111*cdf0e10cSrcweir if( nColumn != 0 ) 112*cdf0e10cSrcweir throw IndexOutOfBoundsException(); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir return mxTableModel->getCellByPosition( mnColumn, nRow ); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (IndexOutOfBoundsException, RuntimeException) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir throwIfDisposed(); 122*cdf0e10cSrcweir if( (nTop >= 0 ) && (nLeft == 0) && (nBottom >= nTop) && (nRight == 0) ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir return mxTableModel->getCellRangeByPosition( mnColumn, nTop, mnColumn, nBottom ); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir throw IndexOutOfBoundsException(); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByName( const OUString& /*aRange*/ ) throw (RuntimeException) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir return Reference< XCellRange >(); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 137*cdf0e10cSrcweir // XNamed 138*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir OUString SAL_CALL TableColumn::getName() throw (RuntimeException) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir return maName; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir void SAL_CALL TableColumn::setName( const OUString& aName ) throw (RuntimeException) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir maName = aName; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 153*cdf0e10cSrcweir // XFastPropertySet 154*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir bool bOk = false; 159*cdf0e10cSrcweir bool bChange = false; 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel(); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir TableColumnUndo* pUndo = 0; 164*cdf0e10cSrcweir if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled() ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir TableColumnRef xThis( this ); 167*cdf0e10cSrcweir pUndo = new TableColumnUndo( xThis ); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir switch( nHandle ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir case Property_Width: 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir sal_Int32 nWidth = mnWidth; 175*cdf0e10cSrcweir bOk = aValue >>= nWidth; 176*cdf0e10cSrcweir if( bOk && (nWidth != mnWidth) ) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir mnWidth = nWidth; 179*cdf0e10cSrcweir mbOptimalWidth = mnWidth == 0; 180*cdf0e10cSrcweir bChange = true; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir break; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir case Property_OptimalWidth: 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir sal_Bool bOptimalWidth = mbOptimalWidth; 187*cdf0e10cSrcweir bOk = aValue >>= bOptimalWidth; 188*cdf0e10cSrcweir if( bOk && (mbOptimalWidth != bOptimalWidth) ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir mbOptimalWidth = bOptimalWidth; 191*cdf0e10cSrcweir if( bOptimalWidth ) 192*cdf0e10cSrcweir mnWidth = 0; 193*cdf0e10cSrcweir bChange = true; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir break; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir case Property_IsVisible: 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir sal_Bool bIsVisible = mbIsVisible; 200*cdf0e10cSrcweir bOk = aValue >>= bIsVisible; 201*cdf0e10cSrcweir if( bOk && (mbIsVisible != bIsVisible) ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir mbIsVisible = bIsVisible; 204*cdf0e10cSrcweir bChange = true; 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir break; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir case Property_IsStartOfNewPage: 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir sal_Bool bIsStartOfNewPage = mbIsStartOfNewPage; 212*cdf0e10cSrcweir bOk = aValue >>= bIsStartOfNewPage; 213*cdf0e10cSrcweir if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir mbIsStartOfNewPage = bIsStartOfNewPage; 216*cdf0e10cSrcweir bChange = true; 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir break; 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir default: 221*cdf0e10cSrcweir throw UnknownPropertyException(); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir if( !bOk ) 224*cdf0e10cSrcweir throw IllegalArgumentException(); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir if( bChange ) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir if( pUndo ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir pModel->AddUndo( pUndo ); 231*cdf0e10cSrcweir pUndo = 0; 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir mxTableModel->setModified(sal_True); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir if( pUndo ) 237*cdf0e10cSrcweir delete pUndo; 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir Any SAL_CALL TableColumn::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir switch( nHandle ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir case Property_Width: return Any( mnWidth ); 247*cdf0e10cSrcweir case Property_OptimalWidth: return Any( mbOptimalWidth ); 248*cdf0e10cSrcweir case Property_IsVisible: return Any( mbIsVisible ); 249*cdf0e10cSrcweir case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage ); 250*cdf0e10cSrcweir default: throw UnknownPropertyException(); 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir rtl::Reference< ::comphelper::FastPropertySetInfo > TableColumn::getStaticPropertySetInfo() 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir static rtl::Reference< ::comphelper::FastPropertySetInfo > xInfo; 259*cdf0e10cSrcweir if( !xInfo.is() ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 262*cdf0e10cSrcweir if( !xInfo.is() ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir comphelper::PropertyVector aProperties(6); 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir aProperties[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ) ); 267*cdf0e10cSrcweir aProperties[0].Handle = Property_Width; 268*cdf0e10cSrcweir aProperties[0].Type = ::getCppuType((const sal_Int32*)0); 269*cdf0e10cSrcweir aProperties[0].Attributes = 0; 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir aProperties[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalWidth" ) ); 272*cdf0e10cSrcweir aProperties[1].Handle = Property_OptimalWidth; 273*cdf0e10cSrcweir aProperties[1].Type = ::getBooleanCppuType(); 274*cdf0e10cSrcweir aProperties[1].Attributes = 0; 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir aProperties[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) ); 277*cdf0e10cSrcweir aProperties[2].Handle = Property_IsVisible; 278*cdf0e10cSrcweir aProperties[2].Type = ::getBooleanCppuType(); 279*cdf0e10cSrcweir aProperties[2].Attributes = 0; 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir aProperties[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" ) ); 282*cdf0e10cSrcweir aProperties[3].Handle = Property_IsStartOfNewPage; 283*cdf0e10cSrcweir aProperties[3].Type = ::getBooleanCppuType(); 284*cdf0e10cSrcweir aProperties[3].Attributes = 0; 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir aProperties[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ); 287*cdf0e10cSrcweir aProperties[4].Handle = Property_Width; 288*cdf0e10cSrcweir aProperties[4].Type = ::getCppuType((const sal_Int32*)0); 289*cdf0e10cSrcweir aProperties[4].Attributes = 0; 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir aProperties[5].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalSize" ) ); 292*cdf0e10cSrcweir aProperties[5].Handle = Property_OptimalWidth; 293*cdf0e10cSrcweir aProperties[5].Type = ::getBooleanCppuType(); 294*cdf0e10cSrcweir aProperties[5].Attributes = 0; 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir xInfo.set( new ::comphelper::FastPropertySetInfo(aProperties) ); 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir return xInfo; 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir } } 306