merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / controller / main / PositionAndSizeHelper.cxx
blob40652e95a898276422c346c8bc662756acc1ab97
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PositionAndSizeHelper.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "PositionAndSizeHelper.hxx"
35 #include "macros.hxx"
36 #include "ChartModelHelper.hxx"
37 #include "ControllerLockGuard.hxx"
38 #include <com/sun/star/chart2/LegendPosition.hpp>
39 #include <com/sun/star/chart2/RelativePosition.hpp>
40 #include <com/sun/star/chart2/RelativeSize.hpp>
41 #include "chartview/ExplicitValueProvider.hxx"
43 // header for class Rectangle
44 #include <tools/gen.hxx>
45 #include <com/sun/star/beans/XPropertySet.hpp>
47 //.............................................................................
48 namespace chart
50 //.............................................................................
51 using namespace ::com::sun::star;
52 using namespace ::com::sun::star::chart2;
54 bool PositionAndSizeHelper::moveObject( ObjectType eObjectType
55 , const uno::Reference< beans::XPropertySet >& xObjectProp
56 , const awt::Rectangle& rNewPositionAndSize
57 , const awt::Rectangle& rPageRectangle
60 if(!xObjectProp.is())
61 return false;
62 Rectangle aObjectRect( Point(rNewPositionAndSize.X,rNewPositionAndSize.Y), Size(rNewPositionAndSize.Width,rNewPositionAndSize.Height) );
63 Rectangle aPageRect( Point(rPageRectangle.X,rPageRectangle.Y), Size(rPageRectangle.Width,rPageRectangle.Height) );
65 if( OBJECTTYPE_TITLE==eObjectType )
67 //@todo decide wether x is primary or secondary
68 chart2::RelativePosition aRelativePosition;
69 aRelativePosition.Anchor = drawing::Alignment_CENTER;
70 //the anchor point at the title object is top/middle
71 Point aPos = aObjectRect.TopLeft();
72 aRelativePosition.Primary = (double(aPos.X())+double(aObjectRect.getWidth())/2.0)/double(aPageRect.getWidth());
73 aRelativePosition.Secondary = (double(aPos.Y())+double(aObjectRect.getHeight())/2.0)/double(aPageRect.getHeight());
74 xObjectProp->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition) );
76 else if( OBJECTTYPE_DATA_CURVE_EQUATION==eObjectType )
78 //@todo decide wether x is primary or secondary
79 chart2::RelativePosition aRelativePosition;
80 aRelativePosition.Anchor = drawing::Alignment_TOP_LEFT;
81 //the anchor point at the title object is top/middle
82 Point aPos = aObjectRect.TopLeft();
83 aRelativePosition.Primary = double(aPos.X())/double(aPageRect.getWidth());
84 aRelativePosition.Secondary = double(aPos.Y())/double(aPageRect.getHeight());
85 xObjectProp->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition) );
87 else if(OBJECTTYPE_LEGEND==eObjectType)
89 LegendPosition ePos = LegendPosition_LINE_END;
90 xObjectProp->getPropertyValue( C2U( "AnchorPosition" )) >>= ePos;
91 chart2::RelativePosition aRelativePosition;
92 Point aAnchor = aObjectRect.TopLeft();
94 switch( ePos )
96 case LegendPosition_LINE_START:
98 //@todo language dependent positions ...
99 aRelativePosition.Anchor = drawing::Alignment_LEFT;
100 aAnchor = aObjectRect.LeftCenter();
102 break;
103 case LegendPosition_LINE_END:
105 //@todo language dependent positions ...
106 aRelativePosition.Anchor = drawing::Alignment_RIGHT;
107 aAnchor = aObjectRect.RightCenter();
109 break;
110 case LegendPosition_PAGE_START:
112 //@todo language dependent positions ...
113 aRelativePosition.Anchor = drawing::Alignment_TOP;
114 aAnchor = aObjectRect.TopCenter();
116 break;
117 case LegendPosition_PAGE_END:
118 //@todo language dependent positions ...
120 aRelativePosition.Anchor = drawing::Alignment_BOTTOM;
121 aAnchor = aObjectRect.BottomCenter();
123 break;
124 case LegendPosition_CUSTOM:
126 //@todo language dependent positions ...
127 aRelativePosition.Anchor = drawing::Alignment_TOP_LEFT;
129 break;
130 case LegendPosition_MAKE_FIXED_SIZE:
131 OSL_ASSERT( false );
132 break;
134 aRelativePosition.Primary =
135 static_cast< double >( aAnchor.X()) /
136 static_cast< double >( aPageRect.getWidth() );
137 aRelativePosition.Secondary =
138 static_cast< double >( aAnchor.Y()) /
139 static_cast< double >( aPageRect.getHeight());
141 xObjectProp->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition) );
143 else if(OBJECTTYPE_DIAGRAM==eObjectType || OBJECTTYPE_DIAGRAM_WALL==eObjectType || OBJECTTYPE_DIAGRAM_FLOOR==eObjectType)
145 //@todo decide wether x is primary or secondary
147 //xChartView
149 //set position:
150 chart2::RelativePosition aRelativePosition;
151 aRelativePosition.Anchor = drawing::Alignment_CENTER;
153 Point aPos = aObjectRect.Center();
154 aRelativePosition.Primary = double(aPos.X())/double(aPageRect.getWidth());
155 aRelativePosition.Secondary = double(aPos.Y())/double(aPageRect.getHeight());
156 xObjectProp->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition) );
158 //set size:
159 RelativeSize aRelativeSize;
160 //the anchor points for the diagram are in the middle of the diagram
161 //and in the middle of the page
162 aRelativeSize.Primary = double(aObjectRect.getWidth())/double(aPageRect.getWidth());
163 aRelativeSize.Secondary = double(aObjectRect.getHeight())/double(aPageRect.getHeight());
164 xObjectProp->setPropertyValue( C2U( "RelativeSize" ), uno::makeAny(aRelativeSize) );
166 else
167 return false;
168 return true;
171 bool PositionAndSizeHelper::moveObject( const rtl::OUString& rObjectCID
172 , const uno::Reference< frame::XModel >& xChartModel
173 , const awt::Rectangle& rNewPositionAndSize
174 , const awt::Rectangle& rPageRectangle
175 , uno::Reference< uno::XInterface > xChartView
178 ControllerLockGuard aLockedControllers( xChartModel );
180 awt::Rectangle aNewPositionAndSize( rNewPositionAndSize );
182 uno::Reference< beans::XPropertySet > xObjectProp = ObjectIdentifier::getObjectPropertySet( rObjectCID, xChartModel );
183 ObjectType eObjectType( ObjectIdentifier::getObjectType( rObjectCID ) );
184 if(OBJECTTYPE_DIAGRAM==eObjectType || OBJECTTYPE_DIAGRAM_WALL==eObjectType || OBJECTTYPE_DIAGRAM_FLOOR==eObjectType)
186 xObjectProp = uno::Reference< beans::XPropertySet >( ObjectIdentifier::getDiagramForCID( rObjectCID, xChartModel ), uno::UNO_QUERY );
187 if(!xObjectProp.is())
188 return false;
190 //add axis title sizes to the diagram size
191 aNewPositionAndSize = ExplicitValueProvider::calculateDiagramPositionAndSizeInclusiveTitle(
192 xChartModel, xChartView, rNewPositionAndSize );
194 return moveObject( eObjectType, xObjectProp, aNewPositionAndSize, rPageRectangle );
197 //.............................................................................
198 } //namespace chart
199 //.............................................................................