/src/libreoffice/svx/source/sidebar/SelectionChangeHandler.cxx
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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | #include <svx/sidebar/SelectionChangeHandler.hxx> |
20 | | #include <svx/sidebar/ContextChangeEventMultiplexer.hxx> |
21 | | |
22 | | #include <com/sun/star/view/XSelectionSupplier.hpp> |
23 | | |
24 | | #include <utility> |
25 | | #include <vcl/EnumContext.hxx> |
26 | | |
27 | | |
28 | | using namespace css; |
29 | | using namespace css::uno; |
30 | | |
31 | | namespace svx::sidebar { |
32 | | |
33 | | SelectionChangeHandler::SelectionChangeHandler ( |
34 | | std::function<OUString()> aSelectionChangeCallback, |
35 | | const Reference<css::frame::XController>& rxController, |
36 | | const vcl::EnumContext::Context eDefaultContext) |
37 | 0 | : maSelectionChangeCallback(std::move(aSelectionChangeCallback)), |
38 | 0 | mxController(rxController), |
39 | 0 | meDefaultContext(eDefaultContext), |
40 | 0 | mbIsConnected(false) |
41 | 0 | { |
42 | 0 | } Unexecuted instantiation: svx::sidebar::SelectionChangeHandler::SelectionChangeHandler(std::__1::function<rtl::OUString ()>, com::sun::star::uno::Reference<com::sun::star::frame::XController> const&, vcl::EnumContext::Context) Unexecuted instantiation: svx::sidebar::SelectionChangeHandler::SelectionChangeHandler(std::__1::function<rtl::OUString ()>, com::sun::star::uno::Reference<com::sun::star::frame::XController> const&, vcl::EnumContext::Context) |
43 | | |
44 | | |
45 | | SelectionChangeHandler::~SelectionChangeHandler() |
46 | 0 | { |
47 | 0 | } |
48 | | |
49 | | |
50 | | void SAL_CALL SelectionChangeHandler::selectionChanged (const lang::EventObject&) |
51 | 0 | { |
52 | 0 | if (maSelectionChangeCallback) |
53 | 0 | { |
54 | 0 | const vcl::EnumContext::Context eContext ( |
55 | 0 | vcl::EnumContext::GetContextEnum(maSelectionChangeCallback())); |
56 | 0 | ContextChangeEventMultiplexer::NotifyContextChange( |
57 | 0 | mxController, |
58 | 0 | eContext==vcl::EnumContext::Context::Unknown |
59 | 0 | ? meDefaultContext |
60 | 0 | : eContext); |
61 | 0 | } |
62 | 0 | } |
63 | | |
64 | | |
65 | | void SAL_CALL SelectionChangeHandler::disposing (const lang::EventObject&) |
66 | 0 | { |
67 | 0 | } |
68 | | |
69 | | |
70 | | void SelectionChangeHandler::disposing(std::unique_lock<std::mutex>&) |
71 | 0 | { |
72 | 0 | if (mbIsConnected) |
73 | 0 | Disconnect(); |
74 | 0 | } |
75 | | |
76 | | |
77 | | void SelectionChangeHandler::Connect() |
78 | 0 | { |
79 | 0 | uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY); |
80 | 0 | if (xSupplier.is()) |
81 | 0 | { |
82 | 0 | mbIsConnected = true; |
83 | 0 | xSupplier->addSelectionChangeListener(this); |
84 | 0 | } |
85 | 0 | } |
86 | | |
87 | | |
88 | | void SelectionChangeHandler::Disconnect() |
89 | 0 | { |
90 | 0 | uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY); |
91 | 0 | if (xSupplier.is()) |
92 | 0 | { |
93 | 0 | mbIsConnected = false; |
94 | 0 | xSupplier->removeSelectionChangeListener(this); |
95 | 0 | } |
96 | 0 | } |
97 | | |
98 | | |
99 | | } // end of namespace svx::sidebar |
100 | | |
101 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |