Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/svdraw/svddrag.cxx
Line
Count
Source
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
20
#include <svx/svdview.hxx>
21
#include <svx/svddrag.hxx>
22
23
0
SdrDragStatUserData::~SdrDragStatUserData() = default;
24
25
SdrDragStat::~SdrDragStat()
26
130k
{
27
130k
}
28
29
void SdrDragStat::Clear()
30
130k
{
31
130k
    mpUserData.reset();
32
130k
    mvPnts.clear();
33
130k
    mvPnts.emplace_back();
34
130k
}
35
36
void SdrDragStat::Reset()
37
130k
{
38
130k
    m_pView=nullptr;
39
130k
    m_pPageView=nullptr;
40
130k
    m_bShown=false;
41
130k
    m_nMinMov=1;
42
130k
    m_bMinMoved=false;
43
130k
    m_bHorFixed=false;
44
130k
    m_bVerFixed=false;
45
130k
    m_bWantNoSnap=false;
46
130k
    m_pHdl=nullptr;
47
130k
    m_bOrtho4=false;
48
130k
    m_bOrtho8=false;
49
130k
    m_pDragMethod=nullptr;
50
130k
    m_bEndDragChangesAttributes=false;
51
130k
    m_bEndDragChangesGeoAndAttributes=false;
52
130k
    mbEndDragChangesLayout=false;
53
130k
    m_bMouseIsUp=false;
54
130k
    Clear();
55
130k
    m_aActionRect=tools::Rectangle();
56
130k
}
57
58
void SdrDragStat::Reset(const Point& rPnt)
59
0
{
60
0
    Reset();
61
0
    mvPnts[0]=rPnt;
62
0
    m_aPos0=rPnt;
63
0
    m_aRealNow=rPnt;
64
0
}
65
66
void SdrDragStat::NextMove(const Point& rPnt)
67
0
{
68
0
    m_aPos0=mvPnts.back();
69
0
    m_aRealNow=rPnt;
70
0
    mvPnts.back()=rPnt;
71
0
}
72
73
void SdrDragStat::NextPoint()
74
0
{
75
0
    mvPnts.emplace_back(m_aRealNow);
76
0
}
77
78
void SdrDragStat::PrevPoint()
79
0
{
80
0
    if (mvPnts.size()>1) { // one has to remain at all times
81
0
        mvPnts.erase(mvPnts.begin()+mvPnts.size()-2);
82
0
        mvPnts.back() = m_aRealNow;
83
0
    }
84
0
}
85
86
bool SdrDragStat::CheckMinMoved(const Point& rPnt)
87
0
{
88
0
    if (!m_bMinMoved) {
89
0
        tools::Long dx=rPnt.X()-GetPrev().X(); if (dx<0) dx=-dx;
90
0
        tools::Long dy=rPnt.Y()-GetPrev().Y(); if (dy<0) dy=-dy;
91
0
        if (dx>=tools::Long(m_nMinMov) || dy>=tools::Long(m_nMinMov))
92
0
            m_bMinMoved=true;
93
0
    }
94
0
    return m_bMinMoved;
95
0
}
96
97
double SdrDragStat::GetXFact() const
98
0
{
99
0
    tools::Long nMul=mvPnts.back().X()-m_aRef1.X();
100
0
    tools::Long nDiv=GetPrev().X()-m_aRef1.X();
101
0
    if (nDiv==0) nDiv=1;
102
0
    if (m_bHorFixed) { nMul=1; nDiv=1; }
103
0
    return double(nMul) / nDiv;
104
0
}
105
106
double SdrDragStat::GetYFact() const
107
0
{
108
0
    tools::Long nMul=mvPnts.back().Y()-m_aRef1.Y();
109
0
    tools::Long nDiv=GetPrev().Y()-m_aRef1.Y();
110
0
    if (nDiv==0) nDiv=1;
111
0
    if (m_bVerFixed) { nMul=1; nDiv=1; }
112
0
    return double(nMul) / nDiv;
113
0
}
114
115
void SdrDragStat::TakeCreateRect(tools::Rectangle& rRect) const
116
0
{
117
0
    rRect=tools::Rectangle(mvPnts[0], mvPnts.back());
118
0
    if (mvPnts.size()>1) {
119
0
        Point aBtmRgt(mvPnts[1]);
120
0
        rRect.SetRight(aBtmRgt.X() );
121
0
        rRect.SetBottom(aBtmRgt.Y() );
122
0
    }
123
0
    if (m_pView!=nullptr && m_pView->IsCreate1stPointAsCenter()) {
124
0
        rRect.AdjustTop(rRect.Top()-rRect.Bottom() );
125
0
        rRect.AdjustLeft(rRect.Left()-rRect.Right() );
126
0
    }
127
0
}
128
129
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */