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 // -----------------------------------------------------------------------------
57 // -----------------------------------------------------------------------------
59 TableColumn::TableColumn( const TableModelRef
& xTableModel
, sal_Int32 nColumn
)
60 : TableColumnBase( getStaticPropertySetInfo() )
61 , mxTableModel( xTableModel
)
64 , mbOptimalWidth( sal_True
)
65 , mbIsVisible( sal_True
)
66 , mbIsStartOfNewPage( sal_False
)
70 // -----------------------------------------------------------------------------
72 TableColumn::~TableColumn()
76 // -----------------------------------------------------------------------------
78 void TableColumn::dispose()
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
)
96 mbOptimalWidth
= r
.mbOptimalWidth
;
97 mbIsVisible
= r
.mbIsVisible
;
98 mbIsStartOfNewPage
= r
.mbIsStartOfNewPage
;
100 mnColumn
= r
.mnColumn
;
105 // -----------------------------------------------------------------------------
107 // -----------------------------------------------------------------------------
109 Reference
< XCell
> SAL_CALL
TableColumn::getCellByPosition( sal_Int32 nColumn
, sal_Int32 nRow
) throw (IndexOutOfBoundsException
, RuntimeException
)
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
)
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 // -----------------------------------------------------------------------------
139 // -----------------------------------------------------------------------------
141 OUString SAL_CALL
TableColumn::getName() throw (RuntimeException
)
146 // -----------------------------------------------------------------------------
148 void SAL_CALL
TableColumn::setName( const OUString
& aName
) throw (RuntimeException
)
153 // -----------------------------------------------------------------------------
155 // -----------------------------------------------------------------------------
157 void SAL_CALL
TableColumn::setFastPropertyValue( sal_Int32 nHandle
, const Any
& aValue
) throw (UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
, RuntimeException
)
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
);
175 sal_Int32 nWidth
= mnWidth
;
176 bOk
= aValue
>>= nWidth
;
177 if( bOk
&& (nWidth
!= mnWidth
) )
180 mbOptimalWidth
= mnWidth
== 0;
185 case Property_OptimalWidth
:
187 sal_Bool bOptimalWidth
= mbOptimalWidth
;
188 bOk
= aValue
>>= bOptimalWidth
;
189 if( bOk
&& (mbOptimalWidth
!= bOptimalWidth
) )
191 mbOptimalWidth
= bOptimalWidth
;
198 case Property_IsVisible
:
200 sal_Bool bIsVisible
= mbIsVisible
;
201 bOk
= aValue
>>= bIsVisible
;
202 if( bOk
&& (mbIsVisible
!= bIsVisible
) )
204 mbIsVisible
= bIsVisible
;
210 case Property_IsStartOfNewPage
:
212 sal_Bool bIsStartOfNewPage
= mbIsStartOfNewPage
;
213 bOk
= aValue
>>= bIsStartOfNewPage
;
214 if( bOk
&& (mbIsStartOfNewPage
!= bIsStartOfNewPage
) )
216 mbIsStartOfNewPage
= bIsStartOfNewPage
;
222 throw UnknownPropertyException();
225 throw IllegalArgumentException();
231 pModel
->AddUndo( pUndo
);
234 mxTableModel
->setModified(sal_True
);
241 // -----------------------------------------------------------------------------
243 Any SAL_CALL
TableColumn::getFastPropertyValue( sal_Int32 nHandle
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
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
;
262 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
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
) );
304 // -----------------------------------------------------------------------------
308 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */