Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / svdraw / clonelist.cxx
blobabc736acb10ebde27c639028432e48833e65bb6f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // #i13033#
31 // New mechanism to hold a ist of all original and cloned objects for later
32 // re-creating the connections for contained connectors
33 #include <clonelist.hxx>
34 #include <svx/svdoedge.hxx>
35 #include <svx/scene3d.hxx>
37 void CloneList::AddPair(const SdrObject* pOriginal, SdrObject* pClone)
39 maOriginalList.push_back(pOriginal);
40 maCloneList.push_back(pClone);
42 // look for subobjects, too.
43 sal_Bool bOriginalIsGroup(pOriginal->IsGroupObject());
44 sal_Bool bCloneIsGroup(pClone->IsGroupObject());
46 if(bOriginalIsGroup && pOriginal->ISA(E3dObject) && !pOriginal->ISA(E3dScene))
47 bOriginalIsGroup = sal_False;
49 if(bCloneIsGroup && pClone->ISA(E3dObject) && !pClone->ISA(E3dScene))
50 bCloneIsGroup = sal_False;
52 if(bOriginalIsGroup && bCloneIsGroup)
54 const SdrObjList* pOriginalList = pOriginal->GetSubList();
55 SdrObjList* pCloneList = pClone->GetSubList();
57 if(pOriginalList && pCloneList
58 && pOriginalList->GetObjCount() == pCloneList->GetObjCount())
60 for(sal_uInt32 a(0); a < pOriginalList->GetObjCount(); a++)
62 // recursive call
63 AddPair(pOriginalList->GetObj(a), pCloneList->GetObj(a));
69 const SdrObject* CloneList::GetOriginal(sal_uInt32 nIndex) const
71 return maOriginalList[nIndex];
74 SdrObject* CloneList::GetClone(sal_uInt32 nIndex) const
76 return maCloneList[nIndex];
79 void CloneList::CopyConnections() const
81 sal_uInt32 cloneCount = maCloneList.size();
83 for(sal_uInt32 a = 0; a < maOriginalList.size(); a++)
85 const SdrEdgeObj* pOriginalEdge = PTR_CAST(SdrEdgeObj, GetOriginal(a));
86 SdrEdgeObj* pCloneEdge = PTR_CAST(SdrEdgeObj, GetClone(a));
88 if(pOriginalEdge && pCloneEdge)
90 SdrObject* pOriginalNode1 = pOriginalEdge->GetConnectedNode(sal_True);
91 SdrObject* pOriginalNode2 = pOriginalEdge->GetConnectedNode(sal_False);
93 if(pOriginalNode1)
95 std::vector<const SdrObject*>::const_iterator it = std::find(maOriginalList.begin(),
96 maOriginalList.end(),
97 pOriginalNode1);
99 sal_uInt32 nPos = it - maOriginalList.begin();
101 if(it != maOriginalList.end())
103 SdrObject *cObj = NULL;
105 if (nPos < cloneCount)
106 cObj = GetClone(nPos);
108 if(pOriginalEdge->GetConnectedNode(sal_True) != cObj)
109 pCloneEdge->ConnectToNode(sal_True, cObj);
113 if(pOriginalNode2)
115 std::vector<const SdrObject*>::const_iterator it = std::find(maOriginalList.begin(),
116 maOriginalList.end(),
117 pOriginalNode2);
119 sal_uInt32 nPos = it - maOriginalList.begin();
121 if(it != maOriginalList.end())
123 SdrObject *cObj = NULL;
125 if (nPos < cloneCount)
126 cObj = GetClone(nPos);
128 if(pOriginalEdge->GetConnectedNode(sal_False) != cObj)
129 pCloneEdge->ConnectToNode(sal_False, cObj);
136 // eof
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */