Line data Source code
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 "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>
28 :
29 : #include "LinePropertiesHelper.hxx"
30 : #include "UserDefinedProperties.hxx"
31 : #include "WrappedDefaultProperty.hxx"
32 :
33 : #include <cppuhelper/supportsservice.hxx>
34 : #include <algorithm>
35 : #include <rtl/ustrbuf.hxx>
36 : #include <rtl/math.hxx>
37 :
38 : using namespace ::com::sun::star;
39 : using namespace ::com::sun::star::chart2;
40 :
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;
45 :
46 : namespace
47 : {
48 : static const char lcl_aServiceName[] = "com.sun.star.comp.chart.Grid";
49 :
50 : struct StaticGridWrapperPropertyArray_Initializer
51 : {
52 9 : Sequence< Property >* operator()()
53 : {
54 9 : static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
55 9 : return &aPropSeq;
56 : }
57 : private:
58 9 : static Sequence< Property > lcl_GetPropertySequence()
59 : {
60 9 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
61 9 : ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
62 9 : ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
63 :
64 : ::std::sort( aProperties.begin(), aProperties.end(),
65 9 : ::chart::PropertyNameLess() );
66 :
67 9 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
68 : }
69 : };
70 :
71 : struct StaticGridWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticGridWrapperPropertyArray_Initializer >
72 : {
73 : };
74 :
75 : } // anonymous namespace
76 :
77 : namespace chart
78 : {
79 : namespace wrapper
80 : {
81 :
82 207 : GridWrapper::GridWrapper(
83 : tGridType eType, ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) :
84 : m_spChart2ModelContact( spChart2ModelContact ),
85 : m_aEventListenerContainer( m_aMutex ),
86 207 : m_eType( eType )
87 : {
88 207 : }
89 :
90 414 : GridWrapper::~GridWrapper()
91 414 : {}
92 :
93 6157 : void GridWrapper::getDimensionAndSubGridBool( tGridType eType, sal_Int32& rnDimensionIndex, bool& rbSubGrid )
94 : {
95 6157 : rnDimensionIndex = 1;
96 6157 : rbSubGrid = false;
97 :
98 6157 : switch( eType )
99 : {
100 : case X_MAJOR_GRID:
101 697 : rnDimensionIndex = 0; rbSubGrid = false; break;
102 : case Y_MAJOR_GRID:
103 4685 : rnDimensionIndex = 1; rbSubGrid = false; break;
104 : case Z_MAJOR_GRID:
105 0 : rnDimensionIndex = 2; rbSubGrid = false; break;
106 : case X_MINOR_GRID:
107 0 : rnDimensionIndex = 0; rbSubGrid = true; break;
108 : case Y_MINOR_GRID:
109 775 : rnDimensionIndex = 1; rbSubGrid = true; break;
110 : case Z_MINOR_GRID:
111 0 : rnDimensionIndex = 2; rbSubGrid = true; break;
112 : }
113 6157 : }
114 :
115 : // ____ XComponent ____
116 205 : void SAL_CALL GridWrapper::dispose()
117 : throw (uno::RuntimeException, std::exception)
118 : {
119 205 : Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
120 205 : m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
121 :
122 205 : clearWrappedPropertySet();
123 205 : }
124 :
125 0 : void SAL_CALL GridWrapper::addEventListener(
126 : const Reference< lang::XEventListener >& xListener )
127 : throw (uno::RuntimeException, std::exception)
128 : {
129 0 : m_aEventListenerContainer.addInterface( xListener );
130 0 : }
131 :
132 0 : void SAL_CALL GridWrapper::removeEventListener(
133 : const Reference< lang::XEventListener >& aListener )
134 : throw (uno::RuntimeException, std::exception)
135 : {
136 0 : m_aEventListenerContainer.removeInterface( aListener );
137 0 : }
138 :
139 : // WrappedPropertySet
140 :
141 6157 : Reference< beans::XPropertySet > GridWrapper::getInnerPropertySet()
142 : {
143 6157 : Reference< beans::XPropertySet > xRet;
144 : try
145 : {
146 6157 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
147 12314 : uno::Reference< XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 /*nCooSysIndex*/ ) );
148 :
149 6157 : sal_Int32 nDimensionIndex = 1;
150 6157 : bool bSubGrid = false;
151 6157 : getDimensionAndSubGridBool( m_eType, nDimensionIndex, bSubGrid );
152 :
153 6157 : sal_Int32 nSubGridIndex = bSubGrid ? 0 : -1;
154 12314 : xRet.set( AxisHelper::getGridProperties( xCooSys , nDimensionIndex, MAIN_AXIS_INDEX, nSubGridIndex ) );
155 : }
156 0 : catch( const uno::Exception & ex )
157 : {
158 : ASSERT_EXCEPTION( ex );
159 : }
160 6157 : return xRet;
161 : }
162 :
163 201 : const Sequence< beans::Property >& GridWrapper::getPropertySequence()
164 : {
165 201 : return *StaticGridWrapperPropertyArray::get();
166 : }
167 :
168 201 : const std::vector< WrappedProperty* > GridWrapper::createWrappedProperties()
169 : {
170 201 : ::std::vector< ::chart::WrappedProperty* > aWrappedProperties;
171 :
172 201 : aWrappedProperties.push_back( new WrappedDefaultProperty( "LineColor", "LineColor", uno::makeAny( sal_Int32( 0x000000) ) ) ); // black
173 :
174 201 : return aWrappedProperties;
175 : }
176 :
177 1 : Sequence< OUString > GridWrapper::getSupportedServiceNames_Static()
178 : {
179 1 : Sequence< OUString > aServices( 4 );
180 1 : aServices[ 0 ] = "com.sun.star.chart.ChartGrid";
181 1 : aServices[ 1 ] = "com.sun.star.xml.UserDefinedAttributesSupplier";
182 1 : aServices[ 2 ] = "com.sun.star.drawing.LineProperties";
183 1 : aServices[ 3 ] = "com.sun.star.beans.PropertySet";
184 :
185 1 : return aServices;
186 : }
187 :
188 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
189 0 : OUString SAL_CALL GridWrapper::getImplementationName()
190 : throw( css::uno::RuntimeException, std::exception )
191 : {
192 0 : return getImplementationName_Static();
193 : }
194 :
195 0 : OUString GridWrapper::getImplementationName_Static()
196 : {
197 0 : return OUString(lcl_aServiceName);
198 : }
199 :
200 1 : sal_Bool SAL_CALL GridWrapper::supportsService( const OUString& rServiceName )
201 : throw( css::uno::RuntimeException, std::exception )
202 : {
203 1 : return cppu::supportsService(this, rServiceName);
204 : }
205 :
206 1 : css::uno::Sequence< OUString > SAL_CALL GridWrapper::getSupportedServiceNames()
207 : throw( css::uno::RuntimeException, std::exception )
208 : {
209 1 : return getSupportedServiceNames_Static();
210 : }
211 :
212 : } // namespace wrapper
213 : } // namespace chart
214 :
215 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|