xref: /trunk/main/chart2/source/controller/chartapiwrapper/WallFloorWrapper.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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_chartcontroller.hxx"
26 
27 #include "WallFloorWrapper.hxx"
28 #include "macros.hxx"
29 #include "Chart2ModelContact.hxx"
30 #include "ContainerHelper.hxx"
31 #include <com/sun/star/beans/PropertyAttribute.hpp>
32 #include <com/sun/star/drawing/FillStyle.hpp>
33 
34 #include "FillProperties.hxx"
35 #include "LineProperties.hxx"
36 #include "UserDefinedProperties.hxx"
37 #include "WrappedDirectStateProperty.hxx"
38 
39 #include <algorithm>
40 #include <rtl/ustrbuf.hxx>
41 #include <rtl/math.hxx>
42 
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::chart2;
45 
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 using ::rtl::OUString;
52 
53 namespace
54 {
55 static const OUString lcl_aServiceName(
56     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.WallOrFloor" ));
57 
58 struct StaticWallFloorWrapperPropertyArray_Initializer
59 {
operator ()__anon9cde1fcc0111::StaticWallFloorWrapperPropertyArray_Initializer60     Sequence< Property >* operator()()
61     {
62         static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
63         return &aPropSeq;
64     }
65 
66 private:
lcl_GetPropertySequence__anon9cde1fcc0111::StaticWallFloorWrapperPropertyArray_Initializer67     Sequence< Property > lcl_GetPropertySequence()
68     {
69         ::std::vector< ::com::sun::star::beans::Property > aProperties;
70         ::chart::FillProperties::AddPropertiesToVector( aProperties );
71         ::chart::LineProperties::AddPropertiesToVector( aProperties );
72         //::chart::NamedProperties::AddPropertiesToVector( aProperties );
73         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
74 
75         ::std::sort( aProperties.begin(), aProperties.end(),
76                      ::chart::PropertyNameLess() );
77 
78         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
79     }
80 };
81 
82 struct StaticWallFloorWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticWallFloorWrapperPropertyArray_Initializer >
83 {
84 };
85 
86 } // anonymous namespace
87 
88 // --------------------------------------------------------------------------------
89 
90 namespace chart
91 {
92 namespace wrapper
93 {
94 
WallFloorWrapper(bool bWall,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)95 WallFloorWrapper::WallFloorWrapper( bool bWall,
96     ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) :
97         m_spChart2ModelContact( spChart2ModelContact ),
98         m_aEventListenerContainer( m_aMutex ),
99         m_bWall( bWall )
100 
101 {
102 }
103 
~WallFloorWrapper()104 WallFloorWrapper::~WallFloorWrapper()
105 {
106 }
107 
108 // ____ XComponent ____
dispose()109 void SAL_CALL WallFloorWrapper::dispose()
110 {
111     Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
112     m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
113 
114     // /--
115     MutexGuard aGuard( GetMutex());
116     clearWrappedPropertySet();
117     // \--
118 }
119 
addEventListener(const Reference<lang::XEventListener> & xListener)120 void SAL_CALL WallFloorWrapper::addEventListener(
121     const Reference< lang::XEventListener >& xListener )
122 {
123     m_aEventListenerContainer.addInterface( xListener );
124 }
125 
removeEventListener(const Reference<lang::XEventListener> & aListener)126 void SAL_CALL WallFloorWrapper::removeEventListener(
127     const Reference< lang::XEventListener >& aListener )
128 {
129     m_aEventListenerContainer.removeInterface( aListener );
130 }
131 
132 // ================================================================================
133 
134 // WrappedPropertySet
getInnerPropertySet()135 Reference< beans::XPropertySet > WallFloorWrapper::getInnerPropertySet()
136 {
137     Reference< beans::XPropertySet > xRet;
138 
139     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
140     if( xDiagram.is() )
141     {
142         if( m_bWall )
143             xRet.set( xDiagram->getWall() );
144         else
145             xRet.set( xDiagram->getFloor() );
146     }
147 
148     return xRet;
149 }
150 
getPropertySequence()151 const Sequence< beans::Property >& WallFloorWrapper::getPropertySequence()
152 {
153     return *StaticWallFloorWrapperPropertyArray::get();
154 }
155 
createWrappedProperties()156 const std::vector< WrappedProperty* > WallFloorWrapper::createWrappedProperties()
157 {
158     ::std::vector< ::chart::WrappedProperty* > aWrappedProperties;
159 
160     // use direct state always, so that in XML the value is always
161     // exported. Because in the old chart the defaults is as follows:
162     // Floor: SOLID (new and old model default), Wall: NONE, except for some chart types (line, scatter)
163     if( m_bWall )
164         aWrappedProperties.push_back( new WrappedDirectStateProperty( C2U("FillStyle"), C2U("FillStyle") ));
165     aWrappedProperties.push_back( new WrappedDirectStateProperty( C2U("FillColor"), C2U("FillColor") ));
166 
167     return aWrappedProperties;
168 }
169 
170 // ================================================================================
171 
getSupportedServiceNames_Static()172 Sequence< OUString > WallFloorWrapper::getSupportedServiceNames_Static()
173 {
174     Sequence< OUString > aServices( 4 );
175     aServices[ 0 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" );
176     aServices[ 1 ] = C2U( "com.sun.star.drawing.FillProperties" );
177     aServices[ 2 ] = C2U( "com.sun.star.drawing.LineProperties" );
178     aServices[ 3 ] = C2U( "com.sun.star.beans.PropertySet" );
179 
180     return aServices;
181 }
182 
183 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
184 APPHELPER_XSERVICEINFO_IMPL( WallFloorWrapper, lcl_aServiceName );
185 
186 } //  namespace wrapper
187 } //  namespace chart
188