[Libreoffice-commits] core.git: Branch 'feature/chart-sidebar' - chart2/Library_chartcontroller.mk chart2/source

Markus Mohrhard markus.mohrhard at googlemail.com
Thu Jul 23 07:21:44 PDT 2015


 chart2/Library_chartcontroller.mk                                  |    1 
 chart2/source/controller/sidebar/ChartAxisPanel.cxx                |   33 +++-
 chart2/source/controller/sidebar/ChartAxisPanel.hxx                |   11 +
 chart2/source/controller/sidebar/ChartSeriesPanel.cxx              |   23 ++
 chart2/source/controller/sidebar/ChartSeriesPanel.hxx              |    9 -
 chart2/source/controller/sidebar/ChartSidebarSelectionListener.cxx |   81 ++++++++++
 chart2/source/controller/sidebar/ChartSidebarSelectionListener.hxx |   58 +++++++
 7 files changed, 207 insertions(+), 9 deletions(-)

New commits:
commit fe24ed6f1ac74bfe5096b96dd8b58b2f47e43a21
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Thu Jul 23 16:20:36 2015 +0200

    add selection change listener
    
    This finally allows us to handle the case where you switch between
    objects of the same type.
    
    Change-Id: Ic13e15e2a426d08995a577dfc1b7ee6f7da04f30

diff --git a/chart2/Library_chartcontroller.mk b/chart2/Library_chartcontroller.mk
index 198640e..2e03a7e 100644
--- a/chart2/Library_chartcontroller.mk
+++ b/chart2/Library_chartcontroller.mk
@@ -194,6 +194,7 @@ $(eval $(call gb_Library_add_exception_objects,chartcontroller,\
     chart2/source/controller/sidebar/ChartErrorBarPanel \
     chart2/source/controller/sidebar/ChartSeriesPanel \
     chart2/source/controller/sidebar/ChartSidebarModifyListener \
+    chart2/source/controller/sidebar/ChartSidebarSelectionListener \
 ))
 
 # Runtime dependency for unit-tests
diff --git a/chart2/source/controller/sidebar/ChartAxisPanel.cxx b/chart2/source/controller/sidebar/ChartAxisPanel.cxx
index ba1a5e7..a9dcae7 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 5c1177f..c21fa33 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 22d13fd..ae5691e 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 10d73ee..156bbc7 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 0000000..1f435e1
--- /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 0000000..cfe90e7
--- /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: */


More information about the Libreoffice-commits mailing list