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/.
10 #include "ChartLinePanel.hxx"
12 #include <PropertyHelper.hxx>
13 #include <ChartController.hxx>
15 #include <svx/xlineit0.hxx>
16 #include <svx/xlnwtit.hxx>
17 #include <svx/xlinjoit.hxx>
18 #include <svx/xlndsit.hxx>
19 #include <svx/xlntrit.hxx>
20 #include <svx/unomid.hxx>
22 #include <svx/tbcontrl.hxx>
23 #include <sfx2/sidebar/SidebarToolBox.hxx>
24 #include <vcl/svapp.hxx>
26 #include <com/sun/star/view/XSelectionSupplier.hpp>
27 #include <com/sun/star/util/XModifyBroadcaster.hpp>
28 #include <com/sun/star/chart2/XDiagram.hpp>
30 #include <comphelper/lok.hxx>
31 #include <sfx2/viewsh.hxx>
32 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
34 namespace chart
{ namespace sidebar
{
38 SvxColorToolBoxControl
* getColorToolBoxControl(sfx2::sidebar::SidebarToolBox
* pToolBoxColor
)
40 css::uno::Reference
<css::frame::XToolbarController
> xController
= pToolBoxColor
->GetFirstController();
41 SvxColorToolBoxControl
* pToolBoxColorControl
= dynamic_cast<SvxColorToolBoxControl
*>(xController
.get());
42 return pToolBoxColorControl
;
45 OUString
getCID(const css::uno::Reference
<css::frame::XModel
>& xModel
)
47 css::uno::Reference
<css::frame::XController
> xController(xModel
->getCurrentController());
48 css::uno::Reference
<css::view::XSelectionSupplier
> xSelectionSupplier(xController
, css::uno::UNO_QUERY
);
49 if (!xSelectionSupplier
.is())
52 css::uno::Any aAny
= xSelectionSupplier
->getSelection();
55 xSelectionSupplier
->select(css::uno::makeAny(OUString("CID/Page=")));
56 aAny
= xSelectionSupplier
->getSelection();
65 css::uno::Reference
<css::beans::XPropertySet
> getPropSet(
66 const css::uno::Reference
<css::frame::XModel
>& xModel
)
68 OUString aCID
= getCID(xModel
);
69 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
70 ObjectIdentifier::getObjectPropertySet(aCID
, xModel
);
72 ObjectType eType
= ObjectIdentifier::getObjectType(aCID
);
73 if (eType
== OBJECTTYPE_DIAGRAM
)
75 css::uno::Reference
<css::chart2::XDiagram
> xDiagram(
76 xPropSet
, css::uno::UNO_QUERY
);
80 xPropSet
.set(xDiagram
->getWall());
86 css::uno::Any
getLineDash(
87 const css::uno::Reference
<css::frame::XModel
>& xModel
, const OUString
& rDashName
)
89 css::uno::Reference
<css::lang::XMultiServiceFactory
> xFact(xModel
, css::uno::UNO_QUERY
);
90 css::uno::Reference
<css::container::XNameAccess
> xNameAccess(
91 xFact
->createInstance("com.sun.star.drawing.DashTable"),
92 css::uno::UNO_QUERY
);
95 if (!xNameAccess
->hasByName(rDashName
))
96 return css::uno::Any();
98 return xNameAccess
->getByName(rDashName
);
101 return css::uno::Any();
107 explicit PreventUpdate(bool& bUpdate
):
124 VclPtr
<vcl::Window
> ChartLinePanel::Create(
125 vcl::Window
* pParent
,
126 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
127 ChartController
* pController
)
129 if (pParent
== nullptr)
130 throw css::lang::IllegalArgumentException("no parent Window given to ChartAxisPanel::Create", nullptr, 0);
132 throw css::lang::IllegalArgumentException("no XFrame given to ChartAxisPanel::Create", nullptr, 1);
134 return VclPtr
<ChartLinePanel
>::Create(
135 pParent
, rxFrame
, pController
);
138 ChartLinePanel::ChartLinePanel(vcl::Window
* pParent
,
139 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
140 ChartController
* pController
):
141 svx::sidebar::LinePropertyPanelBase(pParent
, rxFrame
),
142 mxModel(pController
->getModel()),
143 mxListener(new ChartSidebarModifyListener(this)),
144 mxSelectionListener(new ChartSidebarSelectionListener(this)),
147 maLineColorWrapper(mxModel
, getColorToolBoxControl(mpTBColor
.get()), "LineColor")
150 std::vector
<ObjectType
> aAcceptedTypes
{ OBJECTTYPE_PAGE
, OBJECTTYPE_DIAGRAM
,
151 OBJECTTYPE_DATA_SERIES
, OBJECTTYPE_DATA_POINT
,
152 OBJECTTYPE_TITLE
, OBJECTTYPE_LEGEND
, OBJECTTYPE_DATA_CURVE
,
153 OBJECTTYPE_DATA_AVERAGE_LINE
, OBJECTTYPE_AXIS
};
154 mxSelectionListener
->setAcceptedTypes(aAcceptedTypes
);
158 ChartLinePanel::~ChartLinePanel()
163 void ChartLinePanel::dispose()
165 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcaster(mxModel
, css::uno::UNO_QUERY_THROW
);
166 xBroadcaster
->removeModifyListener(mxListener
);
168 css::uno::Reference
<css::view::XSelectionSupplier
> xSelectionSupplier(mxModel
->getCurrentController(), css::uno::UNO_QUERY
);
169 if (xSelectionSupplier
.is())
170 xSelectionSupplier
->removeSelectionChangeListener(mxSelectionListener
.get());
172 LinePropertyPanelBase::dispose();
175 void ChartLinePanel::Initialize()
177 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcaster(mxModel
, css::uno::UNO_QUERY_THROW
);
178 xBroadcaster
->addModifyListener(mxListener
);
180 css::uno::Reference
<css::view::XSelectionSupplier
> xSelectionSupplier(mxModel
->getCurrentController(), css::uno::UNO_QUERY
);
181 if (xSelectionSupplier
.is())
182 xSelectionSupplier
->addSelectionChangeListener(mxSelectionListener
.get());
184 SvxColorToolBoxControl
* pToolBoxColor
= getColorToolBoxControl(mpTBColor
.get());
185 pToolBoxColor
->setColorSelectFunction(maLineColorWrapper
);
187 setMapUnit(MapUnit::Map100thMM
);
191 void ChartLinePanel::updateData()
193 if (!mbUpdate
|| !mbModelValid
)
196 SolarMutexGuard aGuard
;
197 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
= getPropSet(mxModel
);
201 sal_uInt16 nLineTransparence
= 0;
202 xPropSet
->getPropertyValue("LineTransparence") >>= nLineTransparence
;
203 XLineTransparenceItem
aLineTransparenceItem(nLineTransparence
);
204 updateLineTransparence(false, true, &aLineTransparenceItem
);
206 css::drawing::LineStyle eStyle
= css::drawing::LineStyle_SOLID
;
207 xPropSet
->getPropertyValue("LineStyle") >>= eStyle
;
208 XLineStyleItem
aStyleItem(eStyle
);
209 updateLineStyle(false, true, &aStyleItem
);
212 xPropSet
->getPropertyValue("LineWidth") >>= nWidth
;
213 XLineWidthItem
aWidthItem(nWidth
);
214 updateLineWidth(false, true, &aWidthItem
);
216 css::uno::Any aLineDashName
= xPropSet
->getPropertyValue("LineDashName");
218 aLineDashName
>>= aDashName
;
219 css::uno::Any aLineDash
= getLineDash(mxModel
, aDashName
);
220 XLineDashItem aDashItem
;
221 aDashItem
.PutValue(aLineDash
, MID_LINEDASH
);
222 updateLineDash(false, true, &aDashItem
);
224 maLineColorWrapper
.updateData();
227 void ChartLinePanel::modelInvalid()
229 mbModelValid
= false;
232 void ChartLinePanel::selectionChanged(bool bCorrectType
)
238 void ChartLinePanel::updateModel(
239 css::uno::Reference
<css::frame::XModel
> xModel
)
243 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcaster(mxModel
, css::uno::UNO_QUERY_THROW
);
244 xBroadcaster
->removeModifyListener(mxListener
);
250 maLineColorWrapper
.updateModel(mxModel
);
252 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcasterNew(mxModel
, css::uno::UNO_QUERY_THROW
);
253 xBroadcasterNew
->addModifyListener(mxListener
);
255 css::uno::Reference
<css::view::XSelectionSupplier
> xSelectionSupplier(mxModel
->getCurrentController(), css::uno::UNO_QUERY
);
256 if (xSelectionSupplier
.is())
257 xSelectionSupplier
->addSelectionChangeListener(mxSelectionListener
.get());
260 void ChartLinePanel::setLineStyle(const XLineStyleItem
& rItem
)
262 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
268 PreventUpdate
aPreventUpdate(mbUpdate
);
269 xPropSet
->setPropertyValue("LineStyle", css::uno::Any(rItem
.GetValue()));
272 void ChartLinePanel::setLineDash(const XLineDashItem
& rItem
)
274 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
280 PreventUpdate
aPreventUpdate(mbUpdate
);
282 rItem
.QueryValue(aAny
, MID_LINEDASH
);
283 OUString aDashName
= PropertyHelper::addLineDashUniqueNameToTable(aAny
,
284 css::uno::Reference
<css::lang::XMultiServiceFactory
>(mxModel
, css::uno::UNO_QUERY
),
286 xPropSet
->setPropertyValue("LineDash", aAny
);
287 xPropSet
->setPropertyValue("LineDashName", css::uno::Any(aDashName
));
290 void ChartLinePanel::setLineEndStyle(const XLineEndItem
* /*pItem*/)
294 void ChartLinePanel::setLineStartStyle(const XLineStartItem
* /*pItem*/)
298 void ChartLinePanel::setLineJoint(const XLineJointItem
* pItem
)
300 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
306 PreventUpdate
aPreventUpdate(mbUpdate
);
308 xPropSet
->setPropertyValue("LineJoint", css::uno::Any(pItem
->GetValue()));
311 void ChartLinePanel::setLineCap(const XLineCapItem
* /*pItem*/)
315 void ChartLinePanel::setLineTransparency(const XLineTransparenceItem
& rItem
)
317 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
323 PreventUpdate
aPreventUpdate(mbUpdate
);
324 xPropSet
->setPropertyValue("LineTransparence", css::uno::Any(rItem
.GetValue()));
327 void ChartLinePanel::setLineWidth(const XLineWidthItem
& rItem
)
329 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
=
335 PreventUpdate
aPreventUpdate(mbUpdate
);
336 xPropSet
->setPropertyValue("LineWidth", css::uno::Any(rItem
.GetValue()));
339 void ChartLinePanel::updateLineWidth(bool bDisabled
, bool bSetOrDefault
, const SfxPoolItem
* pItem
)
341 LinePropertyPanelBase::updateLineWidth(bDisabled
, bSetOrDefault
, pItem
);
343 SfxViewShell
* pViewShell
= SfxViewShell::Current();
344 if (comphelper::LibreOfficeKit::isActive() && pViewShell
)
346 pViewShell
->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED
,
347 (".uno:LineWidth=" + std::to_string(mnWidthCoreValue
)).c_str());
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */