| 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 "WrappedScaleTextProperties.hxx" |
| 21 |
#include "Chart2ModelContact.hxx" |
| 22 |
#include <FastPropertyIdRanges.hxx> |
| 23 |
#include <WrappedProperty.hxx> |
| 24 |
|
| 25 |
#include <com/sun/star/beans/PropertyAttribute.hpp> |
| 26 |
#include <com/sun/star/beans/XPropertyState.hpp> |
| 27 |
#include <com/sun/star/beans/XPropertySet.hpp> |
| 28 |
#include <utility> |
| 29 |
#include <comphelper/diagnose_ex.hxx> |
| 30 |
|
| 31 |
using namespace ::com::sun::star; |
| 32 |
using ::com::sun::star::uno::Any; |
| 33 |
using ::com::sun::star::uno::Reference; |
| 34 |
using ::com::sun::star::beans::Property; |
| 35 |
|
| 36 |
namespace chart::wrapper |
| 37 |
{ |
| 38 |
|
| 39 |
namespace { |
| 40 |
|
| 41 |
class WrappedScaleTextProperty : public WrappedProperty |
| 42 |
{ |
| 43 |
public: |
| 44 |
explicit WrappedScaleTextProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact); |
| 45 |
|
| 46 |
virtual void setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const override; |
| 47 |
virtual Any getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const override; |
| 48 |
virtual Any getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const override; |
| 49 |
|
| 50 |
private: |
| 51 |
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact; |
| 52 |
}; |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
WrappedScaleTextProperty::WrappedScaleTextProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact) |
| 57 |
: ::chart::WrappedProperty( u"ScaleText"_ustr , OUString() ) |
| 58 |
, m_spChart2ModelContact(std::move( spChart2ModelContact )) |
| 59 |
{ |
| 60 |
} |
| 61 |
|
| 62 |
void WrappedScaleTextProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const |
| 63 |
{ |
| 64 |
static constexpr OUString aRefSizeName = u"ReferencePageSize"_ustr; |
| 65 |
|
| 66 |
if( !xInnerPropertySet.is() ) |
| 67 |
return; |
| 68 |
|
| 69 |
bool bNewValue = false; |
| 70 |
if( ! (rOuterValue >>= bNewValue) ) |
| 71 |
{ |
| 72 |
if( rOuterValue.hasValue() ) |
| 73 |
throw lang::IllegalArgumentException( u"Property ScaleText requires value of type boolean"_ustr, nullptr, 0 ); |
| 74 |
} |
| 75 |
|
| 76 |
try |
| 77 |
{ |
| 78 |
if( bNewValue ) |
| 79 |
{ |
| 80 |
awt::Size aRefSize( m_spChart2ModelContact->GetPageSize() ); |
| 81 |
xInnerPropertySet->setPropertyValue( aRefSizeName, uno::Any( aRefSize ) ); |
| 82 |
} |
| 83 |
else |
| 84 |
xInnerPropertySet->setPropertyValue( aRefSizeName, Any() ); |
| 85 |
} |
| 86 |
catch( const uno::Exception & ) |
| 87 |
{ |
| 88 |
DBG_UNHANDLED_EXCEPTION("chart2"); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
Any WrappedScaleTextProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const |
| 93 |
{ |
| 94 |
Any aRet( getPropertyDefault( Reference< beans::XPropertyState >( xInnerPropertySet, uno::UNO_QUERY ) ) ); |
| 95 |
if( xInnerPropertySet.is() ) |
| 96 |
{ |
| 97 |
if( xInnerPropertySet->getPropertyValue( u"ReferencePageSize"_ustr ).hasValue() ) |
| 98 |
aRet <<= true; |
| 99 |
else |
| 100 |
aRet <<= false; |
| 101 |
} |
| 102 |
|
| 103 |
return aRet; |
| 104 |
} |
| 105 |
|
| 106 |
Any WrappedScaleTextProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const |
| 107 |
{ |
| 108 |
Any aRet; |
| 109 |
aRet <<= false; |
| 110 |
return aRet; |
| 111 |
} |
| 112 |
|
| 113 |
namespace |
| 114 |
{ |
| 115 |
enum |
| 116 |
{ |
| 117 |
PROP_CHART_SCALE_TEXT = FAST_PROPERTY_ID_START_SCALE_TEXT_PROP |
| 118 |
}; |
| 119 |
|
| 120 |
}//anonymous namespace |
| 121 |
|
| 122 |
void WrappedScaleTextProperties::addProperties( std::vector< Property > & rOutProperties ) |
| 123 |
{ |
| 124 |
rOutProperties.emplace_back( "ScaleText", |
| 125 |
PROP_CHART_SCALE_TEXT, |
| 126 |
cppu::UnoType<bool>::get(), |
| 127 |
beans::PropertyAttribute::MAYBEVOID |
| 128 |
| beans::PropertyAttribute::MAYBEDEFAULT ); |
| 129 |
} |
| 130 |
|
| 131 |
void WrappedScaleTextProperties::addWrappedProperties( std::vector< std::unique_ptr<WrappedProperty> >& rList |
| 132 |
, const std::shared_ptr< Chart2ModelContact >& spChart2ModelContact ) |
| 133 |
{ |
| 134 |
rList.emplace_back( new WrappedScaleTextProperty( spChart2ModelContact ) ); |
| 135 |
} |
| 136 |
|
| 137 |
} //namespace chart::wrapper |
| 138 |
|
| 139 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |