Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
    SolarMutexGuard aGuard;
322
323
0
    if (mpDocShell)
324
0
        mpDocShell->GetDocument().RemoveUnoObject(*this);
325
0
}
326
327
void ScCondFormatsObj::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
328
0
{
329
0
    if ( rHint.GetId() == SfxHintId::Dying )
330
0
    {
331
0
        mpDocShell = nullptr;
332
0
    }
333
0
}
334
335
sal_Int32 ScCondFormatsObj::createByRange(const uno::Reference< sheet::XSheetCellRanges >& xRanges)
336
0
{
337
0
    SolarMutexGuard aGuard;
338
0
    if (!mpDocShell)
339
0
        throw lang::IllegalArgumentException();
340
341
0
    if (!xRanges.is())
342
0
        throw lang::IllegalArgumentException();
343
344
0
    const uno::Sequence<table::CellRangeAddress> aRanges =
345
0
        xRanges->getRangeAddresses();
346
347
0
    ScRangeList aCoreRange;
348
0
    for (const auto& rRange : aRanges)
349
0
    {
350
0
        ScRange aRange;
351
0
        ScUnoConversion::FillScRange(aRange, rRange);
352
0
        aCoreRange.Join(aRange);
353
0
    }
354
355
0
    if (aCoreRange.empty())
356
0
        throw lang::IllegalArgumentException();
357
358
0
    SCTAB nTab = aCoreRange[0].aStart.Tab();
359
360
0
    auto pNewFormat = std::make_unique<ScConditionalFormat>(0, mpDocShell->GetDocument());
361
0
    pNewFormat->SetRange(aCoreRange);
362
0
    ScDocument& rDoc = mpDocShell->GetDocument();
363
0
    sal_Int32 nIndex = rDoc.AddCondFormat(std::move(pNewFormat), nTab);
364
0
    rDoc.AddCondFormatData(aCoreRange, nTab, nIndex);
365
366
0
    return nIndex;
367
0
}
368
369
void ScCondFormatsObj::removeByID(const sal_Int32 nID)
370
0
{
371
0
    SolarMutexGuard aGuard;
372
0
    ScConditionalFormatList* pFormatList = getCoreObject();
373
0
    pFormatList->erase(nID);
374
0
}
375
376
uno::Sequence<uno::Reference<sheet::XConditionalFormat> > ScCondFormatsObj::getConditionalFormats()
377
0
{
378
0
    SolarMutexGuard aGuard;
379
0
    ScConditionalFormatList* pFormatList = getCoreObject();
380
0
    size_t n = pFormatList->size();
381
0
    uno::Sequence<uno::Reference<sheet::XConditionalFormat> > aCondFormats(n);
382
0
    std::transform(pFormatList->begin(), pFormatList->end(), aCondFormats.getArray(),
383
0
                   [this](const auto& rFormat)
384
0
                   { return uno::Reference(new ScCondFormatObj(mpDocShell, this, rFormat->GetKey())); });
385
386
0
    return aCondFormats;
387
0
}
388
389
sal_Int32 ScCondFormatsObj::getLength()
390
0
{
391
0
    SolarMutexGuard aGuard;
392
0
    ScConditionalFormatList* pFormatList = getCoreObject();
393
0
    return pFormatList->size();
394
0
}
395
396
ScConditionalFormatList* ScCondFormatsObj::getCoreObject()
397
0
{
398
0
    if (!mpDocShell)
399
0
        throw uno::RuntimeException();
400
401
0
    ScConditionalFormatList* pList = mpDocShell->GetDocument().GetCondFormList(mnTab);
402
0
    if (!pList)
403
0
        throw uno::RuntimeException();
404
405
0
    return pList;
406
0
}
407
408
namespace {
409
410
uno::Reference<beans::XPropertySet> createConditionEntry(const ScFormatEntry* pEntry,
411
        rtl::Reference<ScCondFormatObj> const & xParent)
412
0
{
413
0
    switch (pEntry->GetType())
414
0
    {
415
0
        case ScFormatEntry::Type::Condition:
416
0
        case ScFormatEntry::Type::ExtCondition:
417
0
            return new ScConditionEntryObj(xParent,
418
0
                    static_cast<const ScCondFormatEntry*>(pEntry));
419
0
        break;
420
0
        case ScFormatEntry::Type::Colorscale:
421
0
            return new ScColorScaleFormatObj(xParent,
422
0
                    static_cast<const ScColorScaleFormat*>(pEntry));
423
0
        break;
424
0
        case ScFormatEntry::Type::Databar:
425
0
            return new ScDataBarFormatObj(xParent,
426
0
                    static_cast<const ScDataBarFormat*>(pEntry));
427
0
        break;
428
0
        case ScFormatEntry::Type::Iconset:
429
0
            return new ScIconSetFormatObj(xParent,
430
0
                    static_cast<const ScIconSetFormat*>(pEntry));
431
0
        break;
432
0
        case ScFormatEntry::Type::Date:
433
0
            return new ScCondDateFormatObj(xParent,
434
0
                    static_cast<const ScCondDateFormatEntry*>(pEntry));
435
0
        break;
436
0
        default:
437
0
        break;
438
0
    }
439
0
    return uno::Reference<beans::XPropertySet>();
440
0
}
441
442
}
443
444
ScCondFormatObj::ScCondFormatObj(ScDocShell* pDocShell, rtl::Reference<ScCondFormatsObj> xCondFormats,
445
        sal_Int32 nKey):
446
0
    mxCondFormatList(std::move(xCondFormats)),
447
0
    mpDocShell(pDocShell),
448
0
    maPropSet(getCondFormatPropset()),
449
0
    mnKey(nKey)
450
0
{
451
0
}
452
453
ScCondFormatObj::~ScCondFormatObj()
454
0
{
455
0
}
456
457
ScConditionalFormat* ScCondFormatObj::getCoreObject()
458
0
{
459
0
    ScConditionalFormatList* pList = mxCondFormatList->getCoreObject();
460
0
    ScConditionalFormat* pFormat = pList->GetFormat(mnKey);
461
0
    if (!pFormat)
462
0
        throw uno::RuntimeException();
463
464
0
    return pFormat;
465
0
}
466
467
ScDocShell* ScCondFormatObj::getDocShell()
468
0
{
469
0
    return mpDocShell;
470
0
}
471
472
namespace
473
{
474
ScColorScaleFormat* createColorScaleFormat(ScDocument& rDoc, size_t nEntries)
475
0
{
476
0
    ScColorScaleFormat* pNewEntry = new ScColorScaleFormat(rDoc);
477
478
0
    for (size_t i = 0; i < nEntries; ++i)
479
0
        pNewEntry->AddEntry(new ScColorScaleEntry);
480
481
0
    pNewEntry->EnsureSize();
482
483
0
    return pNewEntry;
484
0
}
485
}
486
487
void ScCondFormatObj::createEntry(const sal_Int32 nType, const sal_Int32 nPos)
488
0
{
489
0
    SolarMutexGuard aGuard;
490
0
    ScConditionalFormat* pFormat = getCoreObject();
491
0
    if (nPos > sal_Int32(pFormat->size()))
492
0
        throw lang::IllegalArgumentException();
493
494
0
    ScFormatEntry* pNewEntry = nullptr;
495
0
    ScDocument& rDoc = mpDocShell->GetDocument();
496
0
    switch (nType)
497
0
    {
498
0
        case sheet::ConditionEntryType::CONDITION:
499
0
            pNewEntry = new ScCondFormatEntry(ScConditionMode::Equal, u""_ustr, u""_ustr,
500
0
                    rDoc, pFormat->GetRange().GetTopLeftCorner(), u""_ustr);
501
0
        break;
502
0
        case sheet::ConditionEntryType::COLORSCALE:
503
0
            pNewEntry = createColorScaleFormat(rDoc, 0);
504
0
        break;
505
0
        case sheet::ConditionEntryType::COLORSCALE2:
506
0
            pNewEntry = createColorScaleFormat(rDoc, 2);
507
0
        break;
508
0
        case sheet::ConditionEntryType::COLORSCALE3:
509
0
            pNewEntry = createColorScaleFormat(rDoc, 3);
510
0
        break;
511
0
        case sheet::ConditionEntryType::DATABAR:
512
0
            pNewEntry = new ScDataBarFormat(rDoc);
513
0
            static_cast<ScDataBarFormat*>(pNewEntry)->EnsureSize();
514
0
        break;
515
0
        case sheet::ConditionEntryType::ICONSET:
516
0
            pNewEntry = new ScIconSetFormat(rDoc);
517
0
            static_cast<ScIconSetFormat*>(pNewEntry)->EnsureSize();
518
0
        break;
519
0
        case sheet::ConditionEntryType::DATE:
520
0
            pNewEntry = new ScCondDateFormatEntry(rDoc);
521
0
        break;
522
0
        default:
523
0
            SAL_WARN("sc", "unknown conditional format type");
524
0
            throw lang::IllegalArgumentException();
525
0
    }
526
527
0
    pFormat->AddEntry(pNewEntry);
528
0
}
529
530
void ScCondFormatObj::removeByIndex(const sal_Int32 nIndex)
531
0
{
532
0
    SolarMutexGuard aGuard;
533
0
    if (getCoreObject()->size() >= o3tl::make_unsigned(nIndex))
534
0
        throw lang::IllegalArgumentException();
535
536
0
    getCoreObject()->RemoveEntry(nIndex);
537
0
}
538
539
uno::Type ScCondFormatObj::getElementType()
540
0
{
541
0
    return cppu::UnoType<beans::XPropertySet>::get();
542
0
}
543
544
sal_Bool ScCondFormatObj::hasElements()
545
0
{
546
0
    SolarMutexGuard aGuard;
547
0
    ScConditionalFormat* pFormat = getCoreObject();
548
0
    return !pFormat->IsEmpty();
549
0
}
550
551
sal_Int32 ScCondFormatObj::getCount()
552
0
{
553
0
    SolarMutexGuard aGuard;
554
0
    ScConditionalFormat* pFormat = getCoreObject();
555
556
0
    return pFormat->size();
557
0
}
558
559
uno::Any ScCondFormatObj::getByIndex(sal_Int32 nIndex)
560
0
{
561
0
    SolarMutexGuard aGuard;
562
0
    if (getCoreObject()->size() <= o3tl::make_unsigned(nIndex))
563
0
        throw lang::IllegalArgumentException();
564
565
0
    const ScFormatEntry* pEntry = getCoreObject()->GetEntry(nIndex);
566
0
    uno::Reference<beans::XPropertySet> xCondEntry =
567
0
        createConditionEntry(pEntry, this);
568
0
    return uno::Any(xCondEntry);
569
0
}
570
571
uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCondFormatObj::getPropertySetInfo()
572
0
{
573
0
    SolarMutexGuard aGuard;
574
0
    static uno::Reference<beans::XPropertySetInfo> aRef(
575
0
        new SfxItemPropertySetInfo( maPropSet.getPropertyMap()));
576
0
    return aRef;
577
0
}
578
579
void SAL_CALL ScCondFormatObj::setPropertyValue(
580
                        const OUString& aPropertyName, const uno::Any& aValue )
581
0
{
582
0
    SolarMutexGuard aGuard;
583
584
0
    const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap();     // from derived class
585
0
    const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
586
0
    if ( !pEntry )
587
0
        throw beans::UnknownPropertyException(aPropertyName);
588
589
0
    switch(pEntry->nWID)
590
0
    {
591
0
        case ID:
592
0
            throw lang::IllegalArgumentException();
593
0
        break;
594
0
        case CondFormat_Range:
595
0
        {
596
0
            uno::Reference<sheet::XSheetCellRanges> xRange;
597
0
            if (aValue >>= xRange)
598
0
            {
599
0
                ScConditionalFormat* pFormat = getCoreObject();
600
0
                const uno::Sequence<table::CellRangeAddress> aRanges =
601
0
                    xRange->getRangeAddresses();
602
0
                ScRangeList aTargetRange;
603
0
                for (const auto& rRange : aRanges)
604
0
                {
605
0
                    ScRange aRange;
606
0
                    ScUnoConversion::FillScRange(aRange, rRange);
607
0
                    aTargetRange.Join(aRange);
608
0
                }
609
0
                pFormat->SetRange(aTargetRange);
610
0
            }
611
0
        }
612
0
        break;
613
0
        default:
614
0
            SAL_WARN("sc", "unknown property");
615
0
    }
616
0
}
617
618
uno::Any SAL_CALL ScCondFormatObj::getPropertyValue( const OUString& aPropertyName )
619
0
{
620
0
    SolarMutexGuard aGuard;
621
622
0
    const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap();     // from derived class
623
0
    const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
624
0
    if ( !pEntry )
625
0
        throw beans::UnknownPropertyException(aPropertyName);
626
627
0
    uno::Any aAny;
628
0
    switch(pEntry->nWID)
629
0
    {
630
0
        case ID:
631
0
            aAny <<= sal_Int32(getCoreObject()->GetKey());
632
0
        break;
633
0
        case CondFormat_Range:
634
0
        {
635
0
            const ScRangeList& rRange = getCoreObject()->GetRange();
636
0
            uno::Reference<sheet::XSheetCellRanges> xRange;
637
0
            xRange.set(new ScCellRangesObj(mpDocShell, rRange));
638
0
            aAny <<= xRange;
639
0
        }
640
0
        break;
641
0
        default:
642
0
            SAL_WARN("sc", "unknown property");
643
0
    }
644
0
    return aAny;
645
0
}
646
647
void SAL_CALL ScCondFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
648
                            const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
649
0
{
650
0
    SAL_WARN("sc", "not implemented");
651
0
}
652
653
void SAL_CALL ScCondFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
654
                            const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
655
0
{
656
0
    SAL_WARN("sc", "not implemented");
657
0
}
658
659
void SAL_CALL ScCondFormatObj::addVetoableChangeListener( const OUString&,
660
                            const uno::Reference<beans::XVetoableChangeListener>&)
661
0
{
662
0
    SAL_WARN("sc", "not implemented");
663
0
}
664
665
void SAL_CALL ScCondFormatObj::removeVetoableChangeListener( const OUString&,
666
                            const uno::Reference<beans::XVetoableChangeListener>&)
667
0
{
668
0
    SAL_WARN("sc", "not implemented");
669
0
}
670
671
namespace {
672
673
bool isObjectStillAlive(const ScConditionalFormat* pFormat, const ScFormatEntry* pEntry)
674
0
{
675
0
    for(size_t i = 0, n= pFormat->size(); i < n; ++i)
676
0
    {
677
0
        if (pFormat->GetEntry(i) == pEntry)
678
0
            return true;
679
0
    }
680
0
    return false;
681
0
}
682
683
}
684
685
ScConditionEntryObj::ScConditionEntryObj(rtl::Reference<ScCondFormatObj> const & xParent,
686
        const ScCondFormatEntry* pFormat):
687
0
    mpDocShell(xParent->getDocShell()),
688
0
    mxParent(xParent),
689
0
    maPropSet(getConditionEntryrPropSet()),
690
0
    mpFormat(pFormat)
691
0
{
692
0
}
693
694
ScConditionEntryObj::~ScConditionEntryObj()
695
0
{
696
0
}
697
698
ScCondFormatEntry* ScConditionEntryObj::getCoreObject()
699
0
{
700
0
    ScConditionalFormat* pFormat = mxParent->getCoreObject();
701
0
    if (isObjectStillAlive(pFormat, mpFormat))
702
0
        return const_cast<ScCondFormatEntry*>(mpFormat);
703
704
0
    throw lang::IllegalArgumentException();
705
0
}
706
707
sal_Int32 ScConditionEntryObj::getType()
708
0
{
709
0
    return sheet::ConditionEntryType::CONDITION;
710
0
}
711
712
uno::Reference<beans::XPropertySetInfo> SAL_CALL ScConditionEntryObj::getPropertySetInfo()
713
0
{
714
0
    static uno::Reference<beans::XPropertySetInfo> aRef(
715
0
        new SfxItemPropertySetInfo( maPropSet.getPropertyMap() ));
716
0
    return aRef;
717
0
}
718
719
void SAL_CALL ScConditionEntryObj::setPropertyValue(
720
                        const OUString& aPropertyName, const uno::Any& aValue )
721
0
{
722
0
    SolarMutexGuard aGuard;
723
724
0
    const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap();     // from derived class
725
0
    const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
726
0
    if ( !pEntry )
727
0
        throw beans::UnknownPropertyException(aPropertyName);
728
729
0
    switch(pEntry->nWID)
730
0
    {
731
0
        case StyleName:
732
0
        {
733
0
            OUString aStyleName;
734
0
            if ((aValue >>= aStyleName) && !aStyleName.isEmpty())
735
0
                getCoreObject()->UpdateStyleName(aStyleName);
736
0
        }
737
0
        break;
738
0
        case Formula1:
739
0
        {
740
0
            OUString aFormula;
741
0
            if ((aValue >>= aFormula) && !aFormula.isEmpty())
742
0
            {
743
0
                ScCompiler aComp(mpDocShell->GetDocument(), getCoreObject()->GetSrcPos());
744
0
                aComp.SetGrammar(mpDocShell->GetDocument().GetGrammar());
745
0
                std::unique_ptr<ScTokenArray> pArr(aComp.CompileString(aFormula));
746
0
                getCoreObject()->SetFormula1(*pArr);
747
0
            }
748
0
        }
749
0
        break;
750
0
        case Formula2:
751
0
        {
752
0
            OUString aFormula;
753
0
            if ((aValue >>= aFormula) && !aFormula.isEmpty())
754
0
            {
755
0
                ScCompiler aComp(mpDocShell->GetDocument(), getCoreObject()->GetSrcPos());
756
0
                aComp.SetGrammar(mpDocShell->GetDocument().GetGrammar());
757
0
                std::unique_ptr<ScTokenArray> pArr(aComp.CompileString(aFormula));
758
0
                getCoreObject()->SetFormula2(*pArr);
759
0
            }
760
0
        }
761
0
        break;
762
0
        case Operator:
763
0
        {
764
0
            sal_Int32 nVal;
765
0
            if (aValue >>= nVal)
766
0
            {
767
0
                for (ConditionEntryApiMap const & rEntry : aConditionEntryMap)
768
0
                {
769
0
                    if (rEntry.nApiMode == nVal)
770
0
                    {
771
0
                        getCoreObject()->SetOperation(rEntry.eMode);
772
0
                        break;
773
0
                    }
774
0
                }
775
0
            }
776
0
        }
777
0
        break;
778
0
        default:
779
0
            SAL_WARN("sc", "unsupported property");
780
0
    }
781
0
}
782
783
uno::Any SAL_CALL ScConditionEntryObj::getPropertyValue( const OUString& aPropertyName )
784
0
{
785
0
    SolarMutexGuard aGuard;
786
787
0
    const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap();     // from derived class
788
0
    const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
789
0
    if ( !pEntry )
790
0
        throw beans::UnknownPropertyException(aPropertyName);
791
792
0
    uno::Any aAny;
793
0
    switch(pEntry->nWID)
794
0
    {
795
0
        case StyleName:
796
0
            aAny <<= getCoreObject()->GetStyle();
797
0
        break;
798
0
        case Formula1:
799
0
        {
800
0
            ScAddress aCursor = getCoreObject()->GetSrcPos();
801
0
            OUString aFormula = getCoreObject()->GetExpression(aCursor, 0);
802
0
            aAny <<= aFormula;
803
0
        }
804
0
        break;
805
0
        case Formula2:
806
0
        {
807
0
            ScAddress aCursor = getCoreObject()->GetSrcPos();
808
0
            OUString aFormula = getCoreObject()->GetExpression(aCursor, 1);
809
0
            aAny <<= aFormula;
810
0
        }
811
0
        break;
812
0
        case Operator:
813
0
        {
814
0
            ScConditionMode eMode = getCoreObject()->GetOperation();
815
0
            for (ConditionEntryApiMap const & rEntry : aConditionEntryMap)
816
0
            {
817
0
                if (rEntry.eMode == eMode)
818
0
                {
819
0
                    aAny <<= rEntry.nApiMode;
820
0
                    break;
821
0
                }
822
0
            }
823
0
        }
824
0
        break;
825
0
        default:
826
0
            SAL_WARN("sc", "unsupported property");
827
0
    }
828
0
    return aAny;
829
0
}
830
831
void SAL_CALL ScConditionEntryObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
832
                            const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
833
0
{
834
0
    SAL_WARN("sc", "not implemented");
835
0
}
836
837
void SAL_CALL ScConditionEntryObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
838
                            const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
839
0
{
840
0
    SAL_WARN("sc", "not implemented");
841
0
}
842
843
void SAL_CALL ScConditionEntryObj::addVetoableChangeListener( const OUString&,
844
                            const uno::Reference<beans::XVetoableChangeListener>&)
845
0
{
846
0
    SAL_WARN("sc", "not implemented");
847
0
}
848
849
void SAL_CALL ScConditionEntryObj::removeVetoableChangeListener( const OUString&,
850
                            const uno::Reference<beans::XVetoableChangeListener>&)
851
0
{
852
0
    SAL_WARN("sc", "not implemented");
853
0
}
854
855
ScColorScaleFormatObj::ScColorScaleFormatObj(rtl::Reference<ScCondFormatObj> xParent,
856
        const ScColorScaleFormat* pFormat):
857
0
    mxParent(std::move(xParent)),
858
0
    maPropSet(getColorScalePropSet()),
859
0
    mpFormat(pFormat)
860
0
{
861
0
}
862
863
ScColorScaleFormatObj::~ScColorScaleFormatObj()
864
0
{
865
0
}
866
867
ScColorScaleFormat* ScColorScaleFormatObj::getCoreObject()
868
0
{
869
0
    ScConditionalFormat* pFormat = mxParent->getCoreObject();
870
0
    if (isObjectStillAlive(pFormat, mpFormat))
871
0
        return const_cast<ScColorScaleFormat*>(mpFormat);
872
873
0
    throw lang::IllegalArgumentException();
874
0
}
875
876
sal_Int32 ScColorScaleFormatObj::getType()
877
0
{
878
0
    switch (getCoreObject()->size())
879
0
    {
880
0
        case 2:
881
0
            return sheet::ConditionEntryType::COLORSCALE2;
882
0
        case 3:
883
0
            return sheet::ConditionEntryType::COLORSCALE3;
884
0
        default:
885
0
            return sheet::ConditionEntryType::COLORSCALE;
886
0
    }
887
0
}
888
889
uno::Reference<beans::XPropertySetInfo> SAL_CALL ScColorScaleFormatObj::getPropertySetInfo()
890
0
{
891
0
    static uno::Reference<beans::XPropertySetInfo> aRef(
892
0
        new SfxItemPropertySetInfo( maPropSet.getPropertyMap() ));
893
0
    return aRef;
894
0
}
895
896
namespace {
897
898
void setColorScaleEntry(ScColorScaleEntry* pEntry, uno::Reference<sheet::XColorScaleEntry> const & xEntry)
899
0
{
900
0
    ScColorScaleEntryType eType = ScColorScaleEntryType();
901
0
    sal_Int32 nApiType = xEntry->getType();
902
0
    bool bFound = false;
903
0
    for (ColorScaleEntryTypeApiMap const & rEntry : aColorScaleEntryTypeMap)
904
0
    {
905
0
        if (rEntry.nApiType == nApiType)
906
0
        {
907
0
            eType = rEntry.eType;
908
0
            bFound = true;
909
0
            break;
910
0
        }
911
0
    }
912
913
0
    if (!bFound)
914
0
        throw lang::IllegalArgumentException();
915
916
0
    pEntry->SetType(eType);
917
0
    pEntry->SetColor(Color(ColorTransparency, xEntry->getColor()));
918
0
    switch (eType)
919
0
    {
920
0
        case COLORSCALE_FORMULA:
921
            // TODO: Implement
922
0
        break;
923
0
        default:
924
0
        {
925
0
            double nVal = xEntry->getFormula().toDouble();
926
0
            pEntry->SetValue(nVal);
927
0
        }
928
0
        break;
929
0
    }
930
0
}
931
932
}
933
934
void SAL_CALL ScColorScaleFormatObj::setPropertyValue(
935
                        const OUString& aPropertyName, const uno::Any& aValue )
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
    switch(pEntry->nWID)
945
0
    {
946
0
        case ColorScaleEntries:
947
0
        {
948
0
            uno::Sequence<uno::Reference<sheet::XColorScaleEntry> > aEntries;
949
0
            if (!(aValue >>= aEntries))
950
0
                throw lang::IllegalArgumentException();
951
952
0
            if (aEntries.getLength() < 2)
953
0
                throw lang::IllegalArgumentException();
954
955
            // TODO: we need to make sure that there are enough entries
956
0
            size_t n = size_t(aEntries.getLength());
957
0
            for (size_t i = 0; i < n; ++i)
958
0
            {
959
0
                setColorScaleEntry(getCoreObject()->GetEntry(i), aEntries[i]);
960
0
            }
961
962
0
        }
963
0
        break;
964
0
        default:
965
0
            SAL_WARN("sc", "unknown property");
966
0
    }
967
0
}
968
969
uno::Any SAL_CALL ScColorScaleFormatObj::getPropertyValue( const OUString& aPropertyName )
970
0
{
971
0
    SolarMutexGuard aGuard;
972
973
0
    const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap();     // from derived class
974
0
    const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
975
0
    if ( !pEntry )
976
0
        throw beans::UnknownPropertyException(aPropertyName);
977
978
0
    uno::Any aAny;
979
980
0
    switch(pEntry->nWID)
981
0
    {
982
0
        case ColorScaleEntries:
983
0
        {
984
0
            uno::Sequence<uno::Reference<sheet::XColorScaleEntry> > aEntries(getCoreObject()->size());
985
0
            auto aEntriesRange = asNonConstRange(aEntries);
986
0
            for (size_t i = 0; i < getCoreObject()->size(); ++i)
987
0
            {
988
0
                aEntriesRange[i] = new ScColorScaleEntryObj(this, i);
989
0
            }
990
0
            aAny <<= aEntries;
991
0
        }
992
0
        break;
993
0
        default:
994
0
            SAL_WARN("sc", "unknown property");
995
0
    }
996
997
0
    return aAny;
998
0
}
999
1000
void SAL_CALL ScColorScaleFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
1001
                            const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1002
0
{
1003
0
    SAL_WARN("sc", "not implemented");
1004
0
}
1005
1006
void SAL_CALL ScColorScaleFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
1007
                            const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1008
0
{
1009
0
    SAL_WARN("sc", "not implemented");
1010
0
}
1011
1012
void SAL_CALL ScColorScaleFormatObj::addVetoableChangeListener( const OUString&,
1013
                            const uno::Reference<beans::XVetoableChangeListener>&)
1014
0
{
1015
0
    SAL_WARN("sc", "not implemented");
1016
0
}
1017
1018
void SAL_CALL ScColorScaleFormatObj::removeVetoableChangeListener( const OUString&,
1019
                            const uno::Reference<beans::XVetoableChangeListener>&)
1020
0
{
1021
0
    SAL_WARN("sc", "not implemented");
1022
0
}
1023
1024
ScColorScaleEntryObj::ScColorScaleEntryObj(rtl::Reference<ScColorScaleFormatObj> xParent,
1025
        size_t nPos):
1026
0
    mxParent(std::move(xParent)),
1027
0
    mnPos(nPos)
1028
0
{
1029
0
}
1030
1031
ScColorScaleEntryObj::~ScColorScaleEntryObj()
1032
0
{
1033
0
}
1034
1035
ScColorScaleEntry* ScColorScaleEntryObj::getCoreObject()
1036
0
{
1037
0
    ScColorScaleFormat* pFormat = mxParent->getCoreObject();
1038
0
    if (pFormat->size() <= mnPos)
1039
0
        throw lang::IllegalArgumentException();
1040
1041
0
    return pFormat->GetEntry(mnPos);
1042
0
}
1043
1044
sal_Int32 ScColorScaleEntryObj::getColor()
1045
0
{
1046
0
    Color aColor = getCoreObject()->GetColor();
1047
0
    return sal_Int32(aColor);
1048
0
}
1049
1050
void ScColorScaleEntryObj::setColor(sal_Int32 aColor)
1051
0
{
1052
0
    getCoreObject()->SetColor(Color(ColorTransparency, aColor));
1053
0
}
1054
1055
sal_Int32 ScColorScaleEntryObj::getType()
1056
0
{
1057
0
    ScColorScaleEntry* pEntry = getCoreObject();
1058
0
    for (ColorScaleEntryTypeApiMap const & rEntry : aColorScaleEntryTypeMap)
1059
0
    {
1060
0
        if (rEntry.eType == pEntry->GetType())
1061
0
        {
1062
0
            return rEntry.nApiType;
1063
0
        }
1064
0
    }
1065
1066
0
    throw lang::IllegalArgumentException();
1067
0
}
1068
1069
void ScColorScaleEntryObj::setType(sal_Int32 nType)
1070
0
{
1071
0
    ScColorScaleEntry* pEntry = getCoreObject();
1072
0
    for (ColorScaleEntryTypeApiMap const & rEntry : aColorScaleEntryTypeMap)
1073
0
    {
1074
0
        if (rEntry.nApiType == nType)
1075
0
        {
1076
0
            pEntry->SetType(rEntry.eType);
1077
0
            return;
1078
0
        }
1079
0
    }
1080
0
    throw lang::IllegalArgumentException();
1081
0
}
1082
1083
OUString ScColorScaleEntryObj::getFormula()
1084
0
{
1085
0
    ScColorScaleEntry* pEntry = getCoreObject();
1086
0
    switch (pEntry->GetType())
1087
0
    {
1088
0
        case COLORSCALE_FORMULA:
1089
            // TODO: Implement
1090
0
        break;
1091
0
        default:
1092
0
            return OUString::number(pEntry->GetValue());
1093
0
    }
1094
1095
0
    return OUString();
1096
0
}
1097
1098
void ScColorScaleEntryObj::setFormula(const OUString& rFormula)
1099
0
{
1100
0
    ScColorScaleEntry* pEntry = getCoreObject();
1101
0
    switch (pEntry->GetType())
1102
0
    {
1103
0
        case COLORSCALE_FORMULA:
1104
            // TODO: Implement
1105
            // pEntry->SetFormula(rFormula);
1106
0
        break;
1107
0
        default:
1108
0
            pEntry->SetValue(rFormula.toDouble());
1109
0
        break;
1110
0
    }
1111
0
}
1112
1113
1114
ScDataBarFormatObj::ScDataBarFormatObj(rtl::Reference<ScCondFormatObj> xParent,
1115
        const ScDataBarFormat* pFormat):
1116
0
    mxParent(std::move(xParent)),
1117
0
    maPropSet(getDataBarPropSet()),
1118
0
    mpFormat(pFormat)
1119
0
{
1120
0
}
1121
1122
ScDataBarFormatObj::~ScDataBarFormatObj()
1123
0
{
1124
0
}
1125
1126
ScDataBarFormat* ScDataBarFormatObj::getCoreObject()
1127
0
{
1128
0
    ScConditionalFormat* pFormat = mxParent->getCoreObject();
1129
0
    if (isObjectStillAlive(pFormat, mpFormat))
1130
0
        return const_cast<ScDataBarFormat*>(mpFormat);
1131
1132
0
    throw lang::IllegalArgumentException();
1133
0
}
1134
1135
sal_Int32 ScDataBarFormatObj::getType()
1136
0
{
1137
0
    return sheet::ConditionEntryType::DATABAR;
1138
0
}
1139
1140
uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDataBarFormatObj::getPropertySetInfo()
1141
0
{
1142
0
    SolarMutexGuard aGuard;
1143
0
    static uno::Reference<beans::XPropertySetInfo> aRef(
1144
0
        new SfxItemPropertySetInfo( maPropSet.getPropertyMap() ));
1145
0
    return aRef;
1146
0
}
1147
1148
namespace {
1149
1150
void setDataBarEntry(ScColorScaleEntry* pEntry, uno::Reference<sheet::XDataBarEntry> const & xEntry)
1151
0
{
1152
0
    ScColorScaleEntryType eType = ScColorScaleEntryType();
1153
0
    sal_Int32 nApiType = xEntry->getType();
1154
0
    bool bFound = false;
1155
0
    for (DataBarEntryTypeApiMap const & rEntry : aDataBarEntryTypeMap)
1156
0
    {
1157
0
        if (rEntry.nApiType == nApiType)
1158
0
        {
1159
0
            eType = rEntry.eType;
1160
0
            bFound = true;
1161
0
            break;
1162
0
        }
1163
0
    }
1164
1165
0
    if (!bFound)
1166
0
        throw lang::IllegalArgumentException();
1167
1168
0
    pEntry->SetType(eType);
1169
0
    switch (eType)
1170
0
    {
1171
0
        case COLORSCALE_FORMULA:
1172
            // TODO: Implement
1173
0
        break;
1174
0
        default:
1175
0
        {
1176
0
            double nVal = xEntry->getFormula().toDouble();
1177
0
            pEntry->SetValue(nVal);
1178
0
        }
1179
0
        break;
1180
0
    }
1181
0
}
1182
1183
}
1184
1185
void SAL_CALL ScDataBarFormatObj::setPropertyValue(
1186
                        const OUString& aPropertyName, const uno::Any& aValue )
1187
0
{
1188
0
    SolarMutexGuard aGuard;
1189
1190
0
    const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap();     // from derived class
1191
0
    const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
1192
0
    if ( !pEntry )
1193
0
        throw beans::UnknownPropertyException(aPropertyName);
1194
1195
0
    switch(pEntry->nWID)
1196
0
    {
1197
0
        case AxisPosition:
1198
0
        {
1199
0
            sal_Int32 nVal;
1200
0
            if (aValue >>= nVal)
1201
0
            {
1202
0
                for (DataBarAxisApiMap const & rEntry : aDataBarAxisMap)
1203
0
                {
1204
0
                    if (rEntry.nApiPos == nVal)
1205
0
                    {
1206
0
                        getCoreObject()->GetDataBarData()->meAxisPosition =
1207
0
                            rEntry.ePos;
1208
0
                        break;
1209
0
                    }
1210
0
                }
1211
0
            }
1212
0
        }
1213
0
        break;
1214
0
        case UseGradient:
1215
0
        {
1216
0
            bool bUseGradient = true;
1217
0
            if (aValue >>= bUseGradient)
1218
0
            {
1219
0
                getCoreObject()->GetDataBarData()->mbGradient = bUseGradient;
1220
0
            }
1221
0
        }
1222
0
        break;
1223
0
        case UseNegativeColor:
1224
0
        {
1225
0
            bool bUseNegativeColor = false;
1226
0
            if (aValue >>= bUseNegativeColor)
1227
0
            {
1228
0
                getCoreObject()->GetDataBarData()->mbNeg = bUseNegativeColor;
1229
0
                if (bUseNegativeColor && !getCoreObject()->GetDataBarData()->mxNegativeColor)
1230
0
                {
1231
0
                    getCoreObject()->GetDataBarData()->mxNegativeColor = COL_AUTO;
1232
0
                }
1233
0
            }
1234
0
        }
1235
0
        break;
1236
0
        case DataBar_ShowValue:
1237
0
        {
1238
0
            bool bShowValue = true;
1239
0
            if (aValue >>= bShowValue)
1240
0
            {
1241
0
                getCoreObject()->GetDataBarData()->mbOnlyBar = !bShowValue;
1242
0
            }
1243
0
        }
1244
0
        break;
1245
0
        case DataBar_Color:
1246
0
        {
1247
0
            Color nColor = COL_AUTO;
1248
0
            if (aValue >>= nColor)
1249
0
            {
1250
0
                getCoreObject()->GetDataBarData()->maPositiveColor = nColor;
1251
0
            }
1252
0
        }
1253
0
        break;
1254
0
        case AxisColor:
1255
0
        {
1256
0
            Color nAxisColor = COL_AUTO;
1257
0
            if (aValue >>= nAxisColor)
1258
0
            {
1259
0
                getCoreObject()->GetDataBarData()->maAxisColor = nAxisColor;
1260
0
            }
1261
0
        }
1262
0
        break;
1263
0
        case NegativeColor:
1264
0
        {
1265
0
            Color nNegativeColor = COL_AUTO;
1266
0
            if (!(aValue >>= nNegativeColor) || !getCoreObject()->GetDataBarData()->mbNeg)
1267
0
                throw lang::IllegalArgumentException();
1268
1269
0
            getCoreObject()->GetDataBarData()->mxNegativeColor = nNegativeColor;
1270
1271
0
        }
1272
0
        break;
1273
0
        case DataBarEntries:
1274
0
        {
1275
0
            uno::Sequence<uno::Reference<sheet::XDataBarEntry> > aEntries;
1276
0
            if (!(aValue >>= aEntries))
1277
0
                throw lang::IllegalArgumentException();
1278
1279
0
            if (aEntries.getLength() != 2)
1280
0
                throw lang::IllegalArgumentException();
1281
1282
0
            setDataBarEntry(getCoreObject()->GetDataBarData()->mpLowerLimit.get(),
1283
0
                    aEntries[0]);
1284
0
            setDataBarEntry(getCoreObject()->GetDataBarData()->mpUpperLimit.get(),
1285
0
                    aEntries[1]);
1286
1287
0
        }
1288
0
        break;
1289
0
        case MinimumLength:
1290
0
        {
1291
0
            double nLength = 0;
1292
0
            if (!(aValue >>= nLength) || nLength >= 100 || nLength < 0)
1293
0
                throw lang::IllegalArgumentException();
1294
0
            getCoreObject()->GetDataBarData()->mnMinLength = nLength;
1295
1296
0
        }
1297
0
        break;
1298
0
        case MaximumLength:
1299
0
        {
1300
0
            double nLength = 0;
1301
0
            if (!(aValue >>= nLength) || nLength > 100 || nLength <= 0)
1302
0
                throw lang::IllegalArgumentException();
1303
0
            getCoreObject()->GetDataBarData()->mnMaxLength = nLength;
1304
1305
0
        }
1306
0
        break;
1307
0
    }
1308
0
}
1309
1310
uno::Any SAL_CALL ScDataBarFormatObj::getPropertyValue( const OUString& aPropertyName )
1311
0
{
1312
0
    SolarMutexGuard aGuard;
1313
1314
0
    const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap();     // from derived class
1315
0
    const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
1316
0
    if ( !pEntry )
1317
0
        throw beans::UnknownPropertyException(aPropertyName);
1318
1319
0
    uno::Any aAny;
1320
0
    switch(pEntry->nWID)
1321
0
    {
1322
0
        case AxisPosition:
1323
0
        {
1324
0
            databar::ScAxisPosition ePos = getCoreObject()->GetDataBarData()->meAxisPosition;
1325
0
            sal_Int32 nApiPos = sheet::DataBarAxis::AXIS_NONE;
1326
0
            for (DataBarAxisApiMap const & rEntry : aDataBarAxisMap)
1327
0
            {
1328
0
                if (rEntry.ePos == ePos)
1329
0
                {
1330
0
                    nApiPos = rEntry.nApiPos;
1331
0
                }
1332
0
            }
1333
1334
0
            aAny <<= nApiPos;
1335
0
        }
1336
0
        break;
1337
0
        case UseGradient:
1338
0
        {
1339
0
           aAny <<= getCoreObject()->GetDataBarData()->mbGradient;
1340
0
        }
1341
0
        break;
1342
0
        case UseNegativeColor:
1343
0
        {
1344
0
           aAny <<= getCoreObject()->GetDataBarData()->mbNeg;
1345
0
        }
1346
0
        break;
1347
0
        case DataBar_ShowValue:
1348
0
        {
1349
0
            aAny <<= !getCoreObject()->GetDataBarData()->mbOnlyBar;
1350
0
        }
1351
0
        break;
1352
0
        case DataBar_Color:
1353
0
        {
1354
0
            aAny <<= getCoreObject()->GetDataBarData()->maPositiveColor;
1355
0
        }
1356
0
        break;
1357
0
        case AxisColor:
1358
0
        {
1359
0
            aAny <<= getCoreObject()->GetDataBarData()->maAxisColor;
1360
0
        }
1361
0
        break;
1362
0
        case NegativeColor:
1363
0
        {
1364
0
            if (getCoreObject()->GetDataBarData()->mbNeg && getCoreObject()->GetDataBarData()->mxNegativeColor)
1365
0
            {
1366
0
                aAny <<= *getCoreObject()->GetDataBarData()->mxNegativeColor;
1367
0
            }
1368
0
        }
1369
0
        break;
1370
0
        case DataBarEntries:
1371
0
        {
1372
0
            uno::Sequence<uno::Reference<sheet::XDataBarEntry> > aEntries
1373
0
            {
1374
0
                new ScDataBarEntryObj(this, 0),
1375
0
                new ScDataBarEntryObj(this, 1)
1376
0
            };
1377
0
            aAny <<= aEntries;
1378
0
        }
1379
0
        break;
1380
0
    }
1381
0
    return aAny;
1382
0
}
1383
1384
void SAL_CALL ScDataBarFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
1385
                            const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1386
0
{
1387
0
    SAL_WARN("sc", "not implemented");
1388
0
}
1389
1390
void SAL_CALL ScDataBarFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
1391
                            const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1392
0
{
1393
0
    SAL_WARN("sc", "not implemented");
1394
0
}
1395
1396
void SAL_CALL ScDataBarFormatObj::addVetoableChangeListener( const OUString&,
1397
                            const uno::Reference<beans::XVetoableChangeListener>&)
1398
0
{
1399
0
    SAL_WARN("sc", "not implemented");
1400
0
}
1401
1402
void SAL_CALL ScDataBarFormatObj::removeVetoableChangeListener( const OUString&,
1403
                            const uno::Reference<beans::XVetoableChangeListener>&)
1404
0
{
1405
0
    SAL_WARN("sc", "not implemented");
1406
0
}
1407
1408
ScDataBarEntryObj::ScDataBarEntryObj(rtl::Reference<ScDataBarFormatObj> xParent,
1409
        size_t nPos):
1410
0
    mxParent(std::move(xParent)),
1411
0
    mnPos(nPos)
1412
0
{
1413
0
}
1414
1415
ScDataBarEntryObj::~ScDataBarEntryObj()
1416
0
{
1417
0
}
1418
1419
ScColorScaleEntry* ScDataBarEntryObj::getCoreObject()
1420
0
{
1421
0
    ScDataBarFormat* pFormat = mxParent->getCoreObject();
1422
0
    ScColorScaleEntry* pEntry;
1423
0
    if (mnPos == 0)
1424
0
        pEntry = pFormat->GetDataBarData()->mpLowerLimit.get();
1425
0
    else
1426
0
        pEntry = pFormat->GetDataBarData()->mpUpperLimit.get();
1427
1428
0
    return pEntry;
1429
0
}
1430
1431
sal_Int32 ScDataBarEntryObj::getType()
1432
0
{
1433
0
    ScColorScaleEntry* pEntry = getCoreObject();
1434
0
    for (DataBarEntryTypeApiMap const & rEntry : aDataBarEntryTypeMap)
1435
0
    {
1436
0
        if (rEntry.eType == pEntry->GetType())
1437
0
        {
1438
0
            return rEntry.nApiType;
1439
0
        }
1440
0
    }
1441
1442
0
    throw lang::IllegalArgumentException();
1443
0
}
1444
1445
void ScDataBarEntryObj::setType(sal_Int32 nType)
1446
0
{
1447
0
    ScColorScaleEntry* pEntry = getCoreObject();
1448
0
    for (DataBarEntryTypeApiMap const & rEntry : aDataBarEntryTypeMap)
1449
0
    {
1450
0
        if (rEntry.nApiType == nType)
1451
0
        {
1452
0
            pEntry->SetType(rEntry.eType);
1453
0
            return;
1454
0
        }
1455
0
    }
1456
0
    throw lang::IllegalArgumentException();
1457
0
}
1458
1459
OUString ScDataBarEntryObj::getFormula()
1460
0
{
1461
0
    ScColorScaleEntry* pEntry = getCoreObject();
1462
0
    switch (pEntry->GetType())
1463
0
    {
1464
0
        case COLORSCALE_FORMULA:
1465
            // TODO: Implement
1466
0
        break;
1467
0
        default:
1468
0
            return OUString::number(pEntry->GetValue());
1469
0
    }
1470
1471
0
    return OUString();
1472
0
}
1473
1474
void ScDataBarEntryObj::setFormula(const OUString& rFormula)
1475
0
{
1476
0
    ScColorScaleEntry* pEntry = getCoreObject();
1477
0
    switch (pEntry->GetType())
1478
0
    {
1479
0
        case COLORSCALE_FORMULA:
1480
            // TODO: Implement
1481
            // pEntry->SetFormula(rFormula);
1482
0
        break;
1483
0
        default:
1484
0
            pEntry->SetValue(rFormula.toDouble());
1485
0
        break;
1486
0
    }
1487
0
}
1488
1489
1490
ScIconSetFormatObj::ScIconSetFormatObj(rtl::Reference<ScCondFormatObj> xParent,
1491
        const ScIconSetFormat* pFormat):
1492
0
    mxParent(std::move(xParent)),
1493
0
    maPropSet(getIconSetPropSet()),
1494
0
    mpFormat(pFormat)
1495
0
{
1496
0
}
1497
1498
ScIconSetFormatObj::~ScIconSetFormatObj()
1499
0
{
1500
0
}
1501
1502
ScIconSetFormat* ScIconSetFormatObj::getCoreObject()
1503
0
{
1504
0
    ScConditionalFormat* pFormat = mxParent->getCoreObject();
1505
0
    if (isObjectStillAlive(pFormat, mpFormat))
1506
0
        return const_cast<ScIconSetFormat*>(mpFormat);
1507
1508
0
    throw lang::IllegalArgumentException();
1509
0
}
1510
1511
sal_Int32 ScIconSetFormatObj::getType()
1512
0
{
1513
0
    return sheet::ConditionEntryType::ICONSET;
1514
0
}
1515
1516
uno::Reference<beans::XPropertySetInfo> SAL_CALL ScIconSetFormatObj::getPropertySetInfo()
1517
0
{
1518
0
    SolarMutexGuard aGuard;
1519
0
    static uno::Reference<beans::XPropertySetInfo> aRef(
1520
0
        new SfxItemPropertySetInfo( maPropSet.getPropertyMap() ));
1521
0
    return aRef;
1522
0
}
1523
1524
namespace {
1525
1526
void setIconSetEntry(ScIconSetFormat* pFormat, uno::Reference<sheet::XIconSetEntry> const & xEntry, size_t nPos)
1527
0
{
1528
0
    ScIconSetFormatData* pData = pFormat->GetIconSetData();
1529
0
    ScColorScaleEntryType eType = ScColorScaleEntryType();
1530
0
    sal_Int32 nApiType = xEntry->getType();
1531
0
    bool bFound = false;
1532
0
    for (IconSetEntryTypeApiMap const & rEntry : aIconSetEntryTypeMap)
1533
0
    {
1534
0
        if (rEntry.nApiType == nApiType)
1535
0
        {
1536
0
            eType = rEntry.eType;
1537
0
            bFound = true;
1538
0
            break;
1539
0
        }
1540
0
    }
1541
1542
0
    if (!bFound)
1543
0
        throw lang::IllegalArgumentException();
1544
1545
0
    pData->m_Entries[nPos]->SetType(eType);
1546
0
    switch (eType)
1547
0
    {
1548
0
        case COLORSCALE_FORMULA:
1549
            // TODO: Implement
1550
0
        break;
1551
0
        default:
1552
0
        {
1553
0
            double nVal = xEntry->getFormula().toDouble();
1554
0
            pData->m_Entries[nPos]->SetValue(nVal);
1555
0
        }
1556
0
        break;
1557
0
    }
1558
0
}
1559
1560
}
1561
1562
void SAL_CALL ScIconSetFormatObj::setPropertyValue(
1563
                        const OUString& aPropertyName, const uno::Any& aValue )
1564
0
{
1565
0
    SolarMutexGuard aGuard;
1566
1567
0
    const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap();     // from derived class
1568
0
    const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
1569
0
    if ( !pEntry )
1570
0
        throw beans::UnknownPropertyException(aPropertyName);
1571
1572
0
    switch(pEntry->nWID)
1573
0
    {
1574
0
        case ShowValue:
1575
0
        {
1576
0
            bool bShowValue = true;
1577
0
            aValue >>= bShowValue;
1578
0
            getCoreObject()->GetIconSetData()->mbShowValue = bShowValue;
1579
0
        }
1580
0
        break;
1581
0
        case Reverse:
1582
0
        {
1583
0
            bool bReverse = false;
1584
0
            aValue >>= bReverse;
1585
0
            getCoreObject()->GetIconSetData()->mbReverse = bReverse;
1586
0
        }
1587
0
        break;
1588
0
        case Icons:
1589
0
        {
1590
0
            sal_Int32 nApiType = -1;
1591
0
            aValue >>= nApiType;
1592
0
            ScIconSetType eType = IconSet_3Arrows;
1593
0
            bool bFound = false;
1594
0
            for (const IconSetTypeApiMap & rEntry : aIconSetApiMap)
1595
0
            {
1596
0
                if (rEntry.nApiType == nApiType)
1597
0
                {
1598
0
                    eType = rEntry.eType;
1599
0
                    bFound = true;
1600
0
                    break;
1601
0
                }
1602
0
            }
1603
1604
0
            if (!bFound)
1605
0
            {
1606
0
                throw lang::IllegalArgumentException();
1607
0
            }
1608
1609
            // TODO: we need to make sure that there are enough entries
1610
0
            getCoreObject()->GetIconSetData()->eIconSetType = eType;
1611
0
        }
1612
0
        break;
1613
0
        case IconSetEntries:
1614
0
        {
1615
0
            uno::Sequence<uno::Reference<sheet::XIconSetEntry> > aEntries;
1616
0
            if (!(aValue >>= aEntries))
1617
0
                throw lang::IllegalArgumentException();
1618
1619
            // TODO: we need to check that the number of entries
1620
            // corresponds to the icon type
1621
0
            sal_Int32 nLength = aEntries.getLength();
1622
0
            for (size_t i = 0; i < o3tl::make_unsigned(nLength); ++i)
1623
0
            {
1624
0
                setIconSetEntry(getCoreObject(), aEntries[i], i);
1625
0
            }
1626
1627
0
        }
1628
0
        break;
1629
0
        default:
1630
0
        break;
1631
0
    }
1632
0
}
1633
1634
uno::Any SAL_CALL ScIconSetFormatObj::getPropertyValue( const OUString& aPropertyName )
1635
0
{
1636
0
    SolarMutexGuard aGuard;
1637
1638
0
    const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap();     // from derived class
1639
0
    const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
1640
0
    if ( !pEntry )
1641
0
        throw beans::UnknownPropertyException(aPropertyName);
1642
1643
0
    uno::Any aAny;
1644
1645
0
    switch(pEntry->nWID)
1646
0
    {
1647
0
        case ShowValue:
1648
0
            aAny <<= getCoreObject()->GetIconSetData()->mbShowValue;
1649
0
        break;
1650
0
        case Reverse:
1651
0
            aAny <<= getCoreObject()->GetIconSetData()->mbReverse;
1652
0
        break;
1653
0
        case Icons:
1654
0
        {
1655
0
            ScIconSetType eType = getCoreObject()->GetIconSetData()->eIconSetType;
1656
0
            for (const IconSetTypeApiMap & rEntry : aIconSetApiMap)
1657
0
            {
1658
0
                if (rEntry.eType == eType)
1659
0
                {
1660
0
                    aAny <<= rEntry.nApiType;
1661
0
                    break;
1662
0
                }
1663
0
            }
1664
0
        }
1665
0
        break;
1666
0
        case IconSetEntries:
1667
0
        {
1668
0
            size_t nSize = getCoreObject()->size();
1669
0
            uno::Sequence<uno::Reference<sheet::XIconSetEntry> > aEntries(nSize);
1670
0
            auto aEntriesRange = asNonConstRange(aEntries);
1671
0
            for (size_t i = 0; i < nSize; ++i)
1672
0
            {
1673
0
                aEntriesRange[i] = new ScIconSetEntryObj(this, i);
1674
0
            }
1675
0
            aAny <<= aEntries;
1676
0
        }
1677
0
        break;
1678
0
        default:
1679
0
            SAL_WARN("sc", "unknown property");
1680
0
    }
1681
0
    return aAny;
1682
0
}
1683
1684
void SAL_CALL ScIconSetFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
1685
                            const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1686
0
{
1687
0
    SAL_WARN("sc", "not implemented");
1688
0
}
1689
1690
void SAL_CALL ScIconSetFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
1691
                            const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1692
0
{
1693
0
    SAL_WARN("sc", "not implemented");
1694
0
}
1695
1696
void SAL_CALL ScIconSetFormatObj::addVetoableChangeListener( const OUString&,
1697
                            const uno::Reference<beans::XVetoableChangeListener>&)
1698
0
{
1699
0
    SAL_WARN("sc", "not implemented");
1700
0
}
1701
1702
void SAL_CALL ScIconSetFormatObj::removeVetoableChangeListener( const OUString&,
1703
                            const uno::Reference<beans::XVetoableChangeListener>&)
1704
0
{
1705
0
    SAL_WARN("sc", "not implemented");
1706
0
}
1707
1708
ScIconSetEntryObj::ScIconSetEntryObj(rtl::Reference<ScIconSetFormatObj> xParent,
1709
        size_t nPos):
1710
0
    mxParent(std::move(xParent)),
1711
0
    mnPos(nPos)
1712
0
{
1713
0
}
1714
1715
ScIconSetEntryObj::~ScIconSetEntryObj()
1716
0
{
1717
0
}
1718
1719
ScColorScaleEntry* ScIconSetEntryObj::getCoreObject()
1720
0
{
1721
0
    ScIconSetFormat* pFormat = mxParent->getCoreObject();
1722
0
    if (pFormat->GetIconSetData()->m_Entries.size() <= mnPos)
1723
0
        throw lang::IllegalArgumentException();
1724
1725
0
    return pFormat->GetIconSetData()->m_Entries[mnPos].get();
1726
0
}
1727
1728
sal_Int32 ScIconSetEntryObj::getType()
1729
0
{
1730
0
    ScColorScaleEntry* pEntry = getCoreObject();
1731
    // the first entry always is minimum
1732
0
    if (mnPos == 0)
1733
0
        return sheet::IconSetFormatEntry::ICONSET_MIN;
1734
1735
0
    for (IconSetEntryTypeApiMap const & rEntry : aIconSetEntryTypeMap)
1736
0
    {
1737
0
        if (rEntry.eType == pEntry->GetType())
1738
0
        {
1739
0
            return rEntry.nApiType;
1740
0
        }
1741
0
    }
1742
1743
0
    throw lang::IllegalArgumentException();
1744
0
}
1745
1746
void ScIconSetEntryObj::setType(sal_Int32 nType)
1747
0
{
1748
    // first entry is always MIN
1749
0
    if (mnPos == 0)
1750
0
        return;
1751
1752
0
    ScColorScaleEntry* pEntry = getCoreObject();
1753
0
    for (IconSetEntryTypeApiMap const & rEntry : aIconSetEntryTypeMap)
1754
0
    {
1755
0
        if (rEntry.nApiType == nType)
1756
0
        {
1757
0
            pEntry->SetType(rEntry.eType);
1758
0
            return;
1759
0
        }
1760
0
    }
1761
0
    throw lang::IllegalArgumentException();
1762
0
}
1763
1764
OUString ScIconSetEntryObj::getFormula()
1765
0
{
1766
0
    ScColorScaleEntry* pEntry = getCoreObject();
1767
0
    switch (pEntry->GetType())
1768
0
    {
1769
0
        case COLORSCALE_FORMULA:
1770
            // TODO: Implement
1771
0
        break;
1772
0
        default:
1773
0
            return OUString::number(pEntry->GetValue());
1774
0
    }
1775
1776
0
    return OUString();
1777
0
}
1778
1779
void ScIconSetEntryObj::setFormula(const OUString& rFormula)
1780
0
{
1781
0
    ScColorScaleEntry* pEntry = getCoreObject();
1782
0
    switch (pEntry->GetType())
1783
0
    {
1784
0
        case COLORSCALE_FORMULA:
1785
            // TODO: Implement
1786
            // pEntry->SetFormula(rFormula);
1787
0
        break;
1788
0
        default:
1789
0
            pEntry->SetValue(rFormula.toDouble());
1790
0
        break;
1791
0
    }
1792
0
}
1793
1794
ScCondDateFormatObj::ScCondDateFormatObj(rtl::Reference<ScCondFormatObj> xParent,
1795
        const ScCondDateFormatEntry* pFormat):
1796
0
    mxParent(std::move(xParent)),
1797
0
    maPropSet(getCondDatePropSet()),
1798
0
    mpFormat(pFormat)
1799
0
{
1800
0
}
1801
1802
ScCondDateFormatObj::~ScCondDateFormatObj()
1803
0
{
1804
0
}
1805
1806
ScCondDateFormatEntry* ScCondDateFormatObj::getCoreObject()
1807
0
{
1808
0
    ScConditionalFormat* pFormat = mxParent->getCoreObject();
1809
0
    if (isObjectStillAlive(pFormat, mpFormat))
1810
0
        return const_cast<ScCondDateFormatEntry*>(mpFormat);
1811
1812
0
    throw lang::IllegalArgumentException();
1813
0
}
1814
1815
sal_Int32 ScCondDateFormatObj::getType()
1816
0
{
1817
0
    return sheet::ConditionEntryType::DATE;
1818
0
}
1819
1820
uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCondDateFormatObj::getPropertySetInfo()
1821
0
{
1822
0
    SolarMutexGuard aGuard;
1823
0
    static uno::Reference<beans::XPropertySetInfo> aRef(
1824
0
        new SfxItemPropertySetInfo( maPropSet.getPropertyMap() ));
1825
0
    return aRef;
1826
0
}
1827
1828
void SAL_CALL ScCondDateFormatObj::setPropertyValue(
1829
                        const OUString& aPropertyName, const uno::Any& aValue )
1830
0
{
1831
0
    SolarMutexGuard aGuard;
1832
1833
0
    const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap();     // from derived class
1834
0
    const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
1835
0
    if ( !pEntry )
1836
0
        throw beans::UnknownPropertyException(aPropertyName);
1837
1838
0
    switch(pEntry->nWID)
1839
0
    {
1840
0
        case Date_StyleName:
1841
0
        {
1842
0
            OUString aStyleName;
1843
0
            if (!(aValue >>= aStyleName))
1844
0
                throw lang::IllegalArgumentException();
1845
1846
0
            getCoreObject()->SetStyleName(aStyleName);
1847
1848
0
        }
1849
0
        break;
1850
0
        case DateType:
1851
0
        {
1852
0
            sal_Int32 nApiType = -1;
1853
0
            if (!(aValue >>= nApiType))
1854
0
                throw lang::IllegalArgumentException();
1855
1856
0
            for (DateTypeApiMap const & rEntry : aDateTypeApiMap)
1857
0
            {
1858
0
                if (rEntry.nApiType == nApiType)
1859
0
                {
1860
0
                    getCoreObject()->SetDateType(rEntry.eType);
1861
0
                    break;
1862
0
                }
1863
0
            }
1864
0
        }
1865
0
        break;
1866
0
        default:
1867
0
        break;
1868
0
    }
1869
0
}
1870
1871
uno::Any SAL_CALL ScCondDateFormatObj::getPropertyValue( const OUString& aPropertyName )
1872
0
{
1873
0
    SolarMutexGuard aGuard;
1874
1875
0
    const SfxItemPropertyMap& rPropertyMap = maPropSet.getPropertyMap();     // from derived class
1876
0
    const SfxItemPropertyMapEntry* pEntry = rPropertyMap.getByName( aPropertyName );
1877
0
    if ( !pEntry )
1878
0
        throw beans::UnknownPropertyException(aPropertyName);
1879
1880
0
    uno::Any aAny;
1881
1882
0
    switch(pEntry->nWID)
1883
0
    {
1884
0
        case Date_StyleName:
1885
0
        {
1886
0
            OUString aStyleName = getCoreObject()->GetStyleName();
1887
0
            aAny <<= aStyleName;
1888
0
        }
1889
0
        break;
1890
0
        case DateType:
1891
0
        {
1892
0
            condformat::ScCondFormatDateType eType = getCoreObject()->GetDateType();
1893
0
            for (DateTypeApiMap const & rEntry : aDateTypeApiMap)
1894
0
            {
1895
0
                if (rEntry.eType == eType)
1896
0
                {
1897
0
                    aAny <<= rEntry.nApiType;
1898
0
                    break;
1899
0
                }
1900
0
            }
1901
0
        }
1902
0
        break;
1903
0
        default:
1904
0
            SAL_WARN("sc", "unknown property");
1905
0
    }
1906
0
    return aAny;
1907
0
}
1908
1909
void SAL_CALL ScCondDateFormatObj::addPropertyChangeListener( const OUString& /* aPropertyName */,
1910
                            const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1911
0
{
1912
0
    SAL_WARN("sc", "not implemented");
1913
0
}
1914
1915
void SAL_CALL ScCondDateFormatObj::removePropertyChangeListener( const OUString& /* aPropertyName */,
1916
                            const uno::Reference<beans::XPropertyChangeListener>& /* aListener */)
1917
0
{
1918
0
    SAL_WARN("sc", "not implemented");
1919
0
}
1920
1921
void SAL_CALL ScCondDateFormatObj::addVetoableChangeListener( const OUString&,
1922
                            const uno::Reference<beans::XVetoableChangeListener>&)
1923
0
{
1924
0
    SAL_WARN("sc", "not implemented");
1925
0
}
1926
1927
void SAL_CALL ScCondDateFormatObj::removeVetoableChangeListener( const OUString&,
1928
                            const uno::Reference<beans::XVetoableChangeListener>&)
1929
0
{
1930
0
    SAL_WARN("sc", "not implemented");
1931
0
}
1932
1933
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */