1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
31 #include <canvas/propertysethelper.hxx>
33 using namespace ::com::sun::star
;
39 void throwUnknown( const ::rtl::OUString
& aPropertyName
)
41 throw beans::UnknownPropertyException(
42 ::rtl::OUString::createFromAscii("PropertySetHelper: property ") +
44 ::rtl::OUString::createFromAscii(" not found."),
45 uno::Reference
< uno::XInterface
>()
49 void throwVeto( const ::rtl::OUString
& aPropertyName
)
51 throw beans::PropertyVetoException(
52 ::rtl::OUString::createFromAscii("PropertySetHelper: property ") +
54 ::rtl::OUString::createFromAscii(" access was vetoed."),
55 uno::Reference
< uno::XInterface
>() );
58 struct EntryComparator
60 bool operator()( const PropertySetHelper::MapType::MapEntry
& rLHS
,
61 const PropertySetHelper::MapType::MapEntry
& rRHS
)
63 return strcmp( rLHS
.maKey
,
69 PropertySetHelper::PropertySetHelper() :
75 PropertySetHelper::PropertySetHelper( const InputMap
& rMap
) :
82 void PropertySetHelper::initProperties( const InputMap
& rMap
)
87 std::sort( maMapEntries
.begin(),
91 if( !maMapEntries
.empty() )
92 mpMap
.reset( new MapType(&maMapEntries
[0],
97 void PropertySetHelper::addProperties( const InputMap
& rMap
)
99 InputMap
aMerged( getPropertyMap() );
100 aMerged
.insert( aMerged
.end(),
104 initProperties( aMerged
);
107 bool PropertySetHelper::isPropertyName( const ::rtl::OUString
& aPropertyName
) const
113 return mpMap
->lookup( aPropertyName
,
117 uno::Reference
< beans::XPropertySetInfo
> PropertySetHelper::getPropertySetInfo() const
119 // we're a stealth property set
120 return uno::Reference
< beans::XPropertySetInfo
>();
123 void PropertySetHelper::setPropertyValue( const ::rtl::OUString
& aPropertyName
,
124 const uno::Any
& aValue
)
126 Callbacks aCallbacks
;
128 !mpMap
->lookup( aPropertyName
,
131 throwUnknown( aPropertyName
);
134 if( aCallbacks
.setter
.empty() )
135 throwVeto( aPropertyName
);
137 aCallbacks
.setter(aValue
);
140 uno::Any
PropertySetHelper::getPropertyValue( const ::rtl::OUString
& aPropertyName
) const
142 Callbacks aCallbacks
;
144 !mpMap
->lookup( aPropertyName
,
147 throwUnknown( aPropertyName
);
150 if( !aCallbacks
.getter
.empty() )
151 return aCallbacks
.getter();
153 // TODO(Q1): subtlety, empty getter method silently returns
158 void PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString
& aPropertyName
,
159 const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
161 // check validity of property, but otherwise ignore the
163 if( !isPropertyName( aPropertyName
) )
164 throwUnknown( aPropertyName
);
167 void PropertySetHelper::removePropertyChangeListener( const ::rtl::OUString
& /*aPropertyName*/,
168 const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
170 // ignore request, no listener added in the first place
173 void PropertySetHelper::addVetoableChangeListener( const ::rtl::OUString
& aPropertyName
,
174 const uno::Reference
< beans::XVetoableChangeListener
>& /*xListener*/ )
176 // check validity of property, but otherwise ignore the
178 if( !isPropertyName( aPropertyName
) )
179 throwUnknown( aPropertyName
);
182 void PropertySetHelper::removeVetoableChangeListener( const ::rtl::OUString
& /*aPropertyName*/,
183 const uno::Reference
< beans::XVetoableChangeListener
>& /*xListener*/ )
185 // ignore request, no listener added in the first place