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_framework.hxx"
26 #include <uiconfiguration/graphicnameaccess.hxx>
27 
28 //_________________________________________________________________________________________________________________
29 //	interface includes
30 //_________________________________________________________________________________________________________________
31 
32 //_________________________________________________________________________________________________________________
33 //	other includes
34 //_________________________________________________________________________________________________________________
35 
36 #include <comphelper/sequence.hxx>
37 
38 using namespace ::com::sun::star;
39 
40 namespace framework
41 {
42 
GraphicNameAccess()43 GraphicNameAccess::GraphicNameAccess()
44 {
45 }
46 
~GraphicNameAccess()47 GraphicNameAccess::~GraphicNameAccess()
48 {
49 }
50 
addElement(const rtl::OUString & rName,const uno::Reference<graphic::XGraphic> & rElement)51 void GraphicNameAccess::addElement( const rtl::OUString& rName, const uno::Reference< graphic::XGraphic >& rElement )
52 {
53     m_aNameToElementMap.insert( NameGraphicHashMap::value_type( rName, rElement ));
54 }
55 
56 // XNameAccess
getByName(const::rtl::OUString & aName)57 uno::Any SAL_CALL GraphicNameAccess::getByName( const ::rtl::OUString& aName )
58 throw( container::NoSuchElementException,
59        lang::WrappedTargetException,
60 	   uno::RuntimeException)
61 {
62     NameGraphicHashMap::const_iterator pIter = m_aNameToElementMap.find( aName );
63     if ( pIter != m_aNameToElementMap.end() )
64         return uno::makeAny( pIter->second );
65     else
66         throw container::NoSuchElementException();
67 }
68 
getElementNames()69 uno::Sequence< ::rtl::OUString > SAL_CALL GraphicNameAccess::getElementNames()
70 throw(::com::sun::star::uno::RuntimeException)
71 {
72     if ( m_aSeq.getLength() == 0 )
73     {
74         uno::Sequence< rtl::OUString > aSeq( m_aNameToElementMap.size() );
75         NameGraphicHashMap::const_iterator pIter = m_aNameToElementMap.begin();
76         sal_Int32 i( 0);
77         while ( pIter != m_aNameToElementMap.end())
78         {
79             aSeq[i++] = pIter->first;
80             ++pIter;
81         }
82         m_aSeq = aSeq;
83     }
84 
85     return m_aSeq;
86 }
87 
hasByName(const::rtl::OUString & aName)88 sal_Bool SAL_CALL GraphicNameAccess::hasByName( const ::rtl::OUString& aName )
89 throw(::com::sun::star::uno::RuntimeException)
90 {
91     NameGraphicHashMap::const_iterator pIter = m_aNameToElementMap.find( aName );
92     return ( pIter != m_aNameToElementMap.end() );
93 }
94 
95 // XElementAccess
hasElements()96 sal_Bool SAL_CALL GraphicNameAccess::hasElements()
97 throw( uno::RuntimeException )
98 {
99     return ( !m_aNameToElementMap.empty() );
100 }
101 
getElementType()102 uno::Type SAL_CALL GraphicNameAccess::getElementType()
103 throw( uno::RuntimeException )
104 {
105     return ::getCppuType( (const uno::Reference< graphic::XGraphic > *)NULL );
106 }
107 
108 } // namespace framework
109