fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / slideshow / source / engine / waitsymbol.cxx
blob2017d7419ed14ee4d92a89bdba91121784b5d7b0
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 <boost/current_function.hpp>
22 #include <canvas/canvastools.hxx>
24 #include <comphelper/anytostring.hxx>
25 #include <cppuhelper/exc_hlp.hxx>
27 #include <basegfx/point/b2dpoint.hxx>
28 #include <basegfx/vector/b2dvector.hxx>
30 #include <com/sun/star/rendering/XCanvas.hpp>
31 #include <com/sun/star/presentation/XSlideShowView.hpp>
33 #include "waitsymbol.hxx"
34 #include "eventmultiplexer.hxx"
36 #include <o3tl/compat_functional.hxx>
37 #include <algorithm>
40 using namespace com::sun::star;
42 namespace slideshow {
43 namespace internal {
45 const sal_Int32 LEFT_BORDER_SPACE = 10;
46 const sal_Int32 LOWER_BORDER_SPACE = 10;
48 WaitSymbolSharedPtr WaitSymbol::create( const uno::Reference<rendering::XBitmap>& xBitmap,
49 ScreenUpdater& rScreenUpdater,
50 EventMultiplexer& rEventMultiplexer,
51 const UnoViewContainer& rViewContainer )
53 WaitSymbolSharedPtr pRet(
54 new WaitSymbol( xBitmap,
55 rScreenUpdater,
56 rViewContainer ));
58 rEventMultiplexer.addViewHandler( pRet );
60 return pRet;
63 WaitSymbol::WaitSymbol( uno::Reference<rendering::XBitmap> const & xBitmap,
64 ScreenUpdater& rScreenUpdater,
65 const UnoViewContainer& rViewContainer ) :
66 mxBitmap(xBitmap),
67 maViews(),
68 mrScreenUpdater( rScreenUpdater ),
69 mbVisible(false)
71 std::for_each( rViewContainer.begin(),
72 rViewContainer.end(),
73 boost::bind( &WaitSymbol::viewAdded,
74 this,
75 _1 ));
78 void WaitSymbol::setVisible( const bool bVisible )
80 if( mbVisible != bVisible )
82 mbVisible = bVisible;
84 ViewsVecT::const_iterator aIter( maViews.begin() );
85 ViewsVecT::const_iterator const aEnd ( maViews.end() );
86 while( aIter != aEnd )
88 if( aIter->second )
90 if( bVisible )
91 aIter->second->show();
92 else
93 aIter->second->hide();
96 ++aIter;
99 // sprites changed, need a screen update for this frame.
100 mrScreenUpdater.requestImmediateUpdate();
104 basegfx::B2DPoint WaitSymbol::calcSpritePos(
105 UnoViewSharedPtr const & rView ) const
107 const awt::Rectangle aViewArea( rView->getUnoView()->getCanvasArea() );
108 return basegfx::B2DPoint(
109 aViewArea.X + std::min<sal_Int32>( aViewArea.Width, LEFT_BORDER_SPACE ),
110 aViewArea.X + std::max<sal_Int32>( 0,
111 aViewArea.Height
112 - mxBitmap->getSize().Height
113 - LOWER_BORDER_SPACE ) );
116 void WaitSymbol::viewAdded( const UnoViewSharedPtr& rView )
118 cppcanvas::CustomSpriteSharedPtr sprite;
122 const geometry::IntegerSize2D spriteSize( mxBitmap->getSize() );
123 sprite = rView->createSprite( basegfx::B2DVector( spriteSize.Width,
124 spriteSize.Height ),
125 1000.0 ); // sprite should be in front of all
126 // other sprites
127 rendering::ViewState viewState;
128 canvas::tools::initViewState( viewState );
129 rendering::RenderState renderState;
130 canvas::tools::initRenderState( renderState );
131 sprite->getContentCanvas()->getUNOCanvas()->drawBitmap(
132 mxBitmap, viewState, renderState );
134 sprite->setAlpha( 0.9 );
135 sprite->movePixel( calcSpritePos( rView ) );
136 if( mbVisible )
137 sprite->show();
139 catch( uno::Exception& )
141 OSL_FAIL( OUStringToOString(
142 comphelper::anyToString( cppu::getCaughtException() ),
143 RTL_TEXTENCODING_UTF8 ).getStr() );
146 maViews.push_back( ViewsVecT::value_type( rView, sprite ) );
149 void WaitSymbol::viewRemoved( const UnoViewSharedPtr& rView )
151 maViews.erase(
152 std::remove_if(
153 maViews.begin(), maViews.end(),
154 boost::bind(
155 std::equal_to<UnoViewSharedPtr>(),
156 rView,
157 // select view:
158 boost::bind( o3tl::select1st<ViewsVecT::value_type>(), _1 ) ) ),
159 maViews.end() );
162 void WaitSymbol::viewChanged( const UnoViewSharedPtr& rView )
164 // find entry corresponding to modified view
165 ViewsVecT::iterator aModifiedEntry(
166 std::find_if(
167 maViews.begin(),
168 maViews.end(),
169 boost::bind(
170 std::equal_to<UnoViewSharedPtr>(),
171 rView,
172 // select view:
173 boost::bind( o3tl::select1st<ViewsVecT::value_type>(), _1 ))));
175 OSL_ASSERT( aModifiedEntry != maViews.end() );
176 if( aModifiedEntry == maViews.end() )
177 return;
179 if( aModifiedEntry->second )
180 aModifiedEntry->second->movePixel(
181 calcSpritePos(aModifiedEntry->first) );
184 void WaitSymbol::viewsChanged()
186 // reposition sprites on all views
187 ViewsVecT::const_iterator aIter( maViews.begin() );
188 ViewsVecT::const_iterator const aEnd ( maViews.end() );
189 while( aIter != aEnd )
191 if( aIter->second )
192 aIter->second->movePixel(
193 calcSpritePos( aIter->first ));
194 ++aIter;
198 } // namespace internal
199 } // namespace slideshow
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */