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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26
27 #include "AreaWrapper.hxx"
28 #include "macros.hxx"
29 #include "ContainerHelper.hxx"
30 #include "Chart2ModelContact.hxx"
31 #include "WrappedDirectStateProperty.hxx"
32 #include <comphelper/InlineContainer.hxx>
33 #include <com/sun/star/drawing/FillStyle.hpp>
34
35 #include "LineProperties.hxx"
36 #include "FillProperties.hxx"
37 #include "UserDefinedProperties.hxx"
38
39 #include <algorithm>
40
41 using namespace ::com::sun::star;
42 using ::com::sun::star::beans::Property;
43 using ::osl::MutexGuard;
44 using ::com::sun::star::uno::Any;
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::uno::Sequence;
47
48 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
50
51 namespace
52 {
53 static const ::rtl::OUString lcl_aServiceName(
54 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.Area" ));
55
56 struct StaticAreaWrapperPropertyArray_Initializer
57 {
operator ()__anon8d71de8b0111::StaticAreaWrapperPropertyArray_Initializer58 Sequence< Property >* operator()()
59 {
60 static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
61 return &aPropSeq;
62 }
63
64 private:
lcl_GetPropertySequence__anon8d71de8b0111::StaticAreaWrapperPropertyArray_Initializer65 Sequence< Property > lcl_GetPropertySequence()
66 {
67 ::std::vector< ::com::sun::star::beans::Property > aProperties;
68 ::chart::LineProperties::AddPropertiesToVector( aProperties );
69 ::chart::FillProperties::AddPropertiesToVector( aProperties );
70 //::chart::NamedProperties::AddPropertiesToVector( aProperties );
71 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
72
73 ::std::sort( aProperties.begin(), aProperties.end(),
74 ::chart::PropertyNameLess() );
75
76 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
77 }
78 };
79
80 struct StaticAreaWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticAreaWrapperPropertyArray_Initializer >
81 {
82 };
83
84
85 } // anonymous namespace
86
87 // --------------------------------------------------------------------------------
88 // --------------------------------------------------------------------------------
89
90 namespace chart
91 {
92 namespace wrapper
93 {
94
AreaWrapper(::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)95 AreaWrapper::AreaWrapper( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) :
96 m_spChart2ModelContact( spChart2ModelContact ),
97 m_aEventListenerContainer( m_aMutex )
98 {
99 }
100
~AreaWrapper()101 AreaWrapper::~AreaWrapper()
102 {}
103
104 // ____ XShape ____
getPosition()105 awt::Point SAL_CALL AreaWrapper::getPosition()
106 throw (uno::RuntimeException)
107 {
108 return awt::Point(0,0);
109 }
110
setPosition(const awt::Point &)111 void SAL_CALL AreaWrapper::setPosition( const awt::Point& /*aPosition*/ )
112 throw (uno::RuntimeException)
113 {
114 OSL_ENSURE( false, "trying to set position of chart area" );
115 }
116
getSize()117 awt::Size SAL_CALL AreaWrapper::getSize()
118 throw (uno::RuntimeException)
119 {
120 return m_spChart2ModelContact->GetPageSize();
121 }
122
setSize(const awt::Size &)123 void SAL_CALL AreaWrapper::setSize( const awt::Size& /*aSize*/ )
124 throw (beans::PropertyVetoException,
125 uno::RuntimeException)
126 {
127 OSL_ENSURE( false, "trying to set size of chart area" );
128 }
129
130 // ____ XShapeDescriptor (base of XShape) ____
getShapeType()131 ::rtl::OUString SAL_CALL AreaWrapper::getShapeType()
132 throw (uno::RuntimeException)
133 {
134 return C2U( "com.sun.star.chart.ChartArea" );
135 }
136
137 // ____ XComponent ____
dispose()138 void SAL_CALL AreaWrapper::dispose()
139 throw (uno::RuntimeException)
140 {
141 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
142 m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
143
144 // /--
145 MutexGuard aGuard( GetMutex());
146 clearWrappedPropertySet();
147 // \--
148 }
149
addEventListener(const Reference<lang::XEventListener> & xListener)150 void SAL_CALL AreaWrapper::addEventListener(
151 const Reference< lang::XEventListener >& xListener )
152 throw (uno::RuntimeException)
153 {
154 m_aEventListenerContainer.addInterface( xListener );
155 }
156
removeEventListener(const Reference<lang::XEventListener> & aListener)157 void SAL_CALL AreaWrapper::removeEventListener(
158 const Reference< lang::XEventListener >& aListener )
159 throw (uno::RuntimeException)
160 {
161 m_aEventListenerContainer.removeInterface( aListener );
162 }
163
164 // ================================================================================
165
166 // WrappedPropertySet
getInnerPropertySet()167 Reference< beans::XPropertySet > AreaWrapper::getInnerPropertySet()
168 {
169 Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
170 if( xChartDoc.is() )
171 return xChartDoc->getPageBackground();
172 OSL_ENSURE(false,"AreaWrapper::getInnerPropertySet() is NULL");
173 return 0;
174 }
175
getPropertySequence()176 const Sequence< beans::Property >& AreaWrapper::getPropertySequence()
177 {
178 return *StaticAreaWrapperPropertyArray::get();
179 }
180
createWrappedProperties()181 const std::vector< WrappedProperty* > AreaWrapper::createWrappedProperties()
182 {
183 ::std::vector< ::chart::WrappedProperty* > aWrappedProperties;
184
185 aWrappedProperties.push_back( new WrappedDirectStateProperty( C2U("LineStyle"), C2U("LineStyle") ) );
186
187 return aWrappedProperties;
188 }
189
190 // ================================================================================
191
getSupportedServiceNames_Static()192 Sequence< ::rtl::OUString > AreaWrapper::getSupportedServiceNames_Static()
193 {
194 Sequence< ::rtl::OUString > aServices( 4 );
195 aServices[ 0 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" );
196 aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
197 aServices[ 2 ] = C2U( "com.sun.star.drawing.FillProperties" );
198 aServices[ 3 ] = C2U( "com.sun.star.drawing.LineProperties" );
199
200 return aServices;
201 }
202
203 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
204 APPHELPER_XSERVICEINFO_IMPL( AreaWrapper, lcl_aServiceName );
205
206 } // namespace wrapper
207 } // namespace chart
208