1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "PositionAndSizeHelper.hxx"
33 #include "ChartModelHelper.hxx"
34 #include "ControllerLockGuard.hxx"
35 #include <com/sun/star/chart2/LegendPosition.hpp>
36 #include <com/sun/star/chart2/RelativePosition.hpp>
37 #include <com/sun/star/chart2/RelativeSize.hpp>
38 #include "chartview/ExplicitValueProvider.hxx"
40 // header for class Rectangle
41 #include <tools/gen.hxx>
42 #include <com/sun/star/beans/XPropertySet.hpp>
44 //.............................................................................
47 //.............................................................................
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::chart2
;
51 bool PositionAndSizeHelper::moveObject( ObjectType eObjectType
52 , const uno::Reference
< beans::XPropertySet
>& xObjectProp
53 , const awt::Rectangle
& rNewPositionAndSize
54 , const awt::Rectangle
& rPageRectangle
59 Rectangle
aObjectRect( Point(rNewPositionAndSize
.X
,rNewPositionAndSize
.Y
), Size(rNewPositionAndSize
.Width
,rNewPositionAndSize
.Height
) );
60 Rectangle
aPageRect( Point(rPageRectangle
.X
,rPageRectangle
.Y
), Size(rPageRectangle
.Width
,rPageRectangle
.Height
) );
62 if( OBJECTTYPE_TITLE
==eObjectType
)
64 //@todo decide wether x is primary or secondary
65 chart2::RelativePosition aRelativePosition
;
66 aRelativePosition
.Anchor
= drawing::Alignment_CENTER
;
67 //the anchor point at the title object is top/middle
68 Point aPos
= aObjectRect
.TopLeft();
69 aRelativePosition
.Primary
= (double(aPos
.X())+double(aObjectRect
.getWidth())/2.0)/double(aPageRect
.getWidth());
70 aRelativePosition
.Secondary
= (double(aPos
.Y())+double(aObjectRect
.getHeight())/2.0)/double(aPageRect
.getHeight());
71 xObjectProp
->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition
) );
73 else if( OBJECTTYPE_DATA_CURVE_EQUATION
==eObjectType
)
75 //@todo decide wether x is primary or secondary
76 chart2::RelativePosition aRelativePosition
;
77 aRelativePosition
.Anchor
= drawing::Alignment_TOP_LEFT
;
78 //the anchor point at the title object is top/middle
79 Point aPos
= aObjectRect
.TopLeft();
80 aRelativePosition
.Primary
= double(aPos
.X())/double(aPageRect
.getWidth());
81 aRelativePosition
.Secondary
= double(aPos
.Y())/double(aPageRect
.getHeight());
82 xObjectProp
->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition
) );
84 else if(OBJECTTYPE_LEGEND
==eObjectType
)
86 LegendPosition ePos
= LegendPosition_LINE_END
;
87 xObjectProp
->getPropertyValue( C2U( "AnchorPosition" )) >>= ePos
;
88 chart2::RelativePosition aRelativePosition
;
89 Point aAnchor
= aObjectRect
.TopLeft();
93 case LegendPosition_LINE_START
:
95 //@todo language dependent positions ...
96 aRelativePosition
.Anchor
= drawing::Alignment_LEFT
;
97 aAnchor
= aObjectRect
.LeftCenter();
100 case LegendPosition_LINE_END
:
102 //@todo language dependent positions ...
103 aRelativePosition
.Anchor
= drawing::Alignment_RIGHT
;
104 aAnchor
= aObjectRect
.RightCenter();
107 case LegendPosition_PAGE_START
:
109 //@todo language dependent positions ...
110 aRelativePosition
.Anchor
= drawing::Alignment_TOP
;
111 aAnchor
= aObjectRect
.TopCenter();
114 case LegendPosition_PAGE_END
:
115 //@todo language dependent positions ...
117 aRelativePosition
.Anchor
= drawing::Alignment_BOTTOM
;
118 aAnchor
= aObjectRect
.BottomCenter();
121 case LegendPosition_CUSTOM
:
123 //@todo language dependent positions ...
124 aRelativePosition
.Anchor
= drawing::Alignment_TOP_LEFT
;
127 case LegendPosition_MAKE_FIXED_SIZE
:
131 aRelativePosition
.Primary
=
132 static_cast< double >( aAnchor
.X()) /
133 static_cast< double >( aPageRect
.getWidth() );
134 aRelativePosition
.Secondary
=
135 static_cast< double >( aAnchor
.Y()) /
136 static_cast< double >( aPageRect
.getHeight());
138 xObjectProp
->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition
) );
140 else if(OBJECTTYPE_DIAGRAM
==eObjectType
|| OBJECTTYPE_DIAGRAM_WALL
==eObjectType
|| OBJECTTYPE_DIAGRAM_FLOOR
==eObjectType
)
142 //@todo decide wether x is primary or secondary
145 chart2::RelativePosition aRelativePosition
;
146 aRelativePosition
.Anchor
= drawing::Alignment_CENTER
;
148 Point aPos
= aObjectRect
.Center();
149 aRelativePosition
.Primary
= double(aPos
.X())/double(aPageRect
.getWidth());
150 aRelativePosition
.Secondary
= double(aPos
.Y())/double(aPageRect
.getHeight());
151 xObjectProp
->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition
) );
154 RelativeSize aRelativeSize
;
155 //the anchor points for the diagram are in the middle of the diagram
156 //and in the middle of the page
157 aRelativeSize
.Primary
= double(aObjectRect
.getWidth())/double(aPageRect
.getWidth());
158 aRelativeSize
.Secondary
= double(aObjectRect
.getHeight())/double(aPageRect
.getHeight());
159 xObjectProp
->setPropertyValue( C2U( "RelativeSize" ), uno::makeAny(aRelativeSize
) );
166 bool PositionAndSizeHelper::moveObject( const rtl::OUString
& rObjectCID
167 , const uno::Reference
< frame::XModel
>& xChartModel
168 , const awt::Rectangle
& rNewPositionAndSize
169 , const awt::Rectangle
& rPageRectangle
172 ControllerLockGuard
aLockedControllers( xChartModel
);
174 awt::Rectangle
aNewPositionAndSize( rNewPositionAndSize
);
176 uno::Reference
< beans::XPropertySet
> xObjectProp
= ObjectIdentifier::getObjectPropertySet( rObjectCID
, xChartModel
);
177 ObjectType
eObjectType( ObjectIdentifier::getObjectType( rObjectCID
) );
178 if(OBJECTTYPE_DIAGRAM
==eObjectType
|| OBJECTTYPE_DIAGRAM_WALL
==eObjectType
|| OBJECTTYPE_DIAGRAM_FLOOR
==eObjectType
)
180 xObjectProp
= uno::Reference
< beans::XPropertySet
>( ObjectIdentifier::getDiagramForCID( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
181 if(!xObjectProp
.is())
184 return moveObject( eObjectType
, xObjectProp
, aNewPositionAndSize
, rPageRectangle
);
187 //.............................................................................
189 //.............................................................................