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
10*f6e50924SAndrew Rist *
11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist *
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.
19*f6e50924SAndrew Rist *
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 "tablecolumn.hxx"
30cdf0e10cSrcweir #include "tableundo.hxx"
31cdf0e10cSrcweir #include "svx/svdmodel.hxx"
32cdf0e10cSrcweir #include "svx/svdotable.hxx"
33cdf0e10cSrcweir
34cdf0e10cSrcweir // -----------------------------------------------------------------------------
35cdf0e10cSrcweir
36cdf0e10cSrcweir using ::rtl::OUString;
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir using namespace ::com::sun::star::lang;
39cdf0e10cSrcweir using namespace ::com::sun::star::container;
40cdf0e10cSrcweir using namespace ::com::sun::star::table;
41cdf0e10cSrcweir using namespace ::com::sun::star::beans;
42cdf0e10cSrcweir
43cdf0e10cSrcweir // -----------------------------------------------------------------------------
44cdf0e10cSrcweir
45cdf0e10cSrcweir namespace sdr { namespace table {
46cdf0e10cSrcweir
47cdf0e10cSrcweir const sal_Int32 Property_Width = 0;
48cdf0e10cSrcweir const sal_Int32 Property_OptimalWidth = 1;
49cdf0e10cSrcweir const sal_Int32 Property_IsVisible = 2;
50cdf0e10cSrcweir const sal_Int32 Property_IsStartOfNewPage = 3;
51cdf0e10cSrcweir
52cdf0e10cSrcweir // -----------------------------------------------------------------------------
53cdf0e10cSrcweir // TableRow
54cdf0e10cSrcweir // -----------------------------------------------------------------------------
55cdf0e10cSrcweir
TableColumn(const TableModelRef & xTableModel,sal_Int32 nColumn)56cdf0e10cSrcweir TableColumn::TableColumn( const TableModelRef& xTableModel, sal_Int32 nColumn )
57cdf0e10cSrcweir : TableColumnBase( getStaticPropertySetInfo() )
58cdf0e10cSrcweir , mxTableModel( xTableModel )
59cdf0e10cSrcweir , mnColumn( nColumn )
60cdf0e10cSrcweir , mnWidth( 0 )
61cdf0e10cSrcweir , mbOptimalWidth( sal_True )
62cdf0e10cSrcweir , mbIsVisible( sal_True )
63cdf0e10cSrcweir , mbIsStartOfNewPage( sal_False )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
67cdf0e10cSrcweir // -----------------------------------------------------------------------------
68cdf0e10cSrcweir
~TableColumn()69cdf0e10cSrcweir TableColumn::~TableColumn()
70cdf0e10cSrcweir {
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
73cdf0e10cSrcweir // -----------------------------------------------------------------------------
74cdf0e10cSrcweir
dispose()75cdf0e10cSrcweir void TableColumn::dispose()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir mxTableModel.clear();
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
80cdf0e10cSrcweir // -----------------------------------------------------------------------------
81cdf0e10cSrcweir
throwIfDisposed() const82cdf0e10cSrcweir void TableColumn::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir if( !mxTableModel.is() )
85cdf0e10cSrcweir throw DisposedException();
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
88cdf0e10cSrcweir // -----------------------------------------------------------------------------
89cdf0e10cSrcweir
operator =(const TableColumn & r)90cdf0e10cSrcweir TableColumn& TableColumn::operator=( const TableColumn& r )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir mnWidth = r.mnWidth;
93cdf0e10cSrcweir mbOptimalWidth = r.mbOptimalWidth;
94cdf0e10cSrcweir mbIsVisible = r.mbIsVisible;
95cdf0e10cSrcweir mbIsStartOfNewPage = r.mbIsStartOfNewPage;
96cdf0e10cSrcweir
97cdf0e10cSrcweir return *this;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
100cdf0e10cSrcweir // -----------------------------------------------------------------------------
101cdf0e10cSrcweir // XCellRange
102cdf0e10cSrcweir // -----------------------------------------------------------------------------
103cdf0e10cSrcweir
getCellByPosition(sal_Int32 nColumn,sal_Int32 nRow)104cdf0e10cSrcweir Reference< XCell > SAL_CALL TableColumn::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir throwIfDisposed();
107cdf0e10cSrcweir if( nColumn != 0 )
108cdf0e10cSrcweir throw IndexOutOfBoundsException();
109cdf0e10cSrcweir
110cdf0e10cSrcweir return mxTableModel->getCellByPosition( mnColumn, nRow );
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113cdf0e10cSrcweir // -----------------------------------------------------------------------------
114cdf0e10cSrcweir
getCellRangeByPosition(sal_Int32 nLeft,sal_Int32 nTop,sal_Int32 nRight,sal_Int32 nBottom)115cdf0e10cSrcweir Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (IndexOutOfBoundsException, RuntimeException)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir throwIfDisposed();
118cdf0e10cSrcweir if( (nTop >= 0 ) && (nLeft == 0) && (nBottom >= nTop) && (nRight == 0) )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir return mxTableModel->getCellRangeByPosition( mnColumn, nTop, mnColumn, nBottom );
121cdf0e10cSrcweir }
122cdf0e10cSrcweir throw IndexOutOfBoundsException();
123cdf0e10cSrcweir }
124cdf0e10cSrcweir
125cdf0e10cSrcweir // -----------------------------------------------------------------------------
126cdf0e10cSrcweir
getCellRangeByName(const OUString &)127cdf0e10cSrcweir Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByName( const OUString& /*aRange*/ ) throw (RuntimeException)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir return Reference< XCellRange >();
130cdf0e10cSrcweir }
131cdf0e10cSrcweir
132cdf0e10cSrcweir // -----------------------------------------------------------------------------
133cdf0e10cSrcweir // XNamed
134cdf0e10cSrcweir // -----------------------------------------------------------------------------
135cdf0e10cSrcweir
getName()136cdf0e10cSrcweir OUString SAL_CALL TableColumn::getName() throw (RuntimeException)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir return maName;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141cdf0e10cSrcweir // -----------------------------------------------------------------------------
142cdf0e10cSrcweir
setName(const OUString & aName)143cdf0e10cSrcweir void SAL_CALL TableColumn::setName( const OUString& aName ) throw (RuntimeException)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir maName = aName;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir // -----------------------------------------------------------------------------
149cdf0e10cSrcweir // XFastPropertySet
150cdf0e10cSrcweir // -----------------------------------------------------------------------------
151cdf0e10cSrcweir
setFastPropertyValue(sal_Int32 nHandle,const Any & aValue)152cdf0e10cSrcweir void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, RuntimeException)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir bool bOk = false;
155cdf0e10cSrcweir bool bChange = false;
156cdf0e10cSrcweir
157cdf0e10cSrcweir SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();
158cdf0e10cSrcweir
159cdf0e10cSrcweir TableColumnUndo* pUndo = 0;
160cdf0e10cSrcweir if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled() )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir TableColumnRef xThis( this );
163cdf0e10cSrcweir pUndo = new TableColumnUndo( xThis );
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
166cdf0e10cSrcweir switch( nHandle )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir case Property_Width:
169cdf0e10cSrcweir {
170cdf0e10cSrcweir sal_Int32 nWidth = mnWidth;
171cdf0e10cSrcweir bOk = aValue >>= nWidth;
172cdf0e10cSrcweir if( bOk && (nWidth != mnWidth) )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir mnWidth = nWidth;
175cdf0e10cSrcweir mbOptimalWidth = mnWidth == 0;
176cdf0e10cSrcweir bChange = true;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir break;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir case Property_OptimalWidth:
181cdf0e10cSrcweir {
182cdf0e10cSrcweir sal_Bool bOptimalWidth = mbOptimalWidth;
183cdf0e10cSrcweir bOk = aValue >>= bOptimalWidth;
184cdf0e10cSrcweir if( bOk && (mbOptimalWidth != bOptimalWidth) )
185cdf0e10cSrcweir {
186cdf0e10cSrcweir mbOptimalWidth = bOptimalWidth;
187cdf0e10cSrcweir if( bOptimalWidth )
188cdf0e10cSrcweir mnWidth = 0;
189cdf0e10cSrcweir bChange = true;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir break;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir case Property_IsVisible:
194cdf0e10cSrcweir {
195cdf0e10cSrcweir sal_Bool bIsVisible = mbIsVisible;
196cdf0e10cSrcweir bOk = aValue >>= bIsVisible;
197cdf0e10cSrcweir if( bOk && (mbIsVisible != bIsVisible) )
198cdf0e10cSrcweir {
199cdf0e10cSrcweir mbIsVisible = bIsVisible;
200cdf0e10cSrcweir bChange = true;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir break;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir
205cdf0e10cSrcweir case Property_IsStartOfNewPage:
206cdf0e10cSrcweir {
207cdf0e10cSrcweir sal_Bool bIsStartOfNewPage = mbIsStartOfNewPage;
208cdf0e10cSrcweir bOk = aValue >>= bIsStartOfNewPage;
209cdf0e10cSrcweir if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir mbIsStartOfNewPage = bIsStartOfNewPage;
212cdf0e10cSrcweir bChange = true;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir break;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir default:
217cdf0e10cSrcweir throw UnknownPropertyException();
218cdf0e10cSrcweir }
219cdf0e10cSrcweir if( !bOk )
220cdf0e10cSrcweir throw IllegalArgumentException();
221cdf0e10cSrcweir
222cdf0e10cSrcweir if( bChange )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir if( pUndo )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir pModel->AddUndo( pUndo );
227cdf0e10cSrcweir pUndo = 0;
228cdf0e10cSrcweir }
229cdf0e10cSrcweir mxTableModel->setModified(sal_True);
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
232cdf0e10cSrcweir if( pUndo )
233cdf0e10cSrcweir delete pUndo;
234cdf0e10cSrcweir }
235cdf0e10cSrcweir
236cdf0e10cSrcweir // -----------------------------------------------------------------------------
237cdf0e10cSrcweir
getFastPropertyValue(sal_Int32 nHandle)238cdf0e10cSrcweir Any SAL_CALL TableColumn::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
239cdf0e10cSrcweir {
240cdf0e10cSrcweir switch( nHandle )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir case Property_Width: return Any( mnWidth );
243cdf0e10cSrcweir case Property_OptimalWidth: return Any( mbOptimalWidth );
244cdf0e10cSrcweir case Property_IsVisible: return Any( mbIsVisible );
245cdf0e10cSrcweir case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
246cdf0e10cSrcweir default: throw UnknownPropertyException();
247cdf0e10cSrcweir }
248cdf0e10cSrcweir }
249cdf0e10cSrcweir
250cdf0e10cSrcweir // -----------------------------------------------------------------------------
251cdf0e10cSrcweir
getStaticPropertySetInfo()252cdf0e10cSrcweir rtl::Reference< ::comphelper::FastPropertySetInfo > TableColumn::getStaticPropertySetInfo()
253cdf0e10cSrcweir {
254cdf0e10cSrcweir static rtl::Reference< ::comphelper::FastPropertySetInfo > xInfo;
255cdf0e10cSrcweir if( !xInfo.is() )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
258cdf0e10cSrcweir if( !xInfo.is() )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir comphelper::PropertyVector aProperties(6);
261cdf0e10cSrcweir
262cdf0e10cSrcweir aProperties[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ) );
263cdf0e10cSrcweir aProperties[0].Handle = Property_Width;
264cdf0e10cSrcweir aProperties[0].Type = ::getCppuType((const sal_Int32*)0);
265cdf0e10cSrcweir aProperties[0].Attributes = 0;
266cdf0e10cSrcweir
267cdf0e10cSrcweir aProperties[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalWidth" ) );
268cdf0e10cSrcweir aProperties[1].Handle = Property_OptimalWidth;
269cdf0e10cSrcweir aProperties[1].Type = ::getBooleanCppuType();
270cdf0e10cSrcweir aProperties[1].Attributes = 0;
271cdf0e10cSrcweir
272cdf0e10cSrcweir aProperties[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) );
273cdf0e10cSrcweir aProperties[2].Handle = Property_IsVisible;
274cdf0e10cSrcweir aProperties[2].Type = ::getBooleanCppuType();
275cdf0e10cSrcweir aProperties[2].Attributes = 0;
276cdf0e10cSrcweir
277cdf0e10cSrcweir aProperties[3].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" ) );
278cdf0e10cSrcweir aProperties[3].Handle = Property_IsStartOfNewPage;
279cdf0e10cSrcweir aProperties[3].Type = ::getBooleanCppuType();
280cdf0e10cSrcweir aProperties[3].Attributes = 0;
281cdf0e10cSrcweir
282cdf0e10cSrcweir aProperties[4].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) );
283cdf0e10cSrcweir aProperties[4].Handle = Property_Width;
284cdf0e10cSrcweir aProperties[4].Type = ::getCppuType((const sal_Int32*)0);
285cdf0e10cSrcweir aProperties[4].Attributes = 0;
286cdf0e10cSrcweir
287cdf0e10cSrcweir aProperties[5].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalSize" ) );
288cdf0e10cSrcweir aProperties[5].Handle = Property_OptimalWidth;
289cdf0e10cSrcweir aProperties[5].Type = ::getBooleanCppuType();
290cdf0e10cSrcweir aProperties[5].Attributes = 0;
291cdf0e10cSrcweir
292cdf0e10cSrcweir xInfo.set( new ::comphelper::FastPropertySetInfo(aProperties) );
293cdf0e10cSrcweir }
294cdf0e10cSrcweir }
295cdf0e10cSrcweir
296cdf0e10cSrcweir return xInfo;
297cdf0e10cSrcweir }
298cdf0e10cSrcweir
299cdf0e10cSrcweir // -----------------------------------------------------------------------------
300cdf0e10cSrcweir
301cdf0e10cSrcweir } }
302