bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / gdi / WidgetDefinition.cxx
blobcabb0d0817ba3fb61ae1e789f0cd64949cef267e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
11 #include <widgetdraw/WidgetDefinition.hxx>
13 #include <sal/config.h>
14 #include <unordered_map>
16 namespace vcl
18 std::shared_ptr<WidgetDefinitionPart> WidgetDefinition::getDefinition(ControlType eType,
19 ControlPart ePart)
21 auto aIterator = maDefinitions.find(ControlTypeAndPart(eType, ePart));
23 if (aIterator != maDefinitions.end())
24 return aIterator->second;
25 return std::shared_ptr<WidgetDefinitionPart>();
28 std::vector<std::shared_ptr<WidgetDefinitionState>>
29 WidgetDefinitionPart::getStates(ControlType eType, ControlPart ePart, ControlState eState,
30 ImplControlValue const& rValue)
32 std::vector<std::shared_ptr<WidgetDefinitionState>> aStatesToAdd;
34 for (const auto& state : maStates)
36 bool bAdd = true;
38 if (state->msEnabled != "any"
39 && !((state->msEnabled == "true" && eState & ControlState::ENABLED)
40 || (state->msEnabled == "false" && !(eState & ControlState::ENABLED))))
41 bAdd = false;
42 if (state->msFocused != "any"
43 && !((state->msFocused == "true" && eState & ControlState::FOCUSED)
44 || (state->msFocused == "false" && !(eState & ControlState::FOCUSED))))
45 bAdd = false;
46 if (state->msPressed != "any"
47 && !((state->msPressed == "true" && eState & ControlState::PRESSED)
48 || (state->msPressed == "false" && !(eState & ControlState::PRESSED))))
49 bAdd = false;
50 if (state->msRollover != "any"
51 && !((state->msRollover == "true" && eState & ControlState::ROLLOVER)
52 || (state->msRollover == "false" && !(eState & ControlState::ROLLOVER))))
53 bAdd = false;
54 if (state->msDefault != "any"
55 && !((state->msDefault == "true" && eState & ControlState::DEFAULT)
56 || (state->msDefault == "false" && !(eState & ControlState::DEFAULT))))
57 bAdd = false;
58 if (state->msSelected != "any"
59 && !((state->msSelected == "true" && eState & ControlState::SELECTED)
60 || (state->msSelected == "false" && !(eState & ControlState::SELECTED))))
61 bAdd = false;
63 ButtonValue eButtonValue = rValue.getTristateVal();
65 if (state->msButtonValue != "any"
66 && !((state->msButtonValue == "true" && eButtonValue == ButtonValue::On)
67 || (state->msButtonValue == "false" && eButtonValue != ButtonValue::On)))
69 bAdd = false;
72 OString sExtra = "any";
74 switch (eType)
76 case ControlType::TabItem:
78 auto const& rTabItemValue = static_cast<TabitemValue const&>(rValue);
80 if (rTabItemValue.isLeftAligned() && rTabItemValue.isRightAligned()
81 && rTabItemValue.isFirst() && rTabItemValue.isLast())
82 sExtra = "first_last";
83 else if (rTabItemValue.isLeftAligned() || rTabItemValue.isFirst())
84 sExtra = "first";
85 else if (rTabItemValue.isRightAligned() || rTabItemValue.isLast())
86 sExtra = "last";
87 else
88 sExtra = "middle";
90 break;
91 case ControlType::ListHeader:
93 if (ePart == ControlPart::Arrow)
95 if (rValue.getNumericVal() == 1)
96 sExtra = "down";
97 else
98 sExtra = "up";
101 break;
102 case ControlType::Pushbutton:
104 auto const& rPushButtonValue = static_cast<PushButtonValue const&>(rValue);
105 if (rPushButtonValue.mbIsAction)
106 sExtra = "action";
108 break;
109 default:
110 break;
113 if (state->msExtra != "any" && state->msExtra != sExtra)
115 bAdd = false;
118 if (bAdd)
119 aStatesToAdd.push_back(state);
122 return aStatesToAdd;
125 WidgetDefinitionState::WidgetDefinitionState(OString const& sEnabled, OString const& sFocused,
126 OString const& sPressed, OString const& sRollover,
127 OString const& sDefault, OString const& sSelected,
128 OString const& sButtonValue, OString const& sExtra)
129 : msEnabled(sEnabled)
130 , msFocused(sFocused)
131 , msPressed(sPressed)
132 , msRollover(sRollover)
133 , msDefault(sDefault)
134 , msSelected(sSelected)
135 , msButtonValue(sButtonValue)
136 , msExtra(sExtra)
140 void WidgetDefinitionState::addDrawRectangle(Color aStrokeColor, sal_Int32 nStrokeWidth,
141 Color aFillColor, float fX1, float fY1, float fX2,
142 float fY2, sal_Int32 nRx, sal_Int32 nRy)
144 auto pCommand(std::make_shared<WidgetDrawActionRectangle>());
145 pCommand->maStrokeColor = aStrokeColor;
146 pCommand->maFillColor = aFillColor;
147 pCommand->mnStrokeWidth = nStrokeWidth;
148 pCommand->mnRx = nRx;
149 pCommand->mnRy = nRy;
150 pCommand->mfX1 = fX1;
151 pCommand->mfY1 = fY1;
152 pCommand->mfX2 = fX2;
153 pCommand->mfY2 = fY2;
154 mpWidgetDrawActions.push_back(std::move(pCommand));
157 void WidgetDefinitionState::addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1,
158 float fY1, float fX2, float fY2)
160 auto pCommand(std::make_shared<WidgetDrawActionLine>());
161 pCommand->maStrokeColor = aStrokeColor;
162 pCommand->mnStrokeWidth = nStrokeWidth;
163 pCommand->mfX1 = fX1;
164 pCommand->mfY1 = fY1;
165 pCommand->mfX2 = fX2;
166 pCommand->mfY2 = fY2;
167 mpWidgetDrawActions.push_back(std::move(pCommand));
170 void WidgetDefinitionState::addDrawImage(OUString const& sSource)
172 auto pCommand(std::make_shared<WidgetDrawActionImage>());
173 pCommand->msSource = sSource;
174 mpWidgetDrawActions.push_back(std::move(pCommand));
177 void WidgetDefinitionState::addDrawExternal(OUString const& sSource)
179 auto pCommand(std::make_unique<WidgetDrawActionExternal>());
180 pCommand->msSource = sSource;
181 mpWidgetDrawActions.push_back(std::move(pCommand));
184 } // end vcl namespace
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */