Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / table / tablecolumn.cxx
bloba13b3073be257772c980b71ba2f9cde2726ea770
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
30 #include <utility>
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;
48 // TableRow
51 TableColumn::TableColumn( TableModelRef xTableModel, sal_Int32 nColumn )
52 : TableColumnBase( getStaticPropertySetInfo() )
53 , mxTableModel(std::move( xTableModel ))
54 , mnColumn( nColumn )
55 , mnWidth( 0 )
56 , mbOptimalWidth( true )
57 , mbIsVisible( true )
58 , mbIsStartOfNewPage( false )
63 TableColumn::~TableColumn()
68 void TableColumn::dispose()
70 mxTableModel.clear();
74 void TableColumn::throwIfDisposed() const
76 if( !mxTableModel.is() )
77 throw DisposedException();
81 TableColumn& TableColumn::operator=( const TableColumn& r )
83 mnWidth = r.mnWidth;
84 mbOptimalWidth = r.mbOptimalWidth;
85 mbIsVisible = r.mbIsVisible;
86 mbIsStartOfNewPage = r.mbIsStartOfNewPage;
87 maName = r.maName;
88 mnColumn = r.mnColumn;
90 return *this;
94 // XCellRange
97 Reference< XCell > SAL_CALL TableColumn::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow )
99 throwIfDisposed();
100 if( nColumn != 0 )
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 )
109 throwIfDisposed();
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 >();
124 // XNamed
127 OUString SAL_CALL TableColumn::getName()
129 return maName;
133 void SAL_CALL TableColumn::setName( const OUString& aName )
135 maName = aName;
139 // XFastPropertySet
142 void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue )
144 bool bOk = false;
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 ) );
156 switch( nHandle )
158 case Property_Width:
160 sal_Int32 nWidth = mnWidth;
161 bOk = aValue >>= nWidth;
162 if( bOk && (nWidth != mnWidth) )
164 mnWidth = nWidth;
165 mbOptimalWidth = mnWidth == 0;
166 bChange = true;
168 break;
170 case Property_OptimalWidth:
172 bool bOptimalWidth = mbOptimalWidth;
173 bOk = aValue >>= bOptimalWidth;
174 if( bOk && (mbOptimalWidth != bOptimalWidth) )
176 mbOptimalWidth = bOptimalWidth;
177 if( bOptimalWidth )
178 mnWidth = 0;
179 bChange = true;
181 break;
183 case Property_IsVisible:
185 bool bIsVisible = mbIsVisible;
186 bOk = aValue >>= bIsVisible;
187 if( bOk && (mbIsVisible != bIsVisible) )
189 mbIsVisible = bIsVisible;
190 bChange = true;
192 break;
195 case Property_IsStartOfNewPage:
197 bool bIsStartOfNewPage = mbIsStartOfNewPage;
198 bOk = aValue >>= bIsStartOfNewPage;
199 if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
201 mbIsStartOfNewPage = bIsStartOfNewPage;
202 bChange = true;
204 break;
206 default:
207 throw UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
209 if( !bOk )
211 throw IllegalArgumentException();
214 if( bChange )
216 if( pUndo )
218 rModel.AddUndo( std::move(pUndo) );
220 mxTableModel->setModified(true);
225 Any SAL_CALL TableColumn::getFastPropertyValue( sal_Int32 nHandle )
227 switch( 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));
274 }();
276 return xInfo;
279 TableModelRef const & TableColumn::getModel() const
281 return mxTableModel;
284 sal_Int32 TableColumn::getWidth() const
286 return mnWidth;
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */