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