Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / sidebar / graphic / GraphicPropertyPanel.cxx
blob5503649551e6cb740a4451c34c261085a4902655
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>
29 using namespace css;
30 using namespace css::uno;
33 // namespace open
35 namespace svx::sidebar {
38 GraphicPropertyPanel::GraphicPropertyPanel(
39 weld::Widget* pParent,
40 SfxBindings* pBindings)
41 : PanelLayout(pParent, "GraphicPropertyPanel", "svx/ui/sidebargraphic.ui"),
42 maBrightControl(SID_ATTR_GRAF_LUMINANCE, *pBindings, *this),
43 maContrastControl(SID_ATTR_GRAF_CONTRAST, *pBindings, *this),
44 maTransparenceControl(SID_ATTR_GRAF_TRANSPARENCE, *pBindings, *this),
45 maRedControl(SID_ATTR_GRAF_RED, *pBindings, *this),
46 maGreenControl(SID_ATTR_GRAF_GREEN, *pBindings, *this),
47 maBlueControl(SID_ATTR_GRAF_BLUE, *pBindings, *this),
48 maGammaControl(SID_ATTR_GRAF_GAMMA, *pBindings, *this),
49 maModeControl(SID_ATTR_GRAF_MODE, *pBindings, *this),
50 mpBindings(pBindings),
51 mxMtrBrightness(m_xBuilder->weld_metric_spin_button("setbrightness", FieldUnit::PERCENT)),
52 mxMtrContrast(m_xBuilder->weld_metric_spin_button("setcontrast", FieldUnit::PERCENT)),
53 mxLBColorMode(m_xBuilder->weld_combo_box("setcolormode")),
54 mxMtrTrans(m_xBuilder->weld_metric_spin_button("setgraphtransparency", FieldUnit::PERCENT))
56 mxLBColorMode->set_size_request(mxLBColorMode->get_preferred_size().Width(), -1);
57 Initialize();
60 GraphicPropertyPanel::~GraphicPropertyPanel()
62 mxMtrBrightness.reset();
63 mxMtrContrast.reset();
64 mxLBColorMode.reset();
65 mxMtrTrans.reset();
67 maBrightControl.dispose();
68 maContrastControl.dispose();
69 maTransparenceControl.dispose();
70 maRedControl.dispose();
71 maGreenControl.dispose();
72 maBlueControl.dispose();
73 maGammaControl.dispose();
74 maModeControl.dispose();
77 void GraphicPropertyPanel::Initialize()
79 mxMtrBrightness->connect_value_changed( LINK( this, GraphicPropertyPanel, ModifyBrightnessHdl ) );
80 mxMtrContrast->connect_value_changed( LINK( this, GraphicPropertyPanel, ModifyContrastHdl ) );
81 mxMtrTrans->connect_value_changed( LINK( this, GraphicPropertyPanel, ModifyTransHdl ) );
83 mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_STANDARD));
84 mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_GREYS));
85 mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_MONO));
86 mxLBColorMode->append_text(SvxResId(RID_SVXSTR_GRAFMODE_WATERMARK));
87 mxLBColorMode->connect_changed( LINK( this, GraphicPropertyPanel, ClickColorModeHdl ));
90 IMPL_LINK_NOARG( GraphicPropertyPanel, ModifyBrightnessHdl, weld::MetricSpinButton&, void )
92 const sal_Int16 nBright = mxMtrBrightness->get_value(FieldUnit::PERCENT);
93 const SfxInt16Item aBrightItem( SID_ATTR_GRAF_LUMINANCE, nBright );
94 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_LUMINANCE,
95 SfxCallMode::RECORD, { &aBrightItem });
99 IMPL_LINK_NOARG( GraphicPropertyPanel, ModifyContrastHdl, weld::MetricSpinButton&, void )
101 const sal_Int16 nContrast = mxMtrContrast->get_value(FieldUnit::PERCENT);
102 const SfxInt16Item aContrastItem( SID_ATTR_GRAF_CONTRAST, nContrast );
103 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_CONTRAST,
104 SfxCallMode::RECORD, { &aContrastItem });
108 IMPL_LINK_NOARG( GraphicPropertyPanel, ModifyTransHdl, weld::MetricSpinButton&, void )
110 const sal_Int16 nTrans = mxMtrTrans->get_value(FieldUnit::PERCENT);
111 const SfxUInt16Item aTransItem( SID_ATTR_GRAF_TRANSPARENCE, nTrans );
112 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_TRANSPARENCE,
113 SfxCallMode::RECORD, { &aTransItem });
117 IMPL_LINK_NOARG( GraphicPropertyPanel, ClickColorModeHdl, weld::ComboBox&, void )
119 const sal_Int16 nTrans = mxLBColorMode->get_active();
120 const SfxUInt16Item aTransItem( SID_ATTR_GRAF_MODE, nTrans );
121 GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_GRAF_MODE,
122 SfxCallMode::RECORD, { &aTransItem });
125 std::unique_ptr<PanelLayout> GraphicPropertyPanel::Create (
126 weld::Widget* pParent,
127 SfxBindings* pBindings)
129 if (pParent == nullptr)
130 throw lang::IllegalArgumentException("no parent Window given to GraphicPropertyPanel::Create", nullptr, 0);
131 if (pBindings == nullptr)
132 throw lang::IllegalArgumentException("no SfxBindings given to GraphicPropertyPanel::Create", nullptr, 2);
134 return std::make_unique<GraphicPropertyPanel>(pParent, pBindings);
137 void GraphicPropertyPanel::NotifyItemUpdate(
138 sal_uInt16 nSID,
139 SfxItemState eState,
140 const SfxPoolItem* pState)
142 switch( nSID )
144 case SID_ATTR_GRAF_LUMINANCE:
146 if(eState >= SfxItemState::DEFAULT)
148 mxMtrBrightness->set_sensitive(true);
149 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
151 if(pItem)
153 const sal_Int64 nBright = pItem->GetValue();
154 mxMtrBrightness->set_value(nBright, FieldUnit::PERCENT);
157 else if(SfxItemState::DISABLED == eState)
159 mxMtrBrightness->set_sensitive(false);
161 else
163 mxMtrBrightness->set_sensitive(true);
164 mxMtrBrightness->set_text(OUString());
166 break;
168 case SID_ATTR_GRAF_CONTRAST:
170 if(eState >= SfxItemState::DEFAULT)
172 mxMtrContrast->set_sensitive(true);
173 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
175 if(pItem)
177 const sal_Int64 nContrast = pItem->GetValue();
178 mxMtrContrast->set_value(nContrast, FieldUnit::PERCENT);
181 else if(SfxItemState::DISABLED == eState)
183 mxMtrContrast->set_sensitive(false);
185 else
187 mxMtrContrast->set_sensitive(true);
188 mxMtrContrast->set_text(OUString());
190 break;
192 case SID_ATTR_GRAF_TRANSPARENCE:
194 if(eState >= SfxItemState::DEFAULT)
196 mxMtrTrans->set_sensitive(true);
197 const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
199 if(pItem)
201 const sal_Int64 nTrans = pItem->GetValue();
202 mxMtrTrans->set_value(nTrans, FieldUnit::PERCENT);
205 else if(SfxItemState::DISABLED == eState)
207 mxMtrTrans->set_sensitive(false);
209 else
211 mxMtrTrans->set_sensitive(true);
212 mxMtrTrans->set_text(OUString());
214 break;
216 case SID_ATTR_GRAF_MODE:
218 if(eState >= SfxItemState::DEFAULT)
220 mxLBColorMode->set_sensitive(true);
222 if(pState)
224 const sal_uInt16 nTrans = static_cast< const SfxUInt16Item* >(pState)->GetValue();
225 mxLBColorMode->set_active(nTrans);
228 else if(SfxItemState::DISABLED == eState)
230 mxLBColorMode->set_sensitive(false);
232 else
234 mxLBColorMode->set_sensitive(true);
235 mxLBColorMode->set_active(-1);
237 break;
242 // namespace close
244 } // end of namespace svx::sidebar
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */