1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "precompiled_chart2.hxx"
29 
30 #include "WrappedScaleTextProperties.hxx"
31 #include "FastPropertyIdRanges.hxx"
32 #include "macros.hxx"
33 
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 
36 using namespace ::com::sun::star;
37 using ::com::sun::star::uno::Any;
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::Sequence;
40 using ::com::sun::star::beans::Property;
41 using ::rtl::OUString;
42 
43 //.............................................................................
44 namespace chart
45 {
46 namespace wrapper
47 {
48 
49 class WrappedScaleTextProperty : public WrappedProperty
50 {
51 public:
52     WrappedScaleTextProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
53     virtual ~WrappedScaleTextProperty();
54 
55     virtual void setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
56                                     throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException);
57     virtual Any getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
58                                     throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException);
59     virtual Any getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
60                                     throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException);
61 
62 private:
63     ::boost::shared_ptr< Chart2ModelContact >   m_spChart2ModelContact;
64 };
65 
66 WrappedScaleTextProperty::WrappedScaleTextProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
67     : ::chart::WrappedProperty( C2U( "ScaleText" ), rtl::OUString() )
68     , m_spChart2ModelContact( spChart2ModelContact )
69 {
70 }
71 
72 WrappedScaleTextProperty::~WrappedScaleTextProperty()
73 {
74 }
75 
76 void WrappedScaleTextProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
77                 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
78 {
79     static const OUString aRefSizeName( RTL_CONSTASCII_USTRINGPARAM("ReferencePageSize") );
80 
81     if( xInnerPropertySet.is() )
82     {
83         bool bNewValue = false;
84         if( ! (rOuterValue >>= bNewValue) )
85         {
86             if( rOuterValue.hasValue() )
87                 throw lang::IllegalArgumentException( C2U("Property ScaleText requires value of type boolean"), 0, 0 );
88         }
89 
90         try
91         {
92             if( bNewValue )
93             {
94                 awt::Size aRefSize( m_spChart2ModelContact->GetPageSize() );
95 				xInnerPropertySet->setPropertyValue( aRefSizeName, uno::makeAny( aRefSize ) );
96             }
97             else
98                 xInnerPropertySet->setPropertyValue( aRefSizeName, Any() );
99         }
100         catch( uno::Exception & ex )
101         {
102             ASSERT_EXCEPTION( ex );
103         }
104     }
105 }
106 
107 Any WrappedScaleTextProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
108                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
109 {
110     static const OUString aRefSizeName( RTL_CONSTASCII_USTRINGPARAM("ReferencePageSize") );
111 
112     Any aRet( getPropertyDefault( Reference< beans::XPropertyState >( xInnerPropertySet, uno::UNO_QUERY ) ) );
113     if( xInnerPropertySet.is() )
114     {
115         if( xInnerPropertySet->getPropertyValue( aRefSizeName ).hasValue() )
116             aRet <<= true;
117         else
118             aRet <<= false;
119     }
120 
121     return aRet;
122 }
123 
124 Any WrappedScaleTextProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
125                         throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
126 {
127     Any aRet;
128     aRet <<= false;
129     return aRet;
130 }
131 
132 namespace
133 {
134 enum
135 {
136     PROP_CHART_SCALE_TEXT = FAST_PROPERTY_ID_START_SCALE_TEXT_PROP
137 };
138 
139 }//anonymous namespace
140 
141 //-----------------------------------------------------------------------------
142 //-----------------------------------------------------------------------------
143 //-----------------------------------------------------------------------------
144 void WrappedScaleTextProperties::addProperties( ::std::vector< Property > & rOutProperties )
145 {
146     rOutProperties.push_back(
147         Property( C2U( "ScaleText" ),
148                   PROP_CHART_SCALE_TEXT,
149                   ::getBooleanCppuType(),
150                   beans::PropertyAttribute::MAYBEVOID
151                   | beans::PropertyAttribute::MAYBEDEFAULT ));
152 }
153 
154 //-----------------------------------------------------------------------------
155 //-----------------------------------------------------------------------------
156 
157 void WrappedScaleTextProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
158                                  , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
159 {
160     rList.push_back( new WrappedScaleTextProperty( spChart2ModelContact ) );
161 }
162 
163 } //namespace wrapper
164 } //namespace chart
165 //.............................................................................
166