Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/svdraw/svdglev.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/svdglev.hxx>
22
#include <math.h>
23
24
#include <svx/svdundo.hxx>
25
#include <svx/strings.hrc>
26
#include <svx/dialmgr.hxx>
27
#include <svx/svdglue.hxx>
28
#include <svx/svdtrans.hxx>
29
#include <svx/svdobj.hxx>
30
31
SdrGlueEditView::SdrGlueEditView(
32
    SdrModel& rSdrModel,
33
    OutputDevice* pOut)
34
346k
:   SdrPolyEditView(rSdrModel, pOut)
35
346k
{
36
346k
}
37
38
SdrGlueEditView::~SdrGlueEditView()
39
346k
{
40
346k
}
41
42
void SdrGlueEditView::ImpDoMarkedGluePoints(PGlueDoFunc pDoFunc, bool bConst, const void* p1, const void* p2, const void* p3, const void* p4)
43
0
{
44
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
45
0
    const size_t nMarkCount=rMarkList.GetMarkCount();
46
0
    for (size_t nm=0; nm<nMarkCount; ++nm) {
47
0
        SdrMark* pM=rMarkList.GetMark(nm);
48
0
        SdrObject* pObj=pM->GetMarkedSdrObj();
49
0
        const SdrUShortCont& rPts = pM->GetMarkedGluePoints();
50
0
        if (!rPts.empty())
51
0
        {
52
0
            SdrGluePointList* pGPL=nullptr;
53
0
            if (bConst) {
54
0
                const SdrGluePointList* pConstGPL=pObj->GetGluePointList();
55
0
                pGPL=const_cast<SdrGluePointList*>(pConstGPL);
56
0
            } else {
57
0
                pGPL=pObj->ForceGluePointList();
58
0
            }
59
0
            if (pGPL!=nullptr)
60
0
            {
61
0
                if(!bConst && IsUndoEnabled() )
62
0
                    AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
63
64
0
                for(sal_uInt16 nPtId : rPts)
65
0
                {
66
0
                    sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
67
0
                    if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
68
0
                    {
69
0
                        SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
70
0
                        (*pDoFunc)(rGP,pObj,p1,p2,p3,p4);
71
0
                    }
72
0
                }
73
0
                if (!bConst)
74
0
                {
75
0
                    pObj->SetChanged();
76
0
                    pObj->BroadcastObjectChange();
77
0
                }
78
0
            }
79
0
        }
80
0
    }
81
0
    if (!bConst && nMarkCount!=0)
82
0
        GetModel().SetChanged();
83
0
}
84
85
86
static void ImpGetEscDir(SdrGluePoint & rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnThisEsc, const void* pnRet, const void*)
87
0
{
88
0
    TriState& nRet=*const_cast<TriState *>(static_cast<TriState const *>(pnRet));
89
0
    if (nRet!=TRISTATE_INDET) {
90
0
        SdrEscapeDirection nEsc = rGP.GetEscDir();
91
0
        bool bOn = bool(nEsc & *static_cast<SdrEscapeDirection const *>(pnThisEsc));
92
0
        bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
93
0
        if (bFirst) {
94
0
            nRet = bOn ? TRISTATE_TRUE : TRISTATE_FALSE;
95
0
            bFirst = false;
96
0
        }
97
0
        else if (nRet != (bOn ? TRISTATE_TRUE : TRISTATE_FALSE)) nRet=TRISTATE_INDET;
98
0
    }
99
0
}
100
101
TriState SdrGlueEditView::IsMarkedGluePointsEscDir(SdrEscapeDirection nThisEsc) const
102
0
{
103
0
    ForceUndirtyMrkPnt();
104
0
    bool bFirst=true;
105
0
    TriState nRet=TRISTATE_FALSE;
106
0
    const_cast<SdrGlueEditView*>(this)->ImpDoMarkedGluePoints(ImpGetEscDir,true,&bFirst,&nThisEsc,&nRet);
107
0
    return nRet;
108
0
}
109
110
static void ImpSetEscDir(SdrGluePoint& rGP, const SdrObject* /*pObj*/, const void* pnThisEsc, const void* pbOn, const void*, const void*)
111
0
{
112
0
    SdrEscapeDirection nEsc=rGP.GetEscDir();
113
0
    if (*static_cast<bool const *>(pbOn))
114
0
        nEsc |= *static_cast<SdrEscapeDirection const *>(pnThisEsc);
115
0
    else
116
0
        nEsc &= ~*static_cast<SdrEscapeDirection const *>(pnThisEsc);
117
0
    rGP.SetEscDir(nEsc);
118
0
}
119
120
void SdrGlueEditView::SetMarkedGluePointsEscDir(SdrEscapeDirection nThisEsc, bool bOn)
121
0
{
122
0
    ForceUndirtyMrkPnt();
123
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
124
0
    BegUndo(SvxResId(STR_EditSetGlueEscDir),rMarkList.GetGluePointMarkDescription());
125
0
    ImpDoMarkedGluePoints(ImpSetEscDir,false,&nThisEsc,&bOn);
126
0
    EndUndo();
127
0
}
128
129
130
static void ImpGetPercent(SdrGluePoint & rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pnRet, const void*, const void*)
131
0
{
132
0
    TriState& nRet=*const_cast<TriState *>(static_cast<TriState const *>(pnRet));
133
0
    if (nRet!=TRISTATE_INDET) {
134
0
        bool bOn=rGP.IsPercent();
135
0
        bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
136
0
        if (bFirst) {
137
0
            nRet = bOn ? TRISTATE_TRUE : TRISTATE_FALSE;
138
0
            bFirst = false;
139
0
        }
140
0
        else if ((nRet!=TRISTATE_FALSE)!=bOn)
141
0
            nRet=TRISTATE_INDET;
142
0
    }
143
0
}
144
145
TriState SdrGlueEditView::IsMarkedGluePointsPercent() const
146
0
{
147
0
    ForceUndirtyMrkPnt();
148
0
    bool bFirst=true;
149
0
    TriState nRet = TRISTATE_TRUE;
150
0
    const_cast<SdrGlueEditView*>(this)->ImpDoMarkedGluePoints(ImpGetPercent,true,&bFirst,&nRet);
151
0
    return nRet;
152
0
}
153
154
static void ImpSetPercent(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbOn, const void*, const void*, const void*)
155
0
{
156
0
    Point aPos(rGP.GetAbsolutePos(*pObj));
157
0
    rGP.SetPercent(*static_cast<bool const *>(pbOn));
158
0
    rGP.SetAbsolutePos(aPos,*pObj);
159
0
}
160
161
void SdrGlueEditView::SetMarkedGluePointsPercent(bool bOn)
162
0
{
163
0
    ForceUndirtyMrkPnt();
164
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
165
0
    BegUndo(SvxResId(STR_EditSetGluePercent),rMarkList.GetGluePointMarkDescription());
166
0
    ImpDoMarkedGluePoints(ImpSetPercent,false,&bOn);
167
0
    EndUndo();
168
0
}
169
170
171
static void ImpGetAlign(SdrGluePoint & rGP, const SdrObject* /*pObj*/, const void* pbFirst, const void* pbDontCare, const void* pbVert, const void* pnRet)
172
0
{
173
0
    SdrAlign& nRet=*const_cast<SdrAlign *>(static_cast<SdrAlign const *>(pnRet));
174
0
    bool& bDontCare=*const_cast<bool *>(static_cast<bool const *>(pbDontCare));
175
0
    bool bVert=*static_cast<bool const *>(pbVert);
176
0
    if (bDontCare)
177
0
        return;
178
179
0
    SdrAlign nAlg=SdrAlign::NONE;
180
0
    if (bVert) {
181
0
        nAlg=rGP.GetVertAlign();
182
0
    } else {
183
0
        nAlg=rGP.GetHorzAlign();
184
0
    }
185
0
    bool& bFirst=*const_cast<bool *>(static_cast<bool const *>(pbFirst));
186
0
    if (bFirst) { nRet=nAlg; bFirst=false; }
187
0
    else if (nRet!=nAlg) {
188
0
        if (bVert) {
189
0
            nRet=SdrAlign::VERT_DONTCARE;
190
0
        } else {
191
0
            nRet=SdrAlign::HORZ_DONTCARE;
192
0
        }
193
0
        bDontCare=true;
194
0
    }
195
0
}
196
197
SdrAlign SdrGlueEditView::GetMarkedGluePointsAlign(bool bVert) const
198
0
{
199
0
    ForceUndirtyMrkPnt();
200
0
    bool bFirst=true;
201
0
    bool bDontCare=false;
202
0
    SdrAlign nRet=SdrAlign::NONE;
203
0
    const_cast<SdrGlueEditView*>(this)->ImpDoMarkedGluePoints(ImpGetAlign,true,&bFirst,&bDontCare,&bVert,&nRet);
204
0
    return nRet;
205
0
}
206
207
static void ImpSetAlign(SdrGluePoint& rGP, const SdrObject* pObj, const void* pbVert, const void* pnAlign, const void*, const void*)
208
0
{
209
0
    Point aPos(rGP.GetAbsolutePos(*pObj));
210
0
    if (*static_cast<bool const *>(pbVert)) { // bVert?
211
0
        rGP.SetVertAlign(*static_cast<SdrAlign const *>(pnAlign));
212
0
    } else {
213
0
        rGP.SetHorzAlign(*static_cast<SdrAlign const *>(pnAlign));
214
0
    }
215
0
    rGP.SetAbsolutePos(aPos,*pObj);
216
0
}
217
218
void SdrGlueEditView::SetMarkedGluePointsAlign(bool bVert, SdrAlign nAlign)
219
0
{
220
0
    ForceUndirtyMrkPnt();
221
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
222
0
    BegUndo(SvxResId(STR_EditSetGlueAlign),rMarkList.GetGluePointMarkDescription());
223
0
    ImpDoMarkedGluePoints(ImpSetAlign,false,&bVert,&nAlign);
224
0
    EndUndo();
225
0
}
226
227
void SdrGlueEditView::DeleteMarkedGluePoints()
228
0
{
229
0
    BrkAction();
230
0
    ForceUndirtyMrkPnt();
231
0
    const bool bUndo = IsUndoEnabled();
232
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
233
0
    if( bUndo )
234
0
        BegUndo(SvxResId(STR_EditDelete),rMarkList.GetGluePointMarkDescription(),SdrRepeatFunc::Delete);
235
236
0
    const size_t nMarkCount=rMarkList.GetMarkCount();
237
0
    for (size_t nm=0; nm<nMarkCount; ++nm)
238
0
    {
239
0
        SdrMark* pM=rMarkList.GetMark(nm);
240
0
        SdrObject* pObj=pM->GetMarkedSdrObj();
241
0
        const SdrUShortCont& rPts = pM->GetMarkedGluePoints();
242
0
        if (!rPts.empty())
243
0
        {
244
0
            SdrGluePointList* pGPL=pObj->ForceGluePointList();
245
0
            if (pGPL!=nullptr)
246
0
            {
247
0
                if( bUndo )
248
0
                    AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
249
250
0
                for(sal_uInt16 nPtId : rPts)
251
0
                {
252
0
                    sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
253
0
                    if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
254
0
                    {
255
0
                        pGPL->Delete(nGlueIdx);
256
0
                    }
257
0
                }
258
0
                pObj->SetChanged();
259
0
                pObj->BroadcastObjectChange();
260
0
            }
261
0
        }
262
0
    }
263
0
    if( bUndo )
264
0
        EndUndo();
265
0
    UnmarkAllGluePoints();
266
0
    if (nMarkCount!=0)
267
0
        GetModel().SetChanged();
268
0
}
269
270
271
void SdrGlueEditView::ImpCopyMarkedGluePoints()
272
0
{
273
0
    const bool bUndo = IsUndoEnabled();
274
275
0
    if( bUndo )
276
0
        BegUndo();
277
278
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
279
0
    const size_t nMarkCount=rMarkList.GetMarkCount();
280
0
    for (size_t nm=0; nm<nMarkCount; ++nm)
281
0
    {
282
0
        SdrMark* pM=rMarkList.GetMark(nm);
283
0
        SdrObject* pObj=pM->GetMarkedSdrObj();
284
0
        SdrUShortCont& rPts = pM->GetMarkedGluePoints();
285
0
        SdrGluePointList* pGPL=pObj->ForceGluePointList();
286
0
        if (!rPts.empty() && pGPL!=nullptr)
287
0
        {
288
0
            if( bUndo )
289
0
                AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
290
291
0
            SdrUShortCont aIdsToErase;
292
0
            SdrUShortCont aIdsToInsert;
293
0
            for(sal_uInt16 nPtId : rPts)
294
0
            {
295
0
                sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
296
0
                if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND)
297
0
                {
298
0
                    SdrGluePoint aNewGP((*pGPL)[nGlueIdx]);  // clone GluePoint
299
0
                    sal_uInt16 nNewIdx=pGPL->Insert(aNewGP);     // and insert it
300
0
                    sal_uInt16 nNewId=(*pGPL)[nNewIdx].GetId();  // retrieve ID of new GluePoints
301
0
                    aIdsToErase.insert(nPtId);               // select it (instead of the old one)
302
0
                    aIdsToInsert.insert(nNewId);
303
0
                }
304
0
            }
305
0
            for(const auto& rId : aIdsToErase)
306
0
                rPts.erase(rId);
307
0
            rPts.insert(aIdsToInsert);
308
0
        }
309
0
    }
310
0
    if( bUndo )
311
0
        EndUndo();
312
313
0
    if (nMarkCount!=0)
314
0
        GetModel().SetChanged();
315
0
}
316
317
318
void SdrGlueEditView::ImpTransformMarkedGluePoints(PGlueTrFunc pTrFunc, const void* p1, const void* p2, const void* p3, const void* p4)
319
0
{
320
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
321
0
    const size_t nMarkCount=rMarkList.GetMarkCount();
322
0
    for (size_t nm=0; nm<nMarkCount; ++nm) {
323
0
        SdrMark* pM=rMarkList.GetMark(nm);
324
0
        SdrObject* pObj=pM->GetMarkedSdrObj();
325
0
        const SdrUShortCont& rPts = pM->GetMarkedGluePoints();
326
0
        if (!rPts.empty()) {
327
0
            SdrGluePointList* pGPL=pObj->ForceGluePointList();
328
0
            if (pGPL!=nullptr)
329
0
            {
330
0
                if( IsUndoEnabled() )
331
0
                    AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
332
333
0
                for(sal_uInt16 nPtId : rPts)
334
0
                {
335
0
                    sal_uInt16 nGlueIdx=pGPL->FindGluePoint(nPtId);
336
0
                    if (nGlueIdx!=SDRGLUEPOINT_NOTFOUND) {
337
0
                        SdrGluePoint& rGP=(*pGPL)[nGlueIdx];
338
0
                        Point aPos(rGP.GetAbsolutePos(*pObj));
339
0
                        (*pTrFunc)(aPos,p1,p2,p3,p4);
340
0
                        rGP.SetAbsolutePos(aPos,*pObj);
341
0
                    }
342
0
                }
343
0
                pObj->SetChanged();
344
0
                pObj->BroadcastObjectChange();
345
0
            }
346
0
        }
347
0
    }
348
0
    if (nMarkCount!=0)
349
0
        GetModel().SetChanged();
350
0
}
351
352
353
static void ImpMove(Point& rPt, const void* p1, const void* /*p2*/, const void* /*p3*/, const void* /*p4*/)
354
0
{
355
0
    rPt.AdjustX(static_cast<const Size*>(p1)->Width() );
356
0
    rPt.AdjustY(static_cast<const Size*>(p1)->Height() );
357
0
}
358
359
void SdrGlueEditView::MoveMarkedGluePoints(const Size& rSiz, bool bCopy)
360
0
{
361
0
    ForceUndirtyMrkPnt();
362
0
    OUString aStr(SvxResId(STR_EditMove));
363
0
    if (bCopy) aStr += SvxResId(STR_EditWithCopy);
364
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
365
0
    BegUndo(aStr,rMarkList.GetGluePointMarkDescription(),SdrRepeatFunc::Move);
366
0
    if (bCopy) ImpCopyMarkedGluePoints();
367
0
    ImpTransformMarkedGluePoints(ImpMove,&rSiz);
368
0
    EndUndo();
369
0
    AdjustMarkHdl();
370
0
}
371
372
373
static void ImpResize(Point& rPt, const void* p1, const void* p2, const void* p3, const void* /*p4*/)
374
0
{
375
0
    ResizePoint(rPt,*static_cast<const Point*>(p1),*static_cast<const double*>(p2),*static_cast<const double*>(p3));
376
0
}
377
378
void SdrGlueEditView::ResizeMarkedGluePoints(const Point& rRef, double xFact, double yFact, bool bCopy)
379
0
{
380
0
    ForceUndirtyMrkPnt();
381
0
    OUString aStr(SvxResId(STR_EditResize));
382
0
    if (bCopy) aStr+=SvxResId(STR_EditWithCopy);
383
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
384
0
    BegUndo(aStr,rMarkList.GetGluePointMarkDescription(),SdrRepeatFunc::Resize);
385
0
    if (bCopy) ImpCopyMarkedGluePoints();
386
0
    ImpTransformMarkedGluePoints(ImpResize,&rRef,&xFact,&yFact);
387
0
    EndUndo();
388
0
    AdjustMarkHdl();
389
0
}
390
391
392
static void ImpRotate(Point& rPt, const void* p1, const void* /*p2*/, const void* p3, const void* p4)
393
0
{
394
0
    RotatePoint(rPt,*static_cast<const Point*>(p1),*static_cast<const double*>(p3),*static_cast<const double*>(p4));
395
0
}
396
397
void SdrGlueEditView::RotateMarkedGluePoints(const Point& rRef, Degree100 nAngle, bool bCopy)
398
0
{
399
0
    ForceUndirtyMrkPnt();
400
0
    OUString aStr(SvxResId(STR_EditRotate));
401
0
    if (bCopy) aStr+=SvxResId(STR_EditWithCopy);
402
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
403
0
    BegUndo(aStr,rMarkList.GetGluePointMarkDescription(),SdrRepeatFunc::Rotate);
404
0
    if (bCopy) ImpCopyMarkedGluePoints();
405
0
    double nSin = sin(toRadians(nAngle));
406
0
    double nCos = cos(toRadians(nAngle));
407
0
    ImpTransformMarkedGluePoints(ImpRotate,&rRef,&nAngle,&nSin,&nCos);
408
0
    EndUndo();
409
0
    AdjustMarkHdl();
410
0
}
411
412
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */