LibreOffice Module svx (master) 1
tablecolumn.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <com/sun/star/lang/DisposedException.hpp>
22#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23
24#include <tablemodel.hxx>
25#include "tablecolumn.hxx"
26#include "tableundo.hxx"
27#include <svx/svdmodel.hxx>
28#include <svx/svdotable.hxx>
29#include <utility>
30
31
32using namespace ::com::sun::star::uno;
33using namespace ::com::sun::star::lang;
34using namespace ::com::sun::star::container;
35using namespace ::com::sun::star::table;
36using namespace ::com::sun::star::beans;
37
38
39namespace sdr::table {
40
41const sal_Int32 Property_Width = 0;
42const sal_Int32 Property_OptimalWidth = 1;
43const sal_Int32 Property_IsVisible = 2;
44const sal_Int32 Property_IsStartOfNewPage = 3;
45
46
47// TableRow
48
49
50TableColumn::TableColumn( TableModelRef xTableModel, sal_Int32 nColumn )
51: TableColumnBase( getStaticPropertySetInfo() )
52, mxTableModel(std::move( xTableModel ))
53, mnColumn( nColumn )
54, mnWidth( 0 )
55, mbOptimalWidth( true )
56, mbIsVisible( true )
57, mbIsStartOfNewPage( false )
58{
59}
60
61
63{
64}
65
66
68{
69 mxTableModel.clear();
70}
71
72
74{
75 if( !mxTableModel.is() )
76 throw DisposedException();
77}
78
79
81{
82 mnWidth = r.mnWidth;
86 maName = r.maName;
88
89 return *this;
90}
91
92
93// XCellRange
94
95
96Reference< XCell > SAL_CALL TableColumn::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow )
97{
99 if( nColumn != 0 )
100 throw IndexOutOfBoundsException();
101
102 return mxTableModel->getCellByPosition( mnColumn, nRow );
103}
104
105
106Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
107{
109 if( (nTop >= 0 ) && (nLeft == 0) && (nBottom >= nTop) && (nRight == 0) )
110 {
111 return mxTableModel->getCellRangeByPosition( mnColumn, nTop, mnColumn, nBottom );
112 }
113 throw IndexOutOfBoundsException();
114}
115
116
117Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByName( const OUString& /*aRange*/ )
118{
119 return Reference< XCellRange >();
120}
121
122
123// XNamed
124
125
126OUString SAL_CALL TableColumn::getName()
127{
128 return maName;
129}
130
131
132void SAL_CALL TableColumn::setName( const OUString& aName )
133{
134 maName = aName;
135}
136
137
138// XFastPropertySet
139
140
141void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue )
142{
143 bool bOk = false;
144 bool bChange = false;
145
146 SdrModel& rModel(mxTableModel->getSdrTableObj()->getSdrModelFromSdrObject());
147 std::unique_ptr<TableColumnUndo> pUndo;
148
149 if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && rModel.IsUndoEnabled() )
150 {
151 TableColumnRef xThis( this );
152 pUndo.reset( new TableColumnUndo( xThis ) );
153 }
154
155 switch( nHandle )
156 {
157 case Property_Width:
158 {
159 sal_Int32 nWidth = mnWidth;
160 bOk = aValue >>= nWidth;
161 if( bOk && (nWidth != mnWidth) )
162 {
163 mnWidth = nWidth;
164 mbOptimalWidth = mnWidth == 0;
165 bChange = true;
166 }
167 break;
168 }
170 {
171 bool bOptimalWidth = mbOptimalWidth;
172 bOk = aValue >>= bOptimalWidth;
173 if( bOk && (mbOptimalWidth != bOptimalWidth) )
174 {
175 mbOptimalWidth = bOptimalWidth;
176 if( bOptimalWidth )
177 mnWidth = 0;
178 bChange = true;
179 }
180 break;
181 }
183 {
184 bool bIsVisible = mbIsVisible;
185 bOk = aValue >>= bIsVisible;
186 if( bOk && (mbIsVisible != bIsVisible) )
187 {
188 mbIsVisible = bIsVisible;
189 bChange = true;
190 }
191 break;
192 }
193
195 {
196 bool bIsStartOfNewPage = mbIsStartOfNewPage;
197 bOk = aValue >>= bIsStartOfNewPage;
198 if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
199 {
200 mbIsStartOfNewPage = bIsStartOfNewPage;
201 bChange = true;
202 }
203 break;
204 }
205 default:
206 throw UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
207 }
208 if( !bOk )
209 {
210 throw IllegalArgumentException();
211 }
212
213 if( bChange )
214 {
215 if( pUndo )
216 {
217 rModel.AddUndo( std::move(pUndo) );
218 }
219 mxTableModel->setModified(true);
220 }
221}
222
223
224Any SAL_CALL TableColumn::getFastPropertyValue( sal_Int32 nHandle )
225{
226 switch( nHandle )
227 {
228 case Property_Width: return Any( mnWidth );
230 case Property_IsVisible: return Any( mbIsVisible );
232 default: throw UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
233 }
234}
235
236
238{
239 static rtl::Reference<FastPropertySetInfo> xInfo = []() {
241
242 aProperties[0].Name = "Width";
243 aProperties[0].Handle = Property_Width;
245 aProperties[0].Attributes = 0;
246
247 aProperties[1].Name = "OptimalWidth";
250 aProperties[1].Attributes = 0;
251
252 aProperties[2].Name = "IsVisible";
255 aProperties[2].Attributes = 0;
256
257 aProperties[3].Name = "IsStartOfNewPage";
260 aProperties[3].Attributes = 0;
261
262 aProperties[4].Name = "Size";
263 aProperties[4].Handle = Property_Width;
265 aProperties[4].Attributes = 0;
266
267 aProperties[5].Name = "OptimalSize";
270 aProperties[5].Attributes = 0;
271
273 }();
274
275 return xInfo;
276}
277
279{
280 return mxTableModel;
281}
282
283sal_Int32 TableColumn::getWidth() const
284{
285 return mnWidth;
286}
287
288}
289
290/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
Definition: svdmodel.cxx:494
bool IsUndoEnabled() const
returns true if undo is currently enabled This returns false if undo was disabled using EnableUndo( f...
Definition: svdmodel.cxx:525
css::uno::Type const & get()
virtual css::uno::Reference< css::table::XCell > SAL_CALL getCellByPosition(sal_Int32 nColumn, sal_Int32 nRow) override
Definition: tablecolumn.cxx:96
virtual ~TableColumn() override
Definition: tablecolumn.cxx:62
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByPosition(sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom) override
static rtl::Reference< FastPropertySetInfo > getStaticPropertySetInfo()
virtual void SAL_CALL setName(const OUString &aName) override
TableColumn & operator=(const TableColumn &)
Definition: tablecolumn.cxx:80
TableColumn(TableModelRef xTableModel, sal_Int32 nColumn)
Definition: tablecolumn.cxx:50
TableModelRef const & getModel() const
Get the table that owns this column.
friend class TableColumnUndo
Definition: tablecolumn.hxx:37
virtual css::uno::Any SAL_CALL getFastPropertyValue(::sal_Int32 nHandle) override
void throwIfDisposed() const
Definition: tablecolumn.cxx:73
virtual OUString SAL_CALL getName() override
sal_Int32 getWidth() const
Get the width of this column.
virtual void SAL_CALL setFastPropertyValue(::sal_Int32 nHandle, const css::uno::Any &aValue) override
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByName(const OUString &aRange) override
TableModelRef mxTableModel
Definition: tablecolumn.hxx:70
OUString aName
std::vector< css::beans::Property > PropertyVector
Definition: propertyset.hxx:35
::cppu::ImplInheritanceHelper< FastPropertySet, css::table::XCellRange, css::container::XNamed > TableColumnBase
Definition: tablecolumn.hxx:33
const sal_Int32 Property_IsStartOfNewPage
Definition: tablecolumn.cxx:44
const sal_Int32 Property_Width
Definition: tablecolumn.cxx:41
const sal_Int32 Property_IsVisible
Definition: tablecolumn.cxx:43
const sal_Int32 Property_OptimalWidth
Definition: tablecolumn.cxx:42
sal_Int32 nHandle
double mnWidth