Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / controller / itemsetwrapper / GraphicPropertyItemConverter.cxx
blobac0b961ba2e4670fb23ce2c80043e354f41fd5c4
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 .
20 #include <GraphicPropertyItemConverter.hxx>
21 #include "SchWhichPairs.hxx"
22 #include <ItemPropertyMap.hxx>
23 #include <PropertyHelper.hxx>
24 #include <CommonConverters.hxx>
25 #include <editeng/memberids.h>
26 #include <svx/unomid.hxx>
27 #include <svx/xflbmtit.hxx>
28 #include <svx/xflbstit.hxx>
29 #include <svx/xbtmpit.hxx>
30 #include <svx/xflftrit.hxx>
31 #include <svx/xlndsit.hxx>
32 #include <svx/xflhtit.hxx>
33 #include <svx/xflgrit.hxx>
34 #include <svx/xfltrit.hxx>
35 #include <svx/xlntrit.hxx>
36 #include <svx/xgrscit.hxx>
37 #include <com/sun/star/beans/XPropertyState.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/drawing/BitmapMode.hpp>
40 #include <com/sun/star/container/XNameAccess.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <utility>
43 #include <comphelper/diagnose_ex.hxx>
45 using namespace ::com::sun::star;
47 namespace chart::wrapper {
49 namespace {
51 ItemPropertyMapType & lcl_GetDataPointFilledPropertyMap()
53 static ItemPropertyMapType aDataPointPropertyFilledMap{
54 {XATTR_FILLSTYLE, {"FillStyle", 0}},
55 {XATTR_FILLCOLOR, {"Color", 0}},
56 {XATTR_LINECOLOR, {"BorderColor", 0}},
57 {XATTR_LINESTYLE, {"BorderStyle", 0}},
58 {XATTR_LINEWIDTH, {"BorderWidth", 0}},
59 {XATTR_FILLBACKGROUND, {"FillBackground", 0}},
60 {XATTR_FILLBMP_POS, {"FillBitmapRectanglePoint", 0}},
61 {XATTR_FILLBMP_SIZEX, {"FillBitmapSizeX", 0}},
62 {XATTR_FILLBMP_SIZEY, {"FillBitmapSizeY", 0}},
63 {XATTR_FILLBMP_SIZELOG, {"FillBitmapLogicalSize", 0}},
64 {XATTR_FILLBMP_TILEOFFSETX, {"FillBitmapOffsetX", 0}},
65 {XATTR_FILLBMP_TILEOFFSETY, {"FillBitmapOffsetY", 0}},
66 {XATTR_FILLBMP_POSOFFSETX, {"FillBitmapPositionOffsetX", 0}},
67 {XATTR_FILLBMP_POSOFFSETY, {"FillBitmapPositionOffsetY", 0}}};
68 return aDataPointPropertyFilledMap;
70 ItemPropertyMapType & lcl_GetDataPointLinePropertyMap()
72 static ItemPropertyMapType aDataPointPropertyLineMap{
73 {XATTR_LINECOLOR, {"Color", 0}},
74 {XATTR_LINESTYLE, {"LineStyle", 0}},
75 {XATTR_LINEWIDTH, {"LineWidth", 0}},
76 {XATTR_LINECAP, {"LineCap", 0}}};
77 return aDataPointPropertyLineMap;
79 ItemPropertyMapType & lcl_GetLinePropertyMap()
81 static ItemPropertyMapType aLinePropertyMap{
82 {XATTR_LINESTYLE, {"LineStyle", 0}},
83 {XATTR_LINEWIDTH, {"LineWidth", 0}},
84 {XATTR_LINECOLOR, {"LineColor", 0}},
85 {XATTR_LINEJOINT, {"LineJoint", 0}},
86 {XATTR_LINECAP, {"LineCap", 0}}};
87 return aLinePropertyMap;
89 ItemPropertyMapType & lcl_GetFillPropertyMap()
91 static ItemPropertyMapType aFillPropertyMap{
92 {XATTR_FILLSTYLE, {"FillStyle", 0}},
93 {XATTR_FILLCOLOR, {"FillColor", 0}},
94 {XATTR_FILLBACKGROUND, {"FillBackground", 0}},
95 {XATTR_FILLBMP_POS, {"FillBitmapRectanglePoint", 0}},
96 {XATTR_FILLBMP_SIZEX, {"FillBitmapSizeX", 0}},
97 {XATTR_FILLBMP_SIZEY, {"FillBitmapSizeY", 0}},
98 {XATTR_FILLBMP_SIZELOG, {"FillBitmapLogicalSize", 0}},
99 {XATTR_FILLBMP_TILEOFFSETX, {"FillBitmapOffsetX", 0}},
100 {XATTR_FILLBMP_TILEOFFSETY, {"FillBitmapOffsetY", 0}},
101 {XATTR_FILLBMP_POSOFFSETX, {"FillBitmapPositionOffsetX", 0}},
102 {XATTR_FILLBMP_POSOFFSETY, {"FillBitmapPositionOffsetY", 0}}};
103 return aFillPropertyMap;
106 bool lcl_supportsFillProperties( ::chart::wrapper::GraphicObjectType eType )
108 return ( eType == ::chart::wrapper::GraphicObjectType::FilledDataPoint ||
109 eType == ::chart::wrapper::GraphicObjectType::LineAndFillProperties );
112 bool lcl_SetContentForNamedProperty(
113 const uno::Reference< lang::XMultiServiceFactory > & xFactory,
114 const OUString & rTableName,
115 NameOrIndex & rItem, sal_uInt8 nMemberId )
117 bool bResult = false;
118 if( xFactory.is())
120 OUString aPropertyValue( rItem.GetName());
121 uno::Reference< container::XNameAccess > xNameAcc(
122 xFactory->createInstance( rTableName ),
123 uno::UNO_QUERY );
124 if( xNameAcc.is() &&
125 xNameAcc->hasByName( aPropertyValue ))
127 rItem.PutValue( xNameAcc->getByName( aPropertyValue ), nMemberId );
128 bResult = true;
131 return bResult;
134 } // anonymous namespace
136 GraphicPropertyItemConverter::GraphicPropertyItemConverter(
137 const uno::Reference<
138 beans::XPropertySet > & rPropertySet,
139 SfxItemPool& rItemPool,
140 SdrModel& rDrawModel,
141 uno::Reference< lang::XMultiServiceFactory > xNamedPropertyContainerFactory,
142 GraphicObjectType eObjectType /* = FILL_PROPERTIES */ ) :
143 ItemConverter( rPropertySet, rItemPool ),
144 m_GraphicObjectType( eObjectType ),
145 m_rDrawModel( rDrawModel ),
146 m_xNamedPropertyTableFactory(std::move( xNamedPropertyContainerFactory ))
149 GraphicPropertyItemConverter::~GraphicPropertyItemConverter()
152 const WhichRangesContainer& GraphicPropertyItemConverter::GetWhichPairs() const
154 switch( m_GraphicObjectType )
156 case GraphicObjectType::LineDataPoint:
157 case GraphicObjectType::FilledDataPoint:
158 return nRowWhichPairs;
159 case GraphicObjectType::LineProperties:
160 return nLinePropertyWhichPairs;
161 case GraphicObjectType::LineAndFillProperties:
162 return nLineAndFillPropertyWhichPairs;
165 static const WhichRangesContainer empty;
166 return empty;
169 bool GraphicPropertyItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
171 ItemPropertyMapType::const_iterator aEndIt;
172 ItemPropertyMapType::const_iterator aIt;
174 switch( m_GraphicObjectType )
176 case GraphicObjectType::LineDataPoint:
177 aEndIt = lcl_GetDataPointLinePropertyMap().end();
178 aIt = lcl_GetDataPointLinePropertyMap().find( nWhichId );
179 break;
180 case GraphicObjectType::FilledDataPoint:
181 aEndIt = lcl_GetDataPointFilledPropertyMap().end();
182 aIt = lcl_GetDataPointFilledPropertyMap().find( nWhichId );
183 break;
184 case GraphicObjectType::LineProperties:
185 aEndIt = lcl_GetLinePropertyMap().end();
186 aIt = lcl_GetLinePropertyMap().find( nWhichId );
187 break;
189 case GraphicObjectType::LineAndFillProperties:
190 // line
191 aEndIt = lcl_GetLinePropertyMap().end();
192 aIt = lcl_GetLinePropertyMap().find( nWhichId );
194 // not found => try fill
195 if( aIt == aEndIt )
197 aEndIt = lcl_GetFillPropertyMap().end();
198 aIt = lcl_GetFillPropertyMap().find( nWhichId );
200 break;
203 if( aIt == aEndIt )
204 return false;
206 rOutProperty =(*aIt).second;
207 return true;
210 void GraphicPropertyItemConverter::FillSpecialItem(
211 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
213 switch( nWhichId )
215 // bitmap property
216 case XATTR_FILLBMP_TILE:
217 case XATTR_FILLBMP_STRETCH:
219 drawing::BitmapMode aMode = drawing::BitmapMode_REPEAT;
220 if( GetPropertySet()->getPropertyValue( "FillBitmapMode" ) >>= aMode )
222 rOutItemSet.Put( XFillBmpTileItem( aMode == drawing::BitmapMode_REPEAT ));
223 rOutItemSet.Put( XFillBmpStretchItem( aMode == drawing::BitmapMode_STRETCH ));
226 break;
228 case XATTR_FILLFLOATTRANSPARENCE:
231 if( lcl_supportsFillProperties( m_GraphicObjectType ))
233 OUString aPropName =
234 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
235 ? OUString( "TransparencyGradientName" )
236 : OUString( "FillTransparenceGradientName" );
238 uno::Any aValue( GetPropertySet()->getPropertyValue( aPropName ));
239 if( aValue.hasValue())
241 XFillFloatTransparenceItem aItem;
242 aItem.PutValue( aValue, MID_NAME );
244 lcl_SetContentForNamedProperty(
245 m_xNamedPropertyTableFactory, "com.sun.star.drawing.TransparencyGradientTable" ,
246 aItem, MID_FILLGRADIENT );
248 // this is important to enable the item
249 OUString aName;
250 if( (aValue >>= aName) &&
251 !aName.isEmpty())
253 aItem.SetEnabled( true );
254 rOutItemSet.Put( aItem );
259 catch( const beans::UnknownPropertyException & )
261 DBG_UNHANDLED_EXCEPTION("chart2");
263 break;
265 case XATTR_GRADIENTSTEPCOUNT:
266 if( lcl_supportsFillProperties( m_GraphicObjectType ))
268 OUString aPropName =
269 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
270 ? OUString( "GradientStepCount" )
271 : OUString( "FillGradientStepCount" );
273 uno::Any aValue( GetPropertySet()->getPropertyValue( aPropName ) );
274 if( hasLongOrShortValue(aValue) )
276 sal_Int16 nStepCount = getShortForLongAlso(aValue);
277 rOutItemSet.Put( XGradientStepCountItem( nStepCount ));
280 break;
282 case XATTR_LINEDASH:
284 OUString aPropName =
285 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
286 ? OUString( "BorderDashName" )
287 : OUString( "LineDashName" );
289 XLineDashItem aItem;
290 aItem.PutValue( GetPropertySet()->getPropertyValue( aPropName ), MID_NAME );
292 lcl_SetContentForNamedProperty(
293 m_xNamedPropertyTableFactory, "com.sun.star.drawing.DashTable" ,
294 aItem, MID_LINEDASH );
296 // translate model name to UI-name for predefined entries, so
297 // that the correct entry is chosen in the list of UI-names
298 std::unique_ptr<XLineDashItem> pItemToPut = aItem.checkForUniqueItem( & m_rDrawModel );
300 if(pItemToPut)
301 rOutItemSet.Put( std::move(pItemToPut) );
302 else
303 rOutItemSet.Put(aItem);
305 break;
307 case XATTR_FILLGRADIENT:
308 if( lcl_supportsFillProperties( m_GraphicObjectType ))
310 OUString aPropName =
311 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
312 ? OUString( "GradientName" )
313 : OUString( "FillGradientName" );
315 XFillGradientItem aItem;
316 aItem.PutValue( GetPropertySet()->getPropertyValue( aPropName ), MID_NAME );
318 lcl_SetContentForNamedProperty(
319 m_xNamedPropertyTableFactory, "com.sun.star.drawing.GradientTable" ,
320 aItem, MID_FILLGRADIENT );
322 // translate model name to UI-name for predefined entries, so
323 // that the correct entry is chosen in the list of UI-names
324 std::unique_ptr<XFillGradientItem> pItemToPut = aItem.checkForUniqueItem( & m_rDrawModel );
326 if(pItemToPut)
327 rOutItemSet.Put(std::move(pItemToPut) );
328 else
329 rOutItemSet.Put(aItem);
331 break;
333 case XATTR_FILLHATCH:
334 if( lcl_supportsFillProperties( m_GraphicObjectType ))
336 OUString aPropName =
337 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
338 ? OUString( "HatchName" )
339 : OUString( "FillHatchName" );
341 XFillHatchItem aItem;
342 aItem.PutValue( GetPropertySet()->getPropertyValue( aPropName ), MID_NAME );
344 lcl_SetContentForNamedProperty(
345 m_xNamedPropertyTableFactory, "com.sun.star.drawing.HatchTable" ,
346 aItem, MID_FILLHATCH );
348 // translate model name to UI-name for predefined entries, so
349 // that the correct entry is chosen in the list of UI-names
350 std::unique_ptr<XFillHatchItem> pItemToPut = aItem.checkForUniqueItem( & m_rDrawModel );
352 if(pItemToPut)
353 rOutItemSet.Put( std::move(pItemToPut) );
354 else
355 rOutItemSet.Put(aItem);
357 break;
359 case XATTR_FILLBITMAP:
360 if( lcl_supportsFillProperties( m_GraphicObjectType ))
362 XFillBitmapItem aItem;
363 aItem.PutValue( GetPropertySet()->getPropertyValue( "FillBitmapName" ), MID_NAME );
365 lcl_SetContentForNamedProperty(
366 m_xNamedPropertyTableFactory, "com.sun.star.drawing.BitmapTable" ,
367 aItem, MID_BITMAP );
369 // translate model name to UI-name for predefined entries, so
370 // that the correct entry is chosen in the list of UI-names
371 std::unique_ptr<XFillBitmapItem> pItemToPut = aItem.checkForUniqueItem( & m_rDrawModel );
373 if(pItemToPut)
374 rOutItemSet.Put( std::move(pItemToPut) );
375 else
376 rOutItemSet.Put(aItem);
378 break;
380 // hack, because QueryValue of XLineTransparenceItem returns sal_Int32
381 // instead of sal_Int16
382 case XATTR_LINETRANSPARENCE:
384 OUString aPropName =
385 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
386 ? OUString( "BorderTransparency" )
387 : (m_GraphicObjectType == GraphicObjectType::LineDataPoint)
388 ? OUString( "Transparency" )
389 : OUString( "LineTransparence" );
391 XLineTransparenceItem aItem;
392 aItem.PutValue( GetPropertySet()->getPropertyValue( aPropName ), 0 );
394 rOutItemSet.Put( aItem );
396 break;
398 // hack, because QueryValue of XFillTransparenceItem returns sal_Int32
399 // instead of sal_Int16
400 case XATTR_FILLTRANSPARENCE:
401 if( lcl_supportsFillProperties( m_GraphicObjectType ))
403 OUString aPropName =
404 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
405 ? OUString( "Transparency" )
406 : OUString( "FillTransparence" );
408 XFillTransparenceItem aItem;
409 aItem.PutValue( GetPropertySet()->getPropertyValue( aPropName ), 0 );
411 rOutItemSet.Put( aItem );
413 break;
417 bool GraphicPropertyItemConverter::ApplySpecialItem(
418 sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
420 bool bChanged = false;
421 uno::Any aValue;
423 switch( nWhichId )
425 // bitmap property
426 case XATTR_FILLBMP_STRETCH:
427 if( lcl_supportsFillProperties( m_GraphicObjectType ))
429 static constexpr OUString aModePropName(u"FillBitmapMode"_ustr);
430 bool bStretched = rItemSet.Get( XATTR_FILLBMP_STRETCH ).GetValue();
431 drawing::BitmapMode aMode =
432 (bStretched ? drawing::BitmapMode_STRETCH : drawing::BitmapMode_NO_REPEAT);
433 drawing::BitmapMode aOtherMode = drawing::BitmapMode_NO_REPEAT;
435 aValue <<= aMode;
436 GetPropertySet()->getPropertyValue( aModePropName ) >>= aOtherMode;
438 // don't overwrite if it has been set to BitmapMode_REPEAT (= tiled) already
439 // XATTR_FILLBMP_STRETCH and XATTR_FILLBMP_TILE often come in pairs, tdf#104658
440 if( aMode != aOtherMode && aOtherMode != drawing::BitmapMode_REPEAT )
442 GetPropertySet()->setPropertyValue( aModePropName, aValue );
443 bChanged = true;
446 break;
448 case XATTR_FILLBMP_TILE:
449 if( lcl_supportsFillProperties( m_GraphicObjectType ))
451 static constexpr OUString aModePropName(u"FillBitmapMode"_ustr);
452 bool bTiled = rItemSet.Get( XATTR_FILLBMP_TILE ).GetValue();
453 drawing::BitmapMode aMode =
454 (bTiled ? drawing::BitmapMode_REPEAT : drawing::BitmapMode_NO_REPEAT);
456 aValue <<= aMode;
457 if( aValue != GetPropertySet()->getPropertyValue( aModePropName ))
459 GetPropertySet()->setPropertyValue( aModePropName, aValue );
460 bChanged = true;
463 break;
465 case XATTR_FILLFLOATTRANSPARENCE:
468 if( lcl_supportsFillProperties( m_GraphicObjectType ))
470 OUString aPropName =
471 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
472 ? OUString( "TransparencyGradientName" )
473 : OUString( "FillTransparenceGradientName" );
475 const XFillFloatTransparenceItem & rItem =
476 static_cast< const XFillFloatTransparenceItem & >(
477 rItemSet.Get( nWhichId ));
479 if( rItem.IsEnabled() &&
480 rItem.QueryValue( aValue, MID_NAME ))
482 uno::Any aGradient;
483 rItem.QueryValue( aGradient, MID_FILLGRADIENT );
485 // add TransparencyGradient to list if it does not already exist
486 OUString aPreferredName;
487 aValue >>= aPreferredName;
488 aValue <<= PropertyHelper::addTransparencyGradientUniqueNameToTable(
489 aGradient, m_xNamedPropertyTableFactory, aPreferredName );
491 if( aValue != GetPropertySet()->getPropertyValue( aPropName ))
493 GetPropertySet()->setPropertyValue( aPropName, aValue );
494 bChanged = true;
497 else
499 OUString aName;
500 if( ( GetPropertySet()->getPropertyValue( aPropName ) >>= aName )
501 && !aName.isEmpty() )
503 uno::Reference< beans::XPropertyState > xState( GetPropertySet(), uno::UNO_QUERY );
504 if( xState.is())
505 xState->setPropertyToDefault( aPropName );
506 bChanged = true;
511 catch( const beans::UnknownPropertyException & )
513 DBG_UNHANDLED_EXCEPTION("chart2");
515 break;
517 case XATTR_GRADIENTSTEPCOUNT:
519 if( lcl_supportsFillProperties( m_GraphicObjectType ))
521 OUString aPropName =
522 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
523 ? OUString( "GradientStepCount" )
524 : OUString( "FillGradientStepCount" );
526 sal_Int16 nStepCount = static_cast< const XGradientStepCountItem & >(
527 rItemSet.Get( nWhichId )).GetValue();
529 aValue <<= nStepCount;
530 if( aValue != GetPropertySet()->getPropertyValue( aPropName ))
532 GetPropertySet()->setPropertyValue( aPropName, aValue );
533 bChanged = true;
537 break;
539 case XATTR_LINEDASH:
541 OUString aPropName =
542 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
543 ? OUString( "BorderDashName" )
544 : OUString( "LineDashName" );
546 const XLineDashItem & rItem =
547 static_cast< const XLineDashItem & >(
548 rItemSet.Get( nWhichId ));
550 if( rItem.QueryValue( aValue, MID_NAME ))
552 if( aValue != GetPropertySet()->getPropertyValue( aPropName ))
554 // add LineDash to list
555 uno::Any aLineDash;
556 rItem.QueryValue( aLineDash, MID_LINEDASH );
557 OUString aPreferredName;
558 aValue >>= aPreferredName;
559 aValue <<= PropertyHelper::addLineDashUniqueNameToTable(
560 aLineDash, m_xNamedPropertyTableFactory, aPreferredName );
562 GetPropertySet()->setPropertyValue( aPropName, aValue );
563 bChanged = true;
567 break;
569 case XATTR_FILLGRADIENT:
571 if( lcl_supportsFillProperties( m_GraphicObjectType ))
573 OUString aPropName =
574 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
575 ? OUString( "GradientName" )
576 : OUString( "FillGradientName" );
578 const XFillGradientItem & rItem =
579 static_cast< const XFillGradientItem & >(
580 rItemSet.Get( nWhichId ));
582 if( rItem.QueryValue( aValue, MID_NAME ))
584 if( aValue != GetPropertySet()->getPropertyValue( aPropName ))
586 // add Gradient to list
587 uno::Any aGradient;
588 rItem.QueryValue( aGradient, MID_FILLGRADIENT );
589 OUString aPreferredName;
590 aValue >>= aPreferredName;
591 aValue <<= PropertyHelper::addGradientUniqueNameToTable(
592 aGradient, m_xNamedPropertyTableFactory, aPreferredName );
594 GetPropertySet()->setPropertyValue( aPropName, aValue );
595 bChanged = true;
600 break;
602 case XATTR_FILLHATCH:
604 if( lcl_supportsFillProperties( m_GraphicObjectType ))
606 OUString aPropName =
607 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
608 ? OUString( "HatchName" )
609 : OUString( "FillHatchName" );
611 const XFillHatchItem & rItem =
612 static_cast< const XFillHatchItem & >(
613 rItemSet.Get( nWhichId ));
615 if( rItem.QueryValue( aValue, MID_NAME ))
617 if( aValue != GetPropertySet()->getPropertyValue( aPropName ))
619 // add Hatch to list
620 uno::Any aHatch;
621 rItem.QueryValue( aHatch, MID_FILLHATCH );
622 OUString aPreferredName;
623 aValue >>= aPreferredName;
624 aValue <<= PropertyHelper::addHatchUniqueNameToTable(
625 aHatch, m_xNamedPropertyTableFactory, aPreferredName );
627 GetPropertySet()->setPropertyValue( aPropName, aValue );
628 bChanged = true;
633 break;
635 case XATTR_FILLBITMAP:
637 if( lcl_supportsFillProperties( m_GraphicObjectType ))
639 const XFillBitmapItem & rItem =
640 static_cast< const XFillBitmapItem & >(
641 rItemSet.Get( nWhichId ));
643 if( rItem.QueryValue( aValue, MID_NAME ))
645 if( aValue != GetPropertySet()->getPropertyValue( "FillBitmapName" ))
647 // add Bitmap to list
648 uno::Any aBitmap;
649 rItem.QueryValue(aBitmap, MID_BITMAP);
650 OUString aPreferredName;
651 aValue >>= aPreferredName;
652 aValue <<= PropertyHelper::addBitmapUniqueNameToTable(
653 aBitmap, m_xNamedPropertyTableFactory, aPreferredName );
655 GetPropertySet()->setPropertyValue( "FillBitmapName" , aValue );
656 bChanged = true;
661 break;
663 // hack, because QueryValue of XLineTransparenceItem returns sal_Int32
664 // instead of sal_Int16
665 case XATTR_LINETRANSPARENCE:
667 OUString aPropName =
668 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
669 ? OUString( "BorderTransparency" )
670 : (m_GraphicObjectType == GraphicObjectType::LineDataPoint)
671 ? OUString( "Transparency" )
672 : OUString( "LineTransparence" );
674 const XLineTransparenceItem & rItem =
675 static_cast< const XLineTransparenceItem & >(
676 rItemSet.Get( nWhichId ));
678 if( rItem.QueryValue( aValue ))
680 OSL_ENSURE( ! aValue.isExtractableTo(
681 cppu::UnoType<sal_Int16>::get()),
682 "TransparenceItem QueryValue bug is fixed. Remove hack." );
683 sal_Int32 nValue = 0;
684 if( aValue >>= nValue )
686 OSL_ENSURE( nValue < SAL_MAX_INT16, "Transparency value too large" );
687 sal_Int16 nValueToSet( static_cast< sal_Int16 >( nValue ));
688 aValue <<= nValueToSet;
690 GetPropertySet()->setPropertyValue( aPropName, aValue );
691 bChanged = true;
693 else
695 OSL_FAIL( "Wrong type in Transparency Any" );
699 break;
701 // hack, because QueryValue of XFillTransparenceItem returns sal_Int32
702 // instead of sal_Int16
703 case XATTR_FILLTRANSPARENCE:
704 if( lcl_supportsFillProperties( m_GraphicObjectType ))
706 OUString aPropName =
707 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
708 ? OUString( "Transparency" )
709 : OUString( "FillTransparence" );
711 const XFillTransparenceItem & rItem =
712 static_cast< const XFillTransparenceItem & >(
713 rItemSet.Get( nWhichId ));
715 if( rItem.QueryValue( aValue ))
717 OSL_ENSURE( ! aValue.isExtractableTo(
718 cppu::UnoType<sal_Int16>::get()),
719 "TransparenceItem QueryValue bug is fixed. Remove hack." );
720 sal_Int32 nValue = 0;
721 if( aValue >>= nValue )
723 OSL_ENSURE( nValue < SAL_MAX_INT16, "Transparency value too large" );
724 sal_Int16 nValueToSet( static_cast< sal_Int16 >( nValue ));
725 aValue <<= nValueToSet;
727 GetPropertySet()->setPropertyValue( aPropName, aValue );
728 // if linear or no transparence is set, delete the gradient
729 OUString aTransGradPropName =
730 (m_GraphicObjectType == GraphicObjectType::FilledDataPoint)
731 ? OUString( "TransparencyGradientName" )
732 : OUString( "FillTransparenceGradientName" );
733 GetPropertySet()->setPropertyValue(
734 aTransGradPropName, uno::Any( OUString() ));
736 bChanged = true;
738 else
740 OSL_FAIL( "Wrong type in Transparency Any" );
744 break;
747 return bChanged;
750 } // namespace chart
752 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */