1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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
;
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;
49 TableColumn::TableColumn( const TableModelRef
& xTableModel
, sal_Int32 nColumn
)
50 : TableColumnBase( getStaticPropertySetInfo() )
51 , mxTableModel( xTableModel
)
54 , mbOptimalWidth( true )
56 , mbIsStartOfNewPage( false )
62 TableColumn::~TableColumn()
68 void TableColumn::dispose()
75 void TableColumn::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException
)
77 if( !mxTableModel
.is() )
78 throw DisposedException();
83 TableColumn
& TableColumn::operator=( const TableColumn
& r
)
86 mbOptimalWidth
= r
.mbOptimalWidth
;
87 mbIsVisible
= r
.mbIsVisible
;
88 mbIsStartOfNewPage
= r
.mbIsStartOfNewPage
;
90 mnColumn
= r
.mnColumn
;
99 Reference
< XCell
> SAL_CALL
TableColumn::getCellByPosition( sal_Int32 nColumn
, sal_Int32 nRow
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
103 throw IndexOutOfBoundsException();
105 return mxTableModel
->getCellByPosition( mnColumn
, nRow
);
110 Reference
< XCellRange
> SAL_CALL
TableColumn::getCellRangeByPosition( sal_Int32 nLeft
, sal_Int32 nTop
, sal_Int32 nRight
, sal_Int32 nBottom
) throw (IndexOutOfBoundsException
, RuntimeException
, std::exception
)
113 if( (nTop
>= 0 ) && (nLeft
== 0) && (nBottom
>= nTop
) && (nRight
== 0) )
115 return mxTableModel
->getCellRangeByPosition( mnColumn
, nTop
, mnColumn
, nBottom
);
117 throw IndexOutOfBoundsException();
122 Reference
< XCellRange
> SAL_CALL
TableColumn::getCellRangeByName( const OUString
& /*aRange*/ ) throw (RuntimeException
, std::exception
)
124 return Reference
< XCellRange
>();
131 OUString SAL_CALL
TableColumn::getName() throw (RuntimeException
, std::exception
)
138 void SAL_CALL
TableColumn::setName( const OUString
& aName
) throw (RuntimeException
, std::exception
)
147 void SAL_CALL
TableColumn::setFastPropertyValue( sal_Int32 nHandle
, const Any
& aValue
) throw (UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
, RuntimeException
, std::exception
)
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
);
165 sal_Int32 nWidth
= mnWidth
;
166 bOk
= aValue
>>= nWidth
;
167 if( bOk
&& (nWidth
!= mnWidth
) )
170 mbOptimalWidth
= mnWidth
== 0;
175 case Property_OptimalWidth
:
177 bool bOptimalWidth
= mbOptimalWidth
;
178 bOk
= aValue
>>= bOptimalWidth
;
179 if( bOk
&& (mbOptimalWidth
!= bOptimalWidth
) )
181 mbOptimalWidth
= bOptimalWidth
;
188 case Property_IsVisible
:
190 bool bIsVisible
= mbIsVisible
;
191 bOk
= aValue
>>= bIsVisible
;
192 if( bOk
&& (mbIsVisible
!= bIsVisible
) )
194 mbIsVisible
= bIsVisible
;
200 case Property_IsStartOfNewPage
:
202 bool bIsStartOfNewPage
= mbIsStartOfNewPage
;
203 bOk
= aValue
>>= bIsStartOfNewPage
;
204 if( bOk
&& (mbIsStartOfNewPage
!= bIsStartOfNewPage
) )
206 mbIsStartOfNewPage
= bIsStartOfNewPage
;
213 throw UnknownPropertyException();
218 throw IllegalArgumentException();
225 pModel
->AddUndo( pUndo
);
228 mxTableModel
->setModified(sal_True
);
236 Any SAL_CALL
TableColumn::getFastPropertyValue( sal_Int32 nHandle
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
240 case Property_Width
: return Any( mnWidth
);
241 case Property_OptimalWidth
: return Any( mbOptimalWidth
);
242 case Property_IsVisible
: return Any( mbIsVisible
);
243 case Property_IsStartOfNewPage
: return Any( mbIsStartOfNewPage
);
244 default: throw UnknownPropertyException();
250 rtl::Reference
< FastPropertySetInfo
> TableColumn::getStaticPropertySetInfo()
252 static rtl::Reference
< FastPropertySetInfo
> xInfo
;
255 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
258 PropertyVector
aProperties(6);
260 aProperties
[0].Name
= "Width";
261 aProperties
[0].Handle
= Property_Width
;
262 aProperties
[0].Type
= ::cppu::UnoType
<sal_Int32
>::get();
263 aProperties
[0].Attributes
= 0;
265 aProperties
[1].Name
= "OptimalWidth";
266 aProperties
[1].Handle
= Property_OptimalWidth
;
267 aProperties
[1].Type
= cppu::UnoType
<bool>::get();
268 aProperties
[1].Attributes
= 0;
270 aProperties
[2].Name
= "IsVisible";
271 aProperties
[2].Handle
= Property_IsVisible
;
272 aProperties
[2].Type
= cppu::UnoType
<bool>::get();
273 aProperties
[2].Attributes
= 0;
275 aProperties
[3].Name
= "IsStartOfNewPage";
276 aProperties
[3].Handle
= Property_IsStartOfNewPage
;
277 aProperties
[3].Type
= cppu::UnoType
<bool>::get();
278 aProperties
[3].Attributes
= 0;
280 aProperties
[4].Name
= "Size";
281 aProperties
[4].Handle
= Property_Width
;
282 aProperties
[4].Type
= ::cppu::UnoType
<sal_Int32
>::get();
283 aProperties
[4].Attributes
= 0;
285 aProperties
[5].Name
= "OptimalSize";
286 aProperties
[5].Handle
= Property_OptimalWidth
;
287 aProperties
[5].Type
= cppu::UnoType
<bool>::get();
288 aProperties
[5].Attributes
= 0;
290 xInfo
.set( new FastPropertySetInfo(aProperties
) );
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */