1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
11 #include <widgetdraw/WidgetDefinition.hxx>
13 #include <sal/config.h>
14 #include <unordered_map>
18 std::shared_ptr
<WidgetDefinitionPart
> WidgetDefinition::getDefinition(ControlType eType
,
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
)
38 if (state
->msEnabled
!= "any"
39 && !((state
->msEnabled
== "true" && eState
& ControlState::ENABLED
)
40 || (state
->msEnabled
== "false" && !(eState
& ControlState::ENABLED
))))
42 if (state
->msFocused
!= "any"
43 && !((state
->msFocused
== "true" && eState
& ControlState::FOCUSED
)
44 || (state
->msFocused
== "false" && !(eState
& ControlState::FOCUSED
))))
46 if (state
->msPressed
!= "any"
47 && !((state
->msPressed
== "true" && eState
& ControlState::PRESSED
)
48 || (state
->msPressed
== "false" && !(eState
& ControlState::PRESSED
))))
50 if (state
->msRollover
!= "any"
51 && !((state
->msRollover
== "true" && eState
& ControlState::ROLLOVER
)
52 || (state
->msRollover
== "false" && !(eState
& ControlState::ROLLOVER
))))
54 if (state
->msDefault
!= "any"
55 && !((state
->msDefault
== "true" && eState
& ControlState::DEFAULT
)
56 || (state
->msDefault
== "false" && !(eState
& ControlState::DEFAULT
))))
58 if (state
->msSelected
!= "any"
59 && !((state
->msSelected
== "true" && eState
& ControlState::SELECTED
)
60 || (state
->msSelected
== "false" && !(eState
& ControlState::SELECTED
))))
63 ButtonValue eButtonValue
= rValue
.getTristateVal();
65 if (state
->msButtonValue
!= "any"
66 && !((state
->msButtonValue
== "true" && eButtonValue
== ButtonValue::On
)
67 || (state
->msButtonValue
== "false" && eButtonValue
!= ButtonValue::On
)))
72 OString sExtra
= "any";
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())
85 else if (rTabItemValue
.isRightAligned() || rTabItemValue
.isLast())
91 case ControlType::ListHeader
:
93 if (ePart
== ControlPart::Arrow
)
95 if (rValue
.getNumericVal() == 1)
102 case ControlType::Pushbutton
:
104 auto const& rPushButtonValue
= static_cast<PushButtonValue
const&>(rValue
);
105 if (rPushButtonValue
.mbIsAction
)
113 if (state
->msExtra
!= "any" && state
->msExtra
!= sExtra
)
119 aStatesToAdd
.push_back(state
);
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
)
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: */