Update ooo320-m1
[ooovba.git] / chart2 / source / view / axes / VAxisBase.cxx
blobfe8e2759cbbe999574be7bee9b40c33281081c76
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VAxisBase.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "VAxisBase.hxx"
35 #include "ShapeFactory.hxx"
36 #include "CommonConverters.hxx"
37 #include "TickmarkHelper.hxx"
38 #include "macros.hxx"
40 // header for define DBG_ASSERT
41 #include <tools/debug.hxx>
43 #include <memory>
45 //.............................................................................
46 namespace chart
48 //.............................................................................
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::chart2;
51 using ::com::sun::star::uno::Reference;
53 VAxisBase::VAxisBase( sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount
54 , const AxisProperties& rAxisProperties
55 , const uno::Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier )
56 : VAxisOrGridBase( nDimensionIndex, nDimensionCount )
57 , m_xNumberFormatsSupplier( xNumberFormatsSupplier )
58 , m_aAxisProperties( rAxisProperties )
59 , m_bUseTextLabels( false )
60 , m_bReCreateAllTickInfos( true )
61 , m_bRecordMaximumTextSize(false)
62 , m_nMaximumTextWidthSoFar(0)
63 , m_nMaximumTextHeightSoFar(0)
67 VAxisBase::~VAxisBase()
71 sal_Int32 VAxisBase::getDimensionCount()
73 return m_nDimension;
76 void SAL_CALL VAxisBase::initAxisLabelProperties( const ::com::sun::star::awt::Size& rFontReferenceSize
77 , const ::com::sun::star::awt::Rectangle& rMaximumSpaceForLabels )
79 m_aAxisLabelProperties.m_aFontReferenceSize = rFontReferenceSize;
80 m_aAxisLabelProperties.m_aMaximumSpaceForLabels = rMaximumSpaceForLabels;
82 if( !m_aAxisProperties.m_bDisplayLabels )
83 return;
85 if( AxisType::CATEGORY==m_aAxisProperties.m_nAxisType
86 || AxisType::SERIES==m_aAxisProperties.m_nAxisType )
88 if( m_aAxisProperties.m_xAxisTextProvider.is() )
89 m_aTextLabels = m_aAxisProperties.m_xAxisTextProvider->getTextualData();
91 m_bUseTextLabels = true;
92 if( m_aTextLabels.getLength() == 1 && AxisType::SERIES==m_aAxisProperties.m_nAxisType )
94 //don't show a single series name
95 m_aAxisProperties.m_bDisplayLabels = false;
96 return;
100 m_aAxisLabelProperties.nNumberFormatKey = m_aAxisProperties.m_nNumberFormatKey;
101 m_aAxisLabelProperties.init(m_aAxisProperties.m_xAxisModel);
104 void VAxisBase::recordMaximumTextSize( const Reference< drawing::XShape >& xShape, double fRotationAngleDegree )
106 if( m_bRecordMaximumTextSize && xShape.is() )
108 awt::Size aSize( ShapeFactory::getSizeAfterRotation(
109 xShape, fRotationAngleDegree ) );
111 m_nMaximumTextWidthSoFar = std::max( m_nMaximumTextWidthSoFar, aSize.Width );
112 m_nMaximumTextHeightSoFar = std::max( m_nMaximumTextHeightSoFar, aSize.Height );
116 sal_Int32 VAxisBase::estimateMaximumAutoMainIncrementCount()
118 return 10;
121 void VAxisBase::setExrtaLinePositionAtOtherAxis( const double& fCrossingAt )
123 if( m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis )
124 delete m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis;
125 m_aAxisProperties.m_pfExrtaLinePositionAtOtherAxis = new double(fCrossingAt);
128 sal_Bool SAL_CALL VAxisBase::isAnythingToDraw()
130 if( !m_aAxisProperties.m_xAxisModel.is() )
131 return false;
133 DBG_ASSERT(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is(),"Axis is not proper initialized");
134 if(!(m_pShapeFactory&&m_xLogicTarget.is()&&m_xFinalTarget.is()))
135 return false;
137 uno::Reference< beans::XPropertySet > xProps( m_aAxisProperties.m_xAxisModel, uno::UNO_QUERY );
138 if( xProps.is() )
140 sal_Bool bShow = sal_False;
141 xProps->getPropertyValue( C2U( "Show" ) ) >>= bShow;
142 if( !bShow )
143 return false;
145 return true;
148 void SAL_CALL VAxisBase::setExplicitScaleAndIncrement(
149 const ExplicitScaleData& rScale
150 , const ExplicitIncrementData& rIncrement )
151 throw (uno::RuntimeException)
153 m_bReCreateAllTickInfos = true;
154 m_aScale = rScale;
155 m_aIncrement = rIncrement;
158 bool VAxisBase::prepareShapeCreation()
160 //returns true if all is ready for further shape creation and any shapes need to be created
161 if( !isAnythingToDraw() )
162 return false;
164 if( m_bReCreateAllTickInfos )
166 //-----------------------------------------
167 //create all scaled tickmark values
168 if( m_xTextTarget.is() )
170 TickIter aRemoveIter( m_aAllTickInfos, m_aIncrement, 0, 0 );
171 removeTextShapesFromTicks( aRemoveIter, m_xTextTarget );
174 std::auto_ptr< TickmarkHelper > apTickmarkHelper( this->createTickmarkHelper() );
175 apTickmarkHelper->getAllTicks( m_aAllTickInfos );
176 m_bReCreateAllTickInfos = false;
179 if( m_xGroupShape_Shapes.is() )
180 return true;
182 //-----------------------------------------
183 //create named group shape
184 m_xGroupShape_Shapes = this->createGroupShape( m_xLogicTarget, m_nDimension==2 ? m_aCID : C2U(""));
186 if( m_aAxisProperties.m_bDisplayLabels )
187 m_xTextTarget = m_pShapeFactory->createGroup2D( m_xFinalTarget, m_aCID );
189 return true;
192 sal_Int32 VAxisBase::getIndexOfLongestLabel( const uno::Sequence< rtl::OUString >& rLabels )
194 sal_Int32 nRet = 0;
195 sal_Int32 nLength = 0;
196 sal_Int32 nN = 0;
197 for( nN=0; nN<rLabels.getLength(); nN++ )
199 //todo: get real text width (without creating shape) instead of character count
200 if( rLabels[nN].getLength() > nLength )
202 nLength = rLabels[nN].getLength();
203 nRet = nN;
206 return nRet;
209 void VAxisBase::removeTextShapesFromTicks( TickIter& rIter, const Reference< drawing::XShapes >& xTarget )
211 for( TickInfo* pTickInfo = rIter.firstInfo()
212 ; pTickInfo; pTickInfo = rIter.nextInfo() )
214 if(pTickInfo->xTextShape.is())
216 xTarget->remove(pTickInfo->xTextShape);
217 pTickInfo->xTextShape = NULL;
222 void VAxisBase::updateUnscaledValuesAtTicks( TickIter& rIter )
224 Reference< XScaling > xInverseScaling( NULL );
225 if( m_aScale.Scaling.is() )
226 xInverseScaling = m_aScale.Scaling->getInverseScaling();
228 for( TickInfo* pTickInfo = rIter.firstInfo()
229 ; pTickInfo; pTickInfo = rIter.nextInfo() )
231 pTickInfo->updateUnscaledValue( xInverseScaling );
235 //.............................................................................
236 } //namespace chart
237 //.............................................................................