1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26
27 #include "PositionAndSizeHelper.hxx"
28 #include "macros.hxx"
29 #include "ChartModelHelper.hxx"
30 #include "ControllerLockGuard.hxx"
31 #include <com/sun/star/chart2/LegendPosition.hpp>
32 #include <com/sun/star/chart/ChartLegendExpansion.hpp>
33 #include <com/sun/star/chart2/RelativePosition.hpp>
34 #include <com/sun/star/chart2/RelativeSize.hpp>
35 #include "chartview/ExplicitValueProvider.hxx"
36
37 // header for class Rectangle
38 #include <tools/gen.hxx>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40
41 //.............................................................................
42 namespace chart
43 {
44 //.............................................................................
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::chart2;
47
moveObject(ObjectType eObjectType,const uno::Reference<beans::XPropertySet> & xObjectProp,const awt::Rectangle & rNewPositionAndSize,const awt::Rectangle & rPageRectangle)48 bool PositionAndSizeHelper::moveObject( ObjectType eObjectType
49 , const uno::Reference< beans::XPropertySet >& xObjectProp
50 , const awt::Rectangle& rNewPositionAndSize
51 , const awt::Rectangle& rPageRectangle
52 )
53 {
54 if(!xObjectProp.is())
55 return false;
56 Rectangle aObjectRect( Point(rNewPositionAndSize.X,rNewPositionAndSize.Y), Size(rNewPositionAndSize.Width,rNewPositionAndSize.Height) );
57 Rectangle aPageRect( Point(rPageRectangle.X,rPageRectangle.Y), Size(rPageRectangle.Width,rPageRectangle.Height) );
58
59 if( OBJECTTYPE_TITLE==eObjectType )
60 {
61 //@todo decide wether x is primary or secondary
62 chart2::RelativePosition aRelativePosition;
63 aRelativePosition.Anchor = drawing::Alignment_CENTER;
64 //the anchor point at the title object is top/middle
65 Point aPos = aObjectRect.TopLeft();
66 aRelativePosition.Primary = (double(aPos.X())+double(aObjectRect.getWidth())/2.0)/double(aPageRect.getWidth());
67 aRelativePosition.Secondary = (double(aPos.Y())+double(aObjectRect.getHeight())/2.0)/double(aPageRect.getHeight());
68 xObjectProp->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition) );
69 }
70 else if( OBJECTTYPE_DATA_CURVE_EQUATION==eObjectType )
71 {
72 //@todo decide wether x is primary or secondary
73 chart2::RelativePosition aRelativePosition;
74 aRelativePosition.Anchor = drawing::Alignment_TOP_LEFT;
75 //the anchor point at the title object is top/middle
76 Point aPos = aObjectRect.TopLeft();
77 aRelativePosition.Primary = double(aPos.X())/double(aPageRect.getWidth());
78 aRelativePosition.Secondary = double(aPos.Y())/double(aPageRect.getHeight());
79 xObjectProp->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition) );
80 }
81 else if(OBJECTTYPE_LEGEND==eObjectType)
82 {
83 xObjectProp->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny(LegendPosition(LegendPosition_CUSTOM)));
84 xObjectProp->setPropertyValue( C2U( "Expansion" ), uno::makeAny(::com::sun::star::chart::ChartLegendExpansion_CUSTOM));
85 chart2::RelativePosition aRelativePosition;
86 chart2::RelativeSize aRelativeSize;
87 Point aAnchor = aObjectRect.TopLeft();
88
89 aRelativePosition.Primary =
90 static_cast< double >( aAnchor.X()) /
91 static_cast< double >( aPageRect.getWidth() );
92 aRelativePosition.Secondary =
93 static_cast< double >( aAnchor.Y()) /
94 static_cast< double >( aPageRect.getHeight());
95
96 xObjectProp->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition) );
97
98 aRelativeSize.Primary =
99 static_cast< double >( aObjectRect.getWidth()) /
100 static_cast< double >( aPageRect.getWidth() );
101 if (aRelativeSize.Primary > 1.0)
102 aRelativeSize.Primary = 1.0;
103 aRelativeSize.Secondary =
104 static_cast< double >( aObjectRect.getHeight()) /
105 static_cast< double >( aPageRect.getHeight());
106 if (aRelativeSize.Secondary > 1.0)
107 aRelativeSize.Secondary = 1.0;
108
109 xObjectProp->setPropertyValue( C2U( "RelativeSize" ), uno::makeAny(aRelativeSize) );
110 }
111 else if(OBJECTTYPE_DIAGRAM==eObjectType || OBJECTTYPE_DIAGRAM_WALL==eObjectType || OBJECTTYPE_DIAGRAM_FLOOR==eObjectType)
112 {
113 //@todo decide wether x is primary or secondary
114
115 //set position:
116 chart2::RelativePosition aRelativePosition;
117 aRelativePosition.Anchor = drawing::Alignment_CENTER;
118
119 Point aPos = aObjectRect.Center();
120 aRelativePosition.Primary = double(aPos.X())/double(aPageRect.getWidth());
121 aRelativePosition.Secondary = double(aPos.Y())/double(aPageRect.getHeight());
122 xObjectProp->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition) );
123
124 //set size:
125 RelativeSize aRelativeSize;
126 //the anchor points for the diagram are in the middle of the diagram
127 //and in the middle of the page
128 aRelativeSize.Primary = double(aObjectRect.getWidth())/double(aPageRect.getWidth());
129 aRelativeSize.Secondary = double(aObjectRect.getHeight())/double(aPageRect.getHeight());
130 xObjectProp->setPropertyValue( C2U( "RelativeSize" ), uno::makeAny(aRelativeSize) );
131 }
132 else
133 return false;
134 return true;
135 }
136
moveObject(const rtl::OUString & rObjectCID,const uno::Reference<frame::XModel> & xChartModel,const awt::Rectangle & rNewPositionAndSize,const awt::Rectangle & rPageRectangle)137 bool PositionAndSizeHelper::moveObject( const rtl::OUString& rObjectCID
138 , const uno::Reference< frame::XModel >& xChartModel
139 , const awt::Rectangle& rNewPositionAndSize
140 , const awt::Rectangle& rPageRectangle
141 )
142 {
143 ControllerLockGuard aLockedControllers( xChartModel );
144
145 awt::Rectangle aNewPositionAndSize( rNewPositionAndSize );
146
147 uno::Reference< beans::XPropertySet > xObjectProp = ObjectIdentifier::getObjectPropertySet( rObjectCID, xChartModel );
148 ObjectType eObjectType( ObjectIdentifier::getObjectType( rObjectCID ) );
149 if(OBJECTTYPE_DIAGRAM==eObjectType || OBJECTTYPE_DIAGRAM_WALL==eObjectType || OBJECTTYPE_DIAGRAM_FLOOR==eObjectType)
150 {
151 xObjectProp = uno::Reference< beans::XPropertySet >( ObjectIdentifier::getDiagramForCID( rObjectCID, xChartModel ), uno::UNO_QUERY );
152 if(!xObjectProp.is())
153 return false;
154 }
155 return moveObject( eObjectType, xObjectProp, aNewPositionAndSize, rPageRectangle );
156 }
157
158 //.............................................................................
159 } //namespace chart
160 //.............................................................................
161