1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "DragMethod_PieSegment.hxx"
33 #include "Strings.hrc"
36 #include "ObjectIdentifier.hxx"
37 #include <rtl/math.hxx>
38 #include <svx/svdpagv.hxx>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <basegfx/matrix/b2dhommatrix.hxx>
42 //.............................................................................
45 //.............................................................................
47 using namespace ::com::sun::star
;
48 using ::com::sun::star::uno::Reference
;
49 using ::basegfx::B2DVector
;
51 DragMethod_PieSegment::DragMethod_PieSegment( DrawViewWrapper
& rDrawViewWrapper
52 , const rtl::OUString
& rObjectCID
53 , const Reference
< frame::XModel
>& xChartModel
)
54 : DragMethod_Base( rDrawViewWrapper
, rObjectCID
, xChartModel
)
55 , m_aStartVector(100.0,100.0)
56 , m_fInitialOffset(0.0)
57 , m_fAdditionalOffset(0.0)
58 , m_aDragDirection(1000.0,1000.0)
61 rtl::OUString
aParameter( ObjectIdentifier::getDragParameterString( m_aObjectCID
) );
63 sal_Int32
nOffsetPercent(0);
64 awt::Point
aMinimumPosition(0,0);
65 awt::Point
aMaximumPosition(0,0);
67 ObjectIdentifier::parsePieSegmentDragParameterString(
68 aParameter
, nOffsetPercent
, aMinimumPosition
, aMaximumPosition
);
70 m_fInitialOffset
= nOffsetPercent
/ 100.0;
71 if( m_fInitialOffset
< 0.0 )
72 m_fInitialOffset
= 0.0;
73 if( m_fInitialOffset
> 1.0 )
74 m_fInitialOffset
= 1.0;
75 B2DVector
aMinVector( aMinimumPosition
.X
, aMinimumPosition
.Y
);
76 B2DVector
aMaxVector( aMaximumPosition
.X
, aMaximumPosition
.Y
);
77 m_aDragDirection
= aMaxVector
- aMinVector
;
78 m_fDragRange
= m_aDragDirection
.scalar( m_aDragDirection
);
79 if( ::rtl::math::approxEqual( m_fDragRange
, 0.0 ) )
82 DragMethod_PieSegment::~DragMethod_PieSegment()
85 void DragMethod_PieSegment::TakeSdrDragComment(String
& rStr
) const
87 rStr
= String( SchResId( STR_STATUS_PIE_SEGMENT_EXPLODED
) );
88 rStr
.SearchAndReplaceAscii( "%PERCENTVALUE", String::CreateFromInt32( static_cast<sal_Int32
>((m_fAdditionalOffset
+m_fInitialOffset
)*100.0) ));
90 bool DragMethod_PieSegment::BeginSdrDrag()
92 Point
aStart( DragStat().GetStart() );
93 m_aStartVector
= B2DVector( aStart
.X(), aStart
.Y() );
97 void DragMethod_PieSegment::MoveSdrDrag(const Point
& rPnt
)
99 if( DragStat().CheckMinMoved(rPnt
) )
101 //calculate new offset
102 B2DVector
aShiftVector(( B2DVector( rPnt
.X(), rPnt
.Y() ) - m_aStartVector
));
103 m_fAdditionalOffset
= m_aDragDirection
.scalar( aShiftVector
)/m_fDragRange
; // projection
105 if( m_fAdditionalOffset
< -m_fInitialOffset
)
106 m_fAdditionalOffset
= -m_fInitialOffset
;
107 else if( m_fAdditionalOffset
> (1.0-m_fInitialOffset
) )
108 m_fAdditionalOffset
= 1.0 - m_fInitialOffset
;
110 B2DVector aNewPosVector
= m_aStartVector
+ (m_aDragDirection
* m_fAdditionalOffset
);
111 Point aNewPos
= Point( (long)(aNewPosVector
.getX()), (long)(aNewPosVector
.getY()) );
112 if( aNewPos
!= DragStat().GetNow() )
115 DragStat().NextMove( aNewPos
);
120 bool DragMethod_PieSegment::EndSdrDrag(bool /*bCopy*/)
126 Reference
< frame::XModel
> xChartModel( this->getChartModel() );
127 if( xChartModel
.is() )
129 Reference
< beans::XPropertySet
> xPointProperties(
130 ObjectIdentifier::getObjectPropertySet( m_aObjectCID
, xChartModel
) );
131 if( xPointProperties
.is() )
132 xPointProperties
->setPropertyValue( C2U( "Offset" ), uno::makeAny( m_fAdditionalOffset
+m_fInitialOffset
));
135 catch( const uno::Exception
& ex
)
137 ASSERT_EXCEPTION( ex
);
142 basegfx::B2DHomMatrix
DragMethod_PieSegment::getCurrentTransformation()
144 basegfx::B2DHomMatrix aRetval
;
146 aRetval
.translate(DragStat().GetDX(), DragStat().GetDY());
150 void DragMethod_PieSegment::createSdrDragEntries()
152 SdrObject
* pObj
= m_rDrawViewWrapper
.getSelectedObject();
153 SdrPageView
* pPV
= m_rDrawViewWrapper
.GetPageView();
157 const basegfx::B2DPolyPolygon
aNewPolyPolygon(pObj
->TakeXorPoly());
158 addSdrDragEntry(new SdrDragEntryPolyPolygon(aNewPolyPolygon
));
161 //.............................................................................
163 //.............................................................................