1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tablecolumn.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <com/sun/star/lang/DisposedException.hpp>
36 #include "tablecolumn.hxx"
37 #include "tableundo.hxx"
38 #include "svx/svdmodel.hxx"
39 #include "svx/svdotable.hxx"
41 // -----------------------------------------------------------------------------
43 using ::rtl::OUString
;
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::lang
;
46 using namespace ::com::sun::star::container
;
47 using namespace ::com::sun::star::table
;
48 using namespace ::com::sun::star::beans
;
50 // -----------------------------------------------------------------------------
52 namespace sdr
{ namespace table
{
54 const sal_Int32 Property_Width
= 0;
55 const sal_Int32 Property_OptimalWidth
= 1;
56 const sal_Int32 Property_IsVisible
= 2;
57 const sal_Int32 Property_IsStartOfNewPage
= 3;
59 // -----------------------------------------------------------------------------
61 // -----------------------------------------------------------------------------
63 TableColumn::TableColumn( const TableModelRef
& xTableModel
, sal_Int32 nColumn
)
64 : TableColumnBase( getStaticPropertySetInfo() )
65 , mxTableModel( xTableModel
)
68 , mbOptimalWidth( sal_True
)
69 , mbIsVisible( sal_True
)
70 , mbIsStartOfNewPage( sal_False
)
74 // -----------------------------------------------------------------------------
76 TableColumn::~TableColumn()
80 // -----------------------------------------------------------------------------
82 void TableColumn::dispose()
87 // -----------------------------------------------------------------------------
89 void TableColumn::throwIfDisposed() const throw (::com::sun::star::uno::RuntimeException
)
91 if( !mxTableModel
.is() )
92 throw DisposedException();
95 // -----------------------------------------------------------------------------
97 TableColumn
& TableColumn::operator=( const TableColumn
& r
)
100 mbOptimalWidth
= r
.mbOptimalWidth
;
101 mbIsVisible
= r
.mbIsVisible
;
102 mbIsStartOfNewPage
= r
.mbIsStartOfNewPage
;
107 // -----------------------------------------------------------------------------
109 // -----------------------------------------------------------------------------
111 Reference
< XCell
> SAL_CALL
TableColumn::getCellByPosition( sal_Int32 nColumn
, sal_Int32 nRow
) throw (IndexOutOfBoundsException
, RuntimeException
)
115 throw IndexOutOfBoundsException();
117 return mxTableModel
->getCellByPosition( mnColumn
, nRow
);
120 // -----------------------------------------------------------------------------
122 Reference
< XCellRange
> SAL_CALL
TableColumn::getCellRangeByPosition( sal_Int32 nLeft
, sal_Int32 nTop
, sal_Int32 nRight
, sal_Int32 nBottom
) throw (IndexOutOfBoundsException
, RuntimeException
)
125 if( (nTop
>= 0 ) && (nLeft
== 0) && (nBottom
>= nTop
) && (nRight
== 0) )
127 return mxTableModel
->getCellRangeByPosition( mnColumn
, nTop
, mnColumn
, nBottom
);
129 throw IndexOutOfBoundsException();
132 // -----------------------------------------------------------------------------
134 Reference
< XCellRange
> SAL_CALL
TableColumn::getCellRangeByName( const OUString
& /*aRange*/ ) throw (RuntimeException
)
136 return Reference
< XCellRange
>();
139 // -----------------------------------------------------------------------------
141 // -----------------------------------------------------------------------------
143 OUString SAL_CALL
TableColumn::getName() throw (RuntimeException
)
148 // -----------------------------------------------------------------------------
150 void SAL_CALL
TableColumn::setName( const OUString
& aName
) throw (RuntimeException
)
155 // -----------------------------------------------------------------------------
157 // -----------------------------------------------------------------------------
159 void SAL_CALL
TableColumn::setFastPropertyValue( sal_Int32 nHandle
, const Any
& aValue
) throw (UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
, RuntimeException
)
162 bool bChange
= false;
164 SdrModel
* pModel
= mxTableModel
->getSdrTableObj()->GetModel();
166 TableColumnUndo
* pUndo
= 0;
167 if( mxTableModel
.is() && mxTableModel
->getSdrTableObj() && mxTableModel
->getSdrTableObj()->IsInserted() && pModel
&& pModel
->IsUndoEnabled() )
169 TableColumnRef
xThis( this );
170 pUndo
= new TableColumnUndo( xThis
);
177 sal_Int32 nWidth
= mnWidth
;
178 bOk
= aValue
>>= nWidth
;
179 if( bOk
&& (nWidth
!= mnWidth
) )
182 mbOptimalWidth
= mnWidth
== 0;
187 case Property_OptimalWidth
:
189 sal_Bool bOptimalWidth
= mbOptimalWidth
;
190 bOk
= aValue
>>= bOptimalWidth
;
191 if( bOk
&& (mbOptimalWidth
!= bOptimalWidth
) )
193 mbOptimalWidth
= bOptimalWidth
;
200 case Property_IsVisible
:
202 sal_Bool bIsVisible
= mbIsVisible
;
203 bOk
= aValue
>>= bIsVisible
;
204 if( bOk
&& (mbIsVisible
!= bIsVisible
) )
206 mbIsVisible
= bIsVisible
;
212 case Property_IsStartOfNewPage
:
214 sal_Bool bIsStartOfNewPage
= mbIsStartOfNewPage
;
215 bOk
= aValue
>>= bIsStartOfNewPage
;
216 if( bOk
&& (mbIsStartOfNewPage
!= bIsStartOfNewPage
) )
218 mbIsStartOfNewPage
= bIsStartOfNewPage
;
224 throw UnknownPropertyException();
227 throw IllegalArgumentException();
233 pModel
->AddUndo( pUndo
);
236 mxTableModel
->setModified(sal_True
);
243 // -----------------------------------------------------------------------------
245 Any SAL_CALL
TableColumn::getFastPropertyValue( sal_Int32 nHandle
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
249 case Property_Width
: return Any( mnWidth
);
250 case Property_OptimalWidth
: return Any( mbOptimalWidth
);
251 case Property_IsVisible
: return Any( mbIsVisible
);
252 case Property_IsStartOfNewPage
: return Any( mbIsStartOfNewPage
);
253 default: throw UnknownPropertyException();
257 // -----------------------------------------------------------------------------
259 rtl::Reference
< ::comphelper::FastPropertySetInfo
> TableColumn::getStaticPropertySetInfo()
261 static rtl::Reference
< ::comphelper::FastPropertySetInfo
> xInfo
;
264 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
267 comphelper::PropertyVector
aProperties(6);
269 aProperties
[0].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ) );
270 aProperties
[0].Handle
= Property_Width
;
271 aProperties
[0].Type
= ::getCppuType((const sal_Int32
*)0);
272 aProperties
[0].Attributes
= 0;
274 aProperties
[1].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalWidth" ) );
275 aProperties
[1].Handle
= Property_OptimalWidth
;
276 aProperties
[1].Type
= ::getBooleanCppuType();
277 aProperties
[1].Attributes
= 0;
279 aProperties
[2].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) );
280 aProperties
[2].Handle
= Property_IsVisible
;
281 aProperties
[2].Type
= ::getBooleanCppuType();
282 aProperties
[2].Attributes
= 0;
284 aProperties
[3].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" ) );
285 aProperties
[3].Handle
= Property_IsStartOfNewPage
;
286 aProperties
[3].Type
= ::getBooleanCppuType();
287 aProperties
[3].Attributes
= 0;
289 aProperties
[4].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) );
290 aProperties
[4].Handle
= Property_Width
;
291 aProperties
[4].Type
= ::getCppuType((const sal_Int32
*)0);
292 aProperties
[4].Attributes
= 0;
294 aProperties
[5].Name
= OUString( RTL_CONSTASCII_USTRINGPARAM( "OptimalSize" ) );
295 aProperties
[5].Handle
= Property_OptimalWidth
;
296 aProperties
[5].Type
= ::getBooleanCppuType();
297 aProperties
[5].Attributes
= 0;
299 xInfo
.set( new ::comphelper::FastPropertySetInfo(aProperties
) );
306 // -----------------------------------------------------------------------------