LibreOffice Module slideshow (master) 1
waitsymbol.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
20
22
24
27
28#include <com/sun/star/rendering/XCanvas.hpp>
29#include <com/sun/star/presentation/XSlideShowView.hpp>
31
32#include "waitsymbol.hxx"
33#include <eventmultiplexer.hxx>
34
35#include <algorithm>
36#include <utility>
37
38
39using namespace com::sun::star;
40
41namespace slideshow::internal {
42
43const sal_Int32 LEFT_BORDER_SPACE = 10;
44const sal_Int32 LOWER_BORDER_SPACE = 10;
45
47 ScreenUpdater& rScreenUpdater,
48 EventMultiplexer& rEventMultiplexer,
49 const UnoViewContainer& rViewContainer )
50{
52 new WaitSymbol( xBitmap,
53 rScreenUpdater,
54 rViewContainer ));
55
56 rEventMultiplexer.addViewHandler( pRet );
57
58 return pRet;
59}
60
62 ScreenUpdater& rScreenUpdater,
63 const UnoViewContainer& rViewContainer ) :
64 mxBitmap(std::move(xBitmap)),
65 maViews(),
66 mrScreenUpdater( rScreenUpdater ),
67 mbVisible(false)
68{
69 for( const auto& pView : rViewContainer )
70 viewAdded( pView );
71}
72
73void WaitSymbol::setVisible( const bool bVisible )
74{
75 if( mbVisible == bVisible )
76 return;
77
79
80 for( const auto& rView : maViews )
81 {
82 if( rView.second )
83 {
84 if( bVisible )
85 rView.second->show();
86 else
87 rView.second->hide();
88 }
89 }
90
91 // sprites changed, need a screen update for this frame.
93}
94
96 UnoViewSharedPtr const & rView ) const
97{
98 const awt::Rectangle aViewArea( rView->getUnoView()->getCanvasArea() );
99 return basegfx::B2DPoint(
100 aViewArea.X + std::min<sal_Int32>( aViewArea.Width, LEFT_BORDER_SPACE ),
101 aViewArea.X + std::max<sal_Int32>( 0,
102 aViewArea.Height
103 - mxBitmap->getSize().Height
104 - LOWER_BORDER_SPACE ) );
105}
106
108{
110
111 try
112 {
113 const geometry::IntegerSize2D spriteSize( mxBitmap->getSize() );
114 sprite = rView->createSprite( basegfx::B2DSize( spriteSize.Width,
115 spriteSize.Height ),
116 1000.0 ); // sprite should be in front of all
117 // other sprites
118 rendering::ViewState viewState;
119 canvas::tools::initViewState( viewState );
120 rendering::RenderState renderState;
121 canvas::tools::initRenderState( renderState );
122 sprite->getContentCanvas()->getUNOCanvas()->drawBitmap(
123 mxBitmap, viewState, renderState );
124
125 sprite->setAlpha( 0.9 );
126 sprite->movePixel( calcSpritePos( rView ) );
127 if( mbVisible )
128 sprite->show();
129 }
130 catch( uno::Exception& )
131 {
132 TOOLS_WARN_EXCEPTION( "slideshow", "" );
133 }
134
135 maViews.emplace_back( rView, sprite );
136}
137
139{
140 maViews.erase(
141 std::remove_if(
142 maViews.begin(), maViews.end(),
143 [&rView]
144 ( const ViewsVecT::value_type& cp )
145 { return rView == cp.first; } ),
146 maViews.end() );
147}
148
150{
151 // find entry corresponding to modified view
152 ViewsVecT::iterator aModifiedEntry(
153 std::find_if(
154 maViews.begin(),
155 maViews.end(),
156 [&rView]
157 ( const ViewsVecT::value_type& cp )
158 { return rView == cp.first; } ) );
159
160 OSL_ASSERT( aModifiedEntry != maViews.end() );
161 if( aModifiedEntry == maViews.end() )
162 return;
163
164 if( aModifiedEntry->second )
165 aModifiedEntry->second->movePixel(
166 calcSpritePos(aModifiedEntry->first) );
167}
168
170{
171 // reposition sprites on all views
172 for( const auto& rView : maViews )
173 {
174 if( rView.second )
175 rView.second->movePixel(
176 calcSpritePos( rView.first ) );
177 }
178}
179
180} // namespace slideshow::internal
181
182/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class multiplexes user-activated and slide-show global events.
void addViewHandler(const ViewEventHandlerWeakPtr &rHandler)
Register an event handler that will be called when views are changed.
void setVisible(const bool bVisible)
Definition: waitsymbol.cxx:73
virtual void viewChanged(const UnoViewSharedPtr &rView) override
Notify changed view.
Definition: waitsymbol.cxx:149
css::uno::Reference< css::rendering::XBitmap > mxBitmap
Definition: waitsymbol.hxx:77
virtual void viewRemoved(const UnoViewSharedPtr &rView) override
Notify removed view.
Definition: waitsymbol.cxx:138
static WaitSymbolSharedPtr create(const css::uno::Reference< css::rendering::XBitmap > &xBitmap, ScreenUpdater &rScreenUpdater, EventMultiplexer &rEventMultiplexer, const UnoViewContainer &rViewContainer)
Definition: waitsymbol.cxx:46
WaitSymbol(const WaitSymbol &)=delete
virtual void viewAdded(const UnoViewSharedPtr &rView) override
Notify new view.
Definition: waitsymbol.cxx:107
virtual void viewsChanged() override
Notify that all views changed.
Definition: waitsymbol.cxx:169
::basegfx::B2DPoint calcSpritePos(UnoViewSharedPtr const &rView) const
Definition: waitsymbol.cxx:95
VclPtr< VirtualDevice > mxBitmap
#define TOOLS_WARN_EXCEPTION(area, stream)
rendering::RenderState & initRenderState(rendering::RenderState &renderState)
rendering::ViewState & initViewState(rendering::ViewState &viewState)
std::shared_ptr< ::cppcanvas::CustomSprite > CustomSpriteSharedPtr
std::shared_ptr< class WaitSymbol > WaitSymbolSharedPtr
Definition: waitsymbol.hxx:36
std::shared_ptr< UnoView > UnoViewSharedPtr
bool mbVisible
bool bVisible