/src/libreoffice/sc/source/ui/Accessibility/DrawModelBroadcaster.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 | | |
20 | | #include <DrawModelBroadcaster.hxx> |
21 | | #include <svx/svdmodel.hxx> |
22 | | #include <svx/unomod.hxx> |
23 | | #include <svx/svdobj.hxx> |
24 | | |
25 | | using namespace ::com::sun::star; |
26 | | |
27 | | ScDrawModelBroadcaster::ScDrawModelBroadcaster( SdrModel *pDrawModel ) : |
28 | 0 | mpDrawModel( pDrawModel ) |
29 | 0 | { |
30 | 0 | if (mpDrawModel) |
31 | 0 | StartListening( *mpDrawModel ); |
32 | 0 | } |
33 | | |
34 | | ScDrawModelBroadcaster::~ScDrawModelBroadcaster() |
35 | 0 | { |
36 | 0 | if (mpDrawModel) |
37 | 0 | EndListening( *mpDrawModel ); |
38 | 0 | } |
39 | | |
40 | | void SAL_CALL ScDrawModelBroadcaster::addEventListener( const uno::Reference< document::XEventListener >& xListener ) |
41 | 0 | { |
42 | 0 | std::unique_lock aGuard(maListenerMutex); |
43 | 0 | maEventListeners.addInterface( aGuard, xListener ); |
44 | 0 | } |
45 | | |
46 | | void SAL_CALL ScDrawModelBroadcaster::removeEventListener( const uno::Reference< document::XEventListener >& xListener ) |
47 | 0 | { |
48 | 0 | std::unique_lock aGuard(maListenerMutex); |
49 | 0 | maEventListeners.removeInterface( aGuard, xListener ); |
50 | 0 | } |
51 | | |
52 | | void SAL_CALL ScDrawModelBroadcaster::addShapeEventListener( |
53 | | const css::uno::Reference< css::drawing::XShape >& xShape, |
54 | | const uno::Reference< document::XShapeEventListener >& xListener ) |
55 | 0 | { |
56 | 0 | assert(xShape.is() && "no shape?"); |
57 | 0 | std::scoped_lock aGuard(maListenerMutex); |
58 | 0 | auto rv = maShapeListeners.emplace(xShape, xListener); |
59 | 0 | assert(rv.second && "duplicate listener?"); |
60 | 0 | (void)rv; |
61 | 0 | } |
62 | | |
63 | | void SAL_CALL ScDrawModelBroadcaster::removeShapeEventListener( |
64 | | const css::uno::Reference< css::drawing::XShape >& xShape, |
65 | | const uno::Reference< document::XShapeEventListener >& xListener ) |
66 | 0 | { |
67 | 0 | std::scoped_lock aGuard(maListenerMutex); |
68 | 0 | auto it = maShapeListeners.find(xShape); |
69 | 0 | if (it != maShapeListeners.end()) |
70 | 0 | { |
71 | 0 | assert(it->second == xListener && "removing wrong listener?"); |
72 | 0 | (void)xListener; |
73 | 0 | maShapeListeners.erase(it); |
74 | 0 | } |
75 | 0 | } |
76 | | |
77 | | void ScDrawModelBroadcaster::Notify( SfxBroadcaster&, |
78 | | const SfxHint& rHint ) |
79 | 0 | { |
80 | 0 | if (rHint.GetId() != SfxHintId::ThisIsAnSdrHint) |
81 | 0 | return; |
82 | 0 | const SdrHint* pSdrHint = static_cast<const SdrHint*>(&rHint); |
83 | |
|
84 | 0 | document::EventObject aEvent; |
85 | 0 | if( !SvxUnoDrawMSFactory::createEvent( mpDrawModel, pSdrHint, aEvent ) ) |
86 | 0 | return; |
87 | | |
88 | 0 | std::unique_lock aGuard(maListenerMutex); |
89 | 0 | maEventListeners.forEach(aGuard, |
90 | 0 | [&aEvent](const css::uno::Reference<document::XEventListener>& xListener) |
91 | 0 | { |
92 | 0 | xListener->notifyEvent(aEvent); |
93 | 0 | } |
94 | 0 | ); |
95 | | |
96 | | // right now, we're only handling the specific event necessary to fix this performance problem |
97 | 0 | if (pSdrHint->GetKind() == SdrHintKind::ObjectChange) |
98 | 0 | { |
99 | 0 | auto pSdrObject = const_cast<SdrObject*>(pSdrHint->GetObject()); |
100 | 0 | uno::Reference<drawing::XShape> xShape(pSdrObject->getUnoShape(), uno::UNO_QUERY); |
101 | 0 | auto it = maShapeListeners.find(xShape); |
102 | 0 | if (it != maShapeListeners.end()) |
103 | 0 | it->second->notifyShapeEvent(aEvent); |
104 | 0 | } |
105 | 0 | } |
106 | | |
107 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |