2015-07-17 20:51:37 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
|
|
|
|
2018-11-30 01:31:19 +01:00
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
2015-07-17 20:51:37 +02:00
|
|
|
#include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
|
2018-11-30 01:31:19 +01:00
|
|
|
#include <com/sun/star/chart2/AxisOrientation.hpp>
|
|
|
|
#include <com/sun/star/chart2/XAxis.hpp>
|
|
|
|
|
2018-08-22 00:10:54 +02:00
|
|
|
#include <com/sun/star/util/XModifyBroadcaster.hpp>
|
2015-07-17 20:51:37 +02:00
|
|
|
|
|
|
|
#include "ChartAxisPanel.hxx"
|
2017-10-23 22:44:16 +02:00
|
|
|
#include <ChartController.hxx>
|
2015-07-17 20:51:37 +02:00
|
|
|
#include <vcl/lstbox.hxx>
|
|
|
|
#include <vcl/field.hxx>
|
|
|
|
|
|
|
|
using namespace css;
|
|
|
|
using namespace css::uno;
|
|
|
|
|
|
|
|
namespace chart { namespace sidebar {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-04-12 10:50:29 +02:00
|
|
|
bool isLabelShown(const css::uno::Reference<css::frame::XModel>& xModel,
|
2015-07-17 20:51:37 +02:00
|
|
|
const OUString& rCID)
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::beans::XPropertySet > xAxis(
|
|
|
|
ObjectIdentifier::getAxisForCID(rCID, xModel), uno::UNO_QUERY );
|
|
|
|
|
|
|
|
if (!xAxis.is())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
uno::Any aAny = xAxis->getPropertyValue("DisplayLabels");
|
|
|
|
if (!aAny.hasValue())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool bVisible = false;
|
|
|
|
aAny >>= bVisible;
|
|
|
|
return bVisible;
|
|
|
|
}
|
|
|
|
|
2016-04-12 10:50:29 +02:00
|
|
|
void setLabelShown(const css::uno::Reference<css::frame::XModel>& xModel,
|
2015-07-17 20:51:37 +02:00
|
|
|
const OUString& rCID, bool bVisible)
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::beans::XPropertySet > xAxis(
|
|
|
|
ObjectIdentifier::getAxisForCID(rCID, xModel), uno::UNO_QUERY );
|
|
|
|
|
|
|
|
if (!xAxis.is())
|
|
|
|
return;
|
|
|
|
|
2017-02-03 08:54:47 +02:00
|
|
|
xAxis->setPropertyValue("DisplayLabels", css::uno::Any(bVisible));
|
2015-07-17 20:51:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct AxisLabelPosMap
|
|
|
|
{
|
|
|
|
sal_Int32 nPos;
|
|
|
|
css::chart::ChartAxisLabelPosition ePos;
|
|
|
|
};
|
|
|
|
|
2018-10-16 15:03:01 +02:00
|
|
|
static AxisLabelPosMap const aLabelPosMap[] = {
|
2015-07-17 20:51:37 +02:00
|
|
|
{ 0, css::chart::ChartAxisLabelPosition_NEAR_AXIS },
|
|
|
|
{ 1, css::chart::ChartAxisLabelPosition_NEAR_AXIS_OTHER_SIDE },
|
|
|
|
{ 2, css::chart::ChartAxisLabelPosition_OUTSIDE_START },
|
|
|
|
{ 3, css::chart::ChartAxisLabelPosition_OUTSIDE_END }
|
|
|
|
};
|
|
|
|
|
2016-04-12 10:50:29 +02:00
|
|
|
sal_Int32 getLabelPosition(const css::uno::Reference<css::frame::XModel>& xModel,
|
2015-07-17 20:51:37 +02:00
|
|
|
const OUString& rCID)
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::beans::XPropertySet > xAxis(
|
|
|
|
ObjectIdentifier::getAxisForCID(rCID, xModel), uno::UNO_QUERY );
|
|
|
|
|
|
|
|
if (!xAxis.is())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
uno::Any aAny = xAxis->getPropertyValue("LabelPosition");
|
|
|
|
if (!aAny.hasValue())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
css::chart::ChartAxisLabelPosition ePos;
|
|
|
|
aAny >>= ePos;
|
2018-10-16 15:03:01 +02:00
|
|
|
for (AxisLabelPosMap const & i : aLabelPosMap)
|
2015-07-17 20:51:37 +02:00
|
|
|
{
|
2016-04-21 11:03:55 +02:00
|
|
|
if (i.ePos == ePos)
|
|
|
|
return i.nPos;
|
2015-07-17 20:51:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-12 10:50:29 +02:00
|
|
|
void setLabelPosition(const css::uno::Reference<css::frame::XModel>& xModel,
|
2015-07-17 20:51:37 +02:00
|
|
|
const OUString& rCID, sal_Int32 nPos)
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::beans::XPropertySet > xAxis(
|
|
|
|
ObjectIdentifier::getAxisForCID(rCID, xModel), uno::UNO_QUERY );
|
|
|
|
|
|
|
|
if (!xAxis.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
css::chart::ChartAxisLabelPosition ePos;
|
2018-10-16 15:03:01 +02:00
|
|
|
for (AxisLabelPosMap const & i : aLabelPosMap)
|
2015-07-17 20:51:37 +02:00
|
|
|
{
|
2016-04-21 11:03:55 +02:00
|
|
|
if (i.nPos == nPos)
|
|
|
|
ePos = i.ePos;
|
2015-07-17 20:51:37 +02:00
|
|
|
}
|
|
|
|
|
2017-02-03 08:54:47 +02:00
|
|
|
xAxis->setPropertyValue("LabelPosition", css::uno::Any(ePos));
|
2015-07-17 20:51:37 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 10:50:29 +02:00
|
|
|
bool isReverse(const css::uno::Reference<css::frame::XModel>& xModel,
|
2015-07-17 20:51:37 +02:00
|
|
|
const OUString& rCID)
|
|
|
|
{
|
2019-07-19 09:50:11 +02:00
|
|
|
css::uno::Reference< css::chart2::XAxis > xAxis =
|
|
|
|
ObjectIdentifier::getAxisForCID(rCID, xModel);
|
2015-07-17 20:51:37 +02:00
|
|
|
|
|
|
|
if (!xAxis.is())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
css::chart2::ScaleData aData = xAxis->getScaleData();
|
|
|
|
|
|
|
|
return aData.Orientation == css::chart2::AxisOrientation_REVERSE;
|
|
|
|
}
|
|
|
|
|
2016-04-12 10:50:29 +02:00
|
|
|
void setReverse(const css::uno::Reference<css::frame::XModel>& xModel,
|
2015-07-17 20:51:37 +02:00
|
|
|
const OUString& rCID, bool bReverse)
|
|
|
|
{
|
2019-07-19 09:50:11 +02:00
|
|
|
css::uno::Reference< css::chart2::XAxis > xAxis =
|
|
|
|
ObjectIdentifier::getAxisForCID(rCID, xModel);
|
2015-07-17 20:51:37 +02:00
|
|
|
|
|
|
|
if (!xAxis.is())
|
|
|
|
return;
|
|
|
|
|
|
|
|
css::chart2::ScaleData aData = xAxis->getScaleData();
|
|
|
|
if (bReverse)
|
|
|
|
aData.Orientation = css::chart2::AxisOrientation_REVERSE;
|
|
|
|
else
|
|
|
|
aData.Orientation = css::chart2::AxisOrientation_MATHEMATICAL;
|
|
|
|
|
|
|
|
xAxis->setScaleData(aData);
|
|
|
|
}
|
|
|
|
|
2016-04-12 10:50:29 +02:00
|
|
|
OUString getCID(const css::uno::Reference<css::frame::XModel>& xModel)
|
2015-07-17 20:51:37 +02:00
|
|
|
{
|
|
|
|
css::uno::Reference<css::frame::XController> xController(xModel->getCurrentController());
|
|
|
|
css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(xController, css::uno::UNO_QUERY);
|
|
|
|
if (!xSelectionSupplier.is())
|
|
|
|
return OUString();
|
|
|
|
|
|
|
|
uno::Any aAny = xSelectionSupplier->getSelection();
|
|
|
|
assert(aAny.hasValue());
|
|
|
|
OUString aCID;
|
|
|
|
aAny >>= aCID;
|
2018-11-22 15:51:18 +01:00
|
|
|
#if defined DBG_UTIL && !defined NDEBUG
|
2015-07-17 20:51:37 +02:00
|
|
|
ObjectType eType = ObjectIdentifier::getObjectType(aCID);
|
|
|
|
assert(eType == OBJECTTYPE_AXIS);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return aCID;
|
|
|
|
}
|
|
|
|
|
2016-04-12 10:50:29 +02:00
|
|
|
void setAxisRotation(const css::uno::Reference<css::frame::XModel>& xModel,
|
2015-10-23 00:34:55 +02:00
|
|
|
const OUString& rCID, double nVal)
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::beans::XPropertySet > xAxis(
|
|
|
|
ObjectIdentifier::getAxisForCID(rCID, xModel), uno::UNO_QUERY );
|
|
|
|
|
|
|
|
if (!xAxis.is())
|
|
|
|
return;
|
|
|
|
|
2017-02-03 08:54:47 +02:00
|
|
|
xAxis->setPropertyValue("TextRotation", css::uno::Any(nVal));
|
2015-10-23 00:34:55 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 10:50:29 +02:00
|
|
|
double getAxisRotation(const css::uno::Reference<css::frame::XModel>& xModel,
|
2015-10-23 00:34:55 +02:00
|
|
|
const OUString& rCID)
|
|
|
|
{
|
|
|
|
css::uno::Reference< css::beans::XPropertySet > xAxis(
|
|
|
|
ObjectIdentifier::getAxisForCID(rCID, xModel), uno::UNO_QUERY );
|
|
|
|
|
|
|
|
if (!xAxis.is())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
css::uno::Any aAny = xAxis->getPropertyValue("TextRotation");
|
|
|
|
double nVal = 0;
|
|
|
|
aAny >>= nVal;
|
|
|
|
return nVal;
|
|
|
|
}
|
|
|
|
|
2015-07-17 20:51:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ChartAxisPanel::ChartAxisPanel(
|
|
|
|
vcl::Window* pParent,
|
|
|
|
const css::uno::Reference<css::frame::XFrame>& rxFrame,
|
|
|
|
ChartController* pController)
|
|
|
|
: PanelLayout(pParent, "ChartAxisPanel", "modules/schart/ui/sidebaraxis.ui", rxFrame),
|
|
|
|
mxModel(pController->getModel()),
|
2015-07-23 16:20:36 +02:00
|
|
|
mxModifyListener(new ChartSidebarModifyListener(this)),
|
2015-07-31 17:34:56 +02:00
|
|
|
mxSelectionListener(new ChartSidebarSelectionListener(this, OBJECTTYPE_AXIS)),
|
|
|
|
mbModelValid(true)
|
2015-07-17 20:51:37 +02:00
|
|
|
{
|
|
|
|
get(mpCBShowLabel, "checkbutton_show_label");
|
|
|
|
get(mpCBReverse, "checkbutton_reverse");
|
|
|
|
|
|
|
|
get(mpLBLabelPos, "comboboxtext_label_position");
|
2015-10-23 00:34:55 +02:00
|
|
|
get(mpNFRotation, "spinbutton1");
|
2015-07-29 15:55:54 +02:00
|
|
|
get(mpGridLabel, "label_props");
|
2015-07-17 20:51:37 +02:00
|
|
|
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
ChartAxisPanel::~ChartAxisPanel()
|
|
|
|
{
|
|
|
|
disposeOnce();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartAxisPanel::dispose()
|
|
|
|
{
|
|
|
|
css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
|
2015-07-23 16:20:36 +02:00
|
|
|
xBroadcaster->removeModifyListener(mxModifyListener);
|
|
|
|
|
|
|
|
css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(mxModel->getCurrentController(), css::uno::UNO_QUERY);
|
|
|
|
if (xSelectionSupplier.is())
|
|
|
|
xSelectionSupplier->removeSelectionChangeListener(mxSelectionListener);
|
2015-07-17 20:51:37 +02:00
|
|
|
|
|
|
|
mpCBShowLabel.clear();
|
|
|
|
mpCBReverse.clear();
|
|
|
|
|
|
|
|
mpLBLabelPos.clear();
|
2015-07-29 15:55:54 +02:00
|
|
|
mpGridLabel.clear();
|
2015-07-17 20:51:37 +02:00
|
|
|
|
2015-10-23 00:34:55 +02:00
|
|
|
mpNFRotation.clear();
|
|
|
|
|
2015-07-17 20:51:37 +02:00
|
|
|
PanelLayout::dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartAxisPanel::Initialize()
|
|
|
|
{
|
|
|
|
css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
|
2015-07-23 16:20:36 +02:00
|
|
|
xBroadcaster->addModifyListener(mxModifyListener);
|
|
|
|
|
|
|
|
css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(mxModel->getCurrentController(), css::uno::UNO_QUERY);
|
|
|
|
if (xSelectionSupplier.is())
|
|
|
|
xSelectionSupplier->addSelectionChangeListener(mxSelectionListener);
|
2015-07-17 20:51:37 +02:00
|
|
|
|
|
|
|
updateData();
|
|
|
|
|
2015-08-19 09:11:34 +02:00
|
|
|
Link<Button*,void> aLink = LINK(this, ChartAxisPanel, CheckBoxHdl);
|
2015-07-17 20:51:37 +02:00
|
|
|
mpCBShowLabel->SetClickHdl(aLink);
|
|
|
|
mpCBReverse->SetClickHdl(aLink);
|
|
|
|
|
2015-10-23 00:34:55 +02:00
|
|
|
Link<Edit&, void> aSpinButtonLink = LINK(this, ChartAxisPanel, TextRotationHdl);
|
|
|
|
mpNFRotation->SetModifyHdl(aSpinButtonLink);
|
|
|
|
|
2015-07-17 20:51:37 +02:00
|
|
|
mpLBLabelPos->SetSelectHdl(LINK(this, ChartAxisPanel, ListBoxHdl));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartAxisPanel::updateData()
|
|
|
|
{
|
2015-07-31 17:34:56 +02:00
|
|
|
if (!mbModelValid)
|
|
|
|
return;
|
|
|
|
|
2015-07-17 20:51:37 +02:00
|
|
|
OUString aCID = getCID(mxModel);
|
|
|
|
SolarMutexGuard aGuard;
|
|
|
|
|
|
|
|
mpCBShowLabel->Check(isLabelShown(mxModel, aCID));
|
2015-07-17 21:29:06 +02:00
|
|
|
mpCBReverse->Check(isReverse(mxModel, aCID));
|
|
|
|
|
|
|
|
mpLBLabelPos->SelectEntryPos(getLabelPosition(mxModel, aCID));
|
2015-10-23 00:34:55 +02:00
|
|
|
mpNFRotation->SetValue(getAxisRotation(mxModel, aCID));
|
2015-07-17 20:51:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VclPtr<vcl::Window> ChartAxisPanel::Create (
|
|
|
|
vcl::Window* pParent,
|
|
|
|
const css::uno::Reference<css::frame::XFrame>& rxFrame,
|
|
|
|
ChartController* pController)
|
|
|
|
{
|
2015-11-10 10:11:17 +01:00
|
|
|
if (pParent == nullptr)
|
|
|
|
throw lang::IllegalArgumentException("no parent Window given to ChartAxisPanel::Create", nullptr, 0);
|
2015-07-17 20:51:37 +02:00
|
|
|
if ( ! rxFrame.is())
|
2015-11-10 10:11:17 +01:00
|
|
|
throw lang::IllegalArgumentException("no XFrame given to ChartAxisPanel::Create", nullptr, 1);
|
2015-07-17 20:51:37 +02:00
|
|
|
|
|
|
|
return VclPtr<ChartAxisPanel>::Create(
|
|
|
|
pParent, rxFrame, pController);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartAxisPanel::DataChanged(
|
|
|
|
const DataChangedEvent& )
|
|
|
|
{
|
|
|
|
updateData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartAxisPanel::HandleContextChange(
|
2016-06-17 23:54:00 +02:00
|
|
|
const vcl::EnumContext& )
|
2015-07-17 20:51:37 +02:00
|
|
|
{
|
|
|
|
updateData();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartAxisPanel::NotifyItemUpdate(
|
|
|
|
sal_uInt16 /*nSID*/,
|
|
|
|
SfxItemState /*eState*/,
|
2019-10-18 11:45:12 +02:00
|
|
|
const SfxPoolItem* /*pState*/ )
|
2015-07-17 20:51:37 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartAxisPanel::modelInvalid()
|
|
|
|
{
|
2015-07-31 17:34:56 +02:00
|
|
|
mbModelValid = false;
|
2015-07-17 20:51:37 +02:00
|
|
|
}
|
|
|
|
|
2015-07-23 01:20:45 +02:00
|
|
|
void ChartAxisPanel::updateModel(
|
|
|
|
css::uno::Reference<css::frame::XModel> xModel)
|
|
|
|
{
|
2015-07-31 17:34:56 +02:00
|
|
|
if (mbModelValid)
|
|
|
|
{
|
|
|
|
css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
|
|
|
|
xBroadcaster->removeModifyListener(mxModifyListener);
|
|
|
|
}
|
2015-07-23 01:20:45 +02:00
|
|
|
|
|
|
|
mxModel = xModel;
|
2015-07-31 17:34:56 +02:00
|
|
|
mbModelValid = true;
|
2015-07-23 01:20:45 +02:00
|
|
|
|
|
|
|
css::uno::Reference<css::util::XModifyBroadcaster> xBroadcasterNew(mxModel, css::uno::UNO_QUERY_THROW);
|
2015-07-23 16:20:36 +02:00
|
|
|
xBroadcasterNew->addModifyListener(mxModifyListener);
|
|
|
|
|
|
|
|
css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(mxModel->getCurrentController(), css::uno::UNO_QUERY);
|
|
|
|
if (xSelectionSupplier.is())
|
|
|
|
xSelectionSupplier->addSelectionChangeListener(mxSelectionListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChartAxisPanel::selectionChanged(bool bCorrectType)
|
|
|
|
{
|
|
|
|
if (bCorrectType)
|
|
|
|
updateData();
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK(ChartAxisPanel, CheckBoxHdl, Button*, pButton, void)
|
2015-07-17 20:51:37 +02:00
|
|
|
{
|
2015-08-19 09:11:34 +02:00
|
|
|
CheckBox* pCheckbox = static_cast<CheckBox*>(pButton);
|
2015-07-17 20:51:37 +02:00
|
|
|
OUString aCID = getCID(mxModel);
|
|
|
|
bool bChecked = pCheckbox->IsChecked();
|
|
|
|
|
|
|
|
if (pCheckbox == mpCBShowLabel.get())
|
2015-07-29 15:55:54 +02:00
|
|
|
{
|
|
|
|
mpGridLabel->Enable(bChecked);
|
2015-07-17 20:51:37 +02:00
|
|
|
setLabelShown(mxModel, aCID, bChecked);
|
2015-07-29 15:55:54 +02:00
|
|
|
}
|
2015-07-17 20:51:37 +02:00
|
|
|
else if (pCheckbox == mpCBReverse.get())
|
|
|
|
setReverse(mxModel, aCID, bChecked);
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK_NOARG(ChartAxisPanel, ListBoxHdl, ListBox&, void)
|
2015-07-17 20:51:37 +02:00
|
|
|
{
|
|
|
|
OUString aCID = getCID(mxModel);
|
2017-09-14 16:57:06 +02:00
|
|
|
sal_Int32 nPos = mpLBLabelPos->GetSelectedEntryPos();
|
2015-07-17 20:51:37 +02:00
|
|
|
|
|
|
|
setLabelPosition(mxModel, aCID, nPos);
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK(ChartAxisPanel, TextRotationHdl, Edit&, rMetricField, void)
|
2015-10-23 00:34:55 +02:00
|
|
|
{
|
|
|
|
OUString aCID = getCID(mxModel);
|
|
|
|
double nVal = static_cast<NumericField&>(rMetricField).GetValue();
|
|
|
|
setAxisRotation(mxModel, aCID, nVal);
|
|
|
|
}
|
|
|
|
|
2015-07-17 20:51:37 +02:00
|
|
|
}} // end of namespace ::chart::sidebar
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|