Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / svdraw / svddrag.cxx
blob0c785dc6742613d0c1592af3869401d72a9c949d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/svdview.hxx>
21 #include <svx/svddrag.hxx>
23 SdrDragStatUserData::~SdrDragStatUserData() = default;
25 SdrDragStat::~SdrDragStat()
29 void SdrDragStat::Clear()
31 mpUserData.reset();
32 mvPnts.clear();
33 mvPnts.emplace_back();
36 void SdrDragStat::Reset()
38 pView=nullptr;
39 pPageView=nullptr;
40 bShown=false;
41 nMinMov=1;
42 bMinMoved=false;
43 bHorFixed=false;
44 bVerFixed=false;
45 bWantNoSnap=false;
46 pHdl=nullptr;
47 bOrtho4=false;
48 bOrtho8=false;
49 pDragMethod=nullptr;
50 bEndDragChangesAttributes=false;
51 bEndDragChangesGeoAndAttributes=false;
52 mbEndDragChangesLayout=false;
53 bMouseIsUp=false;
54 Clear();
55 aActionRect=tools::Rectangle();
58 void SdrDragStat::Reset(const Point& rPnt)
60 Reset();
61 mvPnts[0]=rPnt;
62 aPos0=rPnt;
63 aRealNow=rPnt;
66 void SdrDragStat::NextMove(const Point& rPnt)
68 aPos0=mvPnts.back();
69 aRealNow=rPnt;
70 mvPnts.back()=rPnt;
73 void SdrDragStat::NextPoint()
75 mvPnts.emplace_back(aRealNow);
78 void SdrDragStat::PrevPoint()
80 if (mvPnts.size()>1) { // one has to remain at all times
81 mvPnts.erase(mvPnts.begin()+mvPnts.size()-2);
82 mvPnts.back() = aRealNow;
86 bool SdrDragStat::CheckMinMoved(const Point& rPnt)
88 if (!bMinMoved) {
89 tools::Long dx=rPnt.X()-GetPrev().X(); if (dx<0) dx=-dx;
90 tools::Long dy=rPnt.Y()-GetPrev().Y(); if (dy<0) dy=-dy;
91 if (dx>=tools::Long(nMinMov) || dy>=tools::Long(nMinMov))
92 bMinMoved=true;
94 return bMinMoved;
97 Fraction SdrDragStat::GetXFact() const
99 tools::Long nMul=mvPnts.back().X()-aRef1.X();
100 tools::Long nDiv=GetPrev().X()-aRef1.X();
101 if (nDiv==0) nDiv=1;
102 if (bHorFixed) { nMul=1; nDiv=1; }
103 return Fraction(nMul,nDiv);
106 Fraction SdrDragStat::GetYFact() const
108 tools::Long nMul=mvPnts.back().Y()-aRef1.Y();
109 tools::Long nDiv=GetPrev().Y()-aRef1.Y();
110 if (nDiv==0) nDiv=1;
111 if (bVerFixed) { nMul=1; nDiv=1; }
112 return Fraction(nMul,nDiv);
115 void SdrDragStat::TakeCreateRect(tools::Rectangle& rRect) const
117 rRect=tools::Rectangle(mvPnts[0], mvPnts.back());
118 if (mvPnts.size()>1) {
119 Point aBtmRgt(mvPnts[1]);
120 rRect.SetRight(aBtmRgt.X() );
121 rRect.SetBottom(aBtmRgt.Y() );
123 if (pView!=nullptr && pView->IsCreate1stPointAsCenter()) {
124 rRect.AdjustTop(rRect.Top()-rRect.Bottom() );
125 rRect.AdjustLeft(rRect.Left()-rRect.Right() );
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */