Bump version to 24.04.3.4
[LibreOffice.git] / svx / source / sidebar / graphic / GraphicPropertyPanel.cxx
blob11a3130d466b1b4760271742a4d53047f7acd6c0
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 "GraphicPropertyPanel.hxx"
21 #include <svx/strings.hrc>
22 #include <svx/svxids.hrc>
23 #include <svx/dialmgr.hxx>
24 #include <svl/intitem.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 #include <svl/itemset.hxx>
30 using namespace css;
31 using namespace css::uno;
34 // namespace open
36 namespace svx::sidebar {
39 GraphicPropertyPanel::GraphicPropertyPanel(
40 weld::Widget* pParent,
41 SfxBindings* pBindings)
42 : PanelLayout(pParent, "GraphicPropertyPanel", "svx/ui/sidebargraphic.ui"),
43 maBrightControl(SID_ATTR_GRAF_LUMINANCE, *pBindings, *this),
44 maContrastControl(SID_ATTR_GRAF_CONTRAST, *pBindings, *this),
45 maTransparenceControl(SID_ATTR_GRAF_TRANSPARENCE, *pBindings, *this),
46 maRedControl(SID_ATTR_GRAF_RED, *pBindings, *this),
47 maGreenControl(SID_ATTR_GRAF_GREEN, *pBindings, *this),
48 maBlueControl(SID_ATTR_GRAF_BLUE, *pBindings, *this),
49 maGammaControl(SID_ATTR_GRAF_GAMMA, *pBindings, *this),
50 maModeControl(SID_ATTR_GRAF_MODE, *pBindings, *this),
51 mpBindings(pBindings),
52 mxMtrBrightness(m_xBuilder->weld_metric_spin_button("setbrightness", FieldUnit::PERCENT)),
53 mxMtrContrast(m_xBuilder->weld_metric_spin_button("setcontrast", FieldUnit::PERCENT)),
54 mxLBColorMode(m_xBuilder->weld_combo_box("setcolormode")),
55 mxMtrTrans(m_xBuilder->weld_metric_spin_button("setgraphtransparency", FieldUnit::PERCENT))
57 mxLBColorMode->set_size_request(mxLBColorMode->get_preferred_size().Width(), -1);
58 Initialize();
61 GraphicPropertyPanel::~GraphicPropertyPanel()
63 mxMtrBrightness.reset();
64 mxMtrContrast.reset();
65 mxLBColorMode.reset();
66 mxMtrTrans.reset();
68 maBrightControl.dispose();
69 maContrastControl.dispose();
70 maTransparenceControl.dispose();
71 maRedControl.dispose();
72 maGreenControl.dispose();
73 maBlueControl.dispose();
74 maGammaControl.dispose();
75 maModeControl.dispose();
78 void GraphicPropertyPanel::Initialize()
80 mxMtrBrightness->connect_value_changed( LINK( this, GraphicPropertyPanel, ModifyBrightnessHdl ) );
81 mxMtrContrast->connect_value_changed( LINK( this, GraphicPropertyPanel, ModifyContrastHdl ) );
82 mxMtrTrans->connect_value_changed( LINK( this, GraphicPropertyPanel, ModifyTransHdl ) );
84 mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_STANDARD));
85 mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_GREYS));
86 mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_MONO));
87 mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_WATERMARK));
88 mxLBColorMode->connect_changed( LINK( this, GraphicPropertyPanel, ClickColorModeHdl ));
91 IMPL_LINK_NOARG( GraphicPropertyPanel, ModifyBrightnessHdl, weld::MetricSpinButton&, void )
93 const sal_Int16 nBright = mxMtrBrightness->get_value(FieldUnit::PERCENT);
94 const SfxInt16Item aBrightItem( SID_ATTR_GRAF_LUMINANCE, nBright );
95 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_LUMINANCE,
96 SfxCallMode::RECORD, { &aBrightItem });
100 IMPL_LINK_NOARG( GraphicPropertyPanel, ModifyContrastHdl, weld::MetricSpinButton&, void )
102 const sal_Int16 nContrast = mxMtrContrast->get_value(FieldUnit::PERCENT);
103 const SfxInt16Item aContrastItem( SID_ATTR_GRAF_CONTRAST, nContrast );
104 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_CONTRAST,
105 SfxCallMode::RECORD, { &aContrastItem });
109 IMPL_LINK_NOARG( GraphicPropertyPanel, ModifyTransHdl, weld::MetricSpinButton&, void )
111 const sal_Int16 nTrans = mxMtrTrans->get_value(FieldUnit::PERCENT);
112 const SfxUInt16Item aTransItem( SID_ATTR_GRAF_TRANSPARENCE, nTrans );
113 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_TRANSPARENCE,
114 SfxCallMode::RECORD, { &aTransItem });
118 IMPL_LINK_NOARG( GraphicPropertyPanel, ClickColorModeHdl, weld::ComboBox&, void )
120 const sal_Int16 nTrans = mxLBColorMode->get_active();
121 const SfxUInt16Item aTransItem( SID_ATTR_GRAF_MODE, nTrans );
122 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_MODE,
123 SfxCallMode::RECORD, { &aTransItem });
126 std::unique_ptr<PanelLayout> GraphicPropertyPanel::Create (
127 weld::Widget* pParent,
128 SfxBindings* pBindings)
130 if (pParent == nullptr)
131 throw lang::IllegalArgumentException("no parent Window given to GraphicPropertyPanel::Create", nullptr, 0);
132 if (pBindings == nullptr)
133 throw lang::IllegalArgumentException("no SfxBindings given to GraphicPropertyPanel::Create", nullptr, 2);
135 return std::make_unique<GraphicPropertyPanel>(pParent, pBindings);
138 void GraphicPropertyPanel::NotifyItemUpdate(
139 sal_uInt16 nSID,
140 SfxItemState eState,
141 const SfxPoolItem* pState)
143 switch( nSID )
145 case SID_ATTR_GRAF_LUMINANCE:
147 if(eState >= SfxItemState::DEFAULT)
149 mxMtrBrightness->set_sensitive(true);
150 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
152 if(pItem)
154 const sal_Int64 nBright = pItem->GetValue();
155 mxMtrBrightness->set_value(nBright, FieldUnit::PERCENT);
158 else if(SfxItemState::DISABLED == eState)
160 mxMtrBrightness->set_sensitive(false);
162 else
164 mxMtrBrightness->set_sensitive(true);
165 mxMtrBrightness->set_text(OUString());
167 break;
169 case SID_ATTR_GRAF_CONTRAST:
171 if(eState >= SfxItemState::DEFAULT)
173 mxMtrContrast->set_sensitive(true);
174 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
176 if(pItem)
178 const sal_Int64 nContrast = pItem->GetValue();
179 mxMtrContrast->set_value(nContrast, FieldUnit::PERCENT);
182 else if(SfxItemState::DISABLED == eState)
184 mxMtrContrast->set_sensitive(false);
186 else
188 mxMtrContrast->set_sensitive(true);
189 mxMtrContrast->set_text(OUString());
191 break;
193 case SID_ATTR_GRAF_TRANSPARENCE:
195 if(eState >= SfxItemState::DEFAULT)
197 mxMtrTrans->set_sensitive(true);
198 const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
200 if(pItem)
202 const sal_Int64 nTrans = pItem->GetValue();
203 mxMtrTrans->set_value(nTrans, FieldUnit::PERCENT);
206 else if(SfxItemState::DISABLED == eState)
208 mxMtrTrans->set_sensitive(false);
210 else
212 mxMtrTrans->set_sensitive(true);
213 mxMtrTrans->set_text(OUString());
215 break;
217 case SID_ATTR_GRAF_MODE:
219 if(eState >= SfxItemState::DEFAULT)
221 mxLBColorMode->set_sensitive(true);
223 if(pState)
225 const sal_uInt16 nTrans = static_cast< const SfxUInt16Item* >(pState)->GetValue();
226 mxLBColorMode->set_active(nTrans);
229 else if(SfxItemState::DISABLED == eState)
231 mxLBColorMode->set_sensitive(false);
233 else
235 mxLBColorMode->set_sensitive(true);
236 mxLBColorMode->set_active(-1);
238 break;
243 // namespace close
245 } // end of namespace svx::sidebar
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */