Kaydet (Commit) bc459213 authored tarafından Markus Mohrhard's avatar Markus Mohrhard

add selection change listener

This finally allows us to handle the case where you switch between
objects of the same type.

Change-Id: Ic13e15e2a426d08995a577dfc1b7ee6f7da04f30
üst 0635208e
......@@ -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
......
......@@ -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)
......
......@@ -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();
......
......@@ -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)
......
......@@ -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();
......
/* -*- 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: */
/* -*- 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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment