1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
40 using namespace com::sun::star
;
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
,
58 rEventMultiplexer
.addViewHandler( pRet
);
63 WaitSymbol::WaitSymbol( uno::Reference
<rendering::XBitmap
> const & xBitmap
,
64 ScreenUpdater
& rScreenUpdater
,
65 const UnoViewContainer
& rViewContainer
) :
68 mrScreenUpdater( rScreenUpdater
),
71 std::for_each( rViewContainer
.begin(),
73 boost::bind( &WaitSymbol::viewAdded
,
78 void WaitSymbol::setVisible( const bool bVisible
)
80 if( mbVisible
!= bVisible
)
84 ViewsVecT::const_iterator
aIter( maViews
.begin() );
85 ViewsVecT::const_iterator
const aEnd ( maViews
.end() );
86 while( aIter
!= aEnd
)
91 aIter
->second
->show();
93 aIter
->second
->hide();
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,
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
,
125 1000.0 ); // sprite should be in front of all
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
) );
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
)
153 maViews
.begin(), maViews
.end(),
155 std::equal_to
<UnoViewSharedPtr
>(),
158 boost::bind( o3tl::select1st
<ViewsVecT::value_type
>(), _1
) ) ),
162 void WaitSymbol::viewChanged( const UnoViewSharedPtr
& rView
)
164 // find entry corresponding to modified view
165 ViewsVecT::iterator
aModifiedEntry(
170 std::equal_to
<UnoViewSharedPtr
>(),
173 boost::bind( o3tl::select1st
<ViewsVecT::value_type
>(), _1
))));
175 OSL_ASSERT( aModifiedEntry
!= maViews
.end() );
176 if( aModifiedEntry
== maViews
.end() )
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
)
192 aIter
->second
->movePixel(
193 calcSpritePos( aIter
->first
));
198 } // namespace internal
199 } // namespace slideshow
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */