1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DragMethod_PieSegment.cxx,v $
10 * $Revision: 1.4.68.1 $
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 "DragMethod_PieSegment.hxx"
36 #include "Strings.hrc"
39 #include "ObjectIdentifier.hxx"
40 #include <rtl/math.hxx>
41 #include <svx/svdpagv.hxx>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <basegfx/matrix/b2dhommatrix.hxx>
45 //.............................................................................
48 //.............................................................................
50 using namespace ::com::sun::star
;
51 using ::com::sun::star::uno::Reference
;
52 using ::basegfx::B2DVector
;
54 DragMethod_PieSegment::DragMethod_PieSegment( DrawViewWrapper
& rDrawViewWrapper
55 , const rtl::OUString
& rObjectCID
56 , const Reference
< frame::XModel
>& xChartModel
)
57 : DragMethod_Base( rDrawViewWrapper
, rObjectCID
, xChartModel
)
58 , m_aStartVector(100.0,100.0)
59 , m_fInitialOffset(0.0)
60 , m_fAdditionalOffset(0.0)
61 , m_aDragDirection(1000.0,1000.0)
64 rtl::OUString
aParameter( ObjectIdentifier::getDragParameterString( m_aObjectCID
) );
66 sal_Int32
nOffsetPercent(0);
67 awt::Point
aMinimumPosition(0,0);
68 awt::Point
aMaximumPosition(0,0);
70 ObjectIdentifier::parsePieSegmentDragParameterString(
71 aParameter
, nOffsetPercent
, aMinimumPosition
, aMaximumPosition
);
73 m_fInitialOffset
= nOffsetPercent
/ 100.0;
74 if( m_fInitialOffset
< 0.0 )
75 m_fInitialOffset
= 0.0;
76 if( m_fInitialOffset
> 1.0 )
77 m_fInitialOffset
= 1.0;
78 B2DVector
aMinVector( aMinimumPosition
.X
, aMinimumPosition
.Y
);
79 B2DVector
aMaxVector( aMaximumPosition
.X
, aMaximumPosition
.Y
);
80 m_aDragDirection
= aMaxVector
- aMinVector
;
81 m_fDragRange
= m_aDragDirection
.scalar( m_aDragDirection
);
82 if( ::rtl::math::approxEqual( m_fDragRange
, 0.0 ) )
85 DragMethod_PieSegment::~DragMethod_PieSegment()
88 void DragMethod_PieSegment::TakeSdrDragComment(String
& rStr
) const
90 rStr
= String( SchResId( STR_STATUS_PIE_SEGMENT_EXPLODED
) );
91 rStr
.SearchAndReplaceAscii( "%PERCENTVALUE", String::CreateFromInt32( static_cast<sal_Int32
>((m_fAdditionalOffset
+m_fInitialOffset
)*100.0) ));
93 bool DragMethod_PieSegment::BeginSdrDrag()
95 Point
aStart( DragStat().GetStart() );
96 m_aStartVector
= B2DVector( aStart
.X(), aStart
.Y() );
100 void DragMethod_PieSegment::MoveSdrDrag(const Point
& rPnt
)
102 if( DragStat().CheckMinMoved(rPnt
) )
104 //calculate new offset
105 B2DVector
aShiftVector(( B2DVector( rPnt
.X(), rPnt
.Y() ) - m_aStartVector
));
106 m_fAdditionalOffset
= m_aDragDirection
.scalar( aShiftVector
)/m_fDragRange
; // projection
108 if( m_fAdditionalOffset
< -m_fInitialOffset
)
109 m_fAdditionalOffset
= -m_fInitialOffset
;
110 else if( m_fAdditionalOffset
> (1.0-m_fInitialOffset
) )
111 m_fAdditionalOffset
= 1.0 - m_fInitialOffset
;
113 B2DVector aNewPosVector
= m_aStartVector
+ (m_aDragDirection
* m_fAdditionalOffset
);
114 Point aNewPos
= Point( (long)(aNewPosVector
.getX()), (long)(aNewPosVector
.getY()) );
115 if( aNewPos
!= DragStat().GetNow() )
118 DragStat().NextMove( aNewPos
);
123 bool DragMethod_PieSegment::EndSdrDrag(bool /*bCopy*/)
129 Reference
< frame::XModel
> xChartModel( this->getChartModel() );
130 if( xChartModel
.is() )
132 Reference
< beans::XPropertySet
> xPointProperties(
133 ObjectIdentifier::getObjectPropertySet( m_aObjectCID
, xChartModel
) );
134 if( xPointProperties
.is() )
135 xPointProperties
->setPropertyValue( C2U( "Offset" ), uno::makeAny( m_fAdditionalOffset
+m_fInitialOffset
));
138 catch( const uno::Exception
& ex
)
140 ASSERT_EXCEPTION( ex
);
145 basegfx::B2DHomMatrix
DragMethod_PieSegment::getCurrentTransformation()
147 basegfx::B2DHomMatrix aRetval
;
149 aRetval
.translate(DragStat().GetDX(), DragStat().GetDY());
153 void DragMethod_PieSegment::createSdrDragEntries()
155 SdrObject
* pObj
= m_rDrawViewWrapper
.getSelectedObject();
156 SdrPageView
* pPV
= m_rDrawViewWrapper
.GetPageView();
160 const basegfx::B2DPolyPolygon
aNewPolyPolygon(pObj
->TakeXorPoly());
161 addSdrDragEntry(new SdrDragEntryPolyPolygon(aNewPolyPolygon
));
164 //.............................................................................
166 //.............................................................................