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 "DragMethod_PieSegment.hxx"
28
29 #include "Strings.hrc"
30 #include "ResId.hxx"
31 #include "macros.hxx"
32 #include "ObjectIdentifier.hxx"
33 #include <rtl/math.hxx>
34 #include <svx/svdpagv.hxx>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <basegfx/matrix/b2dhommatrix.hxx>
37
38 //.............................................................................
39 namespace chart
40 {
41 //.............................................................................
42
43 using namespace ::com::sun::star;
44 using ::com::sun::star::uno::Reference;
45 using ::basegfx::B2DVector;
46
DragMethod_PieSegment(DrawViewWrapper & rDrawViewWrapper,const rtl::OUString & rObjectCID,const Reference<frame::XModel> & xChartModel)47 DragMethod_PieSegment::DragMethod_PieSegment( DrawViewWrapper& rDrawViewWrapper
48 , const rtl::OUString& rObjectCID
49 , const Reference< frame::XModel >& xChartModel )
50 : DragMethod_Base( rDrawViewWrapper, rObjectCID, xChartModel )
51 , m_aStartVector(100.0,100.0)
52 , m_fInitialOffset(0.0)
53 , m_fAdditionalOffset(0.0)
54 , m_aDragDirection(1000.0,1000.0)
55 , m_fDragRange( 1.0 )
56 {
57 rtl::OUString aParameter( ObjectIdentifier::getDragParameterString( m_aObjectCID ) );
58
59 sal_Int32 nOffsetPercent(0);
60 awt::Point aMinimumPosition(0,0);
61 awt::Point aMaximumPosition(0,0);
62
63 ObjectIdentifier::parsePieSegmentDragParameterString(
64 aParameter, nOffsetPercent, aMinimumPosition, aMaximumPosition );
65
66 m_fInitialOffset = nOffsetPercent / 100.0;
67 if( m_fInitialOffset < 0.0 )
68 m_fInitialOffset = 0.0;
69 if( m_fInitialOffset > 1.0 )
70 m_fInitialOffset = 1.0;
71 B2DVector aMinVector( aMinimumPosition.X, aMinimumPosition.Y );
72 B2DVector aMaxVector( aMaximumPosition.X, aMaximumPosition.Y );
73 m_aDragDirection = aMaxVector - aMinVector;
74 m_fDragRange = m_aDragDirection.scalar( m_aDragDirection );
75 if( ::rtl::math::approxEqual( m_fDragRange, 0.0 ) )
76 m_fDragRange = 1.0;
77 }
~DragMethod_PieSegment()78 DragMethod_PieSegment::~DragMethod_PieSegment()
79 {
80 }
TakeSdrDragComment(String & rStr) const81 void DragMethod_PieSegment::TakeSdrDragComment(String& rStr) const
82 {
83 rStr = String( SchResId( STR_STATUS_PIE_SEGMENT_EXPLODED ) );
84 rStr.SearchAndReplaceAscii( "%PERCENTVALUE", String::CreateFromInt32( static_cast<sal_Int32>((m_fAdditionalOffset+m_fInitialOffset)*100.0) ));
85 }
BeginSdrDrag()86 bool DragMethod_PieSegment::BeginSdrDrag()
87 {
88 Point aStart( DragStat().GetStart() );
89 m_aStartVector = B2DVector( aStart.X(), aStart.Y() );
90 Show();
91 return true;
92 }
MoveSdrDrag(const Point & rPnt)93 void DragMethod_PieSegment::MoveSdrDrag(const Point& rPnt)
94 {
95 if( DragStat().CheckMinMoved(rPnt) )
96 {
97 //calculate new offset
98 B2DVector aShiftVector(( B2DVector( rPnt.X(), rPnt.Y() ) - m_aStartVector ));
99 m_fAdditionalOffset = m_aDragDirection.scalar( aShiftVector )/m_fDragRange; // projection
100
101 if( m_fAdditionalOffset < -m_fInitialOffset )
102 m_fAdditionalOffset = -m_fInitialOffset;
103 else if( m_fAdditionalOffset > (1.0-m_fInitialOffset) )
104 m_fAdditionalOffset = 1.0 - m_fInitialOffset;
105
106 B2DVector aNewPosVector = m_aStartVector + (m_aDragDirection * m_fAdditionalOffset);
107 Point aNewPos = Point( (long)(aNewPosVector.getX()), (long)(aNewPosVector.getY()) );
108 if( aNewPos != DragStat().GetNow() )
109 {
110 Hide();
111 DragStat().NextMove( aNewPos );
112 Show();
113 }
114 }
115 }
EndSdrDrag(bool)116 bool DragMethod_PieSegment::EndSdrDrag(bool /*bCopy*/)
117 {
118 Hide();
119
120 try
121 {
122 Reference< frame::XModel > xChartModel( this->getChartModel() );
123 if( xChartModel.is() )
124 {
125 Reference< beans::XPropertySet > xPointProperties(
126 ObjectIdentifier::getObjectPropertySet( m_aObjectCID, xChartModel ) );
127 if( xPointProperties.is() )
128 xPointProperties->setPropertyValue( C2U( "Offset" ), uno::makeAny( m_fAdditionalOffset+m_fInitialOffset ));
129 }
130 }
131 catch( const uno::Exception & ex )
132 {
133 ASSERT_EXCEPTION( ex );
134 }
135
136 return true;
137 }
getCurrentTransformation()138 basegfx::B2DHomMatrix DragMethod_PieSegment::getCurrentTransformation()
139 {
140 basegfx::B2DHomMatrix aRetval;
141
142 aRetval.translate(DragStat().GetDX(), DragStat().GetDY());
143
144 return aRetval;
145 }
createSdrDragEntries()146 void DragMethod_PieSegment::createSdrDragEntries()
147 {
148 SdrObject* pObj = m_rDrawViewWrapper.getSelectedObject();
149 SdrPageView* pPV = m_rDrawViewWrapper.GetPageView();
150
151 if( pObj && pPV )
152 {
153 const basegfx::B2DPolyPolygon aNewPolyPolygon(pObj->TakeXorPoly());
154 addSdrDragEntry(new SdrDragEntryPolyPolygon(aNewPolyPolygon));
155 }
156 }
157 //.............................................................................
158 } //namespace chart
159 //.............................................................................
160