Bump version to 6.4-15
[LibreOffice.git] / svx / source / table / tablecolumn.cxx
blob2342c6f10c87c893b1648cfdac9c29a7505a544c
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 "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;
45 // TableRow
48 TableColumn::TableColumn( const TableModelRef& xTableModel, sal_Int32 nColumn )
49 : TableColumnBase( getStaticPropertySetInfo() )
50 , mxTableModel( xTableModel )
51 , mnColumn( nColumn )
52 , mnWidth( 0 )
53 , mbOptimalWidth( true )
54 , mbIsVisible( true )
55 , mbIsStartOfNewPage( false )
60 TableColumn::~TableColumn()
65 void TableColumn::dispose()
67 mxTableModel.clear();
71 void TableColumn::throwIfDisposed() const
73 if( !mxTableModel.is() )
74 throw DisposedException();
78 TableColumn& TableColumn::operator=( const TableColumn& r )
80 mnWidth = r.mnWidth;
81 mbOptimalWidth = r.mbOptimalWidth;
82 mbIsVisible = r.mbIsVisible;
83 mbIsStartOfNewPage = r.mbIsStartOfNewPage;
84 maName = r.maName;
85 mnColumn = r.mnColumn;
87 return *this;
91 // XCellRange
94 Reference< XCell > SAL_CALL TableColumn::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow )
96 throwIfDisposed();
97 if( nColumn != 0 )
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 )
106 throwIfDisposed();
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 >();
121 // XNamed
124 OUString SAL_CALL TableColumn::getName()
126 return maName;
130 void SAL_CALL TableColumn::setName( const OUString& aName )
132 maName = aName;
136 // XFastPropertySet
139 void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue )
141 bool bOk = false;
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 ) );
153 switch( nHandle )
155 case Property_Width:
157 sal_Int32 nWidth = mnWidth;
158 bOk = aValue >>= nWidth;
159 if( bOk && (nWidth != mnWidth) )
161 mnWidth = nWidth;
162 mbOptimalWidth = mnWidth == 0;
163 bChange = true;
165 break;
167 case Property_OptimalWidth:
169 bool bOptimalWidth = mbOptimalWidth;
170 bOk = aValue >>= bOptimalWidth;
171 if( bOk && (mbOptimalWidth != bOptimalWidth) )
173 mbOptimalWidth = bOptimalWidth;
174 if( bOptimalWidth )
175 mnWidth = 0;
176 bChange = true;
178 break;
180 case Property_IsVisible:
182 bool bIsVisible = mbIsVisible;
183 bOk = aValue >>= bIsVisible;
184 if( bOk && (mbIsVisible != bIsVisible) )
186 mbIsVisible = bIsVisible;
187 bChange = true;
189 break;
192 case Property_IsStartOfNewPage:
194 bool bIsStartOfNewPage = mbIsStartOfNewPage;
195 bOk = aValue >>= bIsStartOfNewPage;
196 if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
198 mbIsStartOfNewPage = bIsStartOfNewPage;
199 bChange = true;
201 break;
203 default:
204 throw UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
206 if( !bOk )
208 throw IllegalArgumentException();
211 if( bChange )
213 if( pUndo )
215 rModel.AddUndo( std::move(pUndo) );
217 mxTableModel->setModified(true);
222 Any SAL_CALL TableColumn::getFastPropertyValue( sal_Int32 nHandle )
224 switch( 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));
271 }();
273 return xInfo;
276 TableModelRef const & TableColumn::getModel() const
278 return mxTableModel;
281 sal_Int32 TableColumn::getWidth() const
283 return mnWidth;
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */