/src/libreoffice/chart2/source/controller/chartapiwrapper/WrappedAutomaticPositionProperties.cxx
Line | Count | Source |
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 "WrappedAutomaticPositionProperties.hxx" |
21 | | #include <FastPropertyIdRanges.hxx> |
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> |
26 | | #include <comphelper/diagnose_ex.hxx> |
27 | | |
28 | | using namespace ::com::sun::star; |
29 | | using ::com::sun::star::uno::Any; |
30 | | using ::com::sun::star::uno::Reference; |
31 | | using ::com::sun::star::beans::Property; |
32 | | |
33 | | namespace chart::wrapper |
34 | | { |
35 | | |
36 | | namespace { |
37 | | |
38 | | class WrappedAutomaticPositionProperty : public WrappedProperty |
39 | | { |
40 | | public: |
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 | | |
50 | | WrappedAutomaticPositionProperty::WrappedAutomaticPositionProperty() |
51 | 0 | : ::chart::WrappedProperty( u"AutomaticPosition"_ustr , OUString() ) |
52 | 0 | { |
53 | 0 | } |
54 | | |
55 | | void WrappedAutomaticPositionProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const |
56 | 0 | { |
57 | 0 | if( !xInnerPropertySet.is() ) |
58 | 0 | return; |
59 | | |
60 | 0 | bool bNewValue = true; |
61 | 0 | if( ! (rOuterValue >>= bNewValue) ) |
62 | 0 | throw lang::IllegalArgumentException( u"Property AutomaticPosition requires value of type boolean"_ustr, nullptr, 0 ); |
63 | | |
64 | 0 | try |
65 | 0 | { |
66 | 0 | if( bNewValue ) |
67 | 0 | { |
68 | 0 | Any aRelativePosition( xInnerPropertySet->getPropertyValue( u"RelativePosition"_ustr ) ); |
69 | 0 | if( aRelativePosition.hasValue() ) |
70 | 0 | xInnerPropertySet->setPropertyValue( u"RelativePosition"_ustr, Any() ); |
71 | 0 | } |
72 | 0 | } |
73 | 0 | catch( const uno::Exception & ) |
74 | 0 | { |
75 | 0 | DBG_UNHANDLED_EXCEPTION("chart2"); |
76 | 0 | } |
77 | 0 | } |
78 | | |
79 | | Any WrappedAutomaticPositionProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const |
80 | 0 | { |
81 | 0 | Any aRet( getPropertyDefault( Reference< beans::XPropertyState >( xInnerPropertySet, uno::UNO_QUERY ) ) ); |
82 | 0 | if( xInnerPropertySet.is() ) |
83 | 0 | { |
84 | 0 | Any aRelativePosition( xInnerPropertySet->getPropertyValue( u"RelativePosition"_ustr ) ); |
85 | 0 | if( !aRelativePosition.hasValue() ) |
86 | 0 | aRet <<= true; |
87 | 0 | } |
88 | 0 | return aRet; |
89 | 0 | } |
90 | | |
91 | | Any WrappedAutomaticPositionProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const |
92 | 0 | { |
93 | 0 | Any aRet; |
94 | 0 | aRet <<= false; |
95 | 0 | return aRet; |
96 | 0 | } |
97 | | |
98 | | namespace |
99 | | { |
100 | | enum |
101 | | { |
102 | | PROP_CHART_AUTOMATIC_POSITION = FAST_PROPERTY_ID_START_CHART_AUTOPOSITION_PROP |
103 | | }; |
104 | | |
105 | | }//anonymous namespace |
106 | | |
107 | | void WrappedAutomaticPositionProperties::addProperties( std::vector< Property > & rOutProperties ) |
108 | 0 | { |
109 | 0 | rOutProperties.emplace_back( "AutomaticPosition", |
110 | 0 | PROP_CHART_AUTOMATIC_POSITION, |
111 | 0 | cppu::UnoType<bool>::get(), |
112 | 0 | beans::PropertyAttribute::BOUND |
113 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
114 | 0 | } |
115 | | |
116 | | void WrappedAutomaticPositionProperties::addWrappedProperties( std::vector< std::unique_ptr<WrappedProperty> >& rList ) |
117 | 0 | { |
118 | 0 | rList.emplace_back( new WrappedAutomaticPositionProperty() ); |
119 | 0 | } |
120 | | |
121 | | } //namespace chart::wrapper |
122 | | |
123 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |