/src/libreoffice/chart2/source/controller/sidebar/ChartLinePanel.cxx
Line | Count | Source |
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/xlntrit.hxx> |
17 | | |
18 | | #include <svx/linectrl.hxx> |
19 | | #include <svx/tbcontrl.hxx> |
20 | | #include <sfx2/weldutils.hxx> |
21 | | #include <vcl/svapp.hxx> |
22 | | |
23 | | #include <com/sun/star/view/XSelectionSupplier.hpp> |
24 | | #include <com/sun/star/chart2/XDiagram.hpp> |
25 | | |
26 | | #include <comphelper/lok.hxx> |
27 | | #include <sfx2/viewsh.hxx> |
28 | | #include <LibreOfficeKit/LibreOfficeKitEnums.h> |
29 | | |
30 | | namespace chart::sidebar { |
31 | | |
32 | | namespace { |
33 | | |
34 | | SvxLineStyleToolBoxControl* getLineStyleToolBoxControl(const ToolbarUnoDispatcher& rToolBoxColor) |
35 | 0 | { |
36 | 0 | css::uno::Reference<css::frame::XToolbarController> xController = rToolBoxColor.GetControllerForCommand(u".uno:XLineStyle"_ustr); |
37 | 0 | SvxLineStyleToolBoxControl* pToolBoxLineStyleControl = dynamic_cast<SvxLineStyleToolBoxControl*>(xController.get()); |
38 | 0 | return pToolBoxLineStyleControl; |
39 | 0 | } |
40 | | |
41 | | SvxColorToolBoxControl* getColorToolBoxControl(const ToolbarUnoDispatcher& rToolBoxLineStyle) |
42 | 0 | { |
43 | 0 | css::uno::Reference<css::frame::XToolbarController> xController = rToolBoxLineStyle.GetControllerForCommand(u".uno:XLineColor"_ustr); |
44 | 0 | SvxColorToolBoxControl* pToolBoxColorControl = dynamic_cast<SvxColorToolBoxControl*>(xController.get()); |
45 | 0 | return pToolBoxColorControl; |
46 | 0 | } |
47 | | |
48 | | OUString getCID(const rtl::Reference<::chart::ChartModel>& xModel) |
49 | 0 | { |
50 | 0 | css::uno::Reference<css::frame::XController> xController(xModel->getCurrentController()); |
51 | 0 | css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(xController, css::uno::UNO_QUERY); |
52 | 0 | if (!xSelectionSupplier.is()) |
53 | 0 | return OUString(); |
54 | | |
55 | 0 | css::uno::Any aAny = xSelectionSupplier->getSelection(); |
56 | 0 | if (!aAny.hasValue()) |
57 | 0 | return OUString(); |
58 | | |
59 | 0 | OUString aCID; |
60 | 0 | aAny >>= aCID; |
61 | |
|
62 | 0 | return aCID; |
63 | 0 | } |
64 | | |
65 | | css::uno::Reference<css::beans::XPropertySet> getPropSet( |
66 | | const rtl::Reference<::chart::ChartModel>& xModel) |
67 | 0 | { |
68 | 0 | OUString aCID = getCID(xModel); |
69 | 0 | css::uno::Reference<css::beans::XPropertySet> xPropSet = |
70 | 0 | ObjectIdentifier::getObjectPropertySet(aCID, xModel); |
71 | |
|
72 | 0 | ObjectType eType = ObjectIdentifier::getObjectType(aCID); |
73 | 0 | if (eType == OBJECTTYPE_DIAGRAM) |
74 | 0 | { |
75 | 0 | css::uno::Reference<css::chart2::XDiagram> xDiagram( |
76 | 0 | xPropSet, css::uno::UNO_QUERY); |
77 | 0 | if (!xDiagram.is()) |
78 | 0 | return xPropSet; |
79 | | |
80 | 0 | xPropSet.set(xDiagram->getWall()); |
81 | 0 | } |
82 | | |
83 | 0 | return xPropSet; |
84 | 0 | } |
85 | | |
86 | | class PreventUpdate |
87 | | { |
88 | | public: |
89 | | explicit PreventUpdate(bool& bUpdate): |
90 | 0 | mbUpdate(bUpdate) |
91 | 0 | { |
92 | 0 | mbUpdate = false; |
93 | 0 | } |
94 | | |
95 | | ~PreventUpdate() |
96 | 0 | { |
97 | 0 | mbUpdate = true; |
98 | 0 | } |
99 | | |
100 | | private: |
101 | | bool& mbUpdate; |
102 | | }; |
103 | | |
104 | | } |
105 | | |
106 | | std::unique_ptr<PanelLayout> ChartLinePanel::Create( |
107 | | weld::Widget* pParent, |
108 | | const css::uno::Reference<css::frame::XFrame>& rxFrame, |
109 | | ChartController* pController) |
110 | 0 | { |
111 | 0 | if (pParent == nullptr) |
112 | 0 | throw css::lang::IllegalArgumentException(u"no parent Window given to ChartAxisPanel::Create"_ustr, nullptr, 0); |
113 | 0 | if (!rxFrame.is()) |
114 | 0 | throw css::lang::IllegalArgumentException(u"no XFrame given to ChartAxisPanel::Create"_ustr, nullptr, 1); |
115 | | |
116 | 0 | return std::make_unique<ChartLinePanel>(pParent, rxFrame, pController); |
117 | 0 | } |
118 | | |
119 | | ChartLinePanel::ChartLinePanel(weld::Widget* pParent, |
120 | | const css::uno::Reference<css::frame::XFrame>& rxFrame, |
121 | | ChartController* pController): |
122 | 0 | svx::sidebar::LinePropertyPanelBase(pParent, rxFrame), |
123 | 0 | mxModel(pController->getChartModel()), |
124 | 0 | mxListener(new ChartSidebarModifyListener(this)), |
125 | 0 | mxSelectionListener(new ChartSidebarSelectionListener(this)), |
126 | 0 | mbUpdate(true), |
127 | 0 | mbModelValid(true), |
128 | 0 | maLineColorWrapper(mxModel, getColorToolBoxControl(*mxColorDispatch), u"LineColor"_ustr), |
129 | 0 | maLineStyleWrapper(mxModel, getLineStyleToolBoxControl(*mxLineStyleDispatch)) |
130 | 0 | { |
131 | 0 | disableArrowHead(); |
132 | 0 | std::vector<ObjectType> aAcceptedTypes { OBJECTTYPE_PAGE, OBJECTTYPE_DIAGRAM, |
133 | 0 | OBJECTTYPE_DATA_SERIES, OBJECTTYPE_DATA_POINT, |
134 | 0 | OBJECTTYPE_TITLE, OBJECTTYPE_LEGEND, OBJECTTYPE_DATA_CURVE, |
135 | 0 | OBJECTTYPE_DATA_AVERAGE_LINE, OBJECTTYPE_AXIS}; |
136 | 0 | mxSelectionListener->setAcceptedTypes(std::move(aAcceptedTypes)); |
137 | 0 | Initialize(); |
138 | 0 | } |
139 | | |
140 | | ChartLinePanel::~ChartLinePanel() |
141 | 0 | { |
142 | 0 | doUpdateModel(nullptr); |
143 | 0 | } |
144 | | |
145 | | void ChartLinePanel::Initialize() |
146 | 0 | { |
147 | 0 | mxModel->addModifyListener(mxListener); |
148 | |
|
149 | 0 | css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(mxModel->getCurrentController(), css::uno::UNO_QUERY); |
150 | 0 | if (xSelectionSupplier.is()) |
151 | 0 | xSelectionSupplier->addSelectionChangeListener(mxSelectionListener); |
152 | |
|
153 | 0 | SvxColorToolBoxControl* pToolBoxColor = getColorToolBoxControl(*mxColorDispatch); |
154 | 0 | pToolBoxColor->setColorSelectFunction(maLineColorWrapper); |
155 | |
|
156 | 0 | SvxLineStyleToolBoxControl* pToolBoxLineStyle = getLineStyleToolBoxControl(*mxLineStyleDispatch); |
157 | 0 | pToolBoxLineStyle->setLineStyleSelectFunction(maLineStyleWrapper); |
158 | |
|
159 | 0 | setMapUnit(MapUnit::Map100thMM); |
160 | 0 | updateData(); |
161 | 0 | } |
162 | | |
163 | | void ChartLinePanel::updateData() |
164 | 0 | { |
165 | 0 | if (!mbUpdate || !mbModelValid) |
166 | 0 | return; |
167 | | |
168 | 0 | SolarMutexGuard aGuard; |
169 | 0 | css::uno::Reference<css::beans::XPropertySet> xPropSet = getPropSet(mxModel); |
170 | 0 | if (!xPropSet.is()) |
171 | 0 | return; |
172 | | |
173 | 0 | sal_uInt16 nLineTransparence = 0; |
174 | 0 | xPropSet->getPropertyValue(u"LineTransparence"_ustr) >>= nLineTransparence; |
175 | 0 | XLineTransparenceItem aLineTransparenceItem(nLineTransparence); |
176 | 0 | updateLineTransparence(false, true, &aLineTransparenceItem); |
177 | |
|
178 | 0 | sal_uInt32 nWidth = 0; |
179 | 0 | xPropSet->getPropertyValue(u"LineWidth"_ustr) >>= nWidth; |
180 | 0 | XLineWidthItem aWidthItem(nWidth); |
181 | 0 | updateLineWidth(false, true, &aWidthItem); |
182 | |
|
183 | 0 | maLineStyleWrapper.updateData(); |
184 | 0 | maLineColorWrapper.updateData(); |
185 | 0 | } |
186 | | |
187 | | void ChartLinePanel::modelInvalid() |
188 | 0 | { |
189 | 0 | mbModelValid = false; |
190 | 0 | } |
191 | | |
192 | | void ChartLinePanel::selectionChanged(bool bCorrectType) |
193 | 0 | { |
194 | 0 | if (bCorrectType) |
195 | 0 | updateData(); |
196 | 0 | } |
197 | | |
198 | | void ChartLinePanel::doUpdateModel(const rtl::Reference<::chart::ChartModel>& xModel) |
199 | 0 | { |
200 | 0 | if (mbModelValid) |
201 | 0 | { |
202 | 0 | mxModel->removeModifyListener(mxListener); |
203 | |
|
204 | 0 | css::uno::Reference<css::view::XSelectionSupplier> oldSelectionSupplier( |
205 | 0 | mxModel->getCurrentController(), css::uno::UNO_QUERY); |
206 | 0 | if (oldSelectionSupplier.is()) { |
207 | 0 | oldSelectionSupplier->removeSelectionChangeListener(mxSelectionListener); |
208 | 0 | } |
209 | 0 | } |
210 | |
|
211 | 0 | mxModel = xModel; |
212 | 0 | mbModelValid = mxModel.is(); |
213 | |
|
214 | 0 | if (!mbModelValid) |
215 | 0 | return; |
216 | | |
217 | 0 | maLineStyleWrapper.updateModel(mxModel); |
218 | 0 | maLineColorWrapper.updateModel(mxModel); |
219 | |
|
220 | 0 | mxModel->addModifyListener(mxListener); |
221 | |
|
222 | 0 | css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(mxModel->getCurrentController(), css::uno::UNO_QUERY); |
223 | 0 | if (xSelectionSupplier.is()) |
224 | 0 | xSelectionSupplier->addSelectionChangeListener(mxSelectionListener); |
225 | 0 | } |
226 | | |
227 | | void ChartLinePanel::updateModel(css::uno::Reference<css::frame::XModel> xModel) |
228 | 0 | { |
229 | 0 | ::chart::ChartModel* pModel = dynamic_cast<::chart::ChartModel*>(xModel.get()); |
230 | 0 | assert(!xModel || pModel); |
231 | 0 | doUpdateModel(pModel); |
232 | 0 | } |
233 | | |
234 | | void ChartLinePanel::setLineTransparency(const XLineTransparenceItem& rItem) |
235 | 0 | { |
236 | 0 | css::uno::Reference<css::beans::XPropertySet> xPropSet = |
237 | 0 | getPropSet(mxModel); |
238 | |
|
239 | 0 | if (!xPropSet.is()) |
240 | 0 | return; |
241 | | |
242 | 0 | PreventUpdate aPreventUpdate(mbUpdate); |
243 | 0 | xPropSet->setPropertyValue(u"LineTransparence"_ustr, css::uno::Any(rItem.GetValue())); |
244 | 0 | } |
245 | | |
246 | | void ChartLinePanel::setLineWidth(const XLineWidthItem& rItem) |
247 | 0 | { |
248 | 0 | css::uno::Reference<css::beans::XPropertySet> xPropSet = |
249 | 0 | getPropSet(mxModel); |
250 | |
|
251 | 0 | if (!xPropSet.is()) |
252 | 0 | return; |
253 | | |
254 | 0 | PreventUpdate aPreventUpdate(mbUpdate); |
255 | 0 | xPropSet->setPropertyValue(u"LineWidth"_ustr, css::uno::Any(rItem.GetValue())); |
256 | 0 | } |
257 | | |
258 | | void ChartLinePanel::updateLineWidth(bool bDisabled, bool bSetOrDefault, const SfxPoolItem* pItem) |
259 | 0 | { |
260 | 0 | LinePropertyPanelBase::updateLineWidth(bDisabled, bSetOrDefault, pItem); |
261 | |
|
262 | 0 | SfxViewShell* pViewShell = SfxViewShell::Current(); |
263 | 0 | if (comphelper::LibreOfficeKit::isActive() && pViewShell) |
264 | 0 | { |
265 | 0 | pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, |
266 | 0 | ".uno:LineWidth=" + OString::number(mnWidthCoreValue)); |
267 | 0 | } |
268 | 0 | } |
269 | | |
270 | | } |
271 | | |
272 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |