170f497fbSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 370f497fbSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 470f497fbSAndrew Rist * or more contributor license agreements. See the NOTICE file 570f497fbSAndrew Rist * distributed with this work for additional information 670f497fbSAndrew Rist * regarding copyright ownership. The ASF licenses this file 770f497fbSAndrew Rist * to you under the Apache License, Version 2.0 (the 870f497fbSAndrew Rist * "License"); you may not use this file except in compliance 970f497fbSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 1170f497fbSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 1370f497fbSAndrew Rist * Unless required by applicable law or agreed to in writing, 1470f497fbSAndrew Rist * software distributed under the License is distributed on an 1570f497fbSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1670f497fbSAndrew Rist * KIND, either express or implied. See the License for the 1770f497fbSAndrew Rist * specific language governing permissions and limitations 1870f497fbSAndrew Rist * under the License. 19cdf0e10cSrcweir * 2070f497fbSAndrew Rist *************************************************************/ 2170f497fbSAndrew Rist 2270f497fbSAndrew 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? 54*a72d41dcSDamjan Jovanovic uno::Reference<presentation::XSlideShowView> rUnoView = rView->getUnoView(); 55cdf0e10cSrcweir if( ::std::find_if( maViews.begin(), 56cdf0e10cSrcweir aEnd, 57cdf0e10cSrcweir ::boost::bind( 58cdf0e10cSrcweir ::std::equal_to< uno::Reference< presentation::XSlideShowView > >(), 59*a72d41dcSDamjan Jovanovic ::boost::cref( rUnoView ), 60cdf0e10cSrcweir ::boost::bind( 61cdf0e10cSrcweir &UnoView::getUnoView, 62cdf0e10cSrcweir _1 ) ) ) != aEnd ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir // yes, nothing to do 65cdf0e10cSrcweir return false; 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir // add locally 69cdf0e10cSrcweir maViews.push_back( rView ); 70cdf0e10cSrcweir 71cdf0e10cSrcweir return true; 72cdf0e10cSrcweir } 73cdf0e10cSrcweir removeView(const uno::Reference<presentation::XSlideShowView> & xView)74cdf0e10cSrcweir UnoViewSharedPtr UnoViewContainer::removeView( const uno::Reference< presentation::XSlideShowView >& xView ) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir // check whether same view is already added 77cdf0e10cSrcweir const UnoViewVector::iterator aEnd( maViews.end() ); 78cdf0e10cSrcweir UnoViewVector::iterator aIter; 79cdf0e10cSrcweir 80cdf0e10cSrcweir // added in the first place? 81cdf0e10cSrcweir if( (aIter=::std::find_if( maViews.begin(), 82cdf0e10cSrcweir aEnd, 83cdf0e10cSrcweir ::boost::bind( 84cdf0e10cSrcweir ::std::equal_to< uno::Reference< presentation::XSlideShowView > >(), 85cdf0e10cSrcweir ::boost::cref( xView ), 86cdf0e10cSrcweir ::boost::bind( 87cdf0e10cSrcweir &UnoView::getUnoView, 88cdf0e10cSrcweir _1 ) ) ) ) == aEnd ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir // nope, nothing to do 91cdf0e10cSrcweir return UnoViewSharedPtr(); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir OSL_ENSURE( 95cdf0e10cSrcweir ::std::count_if( 96cdf0e10cSrcweir maViews.begin(), 97cdf0e10cSrcweir aEnd, 98cdf0e10cSrcweir ::boost::bind( 99cdf0e10cSrcweir ::std::equal_to< uno::Reference< presentation::XSlideShowView > >(), 100cdf0e10cSrcweir ::boost::cref( xView ), 101cdf0e10cSrcweir ::boost::bind( 102cdf0e10cSrcweir &UnoView::getUnoView, 103cdf0e10cSrcweir _1 ))) == 1, 104cdf0e10cSrcweir "UnoViewContainer::removeView(): View was added multiple times" ); 105cdf0e10cSrcweir 106cdf0e10cSrcweir UnoViewSharedPtr pView( *aIter ); 107cdf0e10cSrcweir 108cdf0e10cSrcweir // actually erase from container 109cdf0e10cSrcweir maViews.erase( aIter ); 110cdf0e10cSrcweir 111cdf0e10cSrcweir return pView; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir removeView(const UnoViewSharedPtr & rView)114cdf0e10cSrcweir bool UnoViewContainer::removeView( const UnoViewSharedPtr& rView ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir // remove locally 117cdf0e10cSrcweir const UnoViewVector::iterator aEnd( maViews.end() ); 118cdf0e10cSrcweir UnoViewVector::iterator aIter; 119cdf0e10cSrcweir if( (aIter=::std::find( maViews.begin(), 120cdf0e10cSrcweir aEnd, 121cdf0e10cSrcweir rView )) == aEnd ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir // view seemingly was not added, failed 124cdf0e10cSrcweir return false; 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir OSL_ENSURE( ::std::count( maViews.begin(), 128cdf0e10cSrcweir aEnd, 129cdf0e10cSrcweir rView ) == 1, 130cdf0e10cSrcweir "UnoViewContainer::removeView(): View was added multiple times" ); 131cdf0e10cSrcweir 132cdf0e10cSrcweir // actually erase from container 133cdf0e10cSrcweir maViews.erase( aIter ); 134cdf0e10cSrcweir 135cdf0e10cSrcweir return true; 136cdf0e10cSrcweir } 137cdf0e10cSrcweir dispose()138cdf0e10cSrcweir void UnoViewContainer::dispose() 139cdf0e10cSrcweir { 140cdf0e10cSrcweir ::std::for_each( maViews.begin(), 141cdf0e10cSrcweir maViews.end(), 142cdf0e10cSrcweir ::boost::mem_fn(&UnoView::_dispose) ); 143cdf0e10cSrcweir maViews.clear(); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir } 146cdf0e10cSrcweir } 147