diff options
author | Amin Irgaliev <irgaliev01@mail.ru> | 2023-05-03 19:54:17 +0400 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-05-04 06:23:38 +0200 |
commit | 8d8779808063aeedcf0d2b7efba3d2f82e0d7bef (patch) | |
tree | 16e849b905c5f460a2262647f609e0c3deb07dab /slideshow/source | |
parent | 83b1f6b58a30bdb589e9ce73deef39f021aebde1 (diff) |
tdf#154839 Add navigation buttons for slides
Change-Id: Ie9a533acf94f5760c6233aa70259bec620f420fb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150448
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'slideshow/source')
-rw-r--r-- | slideshow/source/engine/eventmultiplexer.cxx | 66 | ||||
-rw-r--r-- | slideshow/source/engine/slideoverlaybutton.cxx | 187 | ||||
-rw-r--r-- | slideshow/source/engine/slideoverlaybutton.hxx | 102 | ||||
-rw-r--r-- | slideshow/source/engine/slideshowimpl.cxx | 58 | ||||
-rw-r--r-- | slideshow/source/inc/eventmultiplexer.hxx | 8 |
5 files changed, 420 insertions, 1 deletions
diff --git a/slideshow/source/engine/eventmultiplexer.cxx b/slideshow/source/engine/eventmultiplexer.cxx index 4921f6aff8fb..80c4c13d9f46 100644 --- a/slideshow/source/engine/eventmultiplexer.cxx +++ b/slideshow/source/engine/eventmultiplexer.cxx @@ -321,6 +321,10 @@ struct EventMultiplexerImpl /// Schedules tick events, if mbIsAutoMode is true void handleTicks(); + basegfx::B2DPoint toMatrixPoint(uno::Reference<presentation::XSlideShowView> xView, + basegfx::B2DPoint pnt); + basegfx::B2DPoint toNormalPoint(uno::Reference<presentation::XSlideShowView> xView, + basegfx::B2DPoint pnt); EventQueue& mrEventQueue; UnoViewContainer const& mrViewContainer; @@ -573,6 +577,54 @@ void EventMultiplexerImpl::handleTicks() scheduleTick(); } +basegfx::B2DPoint +EventMultiplexerImpl::toNormalPoint(uno::Reference<presentation::XSlideShowView> xView, + basegfx::B2DPoint pnt) +{ + UnoViewVector::const_iterator aIter; + const UnoViewVector::const_iterator aEnd(mrViewContainer.end()); + if ((aIter = std::find_if( + mrViewContainer.begin(), aEnd, + [&xView](const UnoViewSharedPtr& pView) { return xView == pView->getUnoView(); })) + == aEnd) + { + return pnt; + } + + basegfx::B2DPoint aPosition(pnt.getX(), pnt.getY()); + basegfx::B2DHomMatrix aMatrix((*aIter)->getTransformation()); + aPosition *= aMatrix; + + aPosition.setX(basegfx::fround(aPosition.getX())); + aPosition.setY(basegfx::fround(aPosition.getY())); + return aPosition; +} + +basegfx::B2DPoint +EventMultiplexerImpl::toMatrixPoint(uno::Reference<presentation::XSlideShowView> xView, + basegfx::B2DPoint pnt) +{ + UnoViewVector::const_iterator aIter; + const UnoViewVector::const_iterator aEnd(mrViewContainer.end()); + if ((aIter = std::find_if( + mrViewContainer.begin(), aEnd, + [&xView](const UnoViewSharedPtr& pView) { return xView == pView->getUnoView(); })) + == aEnd) + { + return pnt; + } + + basegfx::B2DPoint aPosition(pnt.getX(), pnt.getY()); + basegfx::B2DHomMatrix aMatrix((*aIter)->getTransformation()); + if (!aMatrix.invert()) + ENSURE_OR_THROW(false, "EventMultiplexer::notifyHandlers():" + " view matrix singular"); + aPosition *= aMatrix; + + aPosition.setX(basegfx::fround(aPosition.getX())); + aPosition.setY(basegfx::fround(aPosition.getY())); + return aPosition; +} void EventMultiplexerImpl::clear() { @@ -1233,6 +1285,20 @@ void EventMultiplexer::notifyHyperlinkClicked( { return pHandler.getHandler()->handleHyperlink( hyperLink ); } ); } +basegfx::B2DPoint EventMultiplexer::toMatrixPoint(uno::Reference<uno::XInterface> xInterface, + basegfx::B2DPoint pnt) +{ + uno::Reference<presentation::XSlideShowView> xView(xInterface, uno::UNO_QUERY_THROW); + return mpImpl->toMatrixPoint(xView, pnt); +} + +basegfx::B2DPoint EventMultiplexer::toNormalPoint(uno::Reference<uno::XInterface> xInterface, + basegfx::B2DPoint pnt) +{ + uno::Reference<presentation::XSlideShowView> xView(xInterface, uno::UNO_QUERY_THROW); + return mpImpl->toNormalPoint(xView, pnt); +} + } // namespace presentation /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/slideshow/source/engine/slideoverlaybutton.cxx b/slideshow/source/engine/slideoverlaybutton.cxx new file mode 100644 index 000000000000..c6b92aa975f2 --- /dev/null +++ b/slideshow/source/engine/slideoverlaybutton.cxx @@ -0,0 +1,187 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> + +#include <eventmultiplexer.hxx> +#include "slideoverlaybutton.hxx" + +#include <canvas/canvastools.hxx> +#include <cppcanvas/customsprite.hxx> +#include <basegfx/vector/b2dvector.hxx> +#include <comphelper/diagnose_ex.hxx> + +#include <com/sun/star/presentation/XSlideShowView.hpp> +#include <com/sun/star/rendering/XCanvas.hpp> + +#include <algorithm> +#include <utility> + +namespace slideshow::internal +{ +SlideOverlayButtonSharedPtr SlideOverlayButton::create( + const css::uno::Reference<css::rendering::XBitmap>& xIconBitmap, css::awt::Point pPosition, + std::function<void(basegfx::B2DPoint)> clickHandler, ScreenUpdater& rScreenUpdater, + EventMultiplexer& rEventMultiplexer, const UnoViewContainer& rViewContainer) +{ + SlideOverlayButtonSharedPtr pRet(new SlideOverlayButton( + xIconBitmap, pPosition, clickHandler, rScreenUpdater, rEventMultiplexer, rViewContainer)); + + rEventMultiplexer.addViewHandler(pRet); + // Set priority to 1000 so that the handler fires before the click handler on the slide + rEventMultiplexer.addClickHandler(pRet, 1000); + return pRet; +} + +SlideOverlayButton::SlideOverlayButton(css::uno::Reference<css::rendering::XBitmap> xIconBitmap, + css::awt::Point pPosition, + std::function<void(basegfx::B2DPoint)> clickHandler, + ScreenUpdater& rScreenUpdater, + EventMultiplexer& rEventMultiplexer, + const UnoViewContainer& rViewContainer) + : mxIconBitmap(std::move(xIconBitmap)) + , mrEventMultiplexer(rEventMultiplexer) + , mpPosition(pPosition) + , mClickHandler(clickHandler) + , mrScreenUpdater(rScreenUpdater) +{ + for (const auto& pView : rViewContainer) + viewAdded(pView); +} + +void SlideOverlayButton::setVisible(const bool bVisible) +{ + if (mbVisible == bVisible) + return; + + mbVisible = bVisible; + + for (const auto& rView : maViews) + if (rView.second) + rView.second->show(); + + // sprites changed, need a screen update for this frame. + mrScreenUpdater.requestImmediateUpdate(); +} + +css::geometry::IntegerSize2D SlideOverlayButton::getSize() const { return mxIconBitmap->getSize(); } + +basegfx::B2DPoint SlideOverlayButton::calcSpritePos(UnoViewSharedPtr const& rView) const +{ + const css::awt::Rectangle aViewArea(rView->getUnoView()->getCanvasArea()); + return basegfx::B2DPoint( + aViewArea.X + std::min(aViewArea.Width, mpPosition.X), + aViewArea.Y + + std::max(sal_Int32(0), + aViewArea.Height - mxIconBitmap->getSize().Height - mpPosition.Y)); +} + +void SlideOverlayButton::viewAdded(const UnoViewSharedPtr& rView) +{ + cppcanvas::CustomSpriteSharedPtr sprite; + + try + { + const css::geometry::IntegerSize2D spriteSize(mxIconBitmap->getSize()); + sprite = rView->createSprite(basegfx::B2DSize(spriteSize.Width, spriteSize.Height), + 1000.0); // sprite should be in front of all + // other sprites + css::rendering::ViewState viewState; + canvas::tools::initViewState(viewState); + css::rendering::RenderState renderState; + canvas::tools::initRenderState(renderState); + sprite->getContentCanvas()->getUNOCanvas()->drawBitmap(mxIconBitmap, viewState, + renderState); + + sprite->setAlpha(0.9); + sprite->movePixel(calcSpritePos(rView)); + sprite->show(); + } + catch (css::uno::Exception&) + { + TOOLS_WARN_EXCEPTION("slideshow", ""); + } + + maViews.emplace_back(rView, sprite); +} + +void SlideOverlayButton::viewRemoved(const UnoViewSharedPtr& rView) +{ + maViews.erase( + std::remove_if(maViews.begin(), maViews.end(), + [&rView](const ViewsVecT::value_type& cp) { return rView == cp.first; }), + maViews.end()); +} + +void SlideOverlayButton::viewChanged(const UnoViewSharedPtr& rView) +{ + // find entry corresponding to modified view + ViewsVecT::iterator aModifiedEntry( + std::find_if(maViews.begin(), maViews.end(), + [&rView](const ViewsVecT::value_type& cp) { return rView == cp.first; })); + + assert(aModifiedEntry != maViews.end()); + if (aModifiedEntry == maViews.end()) + return; + + if (aModifiedEntry->second) + aModifiedEntry->second->movePixel(calcSpritePos(aModifiedEntry->first)); +} + +void SlideOverlayButton::viewsChanged() +{ + // reposition sprites on all views + for (const auto& rView : maViews) + { + if (rView.second) + rView.second->movePixel(calcSpritePos(rView.first)); + } +} + +bool SlideOverlayButton::handleMousePressed(const css::awt::MouseEvent& /*e*/) { return false; } + +bool SlideOverlayButton::handleMouseReleased(const css::awt::MouseEvent& e) +{ + css::uno::Reference<css::presentation::XSlideShowView> view(e.Source, + css::uno::UNO_QUERY_THROW); + const basegfx::B2DPoint btnPnt( + view->getCanvasArea().X + std::min(view->getCanvasArea().Width, mpPosition.X), + view->getCanvasArea().Y + + std::max(sal_Int32(0), view->getCanvasArea().Height - mxIconBitmap->getSize().Height + - mpPosition.Y)); + const basegfx::B2DPoint clickPnt + = mrEventMultiplexer.toNormalPoint(e.Source, basegfx::B2DPoint(e.X, e.Y)); + if (clickPnt.getX() > btnPnt.getX() + && clickPnt.getX() < btnPnt.getX() + mxIconBitmap->getSize().Width + && clickPnt.getY() > btnPnt.getY() + && clickPnt.getY() < btnPnt.getY() + mxIconBitmap->getSize().Height) + { + mClickHandler(clickPnt); + return true; + } + return false; +} + +bool SlideOverlayButton::handleMouseDragged(const css::awt::MouseEvent& /*e*/) { return false; } + +bool SlideOverlayButton::handleMouseMoved(const css::awt::MouseEvent& /*e*/) { return false; } + +} // namespace slideshow::internal + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/slideshow/source/engine/slideoverlaybutton.hxx b/slideshow/source/engine/slideoverlaybutton.hxx new file mode 100644 index 000000000000..db733a2b2cd4 --- /dev/null +++ b/slideshow/source/engine/slideoverlaybutton.hxx @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/config.h> + +#include <eventmultiplexer.hxx> +#include <mouseeventhandler.hxx> +#include <screenupdater.hxx> +#include <unoview.hxx> +#include <vieweventhandler.hxx> + +#include <basegfx/point/b2dpoint.hxx> +#include <cppcanvas/sprite.hxx> + +#include <com/sun/star/rendering/XBitmap.hpp> +#include <com/sun/star/awt/Point.hpp> + +#include <functional> +#include <memory> +#include <vector> + +namespace slideshow::internal +{ +class EventMultiplexer; +typedef std::shared_ptr<class SlideOverlayButton> SlideOverlayButtonSharedPtr; + +class SlideOverlayButton : public ViewEventHandler, public MouseEventHandler +{ +public: + SlideOverlayButton(const SlideOverlayButton&) = delete; + SlideOverlayButton& operator=(const SlideOverlayButton&) = delete; + + static SlideOverlayButtonSharedPtr + create(const css::uno::Reference<css::rendering::XBitmap>& xIconBitmap, + css::awt::Point pPosition, std::function<void(basegfx::B2DPoint)> clickHandler, + ScreenUpdater& rScreenUpdater, EventMultiplexer& rEventMultiplexer, + const UnoViewContainer& rViewContainer); + + /** Shows button icon. + */ + void show() { setVisible(true); } + + /** Hides button icon. + */ + void hide() { setVisible(false); } + + css::geometry::IntegerSize2D getSize() const; + basegfx::B2DPoint calcSpritePos(UnoViewSharedPtr const& rView) const; + +private: + SlideOverlayButton(css::uno::Reference<css::rendering::XBitmap> xIconBitmap, + css::awt::Point pPosition, + std::function<void(basegfx::B2DPoint)> clickHandler, + ScreenUpdater& rScreenUpdater, EventMultiplexer& rEventMultiplexer, + const UnoViewContainer& rViewContainer); + + // ViewEventHandler + virtual void viewAdded(const UnoViewSharedPtr& rView) override; + virtual void viewRemoved(const UnoViewSharedPtr& rView) override; + virtual void viewChanged(const UnoViewSharedPtr& rView) override; + virtual void viewsChanged() override; + + // MouseEventHandler + virtual bool handleMousePressed(const css::awt::MouseEvent& e) override; + virtual bool handleMouseReleased(const css::awt::MouseEvent& e) override; + virtual bool handleMouseDragged(const css::awt::MouseEvent& e) override; + virtual bool handleMouseMoved(const css::awt::MouseEvent& e) override; + + void setVisible(const bool bVisible); + + typedef std::vector<std::pair<UnoViewSharedPtr, cppcanvas::CustomSpriteSharedPtr>> ViewsVecT; + + css::uno::Reference<css::rendering::XBitmap> mxIconBitmap; + EventMultiplexer& mrEventMultiplexer; + css::awt::Point mpPosition; + std::function<void(basegfx::B2DPoint)> mClickHandler; + + ViewsVecT maViews; + ScreenUpdater& mrScreenUpdater; + bool mbVisible = false; +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/slideshow/source/engine/slideshowimpl.cxx b/slideshow/source/engine/slideshowimpl.cxx index 1d739ded44c7..473791bb620f 100644 --- a/slideshow/source/engine/slideshowimpl.cxx +++ b/slideshow/source/engine/slideshowimpl.cxx @@ -44,7 +44,7 @@ #include <com/sun/star/util/XUpdatable.hpp> #include <com/sun/star/awt/SystemPointer.hpp> #include <com/sun/star/presentation/XSlideShow.hpp> -#include <com/sun/star/presentation/XSlideShowListener.hpp> +#include <com/sun/star/presentation/XSlideShowNavigationListener.hpp> #include <com/sun/star/lang/NoSupportException.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -80,6 +80,7 @@ #include "effectrewinder.hxx" #include <framerate.hxx> #include "pointersymbol.hxx" +#include "slideoverlaybutton.hxx" #include <map> #include <thread> @@ -437,6 +438,11 @@ private: std::shared_ptr<RehearseTimingsActivity> mpRehearseTimingsActivity; std::shared_ptr<WaitSymbol> mpWaitSymbol; + // navigation buttons + std::shared_ptr<SlideOverlayButton> mpNavigationPrev; + std::shared_ptr<SlideOverlayButton> mpNavigationMenu; + std::shared_ptr<SlideOverlayButton> mpNavigationNext; + std::shared_ptr<PointerSymbol> mpPointerSymbol; /// the current slide transition sound object: @@ -1727,6 +1733,56 @@ sal_Bool SlideShowImpl::setProperty( beans::PropertyValue const& rProperty ) return true; } + if (rProperty.Name == "NavigationSlidePrev") + { + uno::Reference<rendering::XBitmap> xBitmap; + if (!(rProperty.Value >>= xBitmap)) + return false; + + mpNavigationPrev = SlideOverlayButton::create( + xBitmap, { 20, 10 }, [this](basegfx::B2DPoint) { notifySlideEnded(true); }, + maScreenUpdater, maEventMultiplexer, maViewContainer); + + return true; + } + + if (rProperty.Name == "NavigationSlideMenu") + { + uno::Reference<rendering::XBitmap> xBitmap; + if (!(rProperty.Value >>= xBitmap)) + return false; + + mpNavigationMenu = SlideOverlayButton::create( + xBitmap, { 80, 10 }, + [this](basegfx::B2DPoint pos) { + maListenerContainer.forEach( + [pos](const uno::Reference<presentation::XSlideShowListener>& xListener) { + uno::Reference<presentation::XSlideShowNavigationListener> xNavListener( + xListener, uno::UNO_QUERY); + if (xNavListener.is()) + xNavListener->contextMenuShow( + css::awt::Point(static_cast<sal_Int32>(floor(pos.getX())), + static_cast<sal_Int32>(floor(pos.getY())))); + }); + }, + maScreenUpdater, maEventMultiplexer, maViewContainer); + + return true; + } + + if (rProperty.Name == "NavigationSlideNext") + { + uno::Reference<rendering::XBitmap> xBitmap; + if (!(rProperty.Value >>= xBitmap)) + return false; + + mpNavigationNext = SlideOverlayButton::create( + xBitmap, { 140, 10 }, [this](basegfx::B2DPoint) { notifySlideEnded(false); }, + maScreenUpdater, maEventMultiplexer, maViewContainer); + + return true; + } + if ( rProperty.Name == "PointerSymbolBitmap" ) { uno::Reference<rendering::XBitmap> xBitmap; diff --git a/slideshow/source/inc/eventmultiplexer.hxx b/slideshow/source/inc/eventmultiplexer.hxx index e0dd6fd31eb5..21fa333cd109 100644 --- a/slideshow/source/inc/eventmultiplexer.hxx +++ b/slideshow/source/inc/eventmultiplexer.hxx @@ -31,6 +31,8 @@ #include "unoview.hxx" +namespace basegfx { class B2DPoint; } + namespace com::sun::star::drawing { class XShape; } namespace slideshow::internal { @@ -648,6 +650,12 @@ public: */ void notifyHyperlinkClicked( OUString const& hyperLink ); + basegfx::B2DPoint toMatrixPoint(css::uno::Reference<css::uno::XInterface> xInterface, + basegfx::B2DPoint pnt); + + basegfx::B2DPoint toNormalPoint(css::uno::Reference<css::uno::XInterface> xInterface, + basegfx::B2DPoint pnt); + private: std::unique_ptr<EventMultiplexerImpl> mpImpl; }; |