1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "PositionAndSizeHelper.hxx"
32 #include "ChartModelHelper.hxx"
33 #include "ControllerLockGuard.hxx"
34 #include <com/sun/star/chart2/LegendPosition.hpp>
35 #include <com/sun/star/chart/ChartLegendExpansion.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 whether 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 whether 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 xObjectProp
->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny(LegendPosition(LegendPosition_CUSTOM
)));
87 xObjectProp
->setPropertyValue( C2U( "Expansion" ), uno::makeAny(::com::sun::star::chart::ChartLegendExpansion_CUSTOM
));
88 chart2::RelativePosition aRelativePosition
;
89 chart2::RelativeSize aRelativeSize
;
90 Point aAnchor
= aObjectRect
.TopLeft();
92 aRelativePosition
.Primary
=
93 static_cast< double >( aAnchor
.X()) /
94 static_cast< double >( aPageRect
.getWidth() );
95 aRelativePosition
.Secondary
=
96 static_cast< double >( aAnchor
.Y()) /
97 static_cast< double >( aPageRect
.getHeight());
99 xObjectProp
->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition
) );
101 aRelativeSize
.Primary
=
102 static_cast< double >( aObjectRect
.getWidth()) /
103 static_cast< double >( aPageRect
.getWidth() );
104 if (aRelativeSize
.Primary
> 1.0)
105 aRelativeSize
.Primary
= 1.0;
106 aRelativeSize
.Secondary
=
107 static_cast< double >( aObjectRect
.getHeight()) /
108 static_cast< double >( aPageRect
.getHeight());
109 if (aRelativeSize
.Secondary
> 1.0)
110 aRelativeSize
.Secondary
= 1.0;
112 xObjectProp
->setPropertyValue( C2U( "RelativeSize" ), uno::makeAny(aRelativeSize
) );
114 else if(OBJECTTYPE_DIAGRAM
==eObjectType
|| OBJECTTYPE_DIAGRAM_WALL
==eObjectType
|| OBJECTTYPE_DIAGRAM_FLOOR
==eObjectType
)
116 //@todo decide whether x is primary or secondary
119 chart2::RelativePosition aRelativePosition
;
120 aRelativePosition
.Anchor
= drawing::Alignment_CENTER
;
122 Point aPos
= aObjectRect
.Center();
123 aRelativePosition
.Primary
= double(aPos
.X())/double(aPageRect
.getWidth());
124 aRelativePosition
.Secondary
= double(aPos
.Y())/double(aPageRect
.getHeight());
125 xObjectProp
->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition
) );
128 RelativeSize aRelativeSize
;
129 //the anchor points for the diagram are in the middle of the diagram
130 //and in the middle of the page
131 aRelativeSize
.Primary
= double(aObjectRect
.getWidth())/double(aPageRect
.getWidth());
132 aRelativeSize
.Secondary
= double(aObjectRect
.getHeight())/double(aPageRect
.getHeight());
133 xObjectProp
->setPropertyValue( C2U( "RelativeSize" ), uno::makeAny(aRelativeSize
) );
140 bool PositionAndSizeHelper::moveObject( const rtl::OUString
& rObjectCID
141 , const uno::Reference
< frame::XModel
>& xChartModel
142 , const awt::Rectangle
& rNewPositionAndSize
143 , const awt::Rectangle
& rPageRectangle
146 ControllerLockGuard
aLockedControllers( xChartModel
);
148 awt::Rectangle
aNewPositionAndSize( rNewPositionAndSize
);
150 uno::Reference
< beans::XPropertySet
> xObjectProp
= ObjectIdentifier::getObjectPropertySet( rObjectCID
, xChartModel
);
151 ObjectType
eObjectType( ObjectIdentifier::getObjectType( rObjectCID
) );
152 if(OBJECTTYPE_DIAGRAM
==eObjectType
|| OBJECTTYPE_DIAGRAM_WALL
==eObjectType
|| OBJECTTYPE_DIAGRAM_FLOOR
==eObjectType
)
154 xObjectProp
= uno::Reference
< beans::XPropertySet
>( ObjectIdentifier::getDiagramForCID( rObjectCID
, xChartModel
), uno::UNO_QUERY
);
155 if(!xObjectProp
.is())
158 return moveObject( eObjectType
, xObjectProp
, aNewPositionAndSize
, rPageRectangle
);
161 //.............................................................................
163 //.............................................................................
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */