summaryrefslogtreecommitdiffstats
path: root/chart2
diff options
context:
space:
mode:
Diffstat (limited to 'chart2')
-rwxr-xr-xchart2/source/controller/chartapiwrapper/LegendWrapper.cxx21
-rw-r--r--chart2/source/controller/dialogs/res_LegendPosition.cxx77
-rw-r--r--chart2/source/controller/itemsetwrapper/LegendItemConverter.cxx133
-rw-r--r--chart2/source/controller/main/ChartController_Position.cxx14
-rw-r--r--chart2/source/controller/main/ChartController_Tools.cxx4
-rw-r--r--chart2/source/controller/main/ChartController_Window.cxx16
-rw-r--r--chart2/source/controller/main/PositionAndSizeHelper.cxx59
-rw-r--r--chart2/source/controller/main/SelectionHelper.cxx20
-rw-r--r--chart2/source/inc/chartview/ChartSfxItemIds.hxx3
-rwxr-xr-xchart2/source/model/main/Legend.cxx22
-rwxr-xr-xchart2/source/tools/LegendHelper.cxx8
-rw-r--r--chart2/source/view/charttypes/VSeriesPlotter.cxx4
-rw-r--r--chart2/source/view/inc/LegendEntryProvider.hxx4
-rw-r--r--chart2/source/view/inc/VSeriesPlotter.hxx2
-rw-r--r--chart2/source/view/main/ChartItemPool.cxx5
-rw-r--r--chart2/source/view/main/VLegend.cxx414
16 files changed, 507 insertions, 299 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 );
}
}