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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
22 #include <com/sun/star/chart2/AxisOrientation.hpp>
23 #include <com/sun/star/chart2/XAxis.hpp>
25 #include <com/sun/star/util/XModifyBroadcaster.hpp>
27 #include "ChartAxisPanel.hxx"
28 #include <ChartController.hxx>
29 #include <vcl/lstbox.hxx>
30 #include <vcl/field.hxx>
33 using namespace css::uno
;
35 namespace chart
{ namespace sidebar
{
39 bool isLabelShown(const css::uno::Reference
<css::frame::XModel
>& xModel
,
42 css::uno::Reference
< css::beans::XPropertySet
> xAxis(
43 ObjectIdentifier::getAxisForCID(rCID
, xModel
), uno::UNO_QUERY
);
48 uno::Any aAny
= xAxis
->getPropertyValue("DisplayLabels");
52 bool bVisible
= false;
57 void setLabelShown(const css::uno::Reference
<css::frame::XModel
>& xModel
,
58 const OUString
& rCID
, bool bVisible
)
60 css::uno::Reference
< css::beans::XPropertySet
> xAxis(
61 ObjectIdentifier::getAxisForCID(rCID
, xModel
), uno::UNO_QUERY
);
66 xAxis
->setPropertyValue("DisplayLabels", css::uno::Any(bVisible
));
69 struct AxisLabelPosMap
72 css::chart::ChartAxisLabelPosition ePos
;
75 static AxisLabelPosMap
const aLabelPosMap
[] = {
76 { 0, css::chart::ChartAxisLabelPosition_NEAR_AXIS
},
77 { 1, css::chart::ChartAxisLabelPosition_NEAR_AXIS_OTHER_SIDE
},
78 { 2, css::chart::ChartAxisLabelPosition_OUTSIDE_START
},
79 { 3, css::chart::ChartAxisLabelPosition_OUTSIDE_END
}
82 sal_Int32
getLabelPosition(const css::uno::Reference
<css::frame::XModel
>& xModel
,
85 css::uno::Reference
< css::beans::XPropertySet
> xAxis(
86 ObjectIdentifier::getAxisForCID(rCID
, xModel
), uno::UNO_QUERY
);
91 uno::Any aAny
= xAxis
->getPropertyValue("LabelPosition");
95 css::chart::ChartAxisLabelPosition ePos
;
97 for (AxisLabelPosMap
const & i
: aLabelPosMap
)
106 void setLabelPosition(const css::uno::Reference
<css::frame::XModel
>& xModel
,
107 const OUString
& rCID
, sal_Int32 nPos
)
109 css::uno::Reference
< css::beans::XPropertySet
> xAxis(
110 ObjectIdentifier::getAxisForCID(rCID
, xModel
), uno::UNO_QUERY
);
115 css::chart::ChartAxisLabelPosition ePos
;
116 for (AxisLabelPosMap
const & i
: aLabelPosMap
)
122 xAxis
->setPropertyValue("LabelPosition", css::uno::Any(ePos
));
125 bool isReverse(const css::uno::Reference
<css::frame::XModel
>& xModel
,
126 const OUString
& rCID
)
128 css::uno::Reference
< css::chart2::XAxis
> xAxis
=
129 ObjectIdentifier::getAxisForCID(rCID
, xModel
);
134 css::chart2::ScaleData aData
= xAxis
->getScaleData();
136 return aData
.Orientation
== css::chart2::AxisOrientation_REVERSE
;
139 void setReverse(const css::uno::Reference
<css::frame::XModel
>& xModel
,
140 const OUString
& rCID
, bool bReverse
)
142 css::uno::Reference
< css::chart2::XAxis
> xAxis
=
143 ObjectIdentifier::getAxisForCID(rCID
, xModel
);
148 css::chart2::ScaleData aData
= xAxis
->getScaleData();
150 aData
.Orientation
= css::chart2::AxisOrientation_REVERSE
;
152 aData
.Orientation
= css::chart2::AxisOrientation_MATHEMATICAL
;
154 xAxis
->setScaleData(aData
);
157 OUString
getCID(const css::uno::Reference
<css::frame::XModel
>& xModel
)
159 css::uno::Reference
<css::frame::XController
> xController(xModel
->getCurrentController());
160 css::uno::Reference
<css::view::XSelectionSupplier
> xSelectionSupplier(xController
, css::uno::UNO_QUERY
);
161 if (!xSelectionSupplier
.is())
164 uno::Any aAny
= xSelectionSupplier
->getSelection();
165 assert(aAny
.hasValue());
168 #if defined DBG_UTIL && !defined NDEBUG
169 ObjectType eType
= ObjectIdentifier::getObjectType(aCID
);
170 assert(eType
== OBJECTTYPE_AXIS
);
176 void setAxisRotation(const css::uno::Reference
<css::frame::XModel
>& xModel
,
177 const OUString
& rCID
, double nVal
)
179 css::uno::Reference
< css::beans::XPropertySet
> xAxis(
180 ObjectIdentifier::getAxisForCID(rCID
, xModel
), uno::UNO_QUERY
);
185 xAxis
->setPropertyValue("TextRotation", css::uno::Any(nVal
));
188 double getAxisRotation(const css::uno::Reference
<css::frame::XModel
>& xModel
,
189 const OUString
& rCID
)
191 css::uno::Reference
< css::beans::XPropertySet
> xAxis(
192 ObjectIdentifier::getAxisForCID(rCID
, xModel
), uno::UNO_QUERY
);
197 css::uno::Any aAny
= xAxis
->getPropertyValue("TextRotation");
205 ChartAxisPanel::ChartAxisPanel(
206 vcl::Window
* pParent
,
207 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
208 ChartController
* pController
)
209 : PanelLayout(pParent
, "ChartAxisPanel", "modules/schart/ui/sidebaraxis.ui", rxFrame
),
210 mxModel(pController
->getModel()),
211 mxModifyListener(new ChartSidebarModifyListener(this)),
212 mxSelectionListener(new ChartSidebarSelectionListener(this, OBJECTTYPE_AXIS
)),
215 get(mpCBShowLabel
, "checkbutton_show_label");
216 get(mpCBReverse
, "checkbutton_reverse");
218 get(mpLBLabelPos
, "comboboxtext_label_position");
219 get(mpNFRotation
, "spinbutton1");
220 get(mpGridLabel
, "label_props");
225 ChartAxisPanel::~ChartAxisPanel()
230 void ChartAxisPanel::dispose()
232 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcaster(mxModel
, css::uno::UNO_QUERY_THROW
);
233 xBroadcaster
->removeModifyListener(mxModifyListener
);
235 css::uno::Reference
<css::view::XSelectionSupplier
> xSelectionSupplier(mxModel
->getCurrentController(), css::uno::UNO_QUERY
);
236 if (xSelectionSupplier
.is())
237 xSelectionSupplier
->removeSelectionChangeListener(mxSelectionListener
);
239 mpCBShowLabel
.clear();
242 mpLBLabelPos
.clear();
245 mpNFRotation
.clear();
247 PanelLayout::dispose();
250 void ChartAxisPanel::Initialize()
252 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcaster(mxModel
, css::uno::UNO_QUERY_THROW
);
253 xBroadcaster
->addModifyListener(mxModifyListener
);
255 css::uno::Reference
<css::view::XSelectionSupplier
> xSelectionSupplier(mxModel
->getCurrentController(), css::uno::UNO_QUERY
);
256 if (xSelectionSupplier
.is())
257 xSelectionSupplier
->addSelectionChangeListener(mxSelectionListener
);
261 Link
<Button
*,void> aLink
= LINK(this, ChartAxisPanel
, CheckBoxHdl
);
262 mpCBShowLabel
->SetClickHdl(aLink
);
263 mpCBReverse
->SetClickHdl(aLink
);
265 Link
<Edit
&, void> aSpinButtonLink
= LINK(this, ChartAxisPanel
, TextRotationHdl
);
266 mpNFRotation
->SetModifyHdl(aSpinButtonLink
);
268 mpLBLabelPos
->SetSelectHdl(LINK(this, ChartAxisPanel
, ListBoxHdl
));
271 void ChartAxisPanel::updateData()
276 OUString aCID
= getCID(mxModel
);
277 SolarMutexGuard aGuard
;
279 mpCBShowLabel
->Check(isLabelShown(mxModel
, aCID
));
280 mpCBReverse
->Check(isReverse(mxModel
, aCID
));
282 mpLBLabelPos
->SelectEntryPos(getLabelPosition(mxModel
, aCID
));
283 mpNFRotation
->SetValue(getAxisRotation(mxModel
, aCID
));
286 VclPtr
<vcl::Window
> ChartAxisPanel::Create (
287 vcl::Window
* pParent
,
288 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
289 ChartController
* pController
)
291 if (pParent
== nullptr)
292 throw lang::IllegalArgumentException("no parent Window given to ChartAxisPanel::Create", nullptr, 0);
294 throw lang::IllegalArgumentException("no XFrame given to ChartAxisPanel::Create", nullptr, 1);
296 return VclPtr
<ChartAxisPanel
>::Create(
297 pParent
, rxFrame
, pController
);
300 void ChartAxisPanel::DataChanged(
301 const DataChangedEvent
& )
306 void ChartAxisPanel::HandleContextChange(
307 const vcl::EnumContext
& )
312 void ChartAxisPanel::NotifyItemUpdate(
314 SfxItemState
/*eState*/,
315 const SfxPoolItem
* /*pState*/ )
319 void ChartAxisPanel::modelInvalid()
321 mbModelValid
= false;
324 void ChartAxisPanel::updateModel(
325 css::uno::Reference
<css::frame::XModel
> xModel
)
329 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcaster(mxModel
, css::uno::UNO_QUERY_THROW
);
330 xBroadcaster
->removeModifyListener(mxModifyListener
);
336 css::uno::Reference
<css::util::XModifyBroadcaster
> xBroadcasterNew(mxModel
, css::uno::UNO_QUERY_THROW
);
337 xBroadcasterNew
->addModifyListener(mxModifyListener
);
339 css::uno::Reference
<css::view::XSelectionSupplier
> xSelectionSupplier(mxModel
->getCurrentController(), css::uno::UNO_QUERY
);
340 if (xSelectionSupplier
.is())
341 xSelectionSupplier
->addSelectionChangeListener(mxSelectionListener
);
344 void ChartAxisPanel::selectionChanged(bool bCorrectType
)
350 IMPL_LINK(ChartAxisPanel
, CheckBoxHdl
, Button
*, pButton
, void)
352 CheckBox
* pCheckbox
= static_cast<CheckBox
*>(pButton
);
353 OUString aCID
= getCID(mxModel
);
354 bool bChecked
= pCheckbox
->IsChecked();
356 if (pCheckbox
== mpCBShowLabel
.get())
358 mpGridLabel
->Enable(bChecked
);
359 setLabelShown(mxModel
, aCID
, bChecked
);
361 else if (pCheckbox
== mpCBReverse
.get())
362 setReverse(mxModel
, aCID
, bChecked
);
365 IMPL_LINK_NOARG(ChartAxisPanel
, ListBoxHdl
, ListBox
&, void)
367 OUString aCID
= getCID(mxModel
);
368 sal_Int32 nPos
= mpLBLabelPos
->GetSelectedEntryPos();
370 setLabelPosition(mxModel
, aCID
, nPos
);
373 IMPL_LINK(ChartAxisPanel
, TextRotationHdl
, Edit
&, rMetricField
, void)
375 OUString aCID
= getCID(mxModel
);
376 double nVal
= static_cast<NumericField
&>(rMetricField
).GetValue();
377 setAxisRotation(mxModel
, aCID
, nVal
);
380 }} // end of namespace ::chart::sidebar
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */