tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / svx / source / sidebar / area / AreaTransparencyGradientPopup.cxx
blob4b5ed0eda076d9a9d57dbfe4576acc20b9ca8d11
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 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/sidebar/AreaTransparencyGradientPopup.hxx>
21 #include <svx/sidebar/AreaPropertyPanelBase.hxx>
22 #include <svx/xflftrit.hxx>
24 namespace svx::sidebar {
26 AreaTransparencyGradientPopup::AreaTransparencyGradientPopup(const css::uno::Reference<css::frame::XFrame>& rFrame,
27 AreaPropertyPanelBase& rPanel, weld::Widget* pParent)
28 : WeldToolbarPopup(rFrame, pParent, u"svx/ui/floatingareastyle.ui"_ustr, u"FloatingAreaStyle"_ustr)
29 , mrAreaPropertyPanel(rPanel)
30 , mxCenterGrid(m_xBuilder->weld_widget(u"centergrid"_ustr))
31 , mxAngleGrid(m_xBuilder->weld_widget(u"anglegrid"_ustr))
32 , mxMtrTrgrCenterX(m_xBuilder->weld_metric_spin_button(u"centerx"_ustr, FieldUnit::PERCENT))
33 , mxMtrTrgrCenterY(m_xBuilder->weld_metric_spin_button(u"centery"_ustr, FieldUnit::PERCENT))
34 , mxMtrTrgrAngle(m_xBuilder->weld_metric_spin_button(u"angle"_ustr, FieldUnit::DEGREE))
35 , mxBtnLeft45(m_xBuilder->weld_toolbar(u"lefttoolbox"_ustr))
36 , mxBtnRight45(m_xBuilder->weld_toolbar(u"righttoolbox"_ustr))
37 , mxMtrTrgrStartValue(m_xBuilder->weld_metric_spin_button(u"start"_ustr, FieldUnit::PERCENT))
38 , mxMtrTrgrEndValue(m_xBuilder->weld_metric_spin_button(u"end"_ustr, FieldUnit::PERCENT))
39 , mxMtrTrgrBorder(m_xBuilder->weld_metric_spin_button(u"border"_ustr, FieldUnit::PERCENT))
41 Link<weld::MetricSpinButton&,void> aLink = LINK(this, AreaTransparencyGradientPopup, ModifiedTrgrHdl_Impl);
42 mxMtrTrgrCenterX->connect_value_changed(aLink);
43 mxMtrTrgrCenterY->connect_value_changed(aLink);
44 mxMtrTrgrAngle->connect_value_changed(aLink);
45 mxMtrTrgrBorder->connect_value_changed(aLink);
46 mxMtrTrgrStartValue->connect_value_changed(aLink);
47 mxMtrTrgrEndValue->connect_value_changed(aLink);
48 mxBtnLeft45->connect_clicked(LINK(this, AreaTransparencyGradientPopup, Left_Click45_Impl));
49 mxBtnRight45->connect_clicked(LINK(this, AreaTransparencyGradientPopup, Right_Click45_Impl));
52 AreaTransparencyGradientPopup::~AreaTransparencyGradientPopup()
56 void AreaTransparencyGradientPopup::InitStatus(XFillFloatTransparenceItem const * pGradientItem)
58 const basegfx::BGradient& rGradient = pGradientItem->GetGradientValue();
60 basegfx::BGradient aGradient;
61 Color aStart(rGradient.GetColorStops().front().getStopColor());
62 Color aEnd(rGradient.GetColorStops().back().getStopColor());
64 if (rGradient.GetXOffset() == AreaPropertyPanelBase::DEFAULT_CENTERX
65 && rGradient.GetYOffset() == AreaPropertyPanelBase::DEFAULT_CENTERY
66 && static_cast<sal_Int32>(toDegrees(rGradient.GetAngle())) == AreaPropertyPanelBase::DEFAULT_ANGLE
67 && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aStart.GetRed()) + 1) * 100) / 255)
68 == AreaPropertyPanelBase::DEFAULT_STARTVALUE
69 && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aEnd.GetRed()) + 1) * 100) / 255)
70 == AreaPropertyPanelBase::DEFAULT_ENDVALUE
71 && rGradient.GetBorder() == AreaPropertyPanelBase::DEFAULT_BORDER)
73 aGradient = mrAreaPropertyPanel.GetGradient(rGradient.GetGradientStyle());
75 else
77 aGradient = rGradient;
79 mxMtrTrgrCenterX->set_value(aGradient.GetXOffset(), FieldUnit::PERCENT);
80 mxMtrTrgrCenterY->set_value(aGradient.GetYOffset(), FieldUnit::PERCENT);
81 mxMtrTrgrAngle->set_value(toDegrees(aGradient.GetAngle()), FieldUnit::DEGREE);
82 aStart = Color(aGradient.GetColorStops().front().getStopColor());
83 aEnd = Color(aGradient.GetColorStops().back().getStopColor());
84 mxMtrTrgrStartValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aStart.GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT);
85 mxMtrTrgrEndValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aEnd.GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT);
87 // MCGR: preserve ColorStops if given
88 // tdf#155901 We need offset of first and last stop, so include them.
89 if (aGradient.GetColorStops().size() >= 2)
90 maColorStops = aGradient.GetColorStops();
91 else
92 maColorStops.clear();
94 mxMtrTrgrBorder->set_value(aGradient.GetBorder(), FieldUnit::PERCENT);
97 void AreaTransparencyGradientPopup::Rearrange(XFillFloatTransparenceItem const * pGradientItem)
99 InitStatus(pGradientItem);
100 const basegfx::BGradient& rGradient = pGradientItem->GetGradientValue();
101 css::awt::GradientStyle eXGS(rGradient.GetGradientStyle());
103 switch(eXGS)
105 case css::awt::GradientStyle_LINEAR:
106 case css::awt::GradientStyle_AXIAL:
107 mxCenterGrid->hide();
108 mxAngleGrid->show();
109 break;
110 case css::awt::GradientStyle_RADIAL:
111 mxCenterGrid->show();
112 mxAngleGrid->hide();
113 break;
114 case css::awt::GradientStyle_ELLIPTICAL:
115 case css::awt::GradientStyle_SQUARE:
116 case css::awt::GradientStyle_RECT:
117 mxCenterGrid->show();
118 mxAngleGrid->show();
119 break;
120 default:
121 break;
125 void AreaTransparencyGradientPopup::ExecuteValueModify()
127 //Added
128 sal_Int16 aMtrValue = static_cast<sal_Int16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE));
129 while(aMtrValue<0)
130 aMtrValue += 360;
131 sal_uInt16 nVal = aMtrValue/360;
132 nVal = aMtrValue - nVal*360;
133 mxMtrTrgrAngle->set_value(nVal, FieldUnit::DEGREE);
134 //End of new code
136 basegfx::BColorStops aColorStops;
137 basegfx::BColor aStartBColor(mxMtrTrgrStartValue->get_value(FieldUnit::PERCENT) / 100.0);
138 aStartBColor.clamp();
139 basegfx::BColor aEndBColor(mxMtrTrgrEndValue->get_value(FieldUnit::PERCENT) / 100.0);
140 aEndBColor.clamp();
142 if (maColorStops.size() >= 2)
144 aColorStops = maColorStops;
145 aColorStops.front() = basegfx::BColorStop(maColorStops.front().getStopOffset(), aStartBColor);
146 aColorStops.back() = basegfx::BColorStop(maColorStops.back().getStopOffset(), aEndBColor);
148 else
150 aColorStops.emplace_back(0.0, aStartBColor);
151 aColorStops.emplace_back(1.0, aEndBColor);
154 basegfx::BGradient aTmpGradient(
155 aColorStops,
156 static_cast<css::awt::GradientStyle>(mrAreaPropertyPanel.GetSelectedTransparencyTypeIndex()-2),
157 Degree10(static_cast<sal_Int16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE)) * 10),
158 static_cast<sal_uInt16>(mxMtrTrgrCenterX->get_value(FieldUnit::PERCENT)),
159 static_cast<sal_uInt16>(mxMtrTrgrCenterY->get_value(FieldUnit::PERCENT)),
160 static_cast<sal_uInt16>(mxMtrTrgrBorder->get_value(FieldUnit::PERCENT)),
161 100, 100);
163 mrAreaPropertyPanel.SetGradient(aTmpGradient);
165 XFillFloatTransparenceItem aGradientItem(aTmpGradient, true );
167 mrAreaPropertyPanel.setFillFloatTransparence(aGradientItem);
170 IMPL_LINK_NOARG(AreaTransparencyGradientPopup, ModifiedTrgrHdl_Impl, weld::MetricSpinButton&, void)
172 ExecuteValueModify();
175 IMPL_LINK_NOARG(AreaTransparencyGradientPopup, Left_Click45_Impl, const OUString&, void)
177 sal_uInt16 nTemp = static_cast<sal_uInt16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE));
178 if (nTemp>=315)
179 nTemp -= 360;
180 nTemp += 45;
181 mxMtrTrgrAngle->set_value(nTemp, FieldUnit::DEGREE);
182 ExecuteValueModify();
185 IMPL_LINK_NOARG(AreaTransparencyGradientPopup, Right_Click45_Impl, const OUString&, void)
187 sal_uInt16 nTemp = static_cast<sal_uInt16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE));
188 if (nTemp<45)
189 nTemp += 360;
190 nTemp -= 45;
191 mxMtrTrgrAngle->set_value(nTemp, FieldUnit::DEGREE);
192 ExecuteValueModify();
195 void AreaTransparencyGradientPopup::GrabFocus()
197 mxMtrTrgrCenterX->grab_focus();
200 } // end of namespace svx::sidebar
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */