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/.
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 .
21 #include <svx/sidebar/LinePropertyPanelBase.hxx>
22 #include <sfx2/weldutils.hxx>
23 #include <svx/linectrl.hxx>
24 #include <svx/xlnwtit.hxx>
25 #include <svx/xlntrit.hxx>
26 #include <svx/xlncapit.hxx>
27 #include <svx/xlinjoit.hxx>
28 #include <svx/xtable.hxx>
29 #include <bitmaps.hlst>
32 using namespace css::uno
;
34 constexpr OUString SELECTWIDTH
= u
"SelectWidth"_ustr
;
36 namespace svx::sidebar
{
38 // trigger disabling the arrows if the none line style is selected
39 class LineStyleNoneChange
42 LinePropertyPanelBase
& m_rPanel
;
45 LineStyleNoneChange(LinePropertyPanelBase
& rPanel
)
50 void operator()(bool bLineStyleNone
)
52 m_rPanel
.SetNoneLineStyle(bLineStyleNone
);
58 SvxLineStyleToolBoxControl
* getLineStyleToolBoxControl(const ToolbarUnoDispatcher
& rToolBoxColor
)
60 css::uno::Reference
<css::frame::XToolbarController
> xController
= rToolBoxColor
.GetControllerForCommand(".uno:XLineStyle");
61 SvxLineStyleToolBoxControl
* pToolBoxLineStyleControl
= dynamic_cast<SvxLineStyleToolBoxControl
*>(xController
.get());
62 return pToolBoxLineStyleControl
;
67 LinePropertyPanelBase::LinePropertyPanelBase(
68 weld::Widget
* pParent
,
69 const uno::Reference
<css::frame::XFrame
>& rxFrame
)
70 : PanelLayout(pParent
, "LinePropertyPanel", "svx/ui/sidebarline.ui"),
71 mxTBColor(m_xBuilder
->weld_toolbar("color")),
72 mxColorDispatch(new ToolbarUnoDispatcher(*mxTBColor
, *m_xBuilder
, rxFrame
)),
73 mxLineStyleTB(m_xBuilder
->weld_toolbar("linestyle")),
74 mxLineStyleDispatch(new ToolbarUnoDispatcher(*mxLineStyleTB
, *m_xBuilder
, rxFrame
)),
76 mxFTWidth(m_xBuilder
->weld_label("widthlabel")),
77 mxTBWidth(m_xBuilder
->weld_toolbar("width")),
78 mxFTTransparency(m_xBuilder
->weld_label("translabel")),
79 mxMFTransparent(m_xBuilder
->weld_metric_spin_button("linetransparency", FieldUnit::PERCENT
)),
80 mxFTEdgeStyle(m_xBuilder
->weld_label("cornerlabel")),
81 mxLBEdgeStyle(m_xBuilder
->weld_combo_box("edgestyle")),
82 mxFTCapStyle(m_xBuilder
->weld_label("caplabel")),
83 mxLBCapStyle(m_xBuilder
->weld_combo_box("linecapstyle")),
84 mxGridLineProps(m_xBuilder
->weld_widget("lineproperties")),
85 mxBoxArrowProps(m_xBuilder
->weld_widget("arrowproperties")),
86 mxLineWidthPopup(new LineWidthPopup(mxTBWidth
.get(), *this)),
87 mxLineStyleNoneChange(new LineStyleNoneChange(*this)),
89 meMapUnit(MapUnit::MapMM
),
90 maIMGNone(BMP_NONE_ICON
),
91 mbWidthValuable(true),
92 mbArrowSupported(true),
93 mbNoneLineStyle(false)
98 LinePropertyPanelBase::~LinePropertyPanelBase()
100 mxLineWidthPopup
.reset();
103 mxColorDispatch
.reset();
105 mxFTTransparency
.reset();
106 mxMFTransparent
.reset();
107 mxLineStyleDispatch
.reset();
108 mxLineStyleTB
.reset();
109 mxFTEdgeStyle
.reset();
110 mxLBEdgeStyle
.reset();
111 mxFTCapStyle
.reset();
112 mxLBCapStyle
.reset();
113 mxGridLineProps
.reset();
114 mxBoxArrowProps
.reset();
117 void LinePropertyPanelBase::Initialize()
119 mxTBWidth
->set_item_popover(SELECTWIDTH
, mxLineWidthPopup
->getTopLevel());
121 maIMGWidthIcon
[0] = XDashList::CreateBitmapForXDash(nullptr, 1);
122 maIMGWidthIcon
[1] = XDashList::CreateBitmapForXDash(nullptr, 2);
123 maIMGWidthIcon
[2] = XDashList::CreateBitmapForXDash(nullptr, 3);
124 maIMGWidthIcon
[3] = XDashList::CreateBitmapForXDash(nullptr, 4);
125 maIMGWidthIcon
[4] = XDashList::CreateBitmapForXDash(nullptr, 5);
126 maIMGWidthIcon
[5] = XDashList::CreateBitmapForXDash(nullptr, 6);
127 maIMGWidthIcon
[6] = XDashList::CreateBitmapForXDash(nullptr, 7);
128 maIMGWidthIcon
[7] = XDashList::CreateBitmapForXDash(nullptr, 8);
130 Graphic
aGraf(maIMGWidthIcon
[0]);
131 mxTBWidth
->set_item_image(SELECTWIDTH
, aGraf
.GetXGraphic());
132 mxTBWidth
->connect_clicked(LINK(this, LinePropertyPanelBase
, ToolboxWidthSelectHdl
));
134 mxMFTransparent
->connect_value_changed(LINK(this, LinePropertyPanelBase
, ChangeTransparentHdl
));
136 mxLBEdgeStyle
->connect_changed( LINK( this, LinePropertyPanelBase
, ChangeEdgeStyleHdl
) );
138 mxLBCapStyle
->connect_changed( LINK( this, LinePropertyPanelBase
, ChangeCapStyleHdl
) );
140 SvxLineStyleToolBoxControl
* pLineStyleControl
= getLineStyleToolBoxControl(*mxLineStyleDispatch
);
141 pLineStyleControl
->setLineStyleIsNoneFunction(*mxLineStyleNoneChange
);
144 void LinePropertyPanelBase::updateLineTransparence(bool bDisabled
, bool bSetOrDefault
,
145 const SfxPoolItem
* pState
)
149 mxFTTransparency
->set_sensitive(false);
150 mxMFTransparent
->set_sensitive(false);
154 mxFTTransparency
->set_sensitive(true);
155 mxMFTransparent
->set_sensitive(true);
160 if (const XLineTransparenceItem
* pItem
= dynamic_cast<const XLineTransparenceItem
*>(pState
))
162 mnTrans
= pItem
->GetValue();
163 mxMFTransparent
->set_value(mnTrans
, FieldUnit::PERCENT
);
168 mxMFTransparent
->set_value(0, FieldUnit::PERCENT
);//add
169 mxMFTransparent
->set_text(OUString());
172 void LinePropertyPanelBase::updateLineWidth(bool bDisabled
, bool bSetOrDefault
,
173 const SfxPoolItem
* pState
)
177 mxTBWidth
->set_sensitive(false);
178 mxFTWidth
->set_sensitive(false);
182 mxTBWidth
->set_sensitive(true);
183 mxFTWidth
->set_sensitive(true);
188 if (const XLineWidthItem
* pItem
= dynamic_cast<const XLineWidthItem
*>(pState
))
190 mnWidthCoreValue
= pItem
->GetValue();
191 mbWidthValuable
= true;
197 mbWidthValuable
= false;
201 void LinePropertyPanelBase::updateLineJoint(bool bDisabled
, bool bSetOrDefault
,
202 const SfxPoolItem
* pState
)
206 mxLBEdgeStyle
->set_sensitive(false);
207 mxFTEdgeStyle
->set_sensitive(false);
211 mxLBEdgeStyle
->set_sensitive(true);
212 mxFTEdgeStyle
->set_sensitive(true);
217 if (const XLineJointItem
* pItem
= dynamic_cast<const XLineJointItem
*>(pState
))
219 sal_Int32
nEntryPos(0);
221 switch(pItem
->GetValue())
223 case drawing::LineJoint_ROUND
:
228 case drawing::LineJoint_NONE
:
233 case drawing::LineJoint_MIDDLE
:
234 case drawing::LineJoint_MITER
:
239 case drawing::LineJoint_BEVEL
:
251 mxLBEdgeStyle
->set_active(nEntryPos
- 1);
257 mxLBEdgeStyle
->set_active(-1);
260 void LinePropertyPanelBase::updateLineCap(bool bDisabled
, bool bSetOrDefault
,
261 const SfxPoolItem
* pState
)
263 mxLBCapStyle
->set_sensitive(!bDisabled
);
264 mxFTCapStyle
->set_sensitive(!bDisabled
);
268 if (const XLineCapItem
* pItem
= dynamic_cast<const XLineCapItem
*>(pState
))
270 sal_Int32
nEntryPos(0);
272 switch(pItem
->GetValue())
274 case drawing::LineCap_BUTT
:
279 case drawing::LineCap_ROUND
:
284 case drawing::LineCap_SQUARE
:
296 mxLBCapStyle
->set_active(nEntryPos
- 1);
302 mxLBCapStyle
->set_active(-1);
305 IMPL_LINK_NOARG(LinePropertyPanelBase
, ChangeEdgeStyleHdl
, weld::ComboBox
&, void)
307 const sal_Int32
nPos(mxLBEdgeStyle
->get_active());
309 if (nPos
== -1 || !mxLBEdgeStyle
->get_value_changed_from_saved())
312 std::unique_ptr
<XLineJointItem
> pItem
;
318 pItem
.reset(new XLineJointItem(drawing::LineJoint_ROUND
));
323 pItem
.reset(new XLineJointItem(drawing::LineJoint_NONE
));
328 pItem
.reset(new XLineJointItem(drawing::LineJoint_MITER
));
333 pItem
.reset(new XLineJointItem(drawing::LineJoint_BEVEL
));
338 setLineJoint(pItem
.get());
341 IMPL_LINK_NOARG(LinePropertyPanelBase
, ChangeCapStyleHdl
, weld::ComboBox
&, void)
343 const sal_Int32
nPos(mxLBCapStyle
->get_active());
345 if (!(nPos
!= -1 && mxLBCapStyle
->get_value_changed_from_saved()))
348 std::unique_ptr
<XLineCapItem
> pItem
;
354 pItem
.reset(new XLineCapItem(drawing::LineCap_BUTT
));
359 pItem
.reset(new XLineCapItem(drawing::LineCap_ROUND
));
364 pItem
.reset(new XLineCapItem(drawing::LineCap_SQUARE
));
369 setLineCap(pItem
.get());
372 IMPL_LINK_NOARG(LinePropertyPanelBase
, ToolboxWidthSelectHdl
, const OUString
&, void)
374 mxTBWidth
->set_menu_item_active(SELECTWIDTH
, !mxTBWidth
->get_menu_item_active(SELECTWIDTH
));
377 void LinePropertyPanelBase::EndLineWidthPopup()
379 mxTBWidth
->set_menu_item_active(SELECTWIDTH
, false);
382 IMPL_LINK_NOARG( LinePropertyPanelBase
, ChangeTransparentHdl
, weld::MetricSpinButton
&, void )
384 sal_uInt16 nVal
= static_cast<sal_uInt16
>(mxMFTransparent
->get_value(FieldUnit::PERCENT
));
385 XLineTransparenceItem
aItem( nVal
);
387 setLineTransparency(aItem
);
390 void LinePropertyPanelBase::SetWidthIcon(int n
)
393 mxTBWidth
->set_item_icon_name(SELECTWIDTH
, maIMGNone
);
396 Graphic
aGraf(maIMGWidthIcon
[n
-1]);
397 mxTBWidth
->set_item_image(SELECTWIDTH
, aGraf
.GetXGraphic());
401 void LinePropertyPanelBase::SetWidthIcon()
405 mxTBWidth
->set_item_icon_name(SELECTWIDTH
, maIMGNone
);
409 tools::Long nVal
= OutputDevice::LogicToLogic(mnWidthCoreValue
* 10, meMapUnit
, MapUnit::MapPoint
);
413 aGraf
= Graphic(maIMGWidthIcon
[0]);
415 aGraf
= Graphic(maIMGWidthIcon
[1]);
417 aGraf
= Graphic(maIMGWidthIcon
[2]);
419 aGraf
= Graphic(maIMGWidthIcon
[3]);
421 aGraf
= Graphic(maIMGWidthIcon
[4]);
423 aGraf
= Graphic(maIMGWidthIcon
[5]);
425 aGraf
= Graphic(maIMGWidthIcon
[6]);
427 aGraf
= Graphic(maIMGWidthIcon
[7]);
428 mxTBWidth
->set_item_image(SELECTWIDTH
, aGraf
.GetXGraphic());
431 void LinePropertyPanelBase::SetWidth(tools::Long nWidth
)
433 mnWidthCoreValue
= nWidth
;
434 mbWidthValuable
= true;
435 mxLineWidthPopup
->SetWidthSelect(mnWidthCoreValue
, mbWidthValuable
, meMapUnit
);
438 void LinePropertyPanelBase::ActivateControls()
440 mxGridLineProps
->set_sensitive(!mbNoneLineStyle
);
441 mxBoxArrowProps
->set_sensitive(!mbNoneLineStyle
);
442 mxLineStyleTB
->set_item_sensitive(".uno:LineEndStyle", !mbNoneLineStyle
);
444 mxBoxArrowProps
->set_visible(mbArrowSupported
);
445 mxLineStyleTB
->set_item_visible(".uno:LineEndStyle", mbArrowSupported
);
448 void LinePropertyPanelBase::setMapUnit(MapUnit eMapUnit
)
450 meMapUnit
= eMapUnit
;
451 mxLineWidthPopup
->SetWidthSelect(mnWidthCoreValue
, mbWidthValuable
, meMapUnit
);
454 void LinePropertyPanelBase::disableArrowHead()
456 mbArrowSupported
= false;
460 void LinePropertyPanelBase::enableArrowHead()
462 mbArrowSupported
= true;
466 } // end of namespace svx::sidebar
468 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */