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