cid#1636693 COPY_INSTEAD_OF_MOVE
[LibreOffice.git] / svx / source / sidebar / effect / TextEffectPropertyPanel.cxx
blobab8797ee904f45204124f66446e08da4ed05d197
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/.
8 */
10 #include <sal/config.h>
12 #include "TextEffectPropertyPanel.hxx"
14 #include <sfx2/dispatch.hxx>
15 #include <svx/colorbox.hxx>
16 #include <svx/sdmetitm.hxx>
17 #include <svx/sdprcitm.hxx>
18 #include <svx/svddef.hxx>
19 #include <svx/svxids.hrc>
20 #include <svx/xcolit.hxx>
21 #include <svl/itemset.hxx>
23 namespace svx::sidebar
25 TextEffectPropertyPanel::TextEffectPropertyPanel(weld::Widget* pParent, SfxBindings* pBindings)
26 : PanelLayout(pParent, u"TextEffectPropertyPanel"_ustr, u"svx/ui/sidebartexteffect.ui"_ustr)
27 , maTGlowColorController(SID_ATTR_GLOW_TEXT_COLOR, *pBindings, *this)
28 , maTGlowRadiusController(SID_ATTR_GLOW_TEXT_RADIUS, *pBindings, *this)
29 , maTGlowTransparencyController(SID_ATTR_GLOW_TEXT_TRANSPARENCY, *pBindings, *this)
30 , mxFTTTransparency(m_xBuilder->weld_label(u"texttransparency"_ustr))
31 , mpBindings(pBindings)
32 , mxTGlowRadius(
33 m_xBuilder->weld_metric_spin_button(u"LB_GLOW_TEXT_RADIUS"_ustr, FieldUnit::POINT))
34 , mxLBTGlowColor(new ColorListBox(m_xBuilder->weld_menu_button(u"LB_GLOW_TEXT_COLOR"_ustr),
35 [this] { return GetFrameWeld(); }))
36 , mxTGlowTransparency(m_xBuilder->weld_metric_spin_button(u"LB_GLOW_TEXT_TRANSPARENCY"_ustr,
37 FieldUnit::PERCENT))
38 , mxFTTColor(m_xBuilder->weld_label(u"glowtextcolorlabel"_ustr))
40 Initialize();
43 TextEffectPropertyPanel::~TextEffectPropertyPanel()
45 mxTGlowRadius.reset();
46 mxLBTGlowColor.reset();
47 mxTGlowTransparency.reset();
48 mxFTTColor.reset();
49 mxFTTTransparency.reset();
51 maTGlowColorController.dispose();
52 maTGlowRadiusController.dispose();
53 maTGlowTransparencyController.dispose();
56 void TextEffectPropertyPanel::Initialize()
58 mxTGlowRadius->connect_value_changed(LINK(this, TextEffectPropertyPanel, ModifyTGlowRadiusHdl));
59 mxLBTGlowColor->SetSelectHdl(LINK(this, TextEffectPropertyPanel, ModifyTGlowColorHdl));
60 mxTGlowTransparency->connect_value_changed(
61 LINK(this, TextEffectPropertyPanel, ModifyTGlowTransparencyHdl));
64 IMPL_LINK_NOARG(TextEffectPropertyPanel, ModifyTGlowRadiusHdl, weld::MetricSpinButton&, void)
66 SdrMetricItem aItem(SDRATTR_GLOW_TEXT_RADIUS, mxTGlowRadius->get_value(FieldUnit::MM_100TH));
67 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_GLOW_TEXT_RADIUS, SfxCallMode::RECORD,
68 { &aItem });
71 IMPL_LINK_NOARG(TextEffectPropertyPanel, ModifyTGlowColorHdl, ColorListBox&, void)
73 XColorItem aItem(SDRATTR_GLOW_TEXT_COLOR, mxLBTGlowColor->GetSelectEntryColor());
74 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_GLOW_TEXT_COLOR, SfxCallMode::RECORD,
75 { &aItem });
78 IMPL_LINK_NOARG(TextEffectPropertyPanel, ModifyTGlowTransparencyHdl, weld::MetricSpinButton&, void)
80 SdrPercentItem aItem(SDRATTR_GLOW_TEXT_TRANSPARENCY,
81 mxTGlowTransparency->get_value(FieldUnit::PERCENT));
82 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_GLOW_TEXT_TRANSPARENCY, SfxCallMode::RECORD,
83 { &aItem });
86 void TextEffectPropertyPanel::UpdateControls()
88 const bool bTEnabled = mxTGlowRadius->get_value(FieldUnit::MM_100TH) != 0;
89 mxLBTGlowColor->set_sensitive(bTEnabled);
90 mxTGlowTransparency->set_sensitive(bTEnabled);
91 mxFTTColor->set_sensitive(bTEnabled);
92 mxFTTTransparency->set_sensitive(bTEnabled);
95 void TextEffectPropertyPanel::NotifyItemUpdate(sal_uInt16 nSID, SfxItemState eState,
96 const SfxPoolItem* pState)
98 switch (nSID)
100 case SID_ATTR_GLOW_TEXT_COLOR:
102 if (eState >= SfxItemState::DEFAULT)
104 const XColorItem* pColorItem = dynamic_cast<const XColorItem*>(pState);
105 if (pColorItem)
107 mxLBTGlowColor->SelectEntry(pColorItem->GetColorValue());
111 break;
112 case SID_ATTR_GLOW_TEXT_RADIUS:
114 if (eState >= SfxItemState::DEFAULT)
116 const SdrMetricItem* pRadiusItem = dynamic_cast<const SdrMetricItem*>(pState);
117 if (pRadiusItem)
119 mxTGlowRadius->set_value(pRadiusItem->GetValue(), FieldUnit::MM_100TH);
123 break;
124 case SID_ATTR_GLOW_TEXT_TRANSPARENCY:
126 if (eState >= SfxItemState::DEFAULT)
128 if (auto pItem = dynamic_cast<const SdrPercentItem*>(pState))
130 mxTGlowTransparency->set_value(pItem->GetValue(), FieldUnit::PERCENT);
134 break;
136 UpdateControls();
139 std::unique_ptr<PanelLayout> TextEffectPropertyPanel::Create(weld::Widget* pParent,
140 SfxBindings* pBindings)
142 if (pParent == nullptr)
143 throw css::lang::IllegalArgumentException(
144 u"no parent Window given to TextEffectPropertyPanel::Create"_ustr, nullptr, 0);
145 if (pBindings == nullptr)
146 throw css::lang::IllegalArgumentException(
147 u"no SfxBindings given to TextEffectPropertyPanel::Create"_ustr, nullptr, 2);
149 return std::make_unique<TextEffectPropertyPanel>(pParent, pBindings);
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */