merge the formfield patch from ooo-build
[ooovba.git] / canvas / source / tools / propertysethelper.cxx
blobfc98d824f2fd22752376ca4cc087f47a2c6ccc7e
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: propertysethelper.cxx,v $
10 * $Revision: 1.5 $
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_canvas.hxx"
34 #include <canvas/propertysethelper.hxx>
36 using namespace ::com::sun::star;
38 namespace canvas
40 namespace
42 void throwUnknown( const ::rtl::OUString& aPropertyName )
44 throw beans::UnknownPropertyException(
45 ::rtl::OUString::createFromAscii("PropertySetHelper: property ") +
46 aPropertyName +
47 ::rtl::OUString::createFromAscii(" not found."),
48 uno::Reference< uno::XInterface >()
52 void throwVeto( const ::rtl::OUString& aPropertyName )
54 throw beans::PropertyVetoException(
55 ::rtl::OUString::createFromAscii("PropertySetHelper: property ") +
56 aPropertyName +
57 ::rtl::OUString::createFromAscii(" access was vetoed."),
58 uno::Reference< uno::XInterface >() );
61 struct EntryComparator
63 bool operator()( const PropertySetHelper::MapType::MapEntry& rLHS,
64 const PropertySetHelper::MapType::MapEntry& rRHS )
66 return strcmp( rLHS.maKey,
67 rRHS.maKey ) < 0;
72 PropertySetHelper::PropertySetHelper() :
73 mpMap(),
74 maMapEntries()
78 PropertySetHelper::PropertySetHelper( const InputMap& rMap ) :
79 mpMap(),
80 maMapEntries()
82 initProperties(rMap);
85 void PropertySetHelper::initProperties( const InputMap& rMap )
87 mpMap.reset();
88 maMapEntries = rMap;
90 std::sort( maMapEntries.begin(),
91 maMapEntries.end(),
92 EntryComparator() );
94 if( !maMapEntries.empty() )
95 mpMap.reset( new MapType(&maMapEntries[0],
96 maMapEntries.size(),
97 true) );
100 void PropertySetHelper::addProperties( const InputMap& rMap )
102 InputMap aMerged( getPropertyMap() );
103 aMerged.insert( aMerged.end(),
104 rMap.begin(),
105 rMap.end() );
107 initProperties( aMerged );
110 bool PropertySetHelper::isPropertyName( const ::rtl::OUString& aPropertyName ) const
112 if( !mpMap.get() )
113 return false;
115 Callbacks aDummy;
116 return mpMap->lookup( aPropertyName,
117 aDummy );
120 uno::Reference< beans::XPropertySetInfo > PropertySetHelper::getPropertySetInfo() const
122 // we're a stealth property set
123 return uno::Reference< beans::XPropertySetInfo >();
126 void PropertySetHelper::setPropertyValue( const ::rtl::OUString& aPropertyName,
127 const uno::Any& aValue )
129 Callbacks aCallbacks;
130 if( !mpMap.get() ||
131 !mpMap->lookup( aPropertyName,
132 aCallbacks ) )
134 throwUnknown( aPropertyName );
137 if( aCallbacks.setter.empty() )
138 throwVeto( aPropertyName );
140 aCallbacks.setter(aValue);
143 uno::Any PropertySetHelper::getPropertyValue( const ::rtl::OUString& aPropertyName ) const
145 Callbacks aCallbacks;
146 if( !mpMap.get() ||
147 !mpMap->lookup( aPropertyName,
148 aCallbacks ) )
150 throwUnknown( aPropertyName );
153 if( !aCallbacks.getter.empty() )
154 return aCallbacks.getter();
156 // TODO(Q1): subtlety, empty getter method silently returns
157 // the empty any
158 return uno::Any();
161 void PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
162 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
164 // check validity of property, but otherwise ignore the
165 // request
166 if( !isPropertyName( aPropertyName ) )
167 throwUnknown( aPropertyName );
170 void PropertySetHelper::removePropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/,
171 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
173 // ignore request, no listener added in the first place
176 void PropertySetHelper::addVetoableChangeListener( const ::rtl::OUString& aPropertyName,
177 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/ )
179 // check validity of property, but otherwise ignore the
180 // request
181 if( !isPropertyName( aPropertyName ) )
182 throwUnknown( aPropertyName );
185 void PropertySetHelper::removeVetoableChangeListener( const ::rtl::OUString& /*aPropertyName*/,
186 const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/ )
188 // ignore request, no listener added in the first place