1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: propertysethelper.cxx,v $
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
;
42 void throwUnknown( const ::rtl::OUString
& aPropertyName
)
44 throw beans::UnknownPropertyException(
45 ::rtl::OUString::createFromAscii("PropertySetHelper: property ") +
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 ") +
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
,
72 PropertySetHelper::PropertySetHelper() :
78 PropertySetHelper::PropertySetHelper( const InputMap
& rMap
) :
85 void PropertySetHelper::initProperties( const InputMap
& rMap
)
90 std::sort( maMapEntries
.begin(),
94 if( !maMapEntries
.empty() )
95 mpMap
.reset( new MapType(&maMapEntries
[0],
100 void PropertySetHelper::addProperties( const InputMap
& rMap
)
102 InputMap
aMerged( getPropertyMap() );
103 aMerged
.insert( aMerged
.end(),
107 initProperties( aMerged
);
110 bool PropertySetHelper::isPropertyName( const ::rtl::OUString
& aPropertyName
) const
116 return mpMap
->lookup( aPropertyName
,
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
;
131 !mpMap
->lookup( aPropertyName
,
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
;
147 !mpMap
->lookup( aPropertyName
,
150 throwUnknown( aPropertyName
);
153 if( !aCallbacks
.getter
.empty() )
154 return aCallbacks
.getter();
156 // TODO(Q1): subtlety, empty getter method silently returns
161 void PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString
& aPropertyName
,
162 const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
164 // check validity of property, but otherwise ignore the
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
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