Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : // #i13033#
22 : // New mechanism to hold a ist 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>
27 :
28 0 : void CloneList::AddPair(const SdrObject* pOriginal, SdrObject* pClone)
29 : {
30 0 : maOriginalList.push_back(pOriginal);
31 0 : maCloneList.push_back(pClone);
32 :
33 : // look for subobjects, too.
34 0 : bool bOriginalIsGroup(pOriginal->IsGroupObject());
35 0 : bool bCloneIsGroup(pClone->IsGroupObject());
36 :
37 0 : if(bOriginalIsGroup && pOriginal->ISA(E3dObject) && !pOriginal->ISA(E3dScene))
38 0 : bOriginalIsGroup = false;
39 :
40 0 : if(bCloneIsGroup && pClone->ISA(E3dObject) && !pClone->ISA(E3dScene))
41 0 : bCloneIsGroup = false;
42 :
43 0 : if(bOriginalIsGroup && bCloneIsGroup)
44 : {
45 0 : const SdrObjList* pOriginalList = pOriginal->GetSubList();
46 0 : SdrObjList* pCloneList = pClone->GetSubList();
47 :
48 0 : if(pOriginalList && pCloneList
49 0 : && pOriginalList->GetObjCount() == pCloneList->GetObjCount())
50 : {
51 0 : for(size_t a = 0; a < pOriginalList->GetObjCount(); ++a)
52 : {
53 : // recursive call
54 0 : AddPair(pOriginalList->GetObj(a), pCloneList->GetObj(a));
55 : }
56 : }
57 : }
58 0 : }
59 :
60 0 : const SdrObject* CloneList::GetOriginal(sal_uInt32 nIndex) const
61 : {
62 0 : return maOriginalList[nIndex];
63 : }
64 :
65 0 : SdrObject* CloneList::GetClone(sal_uInt32 nIndex) const
66 : {
67 0 : return maCloneList[nIndex];
68 : }
69 :
70 0 : void CloneList::CopyConnections() const
71 : {
72 0 : sal_uInt32 cloneCount = maCloneList.size();
73 :
74 0 : for(size_t a = 0; a < maOriginalList.size(); a++)
75 : {
76 0 : const SdrEdgeObj* pOriginalEdge = PTR_CAST(SdrEdgeObj, GetOriginal(a));
77 0 : SdrEdgeObj* pCloneEdge = PTR_CAST(SdrEdgeObj, GetClone(a));
78 :
79 0 : if(pOriginalEdge && pCloneEdge)
80 : {
81 0 : SdrObject* pOriginalNode1 = pOriginalEdge->GetConnectedNode(true);
82 0 : SdrObject* pOriginalNode2 = pOriginalEdge->GetConnectedNode(false);
83 :
84 0 : if(pOriginalNode1)
85 : {
86 : std::vector<const SdrObject*>::const_iterator it = std::find(maOriginalList.begin(),
87 : maOriginalList.end(),
88 0 : pOriginalNode1);
89 :
90 0 : sal_uInt32 nPos = it - maOriginalList.begin();
91 :
92 0 : if(it != maOriginalList.end())
93 : {
94 0 : SdrObject *cObj = NULL;
95 :
96 0 : if (nPos < cloneCount)
97 0 : cObj = GetClone(nPos);
98 :
99 0 : if(pOriginalEdge->GetConnectedNode(true) != cObj)
100 0 : pCloneEdge->ConnectToNode(true, cObj);
101 : }
102 : }
103 :
104 0 : if(pOriginalNode2)
105 : {
106 : std::vector<const SdrObject*>::const_iterator it = std::find(maOriginalList.begin(),
107 : maOriginalList.end(),
108 0 : pOriginalNode2);
109 :
110 0 : sal_uInt32 nPos = it - maOriginalList.begin();
111 :
112 0 : if(it != maOriginalList.end())
113 : {
114 0 : SdrObject *cObj = NULL;
115 :
116 0 : if (nPos < cloneCount)
117 0 : cObj = GetClone(nPos);
118 :
119 0 : if(pOriginalEdge->GetConnectedNode(false) != cObj)
120 0 : pCloneEdge->ConnectToNode(false, cObj);
121 : }
122 : }
123 : }
124 : }
125 435 : }
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|