update credits
[LibreOffice.git] / svx / source / table / tablecolumn.cxx
blobca3212ceeb8aee166f17681dcffbd9088c2c00cc
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 "tablecolumn.hxx"
24 #include "tableundo.hxx"
25 #include "svx/svdmodel.hxx"
26 #include "svx/svdotable.hxx"
28 // -----------------------------------------------------------------------------
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::lang;
32 using namespace ::com::sun::star::container;
33 using namespace ::com::sun::star::table;
34 using namespace ::com::sun::star::beans;
36 // -----------------------------------------------------------------------------
38 namespace sdr { namespace table {
40 const sal_Int32 Property_Width = 0;
41 const sal_Int32 Property_OptimalWidth = 1;
42 const sal_Int32 Property_IsVisible = 2;
43 const sal_Int32 Property_IsStartOfNewPage = 3;
45 // -----------------------------------------------------------------------------
46 // TableRow
47 // -----------------------------------------------------------------------------
49 TableColumn::TableColumn( const TableModelRef& xTableModel, sal_Int32 nColumn )
50 : TableColumnBase( getStaticPropertySetInfo() )
51 , mxTableModel( xTableModel )
52 , mnColumn( nColumn )
53 , mnWidth( 0 )
54 , mbOptimalWidth( sal_True )
55 , mbIsVisible( sal_True )
56 , mbIsStartOfNewPage( sal_False )
60 // -----------------------------------------------------------------------------
62 TableColumn::~TableColumn()
66 // -----------------------------------------------------------------------------
68 void TableColumn::dispose()
70 mxTableModel.clear();
73 // -----------------------------------------------------------------------------
75 void TableColumn::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException)
77 if( !mxTableModel.is() )
78 throw DisposedException();
81 // -----------------------------------------------------------------------------
83 TableColumn& TableColumn::operator=( const TableColumn& r )
85 mnWidth = r.mnWidth;
86 mbOptimalWidth = r.mbOptimalWidth;
87 mbIsVisible = r.mbIsVisible;
88 mbIsStartOfNewPage = r.mbIsStartOfNewPage;
89 maName = r.maName;
90 mnColumn = r.mnColumn;
92 return *this;
95 // -----------------------------------------------------------------------------
96 // XCellRange
97 // -----------------------------------------------------------------------------
99 Reference< XCell > SAL_CALL TableColumn::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException)
101 throwIfDisposed();
102 if( nColumn != 0 )
103 throw IndexOutOfBoundsException();
105 return mxTableModel->getCellByPosition( mnColumn, nRow );
108 // -----------------------------------------------------------------------------
110 Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (IndexOutOfBoundsException, RuntimeException)
112 throwIfDisposed();
113 if( (nTop >= 0 ) && (nLeft == 0) && (nBottom >= nTop) && (nRight == 0) )
115 return mxTableModel->getCellRangeByPosition( mnColumn, nTop, mnColumn, nBottom );
117 throw IndexOutOfBoundsException();
120 // -----------------------------------------------------------------------------
122 Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByName( const OUString& /*aRange*/ ) throw (RuntimeException)
124 return Reference< XCellRange >();
127 // -----------------------------------------------------------------------------
128 // XNamed
129 // -----------------------------------------------------------------------------
131 OUString SAL_CALL TableColumn::getName() throw (RuntimeException)
133 return maName;
136 // -----------------------------------------------------------------------------
138 void SAL_CALL TableColumn::setName( const OUString& aName ) throw (RuntimeException)
140 maName = aName;
143 // -----------------------------------------------------------------------------
144 // XFastPropertySet
145 // -----------------------------------------------------------------------------
147 void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException)
149 bool bOk = false;
150 bool bChange = false;
152 SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();
154 TableColumnUndo* pUndo = 0;
155 if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled() )
157 TableColumnRef xThis( this );
158 pUndo = new TableColumnUndo( xThis );
161 switch( nHandle )
163 case Property_Width:
165 sal_Int32 nWidth = mnWidth;
166 bOk = aValue >>= nWidth;
167 if( bOk && (nWidth != mnWidth) )
169 mnWidth = nWidth;
170 mbOptimalWidth = mnWidth == 0;
171 bChange = true;
173 break;
175 case Property_OptimalWidth:
177 sal_Bool bOptimalWidth = mbOptimalWidth;
178 bOk = aValue >>= bOptimalWidth;
179 if( bOk && (mbOptimalWidth != bOptimalWidth) )
181 mbOptimalWidth = bOptimalWidth;
182 if( bOptimalWidth )
183 mnWidth = 0;
184 bChange = true;
186 break;
188 case Property_IsVisible:
190 sal_Bool bIsVisible = mbIsVisible;
191 bOk = aValue >>= bIsVisible;
192 if( bOk && (mbIsVisible != bIsVisible) )
194 mbIsVisible = bIsVisible;
195 bChange = true;
197 break;
200 case Property_IsStartOfNewPage:
202 sal_Bool bIsStartOfNewPage = mbIsStartOfNewPage;
203 bOk = aValue >>= bIsStartOfNewPage;
204 if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
206 mbIsStartOfNewPage = bIsStartOfNewPage;
207 bChange = true;
209 break;
211 default:
212 throw UnknownPropertyException();
214 if( !bOk )
215 throw IllegalArgumentException();
217 if( bChange )
219 if( pUndo )
221 pModel->AddUndo( pUndo );
222 pUndo = 0;
224 mxTableModel->setModified(sal_True);
227 delete pUndo;
230 // -----------------------------------------------------------------------------
232 Any SAL_CALL TableColumn::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
234 switch( nHandle )
236 case Property_Width: return Any( mnWidth );
237 case Property_OptimalWidth: return Any( mbOptimalWidth );
238 case Property_IsVisible: return Any( mbIsVisible );
239 case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
240 default: throw UnknownPropertyException();
244 // -----------------------------------------------------------------------------
246 rtl::Reference< FastPropertySetInfo > TableColumn::getStaticPropertySetInfo()
248 static rtl::Reference< FastPropertySetInfo > xInfo;
249 if( !xInfo.is() )
251 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
252 if( !xInfo.is() )
254 PropertyVector aProperties(6);
256 aProperties[0].Name = OUString( "Width" );
257 aProperties[0].Handle = Property_Width;
258 aProperties[0].Type = ::getCppuType((const sal_Int32*)0);
259 aProperties[0].Attributes = 0;
261 aProperties[1].Name = OUString( "OptimalWidth" );
262 aProperties[1].Handle = Property_OptimalWidth;
263 aProperties[1].Type = ::getBooleanCppuType();
264 aProperties[1].Attributes = 0;
266 aProperties[2].Name = OUString( "IsVisible" );
267 aProperties[2].Handle = Property_IsVisible;
268 aProperties[2].Type = ::getBooleanCppuType();
269 aProperties[2].Attributes = 0;
271 aProperties[3].Name = OUString( "IsStartOfNewPage" );
272 aProperties[3].Handle = Property_IsStartOfNewPage;
273 aProperties[3].Type = ::getBooleanCppuType();
274 aProperties[3].Attributes = 0;
276 aProperties[4].Name = OUString( "Size" );
277 aProperties[4].Handle = Property_Width;
278 aProperties[4].Type = ::getCppuType((const sal_Int32*)0);
279 aProperties[4].Attributes = 0;
281 aProperties[5].Name = OUString( "OptimalSize" );
282 aProperties[5].Handle = Property_OptimalWidth;
283 aProperties[5].Type = ::getBooleanCppuType();
284 aProperties[5].Attributes = 0;
286 xInfo.set( new FastPropertySetInfo(aProperties) );
290 return xInfo;
293 // -----------------------------------------------------------------------------
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */