Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/svx/source/svdraw/svdedtv.cxx
Line
Count
Source (jump to first uncovered line)
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/svdedtv.hxx>
21
#include <svx/svdundo.hxx>
22
#include <svx/svdograf.hxx>
23
#include <svx/svdoole2.hxx>
24
#include <svx/svdoedge.hxx>
25
#include <svx/svdlayer.hxx>
26
#include <svx/svdpagv.hxx>
27
#include <svx/svdpage.hxx>
28
#include <svx/svdpoev.hxx>
29
#include <svx/strings.hrc>
30
#include <svx/dialmgr.hxx>
31
#include <svx/e3dsceneupdater.hxx>
32
#include <rtl/strbuf.hxx>
33
#include <svx/svdview.hxx>
34
#include <clonelist.hxx>
35
#include <svx/svdogrp.hxx>
36
#include <svx/xfillit0.hxx>
37
#include <osl/diagnose.h>
38
#include <sfx2/viewsh.hxx>
39
40
#include <com/sun/star/lang/XServiceInfo.hpp>
41
42
using namespace com::sun::star;
43
44
void SdrEditView::ImpResetPossibilityFlags()
45
0
{
46
0
    m_bReadOnly               =false;
47
48
0
    m_bGroupPossible          =false;
49
0
    m_bUnGroupPossible        =false;
50
0
    m_bGrpEnterPossible       =false;
51
0
    m_bToTopPossible          =false;
52
0
    m_bToBtmPossible          =false;
53
0
    m_bReverseOrderPossible   =false;
54
55
0
    m_bImportMtfPossible      =false;
56
0
    m_bCombinePossible        =false;
57
0
    m_bDismantlePossible      =false;
58
0
    m_bCombineNoPolyPolyPossible =false;
59
0
    m_bDismantleMakeLinesPossible=false;
60
0
    m_bOrthoDesiredOnMarked   =false;
61
62
0
    m_bOneOrMoreMovable       =false;
63
0
    m_bMoreThanOneNoMovRot    =false;
64
0
    m_bContortionPossible     =false;
65
0
    m_bMoveAllowed            =false;
66
0
    m_bResizeFreeAllowed      =false;
67
0
    m_bResizePropAllowed      =false;
68
0
    m_bRotateFreeAllowed      =false;
69
0
    m_bRotate90Allowed        =false;
70
0
    m_bMirrorFreeAllowed      =false;
71
0
    m_bMirror45Allowed        =false;
72
0
    m_bMirror90Allowed        =false;
73
0
    m_bTransparenceAllowed    =false;
74
0
    m_bCropAllowed            =false;
75
0
    m_bGradientAllowed        =false;
76
0
    m_bShearAllowed           =false;
77
0
    m_bEdgeRadiusAllowed      =false;
78
0
    m_bCanConvToPath          =false;
79
0
    m_bCanConvToPoly          =false;
80
0
    m_bCanConvToContour       =false;
81
0
    m_bMoveProtect            =false;
82
0
    m_bResizeProtect          =false;
83
0
}
84
85
SdrEditView::SdrEditView(SdrModel& rSdrModel, OutputDevice* pOut)
86
391k
    : SdrMarkView(rSdrModel, pOut)
87
391k
    , m_bPossibilitiesDirty(true)
88
391k
    , m_bReadOnly(false)
89
391k
    , m_bGroupPossible(false)
90
391k
    , m_bUnGroupPossible(false)
91
391k
    , m_bGrpEnterPossible(false)
92
391k
    , m_bToTopPossible(false)
93
391k
    , m_bToBtmPossible(false)
94
391k
    , m_bReverseOrderPossible(false)
95
391k
    , m_bImportMtfPossible(false)
96
391k
    , m_bCombinePossible(false)
97
391k
    , m_bDismantlePossible(false)
98
391k
    , m_bCombineNoPolyPolyPossible(false)
99
391k
    , m_bDismantleMakeLinesPossible(false)
100
391k
    , m_bOrthoDesiredOnMarked(false)
101
391k
    , m_bOneOrMoreMovable(false)
102
391k
    , m_bMoreThanOneNoMovRot(false)
103
391k
    , m_bContortionPossible(false)
104
391k
    , m_bMoveAllowed(false)
105
391k
    , m_bResizeFreeAllowed(false)
106
391k
    , m_bResizePropAllowed(false)
107
391k
    , m_bRotateFreeAllowed(false)
108
391k
    , m_bRotate90Allowed(false)
109
391k
    , m_bMirrorFreeAllowed(false)
110
391k
    , m_bMirror45Allowed(false)
111
391k
    , m_bMirror90Allowed(false)
112
391k
    , m_bShearAllowed(false)
113
391k
    , m_bEdgeRadiusAllowed(false)
114
391k
    , m_bTransparenceAllowed(false)
115
391k
    , m_bCropAllowed(false)
116
391k
    , m_bGradientAllowed(false)
117
391k
    , m_bCanConvToPath(false)
118
391k
    , m_bCanConvToPoly(false)
119
391k
    , m_bCanConvToContour(false)
120
391k
    , m_bMoveProtect(false)
121
391k
    , m_bResizeProtect(false)
122
391k
{
123
391k
}
124
125
SdrEditView::~SdrEditView()
126
391k
{
127
391k
}
128
129
void SdrEditView::InsertNewLayer(const OUString& rName, sal_uInt16 nPos)
130
0
{
131
0
    SdrLayerAdmin& rLA = GetModel().GetLayerAdmin();
132
0
    sal_uInt16 nMax=rLA.GetLayerCount();
133
0
    if (nPos>nMax) nPos=nMax;
134
0
    rLA.NewLayer(rName,nPos);
135
136
0
    if( GetModel().IsUndoEnabled() )
137
0
        AddUndo(GetModel().GetSdrUndoFactory().CreateUndoNewLayer(nPos,rLA, GetModel()));
138
139
0
    GetModel().SetChanged();
140
0
}
141
142
bool SdrEditView::ImpDelLayerCheck(SdrObjList const * pOL, SdrLayerID nDelID) const
143
0
{
144
0
    bool bDelAll(true);
145
146
0
    for(size_t nObjNum = pOL->GetObjCount(); nObjNum > 0 && bDelAll;)
147
0
    {
148
0
        nObjNum--;
149
0
        SdrObject* pObj = pOL->GetObj(nObjNum);
150
0
        assert(pObj);
151
0
        SdrObjList* pSubOL = pObj->GetSubList();
152
153
        // explicitly test for group objects and 3d scenes
154
0
        if(pSubOL && (dynamic_cast<const SdrObjGroup*>(pObj) != nullptr || DynCastE3dScene(pObj)))
155
0
        {
156
0
            if(!ImpDelLayerCheck(pSubOL, nDelID))
157
0
            {
158
0
                bDelAll = false;
159
0
            }
160
0
        }
161
0
        else
162
0
        {
163
0
            if(pObj->GetLayer() != nDelID)
164
0
            {
165
0
                bDelAll = false;
166
0
            }
167
0
        }
168
0
    }
169
170
0
    return bDelAll;
171
0
}
172
173
void SdrEditView::ImpDelLayerDelObjs(SdrObjList* pOL, SdrLayerID nDelID)
174
0
{
175
0
    const size_t nObjCount(pOL->GetObjCount());
176
    // make sure OrdNums are correct
177
0
    pOL->GetObj(0)->GetOrdNum();
178
179
0
    const bool bUndo = GetModel().IsUndoEnabled();
180
181
0
    for(size_t nObjNum = nObjCount; nObjNum > 0;)
182
0
    {
183
0
        nObjNum--;
184
0
        SdrObject* pObj = pOL->GetObj(nObjNum);
185
0
        assert(pObj);
186
0
        SdrObjList* pSubOL = pObj->GetSubList();
187
188
189
        // explicitly test for group objects and 3d scenes
190
0
        if(pSubOL && (dynamic_cast<const SdrObjGroup*>( pObj) != nullptr || DynCastE3dScene(pObj)))
191
0
        {
192
0
            if(ImpDelLayerCheck(pSubOL, nDelID))
193
0
            {
194
0
                if( bUndo )
195
0
                    AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj, true));
196
0
                pOL->RemoveObject(nObjNum);
197
0
            }
198
0
            else
199
0
            {
200
0
                ImpDelLayerDelObjs(pSubOL, nDelID);
201
0
            }
202
0
        }
203
0
        else
204
0
        {
205
0
            if(pObj->GetLayer() == nDelID)
206
0
            {
207
0
                if( bUndo )
208
0
                    AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj, true));
209
0
                pOL->RemoveObject(nObjNum);
210
0
            }
211
0
        }
212
0
    }
213
0
}
214
215
void SdrEditView::DeleteLayer(const OUString& rName)
216
0
{
217
0
    SdrLayerAdmin& rLA = GetModel().GetLayerAdmin();
218
0
    SdrLayer* pLayer = rLA.GetLayer(rName);
219
220
0
    if(!pLayer)
221
0
        return;
222
223
0
    sal_uInt16 nLayerNum(rLA.GetLayerPos(pLayer));
224
0
    SdrLayerID nDelID = pLayer->GetID();
225
226
0
    const bool bUndo = IsUndoEnabled();
227
0
    if( bUndo )
228
0
        BegUndo(SvxResId(STR_UndoDelLayer));
229
230
0
    bool bMaPg(true);
231
232
0
    for(sal_uInt16 nPageKind(0); nPageKind < 2; nPageKind++)
233
0
    {
234
        // MasterPages and DrawPages
235
0
        sal_uInt16 nPgCount(bMaPg ? GetModel().GetMasterPageCount() : GetModel().GetPageCount());
236
237
0
        for(sal_uInt16 nPgNum(0); nPgNum < nPgCount; nPgNum++)
238
0
        {
239
            // over all pages
240
0
            SdrPage* pPage = bMaPg ? GetModel().GetMasterPage(nPgNum) : GetModel().GetPage(nPgNum);
241
0
            const size_t nObjCount(pPage->GetObjCount());
242
243
            // make sure OrdNums are correct
244
0
            if(nObjCount)
245
0
                pPage->GetObj(0)->GetOrdNum();
246
247
0
            for(size_t nObjNum(nObjCount); nObjNum > 0;)
248
0
            {
249
0
                nObjNum--;
250
0
                SdrObject* pObj = pPage->GetObj(nObjNum);
251
0
                assert(pObj);
252
0
                SdrObjList* pSubOL = pObj->GetSubList();
253
254
                // explicitly test for group objects and 3d scenes
255
0
                if(pSubOL && (dynamic_cast<const SdrObjGroup*>(pObj) != nullptr || DynCastE3dScene(pObj)))
256
0
                {
257
0
                    if(ImpDelLayerCheck(pSubOL, nDelID))
258
0
                    {
259
0
                        if( bUndo )
260
0
                            AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj, true));
261
0
                        pPage->RemoveObject(nObjNum);
262
0
                    }
263
0
                    else
264
0
                    {
265
0
                        ImpDelLayerDelObjs(pSubOL, nDelID);
266
0
                    }
267
0
                }
268
0
                else
269
0
                {
270
0
                    if(pObj->GetLayer() == nDelID)
271
0
                    {
272
0
                        if( bUndo )
273
0
                            AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj, true));
274
0
                        pPage->RemoveObject(nObjNum);
275
0
                    }
276
0
                }
277
0
            }
278
0
        }
279
0
        bMaPg = false;
280
0
    }
281
282
0
    if( bUndo )
283
0
    {
284
0
        AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteLayer(nLayerNum, rLA, GetModel()));
285
        // coverity[leaked_storage] - ownership transferred to UndoDeleteLayer
286
0
        rLA.RemoveLayer(nLayerNum).release();
287
0
        EndUndo();
288
0
    }
289
0
    else
290
0
    {
291
0
        rLA.RemoveLayer(nLayerNum);
292
0
    }
293
294
0
    GetModel().SetChanged();
295
0
}
296
297
298
void SdrEditView::EndUndo()
299
0
{
300
    // #i13033#
301
    // Comparison changed to 1L since EndUndo() is called later now
302
    // and EndUndo WILL change count to count-1
303
0
    if(1 == GetModel().GetUndoBracketLevel())
304
0
    {
305
0
        ImpBroadcastEdgesOfMarkedNodes();
306
0
    }
307
308
    // #i13033#
309
    // moved to bottom to still have access to UNDOs inside of
310
    // ImpBroadcastEdgesOfMarkedNodes()
311
0
    GetModel().EndUndo();
312
0
}
313
314
void SdrEditView::ImpBroadcastEdgesOfMarkedNodes()
315
0
{
316
0
    std::vector<SdrObject*>::const_iterator iterPos;
317
0
    const std::vector<SdrObject*>& rAllMarkedObjects = GetTransitiveHullOfMarkedObjects();
318
319
    // #i13033#
320
    // New mechanism to search for necessary disconnections for
321
    // changed connectors inside the transitive hull of all at
322
    // the beginning of UNDO selected objects
323
0
    for(size_t a(0); a < rAllMarkedObjects.size(); a++)
324
0
    {
325
0
        SdrEdgeObj* pEdge = dynamic_cast<SdrEdgeObj*>( rAllMarkedObjects[a] );
326
327
0
        if(pEdge)
328
0
        {
329
0
            SdrObject* pObj1 = pEdge->GetConnectedNode(false);
330
0
            SdrObject* pObj2 = pEdge->GetConnectedNode(true);
331
332
0
            if(pObj1 && !pEdge->CheckNodeConnection(false))
333
0
            {
334
0
                iterPos = std::find(rAllMarkedObjects.begin(),rAllMarkedObjects.end(),pObj1);
335
336
0
                if (iterPos == rAllMarkedObjects.end())
337
0
                {
338
0
                    if( IsUndoEnabled() )
339
0
                        AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pEdge));
340
0
                    pEdge->DisconnectFromNode(false);
341
0
                }
342
0
            }
343
344
0
            if(pObj2 && !pEdge->CheckNodeConnection(true))
345
0
            {
346
0
                iterPos = std::find(rAllMarkedObjects.begin(),rAllMarkedObjects.end(),pObj2);
347
348
0
                if (iterPos == rAllMarkedObjects.end())
349
0
                {
350
0
                    if( IsUndoEnabled() )
351
0
                        AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pEdge));
352
0
                    pEdge->DisconnectFromNode(true);
353
0
                }
354
0
            }
355
0
        }
356
0
    }
357
358
0
    const size_t nMarkedEdgeCnt = GetMarkedEdgesOfMarkedNodes().GetMarkCount();
359
360
0
    for (size_t i=0; i<nMarkedEdgeCnt; ++i) {
361
0
        SdrMark* pEM = GetMarkedEdgesOfMarkedNodes().GetMark(i);
362
0
        SdrObject* pEdgeTmp=pEM->GetMarkedSdrObj();
363
0
        SdrEdgeObj* pEdge=dynamic_cast<SdrEdgeObj*>( pEdgeTmp );
364
0
        if (pEdge!=nullptr) {
365
0
            pEdge->SetEdgeTrackDirty();
366
0
        }
367
0
    }
368
0
}
369
370
371
// Possibilities
372
373
374
void SdrEditView::MarkListHasChanged()
375
90.3k
{
376
90.3k
    SdrMarkView::MarkListHasChanged();
377
90.3k
    m_bPossibilitiesDirty=true;
378
90.3k
}
379
380
void SdrEditView::ModelHasChanged()
381
0
{
382
0
    SdrMarkView::ModelHasChanged();
383
0
    m_bPossibilitiesDirty=true;
384
0
}
385
386
bool SdrEditView::IsResizeAllowed(bool bProp) const
387
0
{
388
0
    ForcePossibilities();
389
0
    if (m_bResizeProtect) return false;
390
0
    if (bProp) return m_bResizePropAllowed;
391
0
    return m_bResizeFreeAllowed;
392
0
}
393
394
bool SdrEditView::IsRotateAllowed(bool b90Deg) const
395
0
{
396
0
    ForcePossibilities();
397
0
    if (m_bMoveProtect) return false;
398
0
    if (b90Deg) return m_bRotate90Allowed;
399
0
    return m_bRotateFreeAllowed;
400
0
}
401
402
bool SdrEditView::IsMirrorAllowed(bool b45Deg, bool b90Deg) const
403
0
{
404
0
    ForcePossibilities();
405
0
    if (m_bMoveProtect) return false;
406
0
    if (b90Deg) return m_bMirror90Allowed;
407
0
    if (b45Deg) return m_bMirror45Allowed;
408
0
    return m_bMirrorFreeAllowed;
409
0
}
410
411
bool SdrEditView::IsTransparenceAllowed() const
412
0
{
413
0
    ForcePossibilities();
414
0
    return m_bTransparenceAllowed;
415
0
}
416
417
bool SdrEditView::IsCropAllowed() const
418
0
{
419
0
    ForcePossibilities();
420
0
    return m_bCropAllowed;
421
0
}
422
423
bool SdrEditView::IsGradientAllowed() const
424
0
{
425
0
    ForcePossibilities();
426
0
    return m_bGradientAllowed;
427
0
}
428
429
bool SdrEditView::IsShearAllowed() const
430
0
{
431
0
    ForcePossibilities();
432
0
    if (m_bResizeProtect) return false;
433
0
    return m_bShearAllowed;
434
0
}
435
436
bool SdrEditView::IsEdgeRadiusAllowed() const
437
0
{
438
0
    ForcePossibilities();
439
0
    return m_bEdgeRadiusAllowed;
440
0
}
441
442
bool SdrEditView::IsCrookAllowed(bool bNoContortion) const
443
0
{
444
    // CrookMode missing here (no rotations allowed when shearing ...)
445
0
    ForcePossibilities();
446
0
    if (bNoContortion) {
447
0
        if (!m_bRotateFreeAllowed) return false;
448
0
        return !m_bMoveProtect && m_bMoveAllowed;
449
0
    } else {
450
0
        return !m_bResizeProtect && m_bContortionPossible;
451
0
    }
452
0
}
453
454
bool SdrEditView::IsDistortAllowed(bool bNoContortion) const
455
0
{
456
0
    ForcePossibilities();
457
0
    if (bNoContortion) {
458
0
        return false;
459
0
    } else {
460
0
        return !m_bResizeProtect && m_bContortionPossible;
461
0
    }
462
0
}
463
464
bool SdrEditView::IsCombinePossible(bool bNoPolyPoly) const
465
0
{
466
0
    ForcePossibilities();
467
0
    if (bNoPolyPoly) return m_bCombineNoPolyPolyPossible;
468
0
    else return m_bCombinePossible;
469
0
}
470
471
bool SdrEditView::IsDismantlePossible(bool bMakeLines) const
472
0
{
473
0
    ForcePossibilities();
474
0
    if (bMakeLines) return m_bDismantleMakeLinesPossible;
475
0
    else return m_bDismantlePossible;
476
0
}
477
478
void SdrEditView::CheckPossibilities()
479
0
{
480
0
    if (mbSomeObjChgdFlag)
481
0
    {
482
0
        m_bPossibilitiesDirty = true;
483
484
        // This call IS necessary to correct the MarkList, in which
485
        // no longer to the model belonging objects still can reside.
486
        // These ones need to be removed.
487
0
        CheckMarked();
488
0
    }
489
490
0
    if (!m_bPossibilitiesDirty)
491
0
        return;
492
493
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
494
0
    ImpResetPossibilityFlags();
495
0
    rMarkList.ForceSort();
496
0
    const size_t nMarkCount = rMarkList.GetMarkCount();
497
0
    if (nMarkCount != 0)
498
0
    {
499
0
        m_bReverseOrderPossible = (nMarkCount >= 2);
500
501
0
        size_t nMovableCount=0;
502
0
        m_bGroupPossible=nMarkCount>=2;
503
0
        m_bCombinePossible=nMarkCount>=2;
504
0
        if (nMarkCount==1)
505
0
        {
506
            // check bCombinePossible more thoroughly
507
            // still missing ...
508
0
            const SdrObject* pObj=rMarkList.GetMark(0)->GetMarkedSdrObj();
509
            //const SdrPathObj* pPath=dynamic_cast<SdrPathObj*>( pObj );
510
0
            bool bGroup=pObj->GetSubList()!=nullptr;
511
0
            bool bHasText=pObj->GetOutlinerParaObject()!=nullptr;
512
0
            if (bGroup || bHasText) {
513
0
                m_bCombinePossible=true;
514
0
            }
515
0
        }
516
0
        m_bCombineNoPolyPolyPossible=m_bCombinePossible;
517
        // accept transformations for now
518
0
        m_bMoveAllowed      =true;
519
0
        m_bResizeFreeAllowed=true;
520
0
        m_bResizePropAllowed=true;
521
0
        m_bRotateFreeAllowed=true;
522
0
        m_bRotate90Allowed  =true;
523
0
        m_bMirrorFreeAllowed=true;
524
0
        m_bMirror45Allowed  =true;
525
0
        m_bMirror90Allowed  =true;
526
0
        m_bShearAllowed     =true;
527
0
        m_bEdgeRadiusAllowed=false;
528
0
        m_bContortionPossible=true;
529
0
        m_bCanConvToContour = true;
530
531
        // these ones are only allowed when single object is selected
532
0
        m_bTransparenceAllowed = (nMarkCount == 1);
533
0
        m_bGradientAllowed = (nMarkCount == 1);
534
0
        m_bCropAllowed = (nMarkCount == 1);
535
0
        if(m_bGradientAllowed)
536
0
        {
537
            // gradient depends on fill style
538
0
            const SdrMark* pM = rMarkList.GetMark(0);
539
0
            const SdrObject* pObj = pM->GetMarkedSdrObj();
540
541
            // may be group object, so get merged ItemSet
542
0
            const SfxItemSet& rSet = pObj->GetMergedItemSet();
543
0
            SfxItemState eState = rSet.GetItemState(XATTR_FILLSTYLE, false);
544
545
0
            if(SfxItemState::INVALID != eState)
546
0
            {
547
                // If state is not DONTCARE, test the item
548
0
                drawing::FillStyle eFillStyle = rSet.Get(XATTR_FILLSTYLE).GetValue();
549
550
0
                if(eFillStyle != drawing::FillStyle_GRADIENT)
551
0
                {
552
0
                    m_bGradientAllowed = false;
553
0
                }
554
0
            }
555
0
        }
556
557
0
        bool bNoMovRotFound=false;
558
0
        const SdrPageView* pPV0=nullptr;
559
560
0
        for (size_t nm=0; nm<nMarkCount; ++nm) {
561
0
            const SdrMark* pM=rMarkList.GetMark(nm);
562
0
            const SdrObject* pObj=pM->GetMarkedSdrObj();
563
0
            const SdrPageView* pPV=pM->GetPageView();
564
0
            if (pPV!=pPV0) {
565
0
                if (pPV->IsReadOnly()) m_bReadOnly=true;
566
0
                pPV0=pPV;
567
0
            }
568
569
0
            SdrObjTransformInfoRec aInfo;
570
0
            pObj->TakeObjInfo(aInfo);
571
0
            bool bMovPrt=pObj->IsMoveProtect();
572
0
            bool bSizPrt=pObj->IsResizeProtect();
573
0
            if (!bMovPrt && aInfo.bMoveAllowed) nMovableCount++; // count MovableObjs
574
0
            if (bMovPrt) m_bMoveProtect=true;
575
0
            if (bSizPrt) m_bResizeProtect=true;
576
577
            // not allowed when not allowed at one object
578
0
            if(!aInfo.bTransparenceAllowed)
579
0
                m_bTransparenceAllowed = false;
580
581
            // If one of these can't do something, none can
582
0
            if (!aInfo.bMoveAllowed      ) m_bMoveAllowed      =false;
583
0
            if (!aInfo.bResizeFreeAllowed) m_bResizeFreeAllowed=false;
584
0
            if (!aInfo.bResizePropAllowed) m_bResizePropAllowed=false;
585
0
            if (!aInfo.bRotateFreeAllowed) m_bRotateFreeAllowed=false;
586
0
            if (!aInfo.bRotate90Allowed  ) m_bRotate90Allowed  =false;
587
0
            if (!aInfo.bMirrorFreeAllowed) m_bMirrorFreeAllowed=false;
588
0
            if (!aInfo.bMirror45Allowed  ) m_bMirror45Allowed  =false;
589
0
            if (!aInfo.bMirror90Allowed  ) m_bMirror90Allowed  =false;
590
0
            if (!aInfo.bShearAllowed     ) m_bShearAllowed     =false;
591
0
            if (aInfo.bEdgeRadiusAllowed) m_bEdgeRadiusAllowed=true;
592
0
            if (aInfo.bNoContortion      ) m_bContortionPossible=false;
593
            // For Crook with Contortion: all objects have to be
594
            // Movable and Rotatable, except for a maximum of 1 of them
595
0
            if (!m_bMoreThanOneNoMovRot) {
596
0
                if (!aInfo.bMoveAllowed || !aInfo.bResizeFreeAllowed) {
597
0
                    m_bMoreThanOneNoMovRot=bNoMovRotFound;
598
0
                    bNoMovRotFound=true;
599
0
                }
600
0
            }
601
602
            // Must be resizable to allow cropping
603
0
            if (!aInfo.bResizeFreeAllowed && !aInfo.bResizePropAllowed)
604
0
                m_bCropAllowed = false;
605
606
            // if one member cannot be converted, no conversion is possible
607
0
            if(!aInfo.bCanConvToContour)
608
0
                m_bCanConvToContour = false;
609
610
            // Ungroup
611
0
            if (!m_bUnGroupPossible) m_bUnGroupPossible=pObj->GetSubList()!=nullptr;
612
            // ConvertToCurve: If at least one can be converted, that is fine.
613
0
            if (aInfo.bCanConvToPath          ) m_bCanConvToPath          =true;
614
0
            if (aInfo.bCanConvToPoly          ) m_bCanConvToPoly          =true;
615
616
            // Combine/Dismantle
617
0
            if(m_bCombinePossible)
618
0
            {
619
0
                m_bCombinePossible = ImpCanConvertForCombine(pObj);
620
0
                m_bCombineNoPolyPolyPossible = m_bCombinePossible;
621
0
            }
622
623
0
            if (!m_bDismantlePossible) m_bDismantlePossible = ImpCanDismantle(pObj, false);
624
0
            if (!m_bDismantleMakeLinesPossible) m_bDismantleMakeLinesPossible = ImpCanDismantle(pObj, true);
625
            // check OrthoDesiredOnMarked
626
0
            if (!m_bOrthoDesiredOnMarked && !aInfo.bNoOrthoDesired) m_bOrthoDesiredOnMarked=true;
627
            // check ImportMtf
628
629
0
            if (!m_bImportMtfPossible)
630
0
            {
631
0
                const SdrGrafObj* pSdrGrafObj = dynamic_cast< const SdrGrafObj* >(pObj);
632
0
                if (pSdrGrafObj != nullptr)
633
0
                {
634
0
                    if ((pSdrGrafObj->HasGDIMetaFile() && !pSdrGrafObj->IsEPS()) ||
635
0
                        pSdrGrafObj->isEmbeddedVectorGraphicData())
636
0
                    {
637
0
                        m_bImportMtfPossible = true;
638
0
                    }
639
0
                }
640
641
0
                const SdrOle2Obj* pSdrOle2Obj = dynamic_cast< const SdrOle2Obj* >(pObj);
642
0
                if (pSdrOle2Obj)
643
0
                {
644
0
                    m_bImportMtfPossible = pSdrOle2Obj->GetObjRef().is();
645
0
                }
646
0
            }
647
0
        }
648
649
0
        m_bOneOrMoreMovable=nMovableCount!=0;
650
0
        m_bGrpEnterPossible=m_bUnGroupPossible;
651
0
    }
652
0
    ImpCheckToTopBtmPossible();
653
0
    static_cast<SdrPolyEditView*>(this)->ImpCheckPolyPossibilities();
654
0
    m_bPossibilitiesDirty=false;
655
656
0
    if (m_bReadOnly || SfxViewShell::IsCurrentLokViewReadOnly() ) {
657
0
        bool bTemp=m_bGrpEnterPossible;
658
0
        ImpResetPossibilityFlags();
659
0
        m_bReadOnly=true;
660
0
        m_bGrpEnterPossible=bTemp;
661
0
    }
662
0
    if (!m_bMoveAllowed)        return;
663
664
    // Don't allow moving glued connectors.
665
    // Currently only implemented for single selection.
666
0
    if (nMarkCount==1) {
667
0
        SdrObject* pObj=rMarkList.GetMark(0)->GetMarkedSdrObj();
668
0
        SdrEdgeObj* pEdge=dynamic_cast<SdrEdgeObj*>( pObj );
669
0
        if (pEdge!=nullptr) {
670
0
            SdrObject* pNode1=pEdge->GetConnectedNode(true);
671
0
            SdrObject* pNode2=pEdge->GetConnectedNode(false);
672
0
            if (pNode1!=nullptr || pNode2!=nullptr) m_bMoveAllowed=false;
673
0
        }
674
0
    }
675
676
    // Don't allow enter Diagrams
677
0
    if (1 == nMarkCount && m_bGrpEnterPossible)
678
0
    {
679
0
        SdrObject* pCandidate(rMarkList.GetMark(0)->GetMarkedSdrObj());
680
681
0
        if(nullptr != pCandidate && pCandidate->isDiagram())
682
0
            m_bGrpEnterPossible = false;
683
0
    }
684
0
}
685
686
687
void SdrEditView::ForceMarkedObjToAnotherPage()
688
0
{
689
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
690
0
    bool bFlg=false;
691
0
    for (size_t nm=0; nm<rMarkList.GetMarkCount(); ++nm) {
692
0
        SdrMark* pM=rMarkList.GetMark(nm);
693
0
        SdrObject* pObj=pM->GetMarkedSdrObj();
694
0
        tools::Rectangle aObjRect(pObj->GetCurrentBoundRect());
695
0
        tools::Rectangle aPgRect(pM->GetPageView()->GetPageRect());
696
0
        if (!aObjRect.Overlaps(aPgRect)) {
697
0
            bool bFnd=false;
698
0
            SdrPageView* pPV = GetSdrPageView();
699
700
0
            if(pPV)
701
0
            {
702
0
                bFnd = aObjRect.Overlaps(pPV->GetPageRect());
703
0
            }
704
705
0
            if(bFnd)
706
0
            {
707
0
                pM->GetPageView()->GetObjList()->RemoveObject(pObj->GetOrdNum());
708
0
                pPV->GetObjList()->InsertObject(pObj, SAL_MAX_SIZE);
709
0
                pM->SetPageView(pPV);
710
0
                InvalidateAllWin(aObjRect);
711
0
                bFlg=true;
712
0
            }
713
0
        }
714
0
    }
715
0
    if (bFlg) {
716
0
        MarkListHasChanged();
717
0
    }
718
0
}
719
720
std::vector<rtl::Reference<SdrObject>> SdrEditView::DeleteMarkedList(SdrMarkList const& rMark)
721
0
{
722
0
    std::vector<rtl::Reference<SdrObject>> ret;
723
0
    if (rMark.GetMarkCount()!=0)
724
0
    {
725
0
        rMark.ForceSort();
726
727
0
        const bool bUndo = IsUndoEnabled();
728
0
        if( bUndo )
729
0
            BegUndo();
730
0
        const size_t nMarkCount(rMark.GetMarkCount());
731
732
0
        if(nMarkCount)
733
0
        {
734
0
            std::vector< E3DModifySceneSnapRectUpdater* > aUpdaters;
735
736
0
            if( bUndo )
737
0
            {
738
0
                for(size_t nm = nMarkCount; nm > 0;)
739
0
                {
740
0
                    --nm;
741
0
                    SdrMark* pM = rMark.GetMark(nm);
742
0
                    SdrObject* pObj = pM->GetMarkedSdrObj();
743
744
                    // extra undo actions for changed connector which now may hold its laid out path (SJ)
745
0
                    AddUndoActions(CreateConnectorUndo( *pObj ));
746
747
0
                    AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
748
0
                }
749
0
            }
750
751
            // make sure, OrderNums are correct:
752
0
            rMark.GetMark(0)->GetMarkedSdrObj()->GetOrdNum();
753
754
0
            for(size_t nm = nMarkCount; nm > 0;)
755
0
            {
756
0
                --nm;
757
0
                SdrMark* pM = rMark.GetMark(nm);
758
0
                SdrObject* pObj = pM->GetMarkedSdrObj();
759
0
                SdrObjList*  pOL = pObj->getParentSdrObjListFromSdrObject();
760
0
                const size_t nOrdNum(pObj->GetOrdNumDirect());
761
762
0
                bool bIs3D = DynCastE3dObject(pObj);
763
                // set up a scene updater if object is a 3d object
764
0
                if(bIs3D)
765
0
                {
766
0
                    aUpdaters.push_back(new E3DModifySceneSnapRectUpdater(pObj));
767
0
                }
768
769
0
                if( !bUndo )
770
0
                {
771
                    // tdf#108863 and tdf#108889 don't delete objects before EndUndo()
772
0
                    ret.push_back(pObj);
773
0
                }
774
775
0
                pOL->RemoveObject(nOrdNum);
776
0
            }
777
778
            // fire scene updaters
779
0
            while(!aUpdaters.empty())
780
0
            {
781
0
                delete aUpdaters.back();
782
0
                aUpdaters.pop_back();
783
0
            }
784
0
        }
785
786
0
        if( bUndo )
787
0
            EndUndo();
788
0
    }
789
0
    return ret;
790
0
}
791
792
static void lcl_LazyDelete(std::vector<rtl::Reference<SdrObject>> & rLazyDelete)
793
0
{
794
    // now delete removed scene objects
795
0
    while (!rLazyDelete.empty())
796
0
        rLazyDelete.pop_back();
797
0
}
798
799
void SdrEditView::DeleteMarkedObj()
800
0
{
801
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
802
    // #i110981# return when nothing is to be done at all
803
0
    if(!rMarkList.GetMarkCount())
804
0
    {
805
0
        return;
806
0
    }
807
808
    // moved breaking action and undo start outside loop
809
0
    BrkAction();
810
0
    BegUndo(SvxResId(STR_EditDelete),rMarkList.GetMarkDescription(),SdrRepeatFunc::Delete);
811
812
0
    std::vector<rtl::Reference<SdrObject>> lazyDeleteObjects;
813
    // remove as long as something is selected. This allows to schedule objects for
814
    // removal for a next run as needed
815
0
    while(rMarkList.GetMarkCount())
816
0
    {
817
        // vector to remember the parents which may be empty after object removal
818
0
        std::vector< SdrObject* > aParents;
819
820
0
        {
821
0
            const size_t nCount(rMarkList.GetMarkCount());
822
823
0
            for(size_t a = 0; a < nCount; ++a)
824
0
            {
825
                // in the first run, add all found parents, but only once
826
0
                SdrMark* pMark(rMarkList.GetMark(a));
827
0
                SdrObject* pObject(pMark->GetMarkedSdrObj());
828
0
                SdrObject* pParent(pObject->getParentSdrObjectFromSdrObject());
829
830
0
                if(pParent)
831
0
                {
832
0
                    if(!aParents.empty())
833
0
                    {
834
0
                        std::vector< SdrObject* >::iterator aFindResult =
835
0
                            std::find(aParents.begin(), aParents.end(), pParent);
836
837
0
                        if(aFindResult == aParents.end())
838
0
                        {
839
0
                            aParents.push_back(pParent);
840
0
                        }
841
0
                    }
842
0
                    else
843
0
                    {
844
0
                        aParents.push_back(pParent);
845
0
                    }
846
0
                }
847
0
            }
848
849
0
            if(!aParents.empty())
850
0
            {
851
                // in a 2nd run, remove all objects which may already be scheduled for
852
                // removal. I am not sure if this can happen, but theoretically
853
                // a to-be-removed object may already be the group/3DScene itself
854
0
                for(size_t a = 0; a < nCount; ++a)
855
0
                {
856
0
                    SdrMark* pMark = rMarkList.GetMark(a);
857
0
                    SdrObject* pObject = pMark->GetMarkedSdrObj();
858
859
0
                    std::vector< SdrObject* >::iterator aFindResult =
860
0
                        std::find(aParents.begin(), aParents.end(), pObject);
861
862
0
                    if(aFindResult != aParents.end())
863
0
                    {
864
0
                        aParents.erase(aFindResult);
865
0
                    }
866
0
                }
867
0
            }
868
0
        }
869
870
        // original stuff: remove selected objects. Handle clear will
871
        // do something only once
872
0
        auto temp(DeleteMarkedList(rMarkList));
873
0
        lazyDeleteObjects.insert(lazyDeleteObjects.end(), temp.begin(), temp.end());
874
0
        GetMarkedObjectListWriteAccess().Clear();
875
0
        maHdlList.Clear();
876
877
0
        while(!aParents.empty() && !rMarkList.GetMarkCount())
878
0
        {
879
            // iterate over remembered parents
880
0
            SdrObject* pParent = aParents.back();
881
0
            aParents.pop_back();
882
883
0
            if(pParent->GetSubList() && 0 == pParent->GetSubList()->GetObjCount())
884
0
            {
885
                // we detected an empty parent, a candidate to leave group/3DScene
886
                // if entered
887
0
                if(GetSdrPageView()->GetCurrentGroup()
888
0
                    && GetSdrPageView()->GetCurrentGroup() == pParent)
889
0
                {
890
0
                    GetSdrPageView()->LeaveOneGroup();
891
0
                }
892
893
                // schedule empty parent for removal
894
0
                GetMarkedObjectListWriteAccess().InsertEntry(
895
0
                    SdrMark(pParent, GetSdrPageView()));
896
0
            }
897
0
        }
898
0
    }
899
900
    // end undo and change messaging moved at the end
901
0
    EndUndo();
902
0
    MarkListHasChanged();
903
904
0
    lcl_LazyDelete(lazyDeleteObjects);
905
0
}
906
907
void SdrEditView::CopyMarkedObj()
908
0
{
909
0
    const SdrMarkList& rMarkList = GetMarkedObjectList();
910
0
    rMarkList.ForceSort();
911
912
0
    SdrMarkList aSourceObjectsForCopy(rMarkList);
913
    // The following loop is used instead of MarkList::Merge(), to be
914
    // able to flag the MarkEntries.
915
0
    const size_t nEdgeCnt = GetEdgesOfMarkedNodes().GetMarkCount();
916
0
    for (size_t nEdgeNum=0; nEdgeNum<nEdgeCnt; ++nEdgeNum) {
917
0
        SdrMark aM(*GetEdgesOfMarkedNodes().GetMark(nEdgeNum));
918
0
        aM.SetUser(1);
919
0
        aSourceObjectsForCopy.InsertEntry(aM);
920
0
    }
921
0
    aSourceObjectsForCopy.ForceSort();
922
923
    // #i13033#
924
    // New mechanism to re-create the connections of cloned connectors
925
0
    CloneList aCloneList;
926
927
0
    const bool bUndo = IsUndoEnabled();
928
929
0
    GetMarkedObjectListWriteAccess().Clear();
930
0
    size_t nCloneErrCnt=0;
931
0
    std::unordered_set<rtl::OUString> aNameSet;
932
0
    const size_t nMarkCount=aSourceObjectsForCopy.GetMarkCount();
933
0
    for (size_t nm=0; nm<nMarkCount; ++nm) {
934
0
        SdrMark* pM=aSourceObjectsForCopy.GetMark(nm);
935
0
        SdrObject* pSource(pM->GetMarkedSdrObj());
936
0
        rtl::Reference<SdrObject> pO(pSource->CloneSdrObject(pSource->getSdrModelFromSdrObject()));
937
0
        if (pO!=nullptr) {
938
0
            pM->GetPageView()->GetObjList()->InsertObjectThenMakeNameUnique(pO.get(), aNameSet);
939
940
0
            if( bUndo )
941
0
                AddUndo(GetModel().GetSdrUndoFactory().CreateUndoCopyObject(*pO));
942
943
0
            SdrMark aME(*pM);
944
0
            aME.SetMarkedSdrObj(pO.get());
945
0
            aCloneList.AddPair(pM->GetMarkedSdrObj(), pO.get());
946
947
0
            if (pM->GetUser()==0)
948
0
            {
949
                // otherwise it is only an Edge we have to copy as well
950
0
                GetMarkedObjectListWriteAccess().InsertEntry(aME);
951
0
            }
952
0
        } else {
953
0
            nCloneErrCnt++;
954
0
        }
955
0
    }
956
957
    // #i13033#
958
    // New mechanism to re-create the connections of cloned connectors
959
0
    aCloneList.CopyConnections();
960
961
0
    if(nCloneErrCnt)
962
0
    {
963
#ifdef DBG_UTIL
964
        OStringBuffer aStr("SdrEditView::CopyMarkedObj(): Error when cloning ");
965
966
        if(nCloneErrCnt == 1)
967
        {
968
            aStr.append("a drawing object.");
969
        }
970
        else
971
        {
972
            aStr.append(OString::number(static_cast<sal_Int32>(nCloneErrCnt))
973
                + " drawing objects.");
974
        }
975
976
        aStr.append(" This object's/These objects's connections will not be copied.");
977
        OSL_FAIL(aStr.getStr());
978
#endif
979
0
    }
980
0
    MarkListHasChanged();
981
0
}
982
983
984
bool SdrEditView::InsertObjectAtView(SdrObject* pObj, SdrPageView& rPV, SdrInsertFlags nOptions)
985
0
{
986
0
    if (nOptions & SdrInsertFlags::SETDEFLAYER) {
987
0
        SdrLayerID nLayer=rPV.GetPage()->GetLayerAdmin().GetLayerID(maActualLayer);
988
0
        if (nLayer==SDRLAYER_NOTFOUND) nLayer=SdrLayerID(0);
989
0
        if (rPV.GetLockedLayers().IsSet(nLayer) || !rPV.GetVisibleLayers().IsSet(nLayer)) {
990
0
            return false;
991
0
        }
992
0
        pObj->NbcSetLayer(nLayer);
993
0
    }
994
0
    if (nOptions & SdrInsertFlags::SETDEFATTR) {
995
0
        if (mpDefaultStyleSheet!=nullptr) pObj->NbcSetStyleSheet(mpDefaultStyleSheet, false);
996
0
        pObj->SetMergedItemSet(maDefaultAttr);
997
0
    }
998
0
    if (!pObj->IsInserted()) {
999
0
        rPV.GetObjList()->InsertObject(pObj, SAL_MAX_SIZE);
1000
0
    }
1001
1002
0
    css::uno::Reference<lang::XServiceInfo> xServices(GetModel().getUnoModel(),
1003
0
                                                      css::uno::UNO_QUERY);
1004
0
    if (xServices.is() && (xServices->supportsService(u"com.sun.star.sheet.SpreadsheetDocument"_ustr) ||
1005
0
                           xServices->supportsService(u"com.sun.star.text.TextDocument"_ustr)))
1006
0
    {
1007
0
        const bool bUndo(IsUndoEnabled());
1008
0
        GetModel().EnableUndo(false);
1009
0
        pObj->MakeNameUnique();
1010
0
        GetModel().EnableUndo(bUndo);
1011
0
    }
1012
1013
0
    if( IsUndoEnabled())
1014
0
    {
1015
0
        bool bDontDeleteReally = true;
1016
0
        EndTextEditCurrentView(bDontDeleteReally);
1017
0
        AddUndo(GetModel().GetSdrUndoFactory().CreateUndoNewObject(*pObj));
1018
0
    }
1019
1020
0
    if (!(nOptions & SdrInsertFlags::DONTMARK)) {
1021
0
        if (!(nOptions & SdrInsertFlags::ADDMARK)) UnmarkAllObj();
1022
0
        MarkObj(pObj,&rPV);
1023
0
    }
1024
0
    return true;
1025
0
}
1026
1027
void SdrEditView::ReplaceObjectAtView(SdrObject* pOldObj, SdrPageView& rPV, SdrObject* pNewObj, bool bMark)
1028
0
{
1029
0
    if(IsTextEdit())
1030
0
    {
1031
#ifdef DBG_UTIL
1032
        if(auto pTextObj = DynCastSdrTextObj(pOldObj))
1033
            if (pTextObj->IsTextEditActive())
1034
                OSL_ENSURE(false, "OldObject is in TextEdit mode, this has to be ended before replacing it using SdrEndTextEdit (!)");
1035
1036
        if(auto pTextObj = DynCastSdrTextObj(pNewObj))
1037
            if (pTextObj->IsTextEditActive())
1038
                OSL_ENSURE(false, "NewObject is in TextEdit mode, this has to be ended before replacing it using SdrEndTextEdit (!)");
1039
#endif
1040
1041
        // #i123468# emergency repair situation, needs to cast up to a class derived from
1042
        // this one; (aw080 has a mechanism for that and the view hierarchy is secured to
1043
        // always be a SdrView)
1044
0
        SdrView *pSdrView = dynamic_cast<SdrView*>(this);
1045
0
        if (pSdrView)
1046
0
            pSdrView->SdrEndTextEdit();
1047
0
    }
1048
1049
0
    SdrObjList* pOL=pOldObj->getParentSdrObjListFromSdrObject();
1050
0
    const bool bUndo = IsUndoEnabled();
1051
0
    if( bUndo  )
1052
0
        AddUndo(GetModel().GetSdrUndoFactory().CreateUndoReplaceObject(*pOldObj,*pNewObj));
1053
1054
0
    if( IsObjMarked( pOldObj ) )
1055
0
        MarkObj( pOldObj, &rPV, true /*unmark!*/ );
1056
1057
0
    pOL->ReplaceObject(pNewObj,pOldObj->GetOrdNum());
1058
1059
0
    if (bMark) MarkObj(pNewObj,&rPV);
1060
0
}
1061
1062
1063
bool SdrEditView::IsUndoEnabled() const
1064
0
{
1065
0
    return GetModel().IsUndoEnabled();
1066
0
}
1067
1068
void SdrEditView::EndTextEditAllViews() const
1069
0
{
1070
0
    GetModel().ForAllListeners(
1071
0
        [](SfxListener* pListener)
1072
0
        {
1073
0
            SdrObjEditView* pView = dynamic_cast<SdrObjEditView*>(pListener);
1074
0
            if (pView && pView->IsTextEdit())
1075
0
                pView->SdrEndTextEdit();
1076
0
            return false;
1077
0
        });
1078
0
}
1079
1080
void SdrEditView::EndTextEditCurrentView(bool bDontDeleteReally)
1081
0
{
1082
0
    if (IsTextEdit())
1083
0
    {
1084
0
        SdrView* pSdrView = dynamic_cast<SdrView*>(this);
1085
0
        if (pSdrView)
1086
0
            pSdrView->SdrEndTextEdit(bDontDeleteReally);
1087
0
    }
1088
0
}
1089
1090
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */