summaryrefslogtreecommitdiff
path: root/chart2/source
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-07-23 16:20:36 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-07-26 00:26:56 +0200
commitbc4592132f3f6b5b04c8c9c5e63976c5d2dc6b4f (patch)
treee492f2a9269f7f6584ba069584b39334eec88c41 /chart2/source
parent0635208edf1cdee4235ea87666a473ac81007555 (diff)
add selection change listener
This finally allows us to handle the case where you switch between objects of the same type. Change-Id: Ic13e15e2a426d08995a577dfc1b7ee6f7da04f30
Diffstat (limited to 'chart2/source')
-rw-r--r--chart2/source/controller/sidebar/ChartAxisPanel.cxx33
-rw-r--r--chart2/source/controller/sidebar/ChartAxisPanel.hxx11
-rw-r--r--chart2/source/controller/sidebar/ChartSeriesPanel.cxx23
-rw-r--r--chart2/source/controller/sidebar/ChartSeriesPanel.hxx9
-rw-r--r--chart2/source/controller/sidebar/ChartSidebarSelectionListener.cxx81
-rw-r--r--chart2/source/controller/sidebar/ChartSidebarSelectionListener.hxx58
6 files changed, 206 insertions, 9 deletions
diff --git a/chart2/source/controller/sidebar/ChartAxisPanel.cxx b/chart2/source/controller/sidebar/ChartAxisPanel.cxx
index ba1a5e7ec2aa..a9dcae73f0d3 100644
--- a/chart2/source/controller/sidebar/ChartAxisPanel.cxx
+++ b/chart2/source/controller/sidebar/ChartAxisPanel.cxx
@@ -190,7 +190,8 @@ ChartAxisPanel::ChartAxisPanel(
: PanelLayout(pParent, "ChartAxisPanel", "modules/schart/ui/sidebaraxis.ui", rxFrame),
mxFrame(rxFrame),
mxModel(pController->getModel()),
- mxListener(new ChartSidebarModifyListener(this))
+ mxModifyListener(new ChartSidebarModifyListener(this)),
+ mxSelectionListener(new ChartSidebarSelectionListener(this, OBJECTTYPE_AXIS))
{
get(mpCBShowLabel, "checkbutton_show_label");
get(mpCBReverse, "checkbutton_reverse");
@@ -208,7 +209,11 @@ ChartAxisPanel::~ChartAxisPanel()
void ChartAxisPanel::dispose()
{
css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
- xBroadcaster->removeModifyListener(mxListener);
+ xBroadcaster->removeModifyListener(mxModifyListener);
+
+ css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(mxModel->getCurrentController(), css::uno::UNO_QUERY);
+ if (xSelectionSupplier.is())
+ xSelectionSupplier->removeSelectionChangeListener(mxSelectionListener);
mpCBShowLabel.clear();
mpCBReverse.clear();
@@ -221,7 +226,11 @@ void ChartAxisPanel::dispose()
void ChartAxisPanel::Initialize()
{
css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
- xBroadcaster->addModifyListener(mxListener);
+ xBroadcaster->addModifyListener(mxModifyListener);
+
+ css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(mxModel->getCurrentController(), css::uno::UNO_QUERY);
+ if (xSelectionSupplier.is())
+ xSelectionSupplier->addSelectionChangeListener(mxSelectionListener);
updateData();
@@ -285,12 +294,26 @@ void ChartAxisPanel::updateModel(
css::uno::Reference<css::frame::XModel> xModel)
{
css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
- xBroadcaster->removeModifyListener(mxListener);
+ xBroadcaster->removeModifyListener(mxModifyListener);
mxModel = xModel;
css::uno::Reference<css::util::XModifyBroadcaster> xBroadcasterNew(mxModel, css::uno::UNO_QUERY_THROW);
- xBroadcasterNew->addModifyListener(mxListener);
+ 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();
+}
+
+void ChartAxisPanel::SelectionInvalid()
+{
}
IMPL_LINK(ChartAxisPanel, CheckBoxHdl, CheckBox*, pCheckbox)
diff --git a/chart2/source/controller/sidebar/ChartAxisPanel.hxx b/chart2/source/controller/sidebar/ChartAxisPanel.hxx
index 5c1177fed392..c21fa331fdd4 100644
--- a/chart2/source/controller/sidebar/ChartAxisPanel.hxx
+++ b/chart2/source/controller/sidebar/ChartAxisPanel.hxx
@@ -17,8 +17,10 @@
#include <svx/sidebar/PanelLayout.hxx>
#include "ChartSidebarModifyListener.hxx"
+#include "ChartSidebarSelectionListener.hxx"
#include <com/sun/star/util/XModifyListener.hpp>
+#include <com/sun/star/view/XSelectionChangeListener.hpp>
class FixedText;
class ListBox;
@@ -34,7 +36,8 @@ class ChartAxisPanel : public PanelLayout,
public ::sfx2::sidebar::IContextChangeReceiver,
public ::sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface,
public sfx2::sidebar::SidebarModelUpdate,
- public ChartSidebarModifyListenerParent
+ public ChartSidebarModifyListenerParent,
+ public ChartSidebarSelectionListenerParent
{
public:
static VclPtr<vcl::Window> Create(
@@ -65,6 +68,9 @@ public:
virtual void updateData() SAL_OVERRIDE;
virtual void modelInvalid() SAL_OVERRIDE;
+ virtual void selectionChanged(bool bCorrectType) SAL_OVERRIDE;
+ virtual void SelectionInvalid() SAL_OVERRIDE;
+
virtual void updateModel(css::uno::Reference<css::frame::XModel> xModel) SAL_OVERRIDE;
private:
@@ -77,7 +83,8 @@ private:
css::uno::Reference<css::frame::XFrame> mxFrame;
css::uno::Reference<css::frame::XModel> mxModel;
- css::uno::Reference<css::util::XModifyListener> mxListener;
+ css::uno::Reference<css::util::XModifyListener> mxModifyListener;
+ css::uno::Reference<css::view::XSelectionChangeListener> mxSelectionListener;
void Initialize();
diff --git a/chart2/source/controller/sidebar/ChartSeriesPanel.cxx b/chart2/source/controller/sidebar/ChartSeriesPanel.cxx
index 0cb9aeed2bf2..644766d4ac69 100644
--- a/chart2/source/controller/sidebar/ChartSeriesPanel.cxx
+++ b/chart2/source/controller/sidebar/ChartSeriesPanel.cxx
@@ -291,7 +291,8 @@ ChartSeriesPanel::ChartSeriesPanel(
: PanelLayout(pParent, "ChartSeriesPanel", "modules/schart/ui/sidebarseries.ui", rxFrame),
mxFrame(rxFrame),
mxModel(pController->getModel()),
- mxListener(new ChartSidebarModifyListener(this))
+ mxListener(new ChartSidebarModifyListener(this)),
+ mxSelectionListener(new ChartSidebarSelectionListener(this, OBJECTTYPE_DATA_SERIES))
{
get(mpCBLabel, "checkbutton_label");
get(mpCBTrendline, "checkbutton_trendline");
@@ -317,6 +318,9 @@ void ChartSeriesPanel::dispose()
{
css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
xBroadcaster->removeModifyListener(mxListener);
+ css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(mxModel->getCurrentController(), css::uno::UNO_QUERY);
+ if (xSelectionSupplier.is())
+ xSelectionSupplier->removeSelectionChangeListener(mxSelectionListener);
mpCBLabel.clear();
mpCBTrendline.clear();
@@ -337,6 +341,9 @@ void ChartSeriesPanel::Initialize()
{
css::uno::Reference<css::util::XModifyBroadcaster> xBroadcaster(mxModel, css::uno::UNO_QUERY_THROW);
xBroadcaster->addModifyListener(mxListener);
+ css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(mxModel->getCurrentController(), css::uno::UNO_QUERY);
+ if (xSelectionSupplier.is())
+ xSelectionSupplier->addSelectionChangeListener(mxSelectionListener);
updateData();
@@ -422,6 +429,20 @@ void ChartSeriesPanel::updateModel(
css::uno::Reference<css::util::XModifyBroadcaster> xBroadcasterNew(mxModel, css::uno::UNO_QUERY_THROW);
xBroadcasterNew->addModifyListener(mxListener);
+
+ css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(mxModel->getCurrentController(), css::uno::UNO_QUERY);
+ if (xSelectionSupplier.is())
+ xSelectionSupplier->addSelectionChangeListener(mxSelectionListener);
+}
+
+void ChartSeriesPanel::selectionChanged(bool bCorrectType)
+{
+ if (bCorrectType)
+ updateData();
+}
+
+void ChartSeriesPanel::SelectionInvalid()
+{
}
IMPL_LINK(ChartSeriesPanel, CheckBoxHdl, CheckBox*, pCheckBox)
diff --git a/chart2/source/controller/sidebar/ChartSeriesPanel.hxx b/chart2/source/controller/sidebar/ChartSeriesPanel.hxx
index 10d73ee8e15e..156bbc779bd0 100644
--- a/chart2/source/controller/sidebar/ChartSeriesPanel.hxx
+++ b/chart2/source/controller/sidebar/ChartSeriesPanel.hxx
@@ -25,8 +25,10 @@
#include <svx/sidebar/PanelLayout.hxx>
#include "ChartSidebarModifyListener.hxx"
+#include "ChartSidebarSelectionListener.hxx"
#include <com/sun/star/util/XModifyListener.hpp>
+#include <com/sun/star/view/XSelectionChangeListener.hpp>
class FixedText;
class ListBox;
@@ -42,7 +44,8 @@ class ChartSeriesPanel : public PanelLayout,
public ::sfx2::sidebar::IContextChangeReceiver,
public ::sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface,
public sfx2::sidebar::SidebarModelUpdate,
- public ChartSidebarModifyListenerParent
+ public ChartSidebarModifyListenerParent,
+ public ChartSidebarSelectionListenerParent
{
public:
static VclPtr<vcl::Window> Create(
@@ -73,6 +76,9 @@ public:
virtual void updateData() SAL_OVERRIDE;
virtual void modelInvalid() SAL_OVERRIDE;
+ virtual void selectionChanged(bool bCorrectType) SAL_OVERRIDE;
+ virtual void SelectionInvalid() SAL_OVERRIDE;
+
virtual void updateModel(css::uno::Reference<css::frame::XModel> xModel) SAL_OVERRIDE;
private:
@@ -93,6 +99,7 @@ private:
css::uno::Reference<css::frame::XModel> mxModel;
css::uno::Reference<css::util::XModifyListener> mxListener;
+ css::uno::Reference<css::view::XSelectionChangeListener> mxSelectionListener;
void Initialize();
diff --git a/chart2/source/controller/sidebar/ChartSidebarSelectionListener.cxx b/chart2/source/controller/sidebar/ChartSidebarSelectionListener.cxx
new file mode 100644
index 000000000000..1f435e1e7d4b
--- /dev/null
+++ b/chart2/source/controller/sidebar/ChartSidebarSelectionListener.cxx
@@ -0,0 +1,81 @@
+/* -*- 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/.
+ */
+
+#include "ChartSidebarSelectionListener.hxx"
+
+#include <com/sun/star/view/XSelectionSupplier.hpp>
+#include <com/sun/star/frame/XController.hpp>
+
+#include "ObjectIdentifier.hxx"
+
+namespace chart {
+namespace sidebar {
+
+ChartSidebarSelectionListenerParent::~ChartSidebarSelectionListenerParent()
+{
+}
+
+ChartSidebarSelectionListener::ChartSidebarSelectionListener(
+ ChartSidebarSelectionListenerParent* pParent):
+ mpParent(pParent),
+ mbAll(true),
+ meType()
+{
+}
+
+ChartSidebarSelectionListener::ChartSidebarSelectionListener(
+ ChartSidebarSelectionListenerParent* pParent,
+ ObjectType eType):
+ mpParent(pParent),
+ mbAll(false),
+ meType(eType)
+{
+}
+
+ChartSidebarSelectionListener::~ChartSidebarSelectionListener()
+{
+}
+
+void ChartSidebarSelectionListener::selectionChanged(const css::lang::EventObject& rEvent)
+ throw (::css::uno::RuntimeException, ::std::exception)
+{
+ (void)rEvent;
+ bool bCorrectObjectSelected = false;
+ if (mbAll)
+ bCorrectObjectSelected = true;
+
+ css::uno::Reference<css::frame::XController> xController(rEvent.Source, css::uno::UNO_QUERY);
+ if (!mbAll && xController.is())
+ {
+ css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(xController, css::uno::UNO_QUERY);
+ if (xSelectionSupplier.is())
+ {
+ css::uno::Any aAny = xSelectionSupplier->getSelection();
+ if (aAny.hasValue())
+ {
+ OUString aCID;
+ aAny >>= aCID;
+ ObjectType eType = ObjectIdentifier::getObjectType(aCID);
+ bCorrectObjectSelected = eType == meType;
+ }
+ }
+ }
+
+ mpParent->selectionChanged(bCorrectObjectSelected);
+}
+
+void ChartSidebarSelectionListener::disposing(const css::lang::EventObject& /*rEvent*/)
+ throw (::css::uno::RuntimeException, ::std::exception)
+{
+ mpParent->SelectionInvalid();
+}
+
+} }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/controller/sidebar/ChartSidebarSelectionListener.hxx b/chart2/source/controller/sidebar/ChartSidebarSelectionListener.hxx
new file mode 100644
index 000000000000..cfe90e784e4d
--- /dev/null
+++ b/chart2/source/controller/sidebar/ChartSidebarSelectionListener.hxx
@@ -0,0 +1,58 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_SIDEBAR_CHARTSIDEBARSELECTIONLISTENER_HXX
+#define INCLUDED_CHART2_SOURCE_CONTROLLER_SIDEBAR_CHARTSIDEBARSELECTIONLISTENER_HXX
+
+#include <com/sun/star/view/XSelectionChangeListener.hpp>
+#include <cppuhelper/implbase1.hxx>
+
+#include "ObjectIdentifier.hxx"
+
+namespace chart {
+namespace sidebar {
+
+class ChartSidebarSelectionListenerParent
+{
+public:
+ virtual ~ChartSidebarSelectionListenerParent();
+
+ virtual void selectionChanged(bool bSelected) = 0;
+
+ virtual void SelectionInvalid() = 0;
+};
+
+class ChartSidebarSelectionListener : public cppu::WeakImplHelper1<css::view::XSelectionChangeListener>
+{
+public:
+
+ // listen to all chart selection changes
+ ChartSidebarSelectionListener(ChartSidebarSelectionListenerParent* pParent);
+ // only liste to the changes of eType
+ ChartSidebarSelectionListener(ChartSidebarSelectionListenerParent* pParent, ObjectType eType);
+ virtual ~ChartSidebarSelectionListener();
+
+ virtual void SAL_CALL selectionChanged(const css::lang::EventObject& rEvent)
+ throw (::css::uno::RuntimeException, ::std::exception) SAL_OVERRIDE;
+
+ virtual void SAL_CALL disposing(const css::lang::EventObject& rEvent)
+ throw (::css::uno::RuntimeException, ::std::exception) SAL_OVERRIDE;
+
+private:
+ ChartSidebarSelectionListenerParent* mpParent;
+
+ bool mbAll;
+ ObjectType meType;
+};
+
+} }
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */