xref: /trunk/main/chart2/source/controller/chartapiwrapper/WrappedScaleTextProperties.cxx (revision 137931e43899a1545869cb6af6ea936d8cee4956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_chartcontroller.hxx"
25 
26 #include "WrappedScaleTextProperties.hxx"
27 #include "FastPropertyIdRanges.hxx"
28 #include "macros.hxx"
29 
30 #include <com/sun/star/beans/PropertyAttribute.hpp>
31 
32 using namespace ::com::sun::star;
33 using ::com::sun::star::uno::Any;
34 using ::com::sun::star::uno::Reference;
35 using ::com::sun::star::uno::Sequence;
36 using ::com::sun::star::beans::Property;
37 using ::rtl::OUString;
38 
39 //.............................................................................
40 namespace chart
41 {
42 namespace wrapper
43 {
44 
45 class WrappedScaleTextProperty : public WrappedProperty
46 {
47 public:
48     WrappedScaleTextProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
49     virtual ~WrappedScaleTextProperty();
50 
51     virtual void setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const;
52     virtual Any getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const;
53     virtual Any getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const;
54 
55 private:
56     ::boost::shared_ptr< Chart2ModelContact >   m_spChart2ModelContact;
57 };
58 
59 WrappedScaleTextProperty::WrappedScaleTextProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
60     : ::chart::WrappedProperty( C2U( "ScaleText" ), rtl::OUString() )
61     , m_spChart2ModelContact( spChart2ModelContact )
62 {
63 }
64 
65 WrappedScaleTextProperty::~WrappedScaleTextProperty()
66 {
67 }
68 
69 void WrappedScaleTextProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
70 {
71     static const OUString aRefSizeName( RTL_CONSTASCII_USTRINGPARAM("ReferencePageSize") );
72 
73     if( xInnerPropertySet.is() )
74     {
75         bool bNewValue = false;
76         if( ! (rOuterValue >>= bNewValue) )
77         {
78             if( rOuterValue.hasValue() )
79                 throw lang::IllegalArgumentException( C2U("Property ScaleText requires value of type boolean"), 0, 0 );
80         }
81 
82         try
83         {
84             if( bNewValue )
85             {
86                 awt::Size aRefSize( m_spChart2ModelContact->GetPageSize() );
87                 xInnerPropertySet->setPropertyValue( aRefSizeName, uno::makeAny( aRefSize ) );
88             }
89             else
90                 xInnerPropertySet->setPropertyValue( aRefSizeName, Any() );
91         }
92         catch( uno::Exception & ex )
93         {
94             ASSERT_EXCEPTION( ex );
95         }
96     }
97 }
98 
99 Any WrappedScaleTextProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
100 {
101     static const OUString aRefSizeName( RTL_CONSTASCII_USTRINGPARAM("ReferencePageSize") );
102 
103     Any aRet( getPropertyDefault( Reference< beans::XPropertyState >( xInnerPropertySet, uno::UNO_QUERY ) ) );
104     if( xInnerPropertySet.is() )
105     {
106         if( xInnerPropertySet->getPropertyValue( aRefSizeName ).hasValue() )
107             aRet <<= true;
108         else
109             aRet <<= false;
110     }
111 
112     return aRet;
113 }
114 
115 Any WrappedScaleTextProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
116 {
117     Any aRet;
118     aRet <<= false;
119     return aRet;
120 }
121 
122 namespace
123 {
124 enum
125 {
126     PROP_CHART_SCALE_TEXT = FAST_PROPERTY_ID_START_SCALE_TEXT_PROP
127 };
128 
129 }//anonymous namespace
130 
131 //-----------------------------------------------------------------------------
132 //-----------------------------------------------------------------------------
133 //-----------------------------------------------------------------------------
134 void WrappedScaleTextProperties::addProperties( ::std::vector< Property > & rOutProperties )
135 {
136     rOutProperties.push_back(
137         Property( C2U( "ScaleText" ),
138                   PROP_CHART_SCALE_TEXT,
139                   ::getBooleanCppuType(),
140                   beans::PropertyAttribute::MAYBEVOID
141                   | beans::PropertyAttribute::MAYBEDEFAULT ));
142 }
143 
144 //-----------------------------------------------------------------------------
145 //-----------------------------------------------------------------------------
146 
147 void WrappedScaleTextProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList
148                                  , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
149 {
150     rList.push_back( new WrappedScaleTextProperty( spChart2ModelContact ) );
151 }
152 
153 } //namespace wrapper
154 } //namespace chart
155 //.............................................................................
156