1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
23 // Carlos Alberto Cortez <calberto.cortez@gmail.com>
30 namespace System.Windows.Forms
32 public sealed class ListViewInsertionMark
34 ListView listview_owner;
35 bool appears_after_item;
40 internal ListViewInsertionMark (ListView listview)
42 listview_owner = listview;
45 public bool AppearsAfterItem {
47 return appears_after_item;
50 if (value == appears_after_item)
53 appears_after_item = value;
55 listview_owner.item_control.Invalidate (bounds);
57 listview_owner.item_control.Invalidate (bounds);
61 public Rectangle Bounds {
69 return color == null ? listview_owner.ForeColor : color.Value;
86 listview_owner.item_control.Invalidate (bounds);
88 listview_owner.item_control.Invalidate (bounds);
94 if (index < 0 || index >= listview_owner.Items.Count) {
95 bounds = Rectangle.Empty;
99 Rectangle item_bounds = listview_owner.Items [index].Bounds;
100 int x_origin = (appears_after_item ? item_bounds.Right : item_bounds.Left) - 2;
101 int height = item_bounds.Height + ThemeEngine.Current.ListViewVerticalSpacing;
103 bounds = new Rectangle (x_origin, item_bounds.Top, 7, height);
106 public int NearestIndex (Point pt)
108 double distance = Double.MaxValue;
111 for (int i = 0; i < listview_owner.Items.Count; i++) {
112 Point pos = listview_owner.GetItemLocation (i);
113 double d = Math.Pow (pos.X - pt.X, 2) + Math.Pow (pos.Y - pt.Y, 2);
120 if (listview_owner.item_control.dragged_item_index == nearest)
126 internal PointF [] TopTriangle {
128 PointF p1 = new PointF (bounds.X, bounds.Y);
129 PointF p2 = new PointF (bounds.Right, bounds.Y);
130 PointF p3 = new PointF (bounds.X + (bounds.Right - bounds.X) / 2, bounds.Y + 5);
132 return new PointF [] {p1, p2, p3};
136 internal PointF [] BottomTriangle {
138 PointF p1 = new PointF (bounds.X, bounds.Bottom);
139 PointF p2 = new PointF (bounds.Right, bounds.Bottom);
140 PointF p3 = new PointF (bounds.X + (bounds.Right - bounds.X) / 2, bounds.Bottom - 5);
142 return new PointF [] {p1, p2, p3};
146 internal Rectangle Line {
148 return new Rectangle (bounds.X + 2, bounds.Y + 2, 2, bounds.Height - 5);