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 
12 
13 #include <sal/config.h>
14 #include <unordered_map>
15 
16 namespace vcl
17 {
18 std::shared_ptr<WidgetDefinitionPart> WidgetDefinition::getDefinition(ControlType eType,
19  ControlPart ePart)
20 {
21  auto aIterator = maDefinitions.find(ControlTypeAndPart(eType, ePart));
22 
23  if (aIterator != maDefinitions.end())
24  return aIterator->second;
25  return std::shared_ptr<WidgetDefinitionPart>();
26 }
27 
28 std::vector<std::shared_ptr<WidgetDefinitionState>>
30  ImplControlValue const& rValue)
31 {
32  std::vector<std::shared_ptr<WidgetDefinitionState>> aStatesToAdd;
33 
34  for (const auto& state : maStates)
35  {
36  bool bAdd = true;
37 
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;
62 
63  ButtonValue eButtonValue = rValue.getTristateVal();
64 
65  if (state->msButtonValue != "any"
66  && !((state->msButtonValue == "true" && eButtonValue == ButtonValue::On)
67  || (state->msButtonValue == "false" && eButtonValue != ButtonValue::On)))
68  {
69  bAdd = false;
70  }
71 
72  OString sExtra = "any";
73 
74  switch (eType)
75  {
77  {
78  auto const& rTabItemValue = static_cast<TabitemValue const&>(rValue);
79 
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";
89  }
90  break;
92  {
93  if (ePart == ControlPart::Arrow)
94  {
95  if (rValue.getNumericVal() == 1)
96  sExtra = "down";
97  else
98  sExtra = "up";
99  }
100  }
101  break;
103  {
104  auto const& rPushButtonValue = static_cast<PushButtonValue const&>(rValue);
105  if (rPushButtonValue.mbIsAction)
106  sExtra = "action";
107  }
108  break;
109  default:
110  break;
111  }
112 
113  if (state->msExtra != "any" && state->msExtra != sExtra)
114  {
115  bAdd = false;
116  }
117 
118  if (bAdd)
119  aStatesToAdd.push_back(state);
120  }
121 
122  return aStatesToAdd;
123 }
124 
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)
137 {
138 }
139 
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)
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 
157 void 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 
170 void 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 
177 void WidgetDefinitionState::addDrawExternal(OUString const& sSource)
178 {
179  auto pCommand(std::make_unique<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: */
WidgetDefinitionState(OString const &sEnabled, OString const &sFocused, OString const &sPressed, OString const &sRollover, OString const &sDefault, OString const &sSelected, OString const &sButtonValue, OString const &sExtra)
std::shared_ptr< WidgetDefinitionPart > getDefinition(ControlType eType, ControlPart ePart)
void addDrawRectangle(Color aStrokeColor, sal_Int32 nStrokeWidth, Color aFillColor, float fX1, float fY1, float fX2, float fY2, sal_Int32 nRx, sal_Int32 nRy)
std::vector< std::shared_ptr< WidgetDrawAction > > mpWidgetDrawActions
void addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1, float fY1, float fX2, float fY2)
std::vector< std::shared_ptr< WidgetDefinitionState > > getStates(ControlType eType, ControlPart ePart, ControlState eState, ImplControlValue const &rValue)
std::vector< std::shared_ptr< WidgetDefinitionState > > maStates
ControlType
These types are all based on the supported variants vcl/salnativewidgets.hxx and must be kept in-sync...
std::unordered_map< ControlTypeAndPart, std::shared_ptr< WidgetDefinitionPart > > maDefinitions
void addDrawImage(OUString const &sSource)
ButtonValue getTristateVal() const
long getNumericVal() const
void addDrawExternal(OUString const &sSource)