vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / chart2 / source / controller / sidebar / ChartLinePanel.cxx
blobfe26ec66c0ecc248d68731e0a6e0972a4a34bf76
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 "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 {
36 namespace {
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())
50 return OUString();
52 css::uno::Any aAny = xSelectionSupplier->getSelection();
53 if (!aAny.hasValue())
55 xSelectionSupplier->select(css::uno::makeAny(OUString("CID/Page=")));
56 aAny = xSelectionSupplier->getSelection();
59 OUString aCID;
60 aAny >>= aCID;
62 return aCID;
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);
77 if (!xDiagram.is())
78 return xPropSet;
80 xPropSet.set(xDiagram->getWall());
83 return xPropSet;
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 );
93 if(xNameAccess.is())
95 if (!xNameAccess->hasByName(rDashName))
96 return css::uno::Any();
98 return xNameAccess->getByName(rDashName);
101 return css::uno::Any();
104 class PreventUpdate
106 public:
107 explicit PreventUpdate(bool& bUpdate):
108 mbUpdate(bUpdate)
110 mbUpdate = false;
113 ~PreventUpdate()
115 mbUpdate = true;
118 private:
119 bool& mbUpdate;
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);
131 if (!rxFrame.is())
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)),
145 mbUpdate(true),
146 mbModelValid(true),
147 maLineColorWrapper(mxModel, getColorToolBoxControl(mpTBColor.get()), "LineColor")
149 disableArrowHead();
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);
155 Initialize();
158 ChartLinePanel::~ChartLinePanel()
160 disposeOnce();
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);
188 updateData();
191 void ChartLinePanel::updateData()
193 if (!mbUpdate || !mbModelValid)
194 return;
196 SolarMutexGuard aGuard;
197 css::uno::Reference<css::beans::XPropertySet> xPropSet = getPropSet(mxModel);
198 if (!xPropSet.is())
199 return;
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);
211 sal_uInt32 nWidth;
212 xPropSet->getPropertyValue("LineWidth") >>= nWidth;
213 XLineWidthItem aWidthItem(nWidth);
214 updateLineWidth(false, true, &aWidthItem);
216 css::uno::Any aLineDashName = xPropSet->getPropertyValue("LineDashName");
217 OUString aDashName;
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)
234 if (bCorrectType)
235 updateData();
238 void ChartLinePanel::updateModel(
239 css::uno::Reference<css::frame::XModel> xModel)
241 if (mbModelValid)
243 css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
244 xBroadcaster->removeModifyListener(mxListener);
247 mxModel = xModel;
248 mbModelValid = true;
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 =
263 getPropSet(mxModel);
265 if (!xPropSet.is())
266 return;
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 =
275 getPropSet(mxModel);
277 if (!xPropSet.is())
278 return;
280 PreventUpdate aPreventUpdate(mbUpdate);
281 css::uno::Any aAny;
282 rItem.QueryValue(aAny, MID_LINEDASH);
283 OUString aDashName = PropertyHelper::addLineDashUniqueNameToTable(aAny,
284 css::uno::Reference<css::lang::XMultiServiceFactory>(mxModel, css::uno::UNO_QUERY),
285 "");
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 =
301 getPropSet(mxModel);
303 if (!xPropSet.is())
304 return;
306 PreventUpdate aPreventUpdate(mbUpdate);
307 if (pItem)
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 =
318 getPropSet(mxModel);
320 if (!xPropSet.is())
321 return;
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 =
330 getPropSet(mxModel);
332 if (!xPropSet.is())
333 return;
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: */