1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "StandardLayoutConnectionList.h"
24 CStandardLayoutConnectionList::CStandardLayoutConnectionList
25 ( const std::vector
<CStandardLayoutNodeInfo
>& nodes
26 , const std::vector
<std::pair
<index_t
, index_t
> >& connections
)
28 , connections (connections
)
32 // implement ILayoutItemList
34 index_t
CStandardLayoutConnectionList::GetCount() const
36 return static_cast<index_t
>(connections
.size());
39 CString
CStandardLayoutConnectionList::GetToolTip (index_t
/* index */) const
44 index_t
CStandardLayoutConnectionList::GetFirstVisible
45 (const CRect
& viewRect
) const
47 return GetNextVisible (static_cast<index_t
>(-1), viewRect
);
50 index_t
CStandardLayoutConnectionList::GetNextVisible
52 , const CRect
& viewRect
) const
54 for (size_t i
= prev
+1, count
= connections
.size(); i
< count
; ++i
)
56 const std::pair
<index_t
, index_t
>& connection
= connections
[i
];
59 commonRect
.UnionRect ( nodes
[connection
.first
].rect
60 , nodes
[connection
.second
].rect
);
61 if (FALSE
!= CRect().IntersectRect (commonRect
, viewRect
))
62 return static_cast<index_t
>(i
);
65 return static_cast<index_t
>(NO_INDEX
);
68 index_t
CStandardLayoutConnectionList::GetAt
69 ( const CPoint
& /* point */
70 , CSize
/* delta */) const
72 return static_cast<index_t
>(NO_INDEX
);
75 // implement ILayoutConnectionList
77 CStandardLayoutConnectionList::SConnection
78 CStandardLayoutConnectionList::GetConnection (index_t index
) const
80 // determine the end points of the connection
82 const std::pair
<index_t
, index_t
>& connection
= connections
[index
];
83 const CRect
* source
= &nodes
[connection
.first
].rect
;
84 const CRect
* dest
= &nodes
[connection
.second
].rect
;
86 if (source
->left
> dest
->right
)
87 std::swap (source
, dest
);
92 if (source
->right
< dest
->left
)
94 // there is a vertical gap between source and dest
96 startPoint
.x
= source
->right
;
97 startPoint
.y
= (source
->top
+ source
->bottom
) / 2;
101 // there must be a horizontal gap
103 if (source
->top
> dest
->top
)
104 std::swap (source
, dest
);
106 startPoint
.x
= (source
->left
+ source
->right
) / 2;
107 startPoint
.y
= source
->bottom
;
110 endPoint
.x
= (dest
->left
+ dest
->right
) / 2;
111 endPoint
.y
= dest
->top
> startPoint
.y
? dest
->top
: dest
->bottom
;
115 static CPoint points
[4];
117 points
[0] = startPoint
;
118 points
[1].x
= (startPoint
.x
+ endPoint
.x
) / 2; // first control point
119 points
[1].y
= startPoint
.y
;
120 points
[2].x
= endPoint
.x
; // second control point
121 points
[2].y
= startPoint
.y
;
122 points
[3] = endPoint
;
129 result
.numberOfPoints
= 4;
130 result
.points
= points
;