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."
37 void throwVeto( const OUString
& aPropertyName
)
39 throw beans::PropertyVetoException(
40 "PropertySetHelper: property " +
41 aPropertyName
+ " access was vetoed." );
44 struct EntryComparator
46 bool operator()( const PropertySetHelper::MapType::MapEntry
& rLHS
,
47 const PropertySetHelper::MapType::MapEntry
& rRHS
)
49 return strcmp( rLHS
.maKey
,
55 PropertySetHelper::PropertySetHelper() :
61 void PropertySetHelper::initProperties( const InputMap
& rMap
)
66 std::sort( maMapEntries
.begin(),
70 if( !maMapEntries
.empty() )
71 mpMap
.reset( new MapType(&maMapEntries
[0],
76 void PropertySetHelper::addProperties( const InputMap
& rMap
)
78 InputMap
aMerged( getPropertyMap() );
79 aMerged
.insert( aMerged
.end(),
83 initProperties( aMerged
);
86 bool PropertySetHelper::isPropertyName( const OUString
& aPropertyName
) const
92 return mpMap
->lookup( aPropertyName
,
96 uno::Reference
< beans::XPropertySetInfo
> PropertySetHelper::getPropertySetInfo() const
98 // we're a stealth property set
99 return uno::Reference
< beans::XPropertySetInfo
>();
102 void PropertySetHelper::setPropertyValue( const OUString
& aPropertyName
,
103 const uno::Any
& aValue
)
105 Callbacks aCallbacks
;
107 !mpMap
->lookup( aPropertyName
,
110 throwUnknown( aPropertyName
);
113 if( aCallbacks
.setter
.empty() )
114 throwVeto( aPropertyName
);
116 aCallbacks
.setter(aValue
);
119 uno::Any
PropertySetHelper::getPropertyValue( const OUString
& aPropertyName
) const
121 Callbacks aCallbacks
;
123 !mpMap
->lookup( aPropertyName
,
126 throwUnknown( aPropertyName
);
129 if( !aCallbacks
.getter
.empty() )
130 return aCallbacks
.getter();
132 // TODO(Q1): subtlety, empty getter method silently returns
137 void PropertySetHelper::addPropertyChangeListener( const OUString
& aPropertyName
,
138 const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
140 // check validity of property, but otherwise ignore the
142 if( !isPropertyName( aPropertyName
) )
143 throwUnknown( aPropertyName
);
146 void PropertySetHelper::addVetoableChangeListener( const OUString
& aPropertyName
,
147 const uno::Reference
< beans::XVetoableChangeListener
>& /*xListener*/ )
149 // check validity of property, but otherwise ignore the
151 if( !isPropertyName( aPropertyName
) )
152 throwUnknown( aPropertyName
);
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */