Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <canvas/propertysethelper.hxx>
31 : :
32 : : using namespace ::com::sun::star;
33 : :
34 : : namespace canvas
35 : : {
36 : : namespace
37 : : {
38 : 0 : void throwUnknown( const ::rtl::OUString& aPropertyName )
39 : : {
40 : : throw beans::UnknownPropertyException(
41 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PropertySetHelper: property " )) +
42 : : aPropertyName +
43 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " not found." )),
44 : : uno::Reference< uno::XInterface >()
45 [ # # ][ # # ]: 0 : );
[ # # ]
46 : : }
47 : :
48 : 0 : void throwVeto( const ::rtl::OUString& aPropertyName )
49 : : {
50 : : throw beans::PropertyVetoException(
51 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PropertySetHelper: property " )) +
52 : : aPropertyName +
53 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " access was vetoed." )),
54 [ # # ][ # # ]: 0 : uno::Reference< uno::XInterface >() );
[ # # ]
55 : : }
56 : :
57 : : struct EntryComparator
58 : : {
59 : 0 : bool operator()( const PropertySetHelper::MapType::MapEntry& rLHS,
60 : : const PropertySetHelper::MapType::MapEntry& rRHS )
61 : : {
62 : : return strcmp( rLHS.maKey,
63 : 0 : rRHS.maKey ) < 0;
64 : : }
65 : : };
66 : : }
67 : :
68 : 0 : PropertySetHelper::PropertySetHelper() :
69 : : mpMap(),
70 [ # # ]: 0 : maMapEntries()
71 : : {
72 : 0 : }
73 : :
74 : 0 : void PropertySetHelper::initProperties( const InputMap& rMap )
75 : : {
76 : 0 : mpMap.reset();
77 : 0 : maMapEntries = rMap;
78 : :
79 : : std::sort( maMapEntries.begin(),
80 : : maMapEntries.end(),
81 [ # # ]: 0 : EntryComparator() );
82 : :
83 [ # # ]: 0 : if( !maMapEntries.empty() )
84 : 0 : mpMap.reset( new MapType(&maMapEntries[0],
85 : 0 : maMapEntries.size(),
86 : 0 : true) );
87 : 0 : }
88 : :
89 : 0 : void PropertySetHelper::addProperties( const InputMap& rMap )
90 : : {
91 [ # # ]: 0 : InputMap aMerged( getPropertyMap() );
92 : : aMerged.insert( aMerged.end(),
93 : : rMap.begin(),
94 [ # # ]: 0 : rMap.end() );
95 : :
96 [ # # ]: 0 : initProperties( aMerged );
97 : 0 : }
98 : :
99 : 0 : bool PropertySetHelper::isPropertyName( const ::rtl::OUString& aPropertyName ) const
100 : : {
101 [ # # ]: 0 : if( !mpMap.get() )
102 : 0 : return false;
103 : :
104 [ # # ]: 0 : Callbacks aDummy;
105 : : return mpMap->lookup( aPropertyName,
106 [ # # ][ # # ]: 0 : aDummy );
107 : : }
108 : :
109 : 0 : uno::Reference< beans::XPropertySetInfo > PropertySetHelper::getPropertySetInfo() const
110 : : {
111 : : // we're a stealth property set
112 : 0 : return uno::Reference< beans::XPropertySetInfo >();
113 : : }
114 : :
115 : 0 : void PropertySetHelper::setPropertyValue( const ::rtl::OUString& aPropertyName,
116 : : const uno::Any& aValue )
117 : : {
118 [ # # ]: 0 : Callbacks aCallbacks;
119 [ # # ][ # # ]: 0 : if( !mpMap.get() ||
[ # # ]
120 : : !mpMap->lookup( aPropertyName,
121 [ # # ]: 0 : aCallbacks ) )
122 : : {
123 [ # # ]: 0 : throwUnknown( aPropertyName );
124 : : }
125 : :
126 [ # # ]: 0 : if( aCallbacks.setter.empty() )
127 [ # # ]: 0 : throwVeto( aPropertyName );
128 : :
129 [ # # ][ # # ]: 0 : aCallbacks.setter(aValue);
130 : 0 : }
131 : :
132 : 0 : uno::Any PropertySetHelper::getPropertyValue( const ::rtl::OUString& aPropertyName ) const
133 : : {
134 [ # # ]: 0 : Callbacks aCallbacks;
135 [ # # ][ # # ]: 0 : if( !mpMap.get() ||
[ # # ]
136 : : !mpMap->lookup( aPropertyName,
137 [ # # ]: 0 : aCallbacks ) )
138 : : {
139 [ # # ]: 0 : throwUnknown( aPropertyName );
140 : : }
141 : :
142 [ # # ]: 0 : if( !aCallbacks.getter.empty() )
143 [ # # ]: 0 : return aCallbacks.getter();
144 : :
145 : : // TODO(Q1): subtlety, empty getter method silently returns
146 : : // the empty any
147 [ # # ]: 0 : return uno::Any();
148 : : }
149 : :
150 : 0 : void PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
151 : : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
152 : : {
153 : : // check validity of property, but otherwise ignore the
154 : : // request
155 [ # # ]: 0 : if( !isPropertyName( aPropertyName ) )
156 : 0 : throwUnknown( aPropertyName );
157 : 0 : }
158 : :
159 : 0 : void PropertySetHelper::removePropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/,
160 : : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
161 : : {
162 : : // ignore request, no listener added in the first place
163 : 0 : }
164 : :
165 : 0 : void PropertySetHelper::addVetoableChangeListener( const ::rtl::OUString& aPropertyName,
166 : : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/ )
167 : : {
168 : : // check validity of property, but otherwise ignore the
169 : : // request
170 [ # # ]: 0 : if( !isPropertyName( aPropertyName ) )
171 : 0 : throwUnknown( aPropertyName );
172 : 0 : }
173 : :
174 : 0 : void PropertySetHelper::removeVetoableChangeListener( const ::rtl::OUString& /*aPropertyName*/,
175 : : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/ )
176 : : {
177 : : // ignore request, no listener added in the first place
178 : 0 : }
179 : : }
180 : :
181 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|