Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <svx/sdasitm.hxx>
21 : #include <svx/svdattr.hxx>
22 :
23 : using namespace ::std;
24 : using namespace com::sun::star;
25 :
26 2841 : SdrCustomShapeEngineItem::SdrCustomShapeEngineItem()
27 2841 : : SfxStringItem( SDRATTR_CUSTOMSHAPE_ENGINE, "" )
28 2841 : {}
29 :
30 2841 : SdrCustomShapeDataItem::SdrCustomShapeDataItem()
31 2841 : : SfxStringItem( SDRATTR_CUSTOMSHAPE_DATA, "" )
32 2841 : {}
33 :
34 211767 : TYPEINIT1_FACTORY( SdrCustomShapeGeometryItem, SfxPoolItem , new SdrCustomShapeGeometryItem);
35 :
36 2841 : SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem()
37 2841 : : SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
38 2841 : {}
39 :
40 10530 : SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( const uno::Sequence< beans::PropertyValue >& rVal )
41 10530 : : SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
42 : {
43 : sal_Int32 i, j;
44 10530 : aPropSeq = rVal;
45 :
46 50967 : for ( i = 0; i < aPropSeq.getLength(); i++ )
47 : {
48 40437 : beans::PropertyValue& rPropVal = aPropSeq[ i ];
49 40437 : aPropHashMap[ rPropVal.Name ] = i;
50 40437 : if ( rPropVal.Value.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
51 : {
52 4365 : uno::Sequence< beans::PropertyValue >& rPropSeq = *( uno::Sequence< beans::PropertyValue >*)rPropVal.Value.getValue();
53 17055 : for ( j = 0; j < rPropSeq.getLength(); j++ )
54 : {
55 12690 : beans::PropertyValue& rPropVal2 = rPropSeq[ j ];
56 12690 : aPropPairHashMap[ PropertyPair( rPropVal.Name, rPropVal2.Name ) ] = j;
57 : }
58 : }
59 : }
60 10530 : }
61 :
62 224437 : com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const OUString& rPropName )
63 : {
64 224437 : com::sun::star::uno::Any* pRet = NULL;
65 224437 : PropertyHashMap::iterator aHashIter( aPropHashMap.find( rPropName ) );
66 224437 : if ( aHashIter != aPropHashMap.end() )
67 99245 : pRet = &aPropSeq[ (*aHashIter).second ].Value;
68 224437 : return pRet;
69 : }
70 :
71 106186 : com::sun::star::uno::Any* SdrCustomShapeGeometryItem::GetPropertyValueByName( const OUString& rSequenceName, const OUString& rPropName )
72 : {
73 106186 : com::sun::star::uno::Any* pRet = NULL;
74 106186 : com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
75 106186 : if ( pSeqAny )
76 : {
77 50979 : if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
78 : {
79 50979 : PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropName ) ) );
80 50979 : if ( aHashIter != aPropPairHashMap.end() )
81 : {
82 : ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
83 17594 : *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
84 17594 : pRet = &rSecSequence[ (*aHashIter).second ].Value;
85 : }
86 : }
87 : }
88 106186 : return pRet;
89 : }
90 :
91 4358 : void SdrCustomShapeGeometryItem::SetPropertyValue( const com::sun::star::beans::PropertyValue& rPropVal )
92 : {
93 4358 : com::sun::star::uno::Any* pAny = GetPropertyValueByName( rPropVal.Name );
94 4358 : if ( pAny )
95 : { // property is already available
96 : sal_Int32 i;
97 1347 : if ( pAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
98 : { // old property is a sequence->each entry has to be removed from the HashPairMap
99 : ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
100 0 : *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pAny->getValue());
101 0 : for ( i = 0; i < rSecSequence.getLength(); i++ )
102 : {
103 0 : PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rPropVal.Name, rSecSequence[ i ].Name ) ) );
104 0 : if ( aHashIter != aPropPairHashMap.end() )
105 0 : aPropPairHashMap.erase( aHashIter );
106 : }
107 : }
108 1347 : *pAny = rPropVal.Value;
109 1347 : if ( rPropVal.Value.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
110 : { // the new property is a sequence->each entry has to be inserted into the HashPairMap
111 : ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
112 0 : *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pAny->getValue());
113 0 : for ( i = 0; i < rSecSequence.getLength(); i++ )
114 : {
115 0 : beans::PropertyValue& rPropVal2 = rSecSequence[ i ];
116 0 : aPropPairHashMap[ PropertyPair( rPropVal.Name, rPropVal2.Name ) ] = i;
117 : }
118 : }
119 : }
120 : else
121 : { // it's a new property
122 3011 : sal_uInt32 nIndex = aPropSeq.getLength();
123 3011 : aPropSeq.realloc( nIndex + 1 );
124 3011 : aPropSeq[ nIndex ] = rPropVal ;
125 :
126 3011 : aPropHashMap[ rPropVal.Name ] = nIndex;
127 : }
128 4358 : }
129 :
130 1857 : void SdrCustomShapeGeometryItem::SetPropertyValue( const OUString& rSequenceName, const com::sun::star::beans::PropertyValue& rPropVal )
131 : {
132 1857 : com::sun::star::uno::Any* pAny = GetPropertyValueByName( rSequenceName, rPropVal.Name );
133 1857 : if ( pAny ) // just replacing
134 0 : *pAny = rPropVal.Value;
135 : else
136 : {
137 1857 : com::sun::star::uno::Any* pSeqAny = GetPropertyValueByName( rSequenceName );
138 1857 : if( pSeqAny == NULL )
139 : {
140 1272 : ::com::sun::star::uno::Sequence < beans::PropertyValue > aSeq;
141 2544 : beans::PropertyValue aValue;
142 1272 : aValue.Name = rSequenceName;
143 1272 : aValue.Value = ::com::sun::star::uno::makeAny( aSeq );
144 :
145 1272 : sal_uInt32 nIndex = aPropSeq.getLength();
146 1272 : aPropSeq.realloc( nIndex + 1 );
147 1272 : aPropSeq[ nIndex ] = aValue;
148 1272 : aPropHashMap[ rSequenceName ] = nIndex;
149 :
150 2544 : pSeqAny = &aPropSeq[ nIndex ].Value;
151 : }
152 :
153 : DBG_ASSERT( pSeqAny, "SdrCustomShapeGeometryItem::SetPropertyValue() - No Value??" );
154 :
155 1857 : if( pSeqAny )
156 : {
157 1857 : if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
158 : {
159 1857 : PropertyPairHashMap::iterator aHashIter( aPropPairHashMap.find( PropertyPair( rSequenceName, rPropVal.Name ) ) );
160 1857 : if ( aHashIter != aPropPairHashMap.end() )
161 : {
162 : ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
163 0 : *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
164 0 : rSecSequence[ (*aHashIter).second ].Value = rPropVal.Value;
165 : }
166 : else
167 : {
168 : ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
169 1857 : *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
170 :
171 1857 : sal_Int32 nCount = rSecSequence.getLength();
172 1857 : rSecSequence.realloc( nCount + 1 );
173 1857 : rSecSequence[ nCount ] = rPropVal;
174 :
175 1857 : aPropPairHashMap[ PropertyPair( rSequenceName, rPropVal.Name ) ] = nCount;
176 : }
177 : }
178 : }
179 : }
180 1857 : }
181 :
182 0 : void SdrCustomShapeGeometryItem::ClearPropertyValue( const OUString& rPropName )
183 : {
184 0 : if ( aPropSeq.getLength() )
185 : {
186 0 : PropertyHashMap::iterator aHashIter( aPropHashMap.find( rPropName ) );
187 0 : if ( aHashIter != aPropHashMap.end() )
188 : {
189 0 : com::sun::star::uno::Any* pSeqAny = &aPropSeq[ (*aHashIter).second ].Value;
190 0 : if ( pSeqAny )
191 : {
192 0 : if ( pSeqAny->getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < beans::PropertyValue >*)0) )
193 : {
194 : ::com::sun::star::uno::Sequence < beans::PropertyValue >& rSecSequence =
195 0 : *((::com::sun::star::uno::Sequence < beans::PropertyValue >*)pSeqAny->getValue());
196 :
197 : sal_Int32 i;
198 0 : for ( i = 0; i < rSecSequence.getLength(); i++ )
199 : {
200 0 : PropertyPairHashMap::iterator _aHashIter( aPropPairHashMap.find( PropertyPair( rPropName, rSecSequence[ i ].Name ) ) );
201 0 : if ( _aHashIter != aPropPairHashMap.end() )
202 0 : aPropPairHashMap.erase( _aHashIter ); // removing property from pair hashmap
203 : }
204 : }
205 : }
206 0 : sal_Int32 nLength = aPropSeq.getLength();
207 0 : if ( nLength )
208 : {
209 0 : sal_Int32 nIndex = (*aHashIter).second;
210 0 : if ( nIndex != ( nLength - 1 ) ) // resizing sequence
211 : {
212 0 : PropertyHashMap::iterator aHashIter2( aPropHashMap.find( aPropSeq[ nLength - 1 ].Name ) );
213 0 : (*aHashIter2).second = nIndex;
214 0 : aPropSeq[ (*aHashIter).second ] = aPropSeq[ aPropSeq.getLength() - 1 ];
215 : }
216 0 : aPropSeq.realloc( aPropSeq.getLength() - 1 );
217 : }
218 0 : aPropHashMap.erase( aHashIter ); // removing property from hashmap
219 : }
220 : }
221 0 : }
222 :
223 39976 : SdrCustomShapeGeometryItem::~SdrCustomShapeGeometryItem()
224 : {
225 39976 : }
226 0 : SdrCustomShapeGeometryItem::SdrCustomShapeGeometryItem( SvStream& /*rIn*/, sal_uInt16 nVersion ):
227 0 : SfxPoolItem( SDRATTR_CUSTOMSHAPE_GEOMETRY )
228 : {
229 : if ( nVersion )
230 : {
231 :
232 : }
233 0 : }
234 95866 : bool SdrCustomShapeGeometryItem::operator==( const SfxPoolItem& rCmp ) const
235 : {
236 95866 : bool bRet = SfxPoolItem::operator==( rCmp );
237 95866 : if ( bRet )
238 95866 : bRet = ((SdrCustomShapeGeometryItem&)rCmp).aPropSeq == aPropSeq;
239 95866 : return bRet;
240 : }
241 :
242 0 : SfxItemPresentation SdrCustomShapeGeometryItem::GetPresentation(
243 : SfxItemPresentation ePresentation, SfxMapUnit /*eCoreMetric*/,
244 : SfxMapUnit /*ePresentationMetric*/, OUString &rText, const IntlWrapper *) const
245 : {
246 0 : rText += " ";
247 0 : if ( ePresentation == SFX_ITEM_PRESENTATION_COMPLETE )
248 : {
249 0 : rText = " " + rText;
250 : }
251 0 : return ePresentation;
252 : }
253 :
254 0 : SfxPoolItem* SdrCustomShapeGeometryItem::Create( SvStream& rIn, sal_uInt16 nItemVersion ) const
255 : {
256 0 : return new SdrCustomShapeGeometryItem( rIn, nItemVersion );
257 : }
258 :
259 0 : SvStream& SdrCustomShapeGeometryItem::Store( SvStream& rOut, sal_uInt16 nItemVersion ) const
260 : {
261 : if ( nItemVersion )
262 : {
263 :
264 : }
265 0 : return rOut;
266 : }
267 :
268 8663 : SfxPoolItem* SdrCustomShapeGeometryItem::Clone( SfxItemPool * /*pPool*/ ) const
269 : {
270 8663 : return new SdrCustomShapeGeometryItem( GetGeometry() );
271 : }
272 :
273 0 : sal_uInt16 SdrCustomShapeGeometryItem::GetVersion( sal_uInt16 /*nFileFormatVersion*/ ) const
274 : {
275 0 : return 1;
276 : }
277 1184 : bool SdrCustomShapeGeometryItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
278 : {
279 1184 : rVal <<= aPropSeq;
280 1184 : return true;
281 : }
282 1333 : bool SdrCustomShapeGeometryItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
283 : {
284 1333 : if ( ! ( rVal >>= aPropSeq ) )
285 0 : return false;
286 : else
287 1333 : return true;
288 : }
289 8663 : const uno::Sequence< beans::PropertyValue >& SdrCustomShapeGeometryItem::GetGeometry() const
290 : {
291 8663 : return aPropSeq;
292 : }
293 :
294 2841 : SdrCustomShapeReplacementURLItem::SdrCustomShapeReplacementURLItem()
295 2841 : : SfxStringItem( SDRATTR_CUSTOMSHAPE_REPLACEMENT_URL, "" )
296 2841 : {}
297 :
298 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|