Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/sidebar/Theme.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <sfx2/sidebar/Theme.hxx>
21
#include <sfx2/app.hxx>
22
#include <tools/color.hxx>
23
24
#include <vcl/svapp.hxx>
25
#include <vcl/settings.hxx>
26
#include <comphelper/diagnose_ex.hxx>
27
28
using namespace css;
29
using namespace css::uno;
30
31
namespace sfx2::sidebar {
32
33
Theme& Theme::GetCurrentTheme()
34
0
{
35
0
    OSL_ASSERT(SfxGetpApp());
36
0
    return SfxGetpApp()->GetSidebarTheme();
37
0
}
38
39
Theme::Theme()
40
0
    : mbIsHighContrastMode(Application::GetSettings().GetStyleSettings().GetHighContrastMode()),
41
0
      mbIsHighContrastModeSetManually(false)
42
0
{
43
0
    SetupPropertyMaps();
44
0
}
Unexecuted instantiation: sfx2::sidebar::Theme::Theme()
Unexecuted instantiation: sfx2::sidebar::Theme::Theme()
45
46
Theme::~Theme()
47
0
{
48
0
}
49
50
Color Theme::GetColor (const ThemeItem eItem)
51
0
{
52
0
    const PropertyType eType (GetPropertyType(eItem));
53
0
    OSL_ASSERT(eType==PT_Color);
54
0
    const sal_Int32 nIndex (GetIndex(eItem, eType));
55
0
    const Theme& rTheme (GetCurrentTheme());
56
0
    if (eType == PT_Color)
57
0
        return rTheme.maColors[nIndex];
58
0
    else
59
0
        return COL_WHITE;
60
0
}
61
62
sal_Int32 Theme::GetInteger (const ThemeItem eItem)
63
0
{
64
0
    const PropertyType eType (GetPropertyType(eItem));
65
0
    OSL_ASSERT(eType==PT_Integer);
66
0
    const sal_Int32 nIndex (GetIndex(eItem, eType));
67
0
    const Theme& rTheme (GetCurrentTheme());
68
0
    return rTheme.maIntegers[nIndex];
69
0
}
70
71
bool Theme::IsHighContrastMode()
72
0
{
73
0
    const Theme& rTheme (GetCurrentTheme());
74
0
    return rTheme.mbIsHighContrastMode;
75
0
}
76
77
void Theme::HandleDataChange()
78
0
{
79
0
    Theme& rTheme (GetCurrentTheme());
80
81
0
    if ( ! rTheme.mbIsHighContrastModeSetManually)
82
0
    {
83
        // Do not modify mbIsHighContrastMode when it was manually set.
84
0
        GetCurrentTheme().mbIsHighContrastMode = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
85
0
        rTheme.maRawValues[Bool_IsHighContrastModeActive] <<= GetCurrentTheme().mbIsHighContrastMode;
86
0
    }
87
88
0
    GetCurrentTheme().UpdateTheme();
89
0
}
90
91
void Theme::InitializeTheme()
92
0
{
93
0
    setPropertyValue(
94
0
        maPropertyIdToNameMap[Bool_UseSystemColors],
95
0
        Any(false));
96
0
}
97
98
void Theme::UpdateTheme()
99
0
{
100
0
    try
101
0
    {
102
0
        const StyleSettings& rStyle (Application::GetSettings().GetStyleSettings());
103
104
0
        Color aBaseBackgroundColor (rStyle.GetDialogColor());
105
        // UX says this should be a little brighter, but that looks off when compared to the other windows.
106
        //aBaseBackgroundColor.IncreaseLuminance(7);
107
0
        Color aSecondColor (aBaseBackgroundColor);
108
0
        aSecondColor.DecreaseLuminance(15);
109
110
0
        setPropertyValue(
111
0
            maPropertyIdToNameMap[Color_DeckBackground],
112
0
            Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
113
114
0
        setPropertyValue(
115
0
            maPropertyIdToNameMap[Color_DeckTitleBarBackground],
116
0
            Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
117
0
        setPropertyValue(
118
0
            maPropertyIdToNameMap[Int_DeckSeparatorHeight],
119
0
            Any(sal_Int32(1)));
120
0
        setPropertyValue(
121
0
            maPropertyIdToNameMap[Color_PanelBackground],
122
0
            Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
123
124
0
        setPropertyValue(
125
0
            maPropertyIdToNameMap[Color_PanelTitleBarBackground],
126
0
            Any(sal_Int32(aSecondColor.GetRGBColor())));
127
0
        setPropertyValue(
128
0
            maPropertyIdToNameMap[Color_TabBarBackground],
129
0
            Any(sal_Int32(aBaseBackgroundColor.GetRGBColor())));
130
131
0
        setPropertyValue(
132
0
            maPropertyIdToNameMap[Color_Highlight],
133
0
            Any(sal_Int32(rStyle.GetHighlightColor().GetRGBColor())));
134
0
        setPropertyValue(
135
0
            maPropertyIdToNameMap[Color_HighlightText],
136
0
            Any(sal_Int32(rStyle.GetHighlightTextColor().GetRGBColor())));
137
0
    }
138
0
    catch(beans::UnknownPropertyException const &)
139
0
    {
140
0
        DBG_UNHANDLED_EXCEPTION("sfx", "unknown property");
141
0
        OSL_ASSERT(false);
142
0
    }
143
0
}
144
145
void Theme::disposing(std::unique_lock<std::mutex>&)
146
0
{
147
0
    SolarMutexGuard aGuard;
148
149
0
    ChangeListeners aListeners;
150
0
    aListeners.swap(maChangeListeners);
151
152
0
    const lang::EventObject aEvent (getXWeak());
153
154
0
    for (const auto& rContainer : aListeners)
155
0
    {
156
0
        for (const auto& rxListener : rContainer.second)
157
0
        {
158
0
            try
159
0
            {
160
0
                rxListener->disposing(aEvent);
161
0
            }
162
0
            catch(const Exception&)
163
0
            {
164
0
            }
165
0
        }
166
0
    }
167
0
}
168
169
Reference<beans::XPropertySet> Theme::GetPropertySet()
170
0
{
171
0
    if (SfxGetpApp())
172
0
        return Reference<beans::XPropertySet>(&GetCurrentTheme());
173
0
    else
174
0
        return Reference<beans::XPropertySet>();
175
0
}
176
177
Reference<beans::XPropertySetInfo> SAL_CALL Theme::getPropertySetInfo()
178
0
{
179
0
    return Reference<beans::XPropertySetInfo>(this);
180
0
}
181
182
void SAL_CALL Theme::setPropertyValue (
183
    const OUString& rsPropertyName,
184
    const css::uno::Any& rValue)
185
0
{
186
0
    SolarMutexGuard aGuard;
187
188
0
    PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
189
0
    if (iId == maPropertyNameToIdMap.end())
190
0
        throw beans::UnknownPropertyException(rsPropertyName);
191
192
0
    const PropertyType eType (GetPropertyType(iId->second));
193
0
    if (eType == PT_Invalid)
194
0
        throw beans::UnknownPropertyException(rsPropertyName);
195
196
0
    const ThemeItem eItem (iId->second);
197
198
0
    if (rValue == maRawValues[eItem])
199
0
    {
200
        // Value is not different from the one in the property
201
        // set => nothing to do.
202
0
        return;
203
0
    }
204
205
0
    const Any aOldValue (maRawValues[eItem]);
206
207
0
    const beans::PropertyChangeEvent aEvent(
208
0
        getXWeak(),
209
0
        rsPropertyName,
210
0
        false,
211
0
        eItem,
212
0
        aOldValue,
213
0
        rValue);
214
215
0
    if (DoVetoableListenersVeto(GetVetoableListeners(AnyItem_, false), aEvent))
216
0
        return;
217
0
    if (DoVetoableListenersVeto(GetVetoableListeners(eItem, false), aEvent))
218
0
        return;
219
220
0
    maRawValues[eItem] = rValue;
221
0
    ProcessNewValue(rValue, eItem, eType);
222
223
0
    BroadcastPropertyChange(GetChangeListeners(AnyItem_, false), aEvent);
224
0
    BroadcastPropertyChange(GetChangeListeners(eItem, false), aEvent);
225
0
}
226
227
Any SAL_CALL Theme::getPropertyValue (
228
    const OUString& rsPropertyName)
229
0
{
230
0
    SolarMutexGuard aGuard;
231
232
0
    PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
233
0
    if (iId == maPropertyNameToIdMap.end())
234
0
        throw beans::UnknownPropertyException(rsPropertyName);
235
236
0
    const PropertyType eType (GetPropertyType(iId->second));
237
0
    if (eType == PT_Invalid)
238
0
        throw beans::UnknownPropertyException(rsPropertyName);
239
240
0
    const ThemeItem eItem (iId->second);
241
242
0
    return maRawValues[eItem];
243
0
}
244
245
void SAL_CALL Theme::addPropertyChangeListener(
246
    const OUString& rsPropertyName,
247
    const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
248
0
{
249
0
    SolarMutexGuard aGuard;
250
251
0
    ThemeItem eItem (AnyItem_);
252
0
    if (rsPropertyName.getLength() > 0)
253
0
    {
254
0
        PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
255
0
        if (iId == maPropertyNameToIdMap.end())
256
0
            throw beans::UnknownPropertyException(rsPropertyName);
257
258
0
        const PropertyType eType (GetPropertyType(iId->second));
259
0
        if (eType == PT_Invalid)
260
0
            throw beans::UnknownPropertyException(rsPropertyName);
261
262
0
        eItem = iId->second;
263
0
    }
264
0
    ChangeListenerContainer* pListeners = GetChangeListeners(eItem, true);
265
0
    if (pListeners != nullptr)
266
0
        pListeners->push_back(rxListener);
267
0
}
268
269
void SAL_CALL Theme::removePropertyChangeListener(
270
    const OUString& rsPropertyName,
271
    const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener)
272
0
{
273
0
    SolarMutexGuard aGuard;
274
275
0
    ThemeItem eItem (AnyItem_);
276
0
    if (rsPropertyName.getLength() > 0)
277
0
    {
278
0
        PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
279
0
        if (iId == maPropertyNameToIdMap.end())
280
0
            throw beans::UnknownPropertyException(rsPropertyName);
281
282
0
        const PropertyType eType (GetPropertyType(iId->second));
283
0
        if (eType == PT_Invalid)
284
0
            throw beans::UnknownPropertyException(rsPropertyName);
285
286
0
        eItem = iId->second;
287
0
    }
288
0
    ChangeListenerContainer* pContainer = GetChangeListeners(eItem, false);
289
0
    if (pContainer != nullptr)
290
0
    {
291
0
        ChangeListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
292
0
        if (iListener != pContainer->end())
293
0
        {
294
0
            pContainer->erase(iListener);
295
296
            // Remove the listener container when empty.
297
0
            if (pContainer->empty())
298
0
                maChangeListeners.erase(eItem);
299
0
        }
300
0
    }
301
0
}
302
303
void SAL_CALL Theme::addVetoableChangeListener(
304
    const OUString& rsPropertyName,
305
    const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
306
0
{
307
0
    SolarMutexGuard aGuard;
308
309
0
    ThemeItem eItem (AnyItem_);
310
0
    if (rsPropertyName.getLength() > 0)
311
0
    {
312
0
        PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
313
0
        if (iId == maPropertyNameToIdMap.end())
314
0
            throw beans::UnknownPropertyException(rsPropertyName);
315
316
0
        const PropertyType eType (GetPropertyType(iId->second));
317
0
        if (eType == PT_Invalid)
318
0
            throw beans::UnknownPropertyException(rsPropertyName);
319
320
0
        eItem = iId->second;
321
0
    }
322
0
    VetoableListenerContainer* pListeners = GetVetoableListeners(eItem, true);
323
0
    if (pListeners != nullptr)
324
0
        pListeners->push_back(rxListener);
325
0
}
326
327
void SAL_CALL Theme::removeVetoableChangeListener(
328
    const OUString& rsPropertyName,
329
    const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener)
330
0
{
331
0
    SolarMutexGuard aGuard;
332
333
0
    ThemeItem eItem (AnyItem_);
334
0
    if (rsPropertyName.getLength() > 0)
335
0
    {
336
0
        PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
337
0
        if (iId == maPropertyNameToIdMap.end())
338
0
            throw beans::UnknownPropertyException(rsPropertyName);
339
340
0
        const PropertyType eType (GetPropertyType(iId->second));
341
0
        if (eType == PT_Invalid)
342
0
            throw beans::UnknownPropertyException(rsPropertyName);
343
344
0
        eItem = iId->second;
345
0
    }
346
0
    VetoableListenerContainer* pContainer = GetVetoableListeners(eItem, false);
347
0
    if (pContainer != nullptr)
348
0
    {
349
0
        VetoableListenerContainer::iterator iListener (::std::find(pContainer->begin(), pContainer->end(), rxListener));
350
0
        if (iListener != pContainer->end())
351
0
        {
352
0
            pContainer->erase(iListener);
353
            // Remove container when empty.
354
0
            if (pContainer->empty())
355
0
                maVetoableListeners.erase(eItem);
356
0
        }
357
0
    }
358
0
}
359
360
css::uno::Sequence<css::beans::Property> SAL_CALL Theme::getProperties()
361
0
{
362
0
    SolarMutexGuard aGuard;
363
364
0
    ::std::vector<beans::Property> aProperties;
365
366
0
    sal_Int32 const nEnd(End_);
367
0
    for (sal_Int32 nItem(Begin_); nItem!=nEnd; ++nItem)
368
0
    {
369
0
        const ThemeItem eItem (static_cast<ThemeItem>(nItem));
370
0
        const PropertyType eType (GetPropertyType(eItem));
371
0
        if (eType == PT_Invalid)
372
0
            continue;
373
374
0
        const beans::Property aProperty(
375
0
            maPropertyIdToNameMap[eItem],
376
0
            eItem,
377
0
            GetCppuType(eType),
378
0
            0);
379
0
        aProperties.push_back(aProperty);
380
0
    }
381
382
0
    return css::uno::Sequence<css::beans::Property>(
383
0
        aProperties.data(),
384
0
        aProperties.size());
385
0
}
386
387
beans::Property SAL_CALL Theme::getPropertyByName (const OUString& rsPropertyName)
388
0
{
389
0
    SolarMutexGuard aGuard;
390
391
0
    PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
392
0
    if (iId == maPropertyNameToIdMap.end())
393
0
        throw beans::UnknownPropertyException(rsPropertyName);
394
395
0
    const PropertyType eType (GetPropertyType(iId->second));
396
0
    if (eType == PT_Invalid)
397
0
        throw beans::UnknownPropertyException(rsPropertyName);
398
399
0
    const ThemeItem eItem (iId->second);
400
401
0
    return beans::Property(
402
0
        rsPropertyName,
403
0
        eItem,
404
0
        GetCppuType(eType),
405
0
        0);
406
0
}
407
408
sal_Bool SAL_CALL Theme::hasPropertyByName (const OUString& rsPropertyName)
409
0
{
410
0
    SolarMutexGuard aGuard;
411
412
0
    PropertyNameToIdMap::const_iterator iId (maPropertyNameToIdMap.find(rsPropertyName));
413
0
    if (iId == maPropertyNameToIdMap.end())
414
0
        return false;
415
416
0
    const PropertyType eType (GetPropertyType(iId->second));
417
0
    if (eType == PT_Invalid)
418
0
        return false;
419
420
0
    return true;
421
0
}
422
423
void Theme::SetupPropertyMaps()
424
0
{
425
0
    maPropertyIdToNameMap.resize(Post_Bool_);
426
0
    maColors.resize(Color_Int_ - Pre_Color_ - 1);
427
0
    maIntegers.resize(Int_Bool_ - Color_Int_ - 1);
428
0
    maBooleans.resize(Post_Bool_ - Int_Bool_ - 1);
429
430
0
    maPropertyNameToIdMap[u"Color_Highlight"_ustr]=Color_Highlight;
431
0
    maPropertyIdToNameMap[Color_Highlight]="Color_Highlight";
432
433
0
    maPropertyNameToIdMap[u"Color_HighlightText"_ustr]=Color_HighlightText;
434
0
    maPropertyIdToNameMap[Color_HighlightText]="Color_HighlightText";
435
436
437
0
    maPropertyNameToIdMap[u"Color_DeckBackground"_ustr]=Color_DeckBackground;
438
0
    maPropertyIdToNameMap[Color_DeckBackground]="Color_DeckBackground";
439
440
0
    maPropertyNameToIdMap[u"Color_DeckTitleBarBackground"_ustr]=Color_DeckTitleBarBackground;
441
0
    maPropertyIdToNameMap[Color_DeckTitleBarBackground]="Color_DeckTitleBarBackground";
442
443
0
    maPropertyNameToIdMap[u"Color_PanelBackground"_ustr]=Color_PanelBackground;
444
0
    maPropertyIdToNameMap[Color_PanelBackground]="Color_PanelBackground";
445
446
0
    maPropertyNameToIdMap[u"Color_PanelTitleBarBackground"_ustr]=Color_PanelTitleBarBackground;
447
0
    maPropertyIdToNameMap[Color_PanelTitleBarBackground]="Color_PanelTitleBarBackground";
448
449
0
    maPropertyNameToIdMap[u"Color_TabBarBackground"_ustr]=Color_TabBarBackground;
450
0
    maPropertyIdToNameMap[Color_TabBarBackground]="Color_TabBarBackground";
451
452
453
0
    maPropertyNameToIdMap[u"Int_DeckBorderSize"_ustr]=Int_DeckBorderSize;
454
0
    maPropertyIdToNameMap[Int_DeckBorderSize]="Int_DeckBorderSize";
455
456
0
    maPropertyNameToIdMap[u"Int_DeckSeparatorHeight"_ustr]=Int_DeckSeparatorHeight;
457
0
    maPropertyIdToNameMap[Int_DeckSeparatorHeight]="Int_DeckSeparatorHeight";
458
459
0
    maPropertyNameToIdMap[u"Int_DeckLeftPadding"_ustr]=Int_DeckLeftPadding;
460
0
    maPropertyIdToNameMap[Int_DeckLeftPadding]="Int_DeckLeftPadding";
461
462
0
    maPropertyNameToIdMap[u"Int_DeckTopPadding"_ustr]=Int_DeckTopPadding;
463
0
    maPropertyIdToNameMap[Int_DeckTopPadding]="Int_DeckTopPadding";
464
465
0
    maPropertyNameToIdMap[u"Int_DeckRightPadding"_ustr]=Int_DeckRightPadding;
466
0
    maPropertyIdToNameMap[Int_DeckRightPadding]="Int_DeckRightPadding";
467
468
0
    maPropertyNameToIdMap[u"Int_DeckBottomPadding"_ustr]=Int_DeckBottomPadding;
469
0
    maPropertyIdToNameMap[Int_DeckBottomPadding]="Int_DeckBottomPadding";
470
471
472
0
    maPropertyNameToIdMap[u"Bool_UseSystemColors"_ustr]=Bool_UseSystemColors;
473
0
    maPropertyIdToNameMap[Bool_UseSystemColors]="Bool_UseSystemColors";
474
475
0
    maPropertyNameToIdMap[u"Bool_IsHighContrastModeActive"_ustr]=Bool_IsHighContrastModeActive;
476
0
    maPropertyIdToNameMap[Bool_IsHighContrastModeActive]="Bool_IsHighContrastModeActive";
477
478
0
    maRawValues.resize(maPropertyIdToNameMap.size());
479
0
}
480
481
Theme::PropertyType Theme::GetPropertyType (const ThemeItem eItem)
482
0
{
483
0
    switch(eItem)
484
0
    {
485
0
        case Color_Highlight:
486
0
        case Color_HighlightText:
487
0
        case Color_DeckBackground:
488
0
        case Color_DeckTitleBarBackground:
489
0
        case Color_PanelBackground:
490
0
        case Color_PanelTitleBarBackground:
491
0
        case Color_TabBarBackground:
492
0
            return PT_Color;
493
494
0
        case Int_DeckBorderSize:
495
0
        case Int_DeckSeparatorHeight:
496
0
        case Int_DeckLeftPadding:
497
0
        case Int_DeckTopPadding:
498
0
        case Int_DeckRightPadding:
499
0
        case Int_DeckBottomPadding:
500
0
            return PT_Integer;
501
502
0
        case Bool_UseSystemColors:
503
0
        case Bool_IsHighContrastModeActive:
504
0
            return PT_Boolean;
505
506
0
        default:
507
0
            return PT_Invalid;
508
0
    }
509
0
}
510
511
css::uno::Type const & Theme::GetCppuType (const PropertyType eType)
512
0
{
513
0
    switch(eType)
514
0
    {
515
0
        case PT_Color:
516
0
            return cppu::UnoType<sal_uInt32>::get();
517
518
0
        case PT_Integer:
519
0
            return cppu::UnoType<sal_Int32>::get();
520
521
0
        case PT_Boolean:
522
0
            return cppu::UnoType<sal_Bool>::get();
523
524
0
        case PT_Invalid:
525
0
        default:
526
0
            return cppu::UnoType<void>::get();
527
0
    }
528
0
}
529
530
sal_Int32 Theme::GetIndex (const ThemeItem eItem, const PropertyType eType)
531
0
{
532
0
    switch(eType)
533
0
    {
534
0
        case PT_Color:
535
0
            return eItem - Pre_Color_-1;
536
0
        case PT_Integer:
537
0
            return eItem - Color_Int_-1;
538
0
        case PT_Boolean:
539
0
            return eItem - Int_Bool_-1;
540
0
        default:
541
0
            OSL_ASSERT(false);
542
0
            return 0;
543
0
    }
544
0
}
545
546
Theme::VetoableListenerContainer* Theme::GetVetoableListeners (
547
    const ThemeItem eItem,
548
    const bool bCreate)
549
0
{
550
0
    VetoableListeners::iterator iContainer (maVetoableListeners.find(eItem));
551
0
    if (iContainer != maVetoableListeners.end())
552
0
        return &iContainer->second;
553
0
    else if (bCreate)
554
0
    {
555
0
        maVetoableListeners[eItem] = VetoableListenerContainer();
556
0
        return &maVetoableListeners[eItem];
557
0
    }
558
0
    else
559
0
        return nullptr;
560
0
}
561
562
Theme::ChangeListenerContainer* Theme::GetChangeListeners (
563
    const ThemeItem eItem,
564
    const bool bCreate)
565
0
{
566
0
    ChangeListeners::iterator iContainer (maChangeListeners.find(eItem));
567
0
    if (iContainer != maChangeListeners.end())
568
0
        return &iContainer->second;
569
0
    else if (bCreate)
570
0
    {
571
0
        maChangeListeners[eItem] = ChangeListenerContainer();
572
0
        return &maChangeListeners[eItem];
573
0
    }
574
0
    else
575
0
        return nullptr;
576
0
}
577
578
bool Theme::DoVetoableListenersVeto (
579
    const VetoableListenerContainer* pListeners,
580
    const beans::PropertyChangeEvent& rEvent)
581
0
{
582
0
    if (pListeners == nullptr)
583
0
        return false;
584
585
0
    VetoableListenerContainer aListeners (*pListeners);
586
0
    try
587
0
    {
588
0
        for (const auto& rxListener : aListeners)
589
0
        {
590
0
            rxListener->vetoableChange(rEvent);
591
0
        }
592
0
    }
593
0
    catch(const beans::PropertyVetoException&)
594
0
    {
595
0
        return true;
596
0
    }
597
0
    catch(const Exception&)
598
0
    {
599
        // Ignore any other errors (such as disposed listeners).
600
0
    }
601
0
    return false;
602
0
}
603
604
void Theme::BroadcastPropertyChange (
605
    const ChangeListenerContainer* pListeners,
606
    const beans::PropertyChangeEvent& rEvent)
607
0
{
608
0
    if (pListeners == nullptr)
609
0
        return;
610
611
0
    const ChangeListenerContainer aListeners (*pListeners);
612
0
    try
613
0
    {
614
0
        for (const auto& rxListener : aListeners)
615
0
        {
616
0
            rxListener->propertyChange(rEvent);
617
0
        }
618
0
    }
619
0
    catch(const Exception&)
620
0
    {
621
        // Ignore any errors (such as disposed listeners).
622
0
    }
623
0
}
624
625
void Theme::ProcessNewValue (
626
    const Any& rValue,
627
    const ThemeItem eItem,
628
    const PropertyType eType)
629
0
{
630
0
    const sal_Int32 nIndex (GetIndex (eItem, eType));
631
0
    switch (eType)
632
0
    {
633
0
        case PT_Color:
634
0
        {
635
0
            Color nColorValue;
636
0
            if (rValue >>= nColorValue)
637
0
                maColors[nIndex] = nColorValue;
638
0
            break;
639
0
        }
640
0
        case PT_Integer:
641
0
        {
642
0
            sal_Int32 nValue (0);
643
0
            if (rValue >>= nValue)
644
0
            {
645
0
                maIntegers[nIndex] = nValue;
646
0
            }
647
0
            break;
648
0
        }
649
0
        case PT_Boolean:
650
0
        {
651
0
            bool bValue (false);
652
0
            if (rValue >>= bValue)
653
0
            {
654
0
                maBooleans[nIndex] = bValue;
655
0
                if (eItem == Bool_IsHighContrastModeActive)
656
0
                {
657
0
                    mbIsHighContrastModeSetManually = true;
658
0
                    mbIsHighContrastMode = maBooleans[nIndex];
659
0
                    HandleDataChange();
660
0
                }
661
0
                else if (eItem == Bool_UseSystemColors)
662
0
                {
663
0
                    HandleDataChange();
664
0
                }
665
0
            }
666
0
            break;
667
0
        }
668
0
        case PT_Invalid:
669
0
            OSL_ASSERT(eType != PT_Invalid);
670
0
            throw RuntimeException();
671
0
    }
672
0
}
673
674
} // end of namespace sfx2::sidebar
675
676
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */