/src/libreoffice/sc/source/ui/unoobj/condformatuno.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 | | |
10 | | #include <sal/config.h> |
11 | | |
12 | | #include <algorithm> |
13 | | #include <memory> |
14 | | #include <condformatuno.hxx> |
15 | | |
16 | | #include <document.hxx> |
17 | | #include <conditio.hxx> |
18 | | #include <colorscale.hxx> |
19 | | #include <docsh.hxx> |
20 | | #include <compiler.hxx> |
21 | | #include <tokenarray.hxx> |
22 | | |
23 | | #include <cellsuno.hxx> |
24 | | #include <convuno.hxx> |
25 | | |
26 | | #include <o3tl/safeint.hxx> |
27 | | #include <utility> |
28 | | #include <vcl/svapp.hxx> |
29 | | #include <rtl/ustring.hxx> |
30 | | #include <sal/log.hxx> |
31 | | |
32 | | #include <com/sun/star/sheet/DataBarAxis.hpp> |
33 | | #include <com/sun/star/sheet/IconSetType.hpp> |
34 | | #include <com/sun/star/sheet/ConditionFormatOperator.hpp> |
35 | | #include <com/sun/star/sheet/DataBarEntryType.hpp> |
36 | | #include <com/sun/star/sheet/ColorScaleEntryType.hpp> |
37 | | #include <com/sun/star/sheet/IconSetFormatEntry.hpp> |
38 | | #include <com/sun/star/sheet/ConditionEntryType.hpp> |
39 | | #include <com/sun/star/sheet/DateType.hpp> |
40 | | |
41 | | namespace { |
42 | | |
43 | | enum CondFormatProperties |
44 | | { |
45 | | ID, |
46 | | CondFormat_Range |
47 | | }; |
48 | | |
49 | | std::span<const SfxItemPropertyMapEntry> getCondFormatPropset() |
50 | 0 | { |
51 | 0 | static const SfxItemPropertyMapEntry aCondFormatPropertyMap_Impl[] = |
52 | 0 | { |
53 | 0 | {u"ID"_ustr, ID, cppu::UnoType<sal_Int32>::get(), 0, 0}, |
54 | 0 | {u"Range"_ustr, CondFormat_Range, cppu::UnoType<sheet::XSheetCellRanges>::get(), 0, 0}, |
55 | 0 | }; |
56 | 0 | return aCondFormatPropertyMap_Impl; |
57 | 0 | } |
58 | | |
59 | | enum ConditionEntryProperties |
60 | | { |
61 | | StyleName, |
62 | | Formula1, |
63 | | Formula2, |
64 | | Operator |
65 | | }; |
66 | | |
67 | | std::span<const SfxItemPropertyMapEntry> getConditionEntryrPropSet() |
68 | 0 | { |
69 | 0 | static const SfxItemPropertyMapEntry aConditionEntryPropertyMap_Impl[] = |
70 | 0 | { |
71 | 0 | {u"StyleName"_ustr, StyleName, cppu::UnoType<OUString>::get(), 0, 0}, |
72 | 0 | {u"Formula1"_ustr, Formula1, cppu::UnoType<OUString>::get(), 0, 0}, |
73 | 0 | {u"Formula2"_ustr, Formula2, cppu::UnoType<OUString>::get(), 0, 0}, |
74 | 0 | {u"Operator"_ustr, Operator, cppu::UnoType<decltype(sheet::ConditionFormatOperator::EQUAL)>::get(), 0, 0 }, |
75 | 0 | }; |
76 | 0 | return aConditionEntryPropertyMap_Impl; |
77 | 0 | } |
78 | | |
79 | | struct ConditionEntryApiMap |
80 | | { |
81 | | ScConditionMode eMode; |
82 | | sal_Int32 nApiMode; |
83 | | }; |
84 | | |
85 | | ConditionEntryApiMap const aConditionEntryMap[] = |
86 | | { |
87 | | {ScConditionMode::Equal, sheet::ConditionFormatOperator::EQUAL}, |
88 | | {ScConditionMode::Less, sheet::ConditionFormatOperator::LESS}, |
89 | | {ScConditionMode::Greater, sheet::ConditionFormatOperator::GREATER}, |
90 | | {ScConditionMode::EqLess, sheet::ConditionFormatOperator::LESS_EQUAL}, |
91 | | {ScConditionMode::EqGreater, sheet::ConditionFormatOperator::GREATER_EQUAL}, |
92 | | {ScConditionMode::NotEqual, sheet::ConditionFormatOperator::NOT_EQUAL}, |
93 | | {ScConditionMode::Between, sheet::ConditionFormatOperator::BETWEEN}, |
94 | | {ScConditionMode::NotBetween, sheet::ConditionFormatOperator::NOT_BETWEEN}, |
95 | | {ScConditionMode::Duplicate, sheet::ConditionFormatOperator::DUPLICATE}, |
96 | | {ScConditionMode::NotDuplicate, sheet::ConditionFormatOperator::UNIQUE}, |
97 | | {ScConditionMode::Direct, sheet::ConditionFormatOperator::EXPRESSION}, |
98 | | {ScConditionMode::Top10, sheet::ConditionFormatOperator::TOP_N_ELEMENTS}, |
99 | | {ScConditionMode::Bottom10, sheet::ConditionFormatOperator::BOTTOM_N_ELEMENTS}, |
100 | | {ScConditionMode::TopPercent, sheet::ConditionFormatOperator::TOP_N_PERCENT}, |
101 | | {ScConditionMode::BottomPercent, sheet::ConditionFormatOperator::BOTTOM_N_PERCENT}, |
102 | | {ScConditionMode::AboveAverage, sheet::ConditionFormatOperator::ABOVE_AVERAGE}, |
103 | | {ScConditionMode::BelowAverage, sheet::ConditionFormatOperator::BELOW_AVERAGE}, |
104 | | {ScConditionMode::AboveEqualAverage, sheet::ConditionFormatOperator::ABOVE_EQUAL_AVERAGE}, |
105 | | {ScConditionMode::BelowEqualAverage, sheet::ConditionFormatOperator::BELOW_EQUAL_AVERAGE}, |
106 | | {ScConditionMode::Error, sheet::ConditionFormatOperator::ERROR}, |
107 | | {ScConditionMode::NoError, sheet::ConditionFormatOperator::NO_ERROR}, |
108 | | {ScConditionMode::BeginsWith, sheet::ConditionFormatOperator::BEGINS_WITH}, |
109 | | {ScConditionMode::EndsWith, sheet::ConditionFormatOperator::ENDS_WITH}, |
110 | | {ScConditionMode::ContainsText, sheet::ConditionFormatOperator::CONTAINS}, |
111 | | {ScConditionMode::NotContainsText, sheet::ConditionFormatOperator::NOT_CONTAINS}, |
112 | | {ScConditionMode::NONE, sheet::ConditionFormatOperator::EQUAL}, |
113 | | }; |
114 | | |
115 | | enum ColorScaleProperties |
116 | | { |
117 | | ColorScaleEntries |
118 | | }; |
119 | | |
120 | | std::span<const SfxItemPropertyMapEntry> getColorScalePropSet() |
121 | 0 | { |
122 | 0 | static const SfxItemPropertyMapEntry aColorScalePropertyMap_Impl[] = |
123 | 0 | { |
124 | 0 | {u"ColorScaleEntries"_ustr, ColorScaleEntries, cppu::UnoType<uno::Sequence< sheet::XColorScaleEntry >>::get(), 0, 0 }, |
125 | 0 | }; |
126 | 0 | return aColorScalePropertyMap_Impl; |
127 | 0 | } |
128 | | |
129 | | struct ColorScaleEntryTypeApiMap |
130 | | { |
131 | | ScColorScaleEntryType eType; |
132 | | sal_Int32 nApiType; |
133 | | }; |
134 | | |
135 | | ColorScaleEntryTypeApiMap const aColorScaleEntryTypeMap[] = |
136 | | { |
137 | | { COLORSCALE_MIN, sheet::ColorScaleEntryType::COLORSCALE_MIN }, |
138 | | { COLORSCALE_MAX, sheet::ColorScaleEntryType::COLORSCALE_MAX }, |
139 | | { COLORSCALE_VALUE, sheet::ColorScaleEntryType::COLORSCALE_VALUE }, |
140 | | { COLORSCALE_FORMULA, sheet::ColorScaleEntryType::COLORSCALE_FORMULA }, |
141 | | { COLORSCALE_PERCENT, sheet::ColorScaleEntryType::COLORSCALE_PERCENT }, |
142 | | { COLORSCALE_PERCENTILE, sheet::ColorScaleEntryType::COLORSCALE_PERCENTILE } |
143 | | }; |
144 | | |
145 | | enum DataBarProperties |
146 | | { |
147 | | AxisPosition, |
148 | | UseGradient, |
149 | | UseNegativeColor, |
150 | | DataBar_ShowValue, |
151 | | DataBar_Color, |
152 | | AxisColor, |
153 | | NegativeColor, |
154 | | DataBarEntries, |
155 | | MinimumLength, |
156 | | MaximumLength |
157 | | }; |
158 | | |
159 | | std::span<const SfxItemPropertyMapEntry> getDataBarPropSet() |
160 | 0 | { |
161 | 0 | static const SfxItemPropertyMapEntry aDataBarPropertyMap_Impl[] = |
162 | 0 | { |
163 | 0 | {u"AxisPosition"_ustr, AxisPosition, cppu::UnoType<decltype(sheet::DataBarAxis::AXIS_AUTOMATIC)>::get(), 0, 0 }, |
164 | 0 | {u"UseGradient"_ustr, UseGradient, cppu::UnoType<bool>::get(), 0, 0 }, |
165 | 0 | {u"UseNegativeColor"_ustr, UseNegativeColor, cppu::UnoType<bool>::get(), 0, 0 }, |
166 | 0 | {u"ShowValue"_ustr, DataBar_ShowValue, cppu::UnoType<bool>::get(), 0, 0 }, |
167 | 0 | {u"Color"_ustr, DataBar_Color, cppu::UnoType<sal_Int32>::get(), 0, 0}, |
168 | 0 | {u"AxisColor"_ustr, AxisColor, cppu::UnoType<sal_Int32>::get(), 0, 0}, |
169 | 0 | {u"NegativeColor"_ustr, NegativeColor, cppu::UnoType<sal_Int32>::get(), 0, 0}, |
170 | 0 | {u"DataBarEntries"_ustr, DataBarEntries, cppu::UnoType<uno::Sequence< sheet::XDataBarEntry >>::get(), 0, 0 }, |
171 | 0 | {u"MinimumLength"_ustr, MinimumLength, cppu::UnoType<double>::get(), 0, 0 }, |
172 | 0 | {u"MaximumLength"_ustr, MaximumLength, cppu::UnoType<double>::get(), 0, 0 }, |
173 | 0 | }; |
174 | 0 | return aDataBarPropertyMap_Impl; |
175 | 0 | } |
176 | | |
177 | | struct DataBarAxisApiMap |
178 | | { |
179 | | databar::ScAxisPosition ePos; |
180 | | sal_Int32 nApiPos; |
181 | | }; |
182 | | |
183 | | DataBarAxisApiMap const aDataBarAxisMap[] = |
184 | | { |
185 | | { databar::NONE, sheet::DataBarAxis::AXIS_NONE }, |
186 | | { databar::AUTOMATIC, sheet::DataBarAxis::AXIS_AUTOMATIC }, |
187 | | { databar::MIDDLE, sheet::DataBarAxis::AXIS_MIDDLE } |
188 | | }; |
189 | | |
190 | | struct DataBarEntryTypeApiMap |
191 | | { |
192 | | ScColorScaleEntryType eType; |
193 | | sal_Int32 nApiType; |
194 | | }; |
195 | | |
196 | | DataBarEntryTypeApiMap const aDataBarEntryTypeMap[] = |
197 | | { |
198 | | { COLORSCALE_AUTO, sheet::DataBarEntryType::DATABAR_AUTO }, |
199 | | { COLORSCALE_MIN, sheet::DataBarEntryType::DATABAR_MIN }, |
200 | | { COLORSCALE_MAX, sheet::DataBarEntryType::DATABAR_MAX }, |
201 | | { COLORSCALE_VALUE, sheet::DataBarEntryType::DATABAR_VALUE }, |
202 | | { COLORSCALE_FORMULA, sheet::DataBarEntryType::DATABAR_FORMULA }, |
203 | | { COLORSCALE_PERCENT, sheet::DataBarEntryType::DATABAR_PERCENT }, |
204 | | { COLORSCALE_PERCENTILE, sheet::DataBarEntryType::DATABAR_PERCENTILE } |
205 | | }; |
206 | | |
207 | | enum IconSetProperties |
208 | | { |
209 | | Icons, |
210 | | Reverse, |
211 | | ShowValue, |
212 | | IconSetEntries |
213 | | }; |
214 | | |
215 | | std::span<const SfxItemPropertyMapEntry> getIconSetPropSet() |
216 | 0 | { |
217 | 0 | static const SfxItemPropertyMapEntry aIconSetPropertyMap_Impl[] = |
218 | 0 | { |
219 | 0 | {u"Icons"_ustr, Icons, cppu::UnoType<decltype(sheet::IconSetType::ICONSET_3SYMBOLS)>::get(), 0, 0 }, |
220 | 0 | {u"Reverse"_ustr, Reverse, cppu::UnoType<bool>::get(), 0, 0 }, |
221 | 0 | {u"ShowValue"_ustr, ShowValue, cppu::UnoType<bool>::get(), 0, 0 }, |
222 | 0 | {u"IconSetEntries"_ustr, IconSetEntries, cppu::UnoType<uno::Sequence< sheet::XIconSetEntry >>::get(), 0, 0 }, |
223 | 0 | }; |
224 | 0 | return aIconSetPropertyMap_Impl; |
225 | 0 | } |
226 | | |
227 | | struct IconSetTypeApiMap |
228 | | { |
229 | | ScIconSetType eType; |
230 | | sal_Int32 nApiType; |
231 | | }; |
232 | | |
233 | | const IconSetTypeApiMap aIconSetApiMap[] = |
234 | | { |
235 | | { IconSet_3Arrows, sheet::IconSetType::ICONSET_3ARROWS }, |
236 | | { IconSet_3ArrowsGray, sheet::IconSetType::ICONSET_3ARROWS_GRAY }, |
237 | | { IconSet_3Flags, sheet::IconSetType::ICONSET_3FLAGS }, |
238 | | { IconSet_3TrafficLights1, sheet::IconSetType::ICONSET_3TRAFFICLIGHTS1 }, |
239 | | { IconSet_3TrafficLights2, sheet::IconSetType::ICONSET_3TRAFFICLIGHTS2 }, |
240 | | { IconSet_3Signs, sheet::IconSetType::ICONSET_3SIGNS }, |
241 | | { IconSet_3Symbols, sheet::IconSetType::ICONSET_3SYMBOLS }, |
242 | | { IconSet_3Symbols2, sheet::IconSetType::ICONSET_3SYMBOLS2 }, |
243 | | { IconSet_3Smilies, sheet::IconSetType::ICONSET_3SMILIES }, |
244 | | { IconSet_3ColorSmilies, sheet::IconSetType::ICONSET_3COLOR_SIMILIES }, |
245 | | { IconSet_4Arrows, sheet::IconSetType::ICONSET_4ARROWS }, |
246 | | { IconSet_4ArrowsGray, sheet::IconSetType::ICONSET_4ARROWS_GRAY }, |
247 | | { IconSet_4Rating, sheet::IconSetType::ICONSET_4RATING }, |
248 | | { IconSet_4RedToBlack, sheet::IconSetType::ICONSET_4RED_TO_BLACK }, |
249 | | { IconSet_4TrafficLights, sheet::IconSetType::ICONSET_4TRAFFICLIGHTS }, |
250 | | { IconSet_5Arrows, sheet::IconSetType::ICONSET_5ARROWS }, |
251 | | { IconSet_5ArrowsGray, sheet::IconSetType::ICONSET_4ARROWS_GRAY }, |
252 | | { IconSet_5Ratings, sheet::IconSetType::ICONSET_5RATINGS }, |
253 | | { IconSet_5Quarters, sheet::IconSetType::ICONSET_5QUARTERS }, |
254 | | }; |
255 | | |
256 | | struct IconSetEntryTypeApiMap |
257 | | { |
258 | | ScColorScaleEntryType eType; |
259 | | sal_Int32 nApiType; |
260 | | }; |
261 | | |
262 | | IconSetEntryTypeApiMap const aIconSetEntryTypeMap[] = |
263 | | { |
264 | | { COLORSCALE_MIN, sheet::IconSetFormatEntry::ICONSET_MIN }, |
265 | | { COLORSCALE_VALUE, sheet::IconSetFormatEntry::ICONSET_VALUE }, |
266 | | { COLORSCALE_FORMULA, sheet::IconSetFormatEntry::ICONSET_FORMULA }, |
267 | | { COLORSCALE_PERCENT, sheet::IconSetFormatEntry::ICONSET_PERCENT }, |
268 | | { COLORSCALE_PERCENTILE, sheet::IconSetFormatEntry::ICONSET_PERCENTILE } |
269 | | }; |
270 | | |
271 | | enum DateProperties |
272 | | { |
273 | | Date_StyleName, |
274 | | DateType |
275 | | }; |
276 | | |
277 | | std::span<const SfxItemPropertyMapEntry> getCondDatePropSet() |
278 | 0 | { |
279 | 0 | static const SfxItemPropertyMapEntry aCondDatePropertyMap_Impl[] = |
280 | 0 | { |
281 | 0 | {u"StyleName"_ustr, StyleName, cppu::UnoType<OUString>::get(), 0, 0}, |
282 | 0 | {u"DateType"_ustr, Icons, cppu::UnoType<decltype(sheet::DateType::TODAY)>::get(), 0, 0 }, |
283 | 0 | }; |
284 | 0 | return aCondDatePropertyMap_Impl; |
285 | 0 | } |
286 | | |
287 | | struct DateTypeApiMap |
288 | | { |
289 | | condformat::ScCondFormatDateType eType; |
290 | | sal_Int32 nApiType; |
291 | | }; |
292 | | |
293 | | DateTypeApiMap const aDateTypeApiMap[] = |
294 | | { |
295 | | { condformat::TODAY, sheet::DateType::TODAY }, |
296 | | { condformat::YESTERDAY, sheet::DateType::YESTERDAY }, |
297 | | { condformat::TOMORROW, sheet::DateType::TOMORROW }, |
298 | | { condformat::LAST7DAYS, sheet::DateType::LAST7DAYS }, |
299 | | { condformat::THISWEEK, sheet::DateType::THISWEEK }, |
300 | | { condformat::LASTWEEK, sheet::DateType::LASTWEEK }, |
301 | | { condformat::NEXTWEEK, sheet::DateType::NEXTWEEK }, |
302 | | { condformat::THISMONTH, sheet::DateType::THISMONTH }, |
303 | | { condformat::LASTMONTH, sheet::DateType::LASTMONTH }, |
304 | | { condformat::NEXTMONTH, sheet::DateType::NEXTMONTH }, |
305 | | { condformat::THISYEAR, sheet::DateType::THISYEAR }, |
306 | | { condformat::LASTYEAR, sheet::DateType::LASTYEAR }, |
307 | | { condformat::NEXTYEAR, sheet::DateType::NEXTYEAR } |
308 | | }; |
309 | | |
310 | | } |
311 | | |
312 | | ScCondFormatsObj::ScCondFormatsObj(ScDocShell* pDocShell, SCTAB nTab): |
313 | 0 | mnTab(nTab), |
314 | 0 | mpDocShell(pDocShell) |
315 | 0 | { |
316 | 0 | pDocShell->GetDocument().AddUnoObject(*this); |
317 | 0 | } |
318 | | |
319 | | ScCondFormatsObj::~ScCondFormatsObj() |
320 | 0 | { |
321 | 0 | if (mpDocShell) |
322 | 0 | mpDocShell->GetDocument().RemoveUnoObject(*this); |
323 | 0 | } |
324 | | |
325 | | void ScCondFormatsObj::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint) |
326 | 0 | { |
327 | 0 | if ( rHint.GetId() == SfxHintId::Dying ) |
328 | 0 | { |
329 | 0 | mpDocShell = nullptr; |
330 | 0 | } |
331 | 0 | } |
332 | | |
333 | | sal_Int32 ScCondFormatsObj::createByRange(const uno::Reference< sheet::XSheetCellRanges >& xRanges) |
334 | 0 | { |
335 | 0 | SolarMutexGuard aGuard; |
336 | 0 | if (!mpDocShell) |
337 | 0 | throw lang::IllegalArgumentException(); |
338 | | |
339 | 0 | if (!xRanges.is()) |
340 | 0 | throw lang::IllegalArgumentException(); |
341 | | |
342 | 0 | const uno::Sequence<table::CellRangeAddress> aRanges = |
343 | 0 | xRanges->getRangeAddresses(); |
344 | |
|
345 | 0 | ScRangeList aCoreRange; |
346 | 0 | for (const auto& rRange : aRanges) |
347 | 0 | { |
348 | 0 | ScRange aRange; |
349 | 0 | ScUnoConversion::FillScRange(aRange, rRange); |
350 | 0 | aCoreRange.Join(aRange); |
351 | 0 | } |
352 | |
|
353 | 0 | if (aCoreRange.empty()) |
354 | 0 | throw lang::IllegalArgumentException(); |
355 | | |
356 | 0 | SCTAB nTab = aCoreRange[0].aStart.Tab(); |
357 | |
|
358 | 0 | auto pNewFormat = std::make_unique<ScConditionalFormat>(0, mpDocShell->GetDocument()); |
359 | 0 | pNewFormat->SetRange(aCoreRange); |
360 | 0 | return mpDocShell->GetDocument().AddCondFormat(std::move(pNewFormat), nTab); |
361 | 0 | } |
362 | | |
363 | | void ScCondFormatsObj::removeByID(const sal_Int32 nID) |
364 | 0 | { |
365 | 0 | SolarMutexGuard aGuard; |
366 | 0 | ScConditionalFormatList* pFormatList = getCoreObject(); |
367 | 0 | pFormatList->erase(nID); |
368 | 0 | } |
369 | | |
370 | | uno::Sequence<uno::Reference<sheet::XConditionalFormat> > ScCondFormatsObj::getConditionalFormats() |
371 | 0 | { |
372 | 0 | SolarMutexGuard aGuard; |
373 | 0 | ScConditionalFormatList* pFormatList = getCoreObject(); |
374 | 0 | size_t n = pFormatList->size(); |
375 | 0 | uno::Sequence<uno::Reference<sheet::XConditionalFormat> > aCondFormats(n); |
376 | 0 | std::transform(pFormatList->begin(), pFormatList->end(), aCondFormats.getArray(), |
377 | 0 | [this](const auto& rFormat) |
378 | 0 | { return uno::Reference(new ScCondFormatObj(mpDocShell, this, rFormat->GetKey())); }); |
379 | |
|
380 | 0 | return aCondFormats; |
381 | 0 | } |
382 | | |
383 | | sal_Int32 ScCondFormatsObj::getLength() |
384 | 0 | { |
385 | 0 | SolarMutexGuard aGuard; |
386 | 0 | ScConditionalFormatList* pFormatList = getCoreObject(); |
387 | 0 | return pFormatList->size(); |
388 | 0 | } |
389 | | |
390 | | ScConditionalFormatList* ScCondFormatsObj::getCoreObject() |
391 | 0 | { |
392 | 0 | if (!mpDocShell) |
393 | 0 | throw uno::RuntimeException(); |
394 | | |
395 | 0 | ScConditionalFormatList* pList = mpDocShell->GetDocument().GetCondFormList(mnTab); |
396 | 0 | if (!pList) |
397 | 0 | throw uno::RuntimeException(); |
398 | | |
399 | 0 | return pList; |
400 | 0 | } |
401 | | |
402 | | namespace { |
403 | | |
404 | | uno::Reference<beans::XPropertySet> createConditionEntry(const ScFormatEntry* pEntry, |
405 | | rtl::Reference<ScCondFormatObj> const & xParent) |
406 | 0 | { |
407 | 0 | switch (pEntry->GetType()) |
408 | 0 | { |
409 | 0 | case ScFormatEntry::Type::Condition: |
410 | 0 | case ScFormatEntry::Type::ExtCondition: |
411 | 0 | return new ScConditionEntryObj(xParent, |
412 | 0 | static_cast<const ScCondFormatEntry*>(pEntry)); |
413 | 0 | break; |
414 | 0 | case ScFormatEntry::Type::Colorscale: |
415 | 0 | return new ScColorScaleFormatObj(xParent, |
416 | 0 | static_cast<const ScColorScaleFormat*>(pEntry)); |
417 | 0 | break; |
418 | 0 | case ScFormatEntry::Type::Databar: |
419 | 0 | return new ScDataBarFormatObj(xParent, |
420 | 0 | static_cast<const ScDataBarFormat*>(pEntry)); |
421 | 0 | break; |
422 | 0 | case ScFormatEntry::Type::Iconset: |
423 | 0 | return new ScIconSetFormatObj(xParent, |
424 | 0 | static_cast<const ScIconSetFormat*>(pEntry)); |
425 | 0 | break; |
426 | 0 | case ScFormatEntry::Type::Date: |
427 | 0 | return new ScCondDateFormatObj(xParent, |
428 | 0 | static_cast<const ScCondDateFormatEntry*>(pEntry)); |
429 | 0 | break; |
430 | 0 | default: |
431 | 0 | break; |
432 | 0 | } |
433 | 0 | return uno::Reference<beans::XPropertySet>(); |
434 | 0 | } |
435 | | |
436 | | } |
437 | | |
438 | | ScCondFormatObj::ScCondFormatObj(ScDocShell* pDocShell, rtl::Reference<ScCondFormatsObj> xCondFormats, |
439 | | sal_Int32 nKey): |
440 | 0 | mxCondFormatList(std::move(xCondFormats)), |
441 | 0 | mpDocShell(pDocShell), |
442 | 0 | maPropSet(getCondFormatPropset()), |
443 | 0 | mnKey(nKey) |
444 | 0 | { |
445 | 0 | } |
446 | | |
447 | | ScCondFormatObj::~ScCondFormatObj() |
448 | 0 | { |
449 | 0 | } |
450 | | |
451 | | ScConditionalFormat* ScCondFormatObj::getCoreObject() |
452 | 0 | { |
453 | 0 | ScConditionalFormatList* pList = mxCondFormatList->getCoreObject(); |
454 | 0 | ScConditionalFormat* pFormat = pList->GetFormat(mnKey); |
455 | 0 | if (!pFormat) |
456 | 0 | throw uno::RuntimeException(); |
457 | | |
458 | 0 | return pFormat; |
459 | 0 | } |
460 | | |
461 | | ScDocShell* ScCondFormatObj::getDocShell() |
462 | 0 | { |
463 | 0 | return mpDocShell; |
464 | 0 | } |
465 | | |
466 | | void ScCondFormatObj::createEntry(const sal_Int32 nType, const sal_Int32 nPos) |
467 | 0 | { |
468 | 0 | SolarMutexGuard aGuard; |
469 | 0 | ScConditionalFormat* pFormat = getCoreObject(); |
470 | 0 | if (nPos > sal_Int32(pFormat->size())) |
471 | 0 | throw lang::IllegalArgumentException(); |
472 | | |
473 | 0 | ScFormatEntry* pNewEntry = nullptr; |
474 | 0 | ScDocument& rDoc = mpDocShell->GetDocument(); |
475 | 0 | switch (nType) |
476 | 0 | { |
477 | 0 | case sheet::ConditionEntryType::CONDITION: |
478 | 0 | pNewEntry = new ScCondFormatEntry(ScConditionMode::Equal, u""_ustr, u""_ustr, |
479 | 0 | rDoc, pFormat->GetRange().GetTopLeftCorner(), u""_ustr); |
480 | 0 | break; |
481 | 0 | case sheet::ConditionEntryType::COLORSCALE: |
482 | 0 | pNewEntry = new ScColorScaleFormat(rDoc); |
483 | 0 | static_cast<ScColorScaleFormat*>(pNewEntry)->EnsureSize(); |
484 | 0 | break; |
485 | 0 | case sheet::ConditionEntryType::DATABAR: |
486 | 0 | pNewEntry = new ScDataBarFormat(rDoc); |
487 | 0 | static_cast<ScDataBarFormat*>(pNewEntry)->EnsureSize(); |
488 | 0 | break; |
489 | 0 | case sheet::ConditionEntryType::ICONSET: |
490 | 0 | pNewEntry = new ScIconSetFormat(rDoc); |
491 | 0 | static_cast<ScIconSetFormat*>(pNewEntry)->EnsureSize(); |
492 | 0 | break; |
493 | 0 | case sheet::ConditionEntryType::DATE: |
494 | 0 | pNewEntry = new ScCondDateFormatEntry(rDoc); |
495 | 0 | break; |
496 | 0 | default: |
497 | 0 | SAL_WARN("sc", "unknown conditional format type"); |
498 | 0 | throw lang::IllegalArgumentException(); |
499 | 0 | } |
500 | | |
501 | 0 | pFormat->AddEntry(pNewEntry); |
502 | 0 | } |
503 | | |
504 | | void ScCondFormatObj::removeByIndex(const sal_Int32 nIndex) |
505 | 0 | { |
506 | 0 | SolarMutexGuard aGuard; |
507 | 0 | if (getCoreObject()->size() >= o3tl::make_unsigned(nIndex)) |
508 | 0 | throw lang::IllegalArgumentException(); |
509 | | |
510 | 0 | getCoreObject()->RemoveEntry(nIndex); |
511 | 0 | } |
512 | | |
513 | | uno::Type ScCondFormatObj::getElementType() |
514 | 0 | { |
515 | 0 | return cppu::UnoType<beans::XPropertySet>::get(); |
516 | 0 | } |
517 | | |
518 | | sal_Bool ScCondFormatObj::hasElements() |
519 | 0 | { |
520 | 0 | SolarMutexGuard aGuard; |
521 | 0 | ScConditionalFormat* pFormat = getCoreObject(); |
522 | 0 | return !pFormat->IsEmpty(); |
523 | 0 | } |
524 | | |
525 | | sal_Int32 ScCondFormatObj::getCount() |
526 | 0 | { |
527 | 0 | SolarMutexGuard aGuard; |
528 | 0 | ScConditionalFormat* pFormat = getCoreObject(); |
529 | |
|
530 | 0 | return pFormat->size(); |
531 | 0 | } |
532 | | |
533 | | uno::Any ScCondFormatObj::getByIndex(sal_Int32 nIndex) |
534 | 0 | { |
535 | 0 | SolarMutexGuard aGuard; |
536 | 0 | if (getCoreObject()->size() <= o3tl::make_unsigned(nIndex)) |
537 | 0 | throw lang::IllegalArgumentException(); |
538 | | |
539 | 0 | const ScFormatEntry* pEntry = getCoreObject()->GetEntry(nIndex); |
540 | 0 | uno::Reference<beans::XPropertySet> xCondEntry = |
541 | 0 | createConditionEntry(pEntry, this); |
542 | 0 | return uno::Any(xCondEntry); |
543 | 0 | } |
544 | | |
545 | | uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCondFormatObj::getPropertySetInfo() |
546 | 0 | { |
547 | 0 | SolarMutexGuard aGuard; |
548 | 0 | static uno::Reference<beans::XPropertySetInfo> aRef( |
549 | 0 | new SfxItemPropertySetInfo( maPropSet.getPropertyMap())); |
550 | 0 | return aRef; |
551 | 0 | } |
552 | | |
553 | | void SAL_CALL ScCondFormatObj::setPropertyValue( |
554 | | const OUString& aPropertyName, const uno::Any& aValue ) |
555 | 0 | { |
556 | 0 | SolarMutexGuard aGuard; |
557 | |
|
558 | 0 | const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class |
559 | 0 | const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName ); |
560 | 0 | if ( !pEntry ) |
561 | 0 | throw beans::UnknownPropertyException(aPropertyName); |
562 | | |
563 | 0 | switch(pEntry->nWID) |
564 | 0 | { |
565 | 0 | case ID: |
566 | 0 | throw lang::IllegalArgumentException(); |
567 | 0 | break; |
568 | 0 | case CondFormat_Range: |
569 | 0 | { |
570 | 0 | uno::Reference<sheet::XSheetCellRanges> xRange; |
571 | 0 | if (aValue >>= xRange) |
572 | 0 | { |
573 | 0 | ScConditionalFormat* pFormat = getCoreObject(); |
574 | 0 | const uno::Sequence<table::CellRangeAddress> aRanges = |
575 | 0 | xRange->getRangeAddresses(); |
576 | 0 | ScRangeList aTargetRange; |
577 | 0 | for (const auto& rRange : aRanges) |
578 | 0 | { |
579 | 0 | ScRange aRange; |
580 | 0 | ScUnoConversion::FillScRange(aRange, rRange); |
581 | 0 | aTargetRange.Join(aRange); |
582 | 0 | } |
583 | 0 | pFormat->SetRange(aTargetRange); |
584 | 0 | } |
585 | 0 | } |
586 | 0 | break; |
587 | 0 | default: |
588 | 0 | SAL_WARN("sc", "unknown property"); |
589 | 0 | } |
590 | 0 | } |
591 | | |
592 | | uno::Any SAL_CALL ScCondFormatObj::getPropertyValue( const OUString& aPropertyName ) |
593 | 0 | { |
594 | 0 | SolarMutexGuard aGuard; |
595 | |
|
596 | 0 | const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class |
597 | 0 | const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName ); |
598 | 0 | if ( !pEntry ) |
599 | 0 | throw beans::UnknownPropertyException(aPropertyName); |
600 | | |
601 | 0 | uno::Any aAny; |
602 | 0 | switch(pEntry->nWID) |
603 | 0 | { |
604 | 0 | case ID: |
605 | 0 | aAny <<= sal_Int32(getCoreObject()->GetKey()); |
606 | 0 | break; |
607 | 0 | case CondFormat_Range: |
608 | 0 | { |
609 | 0 | const ScRangeList& rRange = getCoreObject()->GetRange(); |
610 | 0 | uno::Reference<sheet::XSheetCellRanges> xRange; |
611 | 0 | xRange.set(new ScCellRangesObj(mpDocShell, rRange)); |
612 | 0 | aAny <<= xRange; |
613 | 0 | } |
614 | 0 | break; |
615 | 0 | default: |
616 | 0 | SAL_WARN("sc", "unknown property"); |
617 | 0 | } |
618 | 0 | return aAny; |
619 | 0 | } |
620 | | |
621 | | void SAL_CALL ScCondFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */, |
622 | | const uno::Reference<beans::XPropertyChangeListener>& /* aListener */) |
623 | 0 | { |
624 | 0 | SAL_WARN("sc", "not implemented"); |
625 | 0 | } |
626 | | |
627 | | void SAL_CALL ScCondFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */, |
628 | | const uno::Reference<beans::XPropertyChangeListener>& /* aListener */) |
629 | 0 | { |
630 | 0 | SAL_WARN("sc", "not implemented"); |
631 | 0 | } |
632 | | |
633 | | void SAL_CALL ScCondFormatObj::addVetoableChangeListener( const OUString&, |
634 | | const uno::Reference<beans::XVetoableChangeListener>&) |
635 | 0 | { |
636 | 0 | SAL_WARN("sc", "not implemented"); |
637 | 0 | } |
638 | | |
639 | | void SAL_CALL ScCondFormatObj::removeVetoableChangeListener( const OUString&, |
640 | | const uno::Reference<beans::XVetoableChangeListener>&) |
641 | 0 | { |
642 | 0 | SAL_WARN("sc", "not implemented"); |
643 | 0 | } |
644 | | |
645 | | namespace { |
646 | | |
647 | | bool isObjectStillAlive(const ScConditionalFormat* pFormat, const ScFormatEntry* pEntry) |
648 | 0 | { |
649 | 0 | for(size_t i = 0, n= pFormat->size(); i < n; ++i) |
650 | 0 | { |
651 | 0 | if (pFormat->GetEntry(i) == pEntry) |
652 | 0 | return true; |
653 | 0 | } |
654 | 0 | return false; |
655 | 0 | } |
656 | | |
657 | | } |
658 | | |
659 | | ScConditionEntryObj::ScConditionEntryObj(rtl::Reference<ScCondFormatObj> const & xParent, |
660 | | const ScCondFormatEntry* pFormat): |
661 | 0 | mpDocShell(xParent->getDocShell()), |
662 | 0 | mxParent(xParent), |
663 | 0 | maPropSet(getConditionEntryrPropSet()), |
664 | 0 | mpFormat(pFormat) |
665 | 0 | { |
666 | 0 | } |
667 | | |
668 | | ScConditionEntryObj::~ScConditionEntryObj() |
669 | 0 | { |
670 | 0 | } |
671 | | |
672 | | ScCondFormatEntry* ScConditionEntryObj::getCoreObject() |
673 | 0 | { |
674 | 0 | ScConditionalFormat* pFormat = mxParent->getCoreObject(); |
675 | 0 | if (isObjectStillAlive(pFormat, mpFormat)) |
676 | 0 | return const_cast<ScCondFormatEntry*>(mpFormat); |
677 | | |
678 | 0 | throw lang::IllegalArgumentException(); |
679 | 0 | } |
680 | | |
681 | | sal_Int32 ScConditionEntryObj::getType() |
682 | 0 | { |
683 | 0 | return sheet::ConditionEntryType::CONDITION; |
684 | 0 | } |
685 | | |
686 | | uno::Reference<beans::XPropertySetInfo> SAL_CALL ScConditionEntryObj::getPropertySetInfo() |
687 | 0 | { |
688 | 0 | static uno::Reference<beans::XPropertySetInfo> aRef( |
689 | 0 | new SfxItemPropertySetInfo( maPropSet.getPropertyMap() )); |
690 | 0 | return aRef; |
691 | 0 | } |
692 | | |
693 | | void SAL_CALL ScConditionEntryObj::setPropertyValue( |
694 | | const OUString& aPropertyName, const uno::Any& aValue ) |
695 | 0 | { |
696 | 0 | SolarMutexGuard aGuard; |
697 | |
|
698 | 0 | const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class |
699 | 0 | const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName ); |
700 | 0 | if ( !pEntry ) |
701 | 0 | throw beans::UnknownPropertyException(aPropertyName); |
702 | | |
703 | 0 | switch(pEntry->nWID) |
704 | 0 | { |
705 | 0 | case StyleName: |
706 | 0 | { |
707 | 0 | OUString aStyleName; |
708 | 0 | if ((aValue >>= aStyleName) && !aStyleName.isEmpty()) |
709 | 0 | getCoreObject()->UpdateStyleName(aStyleName); |
710 | 0 | } |
711 | 0 | break; |
712 | 0 | case Formula1: |
713 | 0 | { |
714 | 0 | OUString aFormula; |
715 | 0 | if ((aValue >>= aFormula) && !aFormula.isEmpty()) |
716 | 0 | { |
717 | 0 | ScCompiler aComp(mpDocShell->GetDocument(), getCoreObject()->GetSrcPos()); |
718 | 0 | aComp.SetGrammar(mpDocShell->GetDocument().GetGrammar()); |
719 | 0 | std::unique_ptr<ScTokenArray> pArr(aComp.CompileString(aFormula)); |
720 | 0 | getCoreObject()->SetFormula1(*pArr); |
721 | 0 | } |
722 | 0 | } |
723 | 0 | break; |
724 | 0 | case Formula2: |
725 | 0 | { |
726 | 0 | OUString aFormula; |
727 | 0 | if ((aValue >>= aFormula) && !aFormula.isEmpty()) |
728 | 0 | { |
729 | 0 | ScCompiler aComp(mpDocShell->GetDocument(), getCoreObject()->GetSrcPos()); |
730 | 0 | aComp.SetGrammar(mpDocShell->GetDocument().GetGrammar()); |
731 | 0 | std::unique_ptr<ScTokenArray> pArr(aComp.CompileString(aFormula)); |
732 | 0 | getCoreObject()->SetFormula2(*pArr); |
733 | 0 | } |
734 | 0 | } |
735 | 0 | break; |
736 | 0 | case Operator: |
737 | 0 | { |
738 | 0 | sal_Int32 nVal; |
739 | 0 | if (aValue >>= nVal) |
740 | 0 | { |
741 | 0 | for (ConditionEntryApiMap const & rEntry : aConditionEntryMap) |
742 | 0 | { |
743 | 0 | if (rEntry.nApiMode == nVal) |
744 | 0 | { |
745 | 0 | getCoreObject()->SetOperation(rEntry.eMode); |
746 | 0 | break; |
747 | 0 | } |
748 | 0 | } |
749 | 0 | } |
750 | 0 | } |
751 | 0 | break; |
752 | 0 | default: |
753 | 0 | SAL_WARN("sc", "unsupported property"); |
754 | 0 | } |
755 | 0 | } |
756 | | |
757 | | uno::Any SAL_CALL ScConditionEntryObj::getPropertyValue( const OUString& aPropertyName ) |
758 | 0 | { |
759 | 0 | SolarMutexGuard aGuard; |
760 | |
|
761 | 0 | const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class |
762 | 0 | const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName ); |
763 | 0 | if ( !pEntry ) |
764 | 0 | throw beans::UnknownPropertyException(aPropertyName); |
765 | | |
766 | 0 | uno::Any aAny; |
767 | 0 | switch(pEntry->nWID) |
768 | 0 | { |
769 | 0 | case StyleName: |
770 | 0 | aAny <<= getCoreObject()->GetStyle(); |
771 | 0 | break; |
772 | 0 | case Formula1: |
773 | 0 | { |
774 | 0 | ScAddress aCursor = getCoreObject()->GetSrcPos(); |
775 | 0 | OUString aFormula = getCoreObject()->GetExpression(aCursor, 0); |
776 | 0 | aAny <<= aFormula; |
777 | 0 | } |
778 | 0 | break; |
779 | 0 | case Formula2: |
780 | 0 | { |
781 | 0 | ScAddress aCursor = getCoreObject()->GetSrcPos(); |
782 | 0 | OUString aFormula = getCoreObject()->GetExpression(aCursor, 1); |
783 | 0 | aAny <<= aFormula; |
784 | 0 | } |
785 | 0 | break; |
786 | 0 | case Operator: |
787 | 0 | { |
788 | 0 | ScConditionMode eMode = getCoreObject()->GetOperation(); |
789 | 0 | for (ConditionEntryApiMap const & rEntry : aConditionEntryMap) |
790 | 0 | { |
791 | 0 | if (rEntry.eMode == eMode) |
792 | 0 | { |
793 | 0 | aAny <<= rEntry.nApiMode; |
794 | 0 | break; |
795 | 0 | } |
796 | 0 | } |
797 | 0 | } |
798 | 0 | break; |
799 | 0 | default: |
800 | 0 | SAL_WARN("sc", "unsupported property"); |
801 | 0 | } |
802 | 0 | return aAny; |
803 | 0 | } |
804 | | |
805 | | void SAL_CALL ScConditionEntryObj::addPropertyChangeListener( const OUString& /* aPropertyName */, |
806 | | const uno::Reference<beans::XPropertyChangeListener>& /* aListener */) |
807 | 0 | { |
808 | 0 | SAL_WARN("sc", "not implemented"); |
809 | 0 | } |
810 | | |
811 | | void SAL_CALL ScConditionEntryObj::removePropertyChangeListener( const OUString& /* aPropertyName */, |
812 | | const uno::Reference<beans::XPropertyChangeListener>& /* aListener */) |
813 | 0 | { |
814 | 0 | SAL_WARN("sc", "not implemented"); |
815 | 0 | } |
816 | | |
817 | | void SAL_CALL ScConditionEntryObj::addVetoableChangeListener( const OUString&, |
818 | | const uno::Reference<beans::XVetoableChangeListener>&) |
819 | 0 | { |
820 | 0 | SAL_WARN("sc", "not implemented"); |
821 | 0 | } |
822 | | |
823 | | void SAL_CALL ScConditionEntryObj::removeVetoableChangeListener( const OUString&, |
824 | | const uno::Reference<beans::XVetoableChangeListener>&) |
825 | 0 | { |
826 | 0 | SAL_WARN("sc", "not implemented"); |
827 | 0 | } |
828 | | |
829 | | ScColorScaleFormatObj::ScColorScaleFormatObj(rtl::Reference<ScCondFormatObj> xParent, |
830 | | const ScColorScaleFormat* pFormat): |
831 | 0 | mxParent(std::move(xParent)), |
832 | 0 | maPropSet(getColorScalePropSet()), |
833 | 0 | mpFormat(pFormat) |
834 | 0 | { |
835 | 0 | } |
836 | | |
837 | | ScColorScaleFormatObj::~ScColorScaleFormatObj() |
838 | 0 | { |
839 | 0 | } |
840 | | |
841 | | ScColorScaleFormat* ScColorScaleFormatObj::getCoreObject() |
842 | 0 | { |
843 | 0 | ScConditionalFormat* pFormat = mxParent->getCoreObject(); |
844 | 0 | if (isObjectStillAlive(pFormat, mpFormat)) |
845 | 0 | return const_cast<ScColorScaleFormat*>(mpFormat); |
846 | | |
847 | 0 | throw lang::IllegalArgumentException(); |
848 | 0 | } |
849 | | |
850 | | sal_Int32 ScColorScaleFormatObj::getType() |
851 | 0 | { |
852 | 0 | return sheet::ConditionEntryType::COLORSCALE; |
853 | 0 | } |
854 | | |
855 | | uno::Reference<beans::XPropertySetInfo> SAL_CALL ScColorScaleFormatObj::getPropertySetInfo() |
856 | 0 | { |
857 | 0 | static uno::Reference<beans::XPropertySetInfo> aRef( |
858 | 0 | new SfxItemPropertySetInfo( maPropSet.getPropertyMap() )); |
859 | 0 | return aRef; |
860 | 0 | } |
861 | | |
862 | | namespace { |
863 | | |
864 | | void setColorScaleEntry(ScColorScaleEntry* pEntry, uno::Reference<sheet::XColorScaleEntry> const & xEntry) |
865 | 0 | { |
866 | 0 | ScColorScaleEntryType eType = ScColorScaleEntryType(); |
867 | 0 | sal_Int32 nApiType = xEntry->getType(); |
868 | 0 | bool bFound = false; |
869 | 0 | for (ColorScaleEntryTypeApiMap const & rEntry : aColorScaleEntryTypeMap) |
870 | 0 | { |
871 | 0 | if (rEntry.nApiType == nApiType) |
872 | 0 | { |
873 | 0 | eType = rEntry.eType; |
874 | 0 | bFound = true; |
875 | 0 | break; |
876 | 0 | } |
877 | 0 | } |
878 | |
|
879 | 0 | if (!bFound) |
880 | 0 | throw lang::IllegalArgumentException(); |
881 | | |
882 | 0 | pEntry->SetType(eType); |
883 | 0 | pEntry->SetColor(Color(ColorTransparency, xEntry->getColor())); |
884 | 0 | switch (eType) |
885 | 0 | { |
886 | 0 | case COLORSCALE_FORMULA: |
887 | | // TODO: Implement |
888 | 0 | break; |
889 | 0 | default: |
890 | 0 | { |
891 | 0 | double nVal = xEntry->getFormula().toDouble(); |
892 | 0 | pEntry->SetValue(nVal); |
893 | 0 | } |
894 | 0 | break; |
895 | 0 | } |
896 | 0 | } |
897 | | |
898 | | } |
899 | | |
900 | | void SAL_CALL ScColorScaleFormatObj::setPropertyValue( |
901 | | const OUString& aPropertyName, const uno::Any& aValue ) |
902 | 0 | { |
903 | 0 | SolarMutexGuard aGuard; |
904 | |
|
905 | 0 | const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class |
906 | 0 | const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName ); |
907 | 0 | if ( !pEntry ) |
908 | 0 | throw beans::UnknownPropertyException(aPropertyName); |
909 | | |
910 | 0 | switch(pEntry->nWID) |
911 | 0 | { |
912 | 0 | case ColorScaleEntries: |
913 | 0 | { |
914 | 0 | uno::Sequence<uno::Reference<sheet::XColorScaleEntry> > aEntries; |
915 | 0 | if (!(aValue >>= aEntries)) |
916 | 0 | throw lang::IllegalArgumentException(); |
917 | | |
918 | 0 | if (aEntries.getLength() < 2) |
919 | 0 | throw lang::IllegalArgumentException(); |
920 | | |
921 | | // TODO: we need to make sure that there are enough entries |
922 | 0 | size_t n = size_t(aEntries.getLength()); |
923 | 0 | for (size_t i = 0; i < n; ++i) |
924 | 0 | { |
925 | 0 | setColorScaleEntry(getCoreObject()->GetEntry(i), aEntries[i]); |
926 | 0 | } |
927 | |
|
928 | 0 | } |
929 | 0 | break; |
930 | 0 | default: |
931 | 0 | SAL_WARN("sc", "unknown property"); |
932 | 0 | } |
933 | 0 | } |
934 | | |
935 | | uno::Any SAL_CALL ScColorScaleFormatObj::getPropertyValue( const OUString& aPropertyName ) |
936 | 0 | { |
937 | 0 | SolarMutexGuard aGuard; |
938 | |
|
939 | 0 | const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class |
940 | 0 | const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName ); |
941 | 0 | if ( !pEntry ) |
942 | 0 | throw beans::UnknownPropertyException(aPropertyName); |
943 | | |
944 | 0 | uno::Any aAny; |
945 | |
|
946 | 0 | switch(pEntry->nWID) |
947 | 0 | { |
948 | 0 | case ColorScaleEntries: |
949 | 0 | { |
950 | 0 | uno::Sequence<uno::Reference<sheet::XColorScaleEntry> > aEntries(getCoreObject()->size()); |
951 | 0 | auto aEntriesRange = asNonConstRange(aEntries); |
952 | 0 | for (size_t i = 0; i < getCoreObject()->size(); ++i) |
953 | 0 | { |
954 | 0 | aEntriesRange[i] = new ScColorScaleEntryObj(this, i); |
955 | 0 | } |
956 | 0 | aAny <<= aEntries; |
957 | 0 | } |
958 | 0 | break; |
959 | 0 | default: |
960 | 0 | SAL_WARN("sc", "unknown property"); |
961 | 0 | } |
962 | | |
963 | 0 | return aAny; |
964 | 0 | } |
965 | | |
966 | | void SAL_CALL ScColorScaleFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */, |
967 | | const uno::Reference<beans::XPropertyChangeListener>& /* aListener */) |
968 | 0 | { |
969 | 0 | SAL_WARN("sc", "not implemented"); |
970 | 0 | } |
971 | | |
972 | | void SAL_CALL ScColorScaleFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */, |
973 | | const uno::Reference<beans::XPropertyChangeListener>& /* aListener */) |
974 | 0 | { |
975 | 0 | SAL_WARN("sc", "not implemented"); |
976 | 0 | } |
977 | | |
978 | | void SAL_CALL ScColorScaleFormatObj::addVetoableChangeListener( const OUString&, |
979 | | const uno::Reference<beans::XVetoableChangeListener>&) |
980 | 0 | { |
981 | 0 | SAL_WARN("sc", "not implemented"); |
982 | 0 | } |
983 | | |
984 | | void SAL_CALL ScColorScaleFormatObj::removeVetoableChangeListener( const OUString&, |
985 | | const uno::Reference<beans::XVetoableChangeListener>&) |
986 | 0 | { |
987 | 0 | SAL_WARN("sc", "not implemented"); |
988 | 0 | } |
989 | | |
990 | | ScColorScaleEntryObj::ScColorScaleEntryObj(rtl::Reference<ScColorScaleFormatObj> xParent, |
991 | | size_t nPos): |
992 | 0 | mxParent(std::move(xParent)), |
993 | 0 | mnPos(nPos) |
994 | 0 | { |
995 | 0 | } |
996 | | |
997 | | ScColorScaleEntryObj::~ScColorScaleEntryObj() |
998 | 0 | { |
999 | 0 | } |
1000 | | |
1001 | | ScColorScaleEntry* ScColorScaleEntryObj::getCoreObject() |
1002 | 0 | { |
1003 | 0 | ScColorScaleFormat* pFormat = mxParent->getCoreObject(); |
1004 | 0 | if (pFormat->size() <= mnPos) |
1005 | 0 | throw lang::IllegalArgumentException(); |
1006 | | |
1007 | 0 | return pFormat->GetEntry(mnPos); |
1008 | 0 | } |
1009 | | |
1010 | | sal_Int32 ScColorScaleEntryObj::getColor() |
1011 | 0 | { |
1012 | 0 | Color aColor = getCoreObject()->GetColor(); |
1013 | 0 | return sal_Int32(aColor); |
1014 | 0 | } |
1015 | | |
1016 | | void ScColorScaleEntryObj::setColor(sal_Int32 aColor) |
1017 | 0 | { |
1018 | 0 | getCoreObject()->SetColor(Color(ColorTransparency, aColor)); |
1019 | 0 | } |
1020 | | |
1021 | | sal_Int32 ScColorScaleEntryObj::getType() |
1022 | 0 | { |
1023 | 0 | ScColorScaleEntry* pEntry = getCoreObject(); |
1024 | 0 | for (ColorScaleEntryTypeApiMap const & rEntry : aColorScaleEntryTypeMap) |
1025 | 0 | { |
1026 | 0 | if (rEntry.eType == pEntry->GetType()) |
1027 | 0 | { |
1028 | 0 | return rEntry.nApiType; |
1029 | 0 | } |
1030 | 0 | } |
1031 | | |
1032 | 0 | throw lang::IllegalArgumentException(); |
1033 | 0 | } |
1034 | | |
1035 | | void ScColorScaleEntryObj::setType(sal_Int32 nType) |
1036 | 0 | { |
1037 | 0 | ScColorScaleEntry* pEntry = getCoreObject(); |
1038 | 0 | for (ColorScaleEntryTypeApiMap const & rEntry : aColorScaleEntryTypeMap) |
1039 | 0 | { |
1040 | 0 | if (rEntry.nApiType == nType) |
1041 | 0 | { |
1042 | 0 | pEntry->SetType(rEntry.eType); |
1043 | 0 | return; |
1044 | 0 | } |
1045 | 0 | } |
1046 | 0 | throw lang::IllegalArgumentException(); |
1047 | 0 | } |
1048 | | |
1049 | | OUString ScColorScaleEntryObj::getFormula() |
1050 | 0 | { |
1051 | 0 | ScColorScaleEntry* pEntry = getCoreObject(); |
1052 | 0 | switch (pEntry->GetType()) |
1053 | 0 | { |
1054 | 0 | case COLORSCALE_FORMULA: |
1055 | | // TODO: Implement |
1056 | 0 | break; |
1057 | 0 | default: |
1058 | 0 | return OUString::number(pEntry->GetValue()); |
1059 | 0 | } |
1060 | | |
1061 | 0 | return OUString(); |
1062 | 0 | } |
1063 | | |
1064 | | void ScColorScaleEntryObj::setFormula(const OUString& rFormula) |
1065 | 0 | { |
1066 | 0 | ScColorScaleEntry* pEntry = getCoreObject(); |
1067 | 0 | switch (pEntry->GetType()) |
1068 | 0 | { |
1069 | 0 | case COLORSCALE_FORMULA: |
1070 | | // TODO: Implement |
1071 | | // pEntry->SetFormula(rFormula); |
1072 | 0 | break; |
1073 | 0 | default: |
1074 | 0 | pEntry->SetValue(rFormula.toDouble()); |
1075 | 0 | break; |
1076 | 0 | } |
1077 | 0 | } |
1078 | | |
1079 | | |
1080 | | ScDataBarFormatObj::ScDataBarFormatObj(rtl::Reference<ScCondFormatObj> xParent, |
1081 | | const ScDataBarFormat* pFormat): |
1082 | 0 | mxParent(std::move(xParent)), |
1083 | 0 | maPropSet(getDataBarPropSet()), |
1084 | 0 | mpFormat(pFormat) |
1085 | 0 | { |
1086 | 0 | } |
1087 | | |
1088 | | ScDataBarFormatObj::~ScDataBarFormatObj() |
1089 | 0 | { |
1090 | 0 | } |
1091 | | |
1092 | | ScDataBarFormat* ScDataBarFormatObj::getCoreObject() |
1093 | 0 | { |
1094 | 0 | ScConditionalFormat* pFormat = mxParent->getCoreObject(); |
1095 | 0 | if (isObjectStillAlive(pFormat, mpFormat)) |
1096 | 0 | return const_cast<ScDataBarFormat*>(mpFormat); |
1097 | | |
1098 | 0 | throw lang::IllegalArgumentException(); |
1099 | 0 | } |
1100 | | |
1101 | | sal_Int32 ScDataBarFormatObj::getType() |
1102 | 0 | { |
1103 | 0 | return sheet::ConditionEntryType::DATABAR; |
1104 | 0 | } |
1105 | | |
1106 | | uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDataBarFormatObj::getPropertySetInfo() |
1107 | 0 | { |
1108 | 0 | SolarMutexGuard aGuard; |
1109 | 0 | static uno::Reference<beans::XPropertySetInfo> aRef( |
1110 | 0 | new SfxItemPropertySetInfo( maPropSet.getPropertyMap() )); |
1111 | 0 | return aRef; |
1112 | 0 | } |
1113 | | |
1114 | | namespace { |
1115 | | |
1116 | | void setDataBarEntry(ScColorScaleEntry* pEntry, uno::Reference<sheet::XDataBarEntry> const & xEntry) |
1117 | 0 | { |
1118 | 0 | ScColorScaleEntryType eType = ScColorScaleEntryType(); |
1119 | 0 | sal_Int32 nApiType = xEntry->getType(); |
1120 | 0 | bool bFound = false; |
1121 | 0 | for (DataBarEntryTypeApiMap const & rEntry : aDataBarEntryTypeMap) |
1122 | 0 | { |
1123 | 0 | if (rEntry.nApiType == nApiType) |
1124 | 0 | { |
1125 | 0 | eType = rEntry.eType; |
1126 | 0 | bFound = true; |
1127 | 0 | break; |
1128 | 0 | } |
1129 | 0 | } |
1130 | |
|
1131 | 0 | if (!bFound) |
1132 | 0 | throw lang::IllegalArgumentException(); |
1133 | | |
1134 | 0 | pEntry->SetType(eType); |
1135 | 0 | switch (eType) |
1136 | 0 | { |
1137 | 0 | case COLORSCALE_FORMULA: |
1138 | | // TODO: Implement |
1139 | 0 | break; |
1140 | 0 | default: |
1141 | 0 | { |
1142 | 0 | double nVal = xEntry->getFormula().toDouble(); |
1143 | 0 | pEntry->SetValue(nVal); |
1144 | 0 | } |
1145 | 0 | break; |
1146 | 0 | } |
1147 | 0 | } |
1148 | | |
1149 | | } |
1150 | | |
1151 | | void SAL_CALL ScDataBarFormatObj::setPropertyValue( |
1152 | | const OUString& aPropertyName, const uno::Any& aValue ) |
1153 | 0 | { |
1154 | 0 | SolarMutexGuard aGuard; |
1155 | |
|
1156 | 0 | const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class |
1157 | 0 | const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName ); |
1158 | 0 | if ( !pEntry ) |
1159 | 0 | throw beans::UnknownPropertyException(aPropertyName); |
1160 | | |
1161 | 0 | switch(pEntry->nWID) |
1162 | 0 | { |
1163 | 0 | case AxisPosition: |
1164 | 0 | { |
1165 | 0 | sal_Int32 nVal; |
1166 | 0 | if (aValue >>= nVal) |
1167 | 0 | { |
1168 | 0 | for (DataBarAxisApiMap const & rEntry : aDataBarAxisMap) |
1169 | 0 | { |
1170 | 0 | if (rEntry.nApiPos == nVal) |
1171 | 0 | { |
1172 | 0 | getCoreObject()->GetDataBarData()->meAxisPosition = |
1173 | 0 | rEntry.ePos; |
1174 | 0 | break; |
1175 | 0 | } |
1176 | 0 | } |
1177 | 0 | } |
1178 | 0 | } |
1179 | 0 | break; |
1180 | 0 | case UseGradient: |
1181 | 0 | { |
1182 | 0 | bool bUseGradient = true; |
1183 | 0 | if (aValue >>= bUseGradient) |
1184 | 0 | { |
1185 | 0 | getCoreObject()->GetDataBarData()->mbGradient = bUseGradient; |
1186 | 0 | } |
1187 | 0 | } |
1188 | 0 | break; |
1189 | 0 | case UseNegativeColor: |
1190 | 0 | { |
1191 | 0 | bool bUseNegativeColor = false; |
1192 | 0 | if (aValue >>= bUseNegativeColor) |
1193 | 0 | { |
1194 | 0 | getCoreObject()->GetDataBarData()->mbNeg = bUseNegativeColor; |
1195 | 0 | if (bUseNegativeColor && !getCoreObject()->GetDataBarData()->mxNegativeColor) |
1196 | 0 | { |
1197 | 0 | getCoreObject()->GetDataBarData()->mxNegativeColor = COL_AUTO; |
1198 | 0 | } |
1199 | 0 | } |
1200 | 0 | } |
1201 | 0 | break; |
1202 | 0 | case DataBar_ShowValue: |
1203 | 0 | { |
1204 | 0 | bool bShowValue = true; |
1205 | 0 | if (aValue >>= bShowValue) |
1206 | 0 | { |
1207 | 0 | getCoreObject()->GetDataBarData()->mbOnlyBar = !bShowValue; |
1208 | 0 | } |
1209 | 0 | } |
1210 | 0 | break; |
1211 | 0 | case DataBar_Color: |
1212 | 0 | { |
1213 | 0 | Color nColor = COL_AUTO; |
1214 | 0 | if (aValue >>= nColor) |
1215 | 0 | { |
1216 | 0 | getCoreObject()->GetDataBarData()->maPositiveColor = nColor; |
1217 | 0 | } |
1218 | 0 | } |
1219 | 0 | break; |
1220 | 0 | case AxisColor: |
1221 | 0 | { |
1222 | 0 | Color nAxisColor = COL_AUTO; |
1223 | 0 | if (aValue >>= nAxisColor) |
1224 | 0 | { |
1225 | 0 | getCoreObject()->GetDataBarData()->maAxisColor = nAxisColor; |
1226 | 0 | } |
1227 | 0 | } |
1228 | 0 | break; |
1229 | 0 | case NegativeColor: |
1230 | 0 | { |
1231 | 0 | Color nNegativeColor = COL_AUTO; |
1232 | 0 | if (!(aValue >>= nNegativeColor) || !getCoreObject()->GetDataBarData()->mbNeg) |
1233 | 0 | throw lang::IllegalArgumentException(); |
1234 | | |
1235 | 0 | getCoreObject()->GetDataBarData()->mxNegativeColor = nNegativeColor; |
1236 | |
|
1237 | 0 | } |
1238 | 0 | break; |
1239 | 0 | case DataBarEntries: |
1240 | 0 | { |
1241 | 0 | uno::Sequence<uno::Reference<sheet::XDataBarEntry> > aEntries; |
1242 | 0 | if (!(aValue >>= aEntries)) |
1243 | 0 | throw lang::IllegalArgumentException(); |
1244 | | |
1245 | 0 | if (aEntries.getLength() != 2) |
1246 | 0 | throw lang::IllegalArgumentException(); |
1247 | | |
1248 | 0 | setDataBarEntry(getCoreObject()->GetDataBarData()->mpLowerLimit.get(), |
1249 | 0 | aEntries[0]); |
1250 | 0 | setDataBarEntry(getCoreObject()->GetDataBarData()->mpUpperLimit.get(), |
1251 | 0 | aEntries[1]); |
1252 | |
|
1253 | 0 | } |
1254 | 0 | break; |
1255 | 0 | case MinimumLength: |
1256 | 0 | { |
1257 | 0 | double nLength = 0; |
1258 | 0 | if (!(aValue >>= nLength) || nLength >= 100 || nLength < 0) |
1259 | 0 | throw lang::IllegalArgumentException(); |
1260 | 0 | getCoreObject()->GetDataBarData()->mnMinLength = nLength; |
1261 | |
|
1262 | 0 | } |
1263 | 0 | break; |
1264 | 0 | case MaximumLength: |
1265 | 0 | { |
1266 | 0 | double nLength = 0; |
1267 | 0 | if (!(aValue >>= nLength) || nLength > 100 || nLength <= 0) |
1268 | 0 | throw lang::IllegalArgumentException(); |
1269 | 0 | getCoreObject()->GetDataBarData()->mnMaxLength = nLength; |
1270 | |
|
1271 | 0 | } |
1272 | 0 | break; |
1273 | 0 | } |
1274 | 0 | } |
1275 | | |
1276 | | uno::Any SAL_CALL ScDataBarFormatObj::getPropertyValue( const OUString& aPropertyName ) |
1277 | 0 | { |
1278 | 0 | SolarMutexGuard aGuard; |
1279 | |
|
1280 | 0 | const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class |
1281 | 0 | const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName ); |
1282 | 0 | if ( !pEntry ) |
1283 | 0 | throw beans::UnknownPropertyException(aPropertyName); |
1284 | | |
1285 | 0 | uno::Any aAny; |
1286 | 0 | switch(pEntry->nWID) |
1287 | 0 | { |
1288 | 0 | case AxisPosition: |
1289 | 0 | { |
1290 | 0 | databar::ScAxisPosition ePos = getCoreObject()->GetDataBarData()->meAxisPosition; |
1291 | 0 | sal_Int32 nApiPos = sheet::DataBarAxis::AXIS_NONE; |
1292 | 0 | for (DataBarAxisApiMap const & rEntry : aDataBarAxisMap) |
1293 | 0 | { |
1294 | 0 | if (rEntry.ePos == ePos) |
1295 | 0 | { |
1296 | 0 | nApiPos = rEntry.nApiPos; |
1297 | 0 | } |
1298 | 0 | } |
1299 | |
|
1300 | 0 | aAny <<= nApiPos; |
1301 | 0 | } |
1302 | 0 | break; |
1303 | 0 | case UseGradient: |
1304 | 0 | { |
1305 | 0 | aAny <<= getCoreObject()->GetDataBarData()->mbGradient; |
1306 | 0 | } |
1307 | 0 | break; |
1308 | 0 | case UseNegativeColor: |
1309 | 0 | { |
1310 | 0 | aAny <<= getCoreObject()->GetDataBarData()->mbNeg; |
1311 | 0 | } |
1312 | 0 | break; |
1313 | 0 | case DataBar_ShowValue: |
1314 | 0 | { |
1315 | 0 | aAny <<= !getCoreObject()->GetDataBarData()->mbOnlyBar; |
1316 | 0 | } |
1317 | 0 | break; |
1318 | 0 | case DataBar_Color: |
1319 | 0 | { |
1320 | 0 | aAny <<= getCoreObject()->GetDataBarData()->maPositiveColor; |
1321 | 0 | } |
1322 | 0 | break; |
1323 | 0 | case AxisColor: |
1324 | 0 | { |
1325 | 0 | aAny <<= getCoreObject()->GetDataBarData()->maAxisColor; |
1326 | 0 | } |
1327 | 0 | break; |
1328 | 0 | case NegativeColor: |
1329 | 0 | { |
1330 | 0 | if (getCoreObject()->GetDataBarData()->mbNeg && getCoreObject()->GetDataBarData()->mxNegativeColor) |
1331 | 0 | { |
1332 | 0 | aAny <<= *getCoreObject()->GetDataBarData()->mxNegativeColor; |
1333 | 0 | } |
1334 | 0 | } |
1335 | 0 | break; |
1336 | 0 | case DataBarEntries: |
1337 | 0 | { |
1338 | 0 | uno::Sequence<uno::Reference<sheet::XDataBarEntry> > aEntries |
1339 | 0 | { |
1340 | 0 | new ScDataBarEntryObj(this, 0), |
1341 | 0 | new ScDataBarEntryObj(this, 1) |
1342 | 0 | }; |
1343 | 0 | aAny <<= aEntries; |
1344 | 0 | } |
1345 | 0 | break; |
1346 | 0 | } |
1347 | 0 | return aAny; |
1348 | 0 | } |
1349 | | |
1350 | | void SAL_CALL ScDataBarFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */, |
1351 | | const uno::Reference<beans::XPropertyChangeListener>& /* aListener */) |
1352 | 0 | { |
1353 | 0 | SAL_WARN("sc", "not implemented"); |
1354 | 0 | } |
1355 | | |
1356 | | void SAL_CALL ScDataBarFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */, |
1357 | | const uno::Reference<beans::XPropertyChangeListener>& /* aListener */) |
1358 | 0 | { |
1359 | 0 | SAL_WARN("sc", "not implemented"); |
1360 | 0 | } |
1361 | | |
1362 | | void SAL_CALL ScDataBarFormatObj::addVetoableChangeListener( const OUString&, |
1363 | | const uno::Reference<beans::XVetoableChangeListener>&) |
1364 | 0 | { |
1365 | 0 | SAL_WARN("sc", "not implemented"); |
1366 | 0 | } |
1367 | | |
1368 | | void SAL_CALL ScDataBarFormatObj::removeVetoableChangeListener( const OUString&, |
1369 | | const uno::Reference<beans::XVetoableChangeListener>&) |
1370 | 0 | { |
1371 | 0 | SAL_WARN("sc", "not implemented"); |
1372 | 0 | } |
1373 | | |
1374 | | ScDataBarEntryObj::ScDataBarEntryObj(rtl::Reference<ScDataBarFormatObj> xParent, |
1375 | | size_t nPos): |
1376 | 0 | mxParent(std::move(xParent)), |
1377 | 0 | mnPos(nPos) |
1378 | 0 | { |
1379 | 0 | } |
1380 | | |
1381 | | ScDataBarEntryObj::~ScDataBarEntryObj() |
1382 | 0 | { |
1383 | 0 | } |
1384 | | |
1385 | | ScColorScaleEntry* ScDataBarEntryObj::getCoreObject() |
1386 | 0 | { |
1387 | 0 | ScDataBarFormat* pFormat = mxParent->getCoreObject(); |
1388 | 0 | ScColorScaleEntry* pEntry; |
1389 | 0 | if (mnPos == 0) |
1390 | 0 | pEntry = pFormat->GetDataBarData()->mpLowerLimit.get(); |
1391 | 0 | else |
1392 | 0 | pEntry = pFormat->GetDataBarData()->mpUpperLimit.get(); |
1393 | |
|
1394 | 0 | return pEntry; |
1395 | 0 | } |
1396 | | |
1397 | | sal_Int32 ScDataBarEntryObj::getType() |
1398 | 0 | { |
1399 | 0 | ScColorScaleEntry* pEntry = getCoreObject(); |
1400 | 0 | for (DataBarEntryTypeApiMap const & rEntry : aDataBarEntryTypeMap) |
1401 | 0 | { |
1402 | 0 | if (rEntry.eType == pEntry->GetType()) |
1403 | 0 | { |
1404 | 0 | return rEntry.nApiType; |
1405 | 0 | } |
1406 | 0 | } |
1407 | | |
1408 | 0 | throw lang::IllegalArgumentException(); |
1409 | 0 | } |
1410 | | |
1411 | | void ScDataBarEntryObj::setType(sal_Int32 nType) |
1412 | 0 | { |
1413 | 0 | ScColorScaleEntry* pEntry = getCoreObject(); |
1414 | 0 | for (DataBarEntryTypeApiMap const & rEntry : aDataBarEntryTypeMap) |
1415 | 0 | { |
1416 | 0 | if (rEntry.nApiType == nType) |
1417 | 0 | { |
1418 | 0 | pEntry->SetType(rEntry.eType); |
1419 | 0 | return; |
1420 | 0 | } |
1421 | 0 | } |
1422 | 0 | throw lang::IllegalArgumentException(); |
1423 | 0 | } |
1424 | | |
1425 | | OUString ScDataBarEntryObj::getFormula() |
1426 | 0 | { |
1427 | 0 | ScColorScaleEntry* pEntry = getCoreObject(); |
1428 | 0 | switch (pEntry->GetType()) |
1429 | 0 | { |
1430 | 0 | case COLORSCALE_FORMULA: |
1431 | | // TODO: Implement |
1432 | 0 | break; |
1433 | 0 | default: |
1434 | 0 | return OUString::number(pEntry->GetValue()); |
1435 | 0 | } |
1436 | | |
1437 | 0 | return OUString(); |
1438 | 0 | } |
1439 | | |
1440 | | void ScDataBarEntryObj::setFormula(const OUString& rFormula) |
1441 | 0 | { |
1442 | 0 | ScColorScaleEntry* pEntry = getCoreObject(); |
1443 | 0 | switch (pEntry->GetType()) |
1444 | 0 | { |
1445 | 0 | case COLORSCALE_FORMULA: |
1446 | | // TODO: Implement |
1447 | | // pEntry->SetFormula(rFormula); |
1448 | 0 | break; |
1449 | 0 | default: |
1450 | 0 | pEntry->SetValue(rFormula.toDouble()); |
1451 | 0 | break; |
1452 | 0 | } |
1453 | 0 | } |
1454 | | |
1455 | | |
1456 | | ScIconSetFormatObj::ScIconSetFormatObj(rtl::Reference<ScCondFormatObj> xParent, |
1457 | | const ScIconSetFormat* pFormat): |
1458 | 0 | mxParent(std::move(xParent)), |
1459 | 0 | maPropSet(getIconSetPropSet()), |
1460 | 0 | mpFormat(pFormat) |
1461 | 0 | { |
1462 | 0 | } |
1463 | | |
1464 | | ScIconSetFormatObj::~ScIconSetFormatObj() |
1465 | 0 | { |
1466 | 0 | } |
1467 | | |
1468 | | ScIconSetFormat* ScIconSetFormatObj::getCoreObject() |
1469 | 0 | { |
1470 | 0 | ScConditionalFormat* pFormat = mxParent->getCoreObject(); |
1471 | 0 | if (isObjectStillAlive(pFormat, mpFormat)) |
1472 | 0 | return const_cast<ScIconSetFormat*>(mpFormat); |
1473 | | |
1474 | 0 | throw lang::IllegalArgumentException(); |
1475 | 0 | } |
1476 | | |
1477 | | sal_Int32 ScIconSetFormatObj::getType() |
1478 | 0 | { |
1479 | 0 | return sheet::ConditionEntryType::ICONSET; |
1480 | 0 | } |
1481 | | |
1482 | | uno::Reference<beans::XPropertySetInfo> SAL_CALL ScIconSetFormatObj::getPropertySetInfo() |
1483 | 0 | { |
1484 | 0 | SolarMutexGuard aGuard; |
1485 | 0 | static uno::Reference<beans::XPropertySetInfo> aRef( |
1486 | 0 | new SfxItemPropertySetInfo( maPropSet.getPropertyMap() )); |
1487 | 0 | return aRef; |
1488 | 0 | } |
1489 | | |
1490 | | namespace { |
1491 | | |
1492 | | void setIconSetEntry(ScIconSetFormat* pFormat, uno::Reference<sheet::XIconSetEntry> const & xEntry, size_t nPos) |
1493 | 0 | { |
1494 | 0 | ScIconSetFormatData* pData = pFormat->GetIconSetData(); |
1495 | 0 | ScColorScaleEntryType eType = ScColorScaleEntryType(); |
1496 | 0 | sal_Int32 nApiType = xEntry->getType(); |
1497 | 0 | bool bFound = false; |
1498 | 0 | for (IconSetEntryTypeApiMap const & rEntry : aIconSetEntryTypeMap) |
1499 | 0 | { |
1500 | 0 | if (rEntry.nApiType == nApiType) |
1501 | 0 | { |
1502 | 0 | eType = rEntry.eType; |
1503 | 0 | bFound = true; |
1504 | 0 | break; |
1505 | 0 | } |
1506 | 0 | } |
1507 | |
|
1508 | 0 | if (!bFound) |
1509 | 0 | throw lang::IllegalArgumentException(); |
1510 | | |
1511 | 0 | pData->m_Entries[nPos]->SetType(eType); |
1512 | 0 | switch (eType) |
1513 | 0 | { |
1514 | 0 | case COLORSCALE_FORMULA: |
1515 | | // TODO: Implement |
1516 | 0 | break; |
1517 | 0 | default: |
1518 | 0 | { |
1519 | 0 | double nVal = xEntry->getFormula().toDouble(); |
1520 | 0 | pData->m_Entries[nPos]->SetValue(nVal); |
1521 | 0 | } |
1522 | 0 | break; |
1523 | 0 | } |
1524 | 0 | } |
1525 | | |
1526 | | } |
1527 | | |
1528 | | void SAL_CALL ScIconSetFormatObj::setPropertyValue( |
1529 | | const OUString& aPropertyName, const uno::Any& aValue ) |
1530 | 0 | { |
1531 | 0 | SolarMutexGuard aGuard; |
1532 | |
|
1533 | 0 | const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class |
1534 | 0 | const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName ); |
1535 | 0 | if ( !pEntry ) |
1536 | 0 | throw beans::UnknownPropertyException(aPropertyName); |
1537 | | |
1538 | 0 | switch(pEntry->nWID) |
1539 | 0 | { |
1540 | 0 | case ShowValue: |
1541 | 0 | { |
1542 | 0 | bool bShowValue = true; |
1543 | 0 | aValue >>= bShowValue; |
1544 | 0 | getCoreObject()->GetIconSetData()->mbShowValue = bShowValue; |
1545 | 0 | } |
1546 | 0 | break; |
1547 | 0 | case Reverse: |
1548 | 0 | { |
1549 | 0 | bool bReverse = false; |
1550 | 0 | aValue >>= bReverse; |
1551 | 0 | getCoreObject()->GetIconSetData()->mbReverse = bReverse; |
1552 | 0 | } |
1553 | 0 | break; |
1554 | 0 | case Icons: |
1555 | 0 | { |
1556 | 0 | sal_Int32 nApiType = -1; |
1557 | 0 | aValue >>= nApiType; |
1558 | 0 | ScIconSetType eType = IconSet_3Arrows; |
1559 | 0 | bool bFound = false; |
1560 | 0 | for (const IconSetTypeApiMap & rEntry : aIconSetApiMap) |
1561 | 0 | { |
1562 | 0 | if (rEntry.nApiType == nApiType) |
1563 | 0 | { |
1564 | 0 | eType = rEntry.eType; |
1565 | 0 | bFound = true; |
1566 | 0 | break; |
1567 | 0 | } |
1568 | 0 | } |
1569 | |
|
1570 | 0 | if (!bFound) |
1571 | 0 | { |
1572 | 0 | throw lang::IllegalArgumentException(); |
1573 | 0 | } |
1574 | | |
1575 | | // TODO: we need to make sure that there are enough entries |
1576 | 0 | getCoreObject()->GetIconSetData()->eIconSetType = eType; |
1577 | 0 | } |
1578 | 0 | break; |
1579 | 0 | case IconSetEntries: |
1580 | 0 | { |
1581 | 0 | uno::Sequence<uno::Reference<sheet::XIconSetEntry> > aEntries; |
1582 | 0 | if (!(aValue >>= aEntries)) |
1583 | 0 | throw lang::IllegalArgumentException(); |
1584 | | |
1585 | | // TODO: we need to check that the number of entries |
1586 | | // corresponds to the icon type |
1587 | 0 | sal_Int32 nLength = aEntries.getLength(); |
1588 | 0 | for (size_t i = 0; i < o3tl::make_unsigned(nLength); ++i) |
1589 | 0 | { |
1590 | 0 | setIconSetEntry(getCoreObject(), aEntries[i], i); |
1591 | 0 | } |
1592 | |
|
1593 | 0 | } |
1594 | 0 | break; |
1595 | 0 | default: |
1596 | 0 | break; |
1597 | 0 | } |
1598 | 0 | } |
1599 | | |
1600 | | uno::Any SAL_CALL ScIconSetFormatObj::getPropertyValue( const OUString& aPropertyName ) |
1601 | 0 | { |
1602 | 0 | SolarMutexGuard aGuard; |
1603 | |
|
1604 | 0 | const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class |
1605 | 0 | const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName ); |
1606 | 0 | if ( !pEntry ) |
1607 | 0 | throw beans::UnknownPropertyException(aPropertyName); |
1608 | | |
1609 | 0 | uno::Any aAny; |
1610 | |
|
1611 | 0 | switch(pEntry->nWID) |
1612 | 0 | { |
1613 | 0 | case ShowValue: |
1614 | 0 | aAny <<= getCoreObject()->GetIconSetData()->mbShowValue; |
1615 | 0 | break; |
1616 | 0 | case Reverse: |
1617 | 0 | aAny <<= getCoreObject()->GetIconSetData()->mbReverse; |
1618 | 0 | break; |
1619 | 0 | case Icons: |
1620 | 0 | { |
1621 | 0 | ScIconSetType eType = getCoreObject()->GetIconSetData()->eIconSetType; |
1622 | 0 | for (const IconSetTypeApiMap & rEntry : aIconSetApiMap) |
1623 | 0 | { |
1624 | 0 | if (rEntry.eType == eType) |
1625 | 0 | { |
1626 | 0 | aAny <<= rEntry.nApiType; |
1627 | 0 | break; |
1628 | 0 | } |
1629 | 0 | } |
1630 | 0 | } |
1631 | 0 | break; |
1632 | 0 | case IconSetEntries: |
1633 | 0 | { |
1634 | 0 | size_t nSize = getCoreObject()->size(); |
1635 | 0 | uno::Sequence<uno::Reference<sheet::XIconSetEntry> > aEntries(nSize); |
1636 | 0 | auto aEntriesRange = asNonConstRange(aEntries); |
1637 | 0 | for (size_t i = 0; i < nSize; ++i) |
1638 | 0 | { |
1639 | 0 | aEntriesRange[i] = new ScIconSetEntryObj(this, i); |
1640 | 0 | } |
1641 | 0 | aAny <<= aEntries; |
1642 | 0 | } |
1643 | 0 | break; |
1644 | 0 | default: |
1645 | 0 | SAL_WARN("sc", "unknown property"); |
1646 | 0 | } |
1647 | 0 | return aAny; |
1648 | 0 | } |
1649 | | |
1650 | | void SAL_CALL ScIconSetFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */, |
1651 | | const uno::Reference<beans::XPropertyChangeListener>& /* aListener */) |
1652 | 0 | { |
1653 | 0 | SAL_WARN("sc", "not implemented"); |
1654 | 0 | } |
1655 | | |
1656 | | void SAL_CALL ScIconSetFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */, |
1657 | | const uno::Reference<beans::XPropertyChangeListener>& /* aListener */) |
1658 | 0 | { |
1659 | 0 | SAL_WARN("sc", "not implemented"); |
1660 | 0 | } |
1661 | | |
1662 | | void SAL_CALL ScIconSetFormatObj::addVetoableChangeListener( const OUString&, |
1663 | | const uno::Reference<beans::XVetoableChangeListener>&) |
1664 | 0 | { |
1665 | 0 | SAL_WARN("sc", "not implemented"); |
1666 | 0 | } |
1667 | | |
1668 | | void SAL_CALL ScIconSetFormatObj::removeVetoableChangeListener( const OUString&, |
1669 | | const uno::Reference<beans::XVetoableChangeListener>&) |
1670 | 0 | { |
1671 | 0 | SAL_WARN("sc", "not implemented"); |
1672 | 0 | } |
1673 | | |
1674 | | ScIconSetEntryObj::ScIconSetEntryObj(rtl::Reference<ScIconSetFormatObj> xParent, |
1675 | | size_t nPos): |
1676 | 0 | mxParent(std::move(xParent)), |
1677 | 0 | mnPos(nPos) |
1678 | 0 | { |
1679 | 0 | } |
1680 | | |
1681 | | ScIconSetEntryObj::~ScIconSetEntryObj() |
1682 | 0 | { |
1683 | 0 | } |
1684 | | |
1685 | | ScColorScaleEntry* ScIconSetEntryObj::getCoreObject() |
1686 | 0 | { |
1687 | 0 | ScIconSetFormat* pFormat = mxParent->getCoreObject(); |
1688 | 0 | if (pFormat->GetIconSetData()->m_Entries.size() <= mnPos) |
1689 | 0 | throw lang::IllegalArgumentException(); |
1690 | | |
1691 | 0 | return pFormat->GetIconSetData()->m_Entries[mnPos].get(); |
1692 | 0 | } |
1693 | | |
1694 | | sal_Int32 ScIconSetEntryObj::getType() |
1695 | 0 | { |
1696 | 0 | ScColorScaleEntry* pEntry = getCoreObject(); |
1697 | | // the first entry always is minimum |
1698 | 0 | if (mnPos == 0) |
1699 | 0 | return sheet::IconSetFormatEntry::ICONSET_MIN; |
1700 | | |
1701 | 0 | for (IconSetEntryTypeApiMap const & rEntry : aIconSetEntryTypeMap) |
1702 | 0 | { |
1703 | 0 | if (rEntry.eType == pEntry->GetType()) |
1704 | 0 | { |
1705 | 0 | return rEntry.nApiType; |
1706 | 0 | } |
1707 | 0 | } |
1708 | | |
1709 | 0 | throw lang::IllegalArgumentException(); |
1710 | 0 | } |
1711 | | |
1712 | | void ScIconSetEntryObj::setType(sal_Int32 nType) |
1713 | 0 | { |
1714 | | // first entry is always MIN |
1715 | 0 | if (mnPos == 0) |
1716 | 0 | return; |
1717 | | |
1718 | 0 | ScColorScaleEntry* pEntry = getCoreObject(); |
1719 | 0 | for (IconSetEntryTypeApiMap const & rEntry : aIconSetEntryTypeMap) |
1720 | 0 | { |
1721 | 0 | if (rEntry.nApiType == nType) |
1722 | 0 | { |
1723 | 0 | pEntry->SetType(rEntry.eType); |
1724 | 0 | return; |
1725 | 0 | } |
1726 | 0 | } |
1727 | 0 | throw lang::IllegalArgumentException(); |
1728 | 0 | } |
1729 | | |
1730 | | OUString ScIconSetEntryObj::getFormula() |
1731 | 0 | { |
1732 | 0 | ScColorScaleEntry* pEntry = getCoreObject(); |
1733 | 0 | switch (pEntry->GetType()) |
1734 | 0 | { |
1735 | 0 | case COLORSCALE_FORMULA: |
1736 | | // TODO: Implement |
1737 | 0 | break; |
1738 | 0 | default: |
1739 | 0 | return OUString::number(pEntry->GetValue()); |
1740 | 0 | } |
1741 | | |
1742 | 0 | return OUString(); |
1743 | 0 | } |
1744 | | |
1745 | | void ScIconSetEntryObj::setFormula(const OUString& rFormula) |
1746 | 0 | { |
1747 | 0 | ScColorScaleEntry* pEntry = getCoreObject(); |
1748 | 0 | switch (pEntry->GetType()) |
1749 | 0 | { |
1750 | 0 | case COLORSCALE_FORMULA: |
1751 | | // TODO: Implement |
1752 | | // pEntry->SetFormula(rFormula); |
1753 | 0 | break; |
1754 | 0 | default: |
1755 | 0 | pEntry->SetValue(rFormula.toDouble()); |
1756 | 0 | break; |
1757 | 0 | } |
1758 | 0 | } |
1759 | | |
1760 | | ScCondDateFormatObj::ScCondDateFormatObj(rtl::Reference<ScCondFormatObj> xParent, |
1761 | | const ScCondDateFormatEntry* pFormat): |
1762 | 0 | mxParent(std::move(xParent)), |
1763 | 0 | maPropSet(getCondDatePropSet()), |
1764 | 0 | mpFormat(pFormat) |
1765 | 0 | { |
1766 | 0 | } |
1767 | | |
1768 | | ScCondDateFormatObj::~ScCondDateFormatObj() |
1769 | 0 | { |
1770 | 0 | } |
1771 | | |
1772 | | ScCondDateFormatEntry* ScCondDateFormatObj::getCoreObject() |
1773 | 0 | { |
1774 | 0 | ScConditionalFormat* pFormat = mxParent->getCoreObject(); |
1775 | 0 | if (isObjectStillAlive(pFormat, mpFormat)) |
1776 | 0 | return const_cast<ScCondDateFormatEntry*>(mpFormat); |
1777 | | |
1778 | 0 | throw lang::IllegalArgumentException(); |
1779 | 0 | } |
1780 | | |
1781 | | sal_Int32 ScCondDateFormatObj::getType() |
1782 | 0 | { |
1783 | 0 | return sheet::ConditionEntryType::DATE; |
1784 | 0 | } |
1785 | | |
1786 | | uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCondDateFormatObj::getPropertySetInfo() |
1787 | 0 | { |
1788 | 0 | SolarMutexGuard aGuard; |
1789 | 0 | static uno::Reference<beans::XPropertySetInfo> aRef( |
1790 | 0 | new SfxItemPropertySetInfo( maPropSet.getPropertyMap() )); |
1791 | 0 | return aRef; |
1792 | 0 | } |
1793 | | |
1794 | | void SAL_CALL ScCondDateFormatObj::setPropertyValue( |
1795 | | const OUString& aPropertyName, const uno::Any& aValue ) |
1796 | 0 | { |
1797 | 0 | SolarMutexGuard aGuard; |
1798 | |
|
1799 | 0 | const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class |
1800 | 0 | const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName ); |
1801 | 0 | if ( !pEntry ) |
1802 | 0 | throw beans::UnknownPropertyException(aPropertyName); |
1803 | | |
1804 | 0 | switch(pEntry->nWID) |
1805 | 0 | { |
1806 | 0 | case Date_StyleName: |
1807 | 0 | { |
1808 | 0 | OUString aStyleName; |
1809 | 0 | if (!(aValue >>= aStyleName)) |
1810 | 0 | throw lang::IllegalArgumentException(); |
1811 | | |
1812 | 0 | getCoreObject()->SetStyleName(aStyleName); |
1813 | |
|
1814 | 0 | } |
1815 | 0 | break; |
1816 | 0 | case DateType: |
1817 | 0 | { |
1818 | 0 | sal_Int32 nApiType = -1; |
1819 | 0 | if (!(aValue >>= nApiType)) |
1820 | 0 | throw lang::IllegalArgumentException(); |
1821 | | |
1822 | 0 | for (DateTypeApiMap const & rEntry : aDateTypeApiMap) |
1823 | 0 | { |
1824 | 0 | if (rEntry.nApiType == nApiType) |
1825 | 0 | { |
1826 | 0 | getCoreObject()->SetDateType(rEntry.eType); |
1827 | 0 | break; |
1828 | 0 | } |
1829 | 0 | } |
1830 | 0 | } |
1831 | 0 | break; |
1832 | 0 | default: |
1833 | 0 | break; |
1834 | 0 | } |
1835 | 0 | } |
1836 | | |
1837 | | uno::Any SAL_CALL ScCondDateFormatObj::getPropertyValue( const OUString& aPropertyName ) |
1838 | 0 | { |
1839 | 0 | SolarMutexGuard aGuard; |
1840 | |
|
1841 | 0 | const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class |
1842 | 0 | const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName ); |
1843 | 0 | if ( !pEntry ) |
1844 | 0 | throw beans::UnknownPropertyException(aPropertyName); |
1845 | | |
1846 | 0 | uno::Any aAny; |
1847 | |
|
1848 | 0 | switch(pEntry->nWID) |
1849 | 0 | { |
1850 | 0 | case Date_StyleName: |
1851 | 0 | { |
1852 | 0 | OUString aStyleName = getCoreObject()->GetStyleName(); |
1853 | 0 | aAny <<= aStyleName; |
1854 | 0 | } |
1855 | 0 | break; |
1856 | 0 | case DateType: |
1857 | 0 | { |
1858 | 0 | condformat::ScCondFormatDateType eType = getCoreObject()->GetDateType(); |
1859 | 0 | for (DateTypeApiMap const & rEntry : aDateTypeApiMap) |
1860 | 0 | { |
1861 | 0 | if (rEntry.eType == eType) |
1862 | 0 | { |
1863 | 0 | aAny <<= rEntry.nApiType; |
1864 | 0 | break; |
1865 | 0 | } |
1866 | 0 | } |
1867 | 0 | } |
1868 | 0 | break; |
1869 | 0 | default: |
1870 | 0 | SAL_WARN("sc", "unknown property"); |
1871 | 0 | } |
1872 | 0 | return aAny; |
1873 | 0 | } |
1874 | | |
1875 | | void SAL_CALL ScCondDateFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */, |
1876 | | const uno::Reference<beans::XPropertyChangeListener>& /* aListener */) |
1877 | 0 | { |
1878 | 0 | SAL_WARN("sc", "not implemented"); |
1879 | 0 | } |
1880 | | |
1881 | | void SAL_CALL ScCondDateFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */, |
1882 | | const uno::Reference<beans::XPropertyChangeListener>& /* aListener */) |
1883 | 0 | { |
1884 | 0 | SAL_WARN("sc", "not implemented"); |
1885 | 0 | } |
1886 | | |
1887 | | void SAL_CALL ScCondDateFormatObj::addVetoableChangeListener( const OUString&, |
1888 | | const uno::Reference<beans::XVetoableChangeListener>&) |
1889 | 0 | { |
1890 | 0 | SAL_WARN("sc", "not implemented"); |
1891 | 0 | } |
1892 | | |
1893 | | void SAL_CALL ScCondDateFormatObj::removeVetoableChangeListener( const OUString&, |
1894 | | const uno::Reference<beans::XVetoableChangeListener>&) |
1895 | 0 | { |
1896 | 0 | SAL_WARN("sc", "not implemented"); |
1897 | 0 | } |
1898 | | |
1899 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |