Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/devtools/SelectionChangeHandler.hxx
Line
Count
Source
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
 */
10
11
#pragma once
12
13
#include <DevelopmentToolDockingWindow.hxx>
14
15
#include <com/sun/star/frame/XController.hpp>
16
#include <com/sun/star/view/XSelectionSupplier.hpp>
17
18
#include <comphelper/compbase.hxx>
19
#include <utility>
20
21
typedef comphelper::WeakComponentImplHelper<css::view::XSelectionChangeListener>
22
    SelectionChangeHandlerInterfaceBase;
23
24
/** Selection change handler to listen to document selection changes.
25
 *
26
 * Listens to the changes and notifies the docking window with a new
27
 * selected object, when a change happens.
28
 */
29
class SelectionChangeHandler final : public SelectionChangeHandlerInterfaceBase
30
{
31
private:
32
    css::uno::Reference<css::frame::XController> mxController;
33
    VclPtr<DevelopmentToolDockingWindow> mpDockingWindow;
34
35
public:
36
    SelectionChangeHandler(css::uno::Reference<css::frame::XController> xController,
37
                           DevelopmentToolDockingWindow* pDockingWindow)
38
0
        : mxController(std::move(xController))
39
0
        , mpDockingWindow(pDockingWindow)
40
0
    {
41
0
        css::uno::Reference<css::view::XSelectionSupplier> xSupplier(mxController,
42
0
                                                                     css::uno::UNO_QUERY);
43
0
        xSupplier->addSelectionChangeListener(this);
44
0
    }
45
46
0
    ~SelectionChangeHandler() { mpDockingWindow.disposeAndClear(); }
47
48
    virtual void SAL_CALL selectionChanged(const css::lang::EventObject& /*rEvent*/) override
49
0
    {
50
0
        css::uno::Reference<css::view::XSelectionSupplier> xSupplier(mxController,
51
0
                                                                     css::uno::UNO_QUERY);
52
0
        if (xSupplier.is())
53
0
        {
54
0
            css::uno::Any aAny = xSupplier->getSelection();
55
0
            auto xInterface = aAny.get<css::uno::Reference<css::uno::XInterface>>();
56
0
            mpDockingWindow->selectionChanged(xInterface);
57
0
        }
58
0
    }
59
60
    void stopListening()
61
0
    {
62
0
        css::uno::Reference<css::view::XSelectionSupplier> xSupplier(mxController,
63
0
                                                                     css::uno::UNO_QUERY);
64
0
        xSupplier->removeSelectionChangeListener(this);
65
0
    }
66
67
0
    virtual void SAL_CALL disposing(const css::lang::EventObject& /*rEvent*/) override {}
68
    using comphelper::WeakComponentImplHelperBase::disposing;
69
70
private:
71
    SelectionChangeHandler(const SelectionChangeHandler&) = delete;
72
    SelectionChangeHandler& operator=(const SelectionChangeHandler&) = delete;
73
};
74
75
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */