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 "GridWrapper.hxx"
28 #include "macros.hxx"
29 #include "AxisHelper.hxx"
30 #include "Chart2ModelContact.hxx"
31 #include "ContainerHelper.hxx"
32 #include "AxisIndexDefines.hxx"
33 #include <comphelper/InlineContainer.hxx>
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 
36 #include "LineProperties.hxx"
37 #include "UserDefinedProperties.hxx"
38 #include "WrappedDefaultProperty.hxx"
39 
40 #include <algorithm>
41 #include <rtl/ustrbuf.hxx>
42 #include <rtl/math.hxx>
43 
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::chart2;
46 
47 using ::com::sun::star::beans::Property;
48 using ::osl::MutexGuard;
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.Grid" ));
57 
58 struct StaticGridWrapperPropertyArray_Initializer
59 {
operator ()__anon3174af380111::StaticGridWrapperPropertyArray_Initializer60     Sequence< Property >* operator()()
61     {
62         static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
63         return &aPropSeq;
64     }
65 private:
lcl_GetPropertySequence__anon3174af380111::StaticGridWrapperPropertyArray_Initializer66     Sequence< Property > lcl_GetPropertySequence()
67     {
68         ::std::vector< ::com::sun::star::beans::Property > aProperties;
69         ::chart::LineProperties::AddPropertiesToVector( aProperties );
70         //::chart::NamedLineProperties::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 StaticGridWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticGridWrapperPropertyArray_Initializer >
81 {
82 };
83 
84 } // anonymous namespace
85 
86 // --------------------------------------------------------------------------------
87 
88 namespace chart
89 {
90 namespace wrapper
91 {
92 
GridWrapper(tGridType eType,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)93 GridWrapper::GridWrapper(
94     tGridType eType, ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) :
95         m_spChart2ModelContact( spChart2ModelContact ),
96         m_aEventListenerContainer( m_aMutex ),
97         m_eType( eType )
98 {
99 }
100 
~GridWrapper()101 GridWrapper::~GridWrapper()
102 {}
103 
getDimensionAndSubGridBool(tGridType eType,sal_Int32 & rnDimensionIndex,bool & rbSubGrid)104 void GridWrapper::getDimensionAndSubGridBool( tGridType eType, sal_Int32& rnDimensionIndex, bool& rbSubGrid )
105 {
106     rnDimensionIndex = 1;
107     rbSubGrid = false;
108 
109     switch( eType )
110     {
111         case X_MAJOR_GRID:
112             rnDimensionIndex = 0; rbSubGrid = false; break;
113         case Y_MAJOR_GRID:
114             rnDimensionIndex = 1; rbSubGrid = false; break;
115         case Z_MAJOR_GRID:
116             rnDimensionIndex = 2; rbSubGrid = false; break;
117         case X_MINOR_GRID:
118             rnDimensionIndex = 0; rbSubGrid = true;  break;
119         case Y_MINOR_GRID:
120             rnDimensionIndex = 1; rbSubGrid = true;  break;
121         case Z_MINOR_GRID:
122             rnDimensionIndex = 2; rbSubGrid = true;  break;
123     }
124 }
125 
126 // ____ XComponent ____
dispose()127 void SAL_CALL GridWrapper::dispose()
128     throw (uno::RuntimeException)
129 {
130     Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
131     m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
132 
133     clearWrappedPropertySet();
134 }
135 
addEventListener(const Reference<lang::XEventListener> & xListener)136 void SAL_CALL GridWrapper::addEventListener(
137     const Reference< lang::XEventListener >& xListener )
138     throw (uno::RuntimeException)
139 {
140 	m_aEventListenerContainer.addInterface( xListener );
141 }
142 
removeEventListener(const Reference<lang::XEventListener> & aListener)143 void SAL_CALL GridWrapper::removeEventListener(
144     const Reference< lang::XEventListener >& aListener )
145     throw (uno::RuntimeException)
146 {
147 	m_aEventListenerContainer.removeInterface( aListener );
148 }
149 
150 // ================================================================================
151 
152 // WrappedPropertySet
153 
getInnerPropertySet()154 Reference< beans::XPropertySet > GridWrapper::getInnerPropertySet()
155 {
156     Reference< beans::XPropertySet > xRet;
157     try
158     {
159         Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
160         uno::Reference< XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 /*nCooSysIndex*/ ) );
161 
162         sal_Int32 nDimensionIndex = 1;
163         bool bSubGrid = false;
164         getDimensionAndSubGridBool( m_eType, nDimensionIndex, bSubGrid );
165 
166         sal_Int32 nSubGridIndex = bSubGrid ? 0 : -1;
167         xRet.set( AxisHelper::getGridProperties( xCooSys , nDimensionIndex, MAIN_AXIS_INDEX, nSubGridIndex ) );
168     }
169     catch( uno::Exception & ex )
170     {
171         ASSERT_EXCEPTION( ex );
172     }
173     return xRet;
174 }
175 
getPropertySequence()176 const Sequence< beans::Property >& GridWrapper::getPropertySequence()
177 {
178     return *StaticGridWrapperPropertyArray::get();
179 }
180 
createWrappedProperties()181 const std::vector< WrappedProperty* > GridWrapper::createWrappedProperties()
182 {
183     ::std::vector< ::chart::WrappedProperty* > aWrappedProperties;
184 
185     aWrappedProperties.push_back( new WrappedDefaultProperty( C2U("LineColor"), C2U("LineColor"), uno::makeAny( sal_Int32( 0x000000) ) ) ); // black
186 
187     return aWrappedProperties;
188 }
189 
190 // ================================================================================
191 
getSupportedServiceNames_Static()192 Sequence< OUString > GridWrapper::getSupportedServiceNames_Static()
193 {
194     Sequence< OUString > aServices( 4 );
195     aServices[ 0 ] = C2U( "com.sun.star.chart.ChartGrid" );
196     aServices[ 1 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" );
197     aServices[ 2 ] = C2U( "com.sun.star.drawing.LineProperties" );
198     aServices[ 3 ] = C2U( "com.sun.star.beans.PropertySet" );
199 
200     return aServices;
201 }
202 
203 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
204 APPHELPER_XSERVICEINFO_IMPL( GridWrapper, lcl_aServiceName );
205 
206 } //  namespace wrapper
207 } //  namespace chart
208 
209