1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_framework.hxx" 30 #include <uiconfiguration/graphicnameaccess.hxx> 31 32 //_________________________________________________________________________________________________________________ 33 // interface includes 34 //_________________________________________________________________________________________________________________ 35 36 //_________________________________________________________________________________________________________________ 37 // other includes 38 //_________________________________________________________________________________________________________________ 39 40 #include <comphelper/sequence.hxx> 41 42 using namespace ::com::sun::star; 43 44 namespace framework 45 { 46 47 GraphicNameAccess::GraphicNameAccess() 48 { 49 } 50 51 GraphicNameAccess::~GraphicNameAccess() 52 { 53 } 54 55 void GraphicNameAccess::addElement( const rtl::OUString& rName, const uno::Reference< graphic::XGraphic >& rElement ) 56 { 57 m_aNameToElementMap.insert( NameGraphicHashMap::value_type( rName, rElement )); 58 } 59 60 // XNameAccess 61 uno::Any SAL_CALL GraphicNameAccess::getByName( const ::rtl::OUString& aName ) 62 throw( container::NoSuchElementException, 63 lang::WrappedTargetException, 64 uno::RuntimeException) 65 { 66 NameGraphicHashMap::const_iterator pIter = m_aNameToElementMap.find( aName ); 67 if ( pIter != m_aNameToElementMap.end() ) 68 return uno::makeAny( pIter->second ); 69 else 70 throw container::NoSuchElementException(); 71 } 72 73 uno::Sequence< ::rtl::OUString > SAL_CALL GraphicNameAccess::getElementNames() 74 throw(::com::sun::star::uno::RuntimeException) 75 { 76 if ( m_aSeq.getLength() == 0 ) 77 { 78 uno::Sequence< rtl::OUString > aSeq( m_aNameToElementMap.size() ); 79 NameGraphicHashMap::const_iterator pIter = m_aNameToElementMap.begin(); 80 sal_Int32 i( 0); 81 while ( pIter != m_aNameToElementMap.end()) 82 { 83 aSeq[i++] = pIter->first; 84 ++pIter; 85 } 86 m_aSeq = aSeq; 87 } 88 89 return m_aSeq; 90 } 91 92 sal_Bool SAL_CALL GraphicNameAccess::hasByName( const ::rtl::OUString& aName ) 93 throw(::com::sun::star::uno::RuntimeException) 94 { 95 NameGraphicHashMap::const_iterator pIter = m_aNameToElementMap.find( aName ); 96 return ( pIter != m_aNameToElementMap.end() ); 97 } 98 99 // XElementAccess 100 sal_Bool SAL_CALL GraphicNameAccess::hasElements() 101 throw( uno::RuntimeException ) 102 { 103 return ( !m_aNameToElementMap.empty() ); 104 } 105 106 uno::Type SAL_CALL GraphicNameAccess::getElementType() 107 throw( uno::RuntimeException ) 108 { 109 return ::getCppuType( (const uno::Reference< graphic::XGraphic > *)NULL ); 110 } 111 112 } // namespace framework 113