summaryrefslogtreecommitdiff
path: root/chart2/source
diff options
context:
space:
mode:
authorIngrid Halama [iha] <Ingrid.Halama@oracle.com>2011-01-24 17:44:18 +0100
committerIngrid Halama [iha] <Ingrid.Halama@oracle.com>2011-01-24 17:44:18 +0100
commit0e685f0d9f64e57367cbc0a369885dad894d41d5 (patch)
tree97b7c80edca1d15af4ce76c813bc469b18ae9602 /chart2/source
parentdf5e24fa7d085508a0929c9213a515af344485e2 (diff)
chart52: #28670# make the legend within charts resizeable - part 2
Diffstat (limited to 'chart2/source')
-rw-r--r--chart2/source/controller/chartapiwrapper/LegendWrapper.cxx21
-rw-r--r--chart2/source/controller/dialogs/res_LegendPosition.cxx8
-rw-r--r--chart2/source/controller/itemsetwrapper/LegendItemConverter.cxx8
-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.cxx6
-rw-r--r--chart2/source/controller/main/PositionAndSizeHelper.cxx5
-rw-r--r--chart2/source/model/main/Legend.cxx10
-rw-r--r--chart2/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/VLegend.cxx228
13 files changed, 204 insertions, 118 deletions
diff --git a/chart2/source/controller/chartapiwrapper/LegendWrapper.cxx b/chart2/source/controller/chartapiwrapper/LegendWrapper.cxx
index 02ffcb942c99..df5ecd3642d1 100644
--- 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 ));
}
const Sequence< Property > & lcl_GetPropertySequence()
@@ -426,6 +434,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..4d6c7509052c 100644
--- a/chart2/source/controller/dialogs/res_LegendPosition.cxx
+++ b/chart2/source/controller/dialogs/res_LegendPosition.cxx
@@ -41,7 +41,7 @@
#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"
@@ -151,7 +151,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 +162,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 ));
diff --git a/chart2/source/controller/itemsetwrapper/LegendItemConverter.cxx b/chart2/source/controller/itemsetwrapper/LegendItemConverter.cxx
index 3af6d9342f33..c02df4aa4bfc 100644
--- a/chart2/source/controller/itemsetwrapper/LegendItemConverter.cxx
+++ b/chart2/source/controller/itemsetwrapper/LegendItemConverter.cxx
@@ -36,7 +36,7 @@
#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 <functional>
#include <algorithm>
@@ -164,9 +164,9 @@ bool LegendItemConverter::ApplySpecialItem(
( eOldPos != eNewPos ))
{
GetPropertySet()->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( eNewPos ));
- chart2::LegendExpansion eExp = bIsWide
- ? chart2::LegendExpansion_WIDE
- : chart2::LegendExpansion_HIGH;
+ ::com::sun::star::chart::ChartLegendExpansion eExp = bIsWide
+ ? ::com::sun::star::chart::ChartLegendExpansion_WIDE
+ : ::com::sun::star::chart::ChartLegendExpansion_HIGH;
GetPropertySet()->setPropertyValue( C2U( "Expansion" ), uno::makeAny( eExp ));
GetPropertySet()->setPropertyValue( C2U( "RelativePosition" ), uno::Any());
bChanged = true;
diff --git a/chart2/source/controller/main/ChartController_Position.cxx b/chart2/source/controller/main/ChartController_Position.cxx
index 18f042fe98df..5b7fa68dcea1 100644
--- a/chart2/source/controller/main/ChartController_Position.cxx
+++ b/chart2/source/controller/main/ChartController_Position.cxx
@@ -172,19 +172,15 @@ void SAL_CALL ChartController::executeDispatch_PositionAndSize()
awt::Size aPageSize( ChartModelHelper::getPageSize( getModel() ) );
Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height );
-
bool bChanged = false;
- if ( eObjectType == OBJECTTYPE_LEGEND && (aSelectedSize.Width != aObjectRect.getWidth()
- || aSelectedSize.Height != aObjectRect.getHeight()))
- bChanged = DiagramHelper::switchDiagramPositioningToExcludingPositioning( getModel(), false , true );
-
+ if ( eObjectType == OBJECTTYPE_LEGEND )
+ bChanged = DiagramHelper::switchDiagramPositioningToExcludingPositioning( getModel(), false , true );
- bool bMoved = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID()
- , getModel()
+ 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()) );
- bChanged = bMoved || bChanged;
- if( bChanged )
+
+ if( bMoved || bChanged )
aUndoGuard.commitAction();
}
}
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx
index 779e3c32f1e7..c7c39c01970e 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 cb32f0a7fb4d..0670cf6a6501 100644
--- a/chart2/source/controller/main/ChartController_Window.cxx
+++ b/chart2/source/controller/main/ChartController_Window.cxx
@@ -875,15 +875,15 @@ void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt )
m_xUndoManager, getModel() );
bool bChanged = false;
- if ( eObjectType == OBJECTTYPE_LEGEND && eActionType == ActionDescriptionProvider::RESIZE )
+ 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()) );
- bChanged = bMoved || bChanged;
- if( bChanged )
+
+ if( bMoved || bChanged )
{
bDraggingDone = true;
aUndoGuard.commitAction();
diff --git a/chart2/source/controller/main/PositionAndSizeHelper.cxx b/chart2/source/controller/main/PositionAndSizeHelper.cxx
index 30dfe898866e..bdee4a14f66b 100644
--- a/chart2/source/controller/main/PositionAndSizeHelper.cxx
+++ b/chart2/source/controller/main/PositionAndSizeHelper.cxx
@@ -33,7 +33,7 @@
#include "ChartModelHelper.hxx"
#include "ControllerLockGuard.hxx"
#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 "chartview/ExplicitValueProvider.hxx"
@@ -85,12 +85,11 @@ bool PositionAndSizeHelper::moveObject( ObjectType eObjectType
else if(OBJECTTYPE_LEGEND==eObjectType)
{
xObjectProp->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny(LegendPosition(LegendPosition_CUSTOM)));
- xObjectProp->setPropertyValue( C2U( "Expansion" ), uno::makeAny(LegendExpansion(LegendExpansion_CUSTOM)));
+ xObjectProp->setPropertyValue( C2U( "Expansion" ), uno::makeAny(::com::sun::star::chart::ChartLegendExpansion_CUSTOM));
chart2::RelativePosition aRelativePosition;
chart2::RelativeSize aRelativeSize;
Point aAnchor = aObjectRect.TopLeft();
-
aRelativePosition.Primary =
static_cast< double >( aAnchor.X()) /
static_cast< double >( aPageRect.getWidth() );
diff --git a/chart2/source/model/main/Legend.cxx b/chart2/source/model/main/Legend.cxx
index 9949f768a642..1408bcb91012 100644
--- a/chart2/source/model/main/Legend.cxx
+++ b/chart2/source/model/main/Legend.cxx
@@ -40,7 +40,7 @@
#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>
@@ -64,7 +64,7 @@ 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,
@@ -83,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 ));
@@ -122,7 +122,7 @@ void lcl_AddDefaultsToMap(
::chart::tPropertyValueMap & 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 4e778db1a68c..ac9dc0682bab 100644
--- 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>
@@ -63,11 +63,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 840cbbe3e1e1..2b007141abc1 100644
--- a/chart2/source/view/charttypes/VSeriesPlotter.cxx
+++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx
@@ -1752,7 +1752,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
@@ -1798,7 +1798,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 6b6b06437542..c9d827452fe2 100644
--- a/chart2/source/view/inc/VSeriesPlotter.hxx
+++ b/chart2/source/view/inc/VSeriesPlotter.hxx
@@ -207,7 +207,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/VLegend.cxx b/chart2/source/view/main/VLegend.cxx
index 3538bb06f50b..bad539a2c7c0 100644
--- a/chart2/source/view/main/VLegend.cxx
+++ b/chart2/source/view/main/VLegend.cxx
@@ -42,7 +42,7 @@
#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 +123,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 +145,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;
@@ -241,20 +240,23 @@ awt::Size lcl_createTextShapes(
return aResult;
}
-
-void lcl_placeLegendEntries(
+//returns resulting legend size
+awt::Size lcl_placeLegendEntries(
const tViewLegendEntryContainer & rEntries,
- LegendExpansion eExpansion,
+ ::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
@@ -269,16 +271,29 @@ void lcl_placeLegendEntries(
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());
-
// #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 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 nCurrentXPos = nXPadding;
sal_Int32 nCurrentYPos = nYPadding;
sal_Int32 nMaxEntryWidth = 2 * nXOffset + aMaxSymbolExtent.Width + aMaxEntryExtent.Width;
@@ -289,9 +304,80 @@ void lcl_placeLegendEntries(
nCurrentXPos = -nXPadding;
sal_Int32 nNumberOfColumns = 0, nNumberOfRows = 0;
+ std::vector< sal_Int32 > aColumnWidths;
// 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<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 + nXOffset;
+ 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( nCurrentColumnCount > 1)
+ nSumWidth += nXOffset*(nCurrentColumnCount-1);
+
+ 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;
+ }
+ else if( eExpansion == ::com::sun::star::chart::ChartLegendExpansion_HIGH )
{
sal_Int32 nMaxNumberOfRows = nMaxEntryHeight
? (rAvailableSpace.Height - 2*nYPadding ) / nMaxEntryHeight
@@ -308,7 +394,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 +411,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,7 +427,7 @@ void lcl_placeLegendEntries(
}
if(nNumberOfRows<=0)
- return;
+ return aResultingLegendSize;
// calculate maximum height for current row
std::vector< sal_Int32 > nMaxHeights( nNumberOfRows );
@@ -352,13 +438,23 @@ void lcl_placeLegendEntries(
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);
+ sal_Int32 nEntry = (nColumn + nRow * nNumberOfColumns);
if( nEntry < nNumberOfEntries )
+ {
+ awt::Size aTextSize( aTextShapes[ nEntry ]->getSize() );
nMaxHeight = ::std::max(
- nMaxHeight, nYOffset + aTextShapes[ nEntry ]->getSize().Height );
+ nMaxHeight, nYOffset + aTextSize.Height );
+ if( eExpansion != ::com::sun::star::chart::ChartLegendExpansion_CUSTOM )
+ {
+ sal_Int32 nWidth = nXOffset + aMaxSymbolExtent.Width + aTextSize.Width;
+ if( nColumn>0 )
+ nWidth += nXOffset;
+ if( nRow==0 )
+ aColumnWidths.push_back( nWidth );
+ else
+ aColumnWidths[nColumn] = ::std::max( nWidth, aColumnWidths[nColumn] );
+ }
+ }
}
nMaxHeights[ nRow ] = nMaxHeight;
}
@@ -367,15 +463,11 @@ void lcl_placeLegendEntries(
sal_Int32 nMaxYPos = 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;
@@ -406,7 +498,6 @@ void lcl_placeLegendEntries(
// 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;
@@ -416,18 +507,26 @@ void lcl_placeLegendEntries(
nMaxYPos = ::std::max( nMaxYPos, nCurrentYPos );
}
if( bSymbolsLeftSide )
- nCurrentXPos += nMaxWidth;
+ nCurrentXPos += aColumnWidths[nColumn];
else
- nCurrentXPos -= nMaxWidth;
+ nCurrentXPos -= aColumnWidths[nColumn];
}
- 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 +540,8 @@ void lcl_placeLegendEntries(
xText->setPosition( aPos );
}
}
- rOutLegendSize.Height = nMaxYPos + nYPadding;
+
+ return aResultingLegendSize;
}
// #i109336# Improve auto positioning in chart
@@ -707,39 +807,26 @@ void VLegend::createShapes(
tPropertyValues aLineFillProperties;
tPropertyValues aTextProperties;
- bool bIsCustomSized = false;
-
- // 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;
- awt::Size aCustomSize;
+ ::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;
- bIsCustomSized = (eExpansion == LegendExpansion_CUSTOM);
- RelativeSize aRelativeSize;
- if ((xLegendProp->getPropertyValue( C2U( "RelativeSize" )) >>= aRelativeSize))
- {
- aCustomSize.Width = aRelativeSize.Primary * rPageSize.Width;
- aCustomSize.Height = aRelativeSize.Secondary * rPageSize.Height;
- }
- else
- {
- bIsCustomSized =false;
- eExpansion = LegendExpansion_HIGH;
- }
- 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())
@@ -775,21 +862,12 @@ 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( bIsCustomSized )
- {
- xBorder->setSize( aCustomSize );
- }
- else
- xBorder->setSize( aLegendSize );
- }
+ xBorder->setSize( aLegendSize );
}
}
catch( uno::Exception & ex )