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 "pointersymbol.hxx"
34 #include "eventmultiplexer.hxx"
36 #include <o3tl/compat_functional.hxx>
40 using namespace com::sun::star
;
45 PointerSymbolSharedPtr
PointerSymbol::create( const uno::Reference
<rendering::XBitmap
>& xBitmap
,
46 ScreenUpdater
& rScreenUpdater
,
47 EventMultiplexer
& rEventMultiplexer
,
48 const UnoViewContainer
& rViewContainer
)
50 PointerSymbolSharedPtr
pRet(
51 new PointerSymbol( xBitmap
,
55 rEventMultiplexer
.addViewHandler( pRet
);
60 PointerSymbol::PointerSymbol( uno::Reference
<rendering::XBitmap
> const & xBitmap
,
61 ScreenUpdater
& rScreenUpdater
,
62 const UnoViewContainer
& rViewContainer
) :
65 mrScreenUpdater( rScreenUpdater
),
69 std::for_each( rViewContainer
.begin(),
71 boost::bind( &PointerSymbol::viewAdded
,
76 void PointerSymbol::setVisible( const bool bVisible
)
78 if( mbVisible
!= bVisible
)
82 ViewsVecT::const_iterator
aIter( maViews
.begin() );
83 ViewsVecT::const_iterator
const aEnd ( maViews
.end() );
84 while( aIter
!= aEnd
)
89 aIter
->second
->show();
91 aIter
->second
->hide();
97 // sprites changed, need a screen update for this frame.
98 mrScreenUpdater
.requestImmediateUpdate();
102 basegfx::B2DPoint
PointerSymbol::calcSpritePos(UnoViewSharedPtr
const & rView
) const
104 const awt::Rectangle
aViewArea( rView
->getUnoView()->getCanvasArea() );
105 const geometry::IntegerSize2D
realTranslationOffset ( rView
->getTranslationOffset() );
107 return basegfx::B2DPoint(
108 realTranslationOffset
.Width
+ ((aViewArea
.Width
- aViewArea
.X
) - 2 * realTranslationOffset
.Width
) * maPos
.X
,
109 realTranslationOffset
.Height
+ ((aViewArea
.Height
- aViewArea
.Y
) - 2 * realTranslationOffset
.Height
) * maPos
.Y
);
112 void PointerSymbol::viewAdded( const UnoViewSharedPtr
& rView
)
114 cppcanvas::CustomSpriteSharedPtr sprite
;
118 const geometry::IntegerSize2D
spriteSize( mxBitmap
->getSize() );
119 sprite
= rView
->createSprite( basegfx::B2DVector( spriteSize
.Width
,
121 1000.0 ); // sprite should be in front of all
123 rendering::ViewState viewState
;
124 canvas::tools::initViewState( viewState
);
125 rendering::RenderState renderState
;
126 canvas::tools::initRenderState( renderState
);
127 sprite
->getContentCanvas()->getUNOCanvas()->drawBitmap(
128 mxBitmap
, viewState
, renderState
);
130 sprite
->setAlpha( 0.9 );
131 sprite
->movePixel( calcSpritePos( rView
) );
135 catch( uno::Exception
& )
137 OSL_FAIL( OUStringToOString(
138 comphelper::anyToString( cppu::getCaughtException() ),
139 RTL_TEXTENCODING_UTF8
).getStr() );
142 maViews
.push_back( ViewsVecT::value_type( rView
, sprite
) );
145 void PointerSymbol::viewRemoved( const UnoViewSharedPtr
& rView
)
149 maViews
.begin(), maViews
.end(),
151 std::equal_to
<UnoViewSharedPtr
>(),
154 boost::bind( o3tl::select1st
<ViewsVecT::value_type
>(), _1
) ) ),
158 void PointerSymbol::viewChanged( const UnoViewSharedPtr
& rView
)
160 // find entry corresponding to modified view
161 ViewsVecT::iterator
aModifiedEntry(
166 std::equal_to
<UnoViewSharedPtr
>(),
169 boost::bind( o3tl::select1st
<ViewsVecT::value_type
>(), _1
))));
171 OSL_ASSERT( aModifiedEntry
!= maViews
.end() );
172 if( aModifiedEntry
== maViews
.end() )
175 if( aModifiedEntry
->second
)
176 aModifiedEntry
->second
->movePixel(
177 calcSpritePos(aModifiedEntry
->first
) );
180 void PointerSymbol::viewsChanged()
182 // reposition sprites on all views
183 ViewsVecT::const_iterator
aIter( maViews
.begin() );
184 ViewsVecT::const_iterator
const aEnd ( maViews
.end() );
185 while( aIter
!= aEnd
)
188 aIter
->second
->movePixel(
189 calcSpritePos( aIter
->first
));
194 void PointerSymbol::viewsChanged(const geometry::RealPoint2D pos
)
196 if( pos
.X
!= maPos
.X
|| pos
.Y
!= maPos
.Y
)
200 // reposition sprites on all views
201 ViewsVecT::const_iterator
aIter( maViews
.begin() );
202 ViewsVecT::const_iterator
const aEnd ( maViews
.end() );
203 while( aIter
!= aEnd
)
207 aIter
->second
->movePixel(
208 calcSpritePos( aIter
->first
));
209 mrScreenUpdater
.notifyUpdate();
210 mrScreenUpdater
.commitUpdates();
217 } // namespace internal
218 } // namespace slideshow
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */