Debian Codegraph @

chart2/source/controller/chartapiwrapper/GridWrapper.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include "GridWrapper.hxx"
21 #include <AxisHelper.hxx>
22 #include "Chart2ModelContact.hxx"
23 #include <AxisIndexDefines.hxx>
24 #include <BaseCoordinateSystem.hxx>
25
26 #include <LinePropertiesHelper.hxx>
27 #include <UserDefinedProperties.hxx>
28 #include <WrappedDefaultProperty.hxx>
29
30 #include <comphelper/sequence.hxx>
31 #include <cppuhelper/supportsservice.hxx>
32 #include <algorithm>
33 #include <utility>
34 #include <comphelper/diagnose_ex.hxx>
35
36 using namespace ::com::sun::star;
37
38 using ::com::sun::star::beans::Property;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::Sequence;
41
42 namespace chart::wrapper
43 {
44
45 GridWrapper::GridWrapper(tGridType eType, std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
46 : m_spChart2ModelContact(std::move(spChart2ModelContact))
47 , m_eType(eType)
48 {
49 }
50
51 GridWrapper::~GridWrapper()
52 {}
53
54 void GridWrapper::getDimensionAndSubGridBool( tGridType eType, sal_Int32& rnDimensionIndex, bool& rbSubGrid )
55 {
56 rnDimensionIndex = 1;
57 rbSubGrid = false;
58
59 switch( eType )
60 {
61 case X_MAJOR_GRID:
62 rnDimensionIndex = 0; rbSubGrid = false; break;
63 case Y_MAJOR_GRID:
64 rnDimensionIndex = 1; rbSubGrid = false; break;
65 case Z_MAJOR_GRID:
66 rnDimensionIndex = 2; rbSubGrid = false; break;
67 case X_MINOR_GRID:
68 rnDimensionIndex = 0; rbSubGrid = true; break;
69 case Y_MINOR_GRID:
70 rnDimensionIndex = 1; rbSubGrid = true; break;
71 case Z_MINOR_GRID:
72 rnDimensionIndex = 2; rbSubGrid = true; break;
73 }
74 }
75
76 // ____ XComponent ____
77 void SAL_CALL GridWrapper::dispose()
78 {
79 std::unique_lock g(m_aMutex);
80 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
81 m_aEventListenerContainer.disposeAndClear( g, lang::EventObject( xSource ) );
82
83 clearWrappedPropertySet();
84 }
85
86 void SAL_CALL GridWrapper::addEventListener(
87 const Reference< lang::XEventListener >& xListener )
88 {
89 std::unique_lock g(m_aMutex);
90 m_aEventListenerContainer.addInterface( g, xListener );
91 }
92
93 void SAL_CALL GridWrapper::removeEventListener(
94 const Reference< lang::XEventListener >& aListener )
95 {
96 std::unique_lock g(m_aMutex);
97 m_aEventListenerContainer.removeInterface( g, aListener );
98 }
99
100 // WrappedPropertySet
101
102 Reference< beans::XPropertySet > GridWrapper::getInnerPropertySet()
103 {
104 rtl::Reference< GridProperties > xRet;
105 try
106 {
107 rtl::Reference< ::chart::Diagram > xDiagram( m_spChart2ModelContact->getDiagram() );
108 rtl::Reference< BaseCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 /*nCooSysIndex*/ ) );
109
110 sal_Int32 nDimensionIndex = 1;
111 bool bSubGrid = false;
112 getDimensionAndSubGridBool( m_eType, nDimensionIndex, bSubGrid );
113
114 sal_Int32 nSubGridIndex = bSubGrid ? 0 : -1;
115 xRet = AxisHelper::getGridProperties( xCooSys , nDimensionIndex, MAIN_AXIS_INDEX, nSubGridIndex );
116 }
117 catch( const uno::Exception & )
118 {
119 DBG_UNHANDLED_EXCEPTION("chart2");
120 }
121 return xRet;
122 }
123
124 const Sequence< beans::Property >& GridWrapper::getPropertySequence()
125 {
126 static Sequence< Property > aPropSeq = []()
127 {
128 std::vector< css::beans::Property > aProperties;
129 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
130 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
131
132 std::sort( aProperties.begin(), aProperties.end(),
133 ::chart::PropertyNameLess() );
134
135 return comphelper::containerToSequence( aProperties );
136 }();
137 return aPropSeq;
138 }
139
140 std::vector< std::unique_ptr<WrappedProperty> > GridWrapper::createWrappedProperties()
141 {
142 std::vector< std::unique_ptr<WrappedProperty> > aWrappedProperties;
143
144 aWrappedProperties.emplace_back( new WrappedDefaultProperty( u"LineColor"_ustr, u"LineColor"_ustr, uno::Any( sal_Int32( 0x000000) ) ) ); // black
145
146 return aWrappedProperties;
147 }
148
149 OUString SAL_CALL GridWrapper::getImplementationName()
150 {
151 return u"com.sun.star.comp.chart.Grid"_ustr;
152 }
153
154 sal_Bool SAL_CALL GridWrapper::supportsService( const OUString& rServiceName )
155 {
156 return cppu::supportsService(this, rServiceName);
157 }
158
159 css::uno::Sequence< OUString > SAL_CALL GridWrapper::getSupportedServiceNames()
160 {
161 return {
162 u"com.sun.star.chart.ChartGrid"_ustr,
163 u"com.sun.star.xml.UserDefinedAttributesSupplier"_ustr,
164 u"com.sun.star.drawing.LineProperties"_ustr,
165 u"com.sun.star.beans.PropertySet"_ustr
166 };
167 }
168
169 } // namespace chart::wrapper
170
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */