1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_chart2.hxx" 30 31 #include "GridWrapper.hxx" 32 #include "macros.hxx" 33 #include "AxisHelper.hxx" 34 #include "Chart2ModelContact.hxx" 35 #include "ContainerHelper.hxx" 36 #include "AxisIndexDefines.hxx" 37 #include <comphelper/InlineContainer.hxx> 38 #include <com/sun/star/beans/PropertyAttribute.hpp> 39 40 #include "LineProperties.hxx" 41 #include "UserDefinedProperties.hxx" 42 #include "WrappedDefaultProperty.hxx" 43 44 #include <algorithm> 45 #include <rtl/ustrbuf.hxx> 46 #include <rtl/math.hxx> 47 48 using namespace ::com::sun::star; 49 using namespace ::com::sun::star::chart2; 50 51 using ::com::sun::star::beans::Property; 52 using ::osl::MutexGuard; 53 using ::com::sun::star::uno::Reference; 54 using ::com::sun::star::uno::Sequence; 55 using ::rtl::OUString; 56 57 namespace 58 { 59 static const OUString lcl_aServiceName( 60 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.Grid" )); 61 62 struct StaticGridWrapperPropertyArray_Initializer 63 { 64 Sequence< Property >* operator()() 65 { 66 static Sequence< Property > aPropSeq( lcl_GetPropertySequence() ); 67 return &aPropSeq; 68 } 69 private: 70 Sequence< Property > lcl_GetPropertySequence() 71 { 72 ::std::vector< ::com::sun::star::beans::Property > aProperties; 73 ::chart::LineProperties::AddPropertiesToVector( aProperties ); 74 //::chart::NamedLineProperties::AddPropertiesToVector( aProperties ); 75 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties ); 76 77 ::std::sort( aProperties.begin(), aProperties.end(), 78 ::chart::PropertyNameLess() ); 79 80 return ::chart::ContainerHelper::ContainerToSequence( aProperties ); 81 } 82 }; 83 84 struct StaticGridWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticGridWrapperPropertyArray_Initializer > 85 { 86 }; 87 88 } // anonymous namespace 89 90 // -------------------------------------------------------------------------------- 91 92 namespace chart 93 { 94 namespace wrapper 95 { 96 97 GridWrapper::GridWrapper( 98 tGridType eType, ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) : 99 m_spChart2ModelContact( spChart2ModelContact ), 100 m_aEventListenerContainer( m_aMutex ), 101 m_eType( eType ) 102 { 103 } 104 105 GridWrapper::~GridWrapper() 106 {} 107 108 void GridWrapper::getDimensionAndSubGridBool( tGridType eType, sal_Int32& rnDimensionIndex, bool& rbSubGrid ) 109 { 110 rnDimensionIndex = 1; 111 rbSubGrid = false; 112 113 switch( eType ) 114 { 115 case X_MAJOR_GRID: 116 rnDimensionIndex = 0; rbSubGrid = false; break; 117 case Y_MAJOR_GRID: 118 rnDimensionIndex = 1; rbSubGrid = false; break; 119 case Z_MAJOR_GRID: 120 rnDimensionIndex = 2; rbSubGrid = false; break; 121 case X_MINOR_GRID: 122 rnDimensionIndex = 0; rbSubGrid = true; break; 123 case Y_MINOR_GRID: 124 rnDimensionIndex = 1; rbSubGrid = true; break; 125 case Z_MINOR_GRID: 126 rnDimensionIndex = 2; rbSubGrid = true; break; 127 } 128 } 129 130 // ____ XComponent ____ 131 void SAL_CALL GridWrapper::dispose() 132 throw (uno::RuntimeException) 133 { 134 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); 135 m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) ); 136 137 clearWrappedPropertySet(); 138 } 139 140 void SAL_CALL GridWrapper::addEventListener( 141 const Reference< lang::XEventListener >& xListener ) 142 throw (uno::RuntimeException) 143 { 144 m_aEventListenerContainer.addInterface( xListener ); 145 } 146 147 void SAL_CALL GridWrapper::removeEventListener( 148 const Reference< lang::XEventListener >& aListener ) 149 throw (uno::RuntimeException) 150 { 151 m_aEventListenerContainer.removeInterface( aListener ); 152 } 153 154 // ================================================================================ 155 156 // WrappedPropertySet 157 158 Reference< beans::XPropertySet > GridWrapper::getInnerPropertySet() 159 { 160 Reference< beans::XPropertySet > xRet; 161 try 162 { 163 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 164 uno::Reference< XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 /*nCooSysIndex*/ ) ); 165 166 sal_Int32 nDimensionIndex = 1; 167 bool bSubGrid = false; 168 getDimensionAndSubGridBool( m_eType, nDimensionIndex, bSubGrid ); 169 170 sal_Int32 nSubGridIndex = bSubGrid ? 0 : -1; 171 xRet.set( AxisHelper::getGridProperties( xCooSys , nDimensionIndex, MAIN_AXIS_INDEX, nSubGridIndex ) ); 172 } 173 catch( uno::Exception & ex ) 174 { 175 ASSERT_EXCEPTION( ex ); 176 } 177 return xRet; 178 } 179 180 const Sequence< beans::Property >& GridWrapper::getPropertySequence() 181 { 182 return *StaticGridWrapperPropertyArray::get(); 183 } 184 185 const std::vector< WrappedProperty* > GridWrapper::createWrappedProperties() 186 { 187 ::std::vector< ::chart::WrappedProperty* > aWrappedProperties; 188 189 aWrappedProperties.push_back( new WrappedDefaultProperty( C2U("LineColor"), C2U("LineColor"), uno::makeAny( sal_Int32( 0x000000) ) ) ); // black 190 191 return aWrappedProperties; 192 } 193 194 // ================================================================================ 195 196 Sequence< OUString > GridWrapper::getSupportedServiceNames_Static() 197 { 198 Sequence< OUString > aServices( 4 ); 199 aServices[ 0 ] = C2U( "com.sun.star.chart.ChartGrid" ); 200 aServices[ 1 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" ); 201 aServices[ 2 ] = C2U( "com.sun.star.drawing.LineProperties" ); 202 aServices[ 3 ] = C2U( "com.sun.star.beans.PropertySet" ); 203 204 return aServices; 205 } 206 207 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static 208 APPHELPER_XSERVICEINFO_IMPL( GridWrapper, lcl_aServiceName ); 209 210 } // namespace wrapper 211 } // namespace chart 212 213