LibreOffice Module chart2 (master) 1
ChartSidebarSelectionListener.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
11
12#include <com/sun/star/view/XSelectionSupplier.hpp>
13#include <com/sun/star/frame/XController.hpp>
14
15#include <ObjectIdentifier.hxx>
16
17namespace chart::sidebar {
18
20{
21}
22
25 mpParent(pParent)
26{
27}
28
31 ObjectType eType):
32 mpParent(pParent)
33{
34 maTypes.push_back(eType);
35}
36
38{
39}
40
41void ChartSidebarSelectionListener::selectionChanged(const css::lang::EventObject& rEvent)
42{
43 if (!mpParent)
44 return;
45
46 bool bCorrectObjectSelected = false;
47
48 css::uno::Reference<css::frame::XController> xController(rEvent.Source, css::uno::UNO_QUERY);
49 if (xController.is())
50 {
51 css::uno::Reference<css::view::XSelectionSupplier> xSelectionSupplier(xController, css::uno::UNO_QUERY);
52 if (xSelectionSupplier.is())
53 {
54 css::uno::Any aAny = xSelectionSupplier->getSelection();
55 if (aAny.hasValue())
56 {
57 OUString aCID;
58 aAny >>= aCID;
60 bCorrectObjectSelected = std::any_of(maTypes.begin(), maTypes.end(),
61 [eType](const ObjectType& eTypeInVector) { return eType == eTypeInVector; });
62 }
63 }
64 }
65
66 mpParent->selectionChanged(bCorrectObjectSelected);
67}
68
69void ChartSidebarSelectionListener::disposing(const css::lang::EventObject& /*rEvent*/)
70{
71 if (!mpParent)
72 return;
73
74 mpParent = nullptr;
75}
76
77void ChartSidebarSelectionListener::setAcceptedTypes(std::vector<ObjectType>&& aTypes)
78{
79 maTypes = std::move(aTypes);
80}
81
82}
83
84/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ObjectType getObjectType() const
virtual void selectionChanged(bool bSelected)=0
virtual void SAL_CALL selectionChanged(const css::lang::EventObject &rEvent) override
ChartSidebarSelectionListener(ChartSidebarSelectionListenerParent *pParent)
virtual void SAL_CALL disposing(const css::lang::EventObject &rEvent) override
void setAcceptedTypes(std::vector< ObjectType > &&aTypes)
RegionData_Impl * mpParent
DocumentType eType
Reference< XController > xController
const SvXMLTokenMapEntry aTypes[]