22#include <com/sun/star/chart/ChartLegendExpansion.hpp>
23#include <com/sun/star/chart2/RelativePosition.hpp>
24#include <com/sun/star/chart2/RelativeSize.hpp>
26#include <com/sun/star/beans/XPropertySet.hpp>
27#include <com/sun/star/awt/Rectangle.hpp>
37 ,
const uno::Reference< beans::XPropertySet >& xObjectProp
38 ,
const awt::Rectangle& rNewPositionAndSize
39 ,
const awt::Rectangle& rOldPositionAndSize
40 ,
const awt::Rectangle& rPageRectangle
45 tools::Rectangle aObjectRect(
Point(rNewPositionAndSize.X,rNewPositionAndSize.Y),
Size(rNewPositionAndSize.Width,rNewPositionAndSize.Height) );
49 if (aPageRect.getOpenWidth() == 0 || aPageRect.getOpenHeight() == 0)
55 chart2::RelativePosition aRelativePosition;
56 aRelativePosition.Anchor = drawing::Alignment_CENTER;
58 Point aPos = aObjectRect.TopLeft();
59 aRelativePosition.Primary = (double(aPos.
X())+double(aObjectRect.getOpenWidth())/2.0)/
double(aPageRect.getOpenWidth());
60 aRelativePosition.Secondary = (double(aPos.
Y())+double(aObjectRect.getOpenHeight())/2.0)/
double(aPageRect.getOpenHeight());
61 xObjectProp->setPropertyValue(
"RelativePosition",
uno::Any(aRelativePosition) );
65 RelativePosition aAbsolutePosition;
66 RelativePosition aCustomLabelPosition;
67 aAbsolutePosition.Primary = double(rOldPositionAndSize.X) / double(aPageRect.getOpenWidth());
68 aAbsolutePosition.Secondary = double(rOldPositionAndSize.Y) / double(aPageRect.getOpenHeight());
70 if( xObjectProp->getPropertyValue(
"CustomLabelPosition") >>= aCustomLabelPosition )
72 aAbsolutePosition.Primary -= aCustomLabelPosition.Primary;
73 aAbsolutePosition.Secondary -= aCustomLabelPosition.Secondary;
77 Point aPos = aObjectRect.TopLeft();
78 double fRotation = 0.0;
79 xObjectProp->getPropertyValue(
"TextRotation") >>= fRotation;
80 if( fRotation == 90.0 )
81 aPos = aObjectRect.BottomLeft();
82 else if( fRotation == 270.0 )
83 aPos = aObjectRect.TopRight();
85 aCustomLabelPosition.Primary = double(aPos.
X()) / double(aPageRect.getOpenWidth()) - aAbsolutePosition.Primary;
86 aCustomLabelPosition.Secondary = double(aPos.
Y()) / double(aPageRect.getOpenHeight()) - aAbsolutePosition.Secondary;
87 xObjectProp->setPropertyValue(
"CustomLabelPosition",
uno::Any(aCustomLabelPosition));
92 chart2::RelativePosition aRelativePosition;
93 aRelativePosition.Anchor = drawing::Alignment_TOP_LEFT;
95 Point aPos = aObjectRect.TopLeft();
96 aRelativePosition.Primary = double(aPos.
X())/double(aPageRect.getOpenWidth());
97 aRelativePosition.Secondary = double(aPos.
Y())/double(aPageRect.getOpenHeight());
98 xObjectProp->setPropertyValue(
"RelativePosition",
uno::Any(aRelativePosition) );
102 xObjectProp->setPropertyValue(
"Expansion",
uno::Any(css::chart::ChartLegendExpansion_CUSTOM));
103 chart2::RelativePosition aRelativePosition;
104 chart2::RelativeSize aRelativeSize;
105 Point aAnchor = aObjectRect.TopLeft();
107 aRelativePosition.Primary =
108 static_cast< double >( aAnchor.
X()) /
109 static_cast< double >( aPageRect.getOpenWidth() );
110 aRelativePosition.Secondary =
111 static_cast< double >( aAnchor.
Y()) /
112 static_cast< double >( aPageRect.getOpenHeight());
114 xObjectProp->setPropertyValue(
"RelativePosition",
uno::Any(aRelativePosition) );
116 aRelativeSize.Primary =
117 static_cast< double >( aObjectRect.getOpenWidth()) /
118 static_cast< double >( aPageRect.getOpenWidth() );
119 if (aRelativeSize.Primary > 1.0)
120 aRelativeSize.Primary = 1.0;
121 aRelativeSize.Secondary =
122 static_cast< double >( aObjectRect.getOpenHeight()) /
123 static_cast< double >( aPageRect.getOpenHeight());
124 if (aRelativeSize.Secondary > 1.0)
125 aRelativeSize.Secondary = 1.0;
127 xObjectProp->setPropertyValue(
"RelativeSize",
uno::Any(aRelativeSize) );
134 chart2::RelativePosition aRelativePosition;
135 aRelativePosition.Anchor = drawing::Alignment_CENTER;
137 Point aPos = aObjectRect.Center();
138 aRelativePosition.Primary = double(aPos.
X())/double(aPageRect.getOpenWidth());
139 aRelativePosition.Secondary = double(aPos.
Y())/double(aPageRect.getOpenHeight());
140 xObjectProp->setPropertyValue(
"RelativePosition",
uno::Any(aRelativePosition) );
146 aRelativeSize.Primary = double(aObjectRect.getOpenWidth())/double(aPageRect.getOpenWidth());
147 aRelativeSize.Secondary = double(aObjectRect.getOpenHeight())/double(aPageRect.getOpenHeight());
148 xObjectProp->setPropertyValue(
"RelativeSize",
uno::Any(aRelativeSize) );
157 ,
const awt::Rectangle& rNewPositionAndSize
158 ,
const awt::Rectangle& rOldPositionAndSize
159 ,
const awt::Rectangle& rPageRectangle
162 ControllerLockGuardUNO aLockedControllers( xChartModel );
164 awt::Rectangle aNewPositionAndSize( rNewPositionAndSize );
171 if(!xObjectProp.is())
174 return moveObject( eObjectType, xObjectProp, aNewPositionAndSize, rOldPositionAndSize, rPageRectangle );
constexpr tools::Long Y() const
constexpr tools::Long X() const
static css::uno::Reference< css::beans::XPropertySet > getObjectPropertySet(std::u16string_view rObjectCID, const rtl::Reference< ::chart::ChartModel > &xChartDocument)
static rtl::Reference< ::chart::Diagram > getDiagramForCID(std::u16string_view rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartModel)
ObjectType getObjectType() const
static bool moveObject(ObjectType eObjectType, const css::uno::Reference< css::beans::XPropertySet > &xObjectProp, const css::awt::Rectangle &rNewPositionAndSize, const css::awt::Rectangle &rOldPositionAndSize, const css::awt::Rectangle &rPageRectangle)
@ OBJECTTYPE_DIAGRAM_FLOOR
@ OBJECTTYPE_DATA_CURVE_EQUATION
@ OBJECTTYPE_DIAGRAM_WALL