1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: clonelist.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
35 // New mechanism to hold a ist of all original and cloned objects for later
36 // re-creating the connections for contained connectors
37 #include <clonelist.hxx>
38 #include <svx/svdoedge.hxx>
39 #include <svx/scene3d.hxx>
41 CloneList::CloneList()
45 CloneList::~CloneList()
49 void CloneList::AddPair(const SdrObject
* pOriginal
, SdrObject
* pClone
)
51 maOriginalList
.Insert((SdrObject
*)pOriginal
, LIST_APPEND
);
52 maCloneList
.Insert(pClone
, LIST_APPEND
);
54 // look for subobjects, too.
55 sal_Bool
bOriginalIsGroup(pOriginal
->IsGroupObject());
56 sal_Bool
bCloneIsGroup(pClone
->IsGroupObject());
58 if(bOriginalIsGroup
&& pOriginal
->ISA(E3dObject
) && !pOriginal
->ISA(E3dScene
))
59 bOriginalIsGroup
= sal_False
;
61 if(bCloneIsGroup
&& pClone
->ISA(E3dObject
) && !pClone
->ISA(E3dScene
))
62 bCloneIsGroup
= sal_False
;
64 if(bOriginalIsGroup
&& bCloneIsGroup
)
66 const SdrObjList
* pOriginalList
= pOriginal
->GetSubList();
67 SdrObjList
* pCloneList
= pClone
->GetSubList();
69 if(pOriginalList
&& pCloneList
70 && pOriginalList
->GetObjCount() == pCloneList
->GetObjCount())
72 for(sal_uInt32
a(0); a
< pOriginalList
->GetObjCount(); a
++)
75 AddPair(pOriginalList
->GetObj(a
), pCloneList
->GetObj(a
));
81 sal_uInt32
CloneList::Count() const
83 return maOriginalList
.Count();
86 const SdrObject
* CloneList::GetOriginal(sal_uInt32 nIndex
) const
88 return (SdrObject
*)maOriginalList
.GetObject(nIndex
);
91 SdrObject
* CloneList::GetClone(sal_uInt32 nIndex
) const
93 return (SdrObject
*)maCloneList
.GetObject(nIndex
);
96 void CloneList::CopyConnections() const
98 for(sal_uInt32
a(0); a
< maOriginalList
.Count(); a
++)
100 const SdrEdgeObj
* pOriginalEdge
= PTR_CAST(SdrEdgeObj
, GetOriginal(a
));
101 SdrEdgeObj
* pCloneEdge
= PTR_CAST(SdrEdgeObj
, GetClone(a
));
103 if(pOriginalEdge
&& pCloneEdge
)
105 SdrObject
* pOriginalNode1
= pOriginalEdge
->GetConnectedNode(sal_True
);
106 SdrObject
* pOriginalNode2
= pOriginalEdge
->GetConnectedNode(sal_False
);
110 ULONG
nPos(maOriginalList
.GetPos(pOriginalNode1
));
112 if(LIST_ENTRY_NOTFOUND
!= nPos
)
114 if(pOriginalEdge
->GetConnectedNode(sal_True
) != GetClone(nPos
))
116 pCloneEdge
->ConnectToNode(sal_True
, GetClone(nPos
));
123 ULONG
nPos(maOriginalList
.GetPos(pOriginalNode2
));
125 if(LIST_ENTRY_NOTFOUND
!= nPos
)
127 if(pOriginalEdge
->GetConnectedNode(sal_False
) != GetClone(nPos
))
129 pCloneEdge
->ConnectToNode(sal_False
, GetClone(nPos
));