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 "RegressionEquationItemConverter.hxx" 32 #include "SchWhichPairs.hxx" 33 #include "macros.hxx" 34 #include "ItemPropertyMap.hxx" 35 #include "GraphicPropertyItemConverter.hxx" 36 #include "CharacterPropertyItemConverter.hxx" 37 #include "MultipleItemConverter.hxx" 38 39 #include <svl/intitem.hxx> 40 #include <rtl/math.hxx> 41 42 #include <functional> 43 #include <algorithm> 44 45 using namespace ::com::sun::star; 46 47 namespace 48 { 49 ::comphelper::ItemPropertyMapType & lcl_GetEquationPropertyMap() 50 { 51 static ::comphelper::ItemPropertyMapType aEquationPropertyMap; 52 53 return aEquationPropertyMap; 54 }; 55 } // anonymous namespace 56 57 namespace chart 58 { 59 namespace wrapper 60 { 61 62 RegressionEquationItemConverter::RegressionEquationItemConverter( 63 const ::com::sun::star::uno::Reference< 64 ::com::sun::star::beans::XPropertySet > & rPropertySet, 65 SfxItemPool& rItemPool, 66 SdrModel& rDrawModel, 67 const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory, 68 ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize ) : 69 ItemConverter( rPropertySet, rItemPool ) 70 { 71 m_aConverters.push_back( new GraphicPropertyItemConverter( 72 rPropertySet, rItemPool, rDrawModel, 73 xNamedPropertyContainerFactory, 74 GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES )); 75 76 m_aConverters.push_back( new CharacterPropertyItemConverter( 77 rPropertySet, rItemPool, pRefSize, C2U("ReferencePageSize"))); 78 79 // // CharacterProperties are not at the title but at its contained XFormattedString objects 80 // // take the first formatted string in the sequence 81 // uno::Reference< chart2::XTitle > xTitle( rPropertySet, uno::UNO_QUERY ); 82 // if( xTitle.is()) 83 // { 84 // uno::Sequence< uno::Reference< chart2::XFormattedString > > aStringSeq( xTitle->getText()); 85 // if( aStringSeq.getLength() > 0 ) 86 // { 87 // m_aConverters.push_back( 88 // new FormattedStringsConverter( aStringSeq, rItemPool, pRefSize, rPropertySet )); 89 // } 90 // } 91 } 92 93 RegressionEquationItemConverter::~RegressionEquationItemConverter() 94 { 95 ::std::for_each( m_aConverters.begin(), m_aConverters.end(), 96 ::comphelper::DeleteItemConverterPtr() ); 97 } 98 99 void RegressionEquationItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const 100 { 101 ::std::for_each( m_aConverters.begin(), m_aConverters.end(), 102 ::comphelper::FillItemSetFunc( rOutItemSet )); 103 104 // own items 105 ItemConverter::FillItemSet( rOutItemSet ); 106 } 107 108 bool RegressionEquationItemConverter::ApplyItemSet( const SfxItemSet & rItemSet ) 109 { 110 bool bResult = false; 111 112 ::std::for_each( m_aConverters.begin(), m_aConverters.end(), 113 ::comphelper::ApplyItemSetFunc( rItemSet, bResult )); 114 115 // own items 116 return ItemConverter::ApplyItemSet( rItemSet ) || bResult; 117 } 118 119 const sal_uInt16 * RegressionEquationItemConverter::GetWhichPairs() const 120 { 121 // must span all used items! 122 return nRegEquationWhichPairs; 123 } 124 125 bool RegressionEquationItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const 126 { 127 ::comphelper::ItemPropertyMapType & rMap( lcl_GetEquationPropertyMap()); 128 ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId )); 129 130 if( aIt == rMap.end()) 131 return false; 132 133 rOutProperty =(*aIt).second; 134 return true; 135 } 136 137 bool RegressionEquationItemConverter::ApplySpecialItem( 138 sal_uInt16 nWhichId, const SfxItemSet & rItemSet ) 139 throw( uno::Exception ) 140 { 141 bool bChanged = false; 142 143 switch( nWhichId ) 144 { 145 case SID_ATTR_NUMBERFORMAT_VALUE: 146 { 147 // bool bUseSourceFormat = 148 // (static_cast< const SfxBoolItem & >( 149 // rItemSet.Get( SID_ATTR_NUMBERFORMAT_SOURCE )).GetValue() ); 150 151 // if( ! bUseSourceFormat ) 152 // { 153 uno::Any aValue( static_cast< sal_Int32 >( 154 static_cast< const SfxUInt32Item & >( 155 rItemSet.Get( nWhichId )).GetValue())); 156 if( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )) != aValue ) 157 { 158 GetPropertySet()->setPropertyValue( C2U( "NumberFormat" ), aValue ); 159 bChanged = true; 160 } 161 } 162 break; 163 } 164 165 return bChanged; 166 } 167 168 void RegressionEquationItemConverter::FillSpecialItem( 169 sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const 170 throw( uno::Exception ) 171 { 172 switch( nWhichId ) 173 { 174 case SID_ATTR_NUMBERFORMAT_VALUE: 175 { 176 sal_Int32 nFormatKey = 0; 177 if( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )) >>= nFormatKey ) 178 { 179 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey )); 180 } 181 } 182 break; 183 } 184 } 185 186 } // namespace wrapper 187 } // namespace chart 188