LibreOffice Module chart2 (master) 1
DragMethod_PieSegment.cxx
Go to the documentation of this file.
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
21#include <DrawViewWrapper.hxx>
22#include <ChartModel.hxx>
23#include <strings.hrc>
24#include <ResId.hxx>
25#include <ObjectIdentifier.hxx>
26#include <com/sun/star/beans/XPropertySet.hpp>
27#include <com/sun/star/awt/Point.hpp>
30
31namespace chart
32{
33
34using namespace ::com::sun::star;
35using ::com::sun::star::uno::Reference;
36using ::basegfx::B2DVector;
37
39 , const OUString& rObjectCID
40 , const rtl::Reference<::chart::ChartModel>& xChartModel )
41 : DragMethod_Base( rDrawViewWrapper, rObjectCID, xChartModel )
42 , m_aStartVector(100.0,100.0)
43 , m_fInitialOffset(0.0)
44 , m_fAdditionalOffset(0.0)
45 , m_aDragDirection(1000.0,1000.0)
46 , m_fDragRange( 1.0 )
47{
48 std::u16string_view aParameter( ObjectIdentifier::getDragParameterString( m_aObjectCID ) );
49
50 sal_Int32 nOffsetPercent(0);
51 awt::Point aMinimumPosition(0,0);
52 awt::Point aMaximumPosition(0,0);
53
55 aParameter, nOffsetPercent, aMinimumPosition, aMaximumPosition );
56
57 m_fInitialOffset = nOffsetPercent / 100.0;
58 if( m_fInitialOffset < 0.0 )
59 m_fInitialOffset = 0.0;
60 if( m_fInitialOffset > 1.0 )
61 m_fInitialOffset = 1.0;
62 B2DVector aMinVector( aMinimumPosition.X, aMinimumPosition.Y );
63 B2DVector aMaxVector( aMaximumPosition.X, aMaximumPosition.Y );
64 m_aDragDirection = aMaxVector - aMinVector;
66 if( m_fDragRange == 0.0 )
67 m_fDragRange = 1.0;
68}
70{
71}
73{
74 OUString aStr = SchResId(STR_STATUS_PIE_SEGMENT_EXPLODED);
75 aStr = aStr.replaceFirst( "%PERCENTVALUE", OUString::number( static_cast<sal_Int32>((m_fAdditionalOffset+m_fInitialOffset)*100.0) ));
76 return aStr;
77}
79{
80 Point aStart( DragStat().GetStart() );
81 m_aStartVector = B2DVector( aStart.X(), aStart.Y() );
82 Show();
83 return true;
84}
86{
87 if( !DragStat().CheckMinMoved(rPnt) )
88 return;
89
90 //calculate new offset
91 B2DVector aShiftVector( B2DVector( rPnt.X(), rPnt.Y() ) - m_aStartVector );
92 m_fAdditionalOffset = m_aDragDirection.scalar( aShiftVector )/m_fDragRange; // projection
93
96 else if( m_fAdditionalOffset > (1.0-m_fInitialOffset) )
98
99 B2DVector aNewPosVector = m_aStartVector + (m_aDragDirection * m_fAdditionalOffset);
100 Point aNewPos( static_cast<tools::Long>(aNewPosVector.getX()), static_cast<tools::Long>(aNewPosVector.getY()) );
101 if( aNewPos != DragStat().GetNow() )
102 {
103 Hide();
104 DragStat().NextMove( aNewPos );
105 Show();
106 }
107}
109{
110 Hide();
111
112 try
113 {
115 if( xChartModel.is() )
116 {
117 Reference< beans::XPropertySet > xPointProperties(
119 if( xPointProperties.is() )
120 xPointProperties->setPropertyValue( "Offset", uno::Any( m_fAdditionalOffset+m_fInitialOffset ));
121 }
122 }
123 catch( const uno::Exception & )
124 {
125 DBG_UNHANDLED_EXCEPTION("chart2");
126 }
127
128 return true;
129}
131{
132 basegfx::B2DHomMatrix aRetval;
133
134 aRetval.translate(DragStat().GetDX(), DragStat().GetDY());
135
136 return aRetval;
137}
139{
142
143 if( pObj && pPV )
144 {
145 basegfx::B2DPolyPolygon aNewPolyPolygon(pObj->TakeXorPoly());
146 addSdrDragEntry(std::unique_ptr<SdrDragEntry>(new SdrDragEntryPolyPolygon(std::move(aNewPolyPolygon))));
147 }
148}
149} //namespace chart
150
151/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr tools::Long Y() const
constexpr tools::Long X() const
SdrDragStat & DragStat()
void addSdrDragEntry(std::unique_ptr< SdrDragEntry > pNew)
void NextMove(const Point &rPnt)
virtual basegfx::B2DPolyPolygon TakeXorPoly() const
void translate(double fX, double fY)
double scalar(const B2DVector &rVec) const
DrawViewWrapper & m_rDrawViewWrapper
rtl::Reference<::chart::ChartModel > getChartModel() const
virtual OUString GetSdrDragComment() const override
virtual void MoveSdrDrag(const Point &rPnt) override
virtual basegfx::B2DHomMatrix getCurrentTransformation() const override
DragMethod_PieSegment(DrawViewWrapper &rDrawViewWrapper, const OUString &rObjectCID, const rtl::Reference<::chart::ChartModel > &xChartModel)
virtual bool EndSdrDrag(bool bCopy) override
virtual bool BeginSdrDrag() override
virtual void createSdrDragEntries() override
SdrPageView * GetPageView() const
SdrObject * getSelectedObject() const
static css::uno::Reference< css::beans::XPropertySet > getObjectPropertySet(std::u16string_view rObjectCID, const rtl::Reference< ::chart::ChartModel > &xChartDocument)
static std::u16string_view getDragParameterString(std::u16string_view rCID)
static bool parsePieSegmentDragParameterString(std::u16string_view rDragParameterString, sal_Int32 &rOffsetPercent, css::awt::Point &rMinimumPosition, css::awt::Point &rMaximumPosition)
#define DBG_UNHANDLED_EXCEPTION(...)
aStr
OUString OOO_DLLPUBLIC_CHARTTOOLS SchResId(TranslateId aId)
Definition: ResId.cxx:24
long Long