nss: upgrade to release 3.73
[LibreOffice.git] / svx / source / svdraw / clonelist.cxx
blob12f395ac1d4b8afbaf71dc7a7ed2f0c96a4e3957
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 .
21 // #i13033#
22 // New mechanism to hold a list of all original and cloned objects for later
23 // re-creating the connections for contained connectors
24 #include <clonelist.hxx>
25 #include <svx/svdoedge.hxx>
26 #include <svx/scene3d.hxx>
28 void CloneList::AddPair(const SdrObject* pOriginal, SdrObject* pClone)
30 maOriginalList.push_back(pOriginal);
31 maCloneList.push_back(pClone);
33 // look for subobjects, too.
34 bool bOriginalIsGroup(pOriginal->IsGroupObject());
35 bool bCloneIsGroup(pClone->IsGroupObject());
37 if(bOriginalIsGroup && dynamic_cast<const E3dObject* >(pOriginal) != nullptr && dynamic_cast<const E3dScene* >(pOriginal) == nullptr )
38 bOriginalIsGroup = false;
40 if(bCloneIsGroup && dynamic_cast<const E3dObject* >(pClone) != nullptr && dynamic_cast<const E3dScene* >(pClone) == nullptr)
41 bCloneIsGroup = false;
43 if(!(bOriginalIsGroup && bCloneIsGroup))
44 return;
46 const SdrObjList* pOriginalList = pOriginal->GetSubList();
47 SdrObjList* pCloneList = pClone->GetSubList();
49 if(pOriginalList && pCloneList
50 && pOriginalList->GetObjCount() == pCloneList->GetObjCount())
52 for(size_t a = 0; a < pOriginalList->GetObjCount(); ++a)
54 // recursive call
55 AddPair(pOriginalList->GetObj(a), pCloneList->GetObj(a));
60 const SdrObject* CloneList::GetOriginal(sal_uInt32 nIndex) const
62 return maOriginalList[nIndex];
65 SdrObject* CloneList::GetClone(sal_uInt32 nIndex) const
67 return maCloneList[nIndex];
70 void CloneList::CopyConnections() const
72 sal_uInt32 cloneCount = maCloneList.size();
74 for(size_t a = 0; a < maOriginalList.size(); a++)
76 const SdrEdgeObj* pOriginalEdge = dynamic_cast<const SdrEdgeObj*>( GetOriginal(a) );
77 SdrEdgeObj* pCloneEdge = dynamic_cast<SdrEdgeObj*>( GetClone(a) );
79 if(pOriginalEdge && pCloneEdge)
81 SdrObject* pOriginalNode1 = pOriginalEdge->GetConnectedNode(true);
82 SdrObject* pOriginalNode2 = pOriginalEdge->GetConnectedNode(false);
84 if(pOriginalNode1)
86 std::vector<const SdrObject*>::const_iterator it = std::find(maOriginalList.begin(),
87 maOriginalList.end(),
88 pOriginalNode1);
90 sal_uInt32 nPos = it - maOriginalList.begin();
92 if(it != maOriginalList.end())
94 SdrObject *cObj = nullptr;
96 if (nPos < cloneCount)
97 cObj = GetClone(nPos);
99 if(pOriginalEdge->GetConnectedNode(true) != cObj)
100 pCloneEdge->ConnectToNode(true, cObj);
104 if(pOriginalNode2)
106 std::vector<const SdrObject*>::const_iterator it = std::find(maOriginalList.begin(),
107 maOriginalList.end(),
108 pOriginalNode2);
110 sal_uInt32 nPos = it - maOriginalList.begin();
112 if(it != maOriginalList.end())
114 SdrObject *cObj = nullptr;
116 if (nPos < cloneCount)
117 cObj = GetClone(nPos);
119 if(pOriginalEdge->GetConnectedNode(false) != cObj)
120 pCloneEdge->ConnectToNode(false, cObj);
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */