1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_slideshow.hxx" 30 31 #include <boost/current_function.hpp> 32 #include <canvas/canvastools.hxx> 33 34 #include <comphelper/anytostring.hxx> 35 #include <cppuhelper/exc_hlp.hxx> 36 37 #include <basegfx/point/b2dpoint.hxx> 38 #include <basegfx/vector/b2dvector.hxx> 39 40 #include <com/sun/star/rendering/XCanvas.hpp> 41 42 #include "waitsymbol.hxx" 43 #include "eventmultiplexer.hxx" 44 45 #include <algorithm> 46 47 48 using namespace com::sun::star; 49 50 namespace slideshow { 51 namespace internal { 52 53 const sal_Int32 LEFT_BORDER_SPACE = 10; 54 const sal_Int32 LOWER_BORDER_SPACE = 10; 55 56 WaitSymbolSharedPtr WaitSymbol::create( const uno::Reference<rendering::XBitmap>& xBitmap, 57 ScreenUpdater& rScreenUpdater, 58 EventMultiplexer& rEventMultiplexer, 59 const UnoViewContainer& rViewContainer ) 60 { 61 WaitSymbolSharedPtr pRet( 62 new WaitSymbol( xBitmap, 63 rScreenUpdater, 64 rViewContainer )); 65 66 rEventMultiplexer.addViewHandler( pRet ); 67 68 return pRet; 69 } 70 71 WaitSymbol::WaitSymbol( uno::Reference<rendering::XBitmap> const & xBitmap, 72 ScreenUpdater& rScreenUpdater, 73 const UnoViewContainer& rViewContainer ) : 74 mxBitmap(xBitmap), 75 maViews(), 76 mrScreenUpdater( rScreenUpdater ), 77 mbVisible(false) 78 { 79 std::for_each( rViewContainer.begin(), 80 rViewContainer.end(), 81 boost::bind( &WaitSymbol::viewAdded, 82 this, 83 _1 )); 84 } 85 86 void WaitSymbol::setVisible( const bool bVisible ) 87 { 88 if( mbVisible != bVisible ) 89 { 90 mbVisible = bVisible; 91 92 ViewsVecT::const_iterator aIter( maViews.begin() ); 93 ViewsVecT::const_iterator const aEnd ( maViews.end() ); 94 while( aIter != aEnd ) 95 { 96 if( aIter->second ) 97 { 98 if( bVisible ) 99 aIter->second->show(); 100 else 101 aIter->second->hide(); 102 } 103 104 ++aIter; 105 } 106 107 // sprites changed, need a screen update for this frame. 108 mrScreenUpdater.requestImmediateUpdate(); 109 } 110 } 111 112 basegfx::B2DPoint WaitSymbol::calcSpritePos( 113 UnoViewSharedPtr const & rView ) const 114 { 115 const uno::Reference<rendering::XBitmap> xBitmap( rView->getCanvas()->getUNOCanvas(), 116 uno::UNO_QUERY_THROW ); 117 const geometry::IntegerSize2D realSize( xBitmap->getSize() ); 118 return basegfx::B2DPoint( 119 std::min<sal_Int32>( realSize.Width, LEFT_BORDER_SPACE ), 120 std::max<sal_Int32>( 0, realSize.Height - mxBitmap->getSize().Height 121 - LOWER_BORDER_SPACE ) ); 122 } 123 124 void WaitSymbol::viewAdded( const UnoViewSharedPtr& rView ) 125 { 126 cppcanvas::CustomSpriteSharedPtr sprite; 127 128 try 129 { 130 const geometry::IntegerSize2D spriteSize( mxBitmap->getSize() ); 131 sprite = rView->createSprite( basegfx::B2DVector( spriteSize.Width, 132 spriteSize.Height ), 133 1000.0 ); // sprite should be in front of all 134 // other sprites 135 rendering::ViewState viewState; 136 canvas::tools::initViewState( viewState ); 137 rendering::RenderState renderState; 138 canvas::tools::initRenderState( renderState ); 139 sprite->getContentCanvas()->getUNOCanvas()->drawBitmap( 140 mxBitmap, viewState, renderState ); 141 142 sprite->setAlpha( 0.9 ); 143 sprite->movePixel( calcSpritePos( rView ) ); 144 if( mbVisible ) 145 sprite->show(); 146 } 147 catch( uno::Exception& ) 148 { 149 OSL_ENSURE( false, 150 rtl::OUStringToOString( 151 comphelper::anyToString( cppu::getCaughtException() ), 152 RTL_TEXTENCODING_UTF8 ).getStr() ); 153 } 154 155 maViews.push_back( ViewsVecT::value_type( rView, sprite ) ); 156 } 157 158 void WaitSymbol::viewRemoved( const UnoViewSharedPtr& rView ) 159 { 160 maViews.erase( 161 std::remove_if( 162 maViews.begin(), maViews.end(), 163 boost::bind( 164 std::equal_to<UnoViewSharedPtr>(), 165 rView, 166 // select view: 167 boost::bind( std::select1st<ViewsVecT::value_type>(), _1 ) ) ), 168 maViews.end() ); 169 } 170 171 void WaitSymbol::viewChanged( const UnoViewSharedPtr& rView ) 172 { 173 // find entry corresponding to modified view 174 ViewsVecT::iterator aModifiedEntry( 175 std::find_if( 176 maViews.begin(), 177 maViews.end(), 178 boost::bind( 179 std::equal_to<UnoViewSharedPtr>(), 180 rView, 181 // select view: 182 boost::bind( std::select1st<ViewsVecT::value_type>(), _1 )))); 183 184 OSL_ASSERT( aModifiedEntry != maViews.end() ); 185 if( aModifiedEntry == maViews.end() ) 186 return; 187 188 if( aModifiedEntry->second ) 189 aModifiedEntry->second->movePixel( 190 calcSpritePos(aModifiedEntry->first) ); 191 } 192 193 void WaitSymbol::viewsChanged() 194 { 195 // reposition sprites on all views 196 ViewsVecT::const_iterator aIter( maViews.begin() ); 197 ViewsVecT::const_iterator const aEnd ( maViews.end() ); 198 while( aIter != aEnd ) 199 { 200 if( aIter->second ) 201 aIter->second->movePixel( 202 calcSpritePos( aIter->first )); 203 ++aIter; 204 } 205 } 206 207 } // namespace internal 208 } // namespace presentation 209