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             if( ::std::find_if( maViews.begin(),
55                                 aEnd,
56                                 ::boost::bind(
57                                     ::std::equal_to< uno::Reference< presentation::XSlideShowView > >(),
58                                     ::boost::cref( rView->getUnoView() ),
59                                     ::boost::bind(
60                                         &UnoView::getUnoView,
61                                         _1 ) ) ) != aEnd )
62             {
63                 // yes, nothing to do
64                 return false;
65             }
66 
67             // add locally
68             maViews.push_back( rView );
69 
70             return true;
71         }
72 
removeView(const uno::Reference<presentation::XSlideShowView> & xView)73         UnoViewSharedPtr UnoViewContainer::removeView( const uno::Reference< presentation::XSlideShowView >& xView )
74         {
75             // check whether same view is already added
76             const UnoViewVector::iterator aEnd( maViews.end() );
77             UnoViewVector::iterator aIter;
78 
79             // added in the first place?
80             if( (aIter=::std::find_if( maViews.begin(),
81                                        aEnd,
82                                        ::boost::bind(
83                                            ::std::equal_to< uno::Reference< presentation::XSlideShowView > >(),
84                                            ::boost::cref( xView ),
85                                            ::boost::bind(
86                                                &UnoView::getUnoView,
87                                                _1 ) ) ) ) == aEnd )
88             {
89                 // nope, nothing to do
90                 return UnoViewSharedPtr();
91             }
92 
93             OSL_ENSURE(
94                 ::std::count_if(
95                     maViews.begin(),
96                     aEnd,
97                     ::boost::bind(
98                         ::std::equal_to< uno::Reference< presentation::XSlideShowView > >(),
99                         ::boost::cref( xView ),
100                         ::boost::bind(
101                             &UnoView::getUnoView,
102                             _1 ))) == 1,
103                 "UnoViewContainer::removeView(): View was added multiple times" );
104 
105             UnoViewSharedPtr pView( *aIter );
106 
107             // actually erase from container
108             maViews.erase( aIter );
109 
110             return pView;
111         }
112 
removeView(const UnoViewSharedPtr & rView)113         bool UnoViewContainer::removeView( const UnoViewSharedPtr& rView )
114         {
115             // remove locally
116             const UnoViewVector::iterator aEnd( maViews.end() );
117             UnoViewVector::iterator aIter;
118             if( (aIter=::std::find( maViews.begin(),
119                                     aEnd,
120                                     rView )) == aEnd )
121             {
122                 // view seemingly was not added, failed
123                 return false;
124             }
125 
126             OSL_ENSURE( ::std::count( maViews.begin(),
127                                       aEnd,
128                                       rView ) == 1,
129                         "UnoViewContainer::removeView(): View was added multiple times" );
130 
131             // actually erase from container
132             maViews.erase( aIter );
133 
134             return true;
135         }
136 
dispose()137         void UnoViewContainer::dispose()
138         {
139             ::std::for_each( maViews.begin(),
140                              maViews.end(),
141                              ::boost::mem_fn(&UnoView::_dispose) );
142             maViews.clear();
143         }
144     }
145 }
146