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"
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 // -----------------------------------------------------------------------------
47 // -----------------------------------------------------------------------------
49 TableColumn::TableColumn( const TableModelRef
& xTableModel
, sal_Int32 nColumn
)
50 : TableColumnBase( getStaticPropertySetInfo() )
51 , mxTableModel( xTableModel
)
54 , mbOptimalWidth( sal_True
)
55 , mbIsVisible( sal_True
)
56 , mbIsStartOfNewPage( sal_False
)
60 // -----------------------------------------------------------------------------
62 TableColumn::~TableColumn()
66 // -----------------------------------------------------------------------------
68 void TableColumn::dispose()
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
)
86 mbOptimalWidth
= r
.mbOptimalWidth
;
87 mbIsVisible
= r
.mbIsVisible
;
88 mbIsStartOfNewPage
= r
.mbIsStartOfNewPage
;
90 mnColumn
= r
.mnColumn
;
95 // -----------------------------------------------------------------------------
97 // -----------------------------------------------------------------------------
99 Reference
< XCell
> SAL_CALL
TableColumn::getCellByPosition( sal_Int32 nColumn
, sal_Int32 nRow
) throw (IndexOutOfBoundsException
, RuntimeException
)
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
)
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 // -----------------------------------------------------------------------------
129 // -----------------------------------------------------------------------------
131 OUString SAL_CALL
TableColumn::getName() throw (RuntimeException
)
136 // -----------------------------------------------------------------------------
138 void SAL_CALL
TableColumn::setName( const OUString
& aName
) throw (RuntimeException
)
143 // -----------------------------------------------------------------------------
145 // -----------------------------------------------------------------------------
147 void SAL_CALL
TableColumn::setFastPropertyValue( sal_Int32 nHandle
, const Any
& aValue
) throw (UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, ::com::sun::star::lang::WrappedTargetException
, RuntimeException
)
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 sal_Bool bOptimalWidth
= mbOptimalWidth
;
178 bOk
= aValue
>>= bOptimalWidth
;
179 if( bOk
&& (mbOptimalWidth
!= bOptimalWidth
) )
181 mbOptimalWidth
= bOptimalWidth
;
188 case Property_IsVisible
:
190 sal_Bool bIsVisible
= mbIsVisible
;
191 bOk
= aValue
>>= bIsVisible
;
192 if( bOk
&& (mbIsVisible
!= bIsVisible
) )
194 mbIsVisible
= bIsVisible
;
200 case Property_IsStartOfNewPage
:
202 sal_Bool bIsStartOfNewPage
= mbIsStartOfNewPage
;
203 bOk
= aValue
>>= bIsStartOfNewPage
;
204 if( bOk
&& (mbIsStartOfNewPage
!= bIsStartOfNewPage
) )
206 mbIsStartOfNewPage
= bIsStartOfNewPage
;
212 throw UnknownPropertyException();
215 throw IllegalArgumentException();
221 pModel
->AddUndo( pUndo
);
224 mxTableModel
->setModified(sal_True
);
230 // -----------------------------------------------------------------------------
232 Any SAL_CALL
TableColumn::getFastPropertyValue( sal_Int32 nHandle
) throw (UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
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
;
251 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
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
) );
293 // -----------------------------------------------------------------------------
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */