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>
39 #include <sfx2/viewsh.hxx>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
43 using namespace com::sun::star
;
45 void SdrEditView::ImpResetPossibilityFlags()
49 m_bGroupPossible
=false;
50 m_bUnGroupPossible
=false;
51 m_bGrpEnterPossible
=false;
52 m_bToTopPossible
=false;
53 m_bToBtmPossible
=false;
54 m_bReverseOrderPossible
=false;
56 m_bImportMtfPossible
=false;
57 m_bCombinePossible
=false;
58 m_bDismantlePossible
=false;
59 m_bCombineNoPolyPolyPossible
=false;
60 m_bDismantleMakeLinesPossible
=false;
61 m_bOrthoDesiredOnMarked
=false;
63 m_bOneOrMoreMovable
=false;
64 m_bMoreThanOneNoMovRot
=false;
65 m_bContortionPossible
=false;
66 m_bMoveAllowed
=false;
67 m_bResizeFreeAllowed
=false;
68 m_bResizePropAllowed
=false;
69 m_bRotateFreeAllowed
=false;
70 m_bRotate90Allowed
=false;
71 m_bMirrorFreeAllowed
=false;
72 m_bMirror45Allowed
=false;
73 m_bMirror90Allowed
=false;
74 m_bTransparenceAllowed
=false;
75 m_bCropAllowed
=false;
76 m_bGradientAllowed
=false;
77 m_bShearAllowed
=false;
78 m_bEdgeRadiusAllowed
=false;
79 m_bCanConvToPath
=false;
80 m_bCanConvToPoly
=false;
81 m_bCanConvToContour
=false;
82 m_bMoveProtect
=false;
83 m_bResizeProtect
=false;
86 SdrEditView::SdrEditView(SdrModel
& rSdrModel
, OutputDevice
* pOut
)
87 : SdrMarkView(rSdrModel
, pOut
)
88 , m_bPossibilitiesDirty(true)
90 , m_bGroupPossible(false)
91 , m_bUnGroupPossible(false)
92 , m_bGrpEnterPossible(false)
93 , m_bToTopPossible(false)
94 , m_bToBtmPossible(false)
95 , m_bReverseOrderPossible(false)
96 , m_bImportMtfPossible(false)
97 , m_bCombinePossible(false)
98 , m_bDismantlePossible(false)
99 , m_bCombineNoPolyPolyPossible(false)
100 , m_bDismantleMakeLinesPossible(false)
101 , m_bOrthoDesiredOnMarked(false)
102 , m_bOneOrMoreMovable(false)
103 , m_bMoreThanOneNoMovRot(false)
104 , m_bContortionPossible(false)
105 , m_bMoveAllowed(false)
106 , m_bResizeFreeAllowed(false)
107 , m_bResizePropAllowed(false)
108 , m_bRotateFreeAllowed(false)
109 , m_bRotate90Allowed(false)
110 , m_bMirrorFreeAllowed(false)
111 , m_bMirror45Allowed(false)
112 , m_bMirror90Allowed(false)
113 , m_bShearAllowed(false)
114 , m_bEdgeRadiusAllowed(false)
115 , m_bTransparenceAllowed(false)
116 , m_bCropAllowed(false)
117 , m_bGradientAllowed(false)
118 , m_bCanConvToPath(false)
119 , m_bCanConvToPoly(false)
120 , m_bCanConvToContour(false)
121 , m_bMoveProtect(false)
122 , m_bResizeProtect(false)
126 SdrEditView::~SdrEditView()
130 void SdrEditView::InsertNewLayer(const OUString
& rName
, sal_uInt16 nPos
)
132 SdrLayerAdmin
& rLA
= GetModel().GetLayerAdmin();
133 sal_uInt16 nMax
=rLA
.GetLayerCount();
134 if (nPos
>nMax
) nPos
=nMax
;
135 rLA
.NewLayer(rName
,nPos
);
137 if( GetModel().IsUndoEnabled() )
138 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoNewLayer(nPos
,rLA
, GetModel()));
140 GetModel().SetChanged();
143 bool SdrEditView::ImpDelLayerCheck(SdrObjList
const * pOL
, SdrLayerID nDelID
) const
147 for(size_t nObjNum
= pOL
->GetObjCount(); nObjNum
> 0 && bDelAll
;)
150 SdrObject
* pObj
= pOL
->GetObj(nObjNum
);
151 SdrObjList
* pSubOL
= pObj
->GetSubList();
153 // explicitly test for group objects and 3d scenes
154 if(pSubOL
&& (dynamic_cast<const SdrObjGroup
*>(pObj
) != nullptr || DynCastE3dScene(pObj
)))
156 if(!ImpDelLayerCheck(pSubOL
, nDelID
))
163 if(pObj
->GetLayer() != nDelID
)
173 void SdrEditView::ImpDelLayerDelObjs(SdrObjList
* pOL
, SdrLayerID nDelID
)
175 const size_t nObjCount(pOL
->GetObjCount());
176 // make sure OrdNums are correct
177 pOL
->GetObj(0)->GetOrdNum();
179 const bool bUndo
= GetModel().IsUndoEnabled();
181 for(size_t nObjNum
= nObjCount
; nObjNum
> 0;)
184 SdrObject
* pObj
= pOL
->GetObj(nObjNum
);
185 SdrObjList
* pSubOL
= pObj
->GetSubList();
188 // explicitly test for group objects and 3d scenes
189 if(pSubOL
&& (dynamic_cast<const SdrObjGroup
*>( pObj
) != nullptr || DynCastE3dScene(pObj
)))
191 if(ImpDelLayerCheck(pSubOL
, nDelID
))
194 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj
, true));
195 pOL
->RemoveObject(nObjNum
);
199 ImpDelLayerDelObjs(pSubOL
, nDelID
);
204 if(pObj
->GetLayer() == nDelID
)
207 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj
, true));
208 pOL
->RemoveObject(nObjNum
);
214 void SdrEditView::DeleteLayer(const OUString
& rName
)
216 SdrLayerAdmin
& rLA
= GetModel().GetLayerAdmin();
217 SdrLayer
* pLayer
= rLA
.GetLayer(rName
);
222 sal_uInt16
nLayerNum(rLA
.GetLayerPos(pLayer
));
223 SdrLayerID nDelID
= pLayer
->GetID();
225 const bool bUndo
= IsUndoEnabled();
227 BegUndo(SvxResId(STR_UndoDelLayer
));
231 for(sal_uInt16
nPageKind(0); nPageKind
< 2; nPageKind
++)
233 // MasterPages and DrawPages
234 sal_uInt16
nPgCount(bMaPg
? GetModel().GetMasterPageCount() : GetModel().GetPageCount());
236 for(sal_uInt16
nPgNum(0); nPgNum
< nPgCount
; nPgNum
++)
239 SdrPage
* pPage
= bMaPg
? GetModel().GetMasterPage(nPgNum
) : GetModel().GetPage(nPgNum
);
240 const size_t nObjCount(pPage
->GetObjCount());
242 // make sure OrdNums are correct
244 pPage
->GetObj(0)->GetOrdNum();
246 for(size_t nObjNum(nObjCount
); nObjNum
> 0;)
249 SdrObject
* pObj
= pPage
->GetObj(nObjNum
);
250 SdrObjList
* pSubOL
= pObj
->GetSubList();
252 // explicitly test for group objects and 3d scenes
253 if(pSubOL
&& (dynamic_cast<const SdrObjGroup
*>(pObj
) != nullptr || DynCastE3dScene(pObj
)))
255 if(ImpDelLayerCheck(pSubOL
, nDelID
))
258 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj
, true));
259 pPage
->RemoveObject(nObjNum
);
263 ImpDelLayerDelObjs(pSubOL
, nDelID
);
268 if(pObj
->GetLayer() == nDelID
)
271 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj
, true));
272 pPage
->RemoveObject(nObjNum
);
282 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteLayer(nLayerNum
, rLA
, GetModel()));
283 // coverity[leaked_storage] - ownership transferred to UndoDeleteLayer
284 rLA
.RemoveLayer(nLayerNum
).release();
289 rLA
.RemoveLayer(nLayerNum
);
292 GetModel().SetChanged();
296 void SdrEditView::EndUndo()
299 // Comparison changed to 1L since EndUndo() is called later now
300 // and EndUndo WILL change count to count-1
301 if(1 == GetModel().GetUndoBracketLevel())
303 ImpBroadcastEdgesOfMarkedNodes();
307 // moved to bottom to still have access to UNDOs inside of
308 // ImpBroadcastEdgesOfMarkedNodes()
309 GetModel().EndUndo();
312 void SdrEditView::ImpBroadcastEdgesOfMarkedNodes()
314 std::vector
<SdrObject
*>::const_iterator iterPos
;
315 const std::vector
<SdrObject
*>& rAllMarkedObjects
= GetTransitiveHullOfMarkedObjects();
318 // New mechanism to search for necessary disconnections for
319 // changed connectors inside the transitive hull of all at
320 // the beginning of UNDO selected objects
321 for(size_t a(0); a
< rAllMarkedObjects
.size(); a
++)
323 SdrEdgeObj
* pEdge
= dynamic_cast<SdrEdgeObj
*>( rAllMarkedObjects
[a
] );
327 SdrObject
* pObj1
= pEdge
->GetConnectedNode(false);
328 SdrObject
* pObj2
= pEdge
->GetConnectedNode(true);
330 if(pObj1
&& !pEdge
->CheckNodeConnection(false))
332 iterPos
= std::find(rAllMarkedObjects
.begin(),rAllMarkedObjects
.end(),pObj1
);
334 if (iterPos
== rAllMarkedObjects
.end())
336 if( IsUndoEnabled() )
337 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pEdge
));
338 pEdge
->DisconnectFromNode(false);
342 if(pObj2
&& !pEdge
->CheckNodeConnection(true))
344 iterPos
= std::find(rAllMarkedObjects
.begin(),rAllMarkedObjects
.end(),pObj2
);
346 if (iterPos
== rAllMarkedObjects
.end())
348 if( IsUndoEnabled() )
349 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pEdge
));
350 pEdge
->DisconnectFromNode(true);
356 const size_t nMarkedEdgeCnt
= GetMarkedEdgesOfMarkedNodes().GetMarkCount();
358 for (size_t i
=0; i
<nMarkedEdgeCnt
; ++i
) {
359 SdrMark
* pEM
= GetMarkedEdgesOfMarkedNodes().GetMark(i
);
360 SdrObject
* pEdgeTmp
=pEM
->GetMarkedSdrObj();
361 SdrEdgeObj
* pEdge
=dynamic_cast<SdrEdgeObj
*>( pEdgeTmp
);
362 if (pEdge
!=nullptr) {
363 pEdge
->SetEdgeTrackDirty();
372 void SdrEditView::MarkListHasChanged()
374 SdrMarkView::MarkListHasChanged();
375 m_bPossibilitiesDirty
=true;
378 void SdrEditView::ModelHasChanged()
380 SdrMarkView::ModelHasChanged();
381 m_bPossibilitiesDirty
=true;
384 bool SdrEditView::IsResizeAllowed(bool bProp
) const
386 ForcePossibilities();
387 if (m_bResizeProtect
) return false;
388 if (bProp
) return m_bResizePropAllowed
;
389 return m_bResizeFreeAllowed
;
392 bool SdrEditView::IsRotateAllowed(bool b90Deg
) const
394 ForcePossibilities();
395 if (m_bMoveProtect
) return false;
396 if (b90Deg
) return m_bRotate90Allowed
;
397 return m_bRotateFreeAllowed
;
400 bool SdrEditView::IsMirrorAllowed(bool b45Deg
, bool b90Deg
) const
402 ForcePossibilities();
403 if (m_bMoveProtect
) return false;
404 if (b90Deg
) return m_bMirror90Allowed
;
405 if (b45Deg
) return m_bMirror45Allowed
;
406 return m_bMirrorFreeAllowed
;
409 bool SdrEditView::IsTransparenceAllowed() const
411 ForcePossibilities();
412 return m_bTransparenceAllowed
;
415 bool SdrEditView::IsCropAllowed() const
417 ForcePossibilities();
418 return m_bCropAllowed
;
421 bool SdrEditView::IsGradientAllowed() const
423 ForcePossibilities();
424 return m_bGradientAllowed
;
427 bool SdrEditView::IsShearAllowed() const
429 ForcePossibilities();
430 if (m_bResizeProtect
) return false;
431 return m_bShearAllowed
;
434 bool SdrEditView::IsEdgeRadiusAllowed() const
436 ForcePossibilities();
437 return m_bEdgeRadiusAllowed
;
440 bool SdrEditView::IsCrookAllowed(bool bNoContortion
) const
442 // CrookMode missing here (no rotations allowed when shearing ...)
443 ForcePossibilities();
445 if (!m_bRotateFreeAllowed
) return false;
446 return !m_bMoveProtect
&& m_bMoveAllowed
;
448 return !m_bResizeProtect
&& m_bContortionPossible
;
452 bool SdrEditView::IsDistortAllowed(bool bNoContortion
) const
454 ForcePossibilities();
458 return !m_bResizeProtect
&& m_bContortionPossible
;
462 bool SdrEditView::IsCombinePossible(bool bNoPolyPoly
) const
464 ForcePossibilities();
465 if (bNoPolyPoly
) return m_bCombineNoPolyPolyPossible
;
466 else return m_bCombinePossible
;
469 bool SdrEditView::IsDismantlePossible(bool bMakeLines
) const
471 ForcePossibilities();
472 if (bMakeLines
) return m_bDismantleMakeLinesPossible
;
473 else return m_bDismantlePossible
;
476 void SdrEditView::CheckPossibilities()
478 if (mbSomeObjChgdFlag
)
480 m_bPossibilitiesDirty
= true;
482 // This call IS necessary to correct the MarkList, in which
483 // no longer to the model belonging objects still can reside.
484 // These ones need to be removed.
488 if (!m_bPossibilitiesDirty
)
491 ImpResetPossibilityFlags();
493 const size_t nMarkCount
= GetMarkedObjectCount();
496 m_bReverseOrderPossible
= (nMarkCount
>= 2);
498 size_t nMovableCount
=0;
499 m_bGroupPossible
=nMarkCount
>=2;
500 m_bCombinePossible
=nMarkCount
>=2;
503 // check bCombinePossible more thoroughly
505 const SdrObject
* pObj
=GetMarkedObjectByIndex(0);
506 //const SdrPathObj* pPath=dynamic_cast<SdrPathObj*>( pObj );
507 bool bGroup
=pObj
->GetSubList()!=nullptr;
508 bool bHasText
=pObj
->GetOutlinerParaObject()!=nullptr;
509 if (bGroup
|| bHasText
) {
510 m_bCombinePossible
=true;
513 m_bCombineNoPolyPolyPossible
=m_bCombinePossible
;
514 // accept transformations for now
515 m_bMoveAllowed
=true;
516 m_bResizeFreeAllowed
=true;
517 m_bResizePropAllowed
=true;
518 m_bRotateFreeAllowed
=true;
519 m_bRotate90Allowed
=true;
520 m_bMirrorFreeAllowed
=true;
521 m_bMirror45Allowed
=true;
522 m_bMirror90Allowed
=true;
523 m_bShearAllowed
=true;
524 m_bEdgeRadiusAllowed
=false;
525 m_bContortionPossible
=true;
526 m_bCanConvToContour
= true;
528 // these ones are only allowed when single object is selected
529 m_bTransparenceAllowed
= (nMarkCount
== 1);
530 m_bGradientAllowed
= (nMarkCount
== 1);
531 m_bCropAllowed
= (nMarkCount
== 1);
532 if(m_bGradientAllowed
)
534 // gradient depends on fill style
535 const SdrMark
* pM
= GetSdrMarkByIndex(0);
536 const SdrObject
* pObj
= pM
->GetMarkedSdrObj();
538 // may be group object, so get merged ItemSet
539 const SfxItemSet
& rSet
= pObj
->GetMergedItemSet();
540 SfxItemState eState
= rSet
.GetItemState(XATTR_FILLSTYLE
, false);
542 if(SfxItemState::DONTCARE
!= eState
)
544 // If state is not DONTCARE, test the item
545 drawing::FillStyle eFillStyle
= rSet
.Get(XATTR_FILLSTYLE
).GetValue();
547 if(eFillStyle
!= drawing::FillStyle_GRADIENT
)
549 m_bGradientAllowed
= false;
554 bool bNoMovRotFound
=false;
555 const SdrPageView
* pPV0
=nullptr;
557 for (size_t nm
=0; nm
<nMarkCount
; ++nm
) {
558 const SdrMark
* pM
=GetSdrMarkByIndex(nm
);
559 const SdrObject
* pObj
=pM
->GetMarkedSdrObj();
560 const SdrPageView
* pPV
=pM
->GetPageView();
562 if (pPV
->IsReadOnly()) m_bReadOnly
=true;
566 SdrObjTransformInfoRec aInfo
;
567 pObj
->TakeObjInfo(aInfo
);
568 bool bMovPrt
=pObj
->IsMoveProtect();
569 bool bSizPrt
=pObj
->IsResizeProtect();
570 if (!bMovPrt
&& aInfo
.bMoveAllowed
) nMovableCount
++; // count MovableObjs
571 if (bMovPrt
) m_bMoveProtect
=true;
572 if (bSizPrt
) m_bResizeProtect
=true;
574 // not allowed when not allowed at one object
575 if(!aInfo
.bTransparenceAllowed
)
576 m_bTransparenceAllowed
= false;
578 // If one of these can't do something, none can
579 if (!aInfo
.bMoveAllowed
) m_bMoveAllowed
=false;
580 if (!aInfo
.bResizeFreeAllowed
) m_bResizeFreeAllowed
=false;
581 if (!aInfo
.bResizePropAllowed
) m_bResizePropAllowed
=false;
582 if (!aInfo
.bRotateFreeAllowed
) m_bRotateFreeAllowed
=false;
583 if (!aInfo
.bRotate90Allowed
) m_bRotate90Allowed
=false;
584 if (!aInfo
.bMirrorFreeAllowed
) m_bMirrorFreeAllowed
=false;
585 if (!aInfo
.bMirror45Allowed
) m_bMirror45Allowed
=false;
586 if (!aInfo
.bMirror90Allowed
) m_bMirror90Allowed
=false;
587 if (!aInfo
.bShearAllowed
) m_bShearAllowed
=false;
588 if (aInfo
.bEdgeRadiusAllowed
) m_bEdgeRadiusAllowed
=true;
589 if (aInfo
.bNoContortion
) m_bContortionPossible
=false;
590 // For Crook with Contortion: all objects have to be
591 // Movable and Rotatable, except for a maximum of 1 of them
592 if (!m_bMoreThanOneNoMovRot
) {
593 if (!aInfo
.bMoveAllowed
|| !aInfo
.bResizeFreeAllowed
) {
594 m_bMoreThanOneNoMovRot
=bNoMovRotFound
;
599 // Must be resizable to allow cropping
600 if (!aInfo
.bResizeFreeAllowed
&& !aInfo
.bResizePropAllowed
)
601 m_bCropAllowed
= false;
603 // if one member cannot be converted, no conversion is possible
604 if(!aInfo
.bCanConvToContour
)
605 m_bCanConvToContour
= false;
608 if (!m_bUnGroupPossible
) m_bUnGroupPossible
=pObj
->GetSubList()!=nullptr;
609 // ConvertToCurve: If at least one can be converted, that is fine.
610 if (aInfo
.bCanConvToPath
) m_bCanConvToPath
=true;
611 if (aInfo
.bCanConvToPoly
) m_bCanConvToPoly
=true;
614 if(m_bCombinePossible
)
616 m_bCombinePossible
= ImpCanConvertForCombine(pObj
);
617 m_bCombineNoPolyPolyPossible
= m_bCombinePossible
;
620 if (!m_bDismantlePossible
) m_bDismantlePossible
= ImpCanDismantle(pObj
, false);
621 if (!m_bDismantleMakeLinesPossible
) m_bDismantleMakeLinesPossible
= ImpCanDismantle(pObj
, true);
622 // check OrthoDesiredOnMarked
623 if (!m_bOrthoDesiredOnMarked
&& !aInfo
.bNoOrthoDesired
) m_bOrthoDesiredOnMarked
=true;
626 if (!m_bImportMtfPossible
)
628 const SdrGrafObj
* pSdrGrafObj
= dynamic_cast< const SdrGrafObj
* >(pObj
);
629 if (pSdrGrafObj
!= nullptr)
631 if ((pSdrGrafObj
->HasGDIMetaFile() && !pSdrGrafObj
->IsEPS()) ||
632 pSdrGrafObj
->isEmbeddedVectorGraphicData())
634 m_bImportMtfPossible
= true;
638 const SdrOle2Obj
* pSdrOle2Obj
= dynamic_cast< const SdrOle2Obj
* >(pObj
);
641 m_bImportMtfPossible
= pSdrOle2Obj
->GetObjRef().is();
646 m_bOneOrMoreMovable
=nMovableCount
!=0;
647 m_bGrpEnterPossible
=m_bUnGroupPossible
;
649 ImpCheckToTopBtmPossible();
650 static_cast<SdrPolyEditView
*>(this)->ImpCheckPolyPossibilities();
651 m_bPossibilitiesDirty
=false;
653 if (m_bReadOnly
|| SfxViewShell::IsCurrentLokViewReadOnly() ) {
654 bool bTemp
=m_bGrpEnterPossible
;
655 ImpResetPossibilityFlags();
657 m_bGrpEnterPossible
=bTemp
;
659 if (!m_bMoveAllowed
) return;
661 // Don't allow moving glued connectors.
662 // Currently only implemented for single selection.
664 SdrObject
* pObj
=GetMarkedObjectByIndex(0);
665 SdrEdgeObj
* pEdge
=dynamic_cast<SdrEdgeObj
*>( pObj
);
666 if (pEdge
!=nullptr) {
667 SdrObject
* pNode1
=pEdge
->GetConnectedNode(true);
668 SdrObject
* pNode2
=pEdge
->GetConnectedNode(false);
669 if (pNode1
!=nullptr || pNode2
!=nullptr) m_bMoveAllowed
=false;
673 // Don't allow enter Diagrams
674 if (1 == nMarkCount
&& m_bGrpEnterPossible
)
676 SdrObject
* pCandidate(GetMarkedObjectByIndex(0));
678 if(nullptr != pCandidate
&& pCandidate
->isDiagram())
679 m_bGrpEnterPossible
= false;
684 void SdrEditView::ForceMarkedObjToAnotherPage()
687 for (size_t nm
=0; nm
<GetMarkedObjectCount(); ++nm
) {
688 SdrMark
* pM
=GetSdrMarkByIndex(nm
);
689 SdrObject
* pObj
=pM
->GetMarkedSdrObj();
690 tools::Rectangle
aObjRect(pObj
->GetCurrentBoundRect());
691 tools::Rectangle
aPgRect(pM
->GetPageView()->GetPageRect());
692 if (!aObjRect
.Overlaps(aPgRect
)) {
694 SdrPageView
* pPV
= GetSdrPageView();
698 bFnd
= aObjRect
.Overlaps(pPV
->GetPageRect());
703 pM
->GetPageView()->GetObjList()->RemoveObject(pObj
->GetOrdNum());
704 pPV
->GetObjList()->InsertObject(pObj
, SAL_MAX_SIZE
);
705 pM
->SetPageView(pPV
);
706 InvalidateAllWin(aObjRect
);
712 MarkListHasChanged();
716 std::vector
<rtl::Reference
<SdrObject
>> SdrEditView::DeleteMarkedList(SdrMarkList
const& rMark
)
718 std::vector
<rtl::Reference
<SdrObject
>> ret
;
719 if (rMark
.GetMarkCount()!=0)
723 const bool bUndo
= IsUndoEnabled();
726 const size_t nMarkCount(rMark
.GetMarkCount());
730 std::vector
< E3DModifySceneSnapRectUpdater
* > aUpdaters
;
734 for(size_t nm
= nMarkCount
; nm
> 0;)
737 SdrMark
* pM
= rMark
.GetMark(nm
);
738 SdrObject
* pObj
= pM
->GetMarkedSdrObj();
740 // extra undo actions for changed connector which now may hold its laid out path (SJ)
741 AddUndoActions(CreateConnectorUndo( *pObj
));
743 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj
));
747 // make sure, OrderNums are correct:
748 rMark
.GetMark(0)->GetMarkedSdrObj()->GetOrdNum();
750 for(size_t nm
= nMarkCount
; nm
> 0;)
753 SdrMark
* pM
= rMark
.GetMark(nm
);
754 SdrObject
* pObj
= pM
->GetMarkedSdrObj();
755 SdrObjList
* pOL
= pObj
->getParentSdrObjListFromSdrObject();
756 const size_t nOrdNum(pObj
->GetOrdNumDirect());
758 bool bIs3D
= DynCastE3dObject(pObj
);
759 // set up a scene updater if object is a 3d object
762 aUpdaters
.push_back(new E3DModifySceneSnapRectUpdater(pObj
));
767 // tdf#108863 and tdf#108889 don't delete objects before EndUndo()
771 pOL
->RemoveObject(nOrdNum
);
774 // fire scene updaters
775 while(!aUpdaters
.empty())
777 delete aUpdaters
.back();
778 aUpdaters
.pop_back();
788 static void lcl_LazyDelete(std::vector
<rtl::Reference
<SdrObject
>> & rLazyDelete
)
790 // now delete removed scene objects
791 while (!rLazyDelete
.empty())
792 rLazyDelete
.pop_back();
795 void SdrEditView::DeleteMarkedObj()
797 // #i110981# return when nothing is to be done at all
798 if(!GetMarkedObjectCount())
803 // moved breaking action and undo start outside loop
805 BegUndo(SvxResId(STR_EditDelete
),GetDescriptionOfMarkedObjects(),SdrRepeatFunc::Delete
);
807 std::vector
<rtl::Reference
<SdrObject
>> lazyDeleteObjects
;
808 // remove as long as something is selected. This allows to schedule objects for
809 // removal for a next run as needed
810 while(GetMarkedObjectCount())
812 // vector to remember the parents which may be empty after object removal
813 std::vector
< SdrObject
* > aParents
;
816 const SdrMarkList
& rMarkList
= GetMarkedObjectList();
817 const size_t nCount(rMarkList
.GetMarkCount());
819 for(size_t a
= 0; a
< nCount
; ++a
)
821 // in the first run, add all found parents, but only once
822 SdrMark
* pMark(rMarkList
.GetMark(a
));
823 SdrObject
* pObject(pMark
->GetMarkedSdrObj());
824 SdrObject
* pParent(pObject
->getParentSdrObjectFromSdrObject());
828 if(!aParents
.empty())
830 std::vector
< SdrObject
* >::iterator aFindResult
=
831 std::find(aParents
.begin(), aParents
.end(), pParent
);
833 if(aFindResult
== aParents
.end())
835 aParents
.push_back(pParent
);
840 aParents
.push_back(pParent
);
845 if(!aParents
.empty())
847 // in a 2nd run, remove all objects which may already be scheduled for
848 // removal. I am not sure if this can happen, but theoretically
849 // a to-be-removed object may already be the group/3DScene itself
850 for(size_t a
= 0; a
< nCount
; ++a
)
852 SdrMark
* pMark
= rMarkList
.GetMark(a
);
853 SdrObject
* pObject
= pMark
->GetMarkedSdrObj();
855 std::vector
< SdrObject
* >::iterator aFindResult
=
856 std::find(aParents
.begin(), aParents
.end(), pObject
);
858 if(aFindResult
!= aParents
.end())
860 aParents
.erase(aFindResult
);
866 // original stuff: remove selected objects. Handle clear will
867 // do something only once
868 auto temp(DeleteMarkedList(GetMarkedObjectList()));
869 lazyDeleteObjects
.insert(lazyDeleteObjects
.end(), temp
.begin(), temp
.end());
870 GetMarkedObjectListWriteAccess().Clear();
873 while(!aParents
.empty() && !GetMarkedObjectCount())
875 // iterate over remembered parents
876 SdrObject
* pParent
= aParents
.back();
879 if(pParent
->GetSubList() && 0 == pParent
->GetSubList()->GetObjCount())
881 // we detected an empty parent, a candidate to leave group/3DScene
883 if(GetSdrPageView()->GetCurrentGroup()
884 && GetSdrPageView()->GetCurrentGroup() == pParent
)
886 GetSdrPageView()->LeaveOneGroup();
889 // schedule empty parent for removal
890 GetMarkedObjectListWriteAccess().InsertEntry(
891 SdrMark(pParent
, GetSdrPageView()));
896 // end undo and change messaging moved at the end
898 MarkListHasChanged();
900 lcl_LazyDelete(lazyDeleteObjects
);
903 void SdrEditView::CopyMarkedObj()
907 SdrMarkList
aSourceObjectsForCopy(GetMarkedObjectList());
908 // The following loop is used instead of MarkList::Merge(), to be
909 // able to flag the MarkEntries.
910 const size_t nEdgeCnt
= GetEdgesOfMarkedNodes().GetMarkCount();
911 for (size_t nEdgeNum
=0; nEdgeNum
<nEdgeCnt
; ++nEdgeNum
) {
912 SdrMark
aM(*GetEdgesOfMarkedNodes().GetMark(nEdgeNum
));
914 aSourceObjectsForCopy
.InsertEntry(aM
);
916 aSourceObjectsForCopy
.ForceSort();
919 // New mechanism to re-create the connections of cloned connectors
920 CloneList aCloneList
;
922 const bool bUndo
= IsUndoEnabled();
924 GetMarkedObjectListWriteAccess().Clear();
925 size_t nCloneErrCnt
=0;
926 std::unordered_set
<rtl::OUString
> aNameSet
;
927 const size_t nMarkCount
=aSourceObjectsForCopy
.GetMarkCount();
928 for (size_t nm
=0; nm
<nMarkCount
; ++nm
) {
929 SdrMark
* pM
=aSourceObjectsForCopy
.GetMark(nm
);
930 SdrObject
* pSource(pM
->GetMarkedSdrObj());
931 rtl::Reference
<SdrObject
> pO(pSource
->CloneSdrObject(pSource
->getSdrModelFromSdrObject()));
933 pM
->GetPageView()->GetObjList()->InsertObjectThenMakeNameUnique(pO
.get(), aNameSet
);
936 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoCopyObject(*pO
));
939 aME
.SetMarkedSdrObj(pO
.get());
940 aCloneList
.AddPair(pM
->GetMarkedSdrObj(), pO
.get());
942 if (pM
->GetUser()==0)
944 // otherwise it is only an Edge we have to copy as well
945 GetMarkedObjectListWriteAccess().InsertEntry(aME
);
953 // New mechanism to re-create the connections of cloned connectors
954 aCloneList
.CopyConnections();
959 OStringBuffer
aStr("SdrEditView::CopyMarkedObj(): Error when cloning ");
961 if(nCloneErrCnt
== 1)
963 aStr
.append("a drawing object.");
967 aStr
.append(OString::number(static_cast<sal_Int32
>(nCloneErrCnt
))
968 + " drawing objects.");
971 aStr
.append(" This object's/These objects's connections will not be copied.");
972 OSL_FAIL(aStr
.getStr());
975 MarkListHasChanged();
979 bool SdrEditView::InsertObjectAtView(SdrObject
* pObj
, SdrPageView
& rPV
, SdrInsertFlags nOptions
)
981 if (nOptions
& SdrInsertFlags::SETDEFLAYER
) {
982 SdrLayerID nLayer
=rPV
.GetPage()->GetLayerAdmin().GetLayerID(maActualLayer
);
983 if (nLayer
==SDRLAYER_NOTFOUND
) nLayer
=SdrLayerID(0);
984 if (rPV
.GetLockedLayers().IsSet(nLayer
) || !rPV
.GetVisibleLayers().IsSet(nLayer
)) {
987 pObj
->NbcSetLayer(nLayer
);
989 if (nOptions
& SdrInsertFlags::SETDEFATTR
) {
990 if (mpDefaultStyleSheet
!=nullptr) pObj
->NbcSetStyleSheet(mpDefaultStyleSheet
, false);
991 pObj
->SetMergedItemSet(maDefaultAttr
);
993 if (!pObj
->IsInserted()) {
994 rPV
.GetObjList()->InsertObject(pObj
, SAL_MAX_SIZE
);
997 css::uno::Reference
<lang::XServiceInfo
> xServices(GetModel().getUnoModel(),
998 css::uno::UNO_QUERY
);
999 if (xServices
.is() && (xServices
->supportsService("com.sun.star.sheet.SpreadsheetDocument") ||
1000 xServices
->supportsService("com.sun.star.text.TextDocument")))
1002 const bool bUndo(IsUndoEnabled());
1003 GetModel().EnableUndo(false);
1004 pObj
->MakeNameUnique();
1005 GetModel().EnableUndo(bUndo
);
1008 if( IsUndoEnabled())
1010 bool bDontDeleteReally
= true;
1011 EndTextEditCurrentView(bDontDeleteReally
);
1012 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoNewObject(*pObj
));
1015 if (!(nOptions
& SdrInsertFlags::DONTMARK
)) {
1016 if (!(nOptions
& SdrInsertFlags::ADDMARK
)) UnmarkAllObj();
1022 void SdrEditView::ReplaceObjectAtView(SdrObject
* pOldObj
, SdrPageView
& rPV
, SdrObject
* pNewObj
, bool bMark
)
1027 if(auto pTextObj
= DynCastSdrTextObj(pOldObj
))
1028 if (pTextObj
->IsTextEditActive())
1029 OSL_ENSURE(false, "OldObject is in TextEdit mode, this has to be ended before replacing it using SdrEndTextEdit (!)");
1031 if(auto pTextObj
= DynCastSdrTextObj(pNewObj
))
1032 if (pTextObj
->IsTextEditActive())
1033 OSL_ENSURE(false, "NewObject is in TextEdit mode, this has to be ended before replacing it using SdrEndTextEdit (!)");
1036 // #i123468# emergency repair situation, needs to cast up to a class derived from
1037 // this one; (aw080 has a mechanism for that and the view hierarchy is secured to
1038 // always be a SdrView)
1039 SdrView
*pSdrView
= dynamic_cast<SdrView
*>(this);
1041 pSdrView
->SdrEndTextEdit();
1044 SdrObjList
* pOL
=pOldObj
->getParentSdrObjListFromSdrObject();
1045 const bool bUndo
= IsUndoEnabled();
1047 AddUndo(GetModel().GetSdrUndoFactory().CreateUndoReplaceObject(*pOldObj
,*pNewObj
));
1049 if( IsObjMarked( pOldObj
) )
1050 MarkObj( pOldObj
, &rPV
, true /*unmark!*/ );
1052 pOL
->ReplaceObject(pNewObj
,pOldObj
->GetOrdNum());
1054 if (bMark
) MarkObj(pNewObj
,&rPV
);
1058 bool SdrEditView::IsUndoEnabled() const
1060 return GetModel().IsUndoEnabled();
1063 void SdrEditView::EndTextEditAllViews() const
1065 GetModel().ForAllListeners(
1066 [](SfxListener
* pListener
)
1068 SdrObjEditView
* pView
= dynamic_cast<SdrObjEditView
*>(pListener
);
1069 if (pView
&& pView
->IsTextEdit())
1070 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: */