1*70f497fbSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*70f497fbSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*70f497fbSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*70f497fbSAndrew Rist * distributed with this work for additional information 6*70f497fbSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*70f497fbSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*70f497fbSAndrew Rist * "License"); you may not use this file except in compliance 9*70f497fbSAndrew Rist * with the License. You may obtain a copy of the License at 10*70f497fbSAndrew Rist * 11*70f497fbSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*70f497fbSAndrew Rist * 13*70f497fbSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*70f497fbSAndrew Rist * software distributed under the License is distributed on an 15*70f497fbSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*70f497fbSAndrew Rist * KIND, either express or implied. See the License for the 17*70f497fbSAndrew Rist * specific language governing permissions and limitations 18*70f497fbSAndrew Rist * under the License. 19*70f497fbSAndrew Rist * 20*70f497fbSAndrew Rist *************************************************************/ 21*70f497fbSAndrew Rist 22*70f497fbSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_slideshow.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <canvas/debug.hxx> 28cdf0e10cSrcweir #include <unoviewcontainer.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <boost/bind.hpp> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <algorithm> 33cdf0e10cSrcweir 34cdf0e10cSrcweir 35cdf0e10cSrcweir using namespace ::com::sun::star; 36cdf0e10cSrcweir 37cdf0e10cSrcweir // ----------------------------------------------------------------------------- 38cdf0e10cSrcweir 39cdf0e10cSrcweir namespace slideshow 40cdf0e10cSrcweir { 41cdf0e10cSrcweir namespace internal 42cdf0e10cSrcweir { UnoViewContainer()43cdf0e10cSrcweir UnoViewContainer::UnoViewContainer() : 44cdf0e10cSrcweir maViews() 45cdf0e10cSrcweir { 46cdf0e10cSrcweir } 47cdf0e10cSrcweir addView(const UnoViewSharedPtr & rView)48cdf0e10cSrcweir bool UnoViewContainer::addView( const UnoViewSharedPtr& rView ) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir // check whether same view is already added 51cdf0e10cSrcweir const UnoViewVector::iterator aEnd( maViews.end() ); 52cdf0e10cSrcweir 53cdf0e10cSrcweir // already added? 54cdf0e10cSrcweir if( ::std::find_if( maViews.begin(), 55cdf0e10cSrcweir aEnd, 56cdf0e10cSrcweir ::boost::bind( 57cdf0e10cSrcweir ::std::equal_to< uno::Reference< presentation::XSlideShowView > >(), 58cdf0e10cSrcweir ::boost::cref( rView->getUnoView() ), 59cdf0e10cSrcweir ::boost::bind( 60cdf0e10cSrcweir &UnoView::getUnoView, 61cdf0e10cSrcweir _1 ) ) ) != aEnd ) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir // yes, nothing to do 64cdf0e10cSrcweir return false; 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir // add locally 68cdf0e10cSrcweir maViews.push_back( rView ); 69cdf0e10cSrcweir 70cdf0e10cSrcweir return true; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir removeView(const uno::Reference<presentation::XSlideShowView> & xView)73cdf0e10cSrcweir UnoViewSharedPtr UnoViewContainer::removeView( const uno::Reference< presentation::XSlideShowView >& xView ) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir // check whether same view is already added 76cdf0e10cSrcweir const UnoViewVector::iterator aEnd( maViews.end() ); 77cdf0e10cSrcweir UnoViewVector::iterator aIter; 78cdf0e10cSrcweir 79cdf0e10cSrcweir // added in the first place? 80cdf0e10cSrcweir if( (aIter=::std::find_if( maViews.begin(), 81cdf0e10cSrcweir aEnd, 82cdf0e10cSrcweir ::boost::bind( 83cdf0e10cSrcweir ::std::equal_to< uno::Reference< presentation::XSlideShowView > >(), 84cdf0e10cSrcweir ::boost::cref( xView ), 85cdf0e10cSrcweir ::boost::bind( 86cdf0e10cSrcweir &UnoView::getUnoView, 87cdf0e10cSrcweir _1 ) ) ) ) == aEnd ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir // nope, nothing to do 90cdf0e10cSrcweir return UnoViewSharedPtr(); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir OSL_ENSURE( 94cdf0e10cSrcweir ::std::count_if( 95cdf0e10cSrcweir maViews.begin(), 96cdf0e10cSrcweir aEnd, 97cdf0e10cSrcweir ::boost::bind( 98cdf0e10cSrcweir ::std::equal_to< uno::Reference< presentation::XSlideShowView > >(), 99cdf0e10cSrcweir ::boost::cref( xView ), 100cdf0e10cSrcweir ::boost::bind( 101cdf0e10cSrcweir &UnoView::getUnoView, 102cdf0e10cSrcweir _1 ))) == 1, 103cdf0e10cSrcweir "UnoViewContainer::removeView(): View was added multiple times" ); 104cdf0e10cSrcweir 105cdf0e10cSrcweir UnoViewSharedPtr pView( *aIter ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir // actually erase from container 108cdf0e10cSrcweir maViews.erase( aIter ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir return pView; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir removeView(const UnoViewSharedPtr & rView)113cdf0e10cSrcweir bool UnoViewContainer::removeView( const UnoViewSharedPtr& rView ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir // remove locally 116cdf0e10cSrcweir const UnoViewVector::iterator aEnd( maViews.end() ); 117cdf0e10cSrcweir UnoViewVector::iterator aIter; 118cdf0e10cSrcweir if( (aIter=::std::find( maViews.begin(), 119cdf0e10cSrcweir aEnd, 120cdf0e10cSrcweir rView )) == aEnd ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir // view seemingly was not added, failed 123cdf0e10cSrcweir return false; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir OSL_ENSURE( ::std::count( maViews.begin(), 127cdf0e10cSrcweir aEnd, 128cdf0e10cSrcweir rView ) == 1, 129cdf0e10cSrcweir "UnoViewContainer::removeView(): View was added multiple times" ); 130cdf0e10cSrcweir 131cdf0e10cSrcweir // actually erase from container 132cdf0e10cSrcweir maViews.erase( aIter ); 133cdf0e10cSrcweir 134cdf0e10cSrcweir return true; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir dispose()137cdf0e10cSrcweir void UnoViewContainer::dispose() 138cdf0e10cSrcweir { 139cdf0e10cSrcweir ::std::for_each( maViews.begin(), 140cdf0e10cSrcweir maViews.end(), 141cdf0e10cSrcweir ::boost::mem_fn(&UnoView::_dispose) ); 142cdf0e10cSrcweir maViews.clear(); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir } 145cdf0e10cSrcweir } 146