diff options
author | obo <obo@openoffice.org> | 2010-06-09 08:49:31 +0200 |
---|---|---|
committer | obo <obo@openoffice.org> | 2010-06-09 08:49:31 +0200 |
commit | 5147fa872a8cc65be21854759a5a860a6712c4e9 (patch) | |
tree | 8f3eddab24cc5ff44f4895204f876048da9269e6 /chart2 | |
parent | c26519227bd414aa841e16d866a815e4bc1fd4b0 (diff) | |
parent | 017f1bc3f7b1810f2cbf1ba5971184920be87cf8 (diff) |
CWS-TOOLING: integrate CWS chartpositioning
Diffstat (limited to 'chart2')
25 files changed, 661 insertions, 240 deletions
diff --git a/chart2/source/controller/chartapiwrapper/Chart2ModelContact.cxx b/chart2/source/controller/chartapiwrapper/Chart2ModelContact.cxx index 79f5dccc918a..ffc1e95ca796 100644 --- a/chart2/source/controller/chartapiwrapper/Chart2ModelContact.cxx +++ b/chart2/source/controller/chartapiwrapper/Chart2ModelContact.cxx @@ -38,6 +38,7 @@ #include "chartview/ExplicitValueProvider.hxx" #include "chartview/DrawModelWrapper.hxx" #include "AxisHelper.hxx" +#include "DiagramHelper.hxx" using namespace ::com::sun::star; using namespace ::com::sun::star::chart2; @@ -118,7 +119,7 @@ Reference< chart2::XDiagram > Chart2ModelContact::getChart2Diagram() const return ChartModelHelper::findDiagram( this->getChartModel() ); } -ExplicitValueProvider* Chart2ModelContact::getExplicitValueProvider() const +uno::Reference< lang::XUnoTunnel > Chart2ModelContact::getChartView() const { if(!m_xChartView.is()) { @@ -128,7 +129,12 @@ ExplicitValueProvider* Chart2ModelContact::getExplicitValueProvider() const if( xFact.is() ) m_xChartView = Reference< lang::XUnoTunnel >( xFact->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY ); } + return m_xChartView; +} +ExplicitValueProvider* Chart2ModelContact::getExplicitValueProvider() const +{ + getChartView(); if(!m_xChartView.is()) return 0; @@ -192,30 +198,54 @@ awt::Size Chart2ModelContact::GetPageSize() const return ChartModelHelper::getPageSize(m_xChartModel); } -awt::Rectangle Chart2ModelContact::GetDiagramRectangleInclusive() const +awt::Rectangle Chart2ModelContact::SubstractAxisTitleSizes( const awt::Rectangle& rPositionRect ) { - awt::Rectangle aRect; + awt::Rectangle aRect = ExplicitValueProvider::substractAxisTitleSizes( + m_xChartModel, getChartView(), rPositionRect ); + return aRect; +} + +awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingTitle() const +{ + awt::Rectangle aRect( GetDiagramRectangleIncludingAxes() ); - ExplicitValueProvider* pProvider( getExplicitValueProvider() ); - if( pProvider ) - { - aRect = pProvider->getRectangleOfObject( lcl_getCIDForDiagram( m_xChartModel ) ); - } //add axis title sizes to the diagram size - aRect = ExplicitValueProvider::calculateDiagramPositionAndSizeInclusiveTitle( - m_xChartModel, m_xChartView, aRect ); + aRect = ExplicitValueProvider::addAxisTitleSizes( + m_xChartModel, getChartView(), aRect ); return aRect; } -awt::Size Chart2ModelContact::GetDiagramSizeInclusive() const +awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingAxes() const { - return ToSize( this->GetDiagramRectangleInclusive() ); + awt::Rectangle aRect(0,0,0,0); + uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) ); + + if( DiagramPositioningMode_INCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) ) + aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel); + else + { + ExplicitValueProvider* pProvider( getExplicitValueProvider() ); + if( pProvider ) + aRect = pProvider->getRectangleOfObject( C2U("PlotAreaIncludingAxes") ); + } + return aRect; } -awt::Point Chart2ModelContact::GetDiagramPositionInclusive() const +awt::Rectangle Chart2ModelContact::GetDiagramRectangleExcludingAxes() const { - return ToPoint( this->GetDiagramRectangleInclusive() ); + awt::Rectangle aRect(0,0,0,0); + uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) ); + + if( DiagramPositioningMode_EXCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) ) + aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel); + else + { + ExplicitValueProvider* pProvider( getExplicitValueProvider() ); + if( pProvider ) + aRect = pProvider->getDiagramRectangleExcludingAxes(); + } + return aRect; } awt::Size Chart2ModelContact::GetLegendSize() const diff --git a/chart2/source/controller/chartapiwrapper/Chart2ModelContact.hxx b/chart2/source/controller/chartapiwrapper/Chart2ModelContact.hxx index dea25ddd50e4..e20167e216c2 100644 --- a/chart2/source/controller/chartapiwrapper/Chart2ModelContact.hxx +++ b/chart2/source/controller/chartapiwrapper/Chart2ModelContact.hxx @@ -93,15 +93,24 @@ public: */ ::com::sun::star::awt::Size GetPageSize() const; - /** Returns the size of the diagram object in logic coordinates inclusive - the space reserved for axis titles. + /** calculates the current axes title sizes and substract that space them from the given recangle */ - ::com::sun::star::awt::Size GetDiagramSizeInclusive() const; + ::com::sun::star::awt::Rectangle SubstractAxisTitleSizes( const ::com::sun::star::awt::Rectangle& rPositionRect ); - /** Returns the position of the diagram in logic coordinates inclusive - the space reserved for axis titles. + /** Returns the position and size of the diagram in logic coordinates (100th mm) including + the space used for axes including axes titles. */ - ::com::sun::star::awt::Point GetDiagramPositionInclusive() const; + ::com::sun::star::awt::Rectangle GetDiagramRectangleIncludingTitle() const; + + /** Returns the position and size of the diagram in logic coordinates (100th mm) including + the space used for axes excluding axes titles. + */ + ::com::sun::star::awt::Rectangle GetDiagramRectangleIncludingAxes() const; + + /** Returns the position and size of the diagram in logic coordinates (100th mm) excluding + the space used for axes (inner plot area). + */ + ::com::sun::star::awt::Rectangle GetDiagramRectangleExcludingAxes() const; /** Returns the size of the object in logic coordinates. */ @@ -134,7 +143,8 @@ public: private: //methods ExplicitValueProvider* getExplicitValueProvider() const; - ::com::sun::star::awt::Rectangle GetDiagramRectangleInclusive() const; + ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XUnoTunnel > getChartView() const; public: //member ::com::sun::star::uno::Reference< diff --git a/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx b/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx index b1db5981f6b3..e05279b15aae 100644 --- a/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx +++ b/chart2/source/controller/chartapiwrapper/DiagramWrapper.cxx @@ -59,6 +59,7 @@ #include "DisposeHelper.hxx" #include <comphelper/InlineContainer.hxx> #include "WrappedAutomaticPositionProperties.hxx" +#include "CommonConverters.hxx" #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/chart2/XTitled.hpp> @@ -737,49 +738,23 @@ Reference< awt::Point SAL_CALL DiagramWrapper::getPosition() throw (uno::RuntimeException) { - awt::Point aPosition; - - Reference< beans::XPropertySet > xProp( this->getInnerPropertySet() ); - if( xProp.is() ) - { - bool bSet = false; - chart2::RelativePosition aRelativePosition; - uno::Any aAPosition( xProp->getPropertyValue( C2U( "RelativePosition" ) ) ); - if( aAPosition >>= aRelativePosition ) - { - awt::Size aPageSize( m_spChart2ModelContact->GetPageSize() ); - aPosition.X = static_cast<sal_Int32>(aRelativePosition.Primary*aPageSize.Width); - aPosition.Y = static_cast<sal_Int32>(aRelativePosition.Secondary*aPageSize.Height); - - aPosition = RelativePositionHelper::getUpperLeftCornerOfAnchoredObject( - aPosition, DiagramWrapper::getSize(), aRelativePosition.Anchor ); - - bSet = true; - } - if(!bSet) - aPosition = m_spChart2ModelContact->GetDiagramPositionInclusive(); - } - + awt::Point aPosition = ToPoint( m_spChart2ModelContact->GetDiagramRectangleIncludingAxes() ); return aPosition; } void SAL_CALL DiagramWrapper::setPosition( const awt::Point& aPosition ) throw (uno::RuntimeException) { + ControllerLockGuard aCtrlLockGuard( m_spChart2ModelContact->getChartModel() ); Reference< beans::XPropertySet > xProp( this->getInnerPropertySet() ); if( xProp.is() ) { - if( aPosition.X < 0 || aPosition.Y < 0 ) + if( aPosition.X < 0 || aPosition.Y < 0 || aPosition.X > 1 || aPosition.Y > 1 ) { - if( !TitleHelper::getTitle( TitleHelper::X_AXIS_TITLE, m_spChart2ModelContact->getChartModel() ).is() && - !TitleHelper::getTitle( TitleHelper::Y_AXIS_TITLE, m_spChart2ModelContact->getChartModel() ).is() ) - { - DBG_ERROR("DiagramWrapper::setPosition called with negative position -> automatic values are taken instead" ); - uno::Any aEmpty; - xProp->setPropertyValue( C2U( "RelativePosition" ), aEmpty ); - return; - } - //else: The saved didagram size does include the axis title sizes thus the position and size could be negative + DBG_ERROR("DiagramWrapper::setPosition called with a position out of range -> automatic values are taken instead" ); + uno::Any aEmpty; + xProp->setPropertyValue( C2U( "RelativePosition" ), aEmpty ); + return; } awt::Size aPageSize( m_spChart2ModelContact->GetPageSize() ); @@ -789,31 +764,14 @@ void SAL_CALL DiagramWrapper::setPosition( const awt::Point& aPosition ) aRelativePosition.Primary = double(aPosition.X)/double(aPageSize.Width); aRelativePosition.Secondary = double(aPosition.Y)/double(aPageSize.Height); xProp->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition) ); + xProp->setPropertyValue( C2U( "PosSizeExcludeAxes" ), uno::makeAny(false) ); } } awt::Size SAL_CALL DiagramWrapper::getSize() throw (uno::RuntimeException) { - awt::Size aSize; - - Reference< beans::XPropertySet > xProp( this->getInnerPropertySet() ); - if( xProp.is() ) - { - bool bSet = false; - chart2::RelativeSize aRelativeSize; - uno::Any aASize( xProp->getPropertyValue( C2U( "RelativeSize" ) ) ); - if(aASize>>=aRelativeSize) - { - awt::Size aPageSize( m_spChart2ModelContact->GetPageSize() ); - aSize.Width = static_cast<sal_Int32>(aRelativeSize.Primary*aPageSize.Width); - aSize.Height = static_cast<sal_Int32>(aRelativeSize.Secondary*aPageSize.Height); - bSet = true; - } - if(!bSet) - aSize = m_spChart2ModelContact->GetDiagramSizeInclusive(); - } - + awt::Size aSize = ToSize( m_spChart2ModelContact->GetDiagramRectangleIncludingAxes() ); return aSize; } @@ -821,6 +779,7 @@ void SAL_CALL DiagramWrapper::setSize( const awt::Size& aSize ) throw (beans::PropertyVetoException, uno::RuntimeException) { + ControllerLockGuard aCtrlLockGuard( m_spChart2ModelContact->getChartModel() ); Reference< beans::XPropertySet > xProp( this->getInnerPropertySet() ); if( xProp.is() ) { @@ -832,18 +791,14 @@ void SAL_CALL DiagramWrapper::setSize( const awt::Size& aSize ) if( aRelativeSize.Primary > 1 || aRelativeSize.Secondary > 1 ) { - if( !TitleHelper::getTitle( TitleHelper::X_AXIS_TITLE, m_spChart2ModelContact->getChartModel() ).is() && - !TitleHelper::getTitle( TitleHelper::Y_AXIS_TITLE, m_spChart2ModelContact->getChartModel() ).is() ) - { - DBG_ERROR("DiagramWrapper::setSize called with sizes bigger than page -> automatic values are taken instead" ); - uno::Any aEmpty; - xProp->setPropertyValue( C2U( "RelativeSize" ), aEmpty ); - return; - } - //else: The saved didagram size does include the axis title sizes thus the position and size could be out of range + DBG_ERROR("DiagramWrapper::setSize called with sizes bigger than page -> automatic values are taken instead" ); + uno::Any aEmpty; + xProp->setPropertyValue( C2U( "RelativeSize" ), aEmpty ); + return; } xProp->setPropertyValue( C2U( "RelativeSize" ), uno::makeAny(aRelativeSize) ); + xProp->setPropertyValue( C2U( "PosSizeExcludeAxes" ), uno::makeAny(false) ); } } @@ -854,6 +809,81 @@ OUString SAL_CALL DiagramWrapper::getShapeType() return C2U( "com.sun.star.chart.Diagram" ); } +// ____ XDiagramPositioning ____ + +void SAL_CALL DiagramWrapper::setAutomaticDiagramPositioning() throw (uno::RuntimeException) +{ + ControllerLockGuard aCtrlLockGuard( m_spChart2ModelContact->getChartModel() ); + uno::Reference< beans::XPropertySet > xDiaProps( this->getDiagram(), uno::UNO_QUERY ); + if( xDiaProps.is() ) + { + xDiaProps->setPropertyValue( C2U( "RelativeSize" ), Any() ); + xDiaProps->setPropertyValue( C2U( "RelativePosition" ), Any() ); + } +} +::sal_Bool SAL_CALL DiagramWrapper::isAutomaticDiagramPositioning( ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xDiaProps( this->getDiagram(), uno::UNO_QUERY ); + if( xDiaProps.is() ) + { + Any aRelativeSize( xDiaProps->getPropertyValue( C2U( "RelativeSize" ) ) ); + Any aRelativePosition( xDiaProps->getPropertyValue( C2U( "RelativePosition" ) ) ); + if( aRelativeSize.hasValue() && aRelativePosition.hasValue() ) + return false; + } + return true; +} +void SAL_CALL DiagramWrapper::setDiagramPositionExcludingAxes( const awt::Rectangle& rPositionRect ) throw (uno::RuntimeException) +{ + ControllerLockGuard aCtrlLockGuard( m_spChart2ModelContact->getChartModel() ); + DiagramHelper::setDiagramPositioning( m_spChart2ModelContact->getChartModel(), rPositionRect ); + uno::Reference< beans::XPropertySet > xDiaProps( this->getDiagram(), uno::UNO_QUERY ); + if( xDiaProps.is() ) + xDiaProps->setPropertyValue(C2U("PosSizeExcludeAxes"), uno::makeAny(true) ); +} +::sal_Bool SAL_CALL DiagramWrapper::isExcludingDiagramPositioning() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xDiaProps( this->getDiagram(), uno::UNO_QUERY ); + if( xDiaProps.is() ) + { + Any aRelativeSize( xDiaProps->getPropertyValue( C2U( "RelativeSize" ) ) ); + Any aRelativePosition( xDiaProps->getPropertyValue( C2U( "RelativePosition" ) ) ); + if( aRelativeSize.hasValue() && aRelativePosition.hasValue() ) + { + sal_Bool bPosSizeExcludeAxes = false; + xDiaProps->getPropertyValue( C2U( "PosSizeExcludeAxes" ) ) >>= bPosSizeExcludeAxes; + return bPosSizeExcludeAxes; + } + } + return false; +} +awt::Rectangle SAL_CALL DiagramWrapper::calculateDiagramPositionExcludingAxes( ) throw (uno::RuntimeException) +{ + return m_spChart2ModelContact->GetDiagramRectangleExcludingAxes(); +} +void SAL_CALL DiagramWrapper::setDiagramPositionIncludingAxes( const awt::Rectangle& rPositionRect ) throw (uno::RuntimeException) +{ + ControllerLockGuard aCtrlLockGuard( m_spChart2ModelContact->getChartModel() ); + DiagramHelper::setDiagramPositioning( m_spChart2ModelContact->getChartModel(), rPositionRect ); + uno::Reference< beans::XPropertySet > xDiaProps( this->getDiagram(), uno::UNO_QUERY ); + if( xDiaProps.is() ) + xDiaProps->setPropertyValue(C2U("PosSizeExcludeAxes"), uno::makeAny(false) ); +} +awt::Rectangle SAL_CALL DiagramWrapper::calculateDiagramPositionIncludingAxes( ) throw (uno::RuntimeException) +{ + return m_spChart2ModelContact->GetDiagramRectangleIncludingAxes(); +} +void SAL_CALL DiagramWrapper::setDiagramPositionIncludingAxesAndAxisTitles( const awt::Rectangle& rPositionRect ) throw (uno::RuntimeException) +{ + ControllerLockGuard aCtrlLockGuard( m_spChart2ModelContact->getChartModel() ); + awt::Rectangle aRect( m_spChart2ModelContact->SubstractAxisTitleSizes(rPositionRect) ); + DiagramWrapper::setDiagramPositionIncludingAxes( aRect ); +} +::com::sun::star::awt::Rectangle SAL_CALL DiagramWrapper::calculateDiagramPositionIncludingAxesAndAxisTitles( ) throw (::com::sun::star::uno::RuntimeException) +{ + return m_spChart2ModelContact->GetDiagramRectangleIncludingTitle(); +} + // ____ XAxisZSupplier ____ Reference< drawing::XShape > SAL_CALL DiagramWrapper::getZAxisTitle() diff --git a/chart2/source/controller/chartapiwrapper/DiagramWrapper.hxx b/chart2/source/controller/chartapiwrapper/DiagramWrapper.hxx index 96689eec2aac..111e24bd6a8b 100644 --- a/chart2/source/controller/chartapiwrapper/DiagramWrapper.hxx +++ b/chart2/source/controller/chartapiwrapper/DiagramWrapper.hxx @@ -30,12 +30,13 @@ #include "WrappedPropertySet.hxx" #include "ServiceMacros.hxx" #include "DiagramHelper.hxx" -#include <cppuhelper/implbase11.hxx> +#include <cppuhelper/implbase12.hxx> #include <comphelper/uno3.hxx> #include <cppuhelper/interfacecontainer.hxx> #include <com/sun/star/chart2/XChartDocument.hpp> #include <com/sun/star/chart2/XDiagram.hpp> #include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/chart/XDiagramPositioning.hpp> #include <com/sun/star/chart2/XDiagramProvider.hpp> #include <com/sun/star/chart2/XChartTypeTemplate.hpp> #include <com/sun/star/chart2/XChartTypeManager.hpp> @@ -61,7 +62,7 @@ namespace wrapper class Chart2ModelContact; -class DiagramWrapper : public ::cppu::ImplInheritanceHelper11< +class DiagramWrapper : public ::cppu::ImplInheritanceHelper12< WrappedPropertySet , ::com::sun::star::chart::XDiagram , ::com::sun::star::chart::XAxisZSupplier @@ -73,6 +74,7 @@ class DiagramWrapper : public ::cppu::ImplInheritanceHelper11< , ::com::sun::star::lang::XServiceInfo , ::com::sun::star::lang::XComponent // , ::com::sun::star::lang::XEventListener + , ::com::sun::star::chart::XDiagramPositioning , ::com::sun::star::chart2::XDiagramProvider , ::com::sun::star::chart::XSecondAxisTitleSupplier > @@ -209,6 +211,18 @@ public: // virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) // throw (::com::sun::star::uno::RuntimeException); + // ____ XDiagramPositioning ____ + + virtual void SAL_CALL setAutomaticDiagramPositioning( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL isAutomaticDiagramPositioning( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDiagramPositionExcludingAxes( const ::com::sun::star::awt::Rectangle& PositionRect ) throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL isExcludingDiagramPositioning( ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Rectangle SAL_CALL calculateDiagramPositionExcludingAxes( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDiagramPositionIncludingAxes( const ::com::sun::star::awt::Rectangle& PositionRect ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Rectangle SAL_CALL calculateDiagramPositionIncludingAxes( ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDiagramPositionIncludingAxesAndAxisTitles( const ::com::sun::star::awt::Rectangle& PositionRect ) throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Rectangle SAL_CALL calculateDiagramPositionIncludingAxesAndAxisTitles( ) throw (::com::sun::star::uno::RuntimeException); + // ____ XDiagramProvider ____ virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram > SAL_CALL getDiagram() diff --git a/chart2/source/controller/dialogs/TabPages.hrc b/chart2/source/controller/dialogs/TabPages.hrc index ba9a330b250e..1f445083738f 100644 --- a/chart2/source/controller/dialogs/TabPages.hrc +++ b/chart2/source/controller/dialogs/TabPages.hrc @@ -46,7 +46,6 @@ ////#define RBT_DOWNUP 3 ////#define RBT_AUTOORDER 4 -//#define TP_STAT 905 #define FL_TEXTBREAK 3 #define CBX_TEXTBREAK 2 #define CBX_TEXTOVERLAP 4 diff --git a/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx b/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx index fbcca6a26bde..48c96a715c5f 100644 --- a/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx +++ b/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx @@ -30,6 +30,7 @@ #include "DrawViewWrapper.hxx" #include "chartview/DrawModelWrapper.hxx" #include "ConfigurationAccess.hxx" +#include "macros.hxx" #include <unotools/lingucfg.hxx> #include <editeng/langitem.hxx> @@ -241,6 +242,14 @@ SdrObject* DrawViewWrapper::getHitObject( const Point& rPnt ) const if( pRet ) { + //ignore some special shapes + rtl::OUString aShapeName = pRet->GetName(); + if( aShapeName.match(C2U("PlotAreaIncludingAxes")) || aShapeName.match(C2U("PlotAreaExcludingAxes")) ) + { + pRet->SetMarkProtect( true ); + return getHitObject( rPnt ); + } + //3d objects need a special treatment //because the simple PickObj method is not accurate in this case for performance reasons E3dObject* pE3d = dynamic_cast< E3dObject* >(pRet); diff --git a/chart2/source/controller/inc/PositionAndSizeHelper.hxx b/chart2/source/controller/inc/PositionAndSizeHelper.hxx index 43392e7a8235..312c92997055 100644 --- a/chart2/source/controller/inc/PositionAndSizeHelper.hxx +++ b/chart2/source/controller/inc/PositionAndSizeHelper.hxx @@ -51,8 +51,7 @@ public: static bool moveObject( const rtl::OUString& rObjectCID , const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xChartModel , const ::com::sun::star::awt::Rectangle& rNewPositionAndSize - , const ::com::sun::star::awt::Rectangle& rPageRectangle - , ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xChartView ); + , const ::com::sun::star::awt::Rectangle& rPageRectangle ); }; //............................................................................. diff --git a/chart2/source/controller/itemsetwrapper/SchWhichPairs.hxx b/chart2/source/controller/itemsetwrapper/SchWhichPairs.hxx index b3c4b7ea19f7..f7ddeb42c11e 100644 --- a/chart2/source/controller/itemsetwrapper/SchWhichPairs.hxx +++ b/chart2/source/controller/itemsetwrapper/SchWhichPairs.hxx @@ -87,27 +87,6 @@ const USHORT nGridWhichPairs[] = 0 }; -const USHORT nChartWhichPairs[] = -{ - SCHATTR_STYLE_START,SCHATTR_STYLE_END, // 59 - 68 sch/schattr.hxx - 0 -}; - -const USHORT nDiagramAreaWhichPairs[] = -{ - XATTR_LINE_FIRST, XATTR_LINE_LAST, // 1000 - 1016 svx/xdef.hxx - XATTR_FILL_FIRST, XATTR_FILL_LAST, // 1018 - 1046 svx/xdef.hxx - 0 -}; - -const USHORT nAreaAndChartWhichPairs[] = // pairs for chart AND area -{ - XATTR_LINE_FIRST, XATTR_LINE_LAST, // 1000 - 1016 svx/xdef.hxx - XATTR_FILL_FIRST, XATTR_FILL_LAST, // 1018 - 1046 svx/xdef.hxx - SCHATTR_STYLE_START,SCHATTR_STYLE_END, // 59 - 68 sch/schattr.hxx - 0 -}; - const USHORT nLegendWhichPairs[] = { XATTR_LINE_FIRST, XATTR_LINE_LAST, // 1000 - 1016 svx/xdef.hxx diff --git a/chart2/source/controller/main/ChartController.hxx b/chart2/source/controller/main/ChartController.hxx index 8deffe47396f..81f4ba5a549e 100644 --- a/chart2/source/controller/main/ChartController.hxx +++ b/chart2/source/controller/main/ChartController.hxx @@ -725,6 +725,8 @@ private: void impl_SetMousePointer( const MouseEvent & rEvent ); void impl_ClearSelection(); + + void impl_switchDiagramPositioningToExcludingPositioning(); }; //............................................................................. diff --git a/chart2/source/controller/main/ChartController_Position.cxx b/chart2/source/controller/main/ChartController_Position.cxx index 6c988ebf22d5..3105ee53bf14 100644 --- a/chart2/source/controller/main/ChartController_Position.cxx +++ b/chart2/source/controller/main/ChartController_Position.cxx @@ -172,8 +172,7 @@ void SAL_CALL ChartController::executeDispatch_PositionAndSize() bool bChanged = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID() , m_aModel->getModel() , awt::Rectangle(aObjectRect.getX(),aObjectRect.getY(),aObjectRect.getWidth(),aObjectRect.getHeight()) - , awt::Rectangle(aPageRect.getX(),aPageRect.getY(),aPageRect.getWidth(),aPageRect.getHeight()) - , m_xChartView ); + , awt::Rectangle(aPageRect.getX(),aPageRect.getY(),aPageRect.getWidth(),aPageRect.getHeight()) ); if( bChanged ) aUndoGuard.commitAction(); } diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx index ff567636ba0e..11fa5e74054e 100644 --- a/chart2/source/controller/main/ChartController_Tools.cxx +++ b/chart2/source/controller/main/ChartController_Tools.cxx @@ -50,6 +50,7 @@ #include "RegressionCurveHelper.hxx" #include "ShapeController.hxx" #include "DiagramHelper.hxx" +#include "ObjectNameProvider.hxx" #include <com/sun/star/chart2/DataPointLabel.hpp> #include <com/sun/star/beans/XPropertyState.hpp> @@ -242,6 +243,7 @@ void ChartController::executeDispatch_NewArrangement() Reference< beans::XPropertyState > xState( xDiagram, uno::UNO_QUERY_THROW ); xState->setPropertyToDefault( C2U("RelativeSize")); xState->setPropertyToDefault( C2U("RelativePosition")); + xState->setPropertyToDefault( C2U("PosSizeExcludeAxes")); // 3d rotation ThreeDHelper::set3DSettingsToDefault( uno::Reference< beans::XPropertySet >( xDiagram, uno::UNO_QUERY ) ); @@ -468,6 +470,8 @@ void ChartController::impl_PasteShapes( SdrModel* pModel ) m_aSelection.applySelection( m_pDrawViewWrapper ); m_pDrawViewWrapper->EndUndo(); + + impl_switchDiagramPositioningToExcludingPositioning(); } } } @@ -514,6 +518,8 @@ void ChartController::impl_PasteStringAsTextShape( const OUString& rString, cons m_pDrawViewWrapper->BegUndo( SVX_RESSTR( RID_SVX_3D_UNDO_EXCHANGE_PASTE ) ); m_pDrawViewWrapper->AddUndo( new SdrUndoInsertObj( *pObj ) ); m_pDrawViewWrapper->EndUndo(); + + impl_switchDiagramPositioningToExcludingPositioning(); } } catch ( const uno::Exception& ex ) @@ -902,4 +908,14 @@ void ChartController::impl_ShapeControllerDispatch( const util::URL& rURL, const } } +void ChartController::impl_switchDiagramPositioningToExcludingPositioning() +{ + UndoGuard aUndoGuard( ActionDescriptionProvider::createDescription( + ActionDescriptionProvider::POS_SIZE, + ObjectNameProvider::getName( OBJECTTYPE_DIAGRAM)), + m_xUndoManager, m_aModel->getModel() ); + if( DiagramHelper::switchDiagramPositioningToExcludingPositioning( m_aModel->getModel(), true, true ) ) + aUndoGuard.commitAction(); +} + } // namespace chart diff --git a/chart2/source/controller/main/ChartController_Window.cxx b/chart2/source/controller/main/ChartController_Window.cxx index 6049be7e3199..8b3deca4e2dd 100644 --- a/chart2/source/controller/main/ChartController_Window.cxx +++ b/chart2/source/controller/main/ChartController_Window.cxx @@ -797,6 +797,7 @@ void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt ) if ( m_eDrawMode == CHARTDRAW_INSERT && pDrawViewWrapper->IsCreateObj() ) { pDrawViewWrapper->EndCreateObj( SDRCREATE_FORCEEND ); + impl_switchDiagramPositioningToExcludingPositioning(); if ( pDrawViewWrapper->AreObjectsMarked() ) { if ( pDrawViewWrapper->GetCurrentObjIdentifier() == OBJ_TEXT ) @@ -870,8 +871,7 @@ void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt ) bool bChanged = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID() , m_aModel->getModel() , awt::Rectangle(aObjectRect.getX(),aObjectRect.getY(),aObjectRect.getWidth(),aObjectRect.getHeight()) - , awt::Rectangle(aPageRect.getX(),aPageRect.getY(),aPageRect.getWidth(),aPageRect.getHeight()) - , m_xChartView ); + , awt::Rectangle(aPageRect.getX(),aPageRect.getY(),aPageRect.getWidth(),aPageRect.getHeight()) ); if( bChanged ) { bDraggingDone = true; diff --git a/chart2/source/controller/main/PositionAndSizeHelper.cxx b/chart2/source/controller/main/PositionAndSizeHelper.cxx index 089abb1822f6..f0ce3eaaa04e 100644 --- a/chart2/source/controller/main/PositionAndSizeHelper.cxx +++ b/chart2/source/controller/main/PositionAndSizeHelper.cxx @@ -141,8 +141,6 @@ bool PositionAndSizeHelper::moveObject( ObjectType eObjectType { //@todo decide wether x is primary or secondary - //xChartView - //set position: chart2::RelativePosition aRelativePosition; aRelativePosition.Anchor = drawing::Alignment_CENTER; @@ -169,7 +167,6 @@ bool PositionAndSizeHelper::moveObject( const rtl::OUString& rObjectCID , const uno::Reference< frame::XModel >& xChartModel , const awt::Rectangle& rNewPositionAndSize , const awt::Rectangle& rPageRectangle - , uno::Reference< uno::XInterface > xChartView ) { ControllerLockGuard aLockedControllers( xChartModel ); @@ -183,10 +180,6 @@ bool PositionAndSizeHelper::moveObject( const rtl::OUString& rObjectCID xObjectProp = uno::Reference< beans::XPropertySet >( ObjectIdentifier::getDiagramForCID( rObjectCID, xChartModel ), uno::UNO_QUERY ); if(!xObjectProp.is()) return false; - - //add axis title sizes to the diagram size - aNewPositionAndSize = ExplicitValueProvider::calculateDiagramPositionAndSizeInclusiveTitle( - xChartModel, xChartView, rNewPositionAndSize ); } return moveObject( eObjectType, xObjectProp, aNewPositionAndSize, rPageRectangle ); } diff --git a/chart2/source/inc/DiagramHelper.hxx b/chart2/source/inc/DiagramHelper.hxx index 14113e7396ca..c7cda6189680 100644 --- a/chart2/source/inc/DiagramHelper.hxx +++ b/chart2/source/inc/DiagramHelper.hxx @@ -46,6 +46,13 @@ namespace chart { +enum DiagramPositioningMode +{ + DiagramPositioningMode_AUTO, + DiagramPositioningMode_EXCLUDING, + DiagramPositioningMode_INCLUDING +}; + class OOO_DLLPUBLIC_CHARTTOOLS DiagramHelper { public: @@ -318,6 +325,19 @@ public: const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartType ); + static DiagramPositioningMode getDiagramPositioningMode( const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram > & xDiagram ); + + static bool setDiagramPositioning( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xChartModel, + const ::com::sun::star::awt::Rectangle& rPosRect /*100th mm*/ ); + + static ::com::sun::star::awt::Rectangle getDiagramRectangleFromModel( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xChartModel ); + + static bool switchDiagramPositioningToExcludingPositioning( const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XModel >& xChartModel + , bool bResetModifiedState //set model back to unchanged if it was unchanged before + , bool bConvertAlsoFromAutoPositioning ); + private: // not implemented DiagramHelper(); diff --git a/chart2/source/inc/chartview/ExplicitValueProvider.hxx b/chart2/source/inc/chartview/ExplicitValueProvider.hxx index 49d38a4247ac..d10ee8d415fc 100644 --- a/chart2/source/inc/chartview/ExplicitValueProvider.hxx +++ b/chart2/source/inc/chartview/ExplicitValueProvider.hxx @@ -68,6 +68,8 @@ public: virtual ::com::sun::star::awt::Rectangle getRectangleOfObject( const rtl::OUString& rObjectCID, bool bSnapRect=false )=0; + virtual ::com::sun::star::awt::Rectangle getDiagramRectangleExcludingAxes()=0; + virtual ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > getShapeForCID( const rtl::OUString& rObjectCID )=0; @@ -77,12 +79,20 @@ public: static ExplicitValueProvider* getExplicitValueProvider( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xChartView ); static ::com::sun::star::awt::Rectangle - calculateDiagramPositionAndSizeInclusiveTitle( + addAxisTitleSizes( + const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XModel >& xChartModel + , const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XInterface >& xChartView + , const ::com::sun::star::awt::Rectangle& rExcludingPositionAndSize ); + + static ::com::sun::star::awt::Rectangle + substractAxisTitleSizes( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& xChartModel , const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xChartView - , const ::com::sun::star::awt::Rectangle& rExclusivePositionAndSize ); + , const ::com::sun::star::awt::Rectangle& rPositionAndSizeIncludingTitles ); static sal_Int32 getExplicitNumberFormatKeyForAxis( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XAxis >& xAxis diff --git a/chart2/source/model/main/Diagram.cxx b/chart2/source/model/main/Diagram.cxx index f74764c398ef..b24f4059ba74 100644 --- a/chart2/source/model/main/Diagram.cxx +++ b/chart2/source/model/main/Diagram.cxx @@ -71,6 +71,7 @@ enum { PROP_DIAGRAM_REL_POS, PROP_DIAGRAM_REL_SIZE, + PROP_DIAGRAM_POSSIZE_EXCLUDE_LABELS, PROP_DIAGRAM_SORT_BY_X_VALUES, PROP_DIAGRAM_CONNECT_BARS, PROP_DIAGRAM_GROUP_BARS_PER_AXIS, @@ -101,6 +102,13 @@ void lcl_AddPropertiesToVector( | beans::PropertyAttribute::MAYBEVOID )); rOutProperties.push_back( + Property( C2U( "PosSizeExcludeAxes" ), + PROP_DIAGRAM_POSSIZE_EXCLUDE_LABELS, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( Property( C2U( "SortByXValues" ), PROP_DIAGRAM_SORT_BY_X_VALUES, ::getBooleanCppuType(), @@ -171,6 +179,7 @@ void lcl_AddPropertiesToVector( void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap ) { + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_POSSIZE_EXCLUDE_LABELS, true ); ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_SORT_BY_X_VALUES, false ); ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_CONNECT_BARS, false ); ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_GROUP_BARS_PER_AXIS, true ); diff --git a/chart2/source/tools/DiagramHelper.cxx b/chart2/source/tools/DiagramHelper.cxx index b95e7522943e..4ce623ae460c 100644 --- a/chart2/source/tools/DiagramHelper.cxx +++ b/chart2/source/tools/DiagramHelper.cxx @@ -39,8 +39,13 @@ #include "CommonConverters.hxx" #include "ExplicitCategoriesProvider.hxx" #include "servicenames_charttypes.hxx" +#include "ChartModelHelper.hxx" +#include "RelativePositionHelper.hxx" +#include "ControllerLockGuard.hxx" #include <com/sun/star/chart/MissingValueTreatment.hpp> +#include <com/sun/star/chart/XChartDocument.hpp> +#include <com/sun/star/chart/XDiagramPositioning.hpp> #include <com/sun/star/chart2/XTitled.hpp> #include <com/sun/star/chart2/XChartTypeContainer.hpp> #include <com/sun/star/chart2/XChartTypeTemplate.hpp> @@ -49,10 +54,14 @@ #include <com/sun/star/chart2/InterpretedData.hpp> #include <com/sun/star/chart2/AxisType.hpp> #include <com/sun/star/chart2/DataPointGeometry3D.hpp> -#include <com/sun/star/drawing/ShadeMode.hpp> +#include <com/sun/star/chart2/RelativePosition.hpp> +#include <com/sun/star/chart2/RelativeSize.hpp> +#include <unotools/saveopt.hxx> #include <rtl/math.hxx> +#include <com/sun/star/util/XModifiable.hpp> + using namespace ::com::sun::star; using namespace ::com::sun::star::chart2; using namespace ::std; @@ -1407,4 +1416,142 @@ sal_Int32 DiagramHelper::getCorrectedMissingValueTreatment( return nResult; } +//static +DiagramPositioningMode DiagramHelper::getDiagramPositioningMode( const uno::Reference< + chart2::XDiagram > & xDiagram ) +{ + DiagramPositioningMode eMode = DiagramPositioningMode_AUTO; + uno::Reference< beans::XPropertySet > xDiaProps( xDiagram, uno::UNO_QUERY ); + if( xDiaProps.is() ) + { + RelativePosition aRelPos; + RelativeSize aRelSize; + if( (xDiaProps->getPropertyValue(C2U("RelativePosition")) >>= aRelPos ) && + (xDiaProps->getPropertyValue(C2U("RelativeSize")) >>= aRelSize ) ) + { + bool bPosSizeExcludeAxes=false; + xDiaProps->getPropertyValue(C2U("PosSizeExcludeAxes")) >>= bPosSizeExcludeAxes; + if( bPosSizeExcludeAxes ) + eMode = DiagramPositioningMode_EXCLUDING; + else + eMode = DiagramPositioningMode_INCLUDING; + } + } + return eMode; +} + +void lcl_ensureRange0to1( double& rValue ) +{ + if(rValue<0.0) + rValue=0.0; + if(rValue>1.0) + rValue=1.0; +} + +//static +bool DiagramHelper::setDiagramPositioning( const uno::Reference< frame::XModel >& xChartModel, + const awt::Rectangle& rPosRect /*100th mm*/ ) +{ + ControllerLockGuard aCtrlLockGuard( xChartModel ); + + bool bChanged = false; + awt::Size aPageSize( ChartModelHelper::getPageSize(xChartModel) ); + uno::Reference< beans::XPropertySet > xDiaProps( ChartModelHelper::findDiagram( xChartModel ), uno::UNO_QUERY ); + if( !xDiaProps.is() ) + return bChanged; + + RelativePosition aOldPos; + RelativeSize aOldSize; + xDiaProps->getPropertyValue(C2U("RelativePosition") ) >>= aOldPos; + xDiaProps->getPropertyValue(C2U("RelativeSize") ) >>= aOldSize; + + RelativePosition aNewPos; + aNewPos.Anchor = drawing::Alignment_TOP_LEFT; + aNewPos.Primary = double(rPosRect.X)/double(aPageSize.Width); + aNewPos.Secondary = double(rPosRect.Y)/double(aPageSize.Height); + + chart2::RelativeSize aNewSize; + aNewSize.Primary = double(rPosRect.Width)/double(aPageSize.Width); + aNewSize.Secondary = double(rPosRect.Height)/double(aPageSize.Height); + + lcl_ensureRange0to1( aNewPos.Primary ); + lcl_ensureRange0to1( aNewPos.Secondary ); + lcl_ensureRange0to1( aNewSize.Primary ); + lcl_ensureRange0to1( aNewSize.Secondary ); + if( (aNewPos.Primary + aNewSize.Primary) > 1.0 ) + aNewPos.Primary = 1.0 - aNewSize.Primary; + if( (aNewPos.Secondary + aNewSize.Secondary) > 1.0 ) + aNewPos.Secondary = 1.0 - aNewSize.Secondary; + + xDiaProps->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aNewPos) ); + xDiaProps->setPropertyValue( C2U( "RelativeSize" ), uno::makeAny(aNewSize) ); + + bChanged = (aOldPos.Anchor!=aNewPos.Anchor) || + (aOldPos.Primary!=aNewPos.Primary) || + (aOldPos.Secondary!=aNewPos.Secondary) || + (aOldSize.Primary!=aNewSize.Primary) || + (aOldSize.Secondary!=aNewSize.Secondary); + return bChanged; +} + +//static +awt::Rectangle DiagramHelper::getDiagramRectangleFromModel( const uno::Reference< frame::XModel >& xChartModel ) +{ + awt::Rectangle aRet(-1,-1,-1,-1); + + uno::Reference< beans::XPropertySet > xDiaProps( ChartModelHelper::findDiagram( xChartModel ), uno::UNO_QUERY ); + if( !xDiaProps.is() ) + return aRet; + + awt::Size aPageSize( ChartModelHelper::getPageSize(xChartModel) ); + + RelativePosition aRelPos; + RelativeSize aRelSize; + xDiaProps->getPropertyValue(C2U("RelativePosition") ) >>= aRelPos; + xDiaProps->getPropertyValue(C2U("RelativeSize") ) >>= aRelSize; + + awt::Size aAbsSize( + aRelSize.Primary * aPageSize.Width, + aRelSize.Secondary * aPageSize.Height ); + + awt::Point aAbsPos( + static_cast< sal_Int32 >( aRelPos.Primary * aPageSize.Width ), + static_cast< sal_Int32 >( aRelPos.Secondary * aPageSize.Height )); + + awt::Point aAbsPosLeftTop = RelativePositionHelper::getUpperLeftCornerOfAnchoredObject( aAbsPos, aAbsSize, aRelPos.Anchor ); + + aRet = awt::Rectangle(aAbsPosLeftTop.X, aAbsPosLeftTop.Y, aAbsSize.Width, aAbsSize.Height ); + + return aRet; +} + +//static +bool DiagramHelper::switchDiagramPositioningToExcludingPositioning( + const uno::Reference< frame::XModel >& xChartModel + , bool bResetModifiedState, bool bConvertAlsoFromAutoPositioning ) +{ + //return true if something was changed + const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() ); + if( nCurrentODFVersion == SvtSaveOptions::ODFVER_LATEST )//#i100778# todo: change this dependent on fileformat evolution + { + uno::Reference< ::com::sun::star::chart::XChartDocument > xOldDoc( xChartModel, uno::UNO_QUERY ) ; + if( xOldDoc.is() ) + { + uno::Reference< ::com::sun::star::chart::XDiagramPositioning > xDiagramPositioning( xOldDoc->getDiagram(), uno::UNO_QUERY ); + if( xDiagramPositioning.is() && ( bConvertAlsoFromAutoPositioning || !xDiagramPositioning->isAutomaticDiagramPositioning() ) + && !xDiagramPositioning->isExcludingDiagramPositioning() ) + { + ControllerLockGuard aCtrlLockGuard( xChartModel ); + uno::Reference< util::XModifiable > xModifiable( xChartModel, uno::UNO_QUERY ); + bool bModelWasModified = xModifiable.is() && xModifiable->isModified(); + xDiagramPositioning->setDiagramPositionExcludingAxes( xDiagramPositioning->calculateDiagramPositionExcludingAxes() ); + if(bResetModifiedState && !bModelWasModified && xModifiable.is() ) + xModifiable->setModified(sal_False); + return true; + } + } + } + return false; +} + } // namespace chart diff --git a/chart2/source/view/charttypes/PieChart.cxx b/chart2/source/view/charttypes/PieChart.cxx index b9eac0fc7291..eee13848b11b 100644 --- a/chart2/source/view/charttypes/PieChart.cxx +++ b/chart2/source/view/charttypes/PieChart.cxx @@ -121,10 +121,12 @@ bool PiePositionHelper::getInnerAndOuterRadius( double fCategoryX //----------------------------------------------------------------------------- PieChart::PieChart( const uno::Reference<XChartType>& xChartTypeModel - , sal_Int32 nDimensionCount ) + , sal_Int32 nDimensionCount + , bool bExcludingPositioning ) : VSeriesPlotter( xChartTypeModel, nDimensionCount ) , m_pPosHelper( new PiePositionHelper( NormalAxis_Z, (m_nDimension==3)?0.0:90.0 ) ) , m_bUseRings(false) + , m_bSizeExcludesLabelsAndExplodedSegments(bExcludingPositioning) { ::rtl::math::setNan(&m_fMaxOffset); @@ -181,6 +183,11 @@ bool PieChart::keepAspectRatio() const return true; } +bool PieChart::shouldSnapRectToUsedArea() +{ + return true; +} + //----------------------------------------------------------------- // lang::XServiceInfo //----------------------------------------------------------------- @@ -273,18 +280,21 @@ double PieChart::getMaxOffset() if(fExplodePercentage>m_fMaxOffset) m_fMaxOffset=fExplodePercentage; - uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; - if( xSeriesProp->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) + if(!m_bSizeExcludesLabelsAndExplodedSegments) { - for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) + uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; + if( xSeriesProp->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) { - uno::Reference< beans::XPropertySet > xPointProp( pSeries->getPropertiesOfPoint(aAttributedDataPointIndexList[nN]) ); - if(xPointProp.is()) + for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) { - fExplodePercentage=0.0; - xPointProp->getPropertyValue( C2U( "Offset" )) >>= fExplodePercentage; - if(fExplodePercentage>m_fMaxOffset) - m_fMaxOffset=fExplodePercentage; + uno::Reference< beans::XPropertySet > xPointProp( pSeries->getPropertiesOfPoint(aAttributedDataPointIndexList[nN]) ); + if(xPointProp.is()) + { + fExplodePercentage=0.0; + xPointProp->getPropertyValue( C2U( "Offset" )) >>= fExplodePercentage; + if(fExplodePercentage>m_fMaxOffset) + m_fMaxOffset=fExplodePercentage; + } } } } @@ -396,7 +406,8 @@ void PieChart::createShapes() for( nPointIndex = 0; nPointIndex < nPointCount; nPointIndex++ ) { double fLogicInnerRadius, fLogicOuterRadius; - bool bIsVisible = m_pPosHelper->getInnerAndOuterRadius( fSlotX+1.0, fLogicInnerRadius, fLogicOuterRadius, m_bUseRings, getMaxOffset() ); + double fOffset = getMaxOffset(); + bool bIsVisible = m_pPosHelper->getInnerAndOuterRadius( fSlotX+1.0, fLogicInnerRadius, fLogicOuterRadius, m_bUseRings, fOffset ); if( !bIsVisible ) continue; diff --git a/chart2/source/view/charttypes/PieChart.hxx b/chart2/source/view/charttypes/PieChart.hxx index 52545f6476b8..e6fedb05d52e 100644 --- a/chart2/source/view/charttypes/PieChart.hxx +++ b/chart2/source/view/charttypes/PieChart.hxx @@ -46,7 +46,7 @@ class PieChart : public VSeriesPlotter public: PieChart( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartTypeModel - , sal_Int32 nDimensionCount ); + , sal_Int32 nDimensionCount, bool bExcludingPositioning ); virtual ~PieChart(); //------------------------------------------------------------------------- @@ -72,6 +72,7 @@ public: //------------------- virtual ::com::sun::star::drawing::Direction3D getPreferredDiagramAspectRatio() const; virtual bool keepAspectRatio() const; + virtual bool shouldSnapRectToUsedArea(); //MinimumAndMaximumSupplier virtual double getMinimumX(); @@ -113,6 +114,7 @@ struct PieLabelInfo; private: //member PiePositionHelper* m_pPosHelper; bool m_bUseRings; + bool m_bSizeExcludesLabelsAndExplodedSegments; struct PieLabelInfo { diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index 37888c8f0a9b..840cbbe3e1e1 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -1744,6 +1744,13 @@ bool VSeriesPlotter::WantToPlotInFrontOfAxisLine() return ChartTypeHelper::isSeriesInFrontOfAxisLine( m_xChartTypeModel ); } +bool VSeriesPlotter::shouldSnapRectToUsedArea() +{ + if( m_nDimension == 3 ) + return false; + return true; +} + Sequence< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntries( LegendExpansion eLegendExpansion , const Reference< beans::XPropertySet >& xTextProperties @@ -2066,7 +2073,8 @@ std::vector< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntriesForCh //static VSeriesPlotter* VSeriesPlotter::createSeriesPlotter( const uno::Reference<XChartType>& xChartTypeModel - , sal_Int32 nDimensionCount ) + , sal_Int32 nDimensionCount + , bool bExcludingPositioning ) { rtl::OUString aChartType = xChartTypeModel->getChartType(); @@ -2085,7 +2093,7 @@ VSeriesPlotter* VSeriesPlotter::createSeriesPlotter( else if( aChartType.equalsIgnoreAsciiCase(CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE) ) pRet = new BubbleChart(xChartTypeModel,nDimensionCount); else if( aChartType.equalsIgnoreAsciiCase(CHART2_SERVICE_NAME_CHARTTYPE_PIE) ) - pRet = new PieChart(xChartTypeModel,nDimensionCount); + pRet = new PieChart(xChartTypeModel,nDimensionCount, bExcludingPositioning ); else if( aChartType.equalsIgnoreAsciiCase(CHART2_SERVICE_NAME_CHARTTYPE_NET) ) pRet = new AreaChart(xChartTypeModel,nDimensionCount,true,true,new PolarPlottingPositionHelper(),true,false,1,drawing::Direction3D(1,1,1) ); else if( aChartType.equalsIgnoreAsciiCase(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) ) diff --git a/chart2/source/view/diagram/VDiagram.cxx b/chart2/source/view/diagram/VDiagram.cxx index 5ffec22969a0..4174226b6f62 100644 --- a/chart2/source/view/diagram/VDiagram.cxx +++ b/chart2/source/view/diagram/VDiagram.cxx @@ -49,6 +49,8 @@ #include <com/sun/star/lang/XTypeProvider.hpp> // header for class SvxShape #include <svx/unoshape.hxx> +// header for GetSdrObjectFromXShape +#include <svx/unoapi.hxx> // header for class E3dScene #include <svx/scene3d.hxx> #include <rtl/math.hxx> @@ -179,6 +181,8 @@ void VDiagram::createShapes_2d() uno::Reference< drawing::XShapes > xOuterGroup_Shapes = m_pShapeFactory->createGroup2D(m_xLogicTarget); m_xOuterGroupShape = uno::Reference<drawing::XShape>( xOuterGroup_Shapes, uno::UNO_QUERY ); + uno::Reference< drawing::XShapes > xGroupForWall( m_pShapeFactory->createGroup2D(xOuterGroup_Shapes,C2U("PlotAreaExcludingAxes")) ); + //create independent group shape as container for datapoints and such things { uno::Reference< drawing::XShapes > xShapes = m_pShapeFactory->createGroup2D(xOuterGroup_Shapes,C2U("testonly;CooContainer=XXX_CID")); @@ -195,8 +199,7 @@ void VDiagram::createShapes_2d() "com.sun.star.drawing.RectangleShape" ) ), uno::UNO_QUERY ); //m_xWall2D->setPosition(m_aAvailablePosIncludingAxes); //m_xWall2D->setSize(m_aAvailableSizeIncludingAxes); - uno::Reference< drawing::XShapes > xShapes( m_xCoordinateRegionShape, uno::UNO_QUERY ); - xShapes->add(m_xWall2D); + xGroupForWall->add(m_xWall2D); uno::Reference< beans::XPropertySet > xProp( m_xWall2D, uno::UNO_QUERY ); if( xProp.is()) { @@ -518,6 +521,7 @@ void VDiagram::createShapes_3d() m_xOuterGroupShape = uno::Reference< drawing::XShape >( m_xShapeFactory->createInstance( C2U( "com.sun.star.drawing.Shape3DSceneObject" ) ), uno::UNO_QUERY ); + ShapeFactory::setShapeName( m_xOuterGroupShape, C2U("PlotAreaExcludingAxes") ); m_xLogicTarget->add(m_xOuterGroupShape); uno::Reference< drawing::XShapes > xOuterGroup_Shapes = diff --git a/chart2/source/view/inc/VSeriesPlotter.hxx b/chart2/source/view/inc/VSeriesPlotter.hxx index 02c1f3b044e9..6b6b06437542 100644 --- a/chart2/source/view/inc/VSeriesPlotter.hxx +++ b/chart2/source/view/inc/VSeriesPlotter.hxx @@ -264,7 +264,8 @@ public: static VSeriesPlotter* createSeriesPlotter( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& xChartTypeModel - , sal_Int32 nDimensionCount ); + , sal_Int32 nDimensionCount + , bool bExcludingPositioning = false /*for pie and donut charts labels and exploded segments are excluded from the given size*/); sal_Int32 getPointCount() const; @@ -293,6 +294,7 @@ public: virtual void rearrangeLabelToAvoidOverlapIfRequested( const ::com::sun::star::awt::Size& rPageSize ); bool WantToPlotInFrontOfAxisLine(); + virtual bool shouldSnapRectToUsedArea(); //------------------------------------------------------------------------- //------------------------------------------------------------------------- diff --git a/chart2/source/view/main/ChartItemPool.cxx b/chart2/source/view/main/ChartItemPool.cxx index 83368fa3907a..d8f997d36da9 100644 --- a/chart2/source/view/main/ChartItemPool.cxx +++ b/chart2/source/view/main/ChartItemPool.cxx @@ -37,6 +37,7 @@ #include <editeng/brshitem.hxx> #include <editeng/sizeitem.hxx> #include <svl/stritem.hxx> +#include <svl/rectitem.hxx> #include <svl/ilstitem.hxx> #define _SVSTDARR_ULONGS #include <svl/svstdarr.hxx> diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index c5ba0c38ab05..c13216a041d7 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -169,6 +169,7 @@ ChartView::ChartView( , m_nScaleYNumerator(1) , m_nScaleYDenominator(1) , m_bSdrViewIsInEditMode(sal_False) + , m_aResultingDiagramRectangleExcludingAxes(0,0,0,0) { } @@ -313,7 +314,7 @@ uno::Any SAL_CALL ChartView::getTransferData( const datatransfer::DataFlavor& aF if( ! (bHighContrastMetaFile || aFlavor.MimeType.equals(lcl_aGDIMetaFileMIMEType)) ) return aRet; - impl_updateView(); + update(); SvMemoryStream aStream( 1024, 1024 ); utl::OStreamWrapper* pStreamWrapper = new utl::OStreamWrapper( aStream ); @@ -681,7 +682,8 @@ void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter( if(nT==0) m_bChartTypeUsesShiftedXAxisTicksPerDefault = ChartTypeHelper::shiftTicksAtXAxisPerDefault( xChartType ); - VSeriesPlotter* pPlotter = VSeriesPlotter::createSeriesPlotter( xChartType, nDimensionCount ); + bool bExcludingPositioning = DiagramPositioningMode_EXCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ); + VSeriesPlotter* pPlotter = VSeriesPlotter::createSeriesPlotter( xChartType, nDimensionCount, bExcludingPositioning ); if( !pPlotter ) continue; m_aSeriesPlotterList.push_back( pPlotter ); @@ -1166,7 +1168,7 @@ drawing::Direction3D SeriesPlotterContainer::getPreferredAspectRatio() namespace { -bool lcl_resizeAfterCompleteCreation( const uno::Reference< XDiagram >& xDiagram ) +bool lcl_IsPieOrDonut( const uno::Reference< XDiagram >& xDiagram ) { //special treatment for pie charts //the size is checked after complete creation to get the datalabels into the given space @@ -1324,16 +1326,23 @@ sal_Int16 lcl_getDefaultWritingModeFromPool( ::boost::shared_ptr< DrawModelWrapp } //end anonymous namespace //------------ create complete diagram shape (inclusive axis and series) -void ChartView::impl_createDiagramAndContent( SeriesPlotterContainer& rSeriesPlotterContainer + +awt::Rectangle ChartView::impl_createDiagramAndContent( SeriesPlotterContainer& rSeriesPlotterContainer , const uno::Reference< drawing::XShapes>& xDiagramPlusAxes_Shapes , const awt::Point& rAvailablePos , const awt::Size& rAvailableSize - , const awt::Size& rPageSize ) + , const awt::Size& rPageSize + , bool bUseFixedInnerSize + , const uno::Reference< drawing::XShape>& xDiagram_MarkHandles /*needs to be resized to fit the result*/ + ) { + //return the used rectangle + awt::Rectangle aUsedOuterRect( rAvailablePos.X, rAvailablePos.Y, 0, 0 ); + // sal_Int32 nDiagramIndex = 0;//todo if more than one diagam is supported uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) ); if( !xDiagram.is()) - return; + return aUsedOuterRect; sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram ); if(!nDimensionCount) @@ -1389,7 +1398,8 @@ void ChartView::impl_createDiagramAndContent( SeriesPlotterContainer& rSeriesPlo aVDiagram.init(xDiagramPlusAxes_Shapes,xDiagramPlusAxes_Shapes,m_xShapeFactory); aVDiagram.createShapes(rAvailablePos,rAvailableSize); xSeriesTargetInFrontOfAxis = aVDiagram.getCoordinateRegion(); - aVDiagram.reduceToMimimumSize(); + if( !bUseFixedInnerSize ) + aVDiagram.reduceToMimimumSize(); } uno::Reference< drawing::XShapes > xTextTargetShapes( ShapeFactory(m_xShapeFactory).createGroup2D(xDiagramPlusAxes_Shapes) ); @@ -1410,19 +1420,21 @@ void ChartView::impl_createDiagramAndContent( SeriesPlotterContainer& rSeriesPlo //calculate resulting size respecting axis label layout and fontscaling + uno::Reference< drawing::XShape > xBoundingShape( xDiagramPlusAxes_Shapes, uno::UNO_QUERY ); + ::basegfx::B2IRectangle aConsumedOuterRect; + //use first coosys only so far; todo: calculate for more than one coosys if we have more in future //todo: this is just a workaround at the moment for pie and donut labels - if( !lcl_resizeAfterCompleteCreation(xDiagram) && rVCooSysList.size() > 0 ) + bool bIsPieOrDonut = lcl_IsPieOrDonut(xDiagram); + if( !bIsPieOrDonut && rVCooSysList.size() > 0 ) { - uno::Reference< drawing::XShape > xBoundingShape( xDiagramPlusAxes_Shapes, uno::UNO_QUERY ); - - ::basegfx::B2IRectangle aFirstConsumedOuterRect( ShapeFactory::getRectangleOfShape(xBoundingShape) ); - VCoordinateSystem* pVCooSys = rVCooSysList[0]; pVCooSys->createMaximumAxesLabels(); - ::basegfx::B2IRectangle aConsumedOuterRect( ShapeFactory::getRectangleOfShape(xBoundingShape) ); - ::basegfx::B2IRectangle aNewInnerRect( aVDiagram.adjustInnerSize( aConsumedOuterRect ) ); + aConsumedOuterRect = ::basegfx::B2IRectangle( ShapeFactory::getRectangleOfShape(xBoundingShape) ); + ::basegfx::B2IRectangle aNewInnerRect( aVDiagram.getCurrentRectangle() ); + if( !bUseFixedInnerSize ) + aNewInnerRect = aVDiagram.adjustInnerSize( aConsumedOuterRect ); pVCooSys->setTransformationSceneToScreen( B3DHomMatrixToHomogenMatrix( createTransformationSceneToScreen( aNewInnerRect ) )); @@ -1445,13 +1457,13 @@ void ChartView::impl_createDiagramAndContent( SeriesPlotterContainer& rSeriesPlo bLessSpaceConsumedThanExpected = true; } - if( bLessSpaceConsumedThanExpected ) + if( bLessSpaceConsumedThanExpected && !bUseFixedInnerSize ) { aVDiagram.adjustInnerSize( aConsumedOuterRect ); pVCooSys->setTransformationSceneToScreen( B3DHomMatrixToHomogenMatrix( createTransformationSceneToScreen( aVDiagram.getCurrentRectangle() ) )); - pVCooSys->updatePositions(); } + pVCooSys->updatePositions();//todo: logically this belongs to the condition above, but it seems also to be neccessary to give the axes group shapes the right bounding rects for hit test - probably caused by bug i106183 -> check again if fixed } //create axes and grids for the final size @@ -1481,7 +1493,7 @@ void ChartView::impl_createDiagramAndContent( SeriesPlotterContainer& rSeriesPlo else { xSeriesTarget = xSeriesTargetBehindAxis; - DBG_ASSERT( !lcl_resizeAfterCompleteCreation(xDiagram), "not implemented yet! - during a complete recreation this shape is destroyed so no series can be created anymore" ); + DBG_ASSERT( !bIsPieOrDonut, "not implemented yet! - during a complete recreation this shape is destroyed so no series can be created anymore" ); } pSeriesPlotter->initPlotter( xSeriesTarget,xTextTargetShapes,m_xShapeFactory,aCID ); pSeriesPlotter->setPageReferenceSize( rPageSize ); @@ -1500,15 +1512,15 @@ void ChartView::impl_createDiagramAndContent( SeriesPlotterContainer& rSeriesPlo m_bPointsWereSkipped = m_bPointsWereSkipped || pSeriesPlotter->PointsWereSkipped(); } - //recreate with corrected sizes if requested - if( lcl_resizeAfterCompleteCreation(xDiagram) ) + //recreate all with corrected sizes if requested + if( bIsPieOrDonut ) { m_bPointsWereSkipped = false; - uno::Reference< drawing::XShape > xBoundingShape( xDiagramPlusAxes_Shapes, uno::UNO_QUERY ); - ::basegfx::B2IRectangle aConsumedOuterRect( ShapeFactory::getRectangleOfShape(xBoundingShape) ); - - ::basegfx::B2IRectangle aNewInnerRect( aVDiagram.adjustInnerSize( aConsumedOuterRect ) ); + aConsumedOuterRect = ::basegfx::B2IRectangle( ShapeFactory::getRectangleOfShape(xBoundingShape) ); + ::basegfx::B2IRectangle aNewInnerRect( aVDiagram.getCurrentRectangle() ); + if( !bUseFixedInnerSize ) + aNewInnerRect = aVDiagram.adjustInnerSize( aConsumedOuterRect ); for( aPlotterIter = rSeriesPlotterList.begin(); aPlotterIter != aPlotterEnd; aPlotterIter++ ) { @@ -1565,6 +1577,63 @@ void ChartView::impl_createDiagramAndContent( SeriesPlotterContainer& rSeriesPlo pSeriesPlotter->rearrangeLabelToAvoidOverlapIfRequested( rPageSize ); } } + + if( bUseFixedInnerSize ) + { + //if( !bIsPieOrDonut ) + // aConsumedOuterRect = ::basegfx::B2IRectangle( ShapeFactory::getRectangleOfShape(xBoundingShape) ); + aUsedOuterRect = awt::Rectangle( aConsumedOuterRect.getMinX(), aConsumedOuterRect.getMinY(), aConsumedOuterRect.getWidth(), aConsumedOuterRect.getHeight() ); + } + else + aUsedOuterRect = awt::Rectangle( rAvailablePos.X, rAvailablePos.Y, rAvailableSize.Width, rAvailableSize.Height ); + + bool bSnapRectToUsedArea = false; + for( aPlotterIter = rSeriesPlotterList.begin(); aPlotterIter != aPlotterEnd; aPlotterIter++ ) + { + VSeriesPlotter* pSeriesPlotter = *aPlotterIter; + bSnapRectToUsedArea = pSeriesPlotter->shouldSnapRectToUsedArea(); + if(bSnapRectToUsedArea) + break; + } + if(bSnapRectToUsedArea) + { + if( bUseFixedInnerSize ) + m_aResultingDiagramRectangleExcludingAxes = getRectangleOfObject( C2U("PlotAreaExcludingAxes") ); + else + { + ::basegfx::B2IRectangle aConsumedInnerRect = aVDiagram.getCurrentRectangle(); + m_aResultingDiagramRectangleExcludingAxes = awt::Rectangle( aConsumedInnerRect.getMinX(), aConsumedInnerRect.getMinY(), aConsumedInnerRect.getWidth(), aConsumedInnerRect.getHeight() ); + } + } + else + { + if( bUseFixedInnerSize ) + m_aResultingDiagramRectangleExcludingAxes = awt::Rectangle( rAvailablePos.X, rAvailablePos.Y, rAvailableSize.Width, rAvailableSize.Height ); + else + { + ::basegfx::B2IRectangle aConsumedInnerRect = aVDiagram.getCurrentRectangle(); + m_aResultingDiagramRectangleExcludingAxes = awt::Rectangle( aConsumedInnerRect.getMinX(), aConsumedInnerRect.getMinY(), aConsumedInnerRect.getWidth(), aConsumedInnerRect.getHeight() ); + } + } + + if( xDiagram_MarkHandles.is() ) + { + awt::Point aPos(rAvailablePos); + awt::Size aSize(rAvailableSize); + bool bPosSizeExcludeAxesProperty = true; + uno::Reference< beans::XPropertySet > xDiaProps( xDiagram, uno::UNO_QUERY_THROW ); + if( xDiaProps.is() ) + xDiaProps->getPropertyValue(C2U("PosSizeExcludeAxes")) >>= bPosSizeExcludeAxesProperty; + if( bUseFixedInnerSize || bPosSizeExcludeAxesProperty ) + { + aPos = awt::Point( m_aResultingDiagramRectangleExcludingAxes.X, m_aResultingDiagramRectangleExcludingAxes.Y ); + aSize = awt::Size( m_aResultingDiagramRectangleExcludingAxes.Width, m_aResultingDiagramRectangleExcludingAxes.Height ); + } + xDiagram_MarkHandles->setPosition( aPos ); + xDiagram_MarkHandles->setSize( aSize ); + } + + return aUsedOuterRect; } //------------------------------------------------------------- @@ -1622,6 +1691,12 @@ uno::Reference< drawing::XShape > ChartView::getShapeForCID( const rtl::OUString return 0; } +awt::Rectangle ChartView::getDiagramRectangleExcludingAxes() +{ + impl_updateView(); + return m_aResultingDiagramRectangleExcludingAxes; +} + awt::Rectangle ChartView::getRectangleOfObject( const rtl::OUString& rObjectCID, bool bSnapRect ) { impl_updateView(); @@ -1645,7 +1720,10 @@ awt::Rectangle ChartView::getRectangleOfObject( const rtl::OUString& rObjectCID, SdrObjList* pRootList = pRootSdrObject->GetSubList(); if( pRootList ) { - SdrObject* pShape = DrawModelWrapper::getNamedSdrObject( C2U("MarkHandles"), pRootList ); + OUString aShapeName = C2U("MarkHandles"); + if( eObjectType == OBJECTTYPE_DIAGRAM ) + aShapeName = C2U("PlotAreaIncludingAxes"); + SdrObject* pShape = DrawModelWrapper::getNamedSdrObject( aShapeName, pRootList ); if( pShape ) xShape = uno::Reference< drawing::XShape >( pShape->getUnoShape(), uno::UNO_QUERY); } @@ -1933,12 +2011,12 @@ sal_Int32 ExplicitValueProvider::getExplicitPercentageNumberFormatKeyForDataLabe } //static -awt::Rectangle ExplicitValueProvider::calculateDiagramPositionAndSizeInclusiveTitle( +awt::Rectangle ExplicitValueProvider::addAxisTitleSizes( const Reference< frame::XModel >& xChartModel , const Reference< uno::XInterface >& xChartView - , const awt::Rectangle& rExclusivePositionAndSize ) + , const awt::Rectangle& rExcludingPositionAndSize ) { - awt::Rectangle aRet(rExclusivePositionAndSize); + awt::Rectangle aRet(rExcludingPositionAndSize); //add axis title sizes to the diagram size uno::Reference< chart2::XTitle > xTitle_Height( TitleHelper::getTitle( TitleHelper::TITLE_AT_STANDARD_X_AXIS_POSITION, xChartModel ) ); @@ -2000,6 +2078,74 @@ awt::Rectangle ExplicitValueProvider::calculateDiagramPositionAndSizeInclusiveTi return aRet; } +//static +awt::Rectangle ExplicitValueProvider::substractAxisTitleSizes( + const Reference< frame::XModel >& xChartModel + , const Reference< uno::XInterface >& xChartView + , const awt::Rectangle& rPositionAndSizeIncludingTitles ) +{ + awt::Rectangle aRet(rPositionAndSizeIncludingTitles); + + //add axis title sizes to the diagram size + uno::Reference< chart2::XTitle > xTitle_Height( TitleHelper::getTitle( TitleHelper::TITLE_AT_STANDARD_X_AXIS_POSITION, xChartModel ) ); + uno::Reference< chart2::XTitle > xTitle_Width( TitleHelper::getTitle( TitleHelper::TITLE_AT_STANDARD_Y_AXIS_POSITION, xChartModel ) ); + uno::Reference< chart2::XTitle > xSecondTitle_Height( TitleHelper::getTitle( TitleHelper::SECONDARY_X_AXIS_TITLE, xChartModel ) ); + uno::Reference< chart2::XTitle > xSecondTitle_Width( TitleHelper::getTitle( TitleHelper::SECONDARY_Y_AXIS_TITLE, xChartModel ) ); + if( xTitle_Height.is() || xTitle_Width.is() || xSecondTitle_Height.is() || xSecondTitle_Width.is() ) + { + ExplicitValueProvider* pExplicitValueProvider = ExplicitValueProvider::getExplicitValueProvider(xChartView); + if( pExplicitValueProvider ) + { + //detect wether x axis points into x direction or not + if( lcl_getPropertySwapXAndYAxis( ChartModelHelper::findDiagram( xChartModel ) ) ) + { + std::swap( xTitle_Height, xTitle_Width ); + std::swap( xSecondTitle_Height, xSecondTitle_Width ); + } + + sal_Int32 nTitleSpaceWidth = 0; + sal_Int32 nTitleSpaceHeight = 0; + sal_Int32 nSecondTitleSpaceWidth = 0; + sal_Int32 nSecondTitleSpaceHeight = 0; + + if( xTitle_Height.is() ) + { + rtl::OUString aCID_X( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle_Height, xChartModel ) ); + nTitleSpaceHeight = pExplicitValueProvider->getRectangleOfObject( aCID_X, true ).Height; + if( nTitleSpaceHeight ) + nTitleSpaceHeight+=lcl_getDiagramTitleSpace(); + } + if( xTitle_Width.is() ) + { + rtl::OUString aCID_Y( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle_Width, xChartModel ) ); + nTitleSpaceWidth = pExplicitValueProvider->getRectangleOfObject( aCID_Y, true ).Width; + if(nTitleSpaceWidth) + nTitleSpaceWidth+=lcl_getDiagramTitleSpace(); + } + if( xSecondTitle_Height.is() ) + { + rtl::OUString aCID_X( ObjectIdentifier::createClassifiedIdentifierForObject( xSecondTitle_Height, xChartModel ) ); + nSecondTitleSpaceHeight = pExplicitValueProvider->getRectangleOfObject( aCID_X, true ).Height; + if( nSecondTitleSpaceHeight ) + nSecondTitleSpaceHeight+=lcl_getDiagramTitleSpace(); + } + if( xSecondTitle_Width.is() ) + { + rtl::OUString aCID_Y( ObjectIdentifier::createClassifiedIdentifierForObject( xSecondTitle_Width, xChartModel ) ); + nSecondTitleSpaceWidth += pExplicitValueProvider->getRectangleOfObject( aCID_Y, true ).Width; + if( nSecondTitleSpaceWidth ) + nSecondTitleSpaceWidth+=lcl_getDiagramTitleSpace(); + } + + aRet.X += nTitleSpaceWidth; + aRet.Y += nSecondTitleSpaceHeight; + aRet.Width -= (nTitleSpaceWidth + nSecondTitleSpaceWidth); + aRet.Height -= (nTitleSpaceHeight + nSecondTitleSpaceHeight); + } + } + return aRet; +} + double lcl_getPageLayoutDistancePercentage() { return 0.02; @@ -2010,9 +2156,10 @@ bool getAvailablePosAndSizeForDiagram( , const awt::Rectangle& rSpaceLeft , const awt::Size & rPageSize , const uno::Reference< XDiagram > & xDiagram - , VTitle* pXTitle, VTitle* pYTitle - , VTitle* pSecondXTitle, VTitle* pSecondYTitle ) + , bool& bUseFixedInnerSize ) { + bUseFixedInnerSize = false; + //@todo: we need a size dependent on the axis labels awt::Rectangle aRemainingSpace(rSpaceLeft); { @@ -2028,7 +2175,9 @@ bool getAvailablePosAndSizeForDiagram( uno::Reference< beans::XPropertySet > xProp(xDiagram, uno::UNO_QUERY); - bool bMakeRoomForTitle = false; + bool bPosSizeExcludeAxes = false; + if( xProp.is() ) + xProp->getPropertyValue( C2U( "PosSizeExcludeAxes" ) ) >>= bPosSizeExcludeAxes; //size: ::com::sun::star::chart2::RelativeSize aRelativeSize; @@ -2036,7 +2185,7 @@ bool getAvailablePosAndSizeForDiagram( { rOutAvailableDiagramSize.Height = static_cast<sal_Int32>(aRelativeSize.Secondary*rPageSize.Height); rOutAvailableDiagramSize.Width = static_cast<sal_Int32>(aRelativeSize.Primary*rPageSize.Width); - bMakeRoomForTitle = true; + bUseFixedInnerSize = bPosSizeExcludeAxes; } else rOutAvailableDiagramSize = awt::Size(aRemainingSpace.Width,aRemainingSpace.Height); @@ -2054,7 +2203,7 @@ bool getAvailablePosAndSizeForDiagram( rOutPos = RelativePositionHelper::getUpperLeftCornerOfAnchoredObject( awt::Point(static_cast<sal_Int32>(fX),static_cast<sal_Int32>(fY)) , rOutAvailableDiagramSize, aRelativePosition.Anchor ); - bMakeRoomForTitle = true; + bUseFixedInnerSize = bPosSizeExcludeAxes; } else rOutPos = awt::Point(aRemainingSpace.X,aRemainingSpace.Y); @@ -2067,52 +2216,6 @@ bool getAvailablePosAndSizeForDiagram( rOutAvailableDiagramSize.Width = rPageSize.Width - rOutPos.X; } - if( bMakeRoomForTitle ) - { - sal_Int32 nTitleSpaceWidth = 0; - sal_Int32 nTitleSpaceHeight = 0; - sal_Int32 nSecondTitleSpaceWidth = 0; - sal_Int32 nSecondTitleSpaceHeight = 0; - { - //todo detect wether x axis points into x direction or not - //detect wether x axis points into x direction or not - if( lcl_getPropertySwapXAndYAxis( xDiagram ) ) - { - std::swap( pXTitle, pYTitle ); - std::swap( pSecondXTitle, pSecondYTitle ); - } - - if( pXTitle ) - { - nTitleSpaceHeight = pXTitle->getFinalSize().Height; - if(nTitleSpaceHeight) - nTitleSpaceHeight+=lcl_getDiagramTitleSpace(); - } - if( pYTitle ) - { - nTitleSpaceWidth = pYTitle->getFinalSize().Width; - if(nTitleSpaceWidth) - nTitleSpaceWidth+=lcl_getDiagramTitleSpace(); - } - if( pSecondXTitle) - { - nSecondTitleSpaceHeight += pSecondXTitle->getFinalSize().Height; - if(nSecondTitleSpaceHeight) - nSecondTitleSpaceHeight+=lcl_getDiagramTitleSpace(); - } - if( pSecondYTitle) - { - nSecondTitleSpaceWidth += pSecondYTitle->getFinalSize().Width; - if(nSecondTitleSpaceWidth) - nSecondTitleSpaceWidth+=lcl_getDiagramTitleSpace(); - } - } - rOutAvailableDiagramSize.Height -= nTitleSpaceHeight + nSecondTitleSpaceHeight; - rOutAvailableDiagramSize.Width -= nTitleSpaceWidth + nSecondTitleSpaceWidth; - rOutPos.X += nTitleSpaceWidth; - rOutPos.Y += nSecondTitleSpaceHeight; - } - return true; } @@ -2154,6 +2257,19 @@ void changePositionOfAxisTitle( VTitle* pVTitle, TitleAlignment eAlignment break; } + sal_Int32 nMaxY = rPageSize.Height - aTitleSize.Height/2; + sal_Int32 nMaxX = rPageSize.Width - aTitleSize.Width/2; + sal_Int32 nMinX = aTitleSize.Width/2; + sal_Int32 nMinY = aTitleSize.Height/2; + if( aNewPosition.Y > nMaxY ) + aNewPosition.Y = nMaxY; + if( aNewPosition.X > nMaxX ) + aNewPosition.X = nMaxX; + if( aNewPosition.Y < nMinY ) + aNewPosition.Y = nMinY; + if( aNewPosition.X < nMinX ) + aNewPosition.X = nMinX; + pVTitle->changePosition( aNewPosition ); } @@ -2478,6 +2594,7 @@ void ChartView::createShapes() if( impl_AddInDrawsAllByItself() ) return; + m_aResultingDiagramRectangleExcludingAxes = awt::Rectangle(0,0,0,0); impl_deleteCoordinateSystems(); if( m_pDrawModelWrapper ) { @@ -2519,9 +2636,15 @@ void ChartView::createShapes() uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) ); rtl::OUString aDiagramCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM, rtl::OUString::valueOf( sal_Int32(0) ) ) );//todo: other index if more than one diagram is possible uno::Reference< drawing::XShapes > xDiagramPlusAxesPlusMarkHandlesGroup_Shapes( ShapeFactory(m_xShapeFactory).createGroup2D(xPageShapes,aDiagramCID) ); - uno::Reference< drawing::XShape > xDiagramPlusAxes_MarkHandles( ShapeFactory(m_xShapeFactory).createInvisibleRectangle( + + uno::Reference< drawing::XShape > xDiagram_MarkHandles( ShapeFactory(m_xShapeFactory).createInvisibleRectangle( + xDiagramPlusAxesPlusMarkHandlesGroup_Shapes, awt::Size(0,0) ) ); + ShapeFactory::setShapeName( xDiagram_MarkHandles, C2U("MarkHandles") ); + + uno::Reference< drawing::XShape > xDiagram_OuterRect( ShapeFactory(m_xShapeFactory).createInvisibleRectangle( xDiagramPlusAxesPlusMarkHandlesGroup_Shapes, awt::Size(0,0) ) ); - ShapeFactory::setShapeName( xDiagramPlusAxes_MarkHandles, C2U("MarkHandles") ); + ShapeFactory::setShapeName( xDiagram_OuterRect, C2U("PlotAreaIncludingAxes") ); + uno::Reference< drawing::XShapes > xDiagramPlusAxes_Shapes( ShapeFactory(m_xShapeFactory).createGroup2D(xDiagramPlusAxesPlusMarkHandlesGroup_Shapes ) ); //------------ create some titles @@ -2606,21 +2729,22 @@ void ChartView::createShapes() //------------ create complete diagram shape (inclusive axis and series) awt::Point aAvailablePosDia; awt::Size aAvailableSizeForDiagram; - if( getAvailablePosAndSizeForDiagram( aAvailablePosDia, aAvailableSizeForDiagram, aRemainingSpace, aPageSize, ChartModelHelper::findDiagram( m_xChartModel ) - , apVTitle_X.get(), apVTitle_Y.get(), apVTitle_SecondX.get(), apVTitle_SecondY.get() ) ) + bool bUseFixedInnerSize = false; + if( getAvailablePosAndSizeForDiagram( aAvailablePosDia, aAvailableSizeForDiagram, aRemainingSpace, aPageSize + , ChartModelHelper::findDiagram( m_xChartModel ), bUseFixedInnerSize ) ) { - impl_createDiagramAndContent( aSeriesPlotterContainer + awt::Rectangle aUsedOuterRect = impl_createDiagramAndContent( aSeriesPlotterContainer , xDiagramPlusAxes_Shapes - , aAvailablePosDia ,aAvailableSizeForDiagram, aPageSize ); + , aAvailablePosDia ,aAvailableSizeForDiagram, aPageSize, bUseFixedInnerSize, xDiagram_MarkHandles ); - if(xDiagramPlusAxes_MarkHandles.is()) + if( xDiagram_OuterRect.is() ) { - xDiagramPlusAxes_MarkHandles->setPosition( aAvailablePosDia ); - xDiagramPlusAxes_MarkHandles->setSize( aAvailableSizeForDiagram ); + xDiagram_OuterRect->setPosition( awt::Point( aUsedOuterRect.X, aUsedOuterRect.Y ) ); + xDiagram_OuterRect->setSize( awt::Size( aUsedOuterRect.Width, aUsedOuterRect.Height ) ); } //correct axis title position - awt::Rectangle aDiagramPlusAxesRect(aAvailablePosDia.X,aAvailablePosDia.Y,aAvailableSizeForDiagram.Width,aAvailableSizeForDiagram.Height); + awt::Rectangle aDiagramPlusAxesRect( aUsedOuterRect ); if(bAutoPosition_XTitle) changePositionOfAxisTitle( apVTitle_X.get(), ALIGN_BOTTOM, aDiagramPlusAxesRect, aPageSize ); if(bAutoPosition_YTitle) @@ -2691,17 +2815,6 @@ void ChartView::impl_updateView() //create chart view { - /* - ::vos::OGuard aGuard( Application::GetSolarMutex()); - while( m_bViewDirty ) - { - createShapes(); - m_bViewDirty = m_bViewUpdatePending; - m_bViewUpdatePending = false; - m_bInViewUpdate = false; - } - */ - m_bViewDirty = false; m_bViewUpdatePending = false; createShapes(); @@ -2871,6 +2984,14 @@ void SAL_CALL ChartView::removeModeChangeApproveListener( const uno::Reference< void SAL_CALL ChartView::update() throw (uno::RuntimeException) { impl_updateView(); + + //#i100778# migrate all imported or old documents to a plot area sizing exclusive axes (in case the save settings allow for this): + //Although in general it is a bad idea to change the model from within the view this is exceptionally the best place to do this special conversion. + //When a view update is requested (what happens for creating the metafile or displaying + //the chart in edit mode or printing) it is most likely that all necessary informations are available - like the underlying spreadsheet data for example. + //Those data is important for the correct axis lable sizes which are needed during conversion. + if( DiagramHelper::switchDiagramPositioningToExcludingPositioning( m_xChartModel, true, false ) ) + impl_updateView(); } // ____ XPropertySet ____ diff --git a/chart2/source/view/main/ChartView.hxx b/chart2/source/view/main/ChartView.hxx index f56da298c5df..476adae03674 100644 --- a/chart2/source/view/main/ChartView.hxx +++ b/chart2/source/view/main/ChartView.hxx @@ -110,6 +110,8 @@ public: virtual ::com::sun::star::awt::Rectangle getRectangleOfObject( const rtl::OUString& rObjectCID, bool bSnapRect=false ); + virtual ::com::sun::star::awt::Rectangle getDiagramRectangleExcludingAxes(); + ::boost::shared_ptr< DrawModelWrapper > getDrawModelWrapper(); // ___XTransferable___ @@ -196,11 +198,13 @@ private: //methods void impl_updateView(); - void impl_createDiagramAndContent( SeriesPlotterContainer& rSeriesPlotterContainer + ::com::sun::star::awt::Rectangle impl_createDiagramAndContent( SeriesPlotterContainer& rSeriesPlotterContainer , const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes>& xDiagramPlusAxes_Shapes , const ::com::sun::star::awt::Point& rAvailablePos , const ::com::sun::star::awt::Size& rAvailableSize - , const ::com::sun::star::awt::Size& rPageSize ); + , const ::com::sun::star::awt::Size& rPageSize + , bool bUseFixedInnerSize + , const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape>& xDiagram_MarkHandles ); private: //member @@ -246,6 +250,8 @@ private: //member sal_Int32 m_nScaleYDenominator; sal_Bool m_bSdrViewIsInEditMode; + + ::com::sun::star::awt::Rectangle m_aResultingDiagramRectangleExcludingAxes; }; //............................................................................. |