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 "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
{
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())
34 css::uno::Any aAny
= xSelectionSupplier
->getSelection();
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
);
59 xPropSet
.set(xDiagram
->getWall());
67 ChartColorWrapper::ChartColorWrapper(
68 css::uno::Reference
<css::frame::XModel
> const & xModel
,
69 SvxColorToolBoxControl
* pControl
,
70 const OUString
& rName
):
77 void ChartColorWrapper::operator()(const OUString
& , const NamedColor
& rColor
)
81 SAL_WARN("chart2", "Invalid reference to mxModel");
85 css::uno::Reference
<css::beans::XPropertySet
> xPropSet
= getPropSet(mxModel
);
89 SAL_WARN("chart2", "Invalid reference to xPropSet");
93 xPropSet
->setPropertyValue(maPropertyName
, css::uno::makeAny(rColor
.first
));
96 void ChartColorWrapper::updateModel(const css::uno::Reference
<css::frame::XModel
>& 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
);
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: */