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 "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 ()__anon624b9d040111::StaticWallFloorWrapperPropertyArray_Initializer60     Sequence< Property >* operator()()
61     {
62         static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
63         return &aPropSeq;
64     }
65 
66 private:
lcl_GetPropertySequence__anon624b9d040111::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     throw (uno::RuntimeException)
111 {
112     Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
113     m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
114 
115     // /--
116     MutexGuard aGuard( GetMutex());
117     clearWrappedPropertySet();
118     // \--
119 }
120 
addEventListener(const Reference<lang::XEventListener> & xListener)121 void SAL_CALL WallFloorWrapper::addEventListener(
122     const Reference< lang::XEventListener >& xListener )
123     throw (uno::RuntimeException)
124 {
125 	m_aEventListenerContainer.addInterface( xListener );
126 }
127 
removeEventListener(const Reference<lang::XEventListener> & aListener)128 void SAL_CALL WallFloorWrapper::removeEventListener(
129     const Reference< lang::XEventListener >& aListener )
130     throw (uno::RuntimeException)
131 {
132 	m_aEventListenerContainer.removeInterface( aListener );
133 }
134 
135 // ================================================================================
136 
137 // WrappedPropertySet
getInnerPropertySet()138 Reference< beans::XPropertySet > WallFloorWrapper::getInnerPropertySet()
139 {
140     Reference< beans::XPropertySet > xRet;
141 
142     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
143     if( xDiagram.is() )
144     {
145         if( m_bWall )
146             xRet.set( xDiagram->getWall() );
147         else
148             xRet.set( xDiagram->getFloor() );
149     }
150 
151     return xRet;
152 }
153 
getPropertySequence()154 const Sequence< beans::Property >& WallFloorWrapper::getPropertySequence()
155 {
156     return *StaticWallFloorWrapperPropertyArray::get();
157 }
158 
createWrappedProperties()159 const std::vector< WrappedProperty* > WallFloorWrapper::createWrappedProperties()
160 {
161     ::std::vector< ::chart::WrappedProperty* > aWrappedProperties;
162 
163     // use direct state always, so that in XML the value is always
164     // exported. Because in the old chart the defaults is as follows:
165     // Floor: SOLID (new and old model default), Wall: NONE, except for some chart types (line, scatter)
166     if( m_bWall )
167         aWrappedProperties.push_back( new WrappedDirectStateProperty( C2U("FillStyle"), C2U("FillStyle") ));
168     aWrappedProperties.push_back( new WrappedDirectStateProperty( C2U("FillColor"), C2U("FillColor") ));
169 
170     return aWrappedProperties;
171 }
172 
173 // ================================================================================
174 
getSupportedServiceNames_Static()175 Sequence< OUString > WallFloorWrapper::getSupportedServiceNames_Static()
176 {
177     Sequence< OUString > aServices( 4 );
178     aServices[ 0 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" );
179     aServices[ 1 ] = C2U( "com.sun.star.drawing.FillProperties" );
180     aServices[ 2 ] = C2U( "com.sun.star.drawing.LineProperties" );
181     aServices[ 3 ] = C2U( "com.sun.star.beans.PropertySet" );
182 
183     return aServices;
184 }
185 
186 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
187 APPHELPER_XSERVICEINFO_IMPL( WallFloorWrapper, lcl_aServiceName );
188 
189 } //  namespace wrapper
190 } //  namespace chart
191