Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / table / tablecolumn.cxx
blob67bf73fb1db66646da5672b3ec5044e1a3994b26
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <com/sun/star/lang/DisposedException.hpp>
32 #include "tablecolumn.hxx"
33 #include "tableundo.hxx"
34 #include "svx/svdmodel.hxx"
35 #include "svx/svdotable.hxx"
37 // -----------------------------------------------------------------------------
39 using ::rtl::OUString;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::container;
43 using namespace ::com::sun::star::table;
44 using namespace ::com::sun::star::beans;
46 // -----------------------------------------------------------------------------
48 namespace sdr { namespace table {
50 const sal_Int32 Property_Width = 0;
51 const sal_Int32 Property_OptimalWidth = 1;
52 const sal_Int32 Property_IsVisible = 2;
53 const sal_Int32 Property_IsStartOfNewPage = 3;
55 // -----------------------------------------------------------------------------
56 // TableRow
57 // -----------------------------------------------------------------------------
59 TableColumn::TableColumn( const TableModelRef& xTableModel, sal_Int32 nColumn )
60 : TableColumnBase( getStaticPropertySetInfo() )
61 , mxTableModel( xTableModel )
62 , mnColumn( nColumn )
63 , mnWidth( 0 )
64 , mbOptimalWidth( sal_True )
65 , mbIsVisible( sal_True )
66 , mbIsStartOfNewPage( sal_False )
70 // -----------------------------------------------------------------------------
72 TableColumn::~TableColumn()
76 // -----------------------------------------------------------------------------
78 void TableColumn::dispose()
80 mxTableModel.clear();
83 // -----------------------------------------------------------------------------
85 void TableColumn::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException)
87 if( !mxTableModel.is() )
88 throw DisposedException();
91 // -----------------------------------------------------------------------------
93 TableColumn& TableColumn::operator=( const TableColumn& r )
95 mnWidth = r.mnWidth;
96 mbOptimalWidth = r.mbOptimalWidth;
97 mbIsVisible = r.mbIsVisible;
98 mbIsStartOfNewPage = r.mbIsStartOfNewPage;
99 maName = r.maName;
100 mnColumn = r.mnColumn;
102 return *this;
105 // -----------------------------------------------------------------------------
106 // XCellRange
107 // -----------------------------------------------------------------------------
109 Reference< XCell > SAL_CALL TableColumn::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException)
111 throwIfDisposed();
112 if( nColumn != 0 )
113 throw IndexOutOfBoundsException();
115 return mxTableModel->getCellByPosition( mnColumn, nRow );
118 // -----------------------------------------------------------------------------
120 Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (IndexOutOfBoundsException, RuntimeException)
122 throwIfDisposed();
123 if( (nTop >= 0 ) && (nLeft == 0) && (nBottom >= nTop) && (nRight == 0) )
125 return mxTableModel->getCellRangeByPosition( mnColumn, nTop, mnColumn, nBottom );
127 throw IndexOutOfBoundsException();
130 // -----------------------------------------------------------------------------
132 Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByName( const OUString& /*aRange*/ ) throw (RuntimeException)
134 return Reference< XCellRange >();
137 // -----------------------------------------------------------------------------
138 // XNamed
139 // -----------------------------------------------------------------------------
141 OUString SAL_CALL TableColumn::getName() throw (RuntimeException)
143 return maName;
146 // -----------------------------------------------------------------------------
148 void SAL_CALL TableColumn::setName( const OUString& aName ) throw (RuntimeException)
150 maName = aName;
153 // -----------------------------------------------------------------------------
154 // XFastPropertySet
155 // -----------------------------------------------------------------------------
157 void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException)
159 bool bOk = false;
160 bool bChange = false;
162 SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();
164 TableColumnUndo* pUndo = 0;
165 if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled() )
167 TableColumnRef xThis( this );
168 pUndo = new TableColumnUndo( xThis );
171 switch( nHandle )
173 case Property_Width:
175 sal_Int32 nWidth = mnWidth;
176 bOk = aValue >>= nWidth;
177 if( bOk && (nWidth != mnWidth) )
179 mnWidth = nWidth;
180 mbOptimalWidth = mnWidth == 0;
181 bChange = true;
183 break;
185 case Property_OptimalWidth:
187 sal_Bool bOptimalWidth = mbOptimalWidth;
188 bOk = aValue >>= bOptimalWidth;
189 if( bOk && (mbOptimalWidth != bOptimalWidth) )
191 mbOptimalWidth = bOptimalWidth;
192 if( bOptimalWidth )
193 mnWidth = 0;
194 bChange = true;
196 break;
198 case Property_IsVisible:
200 sal_Bool bIsVisible = mbIsVisible;
201 bOk = aValue >>= bIsVisible;
202 if( bOk && (mbIsVisible != bIsVisible) )
204 mbIsVisible = bIsVisible;
205 bChange = true;
207 break;
210 case Property_IsStartOfNewPage:
212 sal_Bool bIsStartOfNewPage = mbIsStartOfNewPage;
213 bOk = aValue >>= bIsStartOfNewPage;
214 if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
216 mbIsStartOfNewPage = bIsStartOfNewPage;
217 bChange = true;
219 break;
221 default:
222 throw UnknownPropertyException();
224 if( !bOk )
225 throw IllegalArgumentException();
227 if( bChange )
229 if( pUndo )
231 pModel->AddUndo( pUndo );
232 pUndo = 0;
234 mxTableModel->setModified(sal_True);
237 if( pUndo )
238 delete pUndo;
241 // -----------------------------------------------------------------------------
243 Any SAL_CALL TableColumn::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
245 switch( nHandle )
247 case Property_Width: return Any( mnWidth );
248 case Property_OptimalWidth: return Any( mbOptimalWidth );
249 case Property_IsVisible: return Any( mbIsVisible );
250 case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
251 default: throw UnknownPropertyException();
255 // -----------------------------------------------------------------------------
257 rtl::Reference< ::comphelper::FastPropertySetInfo > TableColumn::getStaticPropertySetInfo()
259 static rtl::Reference< ::comphelper::FastPropertySetInfo > xInfo;
260 if( !xInfo.is() )
262 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
263 if( !xInfo.is() )
265 comphelper::PropertyVector aProperties(6);
267 aProperties[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ) );
268 aProperties[0].Handle = Property_Width;
269 aProperties[0].Type = ::getCppuType((const sal_Int32*)0);
270 aProperties[0].Attributes = 0;
272 aProperties[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalWidth" ) );
273 aProperties[1].Handle = Property_OptimalWidth;
274 aProperties[1].Type = ::getBooleanCppuType();
275 aProperties[1].Attributes = 0;
277 aProperties[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) );
278 aProperties[2].Handle = Property_IsVisible;
279 aProperties[2].Type = ::getBooleanCppuType();
280 aProperties[2].Attributes = 0;
282 aProperties[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" ) );
283 aProperties[3].Handle = Property_IsStartOfNewPage;
284 aProperties[3].Type = ::getBooleanCppuType();
285 aProperties[3].Attributes = 0;
287 aProperties[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) );
288 aProperties[4].Handle = Property_Width;
289 aProperties[4].Type = ::getCppuType((const sal_Int32*)0);
290 aProperties[4].Attributes = 0;
292 aProperties[5].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalSize" ) );
293 aProperties[5].Handle = Property_OptimalWidth;
294 aProperties[5].Type = ::getBooleanCppuType();
295 aProperties[5].Attributes = 0;
297 xInfo.set( new ::comphelper::FastPropertySetInfo(aProperties) );
301 return xInfo;
304 // -----------------------------------------------------------------------------
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */