build fix
[LibreOffice.git] / slideshow / source / engine / waitsymbol.cxx
blobe278d609c4643ff5eda74169d9262bf59317be93
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <canvas/canvastools.hxx>
23 #include <comphelper/anytostring.hxx>
24 #include <cppuhelper/exc_hlp.hxx>
26 #include <basegfx/point/b2dpoint.hxx>
27 #include <basegfx/vector/b2dvector.hxx>
29 #include <com/sun/star/rendering/XCanvas.hpp>
30 #include <com/sun/star/presentation/XSlideShowView.hpp>
32 #include "waitsymbol.hxx"
33 #include "eventmultiplexer.hxx"
35 #include <algorithm>
38 using namespace com::sun::star;
40 namespace slideshow {
41 namespace internal {
43 const sal_Int32 LEFT_BORDER_SPACE = 10;
44 const sal_Int32 LOWER_BORDER_SPACE = 10;
46 WaitSymbolSharedPtr WaitSymbol::create( const uno::Reference<rendering::XBitmap>& xBitmap,
47 ScreenUpdater& rScreenUpdater,
48 EventMultiplexer& rEventMultiplexer,
49 const UnoViewContainer& rViewContainer )
51 WaitSymbolSharedPtr pRet(
52 new WaitSymbol( xBitmap,
53 rScreenUpdater,
54 rViewContainer ));
56 rEventMultiplexer.addViewHandler( pRet );
58 return pRet;
61 WaitSymbol::WaitSymbol( uno::Reference<rendering::XBitmap> const & xBitmap,
62 ScreenUpdater& rScreenUpdater,
63 const UnoViewContainer& rViewContainer ) :
64 mxBitmap(xBitmap),
65 maViews(),
66 mrScreenUpdater( rScreenUpdater ),
67 mbVisible(false)
69 for( const auto& pView : rViewContainer )
70 this->viewAdded( pView );
73 void WaitSymbol::setVisible( const bool bVisible )
75 if( mbVisible != bVisible )
77 mbVisible = bVisible;
79 for( const auto& rView : maViews )
81 if( rView.second )
83 if( bVisible )
84 rView.second->show();
85 else
86 rView.second->hide();
90 // sprites changed, need a screen update for this frame.
91 mrScreenUpdater.requestImmediateUpdate();
95 basegfx::B2DPoint WaitSymbol::calcSpritePos(
96 UnoViewSharedPtr const & rView ) const
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 ) );
107 void WaitSymbol::viewAdded( const UnoViewSharedPtr& rView )
109 cppcanvas::CustomSpriteSharedPtr sprite;
113 const geometry::IntegerSize2D spriteSize( mxBitmap->getSize() );
114 sprite = rView->createSprite( basegfx::B2DVector( 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 );
125 sprite->setAlpha( 0.9 );
126 sprite->movePixel( calcSpritePos( rView ) );
127 if( mbVisible )
128 sprite->show();
130 catch( uno::Exception& )
132 OSL_FAIL( OUStringToOString(
133 comphelper::anyToString( cppu::getCaughtException() ),
134 RTL_TEXTENCODING_UTF8 ).getStr() );
137 maViews.push_back( ViewsVecT::value_type( rView, sprite ) );
140 void WaitSymbol::viewRemoved( const UnoViewSharedPtr& rView )
142 maViews.erase(
143 std::remove_if(
144 maViews.begin(), maViews.end(),
145 [&rView]
146 ( const ViewsVecT::value_type& cp )
147 { return rView == cp.first; } ),
148 maViews.end() );
151 void WaitSymbol::viewChanged( const UnoViewSharedPtr& rView )
153 // find entry corresponding to modified view
154 ViewsVecT::iterator aModifiedEntry(
155 std::find_if(
156 maViews.begin(),
157 maViews.end(),
158 [&rView]
159 ( const ViewsVecT::value_type& cp )
160 { return rView == cp.first; } ) );
162 OSL_ASSERT( aModifiedEntry != maViews.end() );
163 if( aModifiedEntry == maViews.end() )
164 return;
166 if( aModifiedEntry->second )
167 aModifiedEntry->second->movePixel(
168 calcSpritePos(aModifiedEntry->first) );
171 void WaitSymbol::viewsChanged()
173 // reposition sprites on all views
174 for( const auto& rView : maViews )
176 if( rView.second )
177 rView.second->movePixel(
178 calcSpritePos( rView.first ) );
182 } // namespace internal
183 } // namespace slideshow
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */