update dev300-m57
[ooovba.git] / chart2 / source / controller / chartapiwrapper / GridWrapper.cxx
blobf5a7050a1645a59677ea6e062e387399420a6d40
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: GridWrapper.cxx,v $
10 * $Revision: 1.3.44.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "GridWrapper.hxx"
35 #include "macros.hxx"
36 #include "AxisHelper.hxx"
37 #include "Chart2ModelContact.hxx"
38 #include "ContainerHelper.hxx"
39 #include "AxisIndexDefines.hxx"
40 #include <comphelper/InlineContainer.hxx>
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
43 #include "LineProperties.hxx"
44 #include "UserDefinedProperties.hxx"
45 #include "WrappedDefaultProperty.hxx"
47 #include <algorithm>
48 #include <rtl/ustrbuf.hxx>
49 #include <rtl/math.hxx>
51 using namespace ::com::sun::star;
52 using namespace ::com::sun::star::chart2;
54 using ::com::sun::star::beans::Property;
55 using ::osl::MutexGuard;
56 using ::com::sun::star::uno::Reference;
57 using ::com::sun::star::uno::Sequence;
58 using ::rtl::OUString;
60 namespace
62 static const OUString lcl_aServiceName(
63 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.Grid" ));
65 const Sequence< Property > & lcl_GetPropertySequence()
67 static Sequence< Property > aPropSeq;
69 // /--
70 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
71 if( 0 == aPropSeq.getLength() )
73 // get properties
74 ::std::vector< ::com::sun::star::beans::Property > aProperties;
75 ::chart::LineProperties::AddPropertiesToVector( aProperties );
76 // ::chart::NamedLineProperties::AddPropertiesToVector( aProperties );
77 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
79 // and sort them for access via bsearch
80 ::std::sort( aProperties.begin(), aProperties.end(),
81 ::chart::PropertyNameLess() );
83 // transfer result to static Sequence
84 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
87 return aPropSeq;
90 } // anonymous namespace
92 // --------------------------------------------------------------------------------
94 namespace chart
96 namespace wrapper
99 GridWrapper::GridWrapper(
100 tGridType eType, ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) :
101 m_spChart2ModelContact( spChart2ModelContact ),
102 m_aEventListenerContainer( m_aMutex ),
103 m_eType( eType )
107 GridWrapper::~GridWrapper()
110 // static
111 void GridWrapper::getDimensionAndSubGridBool( tGridType eType, sal_Int32& rnDimensionIndex, bool& rbSubGrid )
113 rnDimensionIndex = 1;
114 rbSubGrid = false;
116 switch( eType )
118 case X_MAIN_GRID:
119 rnDimensionIndex = 0; rbSubGrid = false; break;
120 case Y_MAIN_GRID:
121 rnDimensionIndex = 1; rbSubGrid = false; break;
122 case Z_MAIN_GRID:
123 rnDimensionIndex = 2; rbSubGrid = false; break;
124 case X_SUB_GRID:
125 rnDimensionIndex = 0; rbSubGrid = true; break;
126 case Y_SUB_GRID:
127 rnDimensionIndex = 1; rbSubGrid = true; break;
128 case Z_SUB_GRID:
129 rnDimensionIndex = 2; rbSubGrid = true; break;
133 // ____ XComponent ____
134 void SAL_CALL GridWrapper::dispose()
135 throw (uno::RuntimeException)
137 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
138 m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
140 clearWrappedPropertySet();
143 void SAL_CALL GridWrapper::addEventListener(
144 const Reference< lang::XEventListener >& xListener )
145 throw (uno::RuntimeException)
147 m_aEventListenerContainer.addInterface( xListener );
150 void SAL_CALL GridWrapper::removeEventListener(
151 const Reference< lang::XEventListener >& aListener )
152 throw (uno::RuntimeException)
154 m_aEventListenerContainer.removeInterface( aListener );
157 // ================================================================================
159 // WrappedPropertySet
161 Reference< beans::XPropertySet > GridWrapper::getInnerPropertySet()
163 Reference< beans::XPropertySet > xRet;
166 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
167 uno::Reference< XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 /*nCooSysIndex*/ ) );
169 sal_Int32 nDimensionIndex = 1;
170 bool bSubGrid = false;
171 getDimensionAndSubGridBool( m_eType, nDimensionIndex, bSubGrid );
173 sal_Int32 nSubGridIndex = bSubGrid ? 0 : -1;
174 xRet.set( AxisHelper::getGridProperties( xCooSys , nDimensionIndex, MAIN_AXIS_INDEX, nSubGridIndex ) );
176 catch( uno::Exception & ex )
178 ASSERT_EXCEPTION( ex );
180 return xRet;
183 const Sequence< beans::Property >& GridWrapper::getPropertySequence()
185 return lcl_GetPropertySequence();
188 const std::vector< WrappedProperty* > GridWrapper::createWrappedProperties()
190 ::std::vector< ::chart::WrappedProperty* > aWrappedProperties;
192 aWrappedProperties.push_back( new WrappedDefaultProperty( C2U("LineColor"), C2U("LineColor"), uno::makeAny( sal_Int32( 0x000000) ) ) ); // black
194 return aWrappedProperties;
197 // ================================================================================
199 Sequence< OUString > GridWrapper::getSupportedServiceNames_Static()
201 Sequence< OUString > aServices( 4 );
202 aServices[ 0 ] = C2U( "com.sun.star.chart.ChartGrid" );
203 aServices[ 1 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" );
204 aServices[ 2 ] = C2U( "com.sun.star.drawing.LineProperties" );
205 aServices[ 3 ] = C2U( "com.sun.star.beans.PropertySet" );
207 return aServices;
210 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
211 APPHELPER_XSERVICEINFO_IMPL( GridWrapper, lcl_aServiceName );
213 } // namespace wrapper
214 } // namespace chart