vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / chart2 / source / controller / sidebar / ChartColorWrapper.cxx
blobf6bd8725ea13f0de7be1d1734002561d367c7f93
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 "ChartColorWrapper.hxx"
12 #include <ObjectIdentifier.hxx>
13 #include <com/sun/star/chart2/XDiagram.hpp>
14 #include <com/sun/star/view/XSelectionSupplier.hpp>
15 #include <com/sun/star/frame/XController.hpp>
17 #include <svx/tbcontrl.hxx>
19 #include <comphelper/lok.hxx>
20 #include <sfx2/viewsh.hxx>
21 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
23 namespace chart { namespace sidebar {
25 namespace {
27 OUString getCID(const css::uno::Reference<css::frame::XModel>& xModel)
29 css::uno::Reference<css::frame::XController> xController(xModel->getCurrentController());
30 css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(xController, css::uno::UNO_QUERY);
31 if (!xSelectionSupplier.is())
32 return OUString();
34 css::uno::Any aAny = xSelectionSupplier->getSelection();
35 if (!aAny.hasValue())
36 return OUString();
38 OUString aCID;
39 aAny >>= aCID;
41 return aCID;
44 css::uno::Reference<css::beans::XPropertySet> getPropSet(
45 const css::uno::Reference<css::frame::XModel>& xModel)
47 OUString aCID = getCID(xModel);
48 css::uno::Reference<css::beans::XPropertySet> xPropSet =
49 ObjectIdentifier::getObjectPropertySet(aCID, xModel);
51 ObjectType eType = ObjectIdentifier::getObjectType(aCID);
52 if (eType == OBJECTTYPE_DIAGRAM)
54 css::uno::Reference<css::chart2::XDiagram> xDiagram(
55 xPropSet, css::uno::UNO_QUERY);
56 if (!xDiagram.is())
57 return xPropSet;
59 xPropSet.set(xDiagram->getWall());
62 return xPropSet;
67 ChartColorWrapper::ChartColorWrapper(
68 css::uno::Reference<css::frame::XModel> const & xModel,
69 SvxColorToolBoxControl* pControl,
70 const OUString& rName):
71 mxModel(xModel),
72 mpControl(pControl),
73 maPropertyName(rName)
77 void ChartColorWrapper::operator()(const OUString& , const NamedColor& rColor)
79 if (!mxModel.is())
81 SAL_WARN("chart2", "Invalid reference to mxModel");
82 return;
85 css::uno::Reference<css::beans::XPropertySet> xPropSet = getPropSet(mxModel);
87 if (!xPropSet.is())
89 SAL_WARN("chart2", "Invalid reference to xPropSet");
90 return;
93 xPropSet->setPropertyValue(maPropertyName, css::uno::makeAny(rColor.first));
96 void ChartColorWrapper::updateModel(const css::uno::Reference<css::frame::XModel>& xModel)
98 mxModel = xModel;
101 void ChartColorWrapper::updateData()
103 static const OUStringLiteral aLineColor = "LineColor";
104 static const OUStringLiteral aCommands[2] = {".uno:XLineColor", ".uno:FillColor"};
106 css::uno::Reference<css::beans::XPropertySet> xPropSet = getPropSet(mxModel);
107 if (!xPropSet.is())
108 return;
110 css::util::URL aUrl;
111 aUrl.Complete = (maPropertyName == aLineColor) ? aCommands[0] : aCommands[1];
113 css::frame::FeatureStateEvent aEvent;
114 aEvent.FeatureURL = aUrl;
115 aEvent.IsEnabled = true;
116 aEvent.State = xPropSet->getPropertyValue(maPropertyName);
117 mpControl->statusChanged(aEvent);
119 SfxViewShell* pViewShell = SfxViewShell::Current();
120 if (comphelper::LibreOfficeKit::isActive() && pViewShell && (maPropertyName == aLineColor))
122 std::string sCommand = OUStringToOString(aUrl.Complete, RTL_TEXTENCODING_ASCII_US).getStr();
123 sal_uInt32 nColor = -1;
124 aEvent.State >>= nColor;
125 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED,
126 (sCommand + "=" + std::to_string(nColor)).c_str());
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */