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