1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*cde9e8dcSAndrew Rist * distributed with this work for additional information
6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at
10*cde9e8dcSAndrew Rist *
11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist *
13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the
17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist * under the License.
19*cde9e8dcSAndrew Rist *
20*cde9e8dcSAndrew Rist *************************************************************/
21*cde9e8dcSAndrew Rist
22*cde9e8dcSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "GridWrapper.hxx"
28cdf0e10cSrcweir #include "macros.hxx"
29cdf0e10cSrcweir #include "AxisHelper.hxx"
30cdf0e10cSrcweir #include "Chart2ModelContact.hxx"
31cdf0e10cSrcweir #include "ContainerHelper.hxx"
32cdf0e10cSrcweir #include "AxisIndexDefines.hxx"
33cdf0e10cSrcweir #include <comphelper/InlineContainer.hxx>
34cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include "LineProperties.hxx"
37cdf0e10cSrcweir #include "UserDefinedProperties.hxx"
38cdf0e10cSrcweir #include "WrappedDefaultProperty.hxx"
39cdf0e10cSrcweir
40cdf0e10cSrcweir #include <algorithm>
41cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
42cdf0e10cSrcweir #include <rtl/math.hxx>
43cdf0e10cSrcweir
44cdf0e10cSrcweir using namespace ::com::sun::star;
45cdf0e10cSrcweir using namespace ::com::sun::star::chart2;
46cdf0e10cSrcweir
47cdf0e10cSrcweir using ::com::sun::star::beans::Property;
48cdf0e10cSrcweir using ::osl::MutexGuard;
49cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
50cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
51cdf0e10cSrcweir using ::rtl::OUString;
52cdf0e10cSrcweir
53cdf0e10cSrcweir namespace
54cdf0e10cSrcweir {
55cdf0e10cSrcweir static const OUString lcl_aServiceName(
56cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.Grid" ));
57cdf0e10cSrcweir
58cdf0e10cSrcweir struct StaticGridWrapperPropertyArray_Initializer
59cdf0e10cSrcweir {
operator ()__anon17a5b9200111::StaticGridWrapperPropertyArray_Initializer60cdf0e10cSrcweir Sequence< Property >* operator()()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
63cdf0e10cSrcweir return &aPropSeq;
64cdf0e10cSrcweir }
65cdf0e10cSrcweir private:
lcl_GetPropertySequence__anon17a5b9200111::StaticGridWrapperPropertyArray_Initializer66cdf0e10cSrcweir Sequence< Property > lcl_GetPropertySequence()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir ::std::vector< ::com::sun::star::beans::Property > aProperties;
69cdf0e10cSrcweir ::chart::LineProperties::AddPropertiesToVector( aProperties );
70cdf0e10cSrcweir //::chart::NamedLineProperties::AddPropertiesToVector( aProperties );
71cdf0e10cSrcweir ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
72cdf0e10cSrcweir
73cdf0e10cSrcweir ::std::sort( aProperties.begin(), aProperties.end(),
74cdf0e10cSrcweir ::chart::PropertyNameLess() );
75cdf0e10cSrcweir
76cdf0e10cSrcweir return ::chart::ContainerHelper::ContainerToSequence( aProperties );
77cdf0e10cSrcweir }
78cdf0e10cSrcweir };
79cdf0e10cSrcweir
80cdf0e10cSrcweir struct StaticGridWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticGridWrapperPropertyArray_Initializer >
81cdf0e10cSrcweir {
82cdf0e10cSrcweir };
83cdf0e10cSrcweir
84cdf0e10cSrcweir } // anonymous namespace
85cdf0e10cSrcweir
86cdf0e10cSrcweir // --------------------------------------------------------------------------------
87cdf0e10cSrcweir
88cdf0e10cSrcweir namespace chart
89cdf0e10cSrcweir {
90cdf0e10cSrcweir namespace wrapper
91cdf0e10cSrcweir {
92cdf0e10cSrcweir
GridWrapper(tGridType eType,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)93cdf0e10cSrcweir GridWrapper::GridWrapper(
94cdf0e10cSrcweir tGridType eType, ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) :
95cdf0e10cSrcweir m_spChart2ModelContact( spChart2ModelContact ),
96cdf0e10cSrcweir m_aEventListenerContainer( m_aMutex ),
97cdf0e10cSrcweir m_eType( eType )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir }
100cdf0e10cSrcweir
~GridWrapper()101cdf0e10cSrcweir GridWrapper::~GridWrapper()
102cdf0e10cSrcweir {}
103cdf0e10cSrcweir
getDimensionAndSubGridBool(tGridType eType,sal_Int32 & rnDimensionIndex,bool & rbSubGrid)104cdf0e10cSrcweir void GridWrapper::getDimensionAndSubGridBool( tGridType eType, sal_Int32& rnDimensionIndex, bool& rbSubGrid )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir rnDimensionIndex = 1;
107cdf0e10cSrcweir rbSubGrid = false;
108cdf0e10cSrcweir
109cdf0e10cSrcweir switch( eType )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir case X_MAJOR_GRID:
112cdf0e10cSrcweir rnDimensionIndex = 0; rbSubGrid = false; break;
113cdf0e10cSrcweir case Y_MAJOR_GRID:
114cdf0e10cSrcweir rnDimensionIndex = 1; rbSubGrid = false; break;
115cdf0e10cSrcweir case Z_MAJOR_GRID:
116cdf0e10cSrcweir rnDimensionIndex = 2; rbSubGrid = false; break;
117cdf0e10cSrcweir case X_MINOR_GRID:
118cdf0e10cSrcweir rnDimensionIndex = 0; rbSubGrid = true; break;
119cdf0e10cSrcweir case Y_MINOR_GRID:
120cdf0e10cSrcweir rnDimensionIndex = 1; rbSubGrid = true; break;
121cdf0e10cSrcweir case Z_MINOR_GRID:
122cdf0e10cSrcweir rnDimensionIndex = 2; rbSubGrid = true; break;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir }
125cdf0e10cSrcweir
126cdf0e10cSrcweir // ____ XComponent ____
dispose()127cdf0e10cSrcweir void SAL_CALL GridWrapper::dispose()
128cdf0e10cSrcweir throw (uno::RuntimeException)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
131cdf0e10cSrcweir m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
132cdf0e10cSrcweir
133cdf0e10cSrcweir clearWrappedPropertySet();
134cdf0e10cSrcweir }
135cdf0e10cSrcweir
addEventListener(const Reference<lang::XEventListener> & xListener)136cdf0e10cSrcweir void SAL_CALL GridWrapper::addEventListener(
137cdf0e10cSrcweir const Reference< lang::XEventListener >& xListener )
138cdf0e10cSrcweir throw (uno::RuntimeException)
139cdf0e10cSrcweir {
140cdf0e10cSrcweir m_aEventListenerContainer.addInterface( xListener );
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
removeEventListener(const Reference<lang::XEventListener> & aListener)143cdf0e10cSrcweir void SAL_CALL GridWrapper::removeEventListener(
144cdf0e10cSrcweir const Reference< lang::XEventListener >& aListener )
145cdf0e10cSrcweir throw (uno::RuntimeException)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir m_aEventListenerContainer.removeInterface( aListener );
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
150cdf0e10cSrcweir // ================================================================================
151cdf0e10cSrcweir
152cdf0e10cSrcweir // WrappedPropertySet
153cdf0e10cSrcweir
getInnerPropertySet()154cdf0e10cSrcweir Reference< beans::XPropertySet > GridWrapper::getInnerPropertySet()
155cdf0e10cSrcweir {
156cdf0e10cSrcweir Reference< beans::XPropertySet > xRet;
157cdf0e10cSrcweir try
158cdf0e10cSrcweir {
159cdf0e10cSrcweir Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
160cdf0e10cSrcweir uno::Reference< XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 /*nCooSysIndex*/ ) );
161cdf0e10cSrcweir
162cdf0e10cSrcweir sal_Int32 nDimensionIndex = 1;
163cdf0e10cSrcweir bool bSubGrid = false;
164cdf0e10cSrcweir getDimensionAndSubGridBool( m_eType, nDimensionIndex, bSubGrid );
165cdf0e10cSrcweir
166cdf0e10cSrcweir sal_Int32 nSubGridIndex = bSubGrid ? 0 : -1;
167cdf0e10cSrcweir xRet.set( AxisHelper::getGridProperties( xCooSys , nDimensionIndex, MAIN_AXIS_INDEX, nSubGridIndex ) );
168cdf0e10cSrcweir }
169cdf0e10cSrcweir catch( uno::Exception & ex )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
172cdf0e10cSrcweir }
173cdf0e10cSrcweir return xRet;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
getPropertySequence()176cdf0e10cSrcweir const Sequence< beans::Property >& GridWrapper::getPropertySequence()
177cdf0e10cSrcweir {
178cdf0e10cSrcweir return *StaticGridWrapperPropertyArray::get();
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
createWrappedProperties()181cdf0e10cSrcweir const std::vector< WrappedProperty* > GridWrapper::createWrappedProperties()
182cdf0e10cSrcweir {
183cdf0e10cSrcweir ::std::vector< ::chart::WrappedProperty* > aWrappedProperties;
184cdf0e10cSrcweir
185cdf0e10cSrcweir aWrappedProperties.push_back( new WrappedDefaultProperty( C2U("LineColor"), C2U("LineColor"), uno::makeAny( sal_Int32( 0x000000) ) ) ); // black
186cdf0e10cSrcweir
187cdf0e10cSrcweir return aWrappedProperties;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir
190cdf0e10cSrcweir // ================================================================================
191cdf0e10cSrcweir
getSupportedServiceNames_Static()192cdf0e10cSrcweir Sequence< OUString > GridWrapper::getSupportedServiceNames_Static()
193cdf0e10cSrcweir {
194cdf0e10cSrcweir Sequence< OUString > aServices( 4 );
195cdf0e10cSrcweir aServices[ 0 ] = C2U( "com.sun.star.chart.ChartGrid" );
196cdf0e10cSrcweir aServices[ 1 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" );
197cdf0e10cSrcweir aServices[ 2 ] = C2U( "com.sun.star.drawing.LineProperties" );
198cdf0e10cSrcweir aServices[ 3 ] = C2U( "com.sun.star.beans.PropertySet" );
199cdf0e10cSrcweir
200cdf0e10cSrcweir return aServices;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
203cdf0e10cSrcweir // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
204cdf0e10cSrcweir APPHELPER_XSERVICEINFO_IMPL( GridWrapper, lcl_aServiceName );
205cdf0e10cSrcweir
206cdf0e10cSrcweir } // namespace wrapper
207cdf0e10cSrcweir } // namespace chart
208cdf0e10cSrcweir
209