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"
28#include <svx/svdmodel.hxx>
29#include <svx/svdotable.hxx>
30#include <utility>
31
32
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::lang;
35using namespace ::com::sun::star::container;
36using namespace ::com::sun::star::table;
37using namespace ::com::sun::star::beans;
38
39
40namespace sdr::table {
41
42const sal_Int32 Property_Width = 0;
43const sal_Int32 Property_OptimalWidth = 1;
44const sal_Int32 Property_IsVisible = 2;
45const sal_Int32 Property_IsStartOfNewPage = 3;
46
47
48// TableRow
49
50
51TableColumn::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 )
59{
60}
61
62
64{
65}
66
67
69{
70 mxTableModel.clear();
71}
72
73
75{
76 if( !mxTableModel.is() )
77 throw DisposedException();
78}
79
80
82{
83 mnWidth = r.mnWidth;
87 maName = r.maName;
89
90 return *this;
91}
92
93
94// XCellRange
95
96
97Reference< XCell > SAL_CALL TableColumn::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow )
98{
100 if( nColumn != 0 )
101 throw IndexOutOfBoundsException();
102
103 return mxTableModel->getCellByPosition( mnColumn, nRow );
104}
105
106
107Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
108{
110 if( (nTop >= 0 ) && (nLeft == 0) && (nBottom >= nTop) && (nRight == 0) )
111 {
112 return mxTableModel->getCellRangeByPosition( mnColumn, nTop, mnColumn, nBottom );
113 }
114 throw IndexOutOfBoundsException();
115}
116
117
118Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByName( const OUString& /*aRange*/ )
119{
120 return Reference< XCellRange >();
121}
122
123
124// XNamed
125
126
127OUString SAL_CALL TableColumn::getName()
128{
129 return maName;
130}
131
132
133void SAL_CALL TableColumn::setName( const OUString& aName )
134{
135 maName = aName;
136}
137
138
139// XFastPropertySet
140
141
142void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue )
143{
144 bool bOk = false;
145 bool bChange = false;
146
147 SdrModel& rModel(mxTableModel->getSdrTableObj()->getSdrModelFromSdrObject());
148 std::unique_ptr<TableColumnUndo> pUndo;
149
150 if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && rModel.IsUndoEnabled() )
151 {
152 TableColumnRef xThis( this );
153 pUndo.reset( new TableColumnUndo( xThis ) );
154 }
155
156 switch( nHandle )
157 {
158 case Property_Width:
159 {
160 sal_Int32 nWidth = mnWidth;
161 bOk = aValue >>= nWidth;
162 if( bOk && (nWidth != mnWidth) )
163 {
164 mnWidth = nWidth;
165 mbOptimalWidth = mnWidth == 0;
166 bChange = true;
167 }
168 break;
169 }
171 {
172 bool bOptimalWidth = mbOptimalWidth;
173 bOk = aValue >>= bOptimalWidth;
174 if( bOk && (mbOptimalWidth != bOptimalWidth) )
175 {
176 mbOptimalWidth = bOptimalWidth;
177 if( bOptimalWidth )
178 mnWidth = 0;
179 bChange = true;
180 }
181 break;
182 }
184 {
185 bool bIsVisible = mbIsVisible;
186 bOk = aValue >>= bIsVisible;
187 if( bOk && (mbIsVisible != bIsVisible) )
188 {
189 mbIsVisible = bIsVisible;
190 bChange = true;
191 }
192 break;
193 }
194
196 {
197 bool bIsStartOfNewPage = mbIsStartOfNewPage;
198 bOk = aValue >>= bIsStartOfNewPage;
199 if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
200 {
201 mbIsStartOfNewPage = bIsStartOfNewPage;
202 bChange = true;
203 }
204 break;
205 }
206 default:
207 throw UnknownPropertyException( OUString::number(nHandle), getXWeak());
208 }
209 if( !bOk )
210 {
211 throw IllegalArgumentException();
212 }
213
214 if( bChange )
215 {
216 if( pUndo )
217 {
218 rModel.AddUndo( std::move(pUndo) );
219 }
220 mxTableModel->setModified(true);
221 }
222}
223
224
225Any SAL_CALL TableColumn::getFastPropertyValue( sal_Int32 nHandle )
226{
227 switch( nHandle )
228 {
229 case Property_Width: return Any( mnWidth );
231 case Property_IsVisible: return Any( mbIsVisible );
233 default: throw UnknownPropertyException( OUString::number(nHandle), getXWeak());
234 }
235}
236
237
239{
240 static rtl::Reference<FastPropertySetInfo> xInfo = []() {
242
243 aProperties[0].Name = "Width";
244 aProperties[0].Handle = Property_Width;
246 aProperties[0].Attributes = 0;
247
248 aProperties[1].Name = "OptimalWidth";
251 aProperties[1].Attributes = 0;
252
253 aProperties[2].Name = "IsVisible";
256 aProperties[2].Attributes = 0;
257
258 aProperties[3].Name = "IsStartOfNewPage";
261 aProperties[3].Attributes = 0;
262
263 aProperties[4].Name = "Size";
264 aProperties[4].Handle = Property_Width;
266 aProperties[4].Attributes = 0;
267
268 aProperties[5].Name = "OptimalSize";
271 aProperties[5].Attributes = 0;
272
274 }();
275
276 return xInfo;
277}
278
280{
281 return mxTableModel;
282}
283
284sal_Int32 TableColumn::getWidth() const
285{
286 return mnWidth;
287}
288
289}
290
291/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
Definition: svdmodel.cxx:516
bool IsUndoEnabled() const
returns true if undo is currently enabled This returns false if undo was disabled using EnableUndo( f...
Definition: svdmodel.cxx:547
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:97
virtual ~TableColumn() override
Definition: tablecolumn.cxx:63
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:81
TableColumn(TableModelRef xTableModel, sal_Int32 nColumn)
Definition: tablecolumn.cxx:51
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:74
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
const sal_Int32 Property_IsStartOfNewPage
Definition: tablecolumn.cxx:45
const sal_Int32 Property_Width
Definition: tablecolumn.cxx:42
const sal_Int32 Property_IsVisible
Definition: tablecolumn.cxx:44
const sal_Int32 Property_OptimalWidth
Definition: tablecolumn.cxx:43
sal_Int32 nHandle
double mnWidth