summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorBjörn Milcke <bm@openoffice.org>2003-10-20 08:59:32 +0000
committerBjörn Milcke <bm@openoffice.org>2003-10-20 08:59:32 +0000
commitb79a58b62012b6ec8554bdf2cd75eac45e121f10 (patch)
tree9112f0ac9a7b79d6c5da0290c0599092512c668f /chart2
parentea6936eed903097b988e41873ddafb8ab5a49ebf (diff)
positioning concept applied to legend
Diffstat (limited to 'chart2')
-rw-r--r--chart2/source/model/main/Legend.cxx83
-rw-r--r--chart2/source/model/main/Legend.hxx34
-rw-r--r--chart2/source/tools/makefile.mk5
-rw-r--r--chart2/source/view/main/ChartView.cxx81
-rw-r--r--chart2/source/view/main/VLegend.cxx110
-rw-r--r--chart2/source/view/main/VLegend.hxx17
6 files changed, 213 insertions, 117 deletions
diff --git a/chart2/source/model/main/Legend.cxx b/chart2/source/model/main/Legend.cxx
index c3c850653..cd21e714d 100644
--- a/chart2/source/model/main/Legend.cxx
+++ b/chart2/source/model/main/Legend.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: Legend.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: bm $ $Date: 2003-10-16 14:41:42 $
+ * last change: $Author: bm $ $Date: 2003-10-20 09:59:31 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -66,6 +66,7 @@
#include "CharacterProperties.hxx"
#include "UserDefinedProperties.hxx"
#include "LegendHelper.hxx"
+#include "LayoutDefaults.hxx"
#ifndef CHART_PROPERTYHELPER_HXX
#include "PropertyHelper.hxx"
@@ -191,8 +192,9 @@ namespace chart
Legend::Legend( uno::Reference< uno::XComponentContext > const & xContext ) :
::property::OPropertySet( m_aMutex ),
- m_aIdentifier( LegendHelper::getIdentifierForLegend() )
+ m_aIdentifier( LegendHelper::getIdentifierForLegend() )
{
+ setAnchorAndRelposFromProperty( GetDefaultValue( PROP_LEGEND_POSITION ));
}
Legend::~Legend()
@@ -239,6 +241,71 @@ uno::Sequence< uno::Reference< chart2::XLegendEntry > > SAL_CALL Legend::getEntr
return m_aIdentifier;
}
+// ____ XAnchoredObject ____
+void SAL_CALL Legend::setAnchor( const layout::AnchorPoint& aAnchor )
+ throw (uno::RuntimeException)
+{
+ m_aAnchor = aAnchor;
+}
+
+layout::AnchorPoint SAL_CALL Legend::getAnchor()
+ throw (uno::RuntimeException)
+{
+ return m_aAnchor;
+}
+
+void SAL_CALL Legend::setRelativePosition( const layout::RelativePoint& aPosition )
+ throw (uno::RuntimeException)
+{
+ m_aRelativePosition = aPosition;
+}
+
+layout::RelativePoint SAL_CALL Legend::getRelativePosition()
+ throw (uno::RuntimeException)
+{
+ return m_aRelativePosition;
+}
+
+// private
+void Legend::setAnchorAndRelposFromProperty( const uno::Any & rValue )
+{
+ chart2::LegendPosition ePos;
+ if( rValue >>= ePos )
+ {
+ m_aAnchor.AnchorHolder = uno::Reference< layout::XAnchor >();
+
+ // shift legend about 2% into the primary direction
+ m_aRelativePosition.Primary = 0.02;
+ m_aRelativePosition.Secondary = 0.0;
+
+ switch( ePos )
+ {
+ case chart2::LegendPosition_LINE_START:
+ m_aAnchor.Alignment = ::layout_defaults::const_aLineStart;
+ m_aAnchor.EscapeDirection = 0.0;
+ break;
+ case chart2::LegendPosition_LINE_END:
+ m_aAnchor.Alignment = ::layout_defaults::const_aLineEnd;
+ m_aAnchor.EscapeDirection = 180.0;
+ break;
+ case chart2::LegendPosition_PAGE_START:
+ m_aAnchor.Alignment = ::layout_defaults::const_aPageStart;
+ m_aAnchor.EscapeDirection = 270.0;
+ break;
+ case chart2::LegendPosition_PAGE_END:
+ m_aAnchor.Alignment = ::layout_defaults::const_aPageEnd;
+ m_aAnchor.EscapeDirection = 90.0;
+ break;
+
+ case chart2::LegendPosition_CUSTOM:
+ // to avoid warning
+ case chart2::LegendPosition_MAKE_FIXED_SIZE:
+ // nothing to be set
+ break;
+ }
+ }
+}
+
// ================================================================================
uno::Sequence< ::rtl::OUString > Legend::getSupportedServiceNames_Static()
@@ -309,6 +376,16 @@ uno::Reference< beans::XPropertySetInfo > SAL_CALL
// \--
}
+void SAL_CALL Legend::setFastPropertyValue_NoBroadcast
+ ( sal_Int32 nHandle, const uno::Any& rValue )
+ throw (uno::Exception)
+{
+ if( nHandle == PROP_LEGEND_POSITION )
+ setAnchorAndRelposFromProperty( rValue );
+
+ OPropertySet::setFastPropertyValue_NoBroadcast( nHandle, rValue );
+}
+
// implement XServiceInfo methods basing upon getSupportedServiceNames_Static
APPHELPER_XSERVICEINFO_IMPL( Legend, lcl_aServiceName );
diff --git a/chart2/source/model/main/Legend.hxx b/chart2/source/model/main/Legend.hxx
index a388e97dd..aa8915bf6 100644
--- a/chart2/source/model/main/Legend.hxx
+++ b/chart2/source/model/main/Legend.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: Legend.hxx,v $
*
- * $Revision: 1.1.1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: bm $ $Date: 2003-10-06 09:58:31 $
+ * last change: $Author: bm $ $Date: 2003-10-20 09:59:31 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -85,8 +85,8 @@
#ifndef _DRAFTS_COM_SUN_STAR_CHART2_XIDENTIFIABLE_HPP_
#include <drafts/com/sun/star/chart2/XIdentifiable.hpp>
#endif
-#ifndef _DRAFTS_COM_SUN_STAR_LAYOUT_XLAYOUTELEMENT_HPP_
-#include <drafts/com/sun/star/layout/XLayoutElement.hpp>
+#ifndef _DRAFTS_COM_SUN_STAR_LAYOUT_XANCHOREDOBJECT_HPP_
+#include <drafts/com/sun/star/layout/XAnchoredObject.hpp>
#endif
#ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HPP_
#include <com/sun/star/uno/XComponentContext.hpp>
@@ -101,7 +101,7 @@ typedef ::cppu::WeakImplHelper4<
::drafts::com::sun::star::chart2::XLegend,
::com::sun::star::lang::XServiceInfo,
::drafts::com::sun::star::chart2::XIdentifiable,
- ::drafts::com::sun::star::layout::XLayoutElement >
+ ::drafts::com::sun::star::layout::XAnchoredObject >
Legend_Base;
}
@@ -146,6 +146,11 @@ protected:
// const ::com::sun::star::uno::Any& rValue )
// throw (::com::sun::star::lang::IllegalArgumentException);
+ virtual void SAL_CALL setFastPropertyValue_NoBroadcast
+ ( sal_Int32 nHandle,
+ const ::com::sun::star::uno::Any& rValue )
+ throw (::com::sun::star::uno::Exception);
+
// ____ XLegend ____
virtual void SAL_CALL registerEntry( const ::com::sun::star::uno::Reference<
::drafts::com::sun::star::chart2::XLegendEntry >& xEntry )
@@ -164,16 +169,27 @@ protected:
virtual ::rtl::OUString SAL_CALL getIdentifier()
throw (::com::sun::star::uno::RuntimeException);
- // ____ XLayoutElement ____
- // (empty)
+ // ____ XAnchoredObject ____
+ virtual void SAL_CALL setAnchor( const ::drafts::com::sun::star::layout::AnchorPoint& aAnchor )
+ throw (::com::sun::star::uno::RuntimeException);
+ virtual ::drafts::com::sun::star::layout::AnchorPoint SAL_CALL getAnchor()
+ throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL setRelativePosition( const ::drafts::com::sun::star::layout::RelativePoint& aPosition )
+ throw (::com::sun::star::uno::RuntimeException);
+ virtual ::drafts::com::sun::star::layout::RelativePoint SAL_CALL getRelativePosition()
+ throw (::com::sun::star::uno::RuntimeException);
private:
+ void setAnchorAndRelposFromProperty( const ::com::sun::star::uno::Any & rValue );
+
typedef ::std::vector<
::com::sun::star::uno::Reference<
::drafts::com::sun::star::chart2::XLegendEntry > > tLegendEntries;
- tLegendEntries m_aLegendEntries;
- ::rtl::OUString m_aIdentifier;
+ tLegendEntries m_aLegendEntries;
+ ::rtl::OUString m_aIdentifier;
+ ::drafts::com::sun::star::layout::AnchorPoint m_aAnchor;
+ ::drafts::com::sun::star::layout::RelativePoint m_aRelativePosition;
};
} // namespace chart
diff --git a/chart2/source/tools/makefile.mk b/chart2/source/tools/makefile.mk
index 21392c341..1b67dc498 100644
--- a/chart2/source/tools/makefile.mk
+++ b/chart2/source/tools/makefile.mk
@@ -2,9 +2,9 @@
#
# $RCSfile: makefile.mk,v $
#
-# $Revision: 1.1.1.1 $
+# $Revision: 1.2 $
#
-# last change: $Author: bm $ $Date: 2003-10-06 09:58:32 $
+# last change: $Author: bm $ $Date: 2003-10-20 09:59:32 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
@@ -86,6 +86,7 @@ SLOFILES= \
$(SLO)$/CommonConverters.obj \
$(SLO)$/ContextHelper.obj \
$(SLO)$/ImplOPropertySet.obj \
+ $(SLO)$/LayoutHelper.obj \
$(SLO)$/OChartElementContainerHelper.obj \
$(SLO)$/OEnumeration.obj \
$(SLO)$/OIndexContainer.obj \
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index 6869a072c..8c06efd06 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: ChartView.cxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: bm $ $Date: 2003-10-17 14:49:39 $
+ * last change: $Author: bm $ $Date: 2003-10-20 09:59:32 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -71,7 +71,6 @@
#include "TitleHelper.hxx"
#include "LegendHelper.hxx"
#include "VLegend.hxx"
-#include "LayoutDefaults.hxx"
#include "PropertyMapper.hxx"
#ifndef _DRAFTS_COM_SUN_STAR_CHART2_AXISORIENTATION_HPP_
@@ -104,9 +103,6 @@
#ifndef _DRAFTS_COM_SUN_STAR_CHART2_XTITLED_HPP_
#include <drafts/com/sun/star/chart2/XTitled.hpp>
#endif
-#ifndef _DRAFTS_COM_SUN_STAR_CHART2_LEGENDPOSITION_HPP_
-#include <drafts/com/sun/star/chart2/LegendPosition.hpp>
-#endif
#ifndef _COM_SUN_STAR_DRAWING_LINESTYLE_HPP_
#include <com/sun/star/drawing/LineStyle.hpp>
#endif
@@ -117,6 +113,7 @@ namespace chart
//.............................................................................
using namespace ::com::sun::star;
+using namespace ::drafts::com::sun::star;
using namespace ::drafts::com::sun::star::chart2;
//static
@@ -608,80 +605,12 @@ void createLegend( const uno::Reference< XLegend > & xLegend
, const uno::Reference< lang::XMultiServiceFactory>& xShapeFactory
)
{
- if( xLegend.is())
+ if( VLegend::isVisible( xLegend ))
{
- LegendPosition ePos = LegendPosition_LINE_END;
- sal_Bool bShow = sal_True;
- uno::Reference< beans::XPropertySet > xLegendProp( xLegend, uno::UNO_QUERY );
- if( xLegendProp.is())
- {
- try
- {
- xLegendProp->getPropertyValue( C2U( "Position" )) >>= ePos;
- xLegendProp->getPropertyValue( C2U( "Show" )) >>= bShow;
- }
- catch( uno::Exception & ex )
- {
- ASSERT_EXCEPTION( ex );
- }
- }
-
- if( ! bShow )
- return;
-
VLegend aVLegend( xLegend );
aVLegend.init( xPageShapes, xShapeFactory );
aVLegend.createShapes( awt::Size( rOutSpaceLeft.Width, rOutSpaceLeft.Height ) );
-
- const sal_Int32 nEdgeOffset = 300;
-
- switch( ePos )
- {
- case LegendPosition_LINE_END:
- // legend is anchored to (right/middle) position
- // todo: honor Orientation
- aVLegend.changePosition(
- awt::Point( rOutSpaceLeft.X + rOutSpaceLeft.Width - nEdgeOffset,
- rOutSpaceLeft.Y + (rOutSpaceLeft.Height / 2)),
- ::layout_defaults::const_aLineEnd );
- rOutSpaceLeft.Width -= (aVLegend.getSize().Width + nEdgeOffset);
- break;
-
- case LegendPosition_LINE_START:
- // legend is anchored to (left/middle) position
- // todo: honor Orientation
- aVLegend.changePosition(
- awt::Point( rOutSpaceLeft.X + nEdgeOffset,
- rOutSpaceLeft.Y + (rOutSpaceLeft.Height / 2)),
- ::layout_defaults::const_aLineStart );
- rOutSpaceLeft.Width -= (aVLegend.getSize().Width + nEdgeOffset);
- rOutSpaceLeft.X += aVLegend.getSize().Width + nEdgeOffset;
- break;
-
- case LegendPosition_PAGE_START:
- // legend is anchored to (middle/top) position
- // todo: honor Orientation
- aVLegend.changePosition(
- awt::Point( rOutSpaceLeft.X + (rOutSpaceLeft.Width / 2),
- rOutSpaceLeft.Y + nEdgeOffset ),
- ::layout_defaults::const_aPageStart );
- rOutSpaceLeft.Height -= (aVLegend.getSize().Height + nEdgeOffset);
- rOutSpaceLeft.Y += aVLegend.getSize().Height + nEdgeOffset;
- break;
-
- case LegendPosition_PAGE_END:
- // legend is anchored to (middle/bottom) position
- // todo: honor Orientation
- aVLegend.changePosition(
- awt::Point( rOutSpaceLeft.X + (rOutSpaceLeft.Width / 2),
- rOutSpaceLeft.Y + rOutSpaceLeft.Height - nEdgeOffset),
- ::layout_defaults::const_aPageEnd );
- rOutSpaceLeft.Height -= (aVLegend.getSize().Height + nEdgeOffset);
- break;
-
- default:
- break;
- }
+ aVLegend.changePosition( rOutSpaceLeft );
}
}
diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx
index 0228d2fe9..44d1a9e07 100644
--- a/chart2/source/view/main/VLegend.cxx
+++ b/chart2/source/view/main/VLegend.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: VLegend.cxx,v $
*
- * $Revision: 1.12 $
+ * $Revision: 1.13 $
*
- * last change: $Author: bm $ $Date: 2003-10-17 14:50:29 $
+ * last change: $Author: bm $ $Date: 2003-10-20 09:59:32 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -64,6 +64,7 @@
#include "CommonConverters.hxx"
#include "VLegendSymbolFactory.hxx"
#include "chartview/ObjectIdentifier.hxx"
+#include "LayoutHelper.hxx"
#ifndef _COM_SUN_STAR_TEXT_XTEXTRANGE_HPP_
#include <com/sun/star/text/XTextRange.hpp>
@@ -92,7 +93,12 @@
#ifndef _DRAFTS_COM_SUN_STAR_CHART2_LEGENDEXPANSION_HPP_
#include <drafts/com/sun/star/chart2/LegendExpansion.hpp>
#endif
-
+#ifndef _DRAFTS_COM_SUN_STAR_LAYOUT_XANCHOREDOBJECT_HPP_
+#include <drafts/com/sun/star/layout/XAnchoredObject.hpp>
+#endif
+#ifndef _DRAFTS_COM_SUN_STAR_CHART2_LEGENDPOSITION_HPP_
+#include <drafts/com/sun/star/chart2/LegendPosition.hpp>
+#endif
// header for class Matrix3D
#ifndef _B2D_MATRIX3D_HXX
@@ -518,6 +524,25 @@ void SAL_CALL VLegend::init(
// ----------------------------------------
+// static
+bool VLegend::isVisible( const uno::Reference< chart2::XLegend > & xLegend )
+{
+ sal_Bool bShow = sal_False;
+ try
+ {
+ uno::Reference< beans::XPropertySet > xLegendProp( xLegend, uno::UNO_QUERY_THROW );
+ xLegendProp->getPropertyValue( C2U( "Show" )) >>= bShow;
+ }
+ catch( uno::Exception & ex )
+ {
+ ASSERT_EXCEPTION( ex );
+ }
+
+ return bShow;
+}
+
+// ----------------------------------------
+
void VLegend::createShapes(
const awt::Size & rAvailableSpace )
{
@@ -627,29 +652,70 @@ void VLegend::createShapes(
// ----------------------------------------
-void VLegend::changePosition(
- const awt::Point & rPos,
- const layout::Alignment& rAlignment )
+void VLegend::changePosition( awt::Rectangle & rOutAvailableSpace )
{
if(! m_xShape.is())
return;
- m_aBoundRect.X = rPos.X;
- m_aBoundRect.Y = rPos.Y;
- awt::Point aUpperLeft( rPos );
- aUpperLeft.X -= static_cast< sal_Int32 >(
- ::rtl::math::round( rAlignment.Primary * static_cast< double >( m_aBoundRect.Width )));
- aUpperLeft.Y -= static_cast< sal_Int32 >(
- ::rtl::math::round( rAlignment.Secondary * static_cast< double >( m_aBoundRect.Height )));
-
- m_xShape->setPosition( aUpperLeft );
-}
-
-// ----------------------------------------
-
-awt::Size VLegend::getSize() const
-{
- return awt::Size( m_aBoundRect.Width, m_aBoundRect.Height );
+ try
+ {
+ // determine position and alignment depending on anchor
+ uno::Reference< layout::XAnchoredObject > xAnchObj( m_xLegend, uno::UNO_QUERY_THROW );
+ layout::AnchorPoint aAnchor( xAnchObj->getAnchor());
+ layout::RelativePoint aOffset( xAnchObj->getRelativePosition());
+
+ helper::LayoutHelper::rotatePoint( aAnchor.EscapeDirection, aOffset.Primary, aOffset.Secondary );
+
+ awt::Point aPos( static_cast< sal_Int32 >(
+ rOutAvailableSpace.X + rOutAvailableSpace.Width *
+ (aAnchor.Alignment.Primary + aOffset.Primary)),
+ static_cast< sal_Int32 >(
+ rOutAvailableSpace.Y + rOutAvailableSpace.Height *
+ (aAnchor.Alignment.Secondary - aOffset.Secondary)));
+ layout::Alignment aAlignment( helper::LayoutHelper::getStandardAlignmentByAngle(
+ aAnchor.EscapeDirection ));
+
+ // set position according to Alignment
+ m_aBoundRect.X = aPos.X;
+ m_aBoundRect.Y = aPos.Y;
+ awt::Point aUpperLeft( aPos );
+ aUpperLeft.X -= static_cast< sal_Int32 >(
+ ::rtl::math::round( aAlignment.Primary * static_cast< double >( m_aBoundRect.Width )));
+ aUpperLeft.Y -= static_cast< sal_Int32 >(
+ ::rtl::math::round( aAlignment.Secondary * static_cast< double >( m_aBoundRect.Height )));
+
+ m_xShape->setPosition( aUpperLeft );
+
+ // adapt rOutAvailableSpace if LegendPosition is not CUSTOM
+ chart2::LegendPosition ePos = chart2::LegendPosition_CUSTOM;
+ uno::Reference< beans::XPropertySet > xLegendProp( m_xLegend, uno::UNO_QUERY_THROW );
+ xLegendProp->getPropertyValue( C2U( "Position" )) >>= ePos;
+
+ if( ePos == chart2::LegendPosition_LINE_START ||
+ ePos == chart2::LegendPosition_LINE_END )
+ {
+ sal_Int32 nExtent = static_cast< sal_Int32 >(
+ (1.0 + fabs(aOffset.Primary)) *
+ static_cast< double >( m_aBoundRect.Width ));
+ rOutAvailableSpace.Width -= nExtent;
+ if( ePos == chart2::LegendPosition_LINE_START )
+ rOutAvailableSpace.X += nExtent;
+ }
+ else if( ePos == chart2::LegendPosition_PAGE_START ||
+ ePos == chart2::LegendPosition_PAGE_END )
+ {
+ sal_Int32 nExtent = static_cast< sal_Int32 >(
+ (1.0 + fabs(aOffset.Secondary)) *
+ static_cast< double >( m_aBoundRect.Height ));
+ rOutAvailableSpace.Height -= nExtent;
+ if( ePos == chart2::LegendPosition_PAGE_START )
+ rOutAvailableSpace.Y += nExtent;
+ }
+ }
+ catch( uno::Exception & ex )
+ {
+ ASSERT_EXCEPTION( ex );
+ }
}
//.............................................................................
diff --git a/chart2/source/view/main/VLegend.hxx b/chart2/source/view/main/VLegend.hxx
index a74709c14..2ee8b15e0 100644
--- a/chart2/source/view/main/VLegend.hxx
+++ b/chart2/source/view/main/VLegend.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: VLegend.hxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: bm $ $Date: 2003-10-16 11:29:10 $
+ * last change: $Author: bm $ $Date: 2003-10-20 09:59:32 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -102,10 +102,17 @@ public:
void createShapes( const ::com::sun::star::awt::Size & rAvailableSpace );
- void changePosition( const ::com::sun::star::awt::Point & rPos,
- const ::drafts::com::sun::star::layout::Alignment& rAlignment );
+ /** Sets the position according to its internal anchor.
- ::com::sun::star::awt::Size getSize() const;
+ @param rOutAvailableSpace
+ is modified by the method, if the legend is in a standard position,
+ such that the space allocated by the legend is removed from it.
+ */
+ void changePosition( ::com::sun::star::awt::Rectangle & rOutAvailableSpace );
+
+ static bool isVisible(
+ const ::com::sun::star::uno::Reference<
+ ::drafts::com::sun::star::chart2::XLegend > & xLegend );
private:
::com::sun::star::uno::Reference<