Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/svdraw/svdotxdr.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
21
#include <svx/svdotext.hxx>
22
#include <svx/svdhdl.hxx>
23
#include <svx/svddrag.hxx>
24
#include <svx/svdview.hxx>
25
#include <svx/svdorect.hxx>
26
#include <svx/strings.hrc>
27
#include <svx/svdoashp.hxx>
28
#include <tools/bigint.hxx>
29
#include <basegfx/polygon/b2dpolygon.hxx>
30
#include <basegfx/range/b2drange.hxx>
31
#include <basegfx/polygon/b2dpolygontools.hxx>
32
#include <vcl/canvastools.hxx>
33
#include <vcl/ptrstyle.hxx>
34
35
36
sal_uInt32 SdrTextObj::GetHdlCount() const
37
0
{
38
0
    return 8;
39
0
}
40
41
void SdrTextObj::AddToHdlList(SdrHdlList& rHdlList) const
42
0
{
43
0
    for(sal_uInt32 nHdlNum=0; nHdlNum<8; ++nHdlNum)
44
0
    {
45
0
        Point aPnt;
46
0
        SdrHdlKind eKind = SdrHdlKind::UpperLeft;
47
0
        const tools::Rectangle rRectangle = getRectangle();
48
0
        switch (nHdlNum) {
49
0
            case 0: aPnt = rRectangle.TopLeft();      eKind=SdrHdlKind::UpperLeft; break;
50
0
            case 1: aPnt = rRectangle.TopCenter();    eKind=SdrHdlKind::Upper; break;
51
0
            case 2: aPnt = rRectangle.TopRight();     eKind=SdrHdlKind::UpperRight; break;
52
0
            case 3: aPnt = rRectangle.LeftCenter();   eKind=SdrHdlKind::Left ; break;
53
0
            case 4: aPnt = rRectangle.RightCenter();  eKind=SdrHdlKind::Right; break;
54
0
            case 5: aPnt = rRectangle.BottomLeft();   eKind=SdrHdlKind::LowerLeft; break;
55
0
            case 6: aPnt = rRectangle.BottomCenter(); eKind=SdrHdlKind::Lower; break;
56
0
            case 7: aPnt = rRectangle.BottomRight();  eKind=SdrHdlKind::LowerRight; break;
57
0
        }
58
0
        if (maGeo.m_nShearAngle)
59
0
            ShearPoint(aPnt, rRectangle.TopLeft(), maGeo.mfTanShearAngle);
60
0
        if (maGeo.m_nRotationAngle)
61
0
            RotatePoint(aPnt, rRectangle.TopLeft(), maGeo.mfSinRotationAngle, maGeo.mfCosRotationAngle);
62
0
        std::unique_ptr<SdrHdl> pH(new SdrHdl(aPnt,eKind));
63
0
        pH->SetObj(const_cast<SdrTextObj*>(this));
64
0
        pH->SetRotationAngle(maGeo.m_nRotationAngle);
65
0
        rHdlList.AddHdl(std::move(pH));
66
0
    }
67
0
}
68
69
bool SdrTextObj::hasSpecialDrag() const
70
0
{
71
0
    return true;
72
0
}
73
74
tools::Rectangle SdrTextObj::ImpDragCalcRect(const SdrDragStat& rDrag) const
75
0
{
76
0
    tools::Rectangle aTmpRect(getRectangle());
77
0
    Point aPos(rDrag.GetNow());
78
    // Unrotate:
79
0
    if (maGeo.m_nRotationAngle) RotatePoint(aPos,aTmpRect.TopLeft(),-maGeo.mfSinRotationAngle,maGeo.mfCosRotationAngle);
80
    // Unshear:
81
0
    if (maGeo.m_nShearAngle) ShearPoint(aPos,aTmpRect.TopLeft(),-maGeo.mfTanShearAngle);
82
0
    ImpCommonDragCalcRect( rDrag, aTmpRect, aPos );
83
84
0
    if (dynamic_cast<const SdrObjCustomShape*>(this) ==  nullptr)        // not justifying when in CustomShapes, to be able to detect if a shape has to be mirrored
85
0
        ImpJustifyRect(aTmpRect);
86
0
    return aTmpRect;
87
0
}
88
89
90
// drag
91
92
bool SdrTextObj::applySpecialDrag(SdrDragStat& rDrag)
93
0
{
94
0
    tools::Rectangle aNewRect(ImpDragCalcRect(rDrag));
95
96
0
    if(aNewRect.TopLeft() != getRectangle().TopLeft() && (maGeo.m_nRotationAngle || maGeo.m_nShearAngle))
97
0
    {
98
0
        Point aNewPos(aNewRect.TopLeft());
99
100
0
        if (maGeo.m_nShearAngle)
101
0
            ShearPoint(aNewPos, getRectangle().TopLeft(), maGeo.mfTanShearAngle);
102
103
0
        if (maGeo.m_nRotationAngle)
104
0
            RotatePoint(aNewPos, getRectangle().TopLeft(), maGeo.mfSinRotationAngle, maGeo.mfCosRotationAngle);
105
106
0
        aNewRect.SetPos(aNewPos);
107
0
    }
108
109
0
    if (aNewRect != getRectangle())
110
0
    {
111
0
        NbcSetLogicRect(aNewRect);
112
0
    }
113
114
0
    return true;
115
0
}
116
117
OUString SdrTextObj::getSpecialDragComment(const SdrDragStat& /*rDrag*/) const
118
0
{
119
0
    return ImpGetDescriptionStr(STR_DragRectResize);
120
0
}
121
122
123
// Create
124
125
bool SdrTextObj::BegCreate(SdrDragStat& rStat)
126
0
{
127
0
    rStat.SetOrtho4Possible();
128
0
    tools::Rectangle aRect1(rStat.GetStart(), rStat.GetNow());
129
0
    aRect1.Normalize();
130
0
    rStat.SetActionRect(aRect1);
131
0
    setRectangle(aRect1);
132
0
    return true;
133
0
}
134
135
bool SdrTextObj::MovCreate(SdrDragStat& rStat)
136
0
{
137
0
    tools::Rectangle aRect1;
138
0
    rStat.TakeCreateRect(aRect1);
139
0
    ImpJustifyRect(aRect1);
140
0
    rStat.SetActionRect(aRect1);
141
0
    setRectangle(aRect1); // for ObjName
142
0
    SetBoundRectDirty();
143
0
    m_bSnapRectDirty=true;
144
0
    if (auto pRectObj = dynamic_cast<SdrRectObj *>(this)) {
145
0
        pRectObj->SetXPolyDirty();
146
0
    }
147
0
    return true;
148
0
}
149
150
bool SdrTextObj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
151
0
{
152
0
    tools::Rectangle aRectangle(getRectangle());
153
0
    rStat.TakeCreateRect(aRectangle);
154
0
    ImpJustifyRect(aRectangle);
155
0
    setRectangle(aRectangle);
156
157
0
    AdaptTextMinSize();
158
159
0
    SetBoundAndSnapRectsDirty();
160
0
    if (auto pRectObj = dynamic_cast<SdrRectObj *>(this)) {
161
0
        pRectObj->SetXPolyDirty();
162
0
    }
163
0
    return (eCmd==SdrCreateCmd::ForceEnd || rStat.GetPointCount()>=2);
164
0
}
165
166
void SdrTextObj::BrkCreate(SdrDragStat& /*rStat*/)
167
0
{
168
0
}
169
170
bool SdrTextObj::BckCreate(SdrDragStat& /*rStat*/)
171
0
{
172
0
    return true;
173
0
}
174
175
basegfx::B2DPolyPolygon SdrTextObj::TakeCreatePoly(const SdrDragStat& rDrag) const
176
0
{
177
0
    tools::Rectangle aRect1;
178
0
    rDrag.TakeCreateRect(aRect1);
179
0
    aRect1.Normalize();
180
181
0
    basegfx::B2DPolyPolygon aRetval;
182
0
    const basegfx::B2DRange aRange = vcl::unotools::b2DRectangleFromRectangle(aRect1);
183
0
    aRetval.append(basegfx::utils::createPolygonFromRect(aRange));
184
0
    return aRetval;
185
0
}
186
187
PointerStyle SdrTextObj::GetCreatePointer() const
188
0
{
189
0
    if (IsTextFrame()) return PointerStyle::DrawText;
190
0
    return PointerStyle::Cross;
191
0
}
192
193
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */