Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/gdi/WidgetDefinition.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
11
#include <string_view>
12
#include <utility>
13
#include <widgetdraw/WidgetDefinition.hxx>
14
15
#include <sal/config.h>
16
#include <unordered_map>
17
18
namespace vcl
19
{
20
std::shared_ptr<WidgetDefinitionPart> WidgetDefinition::getDefinition(ControlType eType,
21
                                                                      ControlPart ePart)
22
0
{
23
0
    auto aIterator = maDefinitions.find(ControlTypeAndPart(eType, ePart));
24
25
0
    if (aIterator != maDefinitions.end())
26
0
        return aIterator->second;
27
0
    return std::shared_ptr<WidgetDefinitionPart>();
28
0
}
29
30
std::vector<std::shared_ptr<WidgetDefinitionState>>
31
WidgetDefinitionPart::getStates(ControlType eType, ControlPart ePart, ControlState eState,
32
                                ImplControlValue const& rValue)
33
0
{
34
0
    std::vector<std::shared_ptr<WidgetDefinitionState>> aStatesToAdd;
35
36
0
    for (const auto& state : maStates)
37
0
    {
38
0
        bool bAdd = true;
39
40
0
        if (state->msEnabled != "any"
41
0
            && !((state->msEnabled == "true" && eState & ControlState::ENABLED)
42
0
                 || (state->msEnabled == "false" && !(eState & ControlState::ENABLED))))
43
0
            bAdd = false;
44
0
        if (state->msFocused != "any"
45
0
            && !((state->msFocused == "true" && eState & ControlState::FOCUSED)
46
0
                 || (state->msFocused == "false" && !(eState & ControlState::FOCUSED))))
47
0
            bAdd = false;
48
0
        if (state->msPressed != "any"
49
0
            && !((state->msPressed == "true" && eState & ControlState::PRESSED)
50
0
                 || (state->msPressed == "false" && !(eState & ControlState::PRESSED))))
51
0
            bAdd = false;
52
0
        if (state->msRollover != "any"
53
0
            && !((state->msRollover == "true" && eState & ControlState::ROLLOVER)
54
0
                 || (state->msRollover == "false" && !(eState & ControlState::ROLLOVER))))
55
0
            bAdd = false;
56
0
        if (state->msDefault != "any"
57
0
            && !((state->msDefault == "true" && eState & ControlState::DEFAULT)
58
0
                 || (state->msDefault == "false" && !(eState & ControlState::DEFAULT))))
59
0
            bAdd = false;
60
0
        if (state->msSelected != "any"
61
0
            && !((state->msSelected == "true" && eState & ControlState::SELECTED)
62
0
                 || (state->msSelected == "false" && !(eState & ControlState::SELECTED))))
63
0
            bAdd = false;
64
65
0
        ButtonValue eButtonValue = rValue.getTristateVal();
66
67
0
        if (state->msButtonValue != "any"
68
0
            && !((state->msButtonValue == "true" && eButtonValue == ButtonValue::On)
69
0
                 || (state->msButtonValue == "false" && eButtonValue == ButtonValue::Off)))
70
0
        {
71
0
            bAdd = false;
72
0
        }
73
74
0
        std::string_view sExtra = "any";
75
76
0
        switch (eType)
77
0
        {
78
0
            case ControlType::TabItem:
79
0
            {
80
0
                auto const& rTabItemValue = static_cast<TabitemValue const&>(rValue);
81
82
0
                if (rTabItemValue.isLeftAligned() && rTabItemValue.isRightAligned()
83
0
                    && rTabItemValue.isFirst() && rTabItemValue.isLast())
84
0
                    sExtra = "first_last";
85
0
                else if (rTabItemValue.isLeftAligned() || rTabItemValue.isFirst())
86
0
                    sExtra = "first";
87
0
                else if (rTabItemValue.isRightAligned() || rTabItemValue.isLast())
88
0
                    sExtra = "last";
89
0
                else
90
0
                    sExtra = "middle";
91
0
            }
92
0
            break;
93
0
            case ControlType::ListHeader:
94
0
            {
95
0
                if (ePart == ControlPart::Arrow)
96
0
                {
97
0
                    if (rValue.getNumericVal() == 1)
98
0
                        sExtra = "down";
99
0
                    else
100
0
                        sExtra = "up";
101
0
                }
102
0
            }
103
0
            break;
104
0
            case ControlType::Pushbutton:
105
0
            {
106
0
                auto const& rPushButtonValue = static_cast<PushButtonValue const&>(rValue);
107
0
                if (rPushButtonValue.mbIsAction)
108
0
                    sExtra = "action";
109
0
            }
110
0
            break;
111
0
            default:
112
0
                break;
113
0
        }
114
115
0
        if (state->msExtra != "any" && state->msExtra != sExtra)
116
0
        {
117
0
            bAdd = false;
118
0
        }
119
120
0
        if (bAdd)
121
0
            aStatesToAdd.push_back(state);
122
0
    }
123
124
0
    return aStatesToAdd;
125
0
}
126
127
WidgetDefinitionState::WidgetDefinitionState(OString sEnabled, OString sFocused, OString sPressed,
128
                                             OString sRollover, OString sDefault, OString sSelected,
129
                                             OString sButtonValue, OString sExtra)
130
0
    : msEnabled(std::move(sEnabled))
131
0
    , msFocused(std::move(sFocused))
132
0
    , msPressed(std::move(sPressed))
133
0
    , msRollover(std::move(sRollover))
134
0
    , msDefault(std::move(sDefault))
135
0
    , msSelected(std::move(sSelected))
136
0
    , msButtonValue(std::move(sButtonValue))
137
0
    , msExtra(std::move(sExtra))
138
0
{
139
0
}
140
141
void WidgetDefinitionState::addDrawRectangle(Color aStrokeColor, sal_Int32 nStrokeWidth,
142
                                             Color aFillColor, float fX1, float fY1, float fX2,
143
                                             float fY2, sal_Int32 nRx, sal_Int32 nRy)
144
0
{
145
0
    auto pCommand(std::make_shared<WidgetDrawActionRectangle>());
146
0
    pCommand->maStrokeColor = aStrokeColor;
147
0
    pCommand->maFillColor = aFillColor;
148
0
    pCommand->mnStrokeWidth = nStrokeWidth;
149
0
    pCommand->mnRx = nRx;
150
0
    pCommand->mnRy = nRy;
151
0
    pCommand->mfX1 = fX1;
152
0
    pCommand->mfY1 = fY1;
153
0
    pCommand->mfX2 = fX2;
154
0
    pCommand->mfY2 = fY2;
155
0
    mpWidgetDrawActions.push_back(std::move(pCommand));
156
0
}
157
158
void WidgetDefinitionState::addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1,
159
                                        float fY1, float fX2, float fY2)
160
0
{
161
0
    auto pCommand(std::make_shared<WidgetDrawActionLine>());
162
0
    pCommand->maStrokeColor = aStrokeColor;
163
0
    pCommand->mnStrokeWidth = nStrokeWidth;
164
0
    pCommand->mfX1 = fX1;
165
0
    pCommand->mfY1 = fY1;
166
0
    pCommand->mfX2 = fX2;
167
0
    pCommand->mfY2 = fY2;
168
0
    mpWidgetDrawActions.push_back(std::move(pCommand));
169
0
}
170
171
void WidgetDefinitionState::addDrawImage(OUString const& sSource)
172
0
{
173
0
    auto pCommand(std::make_shared<WidgetDrawActionImage>());
174
0
    pCommand->msSource = sSource;
175
0
    mpWidgetDrawActions.push_back(std::move(pCommand));
176
0
}
177
178
void WidgetDefinitionState::addDrawExternal(OUString const& sSource)
179
0
{
180
0
    auto pCommand(std::make_shared<WidgetDrawActionExternal>());
181
0
    pCommand->msSource = sSource;
182
0
    mpWidgetDrawActions.push_back(std::move(pCommand));
183
0
}
184
185
} // end vcl namespace
186
187
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */