Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / svdraw / svdedtv.cxx
blob27015e410e9de0e40fa6f681d7d10fafe546341a
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/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/scene3d.hxx>
37 #include <svx/xfillit0.hxx>
38 #include <osl/diagnose.h>
40 #include <com/sun/star/lang/XServiceInfo.hpp>
42 using namespace com::sun::star;
44 void SdrEditView::ImpResetPossibilityFlags()
46 m_bReadOnly =false;
48 m_bGroupPossible =false;
49 m_bUnGroupPossible =false;
50 m_bGrpEnterPossible =false;
51 m_bToTopPossible =false;
52 m_bToBtmPossible =false;
53 m_bReverseOrderPossible =false;
55 m_bImportMtfPossible =false;
56 m_bCombinePossible =false;
57 m_bDismantlePossible =false;
58 m_bCombineNoPolyPolyPossible =false;
59 m_bDismantleMakeLinesPossible=false;
60 m_bOrthoDesiredOnMarked =false;
62 m_bOneOrMoreMovable =false;
63 m_bMoreThanOneNoMovRot =false;
64 m_bContortionPossible =false;
65 m_bMoveAllowed =false;
66 m_bResizeFreeAllowed =false;
67 m_bResizePropAllowed =false;
68 m_bRotateFreeAllowed =false;
69 m_bRotate90Allowed =false;
70 m_bMirrorFreeAllowed =false;
71 m_bMirror45Allowed =false;
72 m_bMirror90Allowed =false;
73 m_bTransparenceAllowed =false;
74 m_bCropAllowed =false;
75 m_bGradientAllowed =false;
76 m_bShearAllowed =false;
77 m_bEdgeRadiusAllowed =false;
78 m_bCanConvToPath =false;
79 m_bCanConvToPoly =false;
80 m_bCanConvToContour =false;
81 m_bMoveProtect =false;
82 m_bResizeProtect =false;
85 SdrEditView::SdrEditView(SdrModel& rSdrModel, OutputDevice* pOut)
86 : SdrMarkView(rSdrModel, pOut)
87 , m_bPossibilitiesDirty(true)
88 , m_bReadOnly(false)
89 , m_bGroupPossible(false)
90 , m_bUnGroupPossible(false)
91 , m_bGrpEnterPossible(false)
92 , m_bToTopPossible(false)
93 , m_bToBtmPossible(false)
94 , m_bReverseOrderPossible(false)
95 , m_bImportMtfPossible(false)
96 , m_bCombinePossible(false)
97 , m_bDismantlePossible(false)
98 , m_bCombineNoPolyPolyPossible(false)
99 , m_bDismantleMakeLinesPossible(false)
100 , m_bOrthoDesiredOnMarked(false)
101 , m_bOneOrMoreMovable(false)
102 , m_bMoreThanOneNoMovRot(false)
103 , m_bContortionPossible(false)
104 , m_bMoveAllowed(false)
105 , m_bResizeFreeAllowed(false)
106 , m_bResizePropAllowed(false)
107 , m_bRotateFreeAllowed(false)
108 , m_bRotate90Allowed(false)
109 , m_bMirrorFreeAllowed(false)
110 , m_bMirror45Allowed(false)
111 , m_bMirror90Allowed(false)
112 , m_bShearAllowed(false)
113 , m_bEdgeRadiusAllowed(false)
114 , m_bTransparenceAllowed(false)
115 , m_bCropAllowed(false)
116 , m_bGradientAllowed(false)
117 , m_bCanConvToPath(false)
118 , m_bCanConvToPoly(false)
119 , m_bCanConvToContour(false)
120 , m_bMoveProtect(false)
121 , m_bResizeProtect(false)
125 SdrEditView::~SdrEditView()
129 void SdrEditView::InsertNewLayer(const OUString& rName, sal_uInt16 nPos)
131 SdrLayerAdmin& rLA = GetModel().GetLayerAdmin();
132 sal_uInt16 nMax=rLA.GetLayerCount();
133 if (nPos>nMax) nPos=nMax;
134 rLA.NewLayer(rName,nPos);
136 if( GetModel().IsUndoEnabled() )
137 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoNewLayer(nPos,rLA, GetModel()));
139 GetModel().SetChanged();
142 bool SdrEditView::ImpDelLayerCheck(SdrObjList const * pOL, SdrLayerID nDelID) const
144 bool bDelAll(true);
146 for(size_t nObjNum = pOL->GetObjCount(); nObjNum > 0 && bDelAll;)
148 nObjNum--;
149 SdrObject* pObj = pOL->GetObj(nObjNum);
150 SdrObjList* pSubOL = pObj->GetSubList();
152 // explicitly test for group objects and 3d scenes
153 if(pSubOL && (dynamic_cast<const SdrObjGroup*>(pObj) != nullptr || DynCastE3dScene(pObj)))
155 if(!ImpDelLayerCheck(pSubOL, nDelID))
157 bDelAll = false;
160 else
162 if(pObj->GetLayer() != nDelID)
164 bDelAll = false;
169 return bDelAll;
172 void SdrEditView::ImpDelLayerDelObjs(SdrObjList* pOL, SdrLayerID nDelID)
174 const size_t nObjCount(pOL->GetObjCount());
175 // make sure OrdNums are correct
176 pOL->GetObj(0)->GetOrdNum();
178 const bool bUndo = GetModel().IsUndoEnabled();
180 for(size_t nObjNum = nObjCount; nObjNum > 0;)
182 nObjNum--;
183 SdrObject* pObj = pOL->GetObj(nObjNum);
184 SdrObjList* pSubOL = pObj->GetSubList();
187 // explicitly test for group objects and 3d scenes
188 if(pSubOL && (dynamic_cast<const SdrObjGroup*>( pObj) != nullptr || DynCastE3dScene(pObj)))
190 if(ImpDelLayerCheck(pSubOL, nDelID))
192 if( bUndo )
193 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj, true));
194 pOL->RemoveObject(nObjNum);
196 else
198 ImpDelLayerDelObjs(pSubOL, nDelID);
201 else
203 if(pObj->GetLayer() == nDelID)
205 if( bUndo )
206 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj, true));
207 pOL->RemoveObject(nObjNum);
213 void SdrEditView::DeleteLayer(const OUString& rName)
215 SdrLayerAdmin& rLA = GetModel().GetLayerAdmin();
216 SdrLayer* pLayer = rLA.GetLayer(rName);
218 if(!pLayer)
219 return;
221 sal_uInt16 nLayerNum(rLA.GetLayerPos(pLayer));
222 SdrLayerID nDelID = pLayer->GetID();
224 const bool bUndo = IsUndoEnabled();
225 if( bUndo )
226 BegUndo(SvxResId(STR_UndoDelLayer));
228 bool bMaPg(true);
230 for(sal_uInt16 nPageKind(0); nPageKind < 2; nPageKind++)
232 // MasterPages and DrawPages
233 sal_uInt16 nPgCount(bMaPg ? GetModel().GetMasterPageCount() : GetModel().GetPageCount());
235 for(sal_uInt16 nPgNum(0); nPgNum < nPgCount; nPgNum++)
237 // over all pages
238 SdrPage* pPage = bMaPg ? GetModel().GetMasterPage(nPgNum) : GetModel().GetPage(nPgNum);
239 const size_t nObjCount(pPage->GetObjCount());
241 // make sure OrdNums are correct
242 if(nObjCount)
243 pPage->GetObj(0)->GetOrdNum();
245 for(size_t nObjNum(nObjCount); nObjNum > 0;)
247 nObjNum--;
248 SdrObject* pObj = pPage->GetObj(nObjNum);
249 SdrObjList* pSubOL = pObj->GetSubList();
251 // explicitly test for group objects and 3d scenes
252 if(pSubOL && (dynamic_cast<const SdrObjGroup*>(pObj) != nullptr || DynCastE3dScene(pObj)))
254 if(ImpDelLayerCheck(pSubOL, nDelID))
256 if( bUndo )
257 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj, true));
258 pPage->RemoveObject(nObjNum);
260 else
262 ImpDelLayerDelObjs(pSubOL, nDelID);
265 else
267 if(pObj->GetLayer() == nDelID)
269 if( bUndo )
270 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj, true));
271 pPage->RemoveObject(nObjNum);
276 bMaPg = false;
279 if( bUndo )
281 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteLayer(nLayerNum, rLA, GetModel()));
282 // coverity[leaked_storage] - ownership transferred to UndoDeleteLayer
283 rLA.RemoveLayer(nLayerNum).release();
284 EndUndo();
286 else
288 rLA.RemoveLayer(nLayerNum);
291 GetModel().SetChanged();
295 void SdrEditView::EndUndo()
297 // #i13033#
298 // Comparison changed to 1L since EndUndo() is called later now
299 // and EndUndo WILL change count to count-1
300 if(1 == GetModel().GetUndoBracketLevel())
302 ImpBroadcastEdgesOfMarkedNodes();
305 // #i13033#
306 // moved to bottom to still have access to UNDOs inside of
307 // ImpBroadcastEdgesOfMarkedNodes()
308 GetModel().EndUndo();
311 void SdrEditView::ImpBroadcastEdgesOfMarkedNodes()
313 std::vector<SdrObject*>::const_iterator iterPos;
314 const std::vector<SdrObject*>& rAllMarkedObjects = GetTransitiveHullOfMarkedObjects();
316 // #i13033#
317 // New mechanism to search for necessary disconnections for
318 // changed connectors inside the transitive hull of all at
319 // the beginning of UNDO selected objects
320 for(size_t a(0); a < rAllMarkedObjects.size(); a++)
322 SdrEdgeObj* pEdge = dynamic_cast<SdrEdgeObj*>( rAllMarkedObjects[a] );
324 if(pEdge)
326 SdrObject* pObj1 = pEdge->GetConnectedNode(false);
327 SdrObject* pObj2 = pEdge->GetConnectedNode(true);
329 if(pObj1 && !pEdge->CheckNodeConnection(false))
331 iterPos = std::find(rAllMarkedObjects.begin(),rAllMarkedObjects.end(),pObj1);
333 if (iterPos == rAllMarkedObjects.end())
335 if( IsUndoEnabled() )
336 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pEdge));
337 pEdge->DisconnectFromNode(false);
341 if(pObj2 && !pEdge->CheckNodeConnection(true))
343 iterPos = std::find(rAllMarkedObjects.begin(),rAllMarkedObjects.end(),pObj2);
345 if (iterPos == rAllMarkedObjects.end())
347 if( IsUndoEnabled() )
348 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pEdge));
349 pEdge->DisconnectFromNode(true);
355 const size_t nMarkedEdgeCnt = GetMarkedEdgesOfMarkedNodes().GetMarkCount();
357 for (size_t i=0; i<nMarkedEdgeCnt; ++i) {
358 SdrMark* pEM = GetMarkedEdgesOfMarkedNodes().GetMark(i);
359 SdrObject* pEdgeTmp=pEM->GetMarkedSdrObj();
360 SdrEdgeObj* pEdge=dynamic_cast<SdrEdgeObj*>( pEdgeTmp );
361 if (pEdge!=nullptr) {
362 pEdge->SetEdgeTrackDirty();
368 // Possibilities
371 void SdrEditView::MarkListHasChanged()
373 SdrMarkView::MarkListHasChanged();
374 m_bPossibilitiesDirty=true;
377 void SdrEditView::ModelHasChanged()
379 SdrMarkView::ModelHasChanged();
380 m_bPossibilitiesDirty=true;
383 bool SdrEditView::IsResizeAllowed(bool bProp) const
385 ForcePossibilities();
386 if (m_bResizeProtect) return false;
387 if (bProp) return m_bResizePropAllowed;
388 return m_bResizeFreeAllowed;
391 bool SdrEditView::IsRotateAllowed(bool b90Deg) const
393 ForcePossibilities();
394 if (m_bMoveProtect) return false;
395 if (b90Deg) return m_bRotate90Allowed;
396 return m_bRotateFreeAllowed;
399 bool SdrEditView::IsMirrorAllowed(bool b45Deg, bool b90Deg) const
401 ForcePossibilities();
402 if (m_bMoveProtect) return false;
403 if (b90Deg) return m_bMirror90Allowed;
404 if (b45Deg) return m_bMirror45Allowed;
405 return m_bMirrorFreeAllowed;
408 bool SdrEditView::IsTransparenceAllowed() const
410 ForcePossibilities();
411 return m_bTransparenceAllowed;
414 bool SdrEditView::IsCropAllowed() const
416 ForcePossibilities();
417 return m_bCropAllowed;
420 bool SdrEditView::IsGradientAllowed() const
422 ForcePossibilities();
423 return m_bGradientAllowed;
426 bool SdrEditView::IsShearAllowed() const
428 ForcePossibilities();
429 if (m_bResizeProtect) return false;
430 return m_bShearAllowed;
433 bool SdrEditView::IsEdgeRadiusAllowed() const
435 ForcePossibilities();
436 return m_bEdgeRadiusAllowed;
439 bool SdrEditView::IsCrookAllowed(bool bNoContortion) const
441 // CrookMode missing here (no rotations allowed when shearing ...)
442 ForcePossibilities();
443 if (bNoContortion) {
444 if (!m_bRotateFreeAllowed) return false;
445 return !m_bMoveProtect && m_bMoveAllowed;
446 } else {
447 return !m_bResizeProtect && m_bContortionPossible;
451 bool SdrEditView::IsDistortAllowed(bool bNoContortion) const
453 ForcePossibilities();
454 if (bNoContortion) {
455 return false;
456 } else {
457 return !m_bResizeProtect && m_bContortionPossible;
461 bool SdrEditView::IsCombinePossible(bool bNoPolyPoly) const
463 ForcePossibilities();
464 if (bNoPolyPoly) return m_bCombineNoPolyPolyPossible;
465 else return m_bCombinePossible;
468 bool SdrEditView::IsDismantlePossible(bool bMakeLines) const
470 ForcePossibilities();
471 if (bMakeLines) return m_bDismantleMakeLinesPossible;
472 else return m_bDismantlePossible;
475 void SdrEditView::CheckPossibilities()
477 if (mbSomeObjChgdFlag)
479 m_bPossibilitiesDirty = true;
481 // This call IS necessary to correct the MarkList, in which
482 // no longer to the model belonging objects still can reside.
483 // These ones need to be removed.
484 CheckMarked();
487 if (!m_bPossibilitiesDirty)
488 return;
490 ImpResetPossibilityFlags();
491 SortMarkedObjects();
492 const size_t nMarkCount = GetMarkedObjectCount();
493 if (nMarkCount != 0)
495 m_bReverseOrderPossible = (nMarkCount >= 2);
497 size_t nMovableCount=0;
498 m_bGroupPossible=nMarkCount>=2;
499 m_bCombinePossible=nMarkCount>=2;
500 if (nMarkCount==1)
502 // check bCombinePossible more thoroughly
503 // still missing ...
504 const SdrObject* pObj=GetMarkedObjectByIndex(0);
505 //const SdrPathObj* pPath=dynamic_cast<SdrPathObj*>( pObj );
506 bool bGroup=pObj->GetSubList()!=nullptr;
507 bool bHasText=pObj->GetOutlinerParaObject()!=nullptr;
508 if (bGroup || bHasText) {
509 m_bCombinePossible=true;
512 m_bCombineNoPolyPolyPossible=m_bCombinePossible;
513 // accept transformations for now
514 m_bMoveAllowed =true;
515 m_bResizeFreeAllowed=true;
516 m_bResizePropAllowed=true;
517 m_bRotateFreeAllowed=true;
518 m_bRotate90Allowed =true;
519 m_bMirrorFreeAllowed=true;
520 m_bMirror45Allowed =true;
521 m_bMirror90Allowed =true;
522 m_bShearAllowed =true;
523 m_bEdgeRadiusAllowed=false;
524 m_bContortionPossible=true;
525 m_bCanConvToContour = true;
527 // these ones are only allowed when single object is selected
528 m_bTransparenceAllowed = (nMarkCount == 1);
529 m_bGradientAllowed = (nMarkCount == 1);
530 m_bCropAllowed = (nMarkCount == 1);
531 if(m_bGradientAllowed)
533 // gradient depends on fill style
534 const SdrMark* pM = GetSdrMarkByIndex(0);
535 const SdrObject* pObj = pM->GetMarkedSdrObj();
537 // may be group object, so get merged ItemSet
538 const SfxItemSet& rSet = pObj->GetMergedItemSet();
539 SfxItemState eState = rSet.GetItemState(XATTR_FILLSTYLE, false);
541 if(SfxItemState::DONTCARE != eState)
543 // If state is not DONTCARE, test the item
544 drawing::FillStyle eFillStyle = rSet.Get(XATTR_FILLSTYLE).GetValue();
546 if(eFillStyle != drawing::FillStyle_GRADIENT)
548 m_bGradientAllowed = false;
553 bool bNoMovRotFound=false;
554 const SdrPageView* pPV0=nullptr;
556 for (size_t nm=0; nm<nMarkCount; ++nm) {
557 const SdrMark* pM=GetSdrMarkByIndex(nm);
558 const SdrObject* pObj=pM->GetMarkedSdrObj();
559 const SdrPageView* pPV=pM->GetPageView();
560 if (pPV!=pPV0) {
561 if (pPV->IsReadOnly()) m_bReadOnly=true;
562 pPV0=pPV;
565 SdrObjTransformInfoRec aInfo;
566 pObj->TakeObjInfo(aInfo);
567 bool bMovPrt=pObj->IsMoveProtect();
568 bool bSizPrt=pObj->IsResizeProtect();
569 if (!bMovPrt && aInfo.bMoveAllowed) nMovableCount++; // count MovableObjs
570 if (bMovPrt) m_bMoveProtect=true;
571 if (bSizPrt) m_bResizeProtect=true;
573 // not allowed when not allowed at one object
574 if(!aInfo.bTransparenceAllowed)
575 m_bTransparenceAllowed = false;
577 // If one of these can't do something, none can
578 if (!aInfo.bMoveAllowed ) m_bMoveAllowed =false;
579 if (!aInfo.bResizeFreeAllowed) m_bResizeFreeAllowed=false;
580 if (!aInfo.bResizePropAllowed) m_bResizePropAllowed=false;
581 if (!aInfo.bRotateFreeAllowed) m_bRotateFreeAllowed=false;
582 if (!aInfo.bRotate90Allowed ) m_bRotate90Allowed =false;
583 if (!aInfo.bMirrorFreeAllowed) m_bMirrorFreeAllowed=false;
584 if (!aInfo.bMirror45Allowed ) m_bMirror45Allowed =false;
585 if (!aInfo.bMirror90Allowed ) m_bMirror90Allowed =false;
586 if (!aInfo.bShearAllowed ) m_bShearAllowed =false;
587 if (aInfo.bEdgeRadiusAllowed) m_bEdgeRadiusAllowed=true;
588 if (aInfo.bNoContortion ) m_bContortionPossible=false;
589 // For Crook with Contortion: all objects have to be
590 // Movable and Rotatable, except for a maximum of 1 of them
591 if (!m_bMoreThanOneNoMovRot) {
592 if (!aInfo.bMoveAllowed || !aInfo.bResizeFreeAllowed) {
593 m_bMoreThanOneNoMovRot=bNoMovRotFound;
594 bNoMovRotFound=true;
598 // Must be resizable to allow cropping
599 if (!aInfo.bResizeFreeAllowed && !aInfo.bResizePropAllowed)
600 m_bCropAllowed = false;
602 // if one member cannot be converted, no conversion is possible
603 if(!aInfo.bCanConvToContour)
604 m_bCanConvToContour = false;
606 // Ungroup
607 if (!m_bUnGroupPossible) m_bUnGroupPossible=pObj->GetSubList()!=nullptr;
608 // ConvertToCurve: If at least one can be converted, that is fine.
609 if (aInfo.bCanConvToPath ) m_bCanConvToPath =true;
610 if (aInfo.bCanConvToPoly ) m_bCanConvToPoly =true;
612 // Combine/Dismantle
613 if(m_bCombinePossible)
615 m_bCombinePossible = ImpCanConvertForCombine(pObj);
616 m_bCombineNoPolyPolyPossible = m_bCombinePossible;
619 if (!m_bDismantlePossible) m_bDismantlePossible = ImpCanDismantle(pObj, false);
620 if (!m_bDismantleMakeLinesPossible) m_bDismantleMakeLinesPossible = ImpCanDismantle(pObj, true);
621 // check OrthoDesiredOnMarked
622 if (!m_bOrthoDesiredOnMarked && !aInfo.bNoOrthoDesired) m_bOrthoDesiredOnMarked=true;
623 // check ImportMtf
625 if (!m_bImportMtfPossible)
627 const SdrGrafObj* pSdrGrafObj = dynamic_cast< const SdrGrafObj* >(pObj);
628 if (pSdrGrafObj != nullptr)
630 if ((pSdrGrafObj->HasGDIMetaFile() && !pSdrGrafObj->IsEPS()) ||
631 pSdrGrafObj->isEmbeddedVectorGraphicData())
633 m_bImportMtfPossible = true;
637 const SdrOle2Obj* pSdrOle2Obj = dynamic_cast< const SdrOle2Obj* >(pObj);
638 if (pSdrOle2Obj)
640 m_bImportMtfPossible = pSdrOle2Obj->GetObjRef().is();
645 m_bOneOrMoreMovable=nMovableCount!=0;
646 m_bGrpEnterPossible=m_bUnGroupPossible;
648 ImpCheckToTopBtmPossible();
649 static_cast<SdrPolyEditView*>(this)->ImpCheckPolyPossibilities();
650 m_bPossibilitiesDirty=false;
652 if (m_bReadOnly) {
653 bool bTemp=m_bGrpEnterPossible;
654 ImpResetPossibilityFlags();
655 m_bReadOnly=true;
656 m_bGrpEnterPossible=bTemp;
658 if (!m_bMoveAllowed) return;
660 // Don't allow moving glued connectors.
661 // Currently only implemented for single selection.
662 if (nMarkCount==1) {
663 SdrObject* pObj=GetMarkedObjectByIndex(0);
664 SdrEdgeObj* pEdge=dynamic_cast<SdrEdgeObj*>( pObj );
665 if (pEdge!=nullptr) {
666 SdrObject* pNode1=pEdge->GetConnectedNode(true);
667 SdrObject* pNode2=pEdge->GetConnectedNode(false);
668 if (pNode1!=nullptr || pNode2!=nullptr) m_bMoveAllowed=false;
672 // Don't allow enter Diagrams
673 if (1 == nMarkCount && m_bGrpEnterPossible)
675 SdrObject* pCandidate(GetMarkedObjectByIndex(0));
677 if(nullptr != pCandidate && pCandidate->isDiagram())
678 m_bGrpEnterPossible = false;
683 void SdrEditView::ForceMarkedObjToAnotherPage()
685 bool bFlg=false;
686 for (size_t nm=0; nm<GetMarkedObjectCount(); ++nm) {
687 SdrMark* pM=GetSdrMarkByIndex(nm);
688 SdrObject* pObj=pM->GetMarkedSdrObj();
689 tools::Rectangle aObjRect(pObj->GetCurrentBoundRect());
690 tools::Rectangle aPgRect(pM->GetPageView()->GetPageRect());
691 if (!aObjRect.Overlaps(aPgRect)) {
692 bool bFnd=false;
693 SdrPageView* pPV = GetSdrPageView();
695 if(pPV)
697 bFnd = aObjRect.Overlaps(pPV->GetPageRect());
700 if(bFnd)
702 pM->GetPageView()->GetObjList()->RemoveObject(pObj->GetOrdNum());
703 pPV->GetObjList()->InsertObject(pObj, SAL_MAX_SIZE);
704 pM->SetPageView(pPV);
705 InvalidateAllWin(aObjRect);
706 bFlg=true;
710 if (bFlg) {
711 MarkListHasChanged();
715 std::vector<rtl::Reference<SdrObject>> SdrEditView::DeleteMarkedList(SdrMarkList const& rMark)
717 std::vector<rtl::Reference<SdrObject>> ret;
718 if (rMark.GetMarkCount()!=0)
720 rMark.ForceSort();
722 const bool bUndo = IsUndoEnabled();
723 if( bUndo )
724 BegUndo();
725 const size_t nMarkCount(rMark.GetMarkCount());
727 if(nMarkCount)
729 std::vector< E3DModifySceneSnapRectUpdater* > aUpdaters;
731 if( bUndo )
733 for(size_t nm = nMarkCount; nm > 0;)
735 --nm;
736 SdrMark* pM = rMark.GetMark(nm);
737 SdrObject* pObj = pM->GetMarkedSdrObj();
739 // extra undo actions for changed connector which now may hold its laid out path (SJ)
740 AddUndoActions(CreateConnectorUndo( *pObj ));
742 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
746 // make sure, OrderNums are correct:
747 rMark.GetMark(0)->GetMarkedSdrObj()->GetOrdNum();
749 for(size_t nm = nMarkCount; nm > 0;)
751 --nm;
752 SdrMark* pM = rMark.GetMark(nm);
753 SdrObject* pObj = pM->GetMarkedSdrObj();
754 SdrObjList* pOL = pObj->getParentSdrObjListFromSdrObject();
755 const size_t nOrdNum(pObj->GetOrdNumDirect());
757 bool bIs3D = DynCastE3dObject(pObj);
758 // set up a scene updater if object is a 3d object
759 if(bIs3D)
761 aUpdaters.push_back(new E3DModifySceneSnapRectUpdater(pObj));
764 if( !bUndo )
766 // tdf#108863 and tdf#108889 don't delete objects before EndUndo()
767 ret.push_back(pObj);
770 pOL->RemoveObject(nOrdNum);
773 // fire scene updaters
774 while(!aUpdaters.empty())
776 delete aUpdaters.back();
777 aUpdaters.pop_back();
781 if( bUndo )
782 EndUndo();
784 return ret;
787 static void lcl_LazyDelete(std::vector<rtl::Reference<SdrObject>> & rLazyDelete)
789 // now delete removed scene objects
790 while (!rLazyDelete.empty())
791 rLazyDelete.pop_back();
794 void SdrEditView::DeleteMarkedObj()
796 // #i110981# return when nothing is to be done at all
797 if(!GetMarkedObjectCount())
799 return;
802 // moved breaking action and undo start outside loop
803 BrkAction();
804 BegUndo(SvxResId(STR_EditDelete),GetDescriptionOfMarkedObjects(),SdrRepeatFunc::Delete);
806 std::vector<rtl::Reference<SdrObject>> lazyDeleteObjects;
807 // remove as long as something is selected. This allows to schedule objects for
808 // removal for a next run as needed
809 while(GetMarkedObjectCount())
811 // vector to remember the parents which may be empty after object removal
812 std::vector< SdrObject* > aParents;
815 const SdrMarkList& rMarkList = GetMarkedObjectList();
816 const size_t nCount(rMarkList.GetMarkCount());
818 for(size_t a = 0; a < nCount; ++a)
820 // in the first run, add all found parents, but only once
821 SdrMark* pMark(rMarkList.GetMark(a));
822 SdrObject* pObject(pMark->GetMarkedSdrObj());
823 SdrObject* pParent(pObject->getParentSdrObjectFromSdrObject());
825 if(pParent)
827 if(!aParents.empty())
829 std::vector< SdrObject* >::iterator aFindResult =
830 std::find(aParents.begin(), aParents.end(), pParent);
832 if(aFindResult == aParents.end())
834 aParents.push_back(pParent);
837 else
839 aParents.push_back(pParent);
844 if(!aParents.empty())
846 // in a 2nd run, remove all objects which may already be scheduled for
847 // removal. I am not sure if this can happen, but theoretically
848 // a to-be-removed object may already be the group/3DScene itself
849 for(size_t a = 0; a < nCount; ++a)
851 SdrMark* pMark = rMarkList.GetMark(a);
852 SdrObject* pObject = pMark->GetMarkedSdrObj();
854 std::vector< SdrObject* >::iterator aFindResult =
855 std::find(aParents.begin(), aParents.end(), pObject);
857 if(aFindResult != aParents.end())
859 aParents.erase(aFindResult);
865 // original stuff: remove selected objects. Handle clear will
866 // do something only once
867 auto temp(DeleteMarkedList(GetMarkedObjectList()));
868 lazyDeleteObjects.insert(lazyDeleteObjects.end(), temp.begin(), temp.end());
869 GetMarkedObjectListWriteAccess().Clear();
870 maHdlList.Clear();
872 while(!aParents.empty() && !GetMarkedObjectCount())
874 // iterate over remembered parents
875 SdrObject* pParent = aParents.back();
876 aParents.pop_back();
878 if(pParent->GetSubList() && 0 == pParent->GetSubList()->GetObjCount())
880 // we detected an empty parent, a candidate to leave group/3DScene
881 // if entered
882 if(GetSdrPageView()->GetCurrentGroup()
883 && GetSdrPageView()->GetCurrentGroup() == pParent)
885 GetSdrPageView()->LeaveOneGroup();
888 // schedule empty parent for removal
889 GetMarkedObjectListWriteAccess().InsertEntry(
890 SdrMark(pParent, GetSdrPageView()));
895 // end undo and change messaging moved at the end
896 EndUndo();
897 MarkListHasChanged();
899 lcl_LazyDelete(lazyDeleteObjects);
902 void SdrEditView::CopyMarkedObj()
904 SortMarkedObjects();
906 SdrMarkList aSourceObjectsForCopy(GetMarkedObjectList());
907 // The following loop is used instead of MarkList::Merge(), to be
908 // able to flag the MarkEntries.
909 const size_t nEdgeCnt = GetEdgesOfMarkedNodes().GetMarkCount();
910 for (size_t nEdgeNum=0; nEdgeNum<nEdgeCnt; ++nEdgeNum) {
911 SdrMark aM(*GetEdgesOfMarkedNodes().GetMark(nEdgeNum));
912 aM.SetUser(1);
913 aSourceObjectsForCopy.InsertEntry(aM);
915 aSourceObjectsForCopy.ForceSort();
917 // #i13033#
918 // New mechanism to re-create the connections of cloned connectors
919 CloneList aCloneList;
921 const bool bUndo = IsUndoEnabled();
923 GetMarkedObjectListWriteAccess().Clear();
924 size_t nCloneErrCnt=0;
925 std::unordered_set<rtl::OUString> aNameSet;
926 const size_t nMarkCount=aSourceObjectsForCopy.GetMarkCount();
927 for (size_t nm=0; nm<nMarkCount; ++nm) {
928 SdrMark* pM=aSourceObjectsForCopy.GetMark(nm);
929 SdrObject* pSource(pM->GetMarkedSdrObj());
930 rtl::Reference<SdrObject> pO(pSource->CloneSdrObject(pSource->getSdrModelFromSdrObject()));
931 if (pO!=nullptr) {
932 pM->GetPageView()->GetObjList()->InsertObjectThenMakeNameUnique(pO.get(), aNameSet);
934 if( bUndo )
935 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoCopyObject(*pO));
937 SdrMark aME(*pM);
938 aME.SetMarkedSdrObj(pO.get());
939 aCloneList.AddPair(pM->GetMarkedSdrObj(), pO.get());
941 if (pM->GetUser()==0)
943 // otherwise it is only an Edge we have to copy as well
944 GetMarkedObjectListWriteAccess().InsertEntry(aME);
946 } else {
947 nCloneErrCnt++;
951 // #i13033#
952 // New mechanism to re-create the connections of cloned connectors
953 aCloneList.CopyConnections();
955 if(nCloneErrCnt)
957 #ifdef DBG_UTIL
958 OStringBuffer aStr("SdrEditView::CopyMarkedObj(): Error when cloning ");
960 if(nCloneErrCnt == 1)
962 aStr.append("a drawing object.");
964 else
966 aStr.append(OString::number(static_cast<sal_Int32>(nCloneErrCnt))
967 + " drawing objects.");
970 aStr.append(" This object's/These objects's connections will not be copied.");
971 OSL_FAIL(aStr.getStr());
972 #endif
974 MarkListHasChanged();
978 bool SdrEditView::InsertObjectAtView(SdrObject* pObj, SdrPageView& rPV, SdrInsertFlags nOptions)
980 if (nOptions & SdrInsertFlags::SETDEFLAYER) {
981 SdrLayerID nLayer=rPV.GetPage()->GetLayerAdmin().GetLayerID(maActualLayer);
982 if (nLayer==SDRLAYER_NOTFOUND) nLayer=SdrLayerID(0);
983 if (rPV.GetLockedLayers().IsSet(nLayer) || !rPV.GetVisibleLayers().IsSet(nLayer)) {
984 return false;
986 pObj->NbcSetLayer(nLayer);
988 if (nOptions & SdrInsertFlags::SETDEFATTR) {
989 if (mpDefaultStyleSheet!=nullptr) pObj->NbcSetStyleSheet(mpDefaultStyleSheet, false);
990 pObj->SetMergedItemSet(maDefaultAttr);
992 if (!pObj->IsInserted()) {
993 rPV.GetObjList()->InsertObject(pObj, SAL_MAX_SIZE);
995 if( IsUndoEnabled())
997 bool bDontDeleteReally = true;
998 EndTextEditCurrentView(bDontDeleteReally);
999 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoNewObject(*pObj));
1002 css::uno::Reference<lang::XServiceInfo> xServices(GetModel().getUnoModel(),
1003 css::uno::UNO_QUERY);
1004 if (xServices.is() && (xServices->supportsService("com.sun.star.sheet.SpreadsheetDocument") ||
1005 xServices->supportsService("com.sun.star.text.TextDocument")))
1007 const bool bUndo(IsUndoEnabled());
1008 GetModel().EnableUndo(false);
1009 pObj->MakeNameUnique();
1010 GetModel().EnableUndo(bUndo);
1013 if (!(nOptions & SdrInsertFlags::DONTMARK)) {
1014 if (!(nOptions & SdrInsertFlags::ADDMARK)) UnmarkAllObj();
1015 MarkObj(pObj,&rPV);
1017 return true;
1020 void SdrEditView::ReplaceObjectAtView(SdrObject* pOldObj, SdrPageView& rPV, SdrObject* pNewObj, bool bMark)
1022 if(IsTextEdit())
1024 #ifdef DBG_UTIL
1025 if(auto pTextObj = DynCastSdrTextObj(pOldObj))
1026 if (pTextObj->IsTextEditActive())
1027 OSL_ENSURE(false, "OldObject is in TextEdit mode, this has to be ended before replacing it using SdrEndTextEdit (!)");
1029 if(auto pTextObj = DynCastSdrTextObj(pNewObj))
1030 if (pTextObj->IsTextEditActive())
1031 OSL_ENSURE(false, "NewObject is in TextEdit mode, this has to be ended before replacing it using SdrEndTextEdit (!)");
1032 #endif
1034 // #i123468# emergency repair situation, needs to cast up to a class derived from
1035 // this one; (aw080 has a mechanism for that and the view hierarchy is secured to
1036 // always be a SdrView)
1037 SdrView *pSdrView = dynamic_cast<SdrView*>(this);
1038 if (pSdrView)
1039 pSdrView->SdrEndTextEdit();
1042 SdrObjList* pOL=pOldObj->getParentSdrObjListFromSdrObject();
1043 const bool bUndo = IsUndoEnabled();
1044 if( bUndo )
1045 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoReplaceObject(*pOldObj,*pNewObj));
1047 if( IsObjMarked( pOldObj ) )
1048 MarkObj( pOldObj, &rPV, true /*unmark!*/ );
1050 pOL->ReplaceObject(pNewObj,pOldObj->GetOrdNum());
1052 if (bMark) MarkObj(pNewObj,&rPV);
1056 bool SdrEditView::IsUndoEnabled() const
1058 return GetModel().IsUndoEnabled();
1061 void SdrEditView::EndTextEditAllViews() const
1063 size_t nViews = GetModel().GetListenerCount();
1064 for (size_t nView = 0; nView < nViews; ++nView)
1066 SdrObjEditView* pView = dynamic_cast<SdrObjEditView*>(GetModel().GetListener(nView));
1067 if (!pView)
1068 continue;
1070 if (pView->IsTextEdit())
1071 pView->SdrEndTextEdit();
1075 void SdrEditView::EndTextEditCurrentView(bool bDontDeleteReally)
1077 if (IsTextEdit())
1079 SdrView* pSdrView = dynamic_cast<SdrView*>(this);
1080 if (pSdrView)
1081 pSdrView->SdrEndTextEdit(bDontDeleteReally);
1085 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */