Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / GridWrapper.cxx
blobaee6ad0aa6724bd0fa359045793bb2764ef99602
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 <AxisHelper.hxx>
22 #include "Chart2ModelContact.hxx"
23 #include <AxisIndexDefines.hxx>
25 #include <LinePropertiesHelper.hxx>
26 #include <UserDefinedProperties.hxx>
27 #include <WrappedDefaultProperty.hxx>
29 #include <comphelper/sequence.hxx>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <algorithm>
32 #include <tools/diagnose_ex.h>
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::chart2;
37 using ::com::sun::star::beans::Property;
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::Sequence;
41 namespace
44 struct StaticGridWrapperPropertyArray_Initializer
46 Sequence< Property >* operator()()
48 static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
49 return &aPropSeq;
51 private:
52 static Sequence< Property > lcl_GetPropertySequence()
54 std::vector< css::beans::Property > aProperties;
55 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
56 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
58 std::sort( aProperties.begin(), aProperties.end(),
59 ::chart::PropertyNameLess() );
61 return comphelper::containerToSequence( aProperties );
65 struct StaticGridWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticGridWrapperPropertyArray_Initializer >
69 } // anonymous namespace
71 namespace chart
73 namespace wrapper
76 GridWrapper::GridWrapper(tGridType eType, const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact)
77 : m_spChart2ModelContact(spChart2ModelContact)
78 , m_aEventListenerContainer(m_aMutex)
79 , m_eType(eType)
83 GridWrapper::~GridWrapper()
86 void GridWrapper::getDimensionAndSubGridBool( tGridType eType, sal_Int32& rnDimensionIndex, bool& rbSubGrid )
88 rnDimensionIndex = 1;
89 rbSubGrid = false;
91 switch( eType )
93 case X_MAJOR_GRID:
94 rnDimensionIndex = 0; rbSubGrid = false; break;
95 case Y_MAJOR_GRID:
96 rnDimensionIndex = 1; rbSubGrid = false; break;
97 case Z_MAJOR_GRID:
98 rnDimensionIndex = 2; rbSubGrid = false; break;
99 case X_MINOR_GRID:
100 rnDimensionIndex = 0; rbSubGrid = true; break;
101 case Y_MINOR_GRID:
102 rnDimensionIndex = 1; rbSubGrid = true; break;
103 case Z_MINOR_GRID:
104 rnDimensionIndex = 2; rbSubGrid = true; break;
108 // ____ XComponent ____
109 void SAL_CALL GridWrapper::dispose()
111 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
112 m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
114 clearWrappedPropertySet();
117 void SAL_CALL GridWrapper::addEventListener(
118 const Reference< lang::XEventListener >& xListener )
120 m_aEventListenerContainer.addInterface( xListener );
123 void SAL_CALL GridWrapper::removeEventListener(
124 const Reference< lang::XEventListener >& aListener )
126 m_aEventListenerContainer.removeInterface( aListener );
129 // WrappedPropertySet
131 Reference< beans::XPropertySet > GridWrapper::getInnerPropertySet()
133 Reference< beans::XPropertySet > xRet;
136 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
137 uno::Reference< XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 /*nCooSysIndex*/ ) );
139 sal_Int32 nDimensionIndex = 1;
140 bool bSubGrid = false;
141 getDimensionAndSubGridBool( m_eType, nDimensionIndex, bSubGrid );
143 sal_Int32 nSubGridIndex = bSubGrid ? 0 : -1;
144 xRet.set( AxisHelper::getGridProperties( xCooSys , nDimensionIndex, MAIN_AXIS_INDEX, nSubGridIndex ) );
146 catch( const uno::Exception & )
148 DBG_UNHANDLED_EXCEPTION("chart2");
150 return xRet;
153 const Sequence< beans::Property >& GridWrapper::getPropertySequence()
155 return *StaticGridWrapperPropertyArray::get();
158 std::vector< std::unique_ptr<WrappedProperty> > GridWrapper::createWrappedProperties()
160 std::vector< std::unique_ptr<WrappedProperty> > aWrappedProperties;
162 aWrappedProperties.emplace_back( new WrappedDefaultProperty( "LineColor", "LineColor", uno::Any( sal_Int32( 0x000000) ) ) ); // black
164 return aWrappedProperties;
167 OUString SAL_CALL GridWrapper::getImplementationName()
169 return "com.sun.star.comp.chart.Grid";
172 sal_Bool SAL_CALL GridWrapper::supportsService( const OUString& rServiceName )
174 return cppu::supportsService(this, rServiceName);
177 css::uno::Sequence< OUString > SAL_CALL GridWrapper::getSupportedServiceNames()
179 return {
180 "com.sun.star.chart.ChartGrid",
181 "com.sun.star.xml.UserDefinedAttributesSupplier",
182 "com.sun.star.drawing.LineProperties",
183 "com.sun.star.beans.PropertySet"
187 } // namespace wrapper
188 } // namespace chart
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */