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>
24 #include <BaseCoordinateSystem.hxx>
25 #include <GridProperties.hxx>
27 #include <LinePropertiesHelper.hxx>
28 #include <UserDefinedProperties.hxx>
29 #include <WrappedDefaultProperty.hxx>
31 #include <comphelper/sequence.hxx>
32 #include <cppuhelper/supportsservice.hxx>
35 #include <comphelper/diagnose_ex.hxx>
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::chart2
;
40 using ::com::sun::star::beans::Property
;
41 using ::com::sun::star::uno::Reference
;
42 using ::com::sun::star::uno::Sequence
;
44 namespace chart::wrapper
47 GridWrapper::GridWrapper(tGridType eType
, std::shared_ptr
<Chart2ModelContact
> spChart2ModelContact
)
48 : m_spChart2ModelContact(std::move(spChart2ModelContact
))
53 GridWrapper::~GridWrapper()
56 void GridWrapper::getDimensionAndSubGridBool( tGridType eType
, sal_Int32
& rnDimensionIndex
, bool& rbSubGrid
)
64 rnDimensionIndex
= 0; rbSubGrid
= false; break;
66 rnDimensionIndex
= 1; rbSubGrid
= false; break;
68 rnDimensionIndex
= 2; rbSubGrid
= false; break;
70 rnDimensionIndex
= 0; rbSubGrid
= true; break;
72 rnDimensionIndex
= 1; rbSubGrid
= true; break;
74 rnDimensionIndex
= 2; rbSubGrid
= true; break;
78 // ____ XComponent ____
79 void SAL_CALL
GridWrapper::dispose()
81 std::unique_lock
g(m_aMutex
);
82 Reference
< uno::XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
83 m_aEventListenerContainer
.disposeAndClear( g
, lang::EventObject( xSource
) );
85 clearWrappedPropertySet();
88 void SAL_CALL
GridWrapper::addEventListener(
89 const Reference
< lang::XEventListener
>& xListener
)
91 std::unique_lock
g(m_aMutex
);
92 m_aEventListenerContainer
.addInterface( g
, xListener
);
95 void SAL_CALL
GridWrapper::removeEventListener(
96 const Reference
< lang::XEventListener
>& aListener
)
98 std::unique_lock
g(m_aMutex
);
99 m_aEventListenerContainer
.removeInterface( g
, aListener
);
102 // WrappedPropertySet
104 Reference
< beans::XPropertySet
> GridWrapper::getInnerPropertySet()
106 Reference
< beans::XPropertySet
> xRet
;
109 rtl::Reference
< ::chart::Diagram
> xDiagram( m_spChart2ModelContact
->getDiagram() );
110 rtl::Reference
< BaseCoordinateSystem
> xCooSys( AxisHelper::getCoordinateSystemByIndex( xDiagram
, 0 /*nCooSysIndex*/ ) );
112 sal_Int32 nDimensionIndex
= 1;
113 bool bSubGrid
= false;
114 getDimensionAndSubGridBool( m_eType
, nDimensionIndex
, bSubGrid
);
116 sal_Int32 nSubGridIndex
= bSubGrid
? 0 : -1;
117 xRet
= AxisHelper::getGridProperties( xCooSys
, nDimensionIndex
, MAIN_AXIS_INDEX
, nSubGridIndex
);
119 catch( const uno::Exception
& )
121 DBG_UNHANDLED_EXCEPTION("chart2");
126 const Sequence
< beans::Property
>& GridWrapper::getPropertySequence()
128 static Sequence
< Property
> aPropSeq
= []()
130 std::vector
< css::beans::Property
> aProperties
;
131 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
132 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
134 std::sort( aProperties
.begin(), aProperties
.end(),
135 ::chart::PropertyNameLess() );
137 return comphelper::containerToSequence( aProperties
);
142 std::vector
< std::unique_ptr
<WrappedProperty
> > GridWrapper::createWrappedProperties()
144 std::vector
< std::unique_ptr
<WrappedProperty
> > aWrappedProperties
;
146 aWrappedProperties
.emplace_back( new WrappedDefaultProperty( "LineColor", "LineColor", uno::Any( sal_Int32( 0x000000) ) ) ); // black
148 return aWrappedProperties
;
151 OUString SAL_CALL
GridWrapper::getImplementationName()
153 return "com.sun.star.comp.chart.Grid";
156 sal_Bool SAL_CALL
GridWrapper::supportsService( const OUString
& rServiceName
)
158 return cppu::supportsService(this, rServiceName
);
161 css::uno::Sequence
< OUString
> SAL_CALL
GridWrapper::getSupportedServiceNames()
164 "com.sun.star.chart.ChartGrid",
165 "com.sun.star.xml.UserDefinedAttributesSupplier",
166 "com.sun.star.drawing.LineProperties",
167 "com.sun.star.beans.PropertySet"
171 } // namespace chart::wrapper
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */