LibreOffice Module chart2 (master) 1
ChartLinePanel.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#include "ChartLinePanel.hxx"
11
12#include <ChartController.hxx>
13#include <ChartModel.hxx>
14
15#include <svx/xlnwtit.hxx>
16#include <svx/xlinjoit.hxx>
17#include <svx/xlntrit.hxx>
18
19#include <svx/linectrl.hxx>
20#include <svx/tbcontrl.hxx>
21#include <sfx2/weldutils.hxx>
22#include <vcl/svapp.hxx>
23
24#include <com/sun/star/view/XSelectionSupplier.hpp>
25#include <com/sun/star/chart2/XDiagram.hpp>
26
27#include <comphelper/lok.hxx>
28#include <sfx2/viewsh.hxx>
29#include <LibreOfficeKit/LibreOfficeKitEnums.h>
30
31namespace chart::sidebar {
32
33namespace {
34
35SvxLineStyleToolBoxControl* getLineStyleToolBoxControl(const ToolbarUnoDispatcher& rToolBoxColor)
36{
37 css::uno::Reference<css::frame::XToolbarController> xController = rToolBoxColor.GetControllerForCommand(".uno:XLineStyle");
38 SvxLineStyleToolBoxControl* pToolBoxLineStyleControl = dynamic_cast<SvxLineStyleToolBoxControl*>(xController.get());
39 return pToolBoxLineStyleControl;
40}
41
42SvxColorToolBoxControl* getColorToolBoxControl(const ToolbarUnoDispatcher& rToolBoxLineStyle)
43{
44 css::uno::Reference<css::frame::XToolbarController> xController = rToolBoxLineStyle.GetControllerForCommand(".uno:XLineColor");
45 SvxColorToolBoxControl* pToolBoxColorControl = dynamic_cast<SvxColorToolBoxControl*>(xController.get());
46 return pToolBoxColorControl;
47}
48
49OUString getCID(const rtl::Reference<::chart::ChartModel>& xModel)
50{
51 css::uno::Reference<css::frame::XController> xController(xModel->getCurrentController());
52 css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(xController, css::uno::UNO_QUERY);
53 if (!xSelectionSupplier.is())
54 return OUString();
55
56 css::uno::Any aAny = xSelectionSupplier->getSelection();
57 if (!aAny.hasValue())
58 return OUString();
59
60 OUString aCID;
61 aAny >>= aCID;
62
63 return aCID;
64}
65
66css::uno::Reference<css::beans::XPropertySet> getPropSet(
68{
69 OUString aCID = getCID(xModel);
70 css::uno::Reference<css::beans::XPropertySet> xPropSet =
72
74 if (eType == OBJECTTYPE_DIAGRAM)
75 {
76 css::uno::Reference<css::chart2::XDiagram> xDiagram(
77 xPropSet, css::uno::UNO_QUERY);
78 if (!xDiagram.is())
79 return xPropSet;
80
81 xPropSet.set(xDiagram->getWall());
82 }
83
84 return xPropSet;
85}
86
87class PreventUpdate
88{
89public:
90 explicit PreventUpdate(bool& bUpdate):
91 mbUpdate(bUpdate)
92 {
93 mbUpdate = false;
94 }
95
96 ~PreventUpdate()
97 {
98 mbUpdate = true;
99 }
100
101private:
102 bool& mbUpdate;
103};
104
105}
106
107std::unique_ptr<PanelLayout> ChartLinePanel::Create(
108 weld::Widget* pParent,
109 const css::uno::Reference<css::frame::XFrame>& rxFrame,
110 ChartController* pController)
111{
112 if (pParent == nullptr)
113 throw css::lang::IllegalArgumentException("no parent Window given to ChartAxisPanel::Create", nullptr, 0);
114 if (!rxFrame.is())
115 throw css::lang::IllegalArgumentException("no XFrame given to ChartAxisPanel::Create", nullptr, 1);
116
117 return std::make_unique<ChartLinePanel>(pParent, rxFrame, pController);
118}
119
121 const css::uno::Reference<css::frame::XFrame>& rxFrame,
122 ChartController* pController):
123 svx::sidebar::LinePropertyPanelBase(pParent, rxFrame),
124 mxModel(pController->getChartModel()),
126 mxSelectionListener(new ChartSidebarSelectionListener(this)),
127 mbUpdate(true),
128 mbModelValid(true),
129 maLineColorWrapper(mxModel, getColorToolBoxControl(*mxColorDispatch), "LineColor"),
130 maLineStyleWrapper(mxModel, getLineStyleToolBoxControl(*mxLineStyleDispatch))
131{
133 std::vector<ObjectType> aAcceptedTypes { OBJECTTYPE_PAGE, OBJECTTYPE_DIAGRAM,
137 mxSelectionListener->setAcceptedTypes(std::move(aAcceptedTypes));
138 Initialize();
139}
140
142{
143 doUpdateModel(nullptr);
144}
145
147{
148 mxModel->addModifyListener(mxListener);
149
150 css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(mxModel->getCurrentController(), css::uno::UNO_QUERY);
151 if (xSelectionSupplier.is())
152 xSelectionSupplier->addSelectionChangeListener(mxSelectionListener);
153
154 SvxColorToolBoxControl* pToolBoxColor = getColorToolBoxControl(*mxColorDispatch);
156
157 SvxLineStyleToolBoxControl* pToolBoxLineStyle = getLineStyleToolBoxControl(*mxLineStyleDispatch);
159
160 setMapUnit(MapUnit::Map100thMM);
161 updateData();
162}
163
165{
166 if (!mbUpdate || !mbModelValid)
167 return;
168
169 SolarMutexGuard aGuard;
170 css::uno::Reference<css::beans::XPropertySet> xPropSet = getPropSet(mxModel);
171 if (!xPropSet.is())
172 return;
173
174 sal_uInt16 nLineTransparence = 0;
175 xPropSet->getPropertyValue("LineTransparence") >>= nLineTransparence;
176 XLineTransparenceItem aLineTransparenceItem(nLineTransparence);
177 updateLineTransparence(false, true, &aLineTransparenceItem);
178
179 sal_uInt32 nWidth = 0;
180 xPropSet->getPropertyValue("LineWidth") >>= nWidth;
181 XLineWidthItem aWidthItem(nWidth);
182 updateLineWidth(false, true, &aWidthItem);
183
186}
187
189{
190 mbModelValid = false;
191}
192
193void ChartLinePanel::selectionChanged(bool bCorrectType)
194{
195 if (bCorrectType)
196 updateData();
197}
198
200{
201 if (mbModelValid)
202 {
203 mxModel->removeModifyListener(mxListener);
204
205 css::uno::Reference<css::view::XSelectionSupplier> oldSelectionSupplier(
206 mxModel->getCurrentController(), css::uno::UNO_QUERY);
207 if (oldSelectionSupplier.is()) {
208 oldSelectionSupplier->removeSelectionChangeListener(mxSelectionListener);
209 }
210 }
211
212 mxModel = xModel;
213 mbModelValid = mxModel.is();
214
215 if (!mbModelValid)
216 return;
217
220
221 mxModel->addModifyListener(mxListener);
222
223 css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(mxModel->getCurrentController(), css::uno::UNO_QUERY);
224 if (xSelectionSupplier.is())
225 xSelectionSupplier->addSelectionChangeListener(mxSelectionListener);
226}
227
228void ChartLinePanel::updateModel(css::uno::Reference<css::frame::XModel> xModel)
229{
230 ::chart::ChartModel* pModel = dynamic_cast<::chart::ChartModel*>(xModel.get());
231 assert(!xModel || pModel);
232 doUpdateModel(pModel);
233}
234
236{
237 css::uno::Reference<css::beans::XPropertySet> xPropSet =
238 getPropSet(mxModel);
239
240 if (!xPropSet.is())
241 return;
242
243 PreventUpdate aPreventUpdate(mbUpdate);
244 if (pItem)
245 xPropSet->setPropertyValue("LineJoint", css::uno::Any(pItem->GetValue()));
246}
247
249{
250}
251
253{
254 css::uno::Reference<css::beans::XPropertySet> xPropSet =
255 getPropSet(mxModel);
256
257 if (!xPropSet.is())
258 return;
259
260 PreventUpdate aPreventUpdate(mbUpdate);
261 xPropSet->setPropertyValue("LineTransparence", css::uno::Any(rItem.GetValue()));
262}
263
265{
266 css::uno::Reference<css::beans::XPropertySet> xPropSet =
267 getPropSet(mxModel);
268
269 if (!xPropSet.is())
270 return;
271
272 PreventUpdate aPreventUpdate(mbUpdate);
273 xPropSet->setPropertyValue("LineWidth", css::uno::Any(rItem.GetValue()));
274}
275
276void ChartLinePanel::updateLineWidth(bool bDisabled, bool bSetOrDefault, const SfxPoolItem* pItem)
277{
278 LinePropertyPanelBase::updateLineWidth(bDisabled, bSetOrDefault, pItem);
279
280 SfxViewShell* pViewShell = SfxViewShell::Current();
281 if (comphelper::LibreOfficeKit::isActive() && pViewShell)
282 {
283 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED,
284 ".uno:LineWidth=" + OString::number(mnWidthCoreValue));
285 }
286}
287
288}
289
290/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool & mbUpdate
css::uno::Reference< css::frame::XModel2 > mxModel
virtual void libreOfficeKitViewCallback(int nType, const OString &pPayload) const override
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
void setColorSelectFunction(const ColorSelectFunction &aColorSelectFunction)
void setLineStyleSelectFunction(const LineStyleSelectFunction &aLineStyleSelectFunction)
css::uno::Reference< css::frame::XToolbarController > GetControllerForCommand(const OUString &rCommand) const
static css::uno::Reference< css::beans::XPropertySet > getObjectPropertySet(std::u16string_view rObjectCID, const rtl::Reference< ::chart::ChartModel > &xChartDocument)
ObjectType getObjectType() const
void updateModel(const rtl::Reference<::chart::ChartModel > &xModel)
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, ChartController *pController)
virtual void selectionChanged(bool bCorrectType) override
virtual void setLineCap(const XLineCapItem *pItem) override
virtual void setLineWidth(const XLineWidthItem &rItem) override
rtl::Reference< ChartSidebarSelectionListener > mxSelectionListener
css::uno::Reference< css::util::XModifyListener > mxListener
rtl::Reference<::chart::ChartModel > mxModel
virtual void updateLineWidth(bool bDisabled, bool bSetOrDefault, const SfxPoolItem *pItem) override
ChartLinePanel(weld::Widget *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, ChartController *pController)
virtual void updateData() override
ChartLineStyleWrapper maLineStyleWrapper
virtual void modelInvalid() override
void doUpdateModel(rtl::Reference<::chart::ChartModel > xModel)
virtual ~ChartLinePanel() override
ChartColorWrapper maLineColorWrapper
virtual void setLineJoint(const XLineJointItem *pItem) override
virtual void setLineTransparency(const XLineTransparenceItem &rItem) override
virtual void updateModel(css::uno::Reference< css::frame::XModel > xModel) override
void updateModel(const rtl::Reference<::chart::ChartModel > &xModel)
std::unique_ptr< ToolbarUnoDispatcher > mxLineStyleDispatch
void setMapUnit(MapUnit eMapUnit)
std::unique_ptr< ToolbarUnoDispatcher > mxColorDispatch
void updateLineTransparence(bool bDisabled, bool bSetOrDefault, const SfxPoolItem *pItem)
Reference< script::XScriptListener > mxListener
DocumentType eType
@ OBJECTTYPE_DATA_SERIES
@ OBJECTTYPE_DIAGRAM
@ OBJECTTYPE_DATA_POINT
@ OBJECTTYPE_DATA_AVERAGE_LINE
@ OBJECTTYPE_DATA_CURVE
ObjectType
Reference< XController > xController
Reference< XModel > xModel