1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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()
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)
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
146 for(size_t nObjNum
= pOL
->GetObjCount(); nObjNum
> 0 && bDelAll
;)
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
))
162 if(pObj
->GetLayer() != nDelID
)
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;)
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
))
193 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj
, true));
194 pOL
->RemoveObject(nObjNum
);
198 ImpDelLayerDelObjs(pSubOL
, nDelID
);
203 if(pObj
->GetLayer() == nDelID
)
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
);
221 sal_uInt16
nLayerNum(rLA
.GetLayerPos(pLayer
));
222 SdrLayerID nDelID
= pLayer
->GetID();
224 const bool bUndo
= IsUndoEnabled();
226 BegUndo(SvxResId(STR_UndoDelLayer
));
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
++)
238 SdrPage
* pPage
= bMaPg
? GetModel().GetMasterPage(nPgNum
) : GetModel().GetPage(nPgNum
);
239 const size_t nObjCount(pPage
->GetObjCount());
241 // make sure OrdNums are correct
243 pPage
->GetObj(0)->GetOrdNum();
245 for(size_t nObjNum(nObjCount
); nObjNum
> 0;)
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
))
257 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj
, true));
258 pPage
->RemoveObject(nObjNum
);
262 ImpDelLayerDelObjs(pSubOL
, nDelID
);
267 if(pObj
->GetLayer() == nDelID
)
270 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj
, true));
271 pPage
->RemoveObject(nObjNum
);
281 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteLayer(nLayerNum
, rLA
, GetModel()));
282 // coverity[leaked_storage] - ownership transferred to UndoDeleteLayer
283 rLA
.RemoveLayer(nLayerNum
).release();
288 rLA
.RemoveLayer(nLayerNum
);
291 GetModel().SetChanged();
295 void SdrEditView::EndUndo()
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();
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();
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
] );
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();
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();
444 if (!m_bRotateFreeAllowed
) return false;
445 return !m_bMoveProtect
&& m_bMoveAllowed
;
447 return !m_bResizeProtect
&& m_bContortionPossible
;
451 bool SdrEditView::IsDistortAllowed(bool bNoContortion
) const
453 ForcePossibilities();
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.
487 if (!m_bPossibilitiesDirty
)
490 ImpResetPossibilityFlags();
492 const size_t nMarkCount
= GetMarkedObjectCount();
495 m_bReverseOrderPossible
= (nMarkCount
>= 2);
497 size_t nMovableCount
=0;
498 m_bGroupPossible
=nMarkCount
>=2;
499 m_bCombinePossible
=nMarkCount
>=2;
502 // check bCombinePossible more thoroughly
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();
561 if (pPV
->IsReadOnly()) m_bReadOnly
=true;
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
;
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;
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;
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;
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
);
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;
653 bool bTemp
=m_bGrpEnterPossible
;
654 ImpResetPossibilityFlags();
656 m_bGrpEnterPossible
=bTemp
;
658 if (!m_bMoveAllowed
) return;
660 // Don't allow moving glued connectors.
661 // Currently only implemented for single selection.
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()
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
)) {
693 SdrPageView
* pPV
= GetSdrPageView();
697 bFnd
= aObjRect
.Overlaps(pPV
->GetPageRect());
702 pM
->GetPageView()->GetObjList()->RemoveObject(pObj
->GetOrdNum());
703 pPV
->GetObjList()->InsertObject(pObj
, SAL_MAX_SIZE
);
704 pM
->SetPageView(pPV
);
705 InvalidateAllWin(aObjRect
);
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)
722 const bool bUndo
= IsUndoEnabled();
725 const size_t nMarkCount(rMark
.GetMarkCount());
729 std::vector
< E3DModifySceneSnapRectUpdater
* > aUpdaters
;
733 for(size_t nm
= nMarkCount
; nm
> 0;)
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;)
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
761 aUpdaters
.push_back(new E3DModifySceneSnapRectUpdater(pObj
));
766 // tdf#108863 and tdf#108889 don't delete objects before EndUndo()
770 pOL
->RemoveObject(nOrdNum
);
773 // fire scene updaters
774 while(!aUpdaters
.empty())
776 delete aUpdaters
.back();
777 aUpdaters
.pop_back();
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())
802 // moved breaking action and undo start outside loop
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());
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
);
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();
872 while(!aParents
.empty() && !GetMarkedObjectCount())
874 // iterate over remembered parents
875 SdrObject
* pParent
= aParents
.back();
878 if(pParent
->GetSubList() && 0 == pParent
->GetSubList()->GetObjCount())
880 // we detected an empty parent, a candidate to leave group/3DScene
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
897 MarkListHasChanged();
899 lcl_LazyDelete(lazyDeleteObjects
);
902 void SdrEditView::CopyMarkedObj()
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
));
913 aSourceObjectsForCopy
.InsertEntry(aM
);
915 aSourceObjectsForCopy
.ForceSort();
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()));
932 pM
->GetPageView()->GetObjList()->InsertObjectThenMakeNameUnique(pO
.get(), aNameSet
);
935 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoCopyObject(*pO
));
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
);
952 // New mechanism to re-create the connections of cloned connectors
953 aCloneList
.CopyConnections();
958 OStringBuffer
aStr("SdrEditView::CopyMarkedObj(): Error when cloning ");
960 if(nCloneErrCnt
== 1)
962 aStr
.append("a drawing object.");
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());
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
)) {
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
);
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();
1020 void SdrEditView::ReplaceObjectAtView(SdrObject
* pOldObj
, SdrPageView
& rPV
, SdrObject
* pNewObj
, bool bMark
)
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 (!)");
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);
1039 pSdrView
->SdrEndTextEdit();
1042 SdrObjList
* pOL
=pOldObj
->getParentSdrObjListFromSdrObject();
1043 const bool bUndo
= IsUndoEnabled();
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
));
1070 if (pView
->IsTextEdit())
1071 pView
->SdrEndTextEdit();
1075 void SdrEditView::EndTextEditCurrentView(bool bDontDeleteReally
)
1079 SdrView
* pSdrView
= dynamic_cast<SdrView
*>(this);
1081 pSdrView
->SdrEndTextEdit(bDontDeleteReally
);
1085 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */