Line data Source code
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/SelectionAnalyzer.hxx"
21 : #include "svx/sidebar/ContextChangeEventMultiplexer.hxx"
22 : #include "svx/svdmrkv.hxx"
23 :
24 : #include <sfx2/sidebar/EnumContext.hxx>
25 : #include <sfx2/shell.hxx>
26 :
27 :
28 : using namespace css;
29 : using namespace css::uno;
30 :
31 : using namespace sfx2::sidebar;
32 :
33 : namespace svx { namespace sidebar {
34 :
35 135 : SelectionChangeHandler::SelectionChangeHandler (
36 : const boost::function<rtl::OUString()>& rSelectionChangeCallback,
37 : const Reference<frame::XController>& rxController,
38 : const EnumContext::Context eDefaultContext)
39 : : SelectionChangeHandlerInterfaceBase(m_aMutex),
40 : maSelectionChangeCallback(rSelectionChangeCallback),
41 : mxController(rxController),
42 : meDefaultContext(eDefaultContext),
43 135 : mbIsConnected(false)
44 : {
45 135 : }
46 :
47 :
48 :
49 :
50 268 : SelectionChangeHandler::~SelectionChangeHandler()
51 : {
52 268 : }
53 :
54 :
55 :
56 :
57 326 : void SAL_CALL SelectionChangeHandler::selectionChanged (const lang::EventObject&)
58 : throw (uno::RuntimeException, std::exception)
59 : {
60 326 : if (maSelectionChangeCallback)
61 : {
62 : const EnumContext::Context eContext (
63 326 : EnumContext::GetContextEnum(maSelectionChangeCallback()));
64 : ContextChangeEventMultiplexer::NotifyContextChange(
65 : mxController,
66 : eContext==EnumContext::Context_Unknown
67 : ? meDefaultContext
68 326 : : eContext);
69 : }
70 326 : }
71 :
72 :
73 :
74 :
75 0 : void SAL_CALL SelectionChangeHandler::disposing (const lang::EventObject&)
76 : throw (uno::RuntimeException, std::exception)
77 : {
78 0 : }
79 :
80 :
81 :
82 :
83 134 : void SAL_CALL SelectionChangeHandler::disposing()
84 : throw (uno::RuntimeException)
85 : {
86 134 : if (mbIsConnected)
87 0 : Disconnect();
88 134 : }
89 :
90 :
91 :
92 :
93 135 : void SelectionChangeHandler::Connect()
94 : {
95 135 : uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY);
96 135 : if (xSupplier.is())
97 : {
98 135 : mbIsConnected = true;
99 135 : xSupplier->addSelectionChangeListener(this);
100 135 : }
101 135 : }
102 :
103 :
104 :
105 :
106 134 : void SelectionChangeHandler::Disconnect()
107 : {
108 134 : uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY);
109 134 : if (xSupplier.is())
110 : {
111 134 : mbIsConnected = false;
112 134 : xSupplier->removeSelectionChangeListener(this);
113 134 : }
114 134 : }
115 :
116 :
117 390 : } } // end of namespace svx::sidebar
118 :
119 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|