merge the formfield patch from ooo-build
[ooovba.git] / comphelper / source / property / ChainablePropertySetInfo.cxx
blob671b5f20af44adb227e4022d0b3db7ff8430206a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChainablePropertySetInfo.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_comphelper.hxx"
33 #include <comphelper/ChainablePropertySetInfo.hxx>
34 #include <comphelper/TypeGeneration.hxx>
36 using ::rtl::OUString;
37 using ::comphelper::PropertyInfo;
38 using ::comphelper::GenerateCppuType;
39 using ::comphelper::ChainablePropertySetInfo;
40 using ::com::sun::star::uno::Any;
41 using ::com::sun::star::uno::Type;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::uno::XInterface;
45 using ::com::sun::star::uno::RuntimeException;
46 using ::com::sun::star::beans::Property;
47 using ::com::sun::star::beans::XPropertySetInfo;
48 using ::com::sun::star::beans::UnknownPropertyException;
50 ChainablePropertySetInfo::ChainablePropertySetInfo()
51 throw()
55 ChainablePropertySetInfo::ChainablePropertySetInfo( PropertyInfo* pMap )
56 throw()
58 add ( pMap );
61 ChainablePropertySetInfo::~ChainablePropertySetInfo()
62 throw()
66 void ChainablePropertySetInfo::add( PropertyInfo* pMap, sal_Int32 nCount )
67 throw()
69 // nCount < 0 => add all
70 // nCount == 0 => add nothing
71 // nCount > 0 => add at most nCount entries
72 if( maProperties.getLength() )
73 maProperties.realloc( 0 );
75 while( pMap->mpName && ( ( nCount < 0) || ( nCount-- > 0 ) ) )
77 OUString aName( pMap->mpName, pMap->mnNameLen, RTL_TEXTENCODING_ASCII_US );
79 #ifndef PRODUCT
80 PropertyInfoHash::iterator aIter = maMap.find( aName );
81 if( aIter != maMap.end() )
82 OSL_ENSURE( sal_False, "Warning: PropertyInfo added twice, possible error!");
83 #endif
84 maMap[aName] = pMap++;
88 void ChainablePropertySetInfo::remove( const rtl::OUString& aName )
89 throw()
91 maMap.erase ( aName );
92 if ( maProperties.getLength() )
93 maProperties.realloc( 0 );
96 Sequence< ::Property > SAL_CALL ChainablePropertySetInfo::getProperties()
97 throw(::com::sun::star::uno::RuntimeException)
99 sal_Int32 nSize = maMap.size();
100 if( maProperties.getLength() != nSize )
102 maProperties.realloc ( nSize );
103 Property* pProperties = maProperties.getArray();
105 PropertyInfoHash::iterator aIter = maMap.begin();
106 const PropertyInfoHash::iterator aEnd = maMap.end();
107 for ( ; aIter != aEnd; ++aIter, ++pProperties)
109 PropertyInfo* pInfo = (*aIter).second;
111 pProperties->Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
112 pProperties->Handle = pInfo->mnHandle;
113 const Type* pType;
114 GenerateCppuType ( pInfo->meCppuType, pType);
115 pProperties->Type = *pType;
116 pProperties->Attributes = pInfo->mnAttributes;
119 return maProperties;
122 Property SAL_CALL ChainablePropertySetInfo::getPropertyByName( const ::rtl::OUString& rName )
123 throw(::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
125 PropertyInfoHash::iterator aIter = maMap.find( rName );
127 if ( maMap.end() == aIter )
128 throw UnknownPropertyException( rName, *this );
130 PropertyInfo *pInfo = (*aIter).second;
131 Property aProperty;
132 aProperty.Name = OUString( pInfo->mpName, pInfo->mnNameLen, RTL_TEXTENCODING_ASCII_US );
133 aProperty.Handle = pInfo->mnHandle;
134 const Type* pType = &aProperty.Type;
135 GenerateCppuType ( pInfo->meCppuType, pType );
136 aProperty.Type = *pType;
137 aProperty.Attributes = pInfo->mnAttributes;
138 return aProperty;
141 sal_Bool SAL_CALL ChainablePropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName )
142 throw(::com::sun::star::uno::RuntimeException)
144 return static_cast < sal_Bool > ( maMap.find ( rName ) != maMap.end() );