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