1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
;
44 struct StaticGridWrapperPropertyArray_Initializer
46 Sequence
< Property
>* operator()()
48 static Sequence
< Property
> aPropSeq( lcl_GetPropertySequence() );
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
76 GridWrapper::GridWrapper(tGridType eType
, const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
)
77 : m_spChart2ModelContact(spChart2ModelContact
)
78 , m_aEventListenerContainer(m_aMutex
)
83 GridWrapper::~GridWrapper()
86 void GridWrapper::getDimensionAndSubGridBool( tGridType eType
, sal_Int32
& rnDimensionIndex
, bool& rbSubGrid
)
94 rnDimensionIndex
= 0; rbSubGrid
= false; break;
96 rnDimensionIndex
= 1; rbSubGrid
= false; break;
98 rnDimensionIndex
= 2; rbSubGrid
= false; break;
100 rnDimensionIndex
= 0; rbSubGrid
= true; break;
102 rnDimensionIndex
= 1; rbSubGrid
= true; break;
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");
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()
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
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */