1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26
27 // #i13033#
28 // New mechanism to hold a list of all original and cloned objects for later
29 // re-creating the connections for contained connectors
30 #include <clonelist.hxx>
31 #include <svx/svdoedge.hxx>
32 #include <svx/scene3d.hxx>
33
CloneList()34 CloneList::CloneList()
35 {
36 }
37
~CloneList()38 CloneList::~CloneList()
39 {
40 }
41
AddPair(const SdrObject * pOriginal,SdrObject * pClone)42 void CloneList::AddPair(const SdrObject* pOriginal, SdrObject* pClone)
43 {
44 maOriginalList.Insert((SdrObject*)pOriginal, LIST_APPEND);
45 maCloneList.Insert(pClone, LIST_APPEND);
46
47 // look for subobjects, too.
48 sal_Bool bOriginalIsGroup(pOriginal->IsGroupObject());
49 sal_Bool bCloneIsGroup(pClone->IsGroupObject());
50
51 if(bOriginalIsGroup && pOriginal->ISA(E3dObject) && !pOriginal->ISA(E3dScene))
52 bOriginalIsGroup = sal_False;
53
54 if(bCloneIsGroup && pClone->ISA(E3dObject) && !pClone->ISA(E3dScene))
55 bCloneIsGroup = sal_False;
56
57 if(bOriginalIsGroup && bCloneIsGroup)
58 {
59 const SdrObjList* pOriginalList = pOriginal->GetSubList();
60 SdrObjList* pCloneList = pClone->GetSubList();
61
62 if(pOriginalList && pCloneList
63 && pOriginalList->GetObjCount() == pCloneList->GetObjCount())
64 {
65 for(sal_uInt32 a(0); a < pOriginalList->GetObjCount(); a++)
66 {
67 // recursive call
68 AddPair(pOriginalList->GetObj(a), pCloneList->GetObj(a));
69 }
70 }
71 }
72 }
73
Count() const74 sal_uInt32 CloneList::Count() const
75 {
76 return maOriginalList.Count();
77 }
78
GetOriginal(sal_uInt32 nIndex) const79 const SdrObject* CloneList::GetOriginal(sal_uInt32 nIndex) const
80 {
81 return (SdrObject*)maOriginalList.GetObject(nIndex);
82 }
83
GetClone(sal_uInt32 nIndex) const84 SdrObject* CloneList::GetClone(sal_uInt32 nIndex) const
85 {
86 return (SdrObject*)maCloneList.GetObject(nIndex);
87 }
88
CopyConnections() const89 void CloneList::CopyConnections() const
90 {
91 for(sal_uInt32 a(0); a < maOriginalList.Count(); a++)
92 {
93 const SdrEdgeObj* pOriginalEdge = PTR_CAST(SdrEdgeObj, GetOriginal(a));
94 SdrEdgeObj* pCloneEdge = PTR_CAST(SdrEdgeObj, GetClone(a));
95
96 if(pOriginalEdge && pCloneEdge)
97 {
98 SdrObject* pOriginalNode1 = pOriginalEdge->GetConnectedNode(sal_True);
99 SdrObject* pOriginalNode2 = pOriginalEdge->GetConnectedNode(sal_False);
100
101 if(pOriginalNode1)
102 {
103 sal_uLong nPos(maOriginalList.GetPos(pOriginalNode1));
104
105 if(LIST_ENTRY_NOTFOUND != nPos)
106 {
107 if(pOriginalEdge->GetConnectedNode(sal_True) != GetClone(nPos))
108 {
109 pCloneEdge->ConnectToNode(sal_True, GetClone(nPos));
110 }
111 }
112 }
113
114 if(pOriginalNode2)
115 {
116 sal_uLong nPos(maOriginalList.GetPos(pOriginalNode2));
117
118 if(LIST_ENTRY_NOTFOUND != nPos)
119 {
120 if(pOriginalEdge->GetConnectedNode(sal_False) != GetClone(nPos))
121 {
122 pCloneEdge->ConnectToNode(sal_False, GetClone(nPos));
123 }
124 }
125 }
126 }
127 }
128 }
129
130 /* vim: set noet sw=4 ts=4: */
131