diff options
22 files changed, 609 insertions, 346 deletions
diff --git a/chart2/source/controller/chartapiwrapper/LegendWrapper.cxx b/chart2/source/controller/chartapiwrapper/LegendWrapper.cxx index 5b71c7d3e768..05848422f885 100755 --- a/chart2/source/controller/chartapiwrapper/LegendWrapper.cxx +++ b/chart2/source/controller/chartapiwrapper/LegendWrapper.cxx @@ -37,7 +37,7 @@ #include <com/sun/star/chart2/XTitled.hpp> #include <com/sun/star/chart/ChartLegendPosition.hpp> #include <com/sun/star/chart2/LegendPosition.hpp> -#include <com/sun/star/chart2/LegendExpansion.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> #include <com/sun/star/chart2/RelativePosition.hpp> #include <com/sun/star/drawing/FillStyle.hpp> @@ -139,13 +139,13 @@ void WrappedLegendAlignmentProperty::setPropertyValue( const Any& rOuterValue, c chart2::LegendPosition eNewInnerPos(chart2::LegendPosition_LINE_END); if( aInnerValue >>= eNewInnerPos ) { - chart2::LegendExpansion eNewExpansion = + ::com::sun::star::chart::ChartLegendExpansion eNewExpansion = ( eNewInnerPos == chart2::LegendPosition_LINE_END || eNewInnerPos == chart2::LegendPosition_LINE_START ) - ? chart2::LegendExpansion_HIGH - : chart2::LegendExpansion_WIDE; + ? ::com::sun::star::chart::ChartLegendExpansion_HIGH + : ::com::sun::star::chart::ChartLegendExpansion_WIDE; - chart2::LegendExpansion eOldExpansion( chart2::LegendExpansion_HIGH ); + ::com::sun::star::chart::ChartLegendExpansion eOldExpansion( ::com::sun::star::chart::ChartLegendExpansion_HIGH ); bool bExpansionWasSet( xInnerPropertySet->getPropertyValue( C2U( "Expansion" ) ) >>= eOldExpansion ); @@ -232,7 +232,8 @@ static const ::rtl::OUString lcl_aServiceName( enum { - PROP_LEGEND_ALIGNMENT + PROP_LEGEND_ALIGNMENT, + PROP_LEGEND_EXPANSION }; void lcl_AddPropertiesToVector( @@ -244,6 +245,13 @@ void lcl_AddPropertiesToVector( ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartLegendPosition * >(0)), //#i111967# no PropertyChangeEvent is fired on change so far beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "Expansion" ), + PROP_LEGEND_EXPANSION, + ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartLegendExpansion * >(0)), + //#i111967# no PropertyChangeEvent is fired on change so far + beans::PropertyAttribute::MAYBEDEFAULT )); } struct StaticLegendWrapperPropertyArray_Initializer @@ -429,6 +437,7 @@ const std::vector< WrappedProperty* > LegendWrapper::createWrappedProperties() ::std::vector< ::chart::WrappedProperty* > aWrappedProperties; aWrappedProperties.push_back( new WrappedLegendAlignmentProperty() ); + aWrappedProperties.push_back( new WrappedProperty( C2U("Expansion"), C2U("Expansion") )); WrappedCharacterHeightProperty::addWrappedProperties( aWrappedProperties, this ); //same problem as for wall: thje defaults ion the old chart are different for different charttypes, so we need to export explicitly aWrappedProperties.push_back( new WrappedDirectStateProperty( C2U("FillStyle"), C2U("FillStyle") ) ); diff --git a/chart2/source/controller/dialogs/res_LegendPosition.cxx b/chart2/source/controller/dialogs/res_LegendPosition.cxx index c9206a5428df..361019825539 100644 --- a/chart2/source/controller/dialogs/res_LegendPosition.cxx +++ b/chart2/source/controller/dialogs/res_LegendPosition.cxx @@ -41,13 +41,12 @@ #include <svtools/controldims.hrc> #endif #include <com/sun/star/chart2/LegendPosition.hpp> -#include <com/sun/star/chart2/LegendExpansion.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> //itemset stuff #include "chartview/ChartSfxItemIds.hxx" -#include <svx/chrtitem.hxx> -// header for class SfxItemPool -#include <svl/itempool.hxx> +#include <svl/intitem.hxx> +#include <svl/eitem.hxx> //............................................................................. namespace chart @@ -151,7 +150,7 @@ void LegendPositionResources::writeToModel( const ::com::sun::star::uno::Referen //position chart2::LegendPosition eNewPos; - chart2::LegendExpansion eExp = chart2::LegendExpansion_HIGH; + ::com::sun::star::chart::ChartLegendExpansion eExp = ::com::sun::star::chart::ChartLegendExpansion_HIGH; if( m_aRbtLeft.IsChecked() ) eNewPos = chart2::LegendPosition_LINE_START; @@ -162,12 +161,12 @@ void LegendPositionResources::writeToModel( const ::com::sun::star::uno::Referen else if( m_aRbtTop.IsChecked() ) { eNewPos = chart2::LegendPosition_PAGE_START; - eExp = chart2::LegendExpansion_WIDE; + eExp = ::com::sun::star::chart::ChartLegendExpansion_WIDE; } else if( m_aRbtBottom.IsChecked() ) { eNewPos = chart2::LegendPosition_PAGE_END; - eExp = chart2::LegendExpansion_WIDE; + eExp = ::com::sun::star::chart::ChartLegendExpansion_WIDE; } xProp->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( eNewPos )); @@ -197,51 +196,51 @@ IMPL_LINK( LegendPositionResources, PositionEnableHdl, void*, EMPTYARG ) void LegendPositionResources::initFromItemSet( const SfxItemSet& rInAttrs ) { - SvxChartLegendPos ePos = CHLEGEND_NONE; - const SfxPoolItem* pPoolItem = NULL; - if( rInAttrs.GetItemState( SCHATTR_LEGEND_POS, - TRUE, &pPoolItem ) != SFX_ITEM_SET ) - pPoolItem = &(rInAttrs.GetPool()->GetDefaultItem( SCHATTR_LEGEND_POS )); - - if( pPoolItem ) - ePos = ((const SvxChartLegendPosItem*)pPoolItem)->GetValue(); + if( rInAttrs.GetItemState( SCHATTR_LEGEND_POS, TRUE, &pPoolItem ) == SFX_ITEM_SET ) + { + sal_Int32 nLegendPosition = ((const SfxInt32Item*)pPoolItem)->GetValue(); + switch( nLegendPosition ) + { + case chart2::LegendPosition_LINE_START: + m_aRbtLeft.Check(TRUE); + break; + case chart2::LegendPosition_PAGE_START: + m_aRbtTop.Check(TRUE); + break; + case chart2::LegendPosition_LINE_END: + m_aRbtRight.Check(TRUE); + break; + case chart2::LegendPosition_PAGE_END: + m_aRbtBottom.Check(TRUE); + break; + default: + break; + } + } - switch( ePos ) + if( rInAttrs.GetItemState( SCHATTR_LEGEND_SHOW, TRUE, &pPoolItem ) == SFX_ITEM_SET ) { - case CHLEGEND_LEFT: - m_aRbtLeft.Check(TRUE); - break; - case CHLEGEND_TOP: - m_aRbtTop.Check(TRUE); - break; - case CHLEGEND_RIGHT: - m_aRbtRight.Check(TRUE); - break; - case CHLEGEND_BOTTOM: - m_aRbtBottom.Check(TRUE); - break; - default: - break; + bool bShow = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue(); + m_aCbxShow.Check(bShow); } + } void LegendPositionResources::writeToItemSet( SfxItemSet& rOutAttrs ) const { - SvxChartLegendPos ePos; - + sal_Int32 nLegendPosition = chart2::LegendPosition_CUSTOM; if( m_aRbtLeft.IsChecked() ) - ePos = CHLEGEND_LEFT; + nLegendPosition = chart2::LegendPosition_LINE_START; else if( m_aRbtTop.IsChecked() ) - ePos = CHLEGEND_TOP; + nLegendPosition = chart2::LegendPosition_PAGE_START; else if( m_aRbtRight.IsChecked() ) - ePos = CHLEGEND_RIGHT; + nLegendPosition = chart2::LegendPosition_LINE_END; else if( m_aRbtBottom.IsChecked() ) - ePos = CHLEGEND_BOTTOM; - else - ePos = CHLEGEND_NONE; + nLegendPosition = chart2::LegendPosition_PAGE_END; + rOutAttrs.Put(SfxInt32Item(SCHATTR_LEGEND_POS, nLegendPosition )); - rOutAttrs.Put(SvxChartLegendPosItem( ePos, SCHATTR_LEGEND_POS )); + rOutAttrs.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, m_aCbxShow.IsChecked()) ); } IMPL_LINK( LegendPositionResources, PositionChangeHdl, RadioButton*, pRadio ) diff --git a/chart2/source/controller/itemsetwrapper/LegendItemConverter.cxx b/chart2/source/controller/itemsetwrapper/LegendItemConverter.cxx index 3af6d9342f33..c93505181c0d 100644 --- a/chart2/source/controller/itemsetwrapper/LegendItemConverter.cxx +++ b/chart2/source/controller/itemsetwrapper/LegendItemConverter.cxx @@ -33,10 +33,12 @@ #include "ItemPropertyMap.hxx" #include "GraphicPropertyItemConverter.hxx" #include "CharacterPropertyItemConverter.hxx" -#include <svx/chrtitem.hxx> #include <com/sun/star/chart2/XLegend.hpp> #include <com/sun/star/chart2/LegendPosition.hpp> -#include <com/sun/star/chart2/LegendExpansion.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> + +#include <svl/intitem.hxx> +#include <svl/eitem.hxx> #include <functional> #include <algorithm> @@ -104,52 +106,19 @@ bool LegendItemConverter::GetItemProperty( tWhichIdType /*nWhichId*/, tPropertyN } -bool LegendItemConverter::ApplySpecialItem( - USHORT nWhichId, const SfxItemSet & rItemSet ) +bool LegendItemConverter::ApplySpecialItem( USHORT nWhichId, const SfxItemSet& rInItemSet ) throw( uno::Exception ) { bool bChanged = false; switch( nWhichId ) { - case SCHATTR_LEGEND_POS: + case SCHATTR_LEGEND_SHOW: { - chart2::LegendPosition eNewPos = chart2::LegendPosition_LINE_END; - chart2::LegendPosition eOldPos; - bool bIsWide = false; - sal_Bool bShow = sal_True; - - SvxChartLegendPos eItemPos = - static_cast< const SvxChartLegendPosItem & >( - rItemSet.Get( nWhichId )).GetValue(); - switch( eItemPos ) - { - case CHLEGEND_LEFT: - eNewPos = chart2::LegendPosition_LINE_START; - break; - case CHLEGEND_RIGHT: - eNewPos = chart2::LegendPosition_LINE_END; - break; - case CHLEGEND_TOP: - eNewPos = chart2::LegendPosition_PAGE_START; - bIsWide = true; - break; - case CHLEGEND_BOTTOM: - eNewPos = chart2::LegendPosition_PAGE_END; - bIsWide = true; - break; - - case CHLEGEND_NONE: - case CHLEGEND_NONE_LEFT: - case CHLEGEND_NONE_RIGHT: - case CHLEGEND_NONE_TOP: - case CHLEGEND_NONE_BOTTOM: - bShow = sal_False; - break; - } - - try + const SfxPoolItem* pPoolItem = NULL; + if( rInItemSet.GetItemState( SCHATTR_LEGEND_SHOW, TRUE, &pPoolItem ) == SFX_ITEM_SET ) { + sal_Bool bShow = static_cast< const SfxBoolItem * >( pPoolItem )->GetValue(); sal_Bool bWasShown = sal_True; if( ! (GetPropertySet()->getPropertyValue( C2U("Show")) >>= bWasShown) || ( bWasShown != bShow )) @@ -157,25 +126,48 @@ bool LegendItemConverter::ApplySpecialItem( GetPropertySet()->setPropertyValue( C2U("Show"), uno::makeAny( bShow )); bChanged = true; } + } + + } + break; + case SCHATTR_LEGEND_POS: + { + const SfxPoolItem* pPoolItem = NULL; + if( rInItemSet.GetItemState( SCHATTR_LEGEND_POS, TRUE, &pPoolItem ) == SFX_ITEM_SET ) + { + chart2::LegendPosition eNewPos = static_cast<chart2::LegendPosition>(((const SfxInt32Item*)pPoolItem)->GetValue()); - if( bShow ) + ::com::sun::star::chart::ChartLegendExpansion eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH; + switch( eNewPos ) { + case chart2::LegendPosition_LINE_START: + case chart2::LegendPosition_LINE_END: + eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH; + break; + case chart2::LegendPosition_PAGE_START: + case chart2::LegendPosition_PAGE_END: + eExpansion = ::com::sun::star::chart::ChartLegendExpansion_WIDE; + break; + default: + break; + } + + try + { + chart2::LegendPosition eOldPos; if( ! ( GetPropertySet()->getPropertyValue( C2U( "AnchorPosition" )) >>= eOldPos ) || ( eOldPos != eNewPos )) { GetPropertySet()->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( eNewPos )); - chart2::LegendExpansion eExp = bIsWide - ? chart2::LegendExpansion_WIDE - : chart2::LegendExpansion_HIGH; - GetPropertySet()->setPropertyValue( C2U( "Expansion" ), uno::makeAny( eExp )); + GetPropertySet()->setPropertyValue( C2U( "Expansion" ), uno::makeAny( eExpansion )); GetPropertySet()->setPropertyValue( C2U( "RelativePosition" ), uno::Any()); bChanged = true; } } - } - catch( uno::Exception & ex ) - { - ASSERT_EXCEPTION( ex ); + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } } } break; @@ -190,43 +182,18 @@ void LegendItemConverter::FillSpecialItem( { switch( nWhichId ) { - case SCHATTR_LEGEND_POS: + case SCHATTR_LEGEND_SHOW: { - SvxChartLegendPos eItemPos( CHLEGEND_RIGHT ); - chart2::LegendPosition ePos; - sal_Bool bShow = sal_True; GetPropertySet()->getPropertyValue( C2U( "Show" )) >>= bShow; - - if( ! bShow ) - { - eItemPos = CHLEGEND_NONE; - } - else if( GetPropertySet()->getPropertyValue( C2U( "AnchorPosition" )) >>= ePos ) - { - switch( ePos ) - { - case chart2::LegendPosition_LINE_START: - eItemPos = CHLEGEND_LEFT; - break; - case chart2::LegendPosition_LINE_END: - eItemPos = CHLEGEND_RIGHT; - break; - case chart2::LegendPosition_PAGE_START: - eItemPos = CHLEGEND_TOP; - break; - case chart2::LegendPosition_PAGE_END: - eItemPos = CHLEGEND_BOTTOM; - break; - - case chart2::LegendPosition_CUSTOM: - default: - eItemPos = CHLEGEND_RIGHT; - break; - } - } - - rOutItemSet.Put( SvxChartLegendPosItem( eItemPos, SCHATTR_LEGEND_POS ) ); + rOutItemSet.Put( SfxBoolItem(SCHATTR_LEGEND_SHOW, bShow) ); + } + break; + case SCHATTR_LEGEND_POS: + { + chart2::LegendPosition eLegendPos( chart2::LegendPosition_LINE_END ); + GetPropertySet()->getPropertyValue( C2U( "AnchorPosition" )) >>= eLegendPos; + rOutItemSet.Put( SfxInt32Item(SCHATTR_LEGEND_POS, eLegendPos ) ); } break; } diff --git a/chart2/source/controller/main/ChartController_Position.cxx b/chart2/source/controller/main/ChartController_Position.cxx index ceb6877e64e9..11d6c66744da 100644 --- a/chart2/source/controller/main/ChartController_Position.cxx +++ b/chart2/source/controller/main/ChartController_Position.cxx @@ -37,6 +37,7 @@ #include "UndoGuard.hxx" #include "Strings.hrc" #include "ObjectNameProvider.hxx" +#include "DiagramHelper.hxx" #include "chartview/ExplicitValueProvider.hxx" #include "CommonConverters.hxx" #include <svx/ActionDescriptionProvider.hxx> @@ -135,10 +136,12 @@ void SAL_CALL ChartController::executeDispatch_PositionAndSize() if( pProvider ) aSelectedSize = ToSize( ( pProvider->getRectangleOfObject( aCID ) ) ); + ObjectType eObjectType = ObjectIdentifier::getObjectType( aCID ); + UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( ActionDescriptionProvider::POS_SIZE, - ObjectNameProvider::getName( ObjectIdentifier::getObjectType( aCID ))), + ObjectNameProvider::getName( eObjectType)), m_xUndoManager ); SfxAbstractTabDialog * pDlg = NULL; @@ -169,11 +172,14 @@ void SAL_CALL ChartController::executeDispatch_PositionAndSize() awt::Size aPageSize( ChartModelHelper::getPageSize( getModel() ) ); Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height ); - bool bChanged = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID() - , getModel() + bool bChanged = false; + if ( eObjectType == OBJECTTYPE_LEGEND ) + bChanged = DiagramHelper::switchDiagramPositioningToExcludingPositioning( getModel(), false , true ); + + bool bMoved = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID(), getModel() , awt::Rectangle(aObjectRect.getX(),aObjectRect.getY(),aObjectRect.getWidth(),aObjectRect.getHeight()) , awt::Rectangle(aPageRect.getX(),aPageRect.getY(),aPageRect.getWidth(),aPageRect.getHeight()) ); - if( bChanged ) + if( bMoved || bChanged ) aUndoGuard.commit(); } } diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx index 945ccf4b4b34..af48936d33d9 100644 --- a/chart2/source/controller/main/ChartController_Tools.cxx +++ b/chart2/source/controller/main/ChartController_Tools.cxx @@ -251,7 +251,11 @@ void ChartController::executeDispatch_NewArrangement() // legend Reference< beans::XPropertyState > xLegendState( xDiagram->getLegend(), uno::UNO_QUERY ); if( xLegendState.is()) + { xLegendState->setPropertyToDefault( C2U("RelativePosition")); + xLegendState->setPropertyToDefault( C2U("RelativeSize")); + xLegendState->setPropertyToDefault( C2U("AnchorPosition")); + } // titles for( sal_Int32 eType = TitleHelper::TITLE_BEGIN; diff --git a/chart2/source/controller/main/ChartController_Window.cxx b/chart2/source/controller/main/ChartController_Window.cxx index 0a81048d771b..60fd6e6f0d15 100644 --- a/chart2/source/controller/main/ChartController_Window.cxx +++ b/chart2/source/controller/main/ChartController_Window.cxx @@ -871,16 +871,22 @@ void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt ) if( !bIsMoveOnly && m_aSelection.isResizeableObjectSelected() ) eActionType = ActionDescriptionProvider::RESIZE; + ObjectType eObjectType = ObjectIdentifier::getObjectType( m_aSelection.getSelectedCID() ); + UndoGuard aUndoGuard( - ActionDescriptionProvider::createDescription( - eActionType, - ObjectNameProvider::getName( ObjectIdentifier::getObjectType( m_aSelection.getSelectedCID() ))), + ActionDescriptionProvider::createDescription( eActionType, ObjectNameProvider::getName( eObjectType)), m_xUndoManager ); - bool bChanged = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID() + + bool bChanged = false; + if ( eObjectType == OBJECTTYPE_LEGEND ) + bChanged = DiagramHelper::switchDiagramPositioningToExcludingPositioning( getModel(), false , true ); + + bool bMoved = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID() , getModel() , awt::Rectangle(aObjectRect.getX(),aObjectRect.getY(),aObjectRect.getWidth(),aObjectRect.getHeight()) , awt::Rectangle(aPageRect.getX(),aPageRect.getY(),aPageRect.getWidth(),aPageRect.getHeight()) ); - if( bChanged ) + + if( bMoved || bChanged ) { bDraggingDone = true; aUndoGuard.commit(); diff --git a/chart2/source/controller/main/PositionAndSizeHelper.cxx b/chart2/source/controller/main/PositionAndSizeHelper.cxx index f0ce3eaaa04e..bdee4a14f66b 100644 --- a/chart2/source/controller/main/PositionAndSizeHelper.cxx +++ b/chart2/source/controller/main/PositionAndSizeHelper.cxx @@ -33,6 +33,7 @@ #include "ChartModelHelper.hxx" #include "ControllerLockGuard.hxx" #include <com/sun/star/chart2/LegendPosition.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> #include <com/sun/star/chart2/RelativePosition.hpp> #include <com/sun/star/chart2/RelativeSize.hpp> #include "chartview/ExplicitValueProvider.hxx" @@ -83,51 +84,12 @@ bool PositionAndSizeHelper::moveObject( ObjectType eObjectType } else if(OBJECTTYPE_LEGEND==eObjectType) { - LegendPosition ePos = LegendPosition_LINE_END; - xObjectProp->getPropertyValue( C2U( "AnchorPosition" )) >>= ePos; + xObjectProp->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny(LegendPosition(LegendPosition_CUSTOM))); + xObjectProp->setPropertyValue( C2U( "Expansion" ), uno::makeAny(::com::sun::star::chart::ChartLegendExpansion_CUSTOM)); chart2::RelativePosition aRelativePosition; + chart2::RelativeSize aRelativeSize; Point aAnchor = aObjectRect.TopLeft(); - switch( ePos ) - { - case LegendPosition_LINE_START: - { - //@todo language dependent positions ... - aRelativePosition.Anchor = drawing::Alignment_LEFT; - aAnchor = aObjectRect.LeftCenter(); - } - break; - case LegendPosition_LINE_END: - { - //@todo language dependent positions ... - aRelativePosition.Anchor = drawing::Alignment_RIGHT; - aAnchor = aObjectRect.RightCenter(); - } - break; - case LegendPosition_PAGE_START: - { - //@todo language dependent positions ... - aRelativePosition.Anchor = drawing::Alignment_TOP; - aAnchor = aObjectRect.TopCenter(); - } - break; - case LegendPosition_PAGE_END: - //@todo language dependent positions ... - { - aRelativePosition.Anchor = drawing::Alignment_BOTTOM; - aAnchor = aObjectRect.BottomCenter(); - } - break; - case LegendPosition_CUSTOM: - { - //@todo language dependent positions ... - aRelativePosition.Anchor = drawing::Alignment_TOP_LEFT; - } - break; - case LegendPosition_MAKE_FIXED_SIZE: - OSL_ASSERT( false ); - break; - } aRelativePosition.Primary = static_cast< double >( aAnchor.X()) / static_cast< double >( aPageRect.getWidth() ); @@ -136,6 +98,19 @@ bool PositionAndSizeHelper::moveObject( ObjectType eObjectType static_cast< double >( aPageRect.getHeight()); xObjectProp->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition) ); + + aRelativeSize.Primary = + static_cast< double >( aObjectRect.getWidth()) / + static_cast< double >( aPageRect.getWidth() ); + if (aRelativeSize.Primary > 1.0) + aRelativeSize.Primary = 1.0; + aRelativeSize.Secondary = + static_cast< double >( aObjectRect.getHeight()) / + static_cast< double >( aPageRect.getHeight()); + if (aRelativeSize.Secondary > 1.0) + aRelativeSize.Secondary = 1.0; + + xObjectProp->setPropertyValue( C2U( "RelativeSize" ), uno::makeAny(aRelativeSize) ); } else if(OBJECTTYPE_DIAGRAM==eObjectType || OBJECTTYPE_DIAGRAM_WALL==eObjectType || OBJECTTYPE_DIAGRAM_FLOOR==eObjectType) { diff --git a/chart2/source/controller/main/SelectionHelper.cxx b/chart2/source/controller/main/SelectionHelper.cxx index cd51adc7842e..d5dadcf1d800 100644 --- a/chart2/source/controller/main/SelectionHelper.cxx +++ b/chart2/source/controller/main/SelectionHelper.cxx @@ -276,10 +276,11 @@ void Selection::adaptSelectionToNewPos( const Point& rMousePos, DrawViewWrapper* } //check wether the diagram was hit but not selected (e.g. because it has no filling): + rtl::OUString aDiagramCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM, rtl::OUString::valueOf( sal_Int32(0) ) ); rtl::OUString aWallCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, rtl::OUString() ) );//@todo read CID from model - if ( m_aSelectedOID.getObjectCID().equals( aPageCID ) || m_aSelectedOID.getObjectCID().equals( aWallCID ) || !m_aSelectedOID.isAutoGeneratedObject() ) + bool bBackGroundHit = m_aSelectedOID.getObjectCID().equals( aPageCID ) || m_aSelectedOID.getObjectCID().equals( aWallCID ) || !m_aSelectedOID.isAutoGeneratedObject(); + if( bBackGroundHit ) { - rtl::OUString aDiagramCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM, rtl::OUString::valueOf( sal_Int32(0) ) ); //todo: if more than one diagram is available in future do chack the list of all diagrams here SdrObject* pDiagram = pDrawViewWrapper->getNamedSdrObject( aDiagramCID ); if( pDiagram ) @@ -291,6 +292,20 @@ void Selection::adaptSelectionToNewPos( const Point& rMousePos, DrawViewWrapper* } } } + //check wether the legend was hit but not selected (e.g. because it has no filling): + if( bBackGroundHit || m_aSelectedOID.getObjectCID().equals( aDiagramCID ) ) + { + rtl::OUString aLegendCID( ObjectIdentifier::createClassifiedIdentifierForParticle( ObjectIdentifier::createParticleForLegend(0,0) ) );//@todo read CID from model + SdrObject* pLegend = pDrawViewWrapper->getNamedSdrObject( aLegendCID ); + if( pLegend ) + { + if( pDrawViewWrapper->IsObjectHit( pLegend, rMousePos ) ) + { + m_aSelectedOID = ObjectIdentifier( aLegendCID ); + pNewObj = pLegend; + } + } + } } } @@ -309,6 +324,7 @@ bool Selection::isResizeableObjectSelected() case OBJECTTYPE_DIAGRAM: case OBJECTTYPE_DIAGRAM_WALL: case OBJECTTYPE_SHAPE: + case OBJECTTYPE_LEGEND: return true; default: return false; diff --git a/chart2/source/inc/chartview/ChartSfxItemIds.hxx b/chart2/source/inc/chartview/ChartSfxItemIds.hxx index b6390ab12b22..e3846a1d0462 100644 --- a/chart2/source/inc/chartview/ChartSfxItemIds.hxx +++ b/chart2/source/inc/chartview/ChartSfxItemIds.hxx @@ -49,7 +49,8 @@ //legend #define SCHATTR_LEGEND_START (SCHATTR_DATADESCR_END + 1) #define SCHATTR_LEGEND_POS SCHATTR_LEGEND_START -#define SCHATTR_LEGEND_END SCHATTR_LEGEND_POS +#define SCHATTR_LEGEND_SHOW (SCHATTR_LEGEND_START + 1) +#define SCHATTR_LEGEND_END SCHATTR_LEGEND_SHOW //text #define SCHATTR_TEXT_START (SCHATTR_LEGEND_END + 1) diff --git a/chart2/source/model/main/Legend.cxx b/chart2/source/model/main/Legend.cxx index e9f5f5324365..64fb39f91b65 100755 --- a/chart2/source/model/main/Legend.cxx +++ b/chart2/source/model/main/Legend.cxx @@ -40,8 +40,9 @@ #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/awt/Size.hpp> #include <com/sun/star/chart2/LegendPosition.hpp> -#include <com/sun/star/chart2/LegendExpansion.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> #include <com/sun/star/chart2/RelativePosition.hpp> +#include <com/sun/star/chart2/RelativeSize.hpp> #include <algorithm> @@ -63,10 +64,11 @@ static const OUString lcl_aServiceName( enum { PROP_LEGEND_ANCHOR_POSITION, - PROP_LEGEND_PREFERRED_EXPANSION, + PROP_LEGEND_EXPANSION, PROP_LEGEND_SHOW, PROP_LEGEND_REF_PAGE_SIZE, - PROP_LEGEND_REL_POS + PROP_LEGEND_REL_POS, + PROP_LEGEND_REL_SIZE }; void lcl_AddPropertiesToVector( @@ -81,8 +83,8 @@ void lcl_AddPropertiesToVector( rOutProperties.push_back( Property( C2U( "Expansion" ), - PROP_LEGEND_PREFERRED_EXPANSION, - ::getCppuType( reinterpret_cast< const chart2::LegendExpansion * >(0)), + PROP_LEGEND_EXPANSION, + ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartLegendExpansion * >(0)), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEDEFAULT )); @@ -105,6 +107,14 @@ void lcl_AddPropertiesToVector( ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "RelativeSize" ), + PROP_LEGEND_REL_SIZE, + ::getCppuType( reinterpret_cast< const chart2::RelativeSize * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + } struct StaticLegendDefaults_Initializer @@ -123,7 +133,7 @@ private: ::chart::CharacterProperties::AddDefaultsToMap( rOutMap ); ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_ANCHOR_POSITION, chart2::LegendPosition_LINE_END ); - ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_PREFERRED_EXPANSION, chart2::LegendExpansion_HIGH ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_EXPANSION, ::com::sun::star::chart::ChartLegendExpansion_HIGH ); ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_SHOW, true ); float fDefaultCharHeight = 10.0; diff --git a/chart2/source/tools/LegendHelper.cxx b/chart2/source/tools/LegendHelper.cxx index af170e971a5b..aceb033b7919 100755 --- a/chart2/source/tools/LegendHelper.cxx +++ b/chart2/source/tools/LegendHelper.cxx @@ -29,7 +29,7 @@ #include "precompiled_chart2.hxx" #include "LegendHelper.hxx" #include "macros.hxx" -#include <com/sun/star/chart2/LegendExpansion.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> #include <com/sun/star/chart2/LegendPosition.hpp> #include <com/sun/star/chart2/RelativePosition.hpp> #include <com/sun/star/chart2/XChartDocument.hpp> @@ -62,11 +62,11 @@ Reference< chart2::XLegend > LegendHelper::showLegend( const Reference< frame::X if( !(xProp->getPropertyValue( C2U( "AnchorPosition" )) >>= ePos ) ) xProp->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( ePos )); - chart2::LegendExpansion eExpansion = + ::com::sun::star::chart::ChartLegendExpansion eExpansion = ( ePos == chart2::LegendPosition_LINE_END || ePos == chart2::LegendPosition_LINE_START ) - ? chart2::LegendExpansion_HIGH - : chart2::LegendExpansion_WIDE; + ? ::com::sun::star::chart::ChartLegendExpansion_HIGH + : ::com::sun::star::chart::ChartLegendExpansion_WIDE; if( !(xProp->getPropertyValue( C2U( "Expansion" )) >>= eExpansion ) ) xProp->setPropertyValue( C2U( "Expansion" ), uno::makeAny( eExpansion )); diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index c37842e19888..6d3562b10af9 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -1819,7 +1819,7 @@ bool VSeriesPlotter::shouldSnapRectToUsedArea() } Sequence< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntries( - LegendExpansion eLegendExpansion + ::com::sun::star::chart::ChartLegendExpansion eLegendExpansion , const Reference< beans::XPropertySet >& xTextProperties , const Reference< drawing::XShapes >& xTarget , const Reference< lang::XMultiServiceFactory >& xShapeFactory @@ -1865,7 +1865,7 @@ Sequence< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntries( // If the legend is wide and we have a stacked bar-chart the normal order // is the correct one bool bReverse = false; - if( eLegendExpansion != LegendExpansion_WIDE ) + if( eLegendExpansion != ::com::sun::star::chart::ChartLegendExpansion_WIDE ) { StackingDirection eStackingDirection( pSeries->getStackingDirection() ); bReverse = ( eStackingDirection == StackingDirection_Y_STACKING ); diff --git a/chart2/source/view/inc/LegendEntryProvider.hxx b/chart2/source/view/inc/LegendEntryProvider.hxx index 14b6cda47870..ddd4226f3d59 100644 --- a/chart2/source/view/inc/LegendEntryProvider.hxx +++ b/chart2/source/view/inc/LegendEntryProvider.hxx @@ -27,7 +27,7 @@ #ifndef CHART2_VIEW_LEGENDENTRYPROVIDER_HXX #define CHART2_VIEW_LEGENDENTRYPROVIDER_HXX -#include <com/sun/star/chart2/LegendExpansion.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> #ifndef _COM_SUN_STAR_CHART2_VIEWLEGENDENTRYP_HPP_ #include <com/sun/star/chart2/ViewLegendEntry.hpp> @@ -42,7 +42,7 @@ class LegendEntryProvider public: virtual ::com::sun::star::uno::Sequence< ::com::sun::star::chart2::ViewLegendEntry > SAL_CALL createLegendEntries( - ::com::sun::star::chart2::LegendExpansion eLegendExpansion, + ::com::sun::star::chart::ChartLegendExpansion eLegendExpansion, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xTextProperties, const ::com::sun::star::uno::Reference< diff --git a/chart2/source/view/inc/VSeriesPlotter.hxx b/chart2/source/view/inc/VSeriesPlotter.hxx index 8147c3443ec6..232fc8663a77 100644 --- a/chart2/source/view/inc/VSeriesPlotter.hxx +++ b/chart2/source/view/inc/VSeriesPlotter.hxx @@ -209,7 +209,7 @@ public: virtual ::com::sun::star::uno::Sequence< ::com::sun::star::chart2::ViewLegendEntry > SAL_CALL createLegendEntries( - ::com::sun::star::chart2::LegendExpansion eLegendExpansion, + ::com::sun::star::chart::ChartLegendExpansion eLegendExpansion, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xTextProperties, const ::com::sun::star::uno::Reference< diff --git a/chart2/source/view/main/ChartItemPool.cxx b/chart2/source/view/main/ChartItemPool.cxx index fe83c0eea7e2..5cb17abf71b2 100644 --- a/chart2/source/view/main/ChartItemPool.cxx +++ b/chart2/source/view/main/ChartItemPool.cxx @@ -44,6 +44,8 @@ #include <editeng/editids.hrc> #include <svx/svxids.hrc> +#include <com/sun/star/chart2/LegendPosition.hpp> + namespace chart { @@ -69,7 +71,8 @@ ChartItemPool::ChartItemPool(): ppPoolDefaults[SCHATTR_PERCENT_NUMBERFORMAT_SOURCE - SCHATTR_START] = new SfxBoolItem(SCHATTR_PERCENT_NUMBERFORMAT_SOURCE); //legend - ppPoolDefaults[SCHATTR_LEGEND_POS - SCHATTR_START] = new SvxChartLegendPosItem( CHLEGEND_RIGHT, SCHATTR_LEGEND_POS ); + ppPoolDefaults[SCHATTR_LEGEND_POS - SCHATTR_START] = new SfxInt32Item(SCHATTR_LEGEND_POS, ::com::sun::star::chart2::LegendPosition_LINE_END ); + ppPoolDefaults[SCHATTR_LEGEND_SHOW - SCHATTR_START] = new SfxBoolItem(SCHATTR_LEGEND_SHOW, TRUE); //text ppPoolDefaults[SCHATTR_TEXT_DEGREES - SCHATTR_START] = new SfxInt32Item(SCHATTR_TEXT_DEGREES, 0); diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx index fbc74bad05a5..f78a102d50b1 100644 --- a/chart2/source/view/main/VLegend.cxx +++ b/chart2/source/view/main/VLegend.cxx @@ -36,13 +36,14 @@ #include "ShapeFactory.hxx" #include "RelativeSizeHelper.hxx" #include "LegendEntryProvider.hxx" +#include "chartview/DrawModelWrapper.hxx" #include <com/sun/star/text/XTextRange.hpp> #include <com/sun/star/text/WritingMode2.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertyState.hpp> #include <com/sun/star/drawing/TextHorizontalAdjust.hpp> #include <com/sun/star/drawing/LineJoint.hpp> -#include <com/sun/star/chart2/LegendExpansion.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> #include <com/sun/star/chart2/LegendPosition.hpp> #include <com/sun/star/chart2/RelativePosition.hpp> #include <rtl/ustrbuf.hxx> @@ -123,7 +124,6 @@ void lcl_getProperties( const Reference< beans::XPropertySet > & xLegendProp, tPropertyValues & rOutLineFillProperties, tPropertyValues & rOutTextProperties, - sal_Int32 nMaxLabelWidth, const awt::Size & rReferenceSize ) { // Get Line- and FillProperties from model legend @@ -146,7 +146,7 @@ void lcl_getProperties( aTextValueMap[ C2U("TextAutoGrowHeight") ] = uno::makeAny( sal_True ); aTextValueMap[ C2U("TextAutoGrowWidth") ] = uno::makeAny( sal_True ); aTextValueMap[ C2U("TextHorizontalAdjust") ] = uno::makeAny( eHorizAdjust ); - aTextValueMap[ C2U("TextMaximumFrameWidth") ] = uno::makeAny( nMaxLabelWidth ); + aTextValueMap[ C2U("TextMaximumFrameWidth") ] = uno::makeAny( rReferenceSize.Width ); //needs to be overwritten by actual available space in the legend // recalculate font size awt::Size aPropRefSize; @@ -193,16 +193,10 @@ awt::Size lcl_createTextShapes( try { // create label shape - Reference< drawing::XShape > xGroupShapeForSingleEntry( - xShapeFactory->createInstance( - C2U( "com.sun.star.drawing.GroupShape" )), uno::UNO_QUERY_THROW ); - Reference< drawing::XShape >xEntry( + Reference< drawing::XShape > xEntry( xShapeFactory->createInstance( C2U( "com.sun.star.drawing.TextShape" )), uno::UNO_QUERY_THROW ); - xTarget->add( xGroupShapeForSingleEntry ); - - Reference< drawing::XShapes > xGroup( xGroupShapeForSingleEntry, uno::UNO_QUERY_THROW ); - xGroup->add( xEntry ); + xTarget->add( xEntry ); // set label text Sequence< Reference< XFormattedString > > aLabelSeq = (*aIt).aLabel; @@ -230,7 +224,7 @@ awt::Size lcl_createTextShapes( aResult.Height = ::std::max( aResult.Height, aCurrSize.Height ); } - rOutTextShapes.push_back( xGroupShapeForSingleEntry ); + rOutTextShapes.push_back( xEntry ); } catch( uno::Exception & ex ) { @@ -241,20 +235,89 @@ awt::Size lcl_createTextShapes( return aResult; } +void lcl_collectColumnWidths( std::vector< sal_Int32 >& rColumnWidths, const sal_Int32 nNumberOfRows, const sal_Int32 nNumberOfColumns + , const ::std::vector< Reference< drawing::XShape > > aTextShapes, const awt::Size& aMaxSymbolExtent ) +{ + rColumnWidths.clear(); + sal_Int32 nRow = 0; + sal_Int32 nColumn = 0; + sal_Int32 nNumberOfEntries = aTextShapes.size(); + for( ; nRow < nNumberOfRows; ++nRow ) + { + for( nColumn = 0; nColumn < nNumberOfColumns; ++nColumn ) + { + sal_Int32 nEntry = (nColumn + nRow * nNumberOfColumns); + if( nEntry < nNumberOfEntries ) + { + awt::Size aTextSize( aTextShapes[ nEntry ]->getSize() ); + sal_Int32 nWidth = aMaxSymbolExtent.Width + aTextSize.Width; + if( nRow==0 ) + rColumnWidths.push_back( nWidth ); + else + rColumnWidths[nColumn] = ::std::max( nWidth, rColumnWidths[nColumn] ); + } + } + } +} -void lcl_placeLegendEntries( - const tViewLegendEntryContainer & rEntries, - LegendExpansion eExpansion, +void lcl_collectRowHeighs( std::vector< sal_Int32 >& rRowHeights, const sal_Int32 nNumberOfRows, const sal_Int32 nNumberOfColumns + , const ::std::vector< Reference< drawing::XShape > > aTextShapes ) +{ + // calculate maximum height for each row + // and collect column widths + rRowHeights.clear(); + sal_Int32 nRow = 0; + sal_Int32 nColumn = 0; + sal_Int32 nNumberOfEntries = aTextShapes.size(); + for( ; nRow < nNumberOfRows; ++nRow ) + { + sal_Int32 nCurrentRowHeight = 0; + for( nColumn = 0; nColumn < nNumberOfColumns; ++nColumn ) + { + sal_Int32 nEntry = (nColumn + nRow * nNumberOfColumns); + if( nEntry < nNumberOfEntries ) + { + awt::Size aTextSize( aTextShapes[ nEntry ]->getSize() ); + nCurrentRowHeight = ::std::max( nCurrentRowHeight, aTextSize.Height ); + } + } + rRowHeights.push_back( nCurrentRowHeight ); + } +} + +sal_Int32 lcl_getTextLineHeight( const std::vector< sal_Int32 >& aRowHeights, const sal_Int32 nNumberOfRows, double fViewFontSize ) +{ + const sal_Int32 nFontHeight = static_cast< sal_Int32 >( fViewFontSize ); + sal_Int32 nTextLineHeight = nFontHeight; + for( sal_Int32 nR=0; nR<nNumberOfRows; nR++ ) + { + sal_Int32 nFullTextHeight = aRowHeights[ nR ]; + if( ( nFullTextHeight / nFontHeight ) <= 1 ) + { + nTextLineHeight = nFullTextHeight;//found an entry with one line-> have real text height + break; + } + } + return nTextLineHeight; +} + +//returns resulting legend size +awt::Size lcl_placeLegendEntries( + tViewLegendEntryContainer & rEntries, + ::com::sun::star::chart::ChartLegendExpansion eExpansion, bool bSymbolsLeftSide, const Reference< beans::XPropertySet > & xProperties, tPropertyValues & rTextProperties, const Reference< drawing::XShapes > & xTarget, const Reference< lang::XMultiServiceFactory > & xShapeFactory, - const Reference< uno::XComponentContext > & /* xContext */, const awt::Size & rAvailableSpace, - const awt::Size & rPageSize, - awt::Size & rOutLegendSize ) + const awt::Size & rPageSize ) { + bool bIsCustomSize = (eExpansion == ::com::sun::star::chart::ChartLegendExpansion_CUSTOM); + awt::Size aResultingLegendSize(0,0); + if( bIsCustomSize ) + aResultingLegendSize = rAvailableSpace; + //todo double fViewFontSize = lcl_CalcViewFontSize( xProperties, rPageSize ); // padding as percentage of the font height @@ -264,34 +327,188 @@ void lcl_placeLegendEntries( double fXOffset = 0.15; double fYOffset = 0.15; - const sal_Int32 nXPadding = static_cast< sal_Int32 >( fViewFontSize * fXPadding ); - const sal_Int32 nYPadding = static_cast< sal_Int32 >( fViewFontSize * fYPadding ); - const sal_Int32 nXOffset = static_cast< sal_Int32 >( fViewFontSize * fXOffset ); - const sal_Int32 nYOffset = static_cast< sal_Int32 >( fViewFontSize * fYOffset ); - - ::std::vector< Reference< drawing::XShape > > aTextShapes; - awt::Size aMaxEntryExtent = lcl_createTextShapes( - rEntries, xShapeFactory, xTarget, aTextShapes, rTextProperties ); - OSL_ASSERT( aTextShapes.size() == rEntries.size()); + sal_Int32 nXPadding = static_cast< sal_Int32 >( fViewFontSize * fXPadding ); + sal_Int32 nYPadding = static_cast< sal_Int32 >( fViewFontSize * fYPadding ); + sal_Int32 nXOffset = static_cast< sal_Int32 >( fViewFontSize * fXOffset ); + sal_Int32 nYOffset = static_cast< sal_Int32 >( fViewFontSize * fYOffset ); // #i109336# Improve auto positioning in chart double fSymbolSizeFraction = 0.8; awt::Size aMaxSymbolExtent( static_cast< sal_Int32 >( fViewFontSize * fSymbolSizeFraction * 3.0 / 2.0 ), static_cast< sal_Int32 >( fViewFontSize * fSymbolSizeFraction ) ); - sal_Int32 nCurrentXPos = nXPadding; - sal_Int32 nCurrentYPos = nYPadding; + sal_Int32 nMaxTextWidth = rAvailableSpace.Width - (2 * nXOffset) - aMaxSymbolExtent.Width; + rtl::OUString aPropNameTextMaximumFrameWidth( C2U("TextMaximumFrameWidth") ); + uno::Any* pFrameWidthAny = PropertyMapper::getValuePointer( rTextProperties.second, rTextProperties.first, aPropNameTextMaximumFrameWidth); + if(pFrameWidthAny) + { + if( eExpansion == ::com::sun::star::chart::ChartLegendExpansion_HIGH ) + { + // limit the width of texts to 30% of the total available width + // #i109336# Improve auto positioning in chart + nMaxTextWidth = rAvailableSpace.Width * 3 / 10; + } + *pFrameWidthAny = uno::makeAny(nMaxTextWidth); + } + + ::std::vector< Reference< drawing::XShape > > aTextShapes; + awt::Size aMaxEntryExtent = lcl_createTextShapes( rEntries, xShapeFactory, xTarget, aTextShapes, rTextProperties ); + OSL_ASSERT( aTextShapes.size() == rEntries.size()); + sal_Int32 nMaxEntryWidth = 2 * nXOffset + aMaxSymbolExtent.Width + aMaxEntryExtent.Width; sal_Int32 nMaxEntryHeight = nYOffset + aMaxEntryExtent.Height; sal_Int32 nNumberOfEntries = rEntries.size(); - if( !bSymbolsLeftSide ) - nCurrentXPos = -nXPadding; - sal_Int32 nNumberOfColumns = 0, nNumberOfRows = 0; + std::vector< sal_Int32 > aColumnWidths; + std::vector< sal_Int32 > aRowHeights; + + sal_Int32 nTextLineHeight = static_cast< sal_Int32 >( fViewFontSize ); // determine layout depending on LegendExpansion - if( eExpansion == LegendExpansion_HIGH ) + if( eExpansion == ::com::sun::star::chart::ChartLegendExpansion_CUSTOM ) + { + sal_Int32 nCurrentRow=0; + sal_Int32 nCurrentColumn=-1; + sal_Int32 nColumnCount=0; + sal_Int32 nMaxColumnCount=-1; + for( sal_Int32 nN=0; nN<static_cast<sal_Int32>(aTextShapes.size()); nN++ ) + { + Reference< drawing::XShape > xShape( aTextShapes[nN] ); + if( !xShape.is() ) + continue; + awt::Size aSize( xShape->getSize() ); + sal_Int32 nNewWidth = aSize.Width + aMaxSymbolExtent.Width; + sal_Int32 nCurrentColumnCount = aColumnWidths.size(); + + //are we allowed to add a new column? + if( nMaxColumnCount==-1 || (nCurrentColumn+1) < nMaxColumnCount ) + { + //try add a new column + nCurrentColumn++; + if( nCurrentColumn < nCurrentColumnCount ) + { + //check wether the current column width is sufficient for the new entry + if( aColumnWidths[nCurrentColumn]>=nNewWidth ) + { + //all good proceed with next entry + continue; + } + } + if( nCurrentColumn < nCurrentColumnCount ) + aColumnWidths[nCurrentColumn] = std::max( nNewWidth, aColumnWidths[nCurrentColumn] ); + else + aColumnWidths.push_back(nNewWidth); + + //do the columns still fit into the given size? + nCurrentColumnCount = aColumnWidths.size();//update count + sal_Int32 nSumWidth = 0; + for( sal_Int32 nC=0; nC<nCurrentColumnCount; nC++ ) + nSumWidth += aColumnWidths[nC]; + + if( nSumWidth <= rAvailableSpace.Width || nCurrentColumnCount==1 ) + { + //all good proceed with next entry + continue; + } + else + { + //not enough space for the current amount of columns + //try again with less columns + nMaxColumnCount = nCurrentColumnCount-1; + nN=-1; + nCurrentRow=0; + nCurrentColumn=-1; + nColumnCount=0; + aColumnWidths.clear(); + } + } + else + { + //add a new row and try the same entry again + nCurrentRow++; + nCurrentColumn=-1; + nN--; + } + } + nNumberOfColumns = aColumnWidths.size(); + nNumberOfRows = nCurrentRow+1; + + //check if there is not enough space so that some entries must be removed + lcl_collectRowHeighs( aRowHeights, nNumberOfRows, nNumberOfColumns, aTextShapes ); + nTextLineHeight = lcl_getTextLineHeight( aRowHeights, nNumberOfRows, fViewFontSize ); + sal_Int32 nSumHeight = 0; + for( sal_Int32 nR=0; nR<nNumberOfRows; nR++ ) + nSumHeight += aRowHeights[nR]; + sal_Int32 nRemainingSpace = rAvailableSpace.Height - nSumHeight; + + if( nRemainingSpace<0 ) + { + //remove entries that are too big + for( sal_Int32 nR=nNumberOfRows; nR--; ) + { + for( sal_Int32 nC=nNumberOfColumns; nC--; ) + { + sal_Int32 nEntry = (nC + nR * nNumberOfColumns); + if( nEntry < static_cast<sal_Int32>(aTextShapes.size()) ) + { + DrawModelWrapper::removeShape( aTextShapes[nEntry] ); + aTextShapes.pop_back(); + } + if( nEntry < static_cast<sal_Int32>(rEntries.size()) ) + { + DrawModelWrapper::removeShape( rEntries[ nEntry ].aSymbol ); + rEntries.pop_back(); + } + } + nSumHeight -= aRowHeights[nR]; + aRowHeights.pop_back(); + nRemainingSpace = rAvailableSpace.Height - nSumHeight; + if( nRemainingSpace>=0 ) + break; + } + nNumberOfRows = static_cast<sal_Int32>(aRowHeights.size()); + } + if( nRemainingSpace > 0 ) + { + sal_Int32 nNormalSpacingHeight = 2*nYPadding+(nNumberOfRows-1)*nYOffset; + if( nRemainingSpace < nNormalSpacingHeight ) + { + //reduce spacing between the entries + nYPadding = nYOffset = nRemainingSpace/(nNumberOfRows+1); + } + else + { + //we have some space left that should be spread equally between all rows + sal_Int32 nRemainingSingleSpace = (nRemainingSpace-nNormalSpacingHeight)/(nNumberOfRows+1); + nYPadding += nRemainingSingleSpace; + nYOffset += nRemainingSingleSpace; + } + } + + //check spacing between columns + sal_Int32 nSumWidth = 0; + for( sal_Int32 nC=0; nC<nNumberOfColumns; nC++ ) + nSumWidth += aColumnWidths[nC]; + nRemainingSpace = rAvailableSpace.Width - nSumWidth; + if( nRemainingSpace>=0 ) + { + sal_Int32 nNormalSpacingWidth = 2*nXPadding+(nNumberOfColumns-1)*nXOffset; + if( nRemainingSpace < nNormalSpacingWidth ) + { + //reduce spacing between the entries + nXPadding = nXOffset = nRemainingSpace/(nNumberOfColumns+1); + } + else + { + //we have some space left that should be spread equally between all columns + sal_Int32 nRemainingSingleSpace = (nRemainingSpace-nNormalSpacingWidth)/(nNumberOfColumns+1); + nXPadding += nRemainingSingleSpace; + nXOffset += nRemainingSingleSpace; + } + } + } + else if( eExpansion == ::com::sun::star::chart::ChartLegendExpansion_HIGH ) { sal_Int32 nMaxNumberOfRows = nMaxEntryHeight ? (rAvailableSpace.Height - 2*nYPadding ) / nMaxEntryHeight @@ -308,7 +525,7 @@ void lcl_placeLegendEntries( static_cast< double >( nNumberOfColumns ) )) : 0; } - else if( eExpansion == LegendExpansion_WIDE ) + else if( eExpansion == ::com::sun::star::chart::ChartLegendExpansion_WIDE ) { sal_Int32 nMaxNumberOfColumns = nMaxEntryWidth ? (rAvailableSpace.Width - 2*nXPadding ) / nMaxEntryWidth @@ -325,7 +542,7 @@ void lcl_placeLegendEntries( static_cast< double >( nNumberOfRows ) )) : 0; } - else // LegendExpansion_BALANCED + else // ::com::sun::star::chart::ChartLegendExpansion_BALANCED { double fAspect = nMaxEntryHeight ? static_cast< double >( nMaxEntryWidth ) / static_cast< double >( nMaxEntryHeight ) @@ -341,52 +558,49 @@ void lcl_placeLegendEntries( } if(nNumberOfRows<=0) - return; + return aResultingLegendSize; - // calculate maximum height for current row - std::vector< sal_Int32 > nMaxHeights( nNumberOfRows ); - sal_Int32 nRow = 0; - sal_Int32 nColumn = 0; - for( ; nRow < nNumberOfRows; ++nRow ) + if( eExpansion != ::com::sun::star::chart::ChartLegendExpansion_CUSTOM ) { - sal_Int32 nMaxHeight = 0; - for( nColumn = 0; nColumn < nNumberOfColumns; ++nColumn ) - { - sal_Int32 nEntry = ( eExpansion == LegendExpansion_WIDE ) - ? (nColumn + nRow * nNumberOfColumns) - // HIGH or BALANCED - : (nRow + nColumn * nNumberOfRows); - if( nEntry < nNumberOfEntries ) - nMaxHeight = ::std::max( - nMaxHeight, nYOffset + aTextShapes[ nEntry ]->getSize().Height ); - } - nMaxHeights[ nRow ] = nMaxHeight; + lcl_collectColumnWidths( aColumnWidths, nNumberOfRows, nNumberOfColumns, aTextShapes, aMaxSymbolExtent ); + lcl_collectRowHeighs( aRowHeights, nNumberOfRows, nNumberOfColumns, aTextShapes ); + nTextLineHeight = lcl_getTextLineHeight( aRowHeights, nNumberOfRows, fViewFontSize ); } - // place entries ordered in optimal-width columns + sal_Int32 nCurrentXPos = nXPadding; + sal_Int32 nCurrentYPos = nYPadding; + if( !bSymbolsLeftSide ) + nCurrentXPos = -nXPadding; + + // place entries into column and rows sal_Int32 nMaxYPos = 0; + sal_Int32 nRow = 0; + sal_Int32 nColumn = 0; for( nColumn = 0; nColumn < nNumberOfColumns; ++nColumn ) { - sal_Int32 nMaxWidth = 0; nCurrentYPos = nYPadding; - for( nRow = 0; nRow < nNumberOfRows; ++nRow ) { - sal_Int32 nEntry = ( eExpansion == LegendExpansion_WIDE ) - ? (nColumn + nRow * nNumberOfColumns) - // HIGH or BALANCED - : (nRow + nColumn * nNumberOfRows); - + sal_Int32 nEntry = (nColumn + nRow * nNumberOfColumns); if( nEntry >= nNumberOfEntries ) break; + // text shape + Reference< drawing::XShape > xTextShape( aTextShapes[nEntry] ); + if( xTextShape.is() ) + { + awt::Size aTextSize( xTextShape->getSize() ); + sal_Int32 nTextXPos = nCurrentXPos + aMaxSymbolExtent.Width; + if( !bSymbolsLeftSide ) + nTextXPos = nCurrentXPos - aMaxSymbolExtent.Width - aTextSize.Width; + xTextShape->setPosition( awt::Point( nTextXPos, nCurrentYPos )); + } + // symbol Reference< drawing::XShape > xSymbol( rEntries[ nEntry ].aSymbol ); - if( xSymbol.is() ) { // Note: aspect ratio should always be 3:2 - // set symbol size to 75% of maximum space awt::Size aSymbolSize( aMaxSymbolExtent.Width * 75 / 100, @@ -396,38 +610,34 @@ void lcl_placeLegendEntries( if( !bSymbolsLeftSide ) nSymbolXPos = nSymbolXPos - aMaxSymbolExtent.Width; - // #i109336# Improve auto positioning in chart - sal_Int32 nTextHeight = nMaxHeights[ nRow ] - nYOffset; - sal_Int32 nFontSize = static_cast< sal_Int32 >( fViewFontSize ); - sal_Int32 nMaxRowHeight = ( ( ( nTextHeight / nFontSize ) <= 1 ) ? nTextHeight : nFontSize ); - sal_Int32 nSymbolYPos = nCurrentYPos + ( ( nMaxRowHeight - aSymbolSize.Height ) / 2 ); + sal_Int32 nSymbolYPos = nCurrentYPos + ( ( nTextLineHeight - aSymbolSize.Height ) / 2 ); xSymbol->setPosition( awt::Point( nSymbolXPos, nSymbolYPos ) ); } - // position text shape - awt::Size aTextSize( aTextShapes[ nEntry ]->getSize()); - nMaxWidth = ::std::max( nMaxWidth, 2 * nXOffset + aMaxSymbolExtent.Width + aTextSize.Width ); - sal_Int32 nTextXPos = nCurrentXPos + aMaxSymbolExtent.Width; - if( !bSymbolsLeftSide ) - nTextXPos = nCurrentXPos - aMaxSymbolExtent.Width - aTextSize.Width; - aTextShapes[ nEntry ]->setPosition( awt::Point( nTextXPos, nCurrentYPos )); - - nCurrentYPos += nMaxHeights[ nRow ]; + nCurrentYPos += aRowHeights[ nRow ] + nYOffset; nMaxYPos = ::std::max( nMaxYPos, nCurrentYPos ); } if( bSymbolsLeftSide ) - nCurrentXPos += nMaxWidth; + nCurrentXPos += ( aColumnWidths[nColumn] + nXOffset ); else - nCurrentXPos -= nMaxWidth; + nCurrentXPos -= ( aColumnWidths[nColumn] + nXOffset ); } - if( bSymbolsLeftSide ) - rOutLegendSize.Width = nCurrentXPos + nXPadding; - else + if( !bIsCustomSize ) { - sal_Int32 nLegendWidth = -(nCurrentXPos-nXPadding); - rOutLegendSize.Width = nLegendWidth; + if( bSymbolsLeftSide ) + aResultingLegendSize.Width = nCurrentXPos + nXPadding; + else + { + sal_Int32 nLegendWidth = -(nCurrentXPos-nXPadding); + aResultingLegendSize.Width = nLegendWidth; + } + aResultingLegendSize.Height = nMaxYPos + nYPadding; + } + if( !bSymbolsLeftSide ) + { + sal_Int32 nLegendWidth = aResultingLegendSize.Width; awt::Point aPos(0,0); for( sal_Int32 nEntry=0; nEntry<nNumberOfEntries; nEntry++ ) { @@ -441,7 +651,8 @@ void lcl_placeLegendEntries( xText->setPosition( aPos ); } } - rOutLegendSize.Height = nMaxYPos + nYPadding; + + return aResultingLegendSize; } // #i109336# Improve auto positioning in chart @@ -706,23 +917,26 @@ void VLegend::createShapes( tPropertyValues aLineFillProperties; tPropertyValues aTextProperties; - // limit the width of texts to 30% of the total available width - // #i109336# Improve auto positioning in chart - sal_Int32 nMaxLabelWidth = rAvailableSpace.Width * 3 / 10; Reference< beans::XPropertySet > xLegendProp( m_xLegend, uno::UNO_QUERY ); - LegendExpansion eExpansion = LegendExpansion_HIGH; + ::com::sun::star::chart::ChartLegendExpansion eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH; + awt::Size aLegendSize( rAvailableSpace ); + if( xLegendProp.is()) { // get Expansion property xLegendProp->getPropertyValue( C2U( "Expansion" )) >>= eExpansion; - if( eExpansion == LegendExpansion_WIDE ) + if( eExpansion == ::com::sun::star::chart::ChartLegendExpansion_CUSTOM ) { - //#i80377# - nMaxLabelWidth = (rAvailableSpace.Width * 5) / 6;//completely correct would be available width minus symbol size minus distances to page ... + RelativeSize aRelativeSize; + if ((xLegendProp->getPropertyValue( C2U( "RelativeSize" )) >>= aRelativeSize)) + { + aLegendSize.Width = aRelativeSize.Primary * rPageSize.Width; + aLegendSize.Height = aRelativeSize.Secondary * rPageSize.Height; + } + else + eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH; } - - lcl_getProperties( xLegendProp, aLineFillProperties, aTextProperties, nMaxLabelWidth, - rPageSize ); + lcl_getProperties( xLegendProp, aLineFillProperties, aTextProperties, rPageSize ); } if( xBorder.is()) @@ -758,13 +972,11 @@ void VLegend::createShapes( bool bSymbolsLeftSide = lcl_shouldSymbolsBePlacedOnTheLeftSide( xLegendProp, m_nDefaultWritingMode ); // place entries - awt::Size aLegendSize; - lcl_placeLegendEntries( aViewEntries, eExpansion, bSymbolsLeftSide - , xLegendProp, aTextProperties - , xLegendContainer, m_xShapeFactory, m_xContext - , rAvailableSpace, rPageSize, aLegendSize ); + aLegendSize = lcl_placeLegendEntries( aViewEntries, eExpansion, bSymbolsLeftSide + , xLegendProp, aTextProperties, xLegendContainer, m_xShapeFactory + , aLegendSize, rPageSize ); - if( xBorder.is()) + if( xBorder.is() ) xBorder->setSize( aLegendSize ); } } diff --git a/sc/source/filter/excel/xechart.cxx b/sc/source/filter/excel/xechart.cxx index 0d04255f0141..07b4a76a9c82 100644 --- a/sc/source/filter/excel/xechart.cxx +++ b/sc/source/filter/excel/xechart.cxx @@ -36,6 +36,7 @@ #include <com/sun/star/drawing/XShapes.hpp> #include <com/sun/star/chart/ChartAxisLabelPosition.hpp> #include <com/sun/star/chart/ChartAxisPosition.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> #include <com/sun/star/chart/DataLabelPlacement.hpp> #include <com/sun/star/chart/ErrorBarStyle.hpp> #include <com/sun/star/chart/MissingValueTreatment.hpp> @@ -57,9 +58,9 @@ #include <com/sun/star/chart2/CurveStyle.hpp> #include <com/sun/star/chart2/DataPointGeometry3D.hpp> #include <com/sun/star/chart2/DataPointLabel.hpp> -#include <com/sun/star/chart2/LegendExpansion.hpp> #include <com/sun/star/chart2/LegendPosition.hpp> #include <com/sun/star/chart2/RelativePosition.hpp> +#include <com/sun/star/chart2/RelativeSize.hpp> #include <com/sun/star/chart2/StackingDirection.hpp> #include <com/sun/star/chart2/TickmarkStyle.hpp> @@ -94,6 +95,7 @@ using ::com::sun::star::drawing::XShapes; using ::com::sun::star::chart2::IncrementData; using ::com::sun::star::chart2::RelativePosition; +using ::com::sun::star::chart2::RelativeSize; using ::com::sun::star::chart2::ScaleData; using ::com::sun::star::chart2::SubIncrement; using ::com::sun::star::chart2::XAxis; @@ -820,6 +822,12 @@ void XclExpChFrame::Convert( const ScfPropertySet& rPropSet ) ConvertFrameBase( GetChRoot(), rPropSet, meObjType ); } +void XclExpChFrame::SetAutoFlags( bool bAutoPos, bool bAutoSize ) +{ + ::set_flag( maData.mnFlags, EXC_CHFRAME_AUTOPOS, bAutoPos ); + ::set_flag( maData.mnFlags, EXC_CHFRAME_AUTOSIZE, bAutoSize ); +} + bool XclExpChFrame::IsDefault() const { return IsDefaultFrameBase( GetFormatInfo( meObjType ).meDefFrameType ); @@ -2287,33 +2295,52 @@ void XclExpChLegend::Convert( const ScfPropertySet& rPropSet ) mxText.reset( new XclExpChText( GetChRoot() ) ); mxText->ConvertLegend( rPropSet ); - // legend position - Any aRelPosAny; + // legend position and size + Any aRelPosAny, aRelSizeAny; rPropSet.GetAnyProperty( aRelPosAny, EXC_CHPROP_RELATIVEPOSITION ); - if( aRelPosAny.has< RelativePosition >() ) + rPropSet.GetAnyProperty( aRelSizeAny, EXC_CHPROP_RELATIVESIZE ); + cssc::ChartLegendExpansion eApiExpand = cssc::ChartLegendExpansion_CUSTOM; + rPropSet.GetProperty( eApiExpand, EXC_CHPROP_EXPANSION ); + if( aRelPosAny.has< RelativePosition >() || ((eApiExpand == cssc::ChartLegendExpansion_CUSTOM) && aRelSizeAny.has< RelativeSize >()) ) { try { - /* The 'RelativePosition' property is used as indicator of manually - changed legend position, but due to the different anchor modes - used by this property (in the RelativePosition.Anchor member) - it cannot be used to calculate the position easily. For this, - the Chart1 API will be used instead. */ + /* The 'RelativePosition' or 'RelativeSize' properties are used as + indicator of manually changed legend position/size, but due to + the different anchor modes used by this property (in the + RelativePosition.Anchor member) it cannot be used to calculate + the position easily. For this, the Chart1 API will be used + instead. */ Reference< cssc::XChartDocument > xChart1Doc( GetChartDocument(), UNO_QUERY_THROW ); Reference< XShape > xChart1Legend( xChart1Doc->getLegend(), UNO_SET_THROW ); // coordinates in CHLEGEND record written but not used by Excel mxFramePos.reset( new XclExpChFramePos( EXC_CHFRAMEPOS_CHARTSIZE, EXC_CHFRAMEPOS_PARENT ) ); XclChFramePos& rFramePos = mxFramePos->GetFramePosData(); - rFramePos.maRect.mnX = maData.maRect.mnX = CalcChartXFromHmm( xChart1Legend->getPosition().X ); - rFramePos.maRect.mnY = maData.maRect.mnY = CalcChartYFromHmm( xChart1Legend->getPosition().Y ); + rFramePos.mnTLMode = EXC_CHFRAMEPOS_CHARTSIZE; + ::com::sun::star::awt::Point aLegendPos = xChart1Legend->getPosition(); + rFramePos.maRect.mnX = maData.maRect.mnX = CalcChartXFromHmm( aLegendPos.X ); + rFramePos.maRect.mnY = maData.maRect.mnY = CalcChartYFromHmm( aLegendPos.Y ); + // legend size, Excel expects points in CHFRAMEPOS record + rFramePos.mnBRMode = EXC_CHFRAMEPOS_ABSSIZE_POINTS; + ::com::sun::star::awt::Size aLegendSize = xChart1Legend->getSize(); + rFramePos.maRect.mnWidth = static_cast< sal_uInt16 >( aLegendSize.Width * EXC_POINTS_PER_HMM + 0.5 ); + rFramePos.maRect.mnHeight = static_cast< sal_uInt16 >( aLegendSize.Height * EXC_POINTS_PER_HMM + 0.5 ); + maData.maRect.mnWidth = CalcChartXFromHmm( aLegendSize.Width ); + maData.maRect.mnHeight = CalcChartYFromHmm( aLegendSize.Height ); + eApiExpand = cssc::ChartLegendExpansion_CUSTOM; // manual legend position implies manual plot area GetChartData().SetManualPlotArea(); maData.mnDockMode = EXC_CHLEGEND_NOTDOCKED; + // a CHFRAME record with cleared auto flags is needed + if( !mxFrame ) + mxFrame.reset( new XclExpChFrame( GetChRoot(), EXC_CHOBJTYPE_LEGEND ) ); + mxFrame->SetAutoFlags( false, false ); } catch( Exception& ) { OSL_ENSURE( false, "XclExpChLegend::Convert - cannot get legend shape" ); maData.mnDockMode = EXC_CHLEGEND_RIGHT; + eApiExpand = cssc::ChartLegendExpansion_HIGH; } } else @@ -2329,13 +2356,10 @@ void XclExpChLegend::Convert( const ScfPropertySet& rPropSet ) default: OSL_ENSURE( false, "XclExpChLegend::Convert - unrecognized legend position" ); maData.mnDockMode = EXC_CHLEGEND_RIGHT; + eApiExpand = cssc::ChartLegendExpansion_HIGH; } } - - // legend expansion - cssc2::LegendExpansion eApiExpand = cssc2::LegendExpansion_BALANCED; - rPropSet.GetProperty( eApiExpand, EXC_CHPROP_EXPANSION ); - ::set_flag( maData.mnFlags, EXC_CHLEGEND_STACKED, eApiExpand != cssc2::LegendExpansion_WIDE ); + ::set_flag( maData.mnFlags, EXC_CHLEGEND_STACKED, eApiExpand == cssc::ChartLegendExpansion_HIGH ); // other flags ::set_flag( maData.mnFlags, EXC_CHLEGEND_AUTOSERIES ); diff --git a/sc/source/filter/excel/xichart.cxx b/sc/source/filter/excel/xichart.cxx index 8a5084be8bfc..4c2c22be6a9c 100644 --- a/sc/source/filter/excel/xichart.cxx +++ b/sc/source/filter/excel/xichart.cxx @@ -43,6 +43,7 @@ #include <com/sun/star/chart/ChartAxisLabelPosition.hpp> #include <com/sun/star/chart/ChartAxisMarkPosition.hpp> #include <com/sun/star/chart/ChartAxisPosition.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> #include <com/sun/star/chart/TimeInterval.hpp> #include <com/sun/star/chart/TimeUnit.hpp> #include <com/sun/star/chart/XChartDocument.hpp> @@ -61,11 +62,11 @@ #include <com/sun/star/chart2/CurveStyle.hpp> #include <com/sun/star/chart2/DataPointGeometry3D.hpp> #include <com/sun/star/chart2/DataPointLabel.hpp> -#include <com/sun/star/chart2/LegendExpansion.hpp> #include <com/sun/star/chart2/LegendPosition.hpp> #include <com/sun/star/chart2/StackingDirection.hpp> #include <com/sun/star/chart2/TickmarkStyle.hpp> #include <com/sun/star/chart2/RelativePosition.hpp> +#include <com/sun/star/chart2/RelativeSize.hpp> #include <com/sun/star/chart/DataLabelPlacement.hpp> #include <com/sun/star/chart/ErrorBarStyle.hpp> #include <com/sun/star/chart/MissingValueTreatment.hpp> @@ -109,6 +110,7 @@ using ::com::sun::star::drawing::XShape; using ::com::sun::star::chart2::IncrementData; using ::com::sun::star::chart2::RelativePosition; +using ::com::sun::star::chart2::RelativeSize; using ::com::sun::star::chart2::ScaleData; using ::com::sun::star::chart2::SubIncrement; using ::com::sun::star::chart2::XAxis; @@ -337,14 +339,24 @@ sal_Int32 XclImpChRoot::CalcHmmFromChartY( sal_Int32 nPosY ) const CalcHmmFromChartY( rRect.mnHeight ) ); } +double XclImpChRoot::CalcRelativeFromHmmX( sal_Int32 nPosX ) const +{ + return static_cast< double >( nPosX ) / mxChData->maChartRect.GetWidth(); +} + +double XclImpChRoot::CalcRelativeFromHmmY( sal_Int32 nPosY ) const +{ + return static_cast< double >( nPosY ) / mxChData->maChartRect.GetHeight(); +} + double XclImpChRoot::CalcRelativeFromChartX( sal_Int32 nPosX ) const { - return static_cast< double >( CalcHmmFromChartX( nPosX ) ) / mxChData->maChartRect.GetWidth(); + return CalcRelativeFromHmmX( CalcHmmFromChartX( nPosX ) ); } double XclImpChRoot::CalcRelativeFromChartY( sal_Int32 nPosY ) const { - return static_cast< double >( CalcHmmFromChartY( nPosY ) ) / mxChData->maChartRect.GetHeight(); + return CalcRelativeFromHmmY( CalcHmmFromChartY( nPosY ) ); } void XclImpChRoot::ConvertLineFormat( ScfPropertySet& rPropSet, @@ -2468,18 +2480,30 @@ Reference< XLegend > XclImpChLegend::CreateLegend() const manual mode, if the legend is moved or resized). With manual plot areas, Excel ignores the value in maData.mnDockMode completely. */ cssc2::LegendPosition eApiPos = cssc2::LegendPosition_CUSTOM; - cssc2::LegendExpansion eApiExpand = cssc2::LegendExpansion_BALANCED; + cssc::ChartLegendExpansion eApiExpand = cssc::ChartLegendExpansion_CUSTOM; if( !GetChartData().IsManualPlotArea() ) switch( maData.mnDockMode ) { - case EXC_CHLEGEND_LEFT: eApiPos = cssc2::LegendPosition_LINE_START; eApiExpand = cssc2::LegendExpansion_HIGH; break; - case EXC_CHLEGEND_RIGHT: eApiPos = cssc2::LegendPosition_LINE_END; eApiExpand = cssc2::LegendExpansion_HIGH; break; - case EXC_CHLEGEND_TOP: eApiPos = cssc2::LegendPosition_PAGE_START; eApiExpand = cssc2::LegendExpansion_WIDE; break; - case EXC_CHLEGEND_BOTTOM: eApiPos = cssc2::LegendPosition_PAGE_END; eApiExpand = cssc2::LegendExpansion_WIDE; break; + case EXC_CHLEGEND_LEFT: + eApiPos = cssc2::LegendPosition_LINE_START; + eApiExpand = cssc::ChartLegendExpansion_HIGH; + break; + case EXC_CHLEGEND_RIGHT: // top-right not supported - case EXC_CHLEGEND_CORNER: eApiPos = cssc2::LegendPosition_LINE_END; eApiExpand = cssc2::LegendExpansion_HIGH; break; + case EXC_CHLEGEND_CORNER: + eApiPos = cssc2::LegendPosition_LINE_END; + eApiExpand = cssc::ChartLegendExpansion_HIGH; + break; + case EXC_CHLEGEND_TOP: + eApiPos = cssc2::LegendPosition_PAGE_START; + eApiExpand = cssc::ChartLegendExpansion_WIDE; + break; + case EXC_CHLEGEND_BOTTOM: + eApiPos = cssc2::LegendPosition_PAGE_END; + eApiExpand = cssc::ChartLegendExpansion_WIDE; + break; } - // no automatic position: try to find the correct position and size + // no automatic position/size: try to find the correct position and size if( eApiPos == cssc2::LegendPosition_CUSTOM ) { const XclChFramePos* pFramePos = mxFramePos.is() ? &mxFramePos->GetFramePosData() : 0; @@ -2489,38 +2513,35 @@ Reference< XLegend > XclImpChLegend::CreateLegend() const ignored. */ if( pFramePos ) { - RelativePosition aRelPos; - aRelPos.Primary = CalcRelativeFromChartX( pFramePos->maRect.mnX ); - aRelPos.Secondary = CalcRelativeFromChartY( pFramePos->maRect.mnY ); - aRelPos.Anchor = ::com::sun::star::drawing::Alignment_TOP_LEFT; + RelativePosition aRelPos( + CalcRelativeFromChartX( pFramePos->maRect.mnX ), + CalcRelativeFromChartY( pFramePos->maRect.mnY ), + ::com::sun::star::drawing::Alignment_TOP_LEFT ); aLegendProp.SetProperty( EXC_CHPROP_RELATIVEPOSITION, aRelPos ); } else { - // no manual position found, just go for the default + // no manual position/size found, just go for the default eApiPos = cssc2::LegendPosition_LINE_END; } - - /* Legend size. #i71697# It is not possible to set the legend size - directly in the Chart, do some magic here. */ - if( !pFramePos || (pFramePos->mnBRMode != EXC_CHFRAMEPOS_ABSSIZE_POINTS) || - (pFramePos->maRect.mnWidth == 0) || (pFramePos->maRect.mnHeight == 0) ) + /* Legend size. The member mnBRMode specifies whether size is + automatic or changes manually. Manual size is given in points, + not in chart units. */ + if( pFramePos && (pFramePos->mnBRMode == EXC_CHFRAMEPOS_ABSSIZE_POINTS) && + (pFramePos->maRect.mnWidth > 0) && (pFramePos->maRect.mnHeight > 0) ) { - // automatic size: determine entry direction from flags - eApiExpand = ::get_flagvalue( maData.mnFlags, EXC_CHLEGEND_STACKED, - cssc2::LegendExpansion_HIGH, cssc2::LegendExpansion_WIDE ); + eApiExpand = cssc::ChartLegendExpansion_CUSTOM; + sal_Int32 nWidthHmm = static_cast< sal_Int32 >( pFramePos->maRect.mnWidth / EXC_POINTS_PER_HMM ); + sal_Int32 nHeightHmm = static_cast< sal_Int32 >( pFramePos->maRect.mnHeight / EXC_POINTS_PER_HMM ); + RelativeSize aRelSize( CalcRelativeFromHmmX( nWidthHmm ), CalcRelativeFromHmmY( nHeightHmm ) ); + aLegendProp.SetProperty( EXC_CHPROP_RELATIVESIZE, aRelSize ); } else { - // legend size is given in points, not in chart units - double fRatio = static_cast< double >( pFramePos->maRect.mnWidth ) / pFramePos->maRect.mnHeight; - if( fRatio > 1.5 ) - eApiExpand = cssc2::LegendExpansion_WIDE; - else if( fRatio < 0.75 ) - eApiExpand = cssc2::LegendExpansion_HIGH; - else - eApiExpand = cssc2::LegendExpansion_BALANCED; + // automatic size: determine entry direction from flags + eApiExpand = ::get_flagvalue( maData.mnFlags, EXC_CHLEGEND_STACKED, + cssc::ChartLegendExpansion_HIGH, cssc::ChartLegendExpansion_WIDE ); } } aLegendProp.SetProperty( EXC_CHPROP_ANCHORPOSITION, eApiPos ); diff --git a/sc/source/filter/inc/xechart.hxx b/sc/source/filter/inc/xechart.hxx index 5178d6d99968..206392ea6890 100644 --- a/sc/source/filter/inc/xechart.hxx +++ b/sc/source/filter/inc/xechart.hxx @@ -382,6 +382,8 @@ public: /** Converts frame formatting properties from the passed property set. */ void Convert( const ScfPropertySet& rPropSet ); + /** Sets the specified automatic flags. */ + void SetAutoFlags( bool bAutoPos, bool bAutoSize ); /** Returns true, if the frame object contains default formats. */ bool IsDefault() const; diff --git a/sc/source/filter/inc/xichart.hxx b/sc/source/filter/inc/xichart.hxx index 0fbde9db0905..097ce1801896 100644 --- a/sc/source/filter/inc/xichart.hxx +++ b/sc/source/filter/inc/xichart.hxx @@ -134,6 +134,11 @@ public: /** Converts the passed rectangle from Excel chart units into 1/100 mm. */ ::com::sun::star::awt::Rectangle CalcHmmFromChartRect( const XclChRectangle& rRect ) const; + /** Converts the passed horizontal coordinate from 1/100 mm into a relative position. */ + double CalcRelativeFromHmmX( sal_Int32 nPosX ) const; + /** Converts the passed vertical coordinate from 1/100 mm into a relative position. */ + double CalcRelativeFromHmmY( sal_Int32 nPosY ) const; + /** Converts the passed horizontal coordinate from Excel chart units into a relative position. */ double CalcRelativeFromChartX( sal_Int32 nPosX ) const; /** Converts the passed vertical coordinate from Excel chart units into a relative position. */ diff --git a/sc/source/filter/inc/xlchart.hxx b/sc/source/filter/inc/xlchart.hxx index 68186a238847..925b1d14e805 100755 --- a/sc/source/filter/inc/xlchart.hxx +++ b/sc/source/filter/inc/xlchart.hxx @@ -126,6 +126,7 @@ class XclRoot; #define EXC_CHPROP_PERSPECTIVE CREATE_OUSTRING( "Perspective" ) #define EXC_CHPROP_POSITIVEERROR CREATE_OUSTRING( "PositiveError" ) #define EXC_CHPROP_RELATIVEPOSITION CREATE_OUSTRING( "RelativePosition" ) +#define EXC_CHPROP_RELATIVESIZE CREATE_OUSTRING( "RelativeSize" ) #define EXC_CHPROP_RIGHTANGLEDAXES CREATE_OUSTRING( "RightAngledAxes" ) #define EXC_CHPROP_ROLE CREATE_OUSTRING( "Role" ) #define EXC_CHPROP_ROTATIONHORIZONTAL CREATE_OUSTRING( "RotationHorizontal" ) diff --git a/sc/source/filter/inc/xlconst.hxx b/sc/source/filter/inc/xlconst.hxx index 42160aae7529..ac0e42496b63 100644 --- a/sc/source/filter/inc/xlconst.hxx +++ b/sc/source/filter/inc/xlconst.hxx @@ -139,6 +139,8 @@ const sal_Int32 EXC_RK_INT100 = EXC_RK_100FLAG | EXC_RK_INTFLAG; const sal_Int32 EXC_POINTS_PER_INCH = 72; const sal_Int32 EXC_TWIPS_PER_INCH = EXC_POINTS_PER_INCH * 20; +const double EXC_POINTS_PER_HMM = static_cast< double >( EXC_POINTS_PER_INCH ) / 2540.0; + const sal_uInt8 EXC_ORIENT_NONE = 0; /// Text orientation: not rotated. const sal_uInt8 EXC_ORIENT_STACKED = 1; /// Text orientation: vertically stacked. const sal_uInt8 EXC_ORIENT_90CCW = 2; /// Text orientation: 90 deg counterclockwise. |