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 <tablemodel.hxx>
25 #include "tablecolumn.hxx"
26 #include "tableundo.hxx"
27 #include <sdr/properties/cellproperties.hxx>
28 #include <svx/svdmodel.hxx>
29 #include <svx/svdotable.hxx>
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::com::sun::star::container
;
36 using namespace ::com::sun::star::table
;
37 using namespace ::com::sun::star::beans
;
40 namespace sdr::table
{
42 const sal_Int32 Property_Width
= 0;
43 const sal_Int32 Property_OptimalWidth
= 1;
44 const sal_Int32 Property_IsVisible
= 2;
45 const sal_Int32 Property_IsStartOfNewPage
= 3;
51 TableColumn::TableColumn( TableModelRef xTableModel
, sal_Int32 nColumn
)
52 : TableColumnBase( getStaticPropertySetInfo() )
53 , mxTableModel(std::move( xTableModel
))
56 , mbOptimalWidth( true )
58 , mbIsStartOfNewPage( false )
63 TableColumn::~TableColumn()
68 void TableColumn::dispose()
74 void TableColumn::throwIfDisposed() const
76 if( !mxTableModel
.is() )
77 throw DisposedException();
81 TableColumn
& TableColumn::operator=( const TableColumn
& r
)
84 mbOptimalWidth
= r
.mbOptimalWidth
;
85 mbIsVisible
= r
.mbIsVisible
;
86 mbIsStartOfNewPage
= r
.mbIsStartOfNewPage
;
88 mnColumn
= r
.mnColumn
;
97 Reference
< XCell
> SAL_CALL
TableColumn::getCellByPosition( sal_Int32 nColumn
, sal_Int32 nRow
)
101 throw IndexOutOfBoundsException();
103 return mxTableModel
->getCellByPosition( mnColumn
, nRow
);
107 Reference
< XCellRange
> SAL_CALL
TableColumn::getCellRangeByPosition( sal_Int32 nLeft
, sal_Int32 nTop
, sal_Int32 nRight
, sal_Int32 nBottom
)
110 if( (nTop
>= 0 ) && (nLeft
== 0) && (nBottom
>= nTop
) && (nRight
== 0) )
112 return mxTableModel
->getCellRangeByPosition( mnColumn
, nTop
, mnColumn
, nBottom
);
114 throw IndexOutOfBoundsException();
118 Reference
< XCellRange
> SAL_CALL
TableColumn::getCellRangeByName( const OUString
& /*aRange*/ )
120 return Reference
< XCellRange
>();
127 OUString SAL_CALL
TableColumn::getName()
133 void SAL_CALL
TableColumn::setName( const OUString
& aName
)
142 void SAL_CALL
TableColumn::setFastPropertyValue( sal_Int32 nHandle
, const Any
& aValue
)
145 bool bChange
= false;
147 SdrModel
& rModel(mxTableModel
->getSdrTableObj()->getSdrModelFromSdrObject());
148 std::unique_ptr
<TableColumnUndo
> pUndo
;
150 if( mxTableModel
.is() && mxTableModel
->getSdrTableObj() && mxTableModel
->getSdrTableObj()->IsInserted() && rModel
.IsUndoEnabled() )
152 TableColumnRef
xThis( this );
153 pUndo
.reset( new TableColumnUndo( xThis
) );
160 sal_Int32 nWidth
= mnWidth
;
161 bOk
= aValue
>>= nWidth
;
162 if( bOk
&& (nWidth
!= mnWidth
) )
165 mbOptimalWidth
= mnWidth
== 0;
170 case Property_OptimalWidth
:
172 bool bOptimalWidth
= mbOptimalWidth
;
173 bOk
= aValue
>>= bOptimalWidth
;
174 if( bOk
&& (mbOptimalWidth
!= bOptimalWidth
) )
176 mbOptimalWidth
= bOptimalWidth
;
183 case Property_IsVisible
:
185 bool bIsVisible
= mbIsVisible
;
186 bOk
= aValue
>>= bIsVisible
;
187 if( bOk
&& (mbIsVisible
!= bIsVisible
) )
189 mbIsVisible
= bIsVisible
;
195 case Property_IsStartOfNewPage
:
197 bool bIsStartOfNewPage
= mbIsStartOfNewPage
;
198 bOk
= aValue
>>= bIsStartOfNewPage
;
199 if( bOk
&& (mbIsStartOfNewPage
!= bIsStartOfNewPage
) )
201 mbIsStartOfNewPage
= bIsStartOfNewPage
;
207 throw UnknownPropertyException( OUString::number(nHandle
), static_cast<cppu::OWeakObject
*>(this));
211 throw IllegalArgumentException();
218 rModel
.AddUndo( std::move(pUndo
) );
220 mxTableModel
->setModified(true);
225 Any SAL_CALL
TableColumn::getFastPropertyValue( sal_Int32 nHandle
)
229 case Property_Width
: return Any( mnWidth
);
230 case Property_OptimalWidth
: return Any( mbOptimalWidth
);
231 case Property_IsVisible
: return Any( mbIsVisible
);
232 case Property_IsStartOfNewPage
: return Any( mbIsStartOfNewPage
);
233 default: throw UnknownPropertyException( OUString::number(nHandle
), static_cast<cppu::OWeakObject
*>(this));
238 rtl::Reference
< FastPropertySetInfo
> TableColumn::getStaticPropertySetInfo()
240 static rtl::Reference
<FastPropertySetInfo
> xInfo
= []() {
241 PropertyVector
aProperties(6);
243 aProperties
[0].Name
= "Width";
244 aProperties
[0].Handle
= Property_Width
;
245 aProperties
[0].Type
= ::cppu::UnoType
<sal_Int32
>::get();
246 aProperties
[0].Attributes
= 0;
248 aProperties
[1].Name
= "OptimalWidth";
249 aProperties
[1].Handle
= Property_OptimalWidth
;
250 aProperties
[1].Type
= cppu::UnoType
<bool>::get();
251 aProperties
[1].Attributes
= 0;
253 aProperties
[2].Name
= "IsVisible";
254 aProperties
[2].Handle
= Property_IsVisible
;
255 aProperties
[2].Type
= cppu::UnoType
<bool>::get();
256 aProperties
[2].Attributes
= 0;
258 aProperties
[3].Name
= "IsStartOfNewPage";
259 aProperties
[3].Handle
= Property_IsStartOfNewPage
;
260 aProperties
[3].Type
= cppu::UnoType
<bool>::get();
261 aProperties
[3].Attributes
= 0;
263 aProperties
[4].Name
= "Size";
264 aProperties
[4].Handle
= Property_Width
;
265 aProperties
[4].Type
= ::cppu::UnoType
<sal_Int32
>::get();
266 aProperties
[4].Attributes
= 0;
268 aProperties
[5].Name
= "OptimalSize";
269 aProperties
[5].Handle
= Property_OptimalWidth
;
270 aProperties
[5].Type
= cppu::UnoType
<bool>::get();
271 aProperties
[5].Attributes
= 0;
273 return rtl::Reference
<FastPropertySetInfo
>(new FastPropertySetInfo(aProperties
));
279 TableModelRef
const & TableColumn::getModel() const
284 sal_Int32
TableColumn::getWidth() const
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */