tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / unoobj / condformatuno.cxx
blob7ddef5f0094c9e50b584559dcb0b4122f0260c89
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
12 #include <algorithm>
13 #include <memory>
14 #include <condformatuno.hxx>
16 #include <document.hxx>
17 #include <conditio.hxx>
18 #include <colorscale.hxx>
19 #include <docsh.hxx>
20 #include <compiler.hxx>
21 #include <tokenarray.hxx>
23 #include <cellsuno.hxx>
24 #include <convuno.hxx>
26 #include <o3tl/safeint.hxx>
27 #include <utility>
28 #include <vcl/svapp.hxx>
29 #include <rtl/ustring.hxx>
30 #include <sal/log.hxx>
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>
41 namespace {
43 enum CondFormatProperties
45 ID,
46 CondFormat_Range
49 std::span<const SfxItemPropertyMapEntry> getCondFormatPropset()
51 static const SfxItemPropertyMapEntry aCondFormatPropertyMap_Impl[] =
53 {u"ID"_ustr, ID, cppu::UnoType<sal_Int32>::get(), 0, 0},
54 {u"Range"_ustr, CondFormat_Range, cppu::UnoType<sheet::XSheetCellRanges>::get(), 0, 0},
56 return aCondFormatPropertyMap_Impl;
59 enum ConditionEntryProperties
61 StyleName,
62 Formula1,
63 Formula2,
64 Operator
67 std::span<const SfxItemPropertyMapEntry> getConditionEntryrPropSet()
69 static const SfxItemPropertyMapEntry aConditionEntryPropertyMap_Impl[] =
71 {u"StyleName"_ustr, StyleName, cppu::UnoType<OUString>::get(), 0, 0},
72 {u"Formula1"_ustr, Formula1, cppu::UnoType<OUString>::get(), 0, 0},
73 {u"Formula2"_ustr, Formula2, cppu::UnoType<OUString>::get(), 0, 0},
74 {u"Operator"_ustr, Operator, cppu::UnoType<decltype(sheet::ConditionFormatOperator::EQUAL)>::get(), 0, 0 },
76 return aConditionEntryPropertyMap_Impl;
79 struct ConditionEntryApiMap
81 ScConditionMode eMode;
82 sal_Int32 nApiMode;
85 ConditionEntryApiMap const aConditionEntryMap[] =
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},
115 enum ColorScaleProperties
117 ColorScaleEntries
120 std::span<const SfxItemPropertyMapEntry> getColorScalePropSet()
122 static const SfxItemPropertyMapEntry aColorScalePropertyMap_Impl[] =
124 {u"ColorScaleEntries"_ustr, ColorScaleEntries, cppu::UnoType<uno::Sequence< sheet::XColorScaleEntry >>::get(), 0, 0 },
126 return aColorScalePropertyMap_Impl;
129 struct ColorScaleEntryTypeApiMap
131 ScColorScaleEntryType eType;
132 sal_Int32 nApiType;
135 ColorScaleEntryTypeApiMap const aColorScaleEntryTypeMap[] =
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 }
145 enum DataBarProperties
147 AxisPosition,
148 UseGradient,
149 UseNegativeColor,
150 DataBar_ShowValue,
151 DataBar_Color,
152 AxisColor,
153 NegativeColor,
154 DataBarEntries,
155 MinimumLength,
156 MaximumLength
159 std::span<const SfxItemPropertyMapEntry> getDataBarPropSet()
161 static const SfxItemPropertyMapEntry aDataBarPropertyMap_Impl[] =
163 {u"AxisPosition"_ustr, AxisPosition, cppu::UnoType<decltype(sheet::DataBarAxis::AXIS_AUTOMATIC)>::get(), 0, 0 },
164 {u"UseGradient"_ustr, UseGradient, cppu::UnoType<bool>::get(), 0, 0 },
165 {u"UseNegativeColor"_ustr, UseNegativeColor, cppu::UnoType<bool>::get(), 0, 0 },
166 {u"ShowValue"_ustr, DataBar_ShowValue, cppu::UnoType<bool>::get(), 0, 0 },
167 {u"Color"_ustr, DataBar_Color, cppu::UnoType<sal_Int32>::get(), 0, 0},
168 {u"AxisColor"_ustr, AxisColor, cppu::UnoType<sal_Int32>::get(), 0, 0},
169 {u"NegativeColor"_ustr, NegativeColor, cppu::UnoType<sal_Int32>::get(), 0, 0},
170 {u"DataBarEntries"_ustr, DataBarEntries, cppu::UnoType<uno::Sequence< sheet::XDataBarEntry >>::get(), 0, 0 },
171 {u"MinimumLength"_ustr, MinimumLength, cppu::UnoType<double>::get(), 0, 0 },
172 {u"MaximumLength"_ustr, MaximumLength, cppu::UnoType<double>::get(), 0, 0 },
174 return aDataBarPropertyMap_Impl;
177 struct DataBarAxisApiMap
179 databar::ScAxisPosition ePos;
180 sal_Int32 nApiPos;
183 DataBarAxisApiMap const aDataBarAxisMap[] =
185 { databar::NONE, sheet::DataBarAxis::AXIS_NONE },
186 { databar::AUTOMATIC, sheet::DataBarAxis::AXIS_AUTOMATIC },
187 { databar::MIDDLE, sheet::DataBarAxis::AXIS_MIDDLE }
190 struct DataBarEntryTypeApiMap
192 ScColorScaleEntryType eType;
193 sal_Int32 nApiType;
196 DataBarEntryTypeApiMap const aDataBarEntryTypeMap[] =
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 }
207 enum IconSetProperties
209 Icons,
210 Reverse,
211 ShowValue,
212 IconSetEntries
215 std::span<const SfxItemPropertyMapEntry> getIconSetPropSet()
217 static const SfxItemPropertyMapEntry aIconSetPropertyMap_Impl[] =
219 {u"Icons"_ustr, Icons, cppu::UnoType<decltype(sheet::IconSetType::ICONSET_3SYMBOLS)>::get(), 0, 0 },
220 {u"Reverse"_ustr, Reverse, cppu::UnoType<bool>::get(), 0, 0 },
221 {u"ShowValue"_ustr, ShowValue, cppu::UnoType<bool>::get(), 0, 0 },
222 {u"IconSetEntries"_ustr, IconSetEntries, cppu::UnoType<uno::Sequence< sheet::XIconSetEntry >>::get(), 0, 0 },
224 return aIconSetPropertyMap_Impl;
227 struct IconSetTypeApiMap
229 ScIconSetType eType;
230 sal_Int32 nApiType;
233 const IconSetTypeApiMap aIconSetApiMap[] =
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 },
256 struct IconSetEntryTypeApiMap
258 ScColorScaleEntryType eType;
259 sal_Int32 nApiType;
262 IconSetEntryTypeApiMap const aIconSetEntryTypeMap[] =
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 }
271 enum DateProperties
273 Date_StyleName,
274 DateType
277 std::span<const SfxItemPropertyMapEntry> getCondDatePropSet()
279 static const SfxItemPropertyMapEntry aCondDatePropertyMap_Impl[] =
281 {u"StyleName"_ustr, StyleName, cppu::UnoType<OUString>::get(), 0, 0},
282 {u"DateType"_ustr, Icons, cppu::UnoType<decltype(sheet::DateType::TODAY)>::get(), 0, 0 },
284 return aCondDatePropertyMap_Impl;
287 struct DateTypeApiMap
289 condformat::ScCondFormatDateType eType;
290 sal_Int32 nApiType;
293 DateTypeApiMap const aDateTypeApiMap[] =
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 }
312 ScCondFormatsObj::ScCondFormatsObj(ScDocShell* pDocShell, SCTAB nTab):
313 mnTab(nTab),
314 mpDocShell(pDocShell)
316 pDocShell->GetDocument().AddUnoObject(*this);
319 ScCondFormatsObj::~ScCondFormatsObj()
321 if (mpDocShell)
322 mpDocShell->GetDocument().RemoveUnoObject(*this);
325 void ScCondFormatsObj::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
327 if ( rHint.GetId() == SfxHintId::Dying )
329 mpDocShell = nullptr;
333 sal_Int32 ScCondFormatsObj::createByRange(const uno::Reference< sheet::XSheetCellRanges >& xRanges)
335 SolarMutexGuard aGuard;
336 if (!mpDocShell)
337 throw lang::IllegalArgumentException();
339 if (!xRanges.is())
340 throw lang::IllegalArgumentException();
342 const uno::Sequence<table::CellRangeAddress> aRanges =
343 xRanges->getRangeAddresses();
345 ScRangeList aCoreRange;
346 for (const auto& rRange : aRanges)
348 ScRange aRange;
349 ScUnoConversion::FillScRange(aRange, rRange);
350 aCoreRange.Join(aRange);
353 if (aCoreRange.empty())
354 throw lang::IllegalArgumentException();
356 SCTAB nTab = aCoreRange[0].aStart.Tab();
358 auto pNewFormat = std::make_unique<ScConditionalFormat>(0, &mpDocShell->GetDocument());
359 pNewFormat->SetRange(aCoreRange);
360 return mpDocShell->GetDocument().AddCondFormat(std::move(pNewFormat), nTab);
363 void ScCondFormatsObj::removeByID(const sal_Int32 nID)
365 SolarMutexGuard aGuard;
366 ScConditionalFormatList* pFormatList = getCoreObject();
367 pFormatList->erase(nID);
370 uno::Sequence<uno::Reference<sheet::XConditionalFormat> > ScCondFormatsObj::getConditionalFormats()
372 SolarMutexGuard aGuard;
373 ScConditionalFormatList* pFormatList = getCoreObject();
374 size_t n = pFormatList->size();
375 uno::Sequence<uno::Reference<sheet::XConditionalFormat> > aCondFormats(n);
376 std::transform(pFormatList->begin(), pFormatList->end(), aCondFormats.getArray(),
377 [this](const auto& rFormat)
378 { return uno::Reference(new ScCondFormatObj(mpDocShell, this, rFormat->GetKey())); });
380 return aCondFormats;
383 sal_Int32 ScCondFormatsObj::getLength()
385 SolarMutexGuard aGuard;
386 ScConditionalFormatList* pFormatList = getCoreObject();
387 return pFormatList->size();
390 ScConditionalFormatList* ScCondFormatsObj::getCoreObject()
392 if (!mpDocShell)
393 throw uno::RuntimeException();
395 ScConditionalFormatList* pList = mpDocShell->GetDocument().GetCondFormList(mnTab);
396 if (!pList)
397 throw uno::RuntimeException();
399 return pList;
402 namespace {
404 uno::Reference<beans::XPropertySet> createConditionEntry(const ScFormatEntry* pEntry,
405 rtl::Reference<ScCondFormatObj> const & xParent)
407 switch (pEntry->GetType())
409 case ScFormatEntry::Type::Condition:
410 case ScFormatEntry::Type::ExtCondition:
411 return new ScConditionEntryObj(xParent,
412 static_cast<const ScCondFormatEntry*>(pEntry));
413 break;
414 case ScFormatEntry::Type::Colorscale:
415 return new ScColorScaleFormatObj(xParent,
416 static_cast<const ScColorScaleFormat*>(pEntry));
417 break;
418 case ScFormatEntry::Type::Databar:
419 return new ScDataBarFormatObj(xParent,
420 static_cast<const ScDataBarFormat*>(pEntry));
421 break;
422 case ScFormatEntry::Type::Iconset:
423 return new ScIconSetFormatObj(xParent,
424 static_cast<const ScIconSetFormat*>(pEntry));
425 break;
426 case ScFormatEntry::Type::Date:
427 return new ScCondDateFormatObj(xParent,
428 static_cast<const ScCondDateFormatEntry*>(pEntry));
429 break;
430 default:
431 break;
433 return uno::Reference<beans::XPropertySet>();
438 ScCondFormatObj::ScCondFormatObj(ScDocShell* pDocShell, rtl::Reference<ScCondFormatsObj> xCondFormats,
439 sal_Int32 nKey):
440 mxCondFormatList(std::move(xCondFormats)),
441 mpDocShell(pDocShell),
442 maPropSet(getCondFormatPropset()),
443 mnKey(nKey)
447 ScCondFormatObj::~ScCondFormatObj()
451 ScConditionalFormat* ScCondFormatObj::getCoreObject()
453 ScConditionalFormatList* pList = mxCondFormatList->getCoreObject();
454 ScConditionalFormat* pFormat = pList->GetFormat(mnKey);
455 if (!pFormat)
456 throw uno::RuntimeException();
458 return pFormat;
461 ScDocShell* ScCondFormatObj::getDocShell()
463 return mpDocShell;
466 void ScCondFormatObj::createEntry(const sal_Int32 nType, const sal_Int32 nPos)
468 SolarMutexGuard aGuard;
469 ScConditionalFormat* pFormat = getCoreObject();
470 if (nPos > sal_Int32(pFormat->size()))
471 throw lang::IllegalArgumentException();
473 ScFormatEntry* pNewEntry = nullptr;
474 ScDocument& rDoc = mpDocShell->GetDocument();
475 switch (nType)
477 case sheet::ConditionEntryType::CONDITION:
478 pNewEntry = new ScCondFormatEntry(ScConditionMode::Equal, u""_ustr, u""_ustr,
479 rDoc, pFormat->GetRange().GetTopLeftCorner(), u""_ustr);
480 break;
481 case sheet::ConditionEntryType::COLORSCALE:
482 pNewEntry = new ScColorScaleFormat(&rDoc);
483 static_cast<ScColorScaleFormat*>(pNewEntry)->EnsureSize();
484 break;
485 case sheet::ConditionEntryType::DATABAR:
486 pNewEntry = new ScDataBarFormat(&rDoc);
487 static_cast<ScDataBarFormat*>(pNewEntry)->EnsureSize();
488 break;
489 case sheet::ConditionEntryType::ICONSET:
490 pNewEntry = new ScIconSetFormat(&rDoc);
491 static_cast<ScIconSetFormat*>(pNewEntry)->EnsureSize();
492 break;
493 case sheet::ConditionEntryType::DATE:
494 pNewEntry = new ScCondDateFormatEntry(&rDoc);
495 break;
496 default:
497 SAL_WARN("sc", "unknown conditional format type");
498 throw lang::IllegalArgumentException();
501 pFormat->AddEntry(pNewEntry);
504 void ScCondFormatObj::removeByIndex(const sal_Int32 nIndex)
506 SolarMutexGuard aGuard;
507 if (getCoreObject()->size() >= o3tl::make_unsigned(nIndex))
508 throw lang::IllegalArgumentException();
510 getCoreObject()->RemoveEntry(nIndex);
513 uno::Type ScCondFormatObj::getElementType()
515 return cppu::UnoType<beans::XPropertySet>::get();
518 sal_Bool ScCondFormatObj::hasElements()
520 SolarMutexGuard aGuard;
521 ScConditionalFormat* pFormat = getCoreObject();
522 return !pFormat->IsEmpty();
525 sal_Int32 ScCondFormatObj::getCount()
527 SolarMutexGuard aGuard;
528 ScConditionalFormat* pFormat = getCoreObject();
530 return pFormat->size();
533 uno::Any ScCondFormatObj::getByIndex(sal_Int32 nIndex)
535 SolarMutexGuard aGuard;
536 if (getCoreObject()->size() <= o3tl::make_unsigned(nIndex))
537 throw lang::IllegalArgumentException();
539 const ScFormatEntry* pEntry = getCoreObject()->GetEntry(nIndex);
540 uno::Reference<beans::XPropertySet> xCondEntry =
541 createConditionEntry(pEntry, this);
542 return uno::Any(xCondEntry);
545 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCondFormatObj::getPropertySetInfo()
547 SolarMutexGuard aGuard;
548 static uno::Reference<beans::XPropertySetInfo> aRef(
549 new SfxItemPropertySetInfo( maPropSet.getPropertyMap()));
550 return aRef;
553 void SAL_CALL ScCondFormatObj::setPropertyValue(
554 const OUString& aPropertyName, const uno::Any& aValue )
556 SolarMutexGuard aGuard;
558 const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class
559 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
560 if ( !pEntry )
561 throw beans::UnknownPropertyException(aPropertyName);
563 switch(pEntry->nWID)
565 case ID:
566 throw lang::IllegalArgumentException();
567 break;
568 case CondFormat_Range:
570 uno::Reference<sheet::XSheetCellRanges> xRange;
571 if (aValue >>= xRange)
573 ScConditionalFormat* pFormat = getCoreObject();
574 const uno::Sequence<table::CellRangeAddress> aRanges =
575 xRange->getRangeAddresses();
576 ScRangeList aTargetRange;
577 for (const auto& rRange : aRanges)
579 ScRange aRange;
580 ScUnoConversion::FillScRange(aRange, rRange);
581 aTargetRange.Join(aRange);
583 pFormat->SetRange(aTargetRange);
586 break;
587 default:
588 SAL_WARN("sc", "unknown property");
592 uno::Any SAL_CALL ScCondFormatObj::getPropertyValue( const OUString& aPropertyName )
594 SolarMutexGuard aGuard;
596 const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class
597 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
598 if ( !pEntry )
599 throw beans::UnknownPropertyException(aPropertyName);
601 uno::Any aAny;
602 switch(pEntry->nWID)
604 case ID:
605 aAny <<= sal_Int32(getCoreObject()->GetKey());
606 break;
607 case CondFormat_Range:
609 const ScRangeList& rRange = getCoreObject()->GetRange();
610 uno::Reference<sheet::XSheetCellRanges> xRange;
611 xRange.set(new ScCellRangesObj(mpDocShell, rRange));
612 aAny <<= xRange;
614 break;
615 default:
616 SAL_WARN("sc", "unknown property");
618 return aAny;
621 void SAL_CALL ScCondFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
622 const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
624 SAL_WARN("sc", "not implemented");
627 void SAL_CALL ScCondFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
628 const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
630 SAL_WARN("sc", "not implemented");
633 void SAL_CALL ScCondFormatObj::addVetoableChangeListener( const OUString&,
634 const uno::Reference<beans::XVetoableChangeListener>&)
636 SAL_WARN("sc", "not implemented");
639 void SAL_CALL ScCondFormatObj::removeVetoableChangeListener( const OUString&,
640 const uno::Reference<beans::XVetoableChangeListener>&)
642 SAL_WARN("sc", "not implemented");
645 namespace {
647 bool isObjectStillAlive(const ScConditionalFormat* pFormat, const ScFormatEntry* pEntry)
649 for(size_t i = 0, n= pFormat->size(); i < n; ++i)
651 if (pFormat->GetEntry(i) == pEntry)
652 return true;
654 return false;
659 ScConditionEntryObj::ScConditionEntryObj(rtl::Reference<ScCondFormatObj> const & xParent,
660 const ScCondFormatEntry* pFormat):
661 mpDocShell(xParent->getDocShell()),
662 mxParent(xParent),
663 maPropSet(getConditionEntryrPropSet()),
664 mpFormat(pFormat)
668 ScConditionEntryObj::~ScConditionEntryObj()
672 ScCondFormatEntry* ScConditionEntryObj::getCoreObject()
674 ScConditionalFormat* pFormat = mxParent->getCoreObject();
675 if (isObjectStillAlive(pFormat, mpFormat))
676 return const_cast<ScCondFormatEntry*>(mpFormat);
678 throw lang::IllegalArgumentException();
681 sal_Int32 ScConditionEntryObj::getType()
683 return sheet::ConditionEntryType::CONDITION;
686 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScConditionEntryObj::getPropertySetInfo()
688 static uno::Reference<beans::XPropertySetInfo> aRef(
689 new SfxItemPropertySetInfo( maPropSet.getPropertyMap() ));
690 return aRef;
693 void SAL_CALL ScConditionEntryObj::setPropertyValue(
694 const OUString& aPropertyName, const uno::Any& aValue )
696 SolarMutexGuard aGuard;
698 const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class
699 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
700 if ( !pEntry )
701 throw beans::UnknownPropertyException(aPropertyName);
703 switch(pEntry->nWID)
705 case StyleName:
707 OUString aStyleName;
708 if ((aValue >>= aStyleName) && !aStyleName.isEmpty())
709 getCoreObject()->UpdateStyleName(aStyleName);
711 break;
712 case Formula1:
714 OUString aFormula;
715 if ((aValue >>= aFormula) && !aFormula.isEmpty())
717 ScCompiler aComp(mpDocShell->GetDocument(), getCoreObject()->GetSrcPos());
718 aComp.SetGrammar(mpDocShell->GetDocument().GetGrammar());
719 std::unique_ptr<ScTokenArray> pArr(aComp.CompileString(aFormula));
720 getCoreObject()->SetFormula1(*pArr);
723 break;
724 case Formula2:
726 OUString aFormula;
727 if ((aValue >>= aFormula) && !aFormula.isEmpty())
729 ScCompiler aComp(mpDocShell->GetDocument(), getCoreObject()->GetSrcPos());
730 aComp.SetGrammar(mpDocShell->GetDocument().GetGrammar());
731 std::unique_ptr<ScTokenArray> pArr(aComp.CompileString(aFormula));
732 getCoreObject()->SetFormula2(*pArr);
735 break;
736 case Operator:
738 sal_Int32 nVal;
739 if (aValue >>= nVal)
741 for (ConditionEntryApiMap const & rEntry : aConditionEntryMap)
743 if (rEntry.nApiMode == nVal)
745 getCoreObject()->SetOperation(rEntry.eMode);
746 break;
751 break;
752 default:
753 SAL_WARN("sc", "unsupported property");
757 uno::Any SAL_CALL ScConditionEntryObj::getPropertyValue( const OUString& aPropertyName )
759 SolarMutexGuard aGuard;
761 const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class
762 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
763 if ( !pEntry )
764 throw beans::UnknownPropertyException(aPropertyName);
766 uno::Any aAny;
767 switch(pEntry->nWID)
769 case StyleName:
770 aAny <<= getCoreObject()->GetStyle();
771 break;
772 case Formula1:
774 ScAddress aCursor = getCoreObject()->GetSrcPos();
775 OUString aFormula = getCoreObject()->GetExpression(aCursor, 0);
776 aAny <<= aFormula;
778 break;
779 case Formula2:
781 ScAddress aCursor = getCoreObject()->GetSrcPos();
782 OUString aFormula = getCoreObject()->GetExpression(aCursor, 1);
783 aAny <<= aFormula;
785 break;
786 case Operator:
788 ScConditionMode eMode = getCoreObject()->GetOperation();
789 for (ConditionEntryApiMap const & rEntry : aConditionEntryMap)
791 if (rEntry.eMode == eMode)
793 aAny <<= rEntry.nApiMode;
794 break;
798 break;
799 default:
800 SAL_WARN("sc", "unsupported property");
802 return aAny;
805 void SAL_CALL ScConditionEntryObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
806 const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
808 SAL_WARN("sc", "not implemented");
811 void SAL_CALL ScConditionEntryObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
812 const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
814 SAL_WARN("sc", "not implemented");
817 void SAL_CALL ScConditionEntryObj::addVetoableChangeListener( const OUString&,
818 const uno::Reference<beans::XVetoableChangeListener>&)
820 SAL_WARN("sc", "not implemented");
823 void SAL_CALL ScConditionEntryObj::removeVetoableChangeListener( const OUString&,
824 const uno::Reference<beans::XVetoableChangeListener>&)
826 SAL_WARN("sc", "not implemented");
829 ScColorScaleFormatObj::ScColorScaleFormatObj(rtl::Reference<ScCondFormatObj> xParent,
830 const ScColorScaleFormat* pFormat):
831 mxParent(std::move(xParent)),
832 maPropSet(getColorScalePropSet()),
833 mpFormat(pFormat)
837 ScColorScaleFormatObj::~ScColorScaleFormatObj()
841 ScColorScaleFormat* ScColorScaleFormatObj::getCoreObject()
843 ScConditionalFormat* pFormat = mxParent->getCoreObject();
844 if (isObjectStillAlive(pFormat, mpFormat))
845 return const_cast<ScColorScaleFormat*>(mpFormat);
847 throw lang::IllegalArgumentException();
850 sal_Int32 ScColorScaleFormatObj::getType()
852 return sheet::ConditionEntryType::COLORSCALE;
855 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScColorScaleFormatObj::getPropertySetInfo()
857 static uno::Reference<beans::XPropertySetInfo> aRef(
858 new SfxItemPropertySetInfo( maPropSet.getPropertyMap() ));
859 return aRef;
862 namespace {
864 void setColorScaleEntry(ScColorScaleEntry* pEntry, uno::Reference<sheet::XColorScaleEntry> const & xEntry)
866 ScColorScaleEntryType eType = ScColorScaleEntryType();
867 sal_Int32 nApiType = xEntry->getType();
868 bool bFound = false;
869 for (ColorScaleEntryTypeApiMap const & rEntry : aColorScaleEntryTypeMap)
871 if (rEntry.nApiType == nApiType)
873 eType = rEntry.eType;
874 bFound = true;
875 break;
879 if (!bFound)
880 throw lang::IllegalArgumentException();
882 pEntry->SetType(eType);
883 pEntry->SetColor(Color(ColorTransparency, xEntry->getColor()));
884 switch (eType)
886 case COLORSCALE_FORMULA:
887 // TODO: Implement
888 break;
889 default:
891 double nVal = xEntry->getFormula().toDouble();
892 pEntry->SetValue(nVal);
894 break;
900 void SAL_CALL ScColorScaleFormatObj::setPropertyValue(
901 const OUString& aPropertyName, const uno::Any& aValue )
903 SolarMutexGuard aGuard;
905 const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class
906 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
907 if ( !pEntry )
908 throw beans::UnknownPropertyException(aPropertyName);
910 switch(pEntry->nWID)
912 case ColorScaleEntries:
914 uno::Sequence<uno::Reference<sheet::XColorScaleEntry> > aEntries;
915 if (!(aValue >>= aEntries))
916 throw lang::IllegalArgumentException();
918 if (aEntries.getLength() < 2)
919 throw lang::IllegalArgumentException();
921 // TODO: we need to make sure that there are enough entries
922 size_t n = size_t(aEntries.getLength());
923 for (size_t i = 0; i < n; ++i)
925 setColorScaleEntry(getCoreObject()->GetEntry(i), aEntries[i]);
929 break;
930 default:
931 SAL_WARN("sc", "unknown property");
935 uno::Any SAL_CALL ScColorScaleFormatObj::getPropertyValue( const OUString& aPropertyName )
937 SolarMutexGuard aGuard;
939 const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class
940 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
941 if ( !pEntry )
942 throw beans::UnknownPropertyException(aPropertyName);
944 uno::Any aAny;
946 switch(pEntry->nWID)
948 case ColorScaleEntries:
950 uno::Sequence<uno::Reference<sheet::XColorScaleEntry> > aEntries(getCoreObject()->size());
951 auto aEntriesRange = asNonConstRange(aEntries);
952 for (size_t i = 0; i < getCoreObject()->size(); ++i)
954 aEntriesRange[i] = new ScColorScaleEntryObj(this, i);
956 aAny <<= aEntries;
958 break;
959 default:
960 SAL_WARN("sc", "unknown property");
963 return aAny;
966 void SAL_CALL ScColorScaleFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
967 const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
969 SAL_WARN("sc", "not implemented");
972 void SAL_CALL ScColorScaleFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
973 const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
975 SAL_WARN("sc", "not implemented");
978 void SAL_CALL ScColorScaleFormatObj::addVetoableChangeListener( const OUString&,
979 const uno::Reference<beans::XVetoableChangeListener>&)
981 SAL_WARN("sc", "not implemented");
984 void SAL_CALL ScColorScaleFormatObj::removeVetoableChangeListener( const OUString&,
985 const uno::Reference<beans::XVetoableChangeListener>&)
987 SAL_WARN("sc", "not implemented");
990 ScColorScaleEntryObj::ScColorScaleEntryObj(rtl::Reference<ScColorScaleFormatObj> xParent,
991 size_t nPos):
992 mxParent(std::move(xParent)),
993 mnPos(nPos)
997 ScColorScaleEntryObj::~ScColorScaleEntryObj()
1001 ScColorScaleEntry* ScColorScaleEntryObj::getCoreObject()
1003 ScColorScaleFormat* pFormat = mxParent->getCoreObject();
1004 if (pFormat->size() <= mnPos)
1005 throw lang::IllegalArgumentException();
1007 return pFormat->GetEntry(mnPos);
1010 sal_Int32 ScColorScaleEntryObj::getColor()
1012 Color aColor = getCoreObject()->GetColor();
1013 return sal_Int32(aColor);
1016 void ScColorScaleEntryObj::setColor(sal_Int32 aColor)
1018 getCoreObject()->SetColor(Color(ColorTransparency, aColor));
1021 sal_Int32 ScColorScaleEntryObj::getType()
1023 ScColorScaleEntry* pEntry = getCoreObject();
1024 for (ColorScaleEntryTypeApiMap const & rEntry : aColorScaleEntryTypeMap)
1026 if (rEntry.eType == pEntry->GetType())
1028 return rEntry.nApiType;
1032 throw lang::IllegalArgumentException();
1035 void ScColorScaleEntryObj::setType(sal_Int32 nType)
1037 ScColorScaleEntry* pEntry = getCoreObject();
1038 for (ColorScaleEntryTypeApiMap const & rEntry : aColorScaleEntryTypeMap)
1040 if (rEntry.nApiType == nType)
1042 pEntry->SetType(rEntry.eType);
1043 return;
1046 throw lang::IllegalArgumentException();
1049 OUString ScColorScaleEntryObj::getFormula()
1051 ScColorScaleEntry* pEntry = getCoreObject();
1052 switch (pEntry->GetType())
1054 case COLORSCALE_FORMULA:
1055 // TODO: Implement
1056 break;
1057 default:
1058 return OUString::number(pEntry->GetValue());
1061 return OUString();
1064 void ScColorScaleEntryObj::setFormula(const OUString& rFormula)
1066 ScColorScaleEntry* pEntry = getCoreObject();
1067 switch (pEntry->GetType())
1069 case COLORSCALE_FORMULA:
1070 // TODO: Implement
1071 // pEntry->SetFormula(rFormula);
1072 break;
1073 default:
1074 pEntry->SetValue(rFormula.toDouble());
1075 break;
1080 ScDataBarFormatObj::ScDataBarFormatObj(rtl::Reference<ScCondFormatObj> xParent,
1081 const ScDataBarFormat* pFormat):
1082 mxParent(std::move(xParent)),
1083 maPropSet(getDataBarPropSet()),
1084 mpFormat(pFormat)
1088 ScDataBarFormatObj::~ScDataBarFormatObj()
1092 ScDataBarFormat* ScDataBarFormatObj::getCoreObject()
1094 ScConditionalFormat* pFormat = mxParent->getCoreObject();
1095 if (isObjectStillAlive(pFormat, mpFormat))
1096 return const_cast<ScDataBarFormat*>(mpFormat);
1098 throw lang::IllegalArgumentException();
1101 sal_Int32 ScDataBarFormatObj::getType()
1103 return sheet::ConditionEntryType::DATABAR;
1106 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDataBarFormatObj::getPropertySetInfo()
1108 SolarMutexGuard aGuard;
1109 static uno::Reference<beans::XPropertySetInfo> aRef(
1110 new SfxItemPropertySetInfo( maPropSet.getPropertyMap() ));
1111 return aRef;
1114 namespace {
1116 void setDataBarEntry(ScColorScaleEntry* pEntry, uno::Reference<sheet::XDataBarEntry> const & xEntry)
1118 ScColorScaleEntryType eType = ScColorScaleEntryType();
1119 sal_Int32 nApiType = xEntry->getType();
1120 bool bFound = false;
1121 for (DataBarEntryTypeApiMap const & rEntry : aDataBarEntryTypeMap)
1123 if (rEntry.nApiType == nApiType)
1125 eType = rEntry.eType;
1126 bFound = true;
1127 break;
1131 if (!bFound)
1132 throw lang::IllegalArgumentException();
1134 pEntry->SetType(eType);
1135 switch (eType)
1137 case COLORSCALE_FORMULA:
1138 // TODO: Implement
1139 break;
1140 default:
1142 double nVal = xEntry->getFormula().toDouble();
1143 pEntry->SetValue(nVal);
1145 break;
1151 void SAL_CALL ScDataBarFormatObj::setPropertyValue(
1152 const OUString& aPropertyName, const uno::Any& aValue )
1154 SolarMutexGuard aGuard;
1156 const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class
1157 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
1158 if ( !pEntry )
1159 throw beans::UnknownPropertyException(aPropertyName);
1161 switch(pEntry->nWID)
1163 case AxisPosition:
1165 sal_Int32 nVal;
1166 if (aValue >>= nVal)
1168 for (DataBarAxisApiMap const & rEntry : aDataBarAxisMap)
1170 if (rEntry.nApiPos == nVal)
1172 getCoreObject()->GetDataBarData()->meAxisPosition =
1173 rEntry.ePos;
1174 break;
1179 break;
1180 case UseGradient:
1182 bool bUseGradient = true;
1183 if (aValue >>= bUseGradient)
1185 getCoreObject()->GetDataBarData()->mbGradient = bUseGradient;
1188 break;
1189 case UseNegativeColor:
1191 bool bUseNegativeColor = false;
1192 if (aValue >>= bUseNegativeColor)
1194 getCoreObject()->GetDataBarData()->mbNeg = bUseNegativeColor;
1195 if (bUseNegativeColor && !getCoreObject()->GetDataBarData()->mxNegativeColor)
1197 getCoreObject()->GetDataBarData()->mxNegativeColor = COL_AUTO;
1201 break;
1202 case DataBar_ShowValue:
1204 bool bShowValue = true;
1205 if (aValue >>= bShowValue)
1207 getCoreObject()->GetDataBarData()->mbOnlyBar = !bShowValue;
1210 break;
1211 case DataBar_Color:
1213 Color nColor = COL_AUTO;
1214 if (aValue >>= nColor)
1216 getCoreObject()->GetDataBarData()->maPositiveColor = nColor;
1219 break;
1220 case AxisColor:
1222 Color nAxisColor = COL_AUTO;
1223 if (aValue >>= nAxisColor)
1225 getCoreObject()->GetDataBarData()->maAxisColor = nAxisColor;
1228 break;
1229 case NegativeColor:
1231 Color nNegativeColor = COL_AUTO;
1232 if (!(aValue >>= nNegativeColor) || !getCoreObject()->GetDataBarData()->mbNeg)
1233 throw lang::IllegalArgumentException();
1235 getCoreObject()->GetDataBarData()->mxNegativeColor = nNegativeColor;
1238 break;
1239 case DataBarEntries:
1241 uno::Sequence<uno::Reference<sheet::XDataBarEntry> > aEntries;
1242 if (!(aValue >>= aEntries))
1243 throw lang::IllegalArgumentException();
1245 if (aEntries.getLength() != 2)
1246 throw lang::IllegalArgumentException();
1248 setDataBarEntry(getCoreObject()->GetDataBarData()->mpLowerLimit.get(),
1249 aEntries[0]);
1250 setDataBarEntry(getCoreObject()->GetDataBarData()->mpUpperLimit.get(),
1251 aEntries[1]);
1254 break;
1255 case MinimumLength:
1257 double nLength = 0;
1258 if (!(aValue >>= nLength) || nLength >= 100 || nLength < 0)
1259 throw lang::IllegalArgumentException();
1260 getCoreObject()->GetDataBarData()->mnMinLength = nLength;
1263 break;
1264 case MaximumLength:
1266 double nLength = 0;
1267 if (!(aValue >>= nLength) || nLength > 100 || nLength <= 0)
1268 throw lang::IllegalArgumentException();
1269 getCoreObject()->GetDataBarData()->mnMaxLength = nLength;
1272 break;
1276 uno::Any SAL_CALL ScDataBarFormatObj::getPropertyValue( const OUString& aPropertyName )
1278 SolarMutexGuard aGuard;
1280 const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class
1281 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
1282 if ( !pEntry )
1283 throw beans::UnknownPropertyException(aPropertyName);
1285 uno::Any aAny;
1286 switch(pEntry->nWID)
1288 case AxisPosition:
1290 databar::ScAxisPosition ePos = getCoreObject()->GetDataBarData()->meAxisPosition;
1291 sal_Int32 nApiPos = sheet::DataBarAxis::AXIS_NONE;
1292 for (DataBarAxisApiMap const & rEntry : aDataBarAxisMap)
1294 if (rEntry.ePos == ePos)
1296 nApiPos = rEntry.nApiPos;
1300 aAny <<= nApiPos;
1302 break;
1303 case UseGradient:
1305 aAny <<= getCoreObject()->GetDataBarData()->mbGradient;
1307 break;
1308 case UseNegativeColor:
1310 aAny <<= getCoreObject()->GetDataBarData()->mbNeg;
1312 break;
1313 case DataBar_ShowValue:
1315 aAny <<= !getCoreObject()->GetDataBarData()->mbOnlyBar;
1317 break;
1318 case DataBar_Color:
1320 aAny <<= getCoreObject()->GetDataBarData()->maPositiveColor;
1322 break;
1323 case AxisColor:
1325 aAny <<= getCoreObject()->GetDataBarData()->maAxisColor;
1327 break;
1328 case NegativeColor:
1330 if (getCoreObject()->GetDataBarData()->mbNeg && getCoreObject()->GetDataBarData()->mxNegativeColor)
1332 aAny <<= *getCoreObject()->GetDataBarData()->mxNegativeColor;
1335 break;
1336 case DataBarEntries:
1338 uno::Sequence<uno::Reference<sheet::XDataBarEntry> > aEntries
1340 new ScDataBarEntryObj(this, 0),
1341 new ScDataBarEntryObj(this, 1)
1343 aAny <<= aEntries;
1345 break;
1347 return aAny;
1350 void SAL_CALL ScDataBarFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
1351 const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1353 SAL_WARN("sc", "not implemented");
1356 void SAL_CALL ScDataBarFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
1357 const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1359 SAL_WARN("sc", "not implemented");
1362 void SAL_CALL ScDataBarFormatObj::addVetoableChangeListener( const OUString&,
1363 const uno::Reference<beans::XVetoableChangeListener>&)
1365 SAL_WARN("sc", "not implemented");
1368 void SAL_CALL ScDataBarFormatObj::removeVetoableChangeListener( const OUString&,
1369 const uno::Reference<beans::XVetoableChangeListener>&)
1371 SAL_WARN("sc", "not implemented");
1374 ScDataBarEntryObj::ScDataBarEntryObj(rtl::Reference<ScDataBarFormatObj> xParent,
1375 size_t nPos):
1376 mxParent(std::move(xParent)),
1377 mnPos(nPos)
1381 ScDataBarEntryObj::~ScDataBarEntryObj()
1385 ScColorScaleEntry* ScDataBarEntryObj::getCoreObject()
1387 ScDataBarFormat* pFormat = mxParent->getCoreObject();
1388 ScColorScaleEntry* pEntry;
1389 if (mnPos == 0)
1390 pEntry = pFormat->GetDataBarData()->mpLowerLimit.get();
1391 else
1392 pEntry = pFormat->GetDataBarData()->mpUpperLimit.get();
1394 return pEntry;
1397 sal_Int32 ScDataBarEntryObj::getType()
1399 ScColorScaleEntry* pEntry = getCoreObject();
1400 for (DataBarEntryTypeApiMap const & rEntry : aDataBarEntryTypeMap)
1402 if (rEntry.eType == pEntry->GetType())
1404 return rEntry.nApiType;
1408 throw lang::IllegalArgumentException();
1411 void ScDataBarEntryObj::setType(sal_Int32 nType)
1413 ScColorScaleEntry* pEntry = getCoreObject();
1414 for (DataBarEntryTypeApiMap const & rEntry : aDataBarEntryTypeMap)
1416 if (rEntry.nApiType == nType)
1418 pEntry->SetType(rEntry.eType);
1419 return;
1422 throw lang::IllegalArgumentException();
1425 OUString ScDataBarEntryObj::getFormula()
1427 ScColorScaleEntry* pEntry = getCoreObject();
1428 switch (pEntry->GetType())
1430 case COLORSCALE_FORMULA:
1431 // TODO: Implement
1432 break;
1433 default:
1434 return OUString::number(pEntry->GetValue());
1437 return OUString();
1440 void ScDataBarEntryObj::setFormula(const OUString& rFormula)
1442 ScColorScaleEntry* pEntry = getCoreObject();
1443 switch (pEntry->GetType())
1445 case COLORSCALE_FORMULA:
1446 // TODO: Implement
1447 // pEntry->SetFormula(rFormula);
1448 break;
1449 default:
1450 pEntry->SetValue(rFormula.toDouble());
1451 break;
1456 ScIconSetFormatObj::ScIconSetFormatObj(rtl::Reference<ScCondFormatObj> xParent,
1457 const ScIconSetFormat* pFormat):
1458 mxParent(std::move(xParent)),
1459 maPropSet(getIconSetPropSet()),
1460 mpFormat(pFormat)
1464 ScIconSetFormatObj::~ScIconSetFormatObj()
1468 ScIconSetFormat* ScIconSetFormatObj::getCoreObject()
1470 ScConditionalFormat* pFormat = mxParent->getCoreObject();
1471 if (isObjectStillAlive(pFormat, mpFormat))
1472 return const_cast<ScIconSetFormat*>(mpFormat);
1474 throw lang::IllegalArgumentException();
1477 sal_Int32 ScIconSetFormatObj::getType()
1479 return sheet::ConditionEntryType::ICONSET;
1482 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScIconSetFormatObj::getPropertySetInfo()
1484 SolarMutexGuard aGuard;
1485 static uno::Reference<beans::XPropertySetInfo> aRef(
1486 new SfxItemPropertySetInfo( maPropSet.getPropertyMap() ));
1487 return aRef;
1490 namespace {
1492 void setIconSetEntry(ScIconSetFormat* pFormat, uno::Reference<sheet::XIconSetEntry> const & xEntry, size_t nPos)
1494 ScIconSetFormatData* pData = pFormat->GetIconSetData();
1495 ScColorScaleEntryType eType = ScColorScaleEntryType();
1496 sal_Int32 nApiType = xEntry->getType();
1497 bool bFound = false;
1498 for (IconSetEntryTypeApiMap const & rEntry : aIconSetEntryTypeMap)
1500 if (rEntry.nApiType == nApiType)
1502 eType = rEntry.eType;
1503 bFound = true;
1504 break;
1508 if (!bFound)
1509 throw lang::IllegalArgumentException();
1511 pData->m_Entries[nPos]->SetType(eType);
1512 switch (eType)
1514 case COLORSCALE_FORMULA:
1515 // TODO: Implement
1516 break;
1517 default:
1519 double nVal = xEntry->getFormula().toDouble();
1520 pData->m_Entries[nPos]->SetValue(nVal);
1522 break;
1528 void SAL_CALL ScIconSetFormatObj::setPropertyValue(
1529 const OUString& aPropertyName, const uno::Any& aValue )
1531 SolarMutexGuard aGuard;
1533 const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class
1534 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
1535 if ( !pEntry )
1536 throw beans::UnknownPropertyException(aPropertyName);
1538 switch(pEntry->nWID)
1540 case ShowValue:
1542 bool bShowValue = true;
1543 aValue >>= bShowValue;
1544 getCoreObject()->GetIconSetData()->mbShowValue = bShowValue;
1546 break;
1547 case Reverse:
1549 bool bReverse = false;
1550 aValue >>= bReverse;
1551 getCoreObject()->GetIconSetData()->mbReverse = bReverse;
1553 break;
1554 case Icons:
1556 sal_Int32 nApiType = -1;
1557 aValue >>= nApiType;
1558 ScIconSetType eType = IconSet_3Arrows;
1559 bool bFound = false;
1560 for (const IconSetTypeApiMap & rEntry : aIconSetApiMap)
1562 if (rEntry.nApiType == nApiType)
1564 eType = rEntry.eType;
1565 bFound = true;
1566 break;
1570 if (!bFound)
1572 throw lang::IllegalArgumentException();
1575 // TODO: we need to make sure that there are enough entries
1576 getCoreObject()->GetIconSetData()->eIconSetType = eType;
1578 break;
1579 case IconSetEntries:
1581 uno::Sequence<uno::Reference<sheet::XIconSetEntry> > aEntries;
1582 if (!(aValue >>= aEntries))
1583 throw lang::IllegalArgumentException();
1585 // TODO: we need to check that the number of entries
1586 // corresponds to the icon type
1587 sal_Int32 nLength = aEntries.getLength();
1588 for (size_t i = 0; i < o3tl::make_unsigned(nLength); ++i)
1590 setIconSetEntry(getCoreObject(), aEntries[i], i);
1594 break;
1595 default:
1596 break;
1600 uno::Any SAL_CALL ScIconSetFormatObj::getPropertyValue( const OUString& aPropertyName )
1602 SolarMutexGuard aGuard;
1604 const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class
1605 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
1606 if ( !pEntry )
1607 throw beans::UnknownPropertyException(aPropertyName);
1609 uno::Any aAny;
1611 switch(pEntry->nWID)
1613 case ShowValue:
1614 aAny <<= getCoreObject()->GetIconSetData()->mbShowValue;
1615 break;
1616 case Reverse:
1617 aAny <<= getCoreObject()->GetIconSetData()->mbReverse;
1618 break;
1619 case Icons:
1621 ScIconSetType eType = getCoreObject()->GetIconSetData()->eIconSetType;
1622 for (const IconSetTypeApiMap & rEntry : aIconSetApiMap)
1624 if (rEntry.eType == eType)
1626 aAny <<= rEntry.nApiType;
1627 break;
1631 break;
1632 case IconSetEntries:
1634 size_t nSize = getCoreObject()->size();
1635 uno::Sequence<uno::Reference<sheet::XIconSetEntry> > aEntries(nSize);
1636 auto aEntriesRange = asNonConstRange(aEntries);
1637 for (size_t i = 0; i < nSize; ++i)
1639 aEntriesRange[i] = new ScIconSetEntryObj(this, i);
1641 aAny <<= aEntries;
1643 break;
1644 default:
1645 SAL_WARN("sc", "unknown property");
1647 return aAny;
1650 void SAL_CALL ScIconSetFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
1651 const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1653 SAL_WARN("sc", "not implemented");
1656 void SAL_CALL ScIconSetFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
1657 const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1659 SAL_WARN("sc", "not implemented");
1662 void SAL_CALL ScIconSetFormatObj::addVetoableChangeListener( const OUString&,
1663 const uno::Reference<beans::XVetoableChangeListener>&)
1665 SAL_WARN("sc", "not implemented");
1668 void SAL_CALL ScIconSetFormatObj::removeVetoableChangeListener( const OUString&,
1669 const uno::Reference<beans::XVetoableChangeListener>&)
1671 SAL_WARN("sc", "not implemented");
1674 ScIconSetEntryObj::ScIconSetEntryObj(rtl::Reference<ScIconSetFormatObj> xParent,
1675 size_t nPos):
1676 mxParent(std::move(xParent)),
1677 mnPos(nPos)
1681 ScIconSetEntryObj::~ScIconSetEntryObj()
1685 ScColorScaleEntry* ScIconSetEntryObj::getCoreObject()
1687 ScIconSetFormat* pFormat = mxParent->getCoreObject();
1688 if (pFormat->GetIconSetData()->m_Entries.size() <= mnPos)
1689 throw lang::IllegalArgumentException();
1691 return pFormat->GetIconSetData()->m_Entries[mnPos].get();
1694 sal_Int32 ScIconSetEntryObj::getType()
1696 ScColorScaleEntry* pEntry = getCoreObject();
1697 // the first entry always is minimum
1698 if (mnPos == 0)
1699 return sheet::IconSetFormatEntry::ICONSET_MIN;
1701 for (IconSetEntryTypeApiMap const & rEntry : aIconSetEntryTypeMap)
1703 if (rEntry.eType == pEntry->GetType())
1705 return rEntry.nApiType;
1709 throw lang::IllegalArgumentException();
1712 void ScIconSetEntryObj::setType(sal_Int32 nType)
1714 // first entry is always MIN
1715 if (mnPos == 0)
1716 return;
1718 ScColorScaleEntry* pEntry = getCoreObject();
1719 for (IconSetEntryTypeApiMap const & rEntry : aIconSetEntryTypeMap)
1721 if (rEntry.nApiType == nType)
1723 pEntry->SetType(rEntry.eType);
1724 return;
1727 throw lang::IllegalArgumentException();
1730 OUString ScIconSetEntryObj::getFormula()
1732 ScColorScaleEntry* pEntry = getCoreObject();
1733 switch (pEntry->GetType())
1735 case COLORSCALE_FORMULA:
1736 // TODO: Implement
1737 break;
1738 default:
1739 return OUString::number(pEntry->GetValue());
1742 return OUString();
1745 void ScIconSetEntryObj::setFormula(const OUString& rFormula)
1747 ScColorScaleEntry* pEntry = getCoreObject();
1748 switch (pEntry->GetType())
1750 case COLORSCALE_FORMULA:
1751 // TODO: Implement
1752 // pEntry->SetFormula(rFormula);
1753 break;
1754 default:
1755 pEntry->SetValue(rFormula.toDouble());
1756 break;
1760 ScCondDateFormatObj::ScCondDateFormatObj(rtl::Reference<ScCondFormatObj> xParent,
1761 const ScCondDateFormatEntry* pFormat):
1762 mxParent(std::move(xParent)),
1763 maPropSet(getCondDatePropSet()),
1764 mpFormat(pFormat)
1768 ScCondDateFormatObj::~ScCondDateFormatObj()
1772 ScCondDateFormatEntry* ScCondDateFormatObj::getCoreObject()
1774 ScConditionalFormat* pFormat = mxParent->getCoreObject();
1775 if (isObjectStillAlive(pFormat, mpFormat))
1776 return const_cast<ScCondDateFormatEntry*>(mpFormat);
1778 throw lang::IllegalArgumentException();
1781 sal_Int32 ScCondDateFormatObj::getType()
1783 return sheet::ConditionEntryType::DATE;
1786 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCondDateFormatObj::getPropertySetInfo()
1788 SolarMutexGuard aGuard;
1789 static uno::Reference<beans::XPropertySetInfo> aRef(
1790 new SfxItemPropertySetInfo( maPropSet.getPropertyMap() ));
1791 return aRef;
1794 void SAL_CALL ScCondDateFormatObj::setPropertyValue(
1795 const OUString& aPropertyName, const uno::Any& aValue )
1797 SolarMutexGuard aGuard;
1799 const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class
1800 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
1801 if ( !pEntry )
1802 throw beans::UnknownPropertyException(aPropertyName);
1804 switch(pEntry->nWID)
1806 case Date_StyleName:
1808 OUString aStyleName;
1809 if (!(aValue >>= aStyleName))
1810 throw lang::IllegalArgumentException();
1812 getCoreObject()->SetStyleName(aStyleName);
1815 break;
1816 case DateType:
1818 sal_Int32 nApiType = -1;
1819 if (!(aValue >>= nApiType))
1820 throw lang::IllegalArgumentException();
1822 for (DateTypeApiMap const & rEntry : aDateTypeApiMap)
1824 if (rEntry.nApiType == nApiType)
1826 getCoreObject()->SetDateType(rEntry.eType);
1827 break;
1831 break;
1832 default:
1833 break;
1837 uno::Any SAL_CALL ScCondDateFormatObj::getPropertyValue( const OUString& aPropertyName )
1839 SolarMutexGuard aGuard;
1841 const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap(); // from derived class
1842 const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
1843 if ( !pEntry )
1844 throw beans::UnknownPropertyException(aPropertyName);
1846 uno::Any aAny;
1848 switch(pEntry->nWID)
1850 case Date_StyleName:
1852 OUString aStyleName = getCoreObject()->GetStyleName();
1853 aAny <<= aStyleName;
1855 break;
1856 case DateType:
1858 condformat::ScCondFormatDateType eType = getCoreObject()->GetDateType();
1859 for (DateTypeApiMap const & rEntry : aDateTypeApiMap)
1861 if (rEntry.eType == eType)
1863 aAny <<= rEntry.nApiType;
1864 break;
1868 break;
1869 default:
1870 SAL_WARN("sc", "unknown property");
1872 return aAny;
1875 void SAL_CALL ScCondDateFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
1876 const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1878 SAL_WARN("sc", "not implemented");
1881 void SAL_CALL ScCondDateFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
1882 const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1884 SAL_WARN("sc", "not implemented");
1887 void SAL_CALL ScCondDateFormatObj::addVetoableChangeListener( const OUString&,
1888 const uno::Reference<beans::XVetoableChangeListener>&)
1890 SAL_WARN("sc", "not implemented");
1893 void SAL_CALL ScCondDateFormatObj::removeVetoableChangeListener( const OUString&,
1894 const uno::Reference<beans::XVetoableChangeListener>&)
1896 SAL_WARN("sc", "not implemented");
1899 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */