24#include <com/sun/star/beans/PropertyAttribute.hpp>
25#include <com/sun/star/chart/ChartLegendPosition.hpp>
26#include <com/sun/star/chart2/LegendPosition.hpp>
27#include <com/sun/star/chart/ChartLegendExpansion.hpp>
28#include <com/sun/star/chart2/RelativePosition.hpp>
44using ::com::sun::star::beans::Property;
45using ::com::sun::star::uno::Any;
46using ::com::sun::star::uno::Reference;
47using ::com::sun::star::uno::Sequence;
53class WrappedLegendAlignmentProperty :
public WrappedProperty
56 WrappedLegendAlignmentProperty();
58 virtual void setPropertyValue(
const Any& rOuterValue,
const Reference< beans::XPropertySet >& xInnerPropertySet )
const override;
59 virtual Any getPropertyValue(
const Reference< beans::XPropertySet >& xInnerPropertySet )
const override;
62 virtual Any convertInnerToOuterValue(
const Any& rInnerValue )
const override;
63 virtual Any convertOuterToInnerValue(
const Any& rOuterValue )
const override;
68WrappedLegendAlignmentProperty::WrappedLegendAlignmentProperty()
69 : ::
chart::WrappedProperty(
"Alignment",
"AnchorPosition" )
73Any WrappedLegendAlignmentProperty::getPropertyValue(
const Reference< beans::XPropertySet >& xInnerPropertySet )
const
76 if( xInnerPropertySet.is() )
78 bool bShowLegend =
true;
79 xInnerPropertySet->getPropertyValue(
"Show" ) >>= bShowLegend;
82 aRet <<= css::chart::ChartLegendPosition_NONE;
86 aRet = xInnerPropertySet->getPropertyValue( m_aInnerName );
87 aRet = convertInnerToOuterValue( aRet );
95 if(!xInnerPropertySet.is())
98 bool bNewShowLegend =
true;
99 bool bOldShowLegend =
true;
101 css::chart::ChartLegendPosition eOuterPos(css::chart::ChartLegendPosition_NONE);
102 if( (rOuterValue >>= eOuterPos) && eOuterPos == css::chart::ChartLegendPosition_NONE )
103 bNewShowLegend =
false;
104 xInnerPropertySet->getPropertyValue(
"Show" ) >>= bOldShowLegend;
106 if(bNewShowLegend!=bOldShowLegend)
108 xInnerPropertySet->setPropertyValue(
"Show",
uno::Any(bNewShowLegend) );
114 Any aInnerValue = convertOuterToInnerValue( rOuterValue );
115 xInnerPropertySet->setPropertyValue( m_aInnerName, aInnerValue );
118 chart2::LegendPosition eNewInnerPos(chart2::LegendPosition_LINE_END);
119 if( aInnerValue >>= eNewInnerPos )
121 css::chart::ChartLegendExpansion eNewExpansion =
122 ( eNewInnerPos == chart2::LegendPosition_LINE_END ||
123 eNewInnerPos == chart2::LegendPosition_LINE_START )
124 ? css::chart::ChartLegendExpansion_HIGH
125 : css::chart::ChartLegendExpansion_WIDE;
127 css::chart::ChartLegendExpansion eOldExpansion( css::chart::ChartLegendExpansion_HIGH );
128 bool bExpansionWasSet(
129 xInnerPropertySet->getPropertyValue(
"Expansion" ) >>= eOldExpansion );
131 if( !bExpansionWasSet || (eOldExpansion != eNewExpansion))
132 xInnerPropertySet->setPropertyValue(
"Expansion",
uno::Any( eNewExpansion ));
136 Any aRelativePosition( xInnerPropertySet->getPropertyValue(
"RelativePosition") );
137 if(aRelativePosition.hasValue())
139 xInnerPropertySet->setPropertyValue(
"RelativePosition",
Any() );
143Any WrappedLegendAlignmentProperty::convertInnerToOuterValue(
const Any& rInnerValue )
const
145 css::chart::ChartLegendPosition
ePos = css::chart::ChartLegendPosition_NONE;
147 chart2::LegendPosition eNewPos;
148 if( rInnerValue >>= eNewPos )
152 case chart2::LegendPosition_LINE_START:
153 ePos = css::chart::ChartLegendPosition_LEFT;
155 case chart2::LegendPosition_LINE_END:
156 ePos = css::chart::ChartLegendPosition_RIGHT;
158 case chart2::LegendPosition_PAGE_START:
159 ePos = css::chart::ChartLegendPosition_TOP;
161 case chart2::LegendPosition_PAGE_END:
162 ePos = css::chart::ChartLegendPosition_BOTTOM;
166 ePos = css::chart::ChartLegendPosition_NONE;
172Any WrappedLegendAlignmentProperty::convertOuterToInnerValue(
const Any& rOuterValue )
const
174 chart2::LegendPosition eNewPos = chart2::LegendPosition_LINE_END;
176 css::chart::ChartLegendPosition
ePos;
177 if( rOuterValue >>=
ePos )
181 case css::chart::ChartLegendPosition_LEFT:
182 eNewPos = chart2::LegendPosition_LINE_START;
184 case css::chart::ChartLegendPosition_RIGHT:
185 eNewPos = chart2::LegendPosition_LINE_END;
187 case css::chart::ChartLegendPosition_TOP:
188 eNewPos = chart2::LegendPosition_PAGE_START;
190 case css::chart::ChartLegendPosition_BOTTOM:
191 eNewPos = chart2::LegendPosition_PAGE_END;
207 PROP_LEGEND_ALIGNMENT,
208 PROP_LEGEND_EXPANSION
211void lcl_AddPropertiesToVector(
212 std::vector< Property > & rOutProperties )
214 rOutProperties.emplace_back(
"Alignment",
215 PROP_LEGEND_ALIGNMENT,
218 beans::PropertyAttribute::MAYBEDEFAULT );
220 rOutProperties.emplace_back(
"Expansion",
221 PROP_LEGEND_EXPANSION,
224 beans::PropertyAttribute::MAYBEDEFAULT );
227const Sequence< Property >& StaticLegendWrapperPropertyArray()
229 static Sequence< Property > aPropSeq = []()
232 lcl_AddPropertiesToVector( aProperties );
275 chart2::RelativePosition aRelativePosition;
276 aRelativePosition.Anchor = drawing::Alignment_TOP_LEFT;
277 aRelativePosition.Primary = aPageSize.Width == 0 ? 0 : double(aPosition.X)/double(aPageSize.Width);
278 aRelativePosition.Secondary = aPageSize.Height == 0 ? 0 : double(aPosition.Y)/double(aPageSize.Height);
279 xProp->setPropertyValue(
"RelativePosition",
uno::Any(aRelativePosition) );
294 awt::Rectangle aPageRectangle( 0,0,aPageSize.Width,aPageSize.Height);
297 awt::Rectangle aNewPositionAndSize(aPos.X,aPos.Y,aSize.Width,aSize.Height);
300 , xProp, aNewPositionAndSize, awt::Rectangle(), aPageRectangle );
307 return "com.sun.star.chart.ChartLegend";
317 clearWrappedPropertySet();
340 if( xProp->getPropertyValue(
"ReferencePageSize" ).hasValue() )
341 xProp->setPropertyValue(
"ReferencePageSize",
uno::Any(
350 aRet = xProp->getPropertyValue(
"ReferencePageSize" );
365 xRet.set( xDiagram->getLegend(), uno::UNO_QUERY );
366 OSL_ENSURE(xRet.is(),
"LegendWrapper::getInnerPropertySet() is NULL");
372 return StaticLegendWrapperPropertyArray();
377 std::vector< std::unique_ptr<WrappedProperty> > aWrappedProperties;
379 aWrappedProperties.emplace_back(
new WrappedLegendAlignmentProperty() );
380 aWrappedProperties.emplace_back(
new WrappedProperty(
"Expansion",
"Expansion"));
388 return aWrappedProperties;
393 return "com.sun.star.comp.chart.Legend";
404 "com.sun.star.chart.ChartLegend",
405 "com.sun.star.drawing.Shape",
406 "com.sun.star.xml.UserDefinedAttributesSupplier",
407 "com.sun.star.style.CharacterProperties"
css::chart::ChartAxisLabelPosition ePos
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact
PropertiesInfo aProperties
static bool moveObject(ObjectType eObjectType, const css::uno::Reference< css::beans::XPropertySet > &xObjectProp, const css::awt::Rectangle &rNewPositionAndSize, const css::awt::Rectangle &rOldPositionAndSize, const css::awt::Rectangle &rPageRectangle)
virtual void updateReferenceSize() override
virtual css::awt::Point SAL_CALL getPosition() override
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
virtual const css::uno::Sequence< css::beans::Property > & getPropertySequence() override
virtual void SAL_CALL setSize(const css::awt::Size &aSize) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual ~LegendWrapper() override
virtual void SAL_CALL dispose() override
virtual std::vector< std::unique_ptr< WrappedProperty > > createWrappedProperties() override
virtual OUString SAL_CALL getShapeType() override
virtual void SAL_CALL setPosition(const css::awt::Point &aPosition) override
virtual css::uno::Any getReferenceSize() override
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual css::uno::Reference< css::beans::XPropertySet > getInnerPropertySet() override
LegendWrapper(std::shared_ptr< Chart2ModelContact > spChart2ModelContact)
virtual css::awt::Size SAL_CALL getSize() override
::comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > m_aEventListenerContainer
virtual css::awt::Size getCurrentSizeForReference() override
static void addWrappedProperties(std::vector< std::unique_ptr< WrappedProperty > > &rList)
static void addProperties(std::vector< css::beans::Property > &rOutProperties)
static void addWrappedProperties(std::vector< std::unique_ptr< WrappedProperty > > &rList, ReferenceSizePropertyProvider *pRefSizePropProvider)
static void addProperties(std::vector< css::beans::Property > &rOutProperties)
static void addWrappedProperties(std::vector< std::unique_ptr< WrappedProperty > > &rList, const std::shared_ptr< Chart2ModelContact > &spChart2ModelContact)
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
OOO_DLLPUBLIC_CHARTTOOLS void AddPropertiesToVector(std::vector< css::beans::Property > &rOutProperties)
void setPropertyValue(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Set a property to a certain value in the given map.
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)