LibreOffice Module chart2 (master) 1
WrappedAutomaticPositionProperties.cxx
Go to the documentation of this file.
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
22#include <WrappedProperty.hxx>
23#include <com/sun/star/beans/PropertyAttribute.hpp>
24#include <com/sun/star/beans/XPropertyState.hpp>
25#include <com/sun/star/beans/XPropertySet.hpp>
27
28using namespace ::com::sun::star;
29using ::com::sun::star::uno::Any;
30using ::com::sun::star::uno::Reference;
31using ::com::sun::star::beans::Property;
32
33namespace chart::wrapper
34{
35
36namespace {
37
38class WrappedAutomaticPositionProperty : public WrappedProperty
39{
40public:
41 WrappedAutomaticPositionProperty();
42
43 virtual void setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const override;
44 virtual Any getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const override;
45 virtual Any getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const override;
46};
47
48}
49
50WrappedAutomaticPositionProperty::WrappedAutomaticPositionProperty()
51 : ::chart::WrappedProperty( "AutomaticPosition" , OUString() )
52{
53}
54
55void WrappedAutomaticPositionProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
56{
57 if( !xInnerPropertySet.is() )
58 return;
59
60 bool bNewValue = true;
61 if( ! (rOuterValue >>= bNewValue) )
62 throw lang::IllegalArgumentException( "Property AutomaticPosition requires value of type boolean", nullptr, 0 );
63
64 try
65 {
66 if( bNewValue )
67 {
68 Any aRelativePosition( xInnerPropertySet->getPropertyValue( "RelativePosition" ) );
69 if( aRelativePosition.hasValue() )
70 xInnerPropertySet->setPropertyValue( "RelativePosition", Any() );
71 }
72 }
73 catch( const uno::Exception & )
74 {
76 }
77}
78
79Any WrappedAutomaticPositionProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
80{
81 Any aRet( getPropertyDefault( Reference< beans::XPropertyState >( xInnerPropertySet, uno::UNO_QUERY ) ) );
82 if( xInnerPropertySet.is() )
83 {
84 Any aRelativePosition( xInnerPropertySet->getPropertyValue( "RelativePosition" ) );
85 if( !aRelativePosition.hasValue() )
86 aRet <<= true;
87 }
88 return aRet;
89}
90
91Any WrappedAutomaticPositionProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
92{
93 Any aRet;
94 aRet <<= false;
95 return aRet;
96}
97
98namespace
99{
100enum
101{
102 PROP_CHART_AUTOMATIC_POSITION = FAST_PROPERTY_ID_START_CHART_AUTOPOSITION_PROP
103};
104
105}//anonymous namespace
106
107void WrappedAutomaticPositionProperties::addProperties( std::vector< Property > & rOutProperties )
108{
109 rOutProperties.emplace_back( "AutomaticPosition",
110 PROP_CHART_AUTOMATIC_POSITION,
112 beans::PropertyAttribute::BOUND
113 | beans::PropertyAttribute::MAYBEDEFAULT );
114}
115
116void WrappedAutomaticPositionProperties::addWrappedProperties( std::vector< std::unique_ptr<WrappedProperty> >& rList )
117{
118 rList.emplace_back( new WrappedAutomaticPositionProperty() );
119}
120
121} //namespace chart::wrapper
122
123/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define DBG_UNHANDLED_EXCEPTION(...)
void setPropertyValue(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Set a property to a certain value in the given map.
@ FAST_PROPERTY_ID_START_CHART_AUTOPOSITION_PROP
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)