22#include <com/sun/star/awt/MouseButton.hpp>
23#include <com/sun/star/awt/SystemPointer.hpp>
24#include <com/sun/star/system/SystemShellExecute.hpp>
25#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
26#include <com/sun/star/system/XSystemShellExecute.hpp>
35using namespace css::uno;
36using namespace css::drawing;
37using namespace css::system;
43 CursorManager& rCursorManager,
46 const Reference<XDrawPage>& xDrawPage ):
50 mrGlobalListenersMap(rGlobalListenersMap),
51 mrGlobalCursorMap(rGlobalCursorMap),
60void ShapeManagerImpl::activate()
74 for(
const auto& rListener : mrGlobalListenersMap )
75 listenerAdded( rListener.first );
78 for(
const auto& rListener : mrGlobalCursorMap )
79 cursorChanged( rListener.first, rListener.second );
85void ShapeManagerImpl::deactivate()
95 maShapeListenerMap.clear();
96 maShapeCursorMap.clear();
98 mrMultiplexer.removeShapeListenerHandler( shared_from_this() );
103void ShapeManagerImpl::dispose()
108 maHyperlinkShapes.clear();
109 maShapeCursorMap.clear();
110 maShapeListenerMap.clear();
114bool ShapeManagerImpl::handleMousePressed( awt::MouseEvent
const& )
120bool ShapeManagerImpl::handleMouseReleased( awt::MouseEvent
const& e )
122 if( !mbEnabled || e.Buttons != awt::MouseButton::LEFT)
129 OUString
const hyperlink( checkForHyperlink(aPosition) );
130 if( !hyperlink.isEmpty() )
137 OUString
const imageMapLink(checkForImageMap(e));
138 if (!imageMapLink.isEmpty())
140 Reference<XSystemShellExecute> exec(
142 exec->execute(imageMapLink, OUString(), SystemShellExecuteFlags::URIS_ONLY);
149 auto aCurrBroadcaster = std::find_if(maShapeListenerMap.rbegin(), maShapeListenerMap.rend(),
150 [&aPosition](
const ShapeToListenersMap::value_type& rBroadcaster) {
154 return rBroadcaster.first->getBounds().isInside( aPosition )
155 && rBroadcaster.first->isVisible();
157 if (aCurrBroadcaster != maShapeListenerMap.rend())
162 std::shared_ptr<comphelper::OInterfaceContainerHelper3<css::presentation::XShapeEventListener>>
const & pCont =
163 aCurrBroadcaster->second;
165 aCurrBroadcaster->first->getXShape() );
170 {
return rListener->click( xShape, e ); } );
178bool ShapeManagerImpl::handleMouseDragged(
const awt::MouseEvent& )
184bool ShapeManagerImpl::handleMouseMoved(
const awt::MouseEvent& e )
190 const ::basegfx::B2DPoint aPosition( e.X, e.Y );
191 sal_Int16 nNewCursor(-1);
193 if( !checkForHyperlink(aPosition).isEmpty() || !checkForImageMap(e).isEmpty() )
195 nNewCursor = awt::SystemPointer::REFHAND;
201 auto aCurrCursor = std::find_if(maShapeCursorMap.rbegin(), maShapeCursorMap.rend(),
202 [&aPosition](
const ShapeToCursorMap::value_type& rCursor) {
206 return rCursor.first->getBounds().isInside( aPosition )
207 && rCursor.first->isVisible();
209 if (aCurrCursor != maShapeCursorMap.rend())
213 nNewCursor = aCurrCursor->second;
217 if( nNewCursor == -1 )
226bool ShapeManagerImpl::update()
234bool ShapeManagerImpl::needsUpdate()
const
276 maHyperlinkShapes.insert(rArea);
295bool ShapeManagerImpl::listenerAdded(
298 ShapeEventListenerMap::const_iterator aIter = mrGlobalListenersMap.find( xShape );
299 if( aIter == mrGlobalListenersMap.end() )
302 "ShapeManagerImpl::listenerAdded(): global "
303 "shape listener map inconsistency!");
310 maShapeListenerMap.emplace(pShape, aIter->second);
320 if( mrGlobalListenersMap.find(xShape) == mrGlobalListenersMap.end() )
325 maShapeListenerMap.erase(pShape);
340 if( mrGlobalCursorMap.find(xShape) == mrGlobalCursorMap.end() )
343 maShapeCursorMap.erase(pShape);
348 ShapeToCursorMap::iterator aIter;
349 if( (aIter = maShapeCursorMap.find(pShape))
350 == maShapeCursorMap.end() )
352 maShapeCursorMap.emplace(pShape, nCursor);
356 aIter->second = nCursor;
365 AreaSet::const_reverse_iterator iPos( maHyperlinkShapes.rbegin() );
366 AreaSet::const_reverse_iterator
const iEnd( maHyperlinkShapes.rend() );
367 for( ; iPos != iEnd; ++iPos )
372 pArea->getHyperlinkRegions() );
374 for( std::size_t
i = linkRegions.size();
i--; )
378 return linkRegions[
i].second;
385OUString ShapeManagerImpl::checkForImageMap( awt::MouseEvent
const& evt )
const
389 Reference<XShape> xShape(
mxDrawPage->getByIndex(
i), UNO_QUERY_THROW);
394 if (pIMapObj && !pIMapObj->
GetURL().isEmpty())
396 return pIMapObj->
GetURL();
404 maIntrinsicAnimationEventHandlers.add( rHandler );
409 maIntrinsicAnimationEventHandlers.remove( rHandler );
412void ShapeManagerImpl::notifyIntrinsicAnimationsEnabled()
414 maIntrinsicAnimationEventHandlers.applyAll(
415 std::mem_fn(&IntrinsicAnimationEventHandler::enableAnimations));
418void ShapeManagerImpl::notifyIntrinsicAnimationsDisabled()
420 maIntrinsicAnimationEventHandlers.applyAll(
421 std::mem_fn(&IntrinsicAnimationEventHandler::disableAnimations));
const OUString & GetURL() const
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
static IMapObject * GetHitIMapObject(const SdrObject *pObj, const Point &rWinPoint, const OutputDevice *pCmpWnd=nullptr)
bool isInside(const Tuple2D< TYPE > &rTuple) const
This class represents kind of a DOM tree node for shape text.
std::vector< HyperlinkRegion > HyperlinkRegions
ShapeManagerImpl(EventMultiplexer &rMultiplexer, LayerManagerSharedPtr xLayerManager, CursorManager &rCursorManager, const ShapeEventListenerMap &rGlobalListenersMap, const ShapeCursorMap &rGlobalCursorMap, const css::uno::Reference< css::drawing::XDrawPage > &xDrawPage)
Create a shape event broadcaster.
#define ENSURE_OR_RETURN_FALSE(c, m)
Reference< XComponentContext > getProcessComponentContext()
::std::shared_ptr< AnimatableShape > AnimatableShapeSharedPtr
std::shared_ptr< HyperlinkArea > HyperlinkAreaSharedPtr
::std::shared_ptr< LayerManager > LayerManagerSharedPtr
::std::map< css::uno::Reference< css::drawing::XShape >, sal_Int16 > ShapeCursorMap
Maps XShape to mouse cursor.
::std::shared_ptr< IntrinsicAnimationEventHandler > IntrinsicAnimationEventHandlerSharedPtr
::std::map< css::uno::Reference< css::drawing::XShape >, std::shared_ptr< ::comphelper::OInterfaceContainerHelper3< css::presentation::XShapeEventListener > > > ShapeEventListenerMap
Maps XShape to shape listener.
::std::shared_ptr< AttributableShape > AttributableShapeSharedPtr
std::unordered_map< css::uno::Reference< css::drawing::XShape >, ShapeSharedPtr, hash< css::uno::Reference< css::drawing::XShape > > > XShapeToShapeMap
A hash map which maps the XShape to the corresponding Shape object.
::std::shared_ptr< Shape > ShapeSharedPtr
CursorManager & mrCursorManager
parent cursor manager
uno::Reference< drawing::XDrawPage > mxDrawPage
The page model object.
LayerManagerSharedPtr mpLayerManager
EventMultiplexer & mrMultiplexer