LibreOffice Module vcl (master) 1
WidgetDefinition.cxx
Go to the documentation of this file.
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 <utility>
13
14#include <sal/config.h>
15#include <unordered_map>
16
17namespace vcl
18{
19std::shared_ptr<WidgetDefinitionPart> WidgetDefinition::getDefinition(ControlType eType,
20 ControlPart ePart)
21{
22 auto aIterator = maDefinitions.find(ControlTypeAndPart(eType, ePart));
23
24 if (aIterator != maDefinitions.end())
25 return aIterator->second;
26 return std::shared_ptr<WidgetDefinitionPart>();
27}
28
29std::vector<std::shared_ptr<WidgetDefinitionState>>
31 ImplControlValue const& rValue)
32{
33 std::vector<std::shared_ptr<WidgetDefinitionState>> aStatesToAdd;
34
35 for (const auto& state : maStates)
36 {
37 bool bAdd = true;
38
39 if (state->msEnabled != "any"
40 && !((state->msEnabled == "true" && eState & ControlState::ENABLED)
41 || (state->msEnabled == "false" && !(eState & ControlState::ENABLED))))
42 bAdd = false;
43 if (state->msFocused != "any"
44 && !((state->msFocused == "true" && eState & ControlState::FOCUSED)
45 || (state->msFocused == "false" && !(eState & ControlState::FOCUSED))))
46 bAdd = false;
47 if (state->msPressed != "any"
48 && !((state->msPressed == "true" && eState & ControlState::PRESSED)
49 || (state->msPressed == "false" && !(eState & ControlState::PRESSED))))
50 bAdd = false;
51 if (state->msRollover != "any"
52 && !((state->msRollover == "true" && eState & ControlState::ROLLOVER)
53 || (state->msRollover == "false" && !(eState & ControlState::ROLLOVER))))
54 bAdd = false;
55 if (state->msDefault != "any"
56 && !((state->msDefault == "true" && eState & ControlState::DEFAULT)
57 || (state->msDefault == "false" && !(eState & ControlState::DEFAULT))))
58 bAdd = false;
59 if (state->msSelected != "any"
60 && !((state->msSelected == "true" && eState & ControlState::SELECTED)
61 || (state->msSelected == "false" && !(eState & ControlState::SELECTED))))
62 bAdd = false;
63
64 ButtonValue eButtonValue = rValue.getTristateVal();
65
66 if (state->msButtonValue != "any"
67 && !((state->msButtonValue == "true" && eButtonValue == ButtonValue::On)
68 || (state->msButtonValue == "false" && eButtonValue == ButtonValue::Off)))
69 {
70 bAdd = false;
71 }
72
73 OString sExtra = "any";
74
75 switch (eType)
76 {
78 {
79 auto const& rTabItemValue = static_cast<TabitemValue const&>(rValue);
80
81 if (rTabItemValue.isLeftAligned() && rTabItemValue.isRightAligned()
82 && rTabItemValue.isFirst() && rTabItemValue.isLast())
83 sExtra = "first_last";
84 else if (rTabItemValue.isLeftAligned() || rTabItemValue.isFirst())
85 sExtra = "first";
86 else if (rTabItemValue.isRightAligned() || rTabItemValue.isLast())
87 sExtra = "last";
88 else
89 sExtra = "middle";
90 }
91 break;
93 {
94 if (ePart == ControlPart::Arrow)
95 {
96 if (rValue.getNumericVal() == 1)
97 sExtra = "down";
98 else
99 sExtra = "up";
100 }
101 }
102 break;
104 {
105 auto const& rPushButtonValue = static_cast<PushButtonValue const&>(rValue);
106 if (rPushButtonValue.mbIsAction)
107 sExtra = "action";
108 }
109 break;
110 default:
111 break;
112 }
113
114 if (state->msExtra != "any" && state->msExtra != sExtra)
115 {
116 bAdd = false;
117 }
118
119 if (bAdd)
120 aStatesToAdd.push_back(state);
121 }
122
123 return aStatesToAdd;
124}
125
126WidgetDefinitionState::WidgetDefinitionState(OString sEnabled, OString sFocused, OString sPressed,
127 OString sRollover, OString sDefault, OString sSelected,
128 OString sButtonValue, OString sExtra)
129 : msEnabled(std::move(sEnabled))
130 , msFocused(std::move(sFocused))
131 , msPressed(std::move(sPressed))
132 , msRollover(std::move(sRollover))
133 , msDefault(std::move(sDefault))
134 , msSelected(std::move(sSelected))
135 , msButtonValue(std::move(sButtonValue))
136 , msExtra(std::move(sExtra))
137{
138}
139
140void 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)
143{
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));
155}
156
157void WidgetDefinitionState::addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1,
158 float fY1, float fX2, float fY2)
159{
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));
168}
169
170void WidgetDefinitionState::addDrawImage(OUString const& sSource)
171{
172 auto pCommand(std::make_shared<WidgetDrawActionImage>());
173 pCommand->msSource = sSource;
174 mpWidgetDrawActions.push_back(std::move(pCommand));
175}
176
177void WidgetDefinitionState::addDrawExternal(OUString const& sSource)
178{
179 auto pCommand(std::make_shared<WidgetDrawActionExternal>());
180 pCommand->msSource = sSource;
181 mpWidgetDrawActions.push_back(std::move(pCommand));
182}
183
184} // end vcl namespace
185
186/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ControlType
These types are all based on the supported variants vcl/salnativewidgets.hxx and must be kept in-sync...
ButtonValue getTristateVal() const
tools::Long getNumericVal() const
std::vector< std::shared_ptr< WidgetDefinitionState > > getStates(ControlType eType, ControlPart ePart, ControlState eState, ImplControlValue const &rValue)
std::vector< std::shared_ptr< WidgetDefinitionState > > maStates
std::vector< std::shared_ptr< WidgetDrawAction > > mpWidgetDrawActions
WidgetDefinitionState(OString sEnabled, OString sFocused, OString sPressed, OString sRollover, OString sDefault, OString sSelected, OString sButtonValue, OString sExtra)
void addDrawRectangle(Color aStrokeColor, sal_Int32 nStrokeWidth, Color aFillColor, float fX1, float fY1, float fX2, float fY2, sal_Int32 nRx, sal_Int32 nRy)
void addDrawExternal(OUString const &sSource)
void addDrawImage(OUString const &sSource)
void addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1, float fY1, float fX2, float fY2)
std::shared_ptr< WidgetDefinitionPart > getDefinition(ControlType eType, ControlPart ePart)
std::unordered_map< ControlTypeAndPart, std::shared_ptr< WidgetDefinitionPart > > maDefinitions
DocumentType eType