1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <canvas/propertysethelper.hxx>
23 using namespace ::com::sun::star
;
29 void throwUnknown( const OUString
& aPropertyName
)
31 throw beans::UnknownPropertyException(
32 "PropertySetHelper: property " +
33 aPropertyName
+ " not found.",
34 uno::Reference
< uno::XInterface
>()
38 void throwVeto( const OUString
& aPropertyName
)
40 throw beans::PropertyVetoException(
41 "PropertySetHelper: property " +
42 aPropertyName
+ " access was vetoed.",
43 uno::Reference
< uno::XInterface
>() );
46 struct EntryComparator
48 bool operator()( const PropertySetHelper::MapType::MapEntry
& rLHS
,
49 const PropertySetHelper::MapType::MapEntry
& rRHS
)
51 return strcmp( rLHS
.maKey
,
57 PropertySetHelper::PropertySetHelper() :
63 void PropertySetHelper::initProperties( const InputMap
& rMap
)
68 std::sort( maMapEntries
.begin(),
72 if( !maMapEntries
.empty() )
73 mpMap
.reset( new MapType(&maMapEntries
[0],
78 void PropertySetHelper::addProperties( const InputMap
& rMap
)
80 InputMap
aMerged( getPropertyMap() );
81 aMerged
.insert( aMerged
.end(),
85 initProperties( aMerged
);
88 bool PropertySetHelper::isPropertyName( const OUString
& aPropertyName
) const
94 return mpMap
->lookup( aPropertyName
,
98 uno::Reference
< beans::XPropertySetInfo
> PropertySetHelper::getPropertySetInfo() const
100 // we're a stealth property set
101 return uno::Reference
< beans::XPropertySetInfo
>();
104 void PropertySetHelper::setPropertyValue( const OUString
& aPropertyName
,
105 const uno::Any
& aValue
)
107 Callbacks aCallbacks
;
109 !mpMap
->lookup( aPropertyName
,
112 throwUnknown( aPropertyName
);
115 if( aCallbacks
.setter
.empty() )
116 throwVeto( aPropertyName
);
118 aCallbacks
.setter(aValue
);
121 uno::Any
PropertySetHelper::getPropertyValue( const OUString
& aPropertyName
) const
123 Callbacks aCallbacks
;
125 !mpMap
->lookup( aPropertyName
,
128 throwUnknown( aPropertyName
);
131 if( !aCallbacks
.getter
.empty() )
132 return aCallbacks
.getter();
134 // TODO(Q1): subtlety, empty getter method silently returns
139 void PropertySetHelper::addPropertyChangeListener( const OUString
& aPropertyName
,
140 const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
142 // check validity of property, but otherwise ignore the
144 if( !isPropertyName( aPropertyName
) )
145 throwUnknown( aPropertyName
);
148 void PropertySetHelper::removePropertyChangeListener( const OUString
& /*aPropertyName*/,
149 const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
151 // ignore request, no listener added in the first place
154 void PropertySetHelper::addVetoableChangeListener( const OUString
& aPropertyName
,
155 const uno::Reference
< beans::XVetoableChangeListener
>& /*xListener*/ )
157 // check validity of property, but otherwise ignore the
159 if( !isPropertyName( aPropertyName
) )
160 throwUnknown( aPropertyName
);
163 void PropertySetHelper::removeVetoableChangeListener( const OUString
& /*aPropertyName*/,
164 const uno::Reference
< beans::XVetoableChangeListener
>& /*xListener*/ )
166 // ignore request, no listener added in the first place
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */