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