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