fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / canvas / source / tools / propertysethelper.cxx
blob2cdee08d4d374e3a368d8aec3ef80f2e81bca6f4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
25 namespace canvas
27 namespace
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,
52 rRHS.maKey ) < 0;
57 PropertySetHelper::PropertySetHelper() :
58 mpMap(),
59 maMapEntries()
63 void PropertySetHelper::initProperties( const InputMap& rMap )
65 mpMap.reset();
66 maMapEntries = rMap;
68 std::sort( maMapEntries.begin(),
69 maMapEntries.end(),
70 EntryComparator() );
72 if( !maMapEntries.empty() )
73 mpMap.reset( new MapType(&maMapEntries[0],
74 maMapEntries.size(),
75 true) );
78 void PropertySetHelper::addProperties( const InputMap& rMap )
80 InputMap aMerged( getPropertyMap() );
81 aMerged.insert( aMerged.end(),
82 rMap.begin(),
83 rMap.end() );
85 initProperties( aMerged );
88 bool PropertySetHelper::isPropertyName( const OUString& aPropertyName ) const
90 if( !mpMap.get() )
91 return false;
93 Callbacks aDummy;
94 return mpMap->lookup( aPropertyName,
95 aDummy );
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;
108 if( !mpMap.get() ||
109 !mpMap->lookup( aPropertyName,
110 aCallbacks ) )
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;
124 if( !mpMap.get() ||
125 !mpMap->lookup( aPropertyName,
126 aCallbacks ) )
128 throwUnknown( aPropertyName );
131 if( !aCallbacks.getter.empty() )
132 return aCallbacks.getter();
134 // TODO(Q1): subtlety, empty getter method silently returns
135 // the empty any
136 return uno::Any();
139 void PropertySetHelper::addPropertyChangeListener( const OUString& aPropertyName,
140 const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
142 // check validity of property, but otherwise ignore the
143 // request
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
158 // request
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: */