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>
22 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24 #include "tablecolumn.hxx"
25 #include "tableundo.hxx"
26 #include <svx/svdmodel.hxx>
27 #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
;
37 namespace sdr
{ namespace table
{
39 const sal_Int32 Property_Width
= 0;
40 const sal_Int32 Property_OptimalWidth
= 1;
41 const sal_Int32 Property_IsVisible
= 2;
42 const sal_Int32 Property_IsStartOfNewPage
= 3;
48 TableColumn::TableColumn( const TableModelRef
& xTableModel
, sal_Int32 nColumn
)
49 : TableColumnBase( getStaticPropertySetInfo() )
50 , mxTableModel( xTableModel
)
53 , mbOptimalWidth( true )
55 , mbIsStartOfNewPage( false )
60 TableColumn::~TableColumn()
65 void TableColumn::dispose()
71 void TableColumn::throwIfDisposed() const
73 if( !mxTableModel
.is() )
74 throw DisposedException();
78 TableColumn
& TableColumn::operator=( const TableColumn
& r
)
81 mbOptimalWidth
= r
.mbOptimalWidth
;
82 mbIsVisible
= r
.mbIsVisible
;
83 mbIsStartOfNewPage
= r
.mbIsStartOfNewPage
;
85 mnColumn
= r
.mnColumn
;
94 Reference
< XCell
> SAL_CALL
TableColumn::getCellByPosition( sal_Int32 nColumn
, sal_Int32 nRow
)
98 throw IndexOutOfBoundsException();
100 return mxTableModel
->getCellByPosition( mnColumn
, nRow
);
104 Reference
< XCellRange
> SAL_CALL
TableColumn::getCellRangeByPosition( sal_Int32 nLeft
, sal_Int32 nTop
, sal_Int32 nRight
, sal_Int32 nBottom
)
107 if( (nTop
>= 0 ) && (nLeft
== 0) && (nBottom
>= nTop
) && (nRight
== 0) )
109 return mxTableModel
->getCellRangeByPosition( mnColumn
, nTop
, mnColumn
, nBottom
);
111 throw IndexOutOfBoundsException();
115 Reference
< XCellRange
> SAL_CALL
TableColumn::getCellRangeByName( const OUString
& /*aRange*/ )
117 return Reference
< XCellRange
>();
124 OUString SAL_CALL
TableColumn::getName()
130 void SAL_CALL
TableColumn::setName( const OUString
& aName
)
139 void SAL_CALL
TableColumn::setFastPropertyValue( sal_Int32 nHandle
, const Any
& aValue
)
142 bool bChange
= false;
144 SdrModel
& rModel(mxTableModel
->getSdrTableObj()->getSdrModelFromSdrObject());
145 std::unique_ptr
<TableColumnUndo
> pUndo
;
147 if( mxTableModel
.is() && mxTableModel
->getSdrTableObj() && mxTableModel
->getSdrTableObj()->IsInserted() && rModel
.IsUndoEnabled() )
149 TableColumnRef
xThis( this );
150 pUndo
.reset( new TableColumnUndo( xThis
) );
157 sal_Int32 nWidth
= mnWidth
;
158 bOk
= aValue
>>= nWidth
;
159 if( bOk
&& (nWidth
!= mnWidth
) )
162 mbOptimalWidth
= mnWidth
== 0;
167 case Property_OptimalWidth
:
169 bool bOptimalWidth
= mbOptimalWidth
;
170 bOk
= aValue
>>= bOptimalWidth
;
171 if( bOk
&& (mbOptimalWidth
!= bOptimalWidth
) )
173 mbOptimalWidth
= bOptimalWidth
;
180 case Property_IsVisible
:
182 bool bIsVisible
= mbIsVisible
;
183 bOk
= aValue
>>= bIsVisible
;
184 if( bOk
&& (mbIsVisible
!= bIsVisible
) )
186 mbIsVisible
= bIsVisible
;
192 case Property_IsStartOfNewPage
:
194 bool bIsStartOfNewPage
= mbIsStartOfNewPage
;
195 bOk
= aValue
>>= bIsStartOfNewPage
;
196 if( bOk
&& (mbIsStartOfNewPage
!= bIsStartOfNewPage
) )
198 mbIsStartOfNewPage
= bIsStartOfNewPage
;
204 throw UnknownPropertyException( OUString::number(nHandle
), static_cast<cppu::OWeakObject
*>(this));
208 throw IllegalArgumentException();
215 rModel
.AddUndo( std::move(pUndo
) );
217 mxTableModel
->setModified(true);
222 Any SAL_CALL
TableColumn::getFastPropertyValue( sal_Int32 nHandle
)
226 case Property_Width
: return Any( mnWidth
);
227 case Property_OptimalWidth
: return Any( mbOptimalWidth
);
228 case Property_IsVisible
: return Any( mbIsVisible
);
229 case Property_IsStartOfNewPage
: return Any( mbIsStartOfNewPage
);
230 default: throw UnknownPropertyException( OUString::number(nHandle
), static_cast<cppu::OWeakObject
*>(this));
235 rtl::Reference
< FastPropertySetInfo
> TableColumn::getStaticPropertySetInfo()
237 static rtl::Reference
<FastPropertySetInfo
> xInfo
= []() {
238 PropertyVector
aProperties(6);
240 aProperties
[0].Name
= "Width";
241 aProperties
[0].Handle
= Property_Width
;
242 aProperties
[0].Type
= ::cppu::UnoType
<sal_Int32
>::get();
243 aProperties
[0].Attributes
= 0;
245 aProperties
[1].Name
= "OptimalWidth";
246 aProperties
[1].Handle
= Property_OptimalWidth
;
247 aProperties
[1].Type
= cppu::UnoType
<bool>::get();
248 aProperties
[1].Attributes
= 0;
250 aProperties
[2].Name
= "IsVisible";
251 aProperties
[2].Handle
= Property_IsVisible
;
252 aProperties
[2].Type
= cppu::UnoType
<bool>::get();
253 aProperties
[2].Attributes
= 0;
255 aProperties
[3].Name
= "IsStartOfNewPage";
256 aProperties
[3].Handle
= Property_IsStartOfNewPage
;
257 aProperties
[3].Type
= cppu::UnoType
<bool>::get();
258 aProperties
[3].Attributes
= 0;
260 aProperties
[4].Name
= "Size";
261 aProperties
[4].Handle
= Property_Width
;
262 aProperties
[4].Type
= ::cppu::UnoType
<sal_Int32
>::get();
263 aProperties
[4].Attributes
= 0;
265 aProperties
[5].Name
= "OptimalSize";
266 aProperties
[5].Handle
= Property_OptimalWidth
;
267 aProperties
[5].Type
= cppu::UnoType
<bool>::get();
268 aProperties
[5].Attributes
= 0;
270 return rtl::Reference
<FastPropertySetInfo
>(new FastPropertySetInfo(aProperties
));
276 TableModelRef
const & TableColumn::getModel() const
281 sal_Int32
TableColumn::getWidth() const
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */