fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / GridWrapper.cxx
blobe6ea629bbc4ee16938681a39aa7f61bb2f1d76d8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "GridWrapper.hxx"
21 #include "macros.hxx"
22 #include "AxisHelper.hxx"
23 #include "Chart2ModelContact.hxx"
24 #include "ContainerHelper.hxx"
25 #include "AxisIndexDefines.hxx"
26 #include <comphelper/InlineContainer.hxx>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include "LinePropertiesHelper.hxx"
30 #include "UserDefinedProperties.hxx"
31 #include "WrappedDefaultProperty.hxx"
33 #include <cppuhelper/supportsservice.hxx>
34 #include <algorithm>
35 #include <rtl/ustrbuf.hxx>
36 #include <rtl/math.hxx>
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::chart2;
41 using ::com::sun::star::beans::Property;
42 using ::osl::MutexGuard;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::uno::Sequence;
46 namespace
48 static const char lcl_aServiceName[] = "com.sun.star.comp.chart.Grid";
50 struct StaticGridWrapperPropertyArray_Initializer
52 Sequence< Property >* operator()()
54 static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
55 return &aPropSeq;
57 private:
58 static Sequence< Property > lcl_GetPropertySequence()
60 ::std::vector< ::com::sun::star::beans::Property > aProperties;
61 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
62 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
64 ::std::sort( aProperties.begin(), aProperties.end(),
65 ::chart::PropertyNameLess() );
67 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
71 struct StaticGridWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticGridWrapperPropertyArray_Initializer >
75 } // anonymous namespace
77 namespace chart
79 namespace wrapper
82 GridWrapper::GridWrapper(
83 tGridType eType, ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) :
84 m_spChart2ModelContact( spChart2ModelContact ),
85 m_aEventListenerContainer( m_aMutex ),
86 m_eType( eType )
90 GridWrapper::~GridWrapper()
93 void GridWrapper::getDimensionAndSubGridBool( tGridType eType, sal_Int32& rnDimensionIndex, bool& rbSubGrid )
95 rnDimensionIndex = 1;
96 rbSubGrid = false;
98 switch( eType )
100 case X_MAJOR_GRID:
101 rnDimensionIndex = 0; rbSubGrid = false; break;
102 case Y_MAJOR_GRID:
103 rnDimensionIndex = 1; rbSubGrid = false; break;
104 case Z_MAJOR_GRID:
105 rnDimensionIndex = 2; rbSubGrid = false; break;
106 case X_MINOR_GRID:
107 rnDimensionIndex = 0; rbSubGrid = true; break;
108 case Y_MINOR_GRID:
109 rnDimensionIndex = 1; rbSubGrid = true; break;
110 case Z_MINOR_GRID:
111 rnDimensionIndex = 2; rbSubGrid = true; break;
115 // ____ XComponent ____
116 void SAL_CALL GridWrapper::dispose()
117 throw (uno::RuntimeException, std::exception)
119 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
120 m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
122 clearWrappedPropertySet();
125 void SAL_CALL GridWrapper::addEventListener(
126 const Reference< lang::XEventListener >& xListener )
127 throw (uno::RuntimeException, std::exception)
129 m_aEventListenerContainer.addInterface( xListener );
132 void SAL_CALL GridWrapper::removeEventListener(
133 const Reference< lang::XEventListener >& aListener )
134 throw (uno::RuntimeException, std::exception)
136 m_aEventListenerContainer.removeInterface( aListener );
139 // WrappedPropertySet
141 Reference< beans::XPropertySet > GridWrapper::getInnerPropertySet()
143 Reference< beans::XPropertySet > xRet;
146 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
147 uno::Reference< XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 /*nCooSysIndex*/ ) );
149 sal_Int32 nDimensionIndex = 1;
150 bool bSubGrid = false;
151 getDimensionAndSubGridBool( m_eType, nDimensionIndex, bSubGrid );
153 sal_Int32 nSubGridIndex = bSubGrid ? 0 : -1;
154 xRet.set( AxisHelper::getGridProperties( xCooSys , nDimensionIndex, MAIN_AXIS_INDEX, nSubGridIndex ) );
156 catch( const uno::Exception & ex )
158 ASSERT_EXCEPTION( ex );
160 return xRet;
163 const Sequence< beans::Property >& GridWrapper::getPropertySequence()
165 return *StaticGridWrapperPropertyArray::get();
168 const std::vector< WrappedProperty* > GridWrapper::createWrappedProperties()
170 ::std::vector< ::chart::WrappedProperty* > aWrappedProperties;
172 aWrappedProperties.push_back( new WrappedDefaultProperty( "LineColor", "LineColor", uno::makeAny( sal_Int32( 0x000000) ) ) ); // black
174 return aWrappedProperties;
177 Sequence< OUString > GridWrapper::getSupportedServiceNames_Static()
179 Sequence< OUString > aServices( 4 );
180 aServices[ 0 ] = "com.sun.star.chart.ChartGrid";
181 aServices[ 1 ] = "com.sun.star.xml.UserDefinedAttributesSupplier";
182 aServices[ 2 ] = "com.sun.star.drawing.LineProperties";
183 aServices[ 3 ] = "com.sun.star.beans.PropertySet";
185 return aServices;
188 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
189 OUString SAL_CALL GridWrapper::getImplementationName()
190 throw( css::uno::RuntimeException, std::exception )
192 return getImplementationName_Static();
195 OUString GridWrapper::getImplementationName_Static()
197 return OUString(lcl_aServiceName);
200 sal_Bool SAL_CALL GridWrapper::supportsService( const OUString& rServiceName )
201 throw( css::uno::RuntimeException, std::exception )
203 return cppu::supportsService(this, rServiceName);
206 css::uno::Sequence< OUString > SAL_CALL GridWrapper::getSupportedServiceNames()
207 throw( css::uno::RuntimeException, std::exception )
209 return getSupportedServiceNames_Static();
212 } // namespace wrapper
213 } // namespace chart
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */