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 .
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/svdpage.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
&& DynCastE3dObject(pOriginal
) != nullptr && DynCastE3dScene(pOriginal
) == nullptr )
38 bOriginalIsGroup
= false;
40 if(bCloneIsGroup
&& DynCastE3dObject(pClone
) != nullptr && DynCastE3dScene(pClone
) == nullptr)
41 bCloneIsGroup
= false;
43 if(!(bOriginalIsGroup
&& bCloneIsGroup
))
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
)
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 for (bool bTail1
: { true, false })
83 SdrObject
* pOriginalNode
= pOriginalEdge
->GetConnectedNode(bTail1
);
86 std::vector
<const SdrObject
*>::const_iterator it
= std::find(maOriginalList
.begin(),
90 if(it
!= maOriginalList
.end())
92 sal_uInt32 nPos
= it
- maOriginalList
.begin();
93 SdrObject
*cObj
= nullptr;
95 if (nPos
< cloneCount
)
96 cObj
= GetClone(nPos
);
98 if(pOriginalNode
!= cObj
)
99 pCloneEdge
->ConnectToNode(bTail1
, cObj
);
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */