Rayburn Davis
2014-09-15 fb4519e5c864e7c153b6bafcf79275ed36a9bda3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Text;
using System.Windows.Forms;
 
namespace DupliDelete.DuplicateListView
{
    public partial class DuplicateListView : UserControl
    {
        // Variables
 
        /// <summary>
        /// Defines what to draw first at the top of the list.
        /// </summary>
        public DrawIndex DrawStartIndex=new DrawIndex();
 
        /// <summary>
        /// Defines the place where the text should start to be drawn
        /// </summary>
        public int ItemTextStartX = 25, ItemTextStartY = 21;
 
        /// <summary>
        /// Item height
        /// </summary>
        public int ItemHeight = 21;
 
        /// <summary>
        /// Index relative to top item that the mouse is over
        /// </summary>
        public int MouseOverIndex=-1;
 
        /// <summary>
        /// Current mouse position
        /// </summary>
        public new Point MousePosition;
 
        /// <summary>
        /// True if the user has opted to highlight the item the mouse is over
        /// </summary>
        public bool HighlightMouseOverItems = true;
 
        /// <summary>
        /// The selected index
        /// </summary>
        public DrawIndex SelectedItem = new DrawIndex();
 
        /// <summary>
        /// Color for mouse over items
        /// </summary>
        Color MouseOverColor = Color.FromArgb(242, 242, 242);
        SolidBrush MouseOverBrush;
 
        /// <summary>
        /// The font that draws the duplicates
        /// </summary>
        Font GroupFont = new Font("Courier", Convert.ToSingle(8));
 
        /// <summary>
        /// The font that draws the duplicates
        /// </summary>
        Font DuplicateFont = new Font("Courier", Convert.ToSingle(8));
 
        /// <summary>
        /// Column collection
        /// </summary>
        public ColumnGroupCollection Columns = new ColumnGroupCollection();
 
        public int OldVerticalScrollBarValue=0;
 
        /// <summary>
        /// Image for header
        /// </summary>
        Image header_image;
 
        /// <summary>
        /// Image for selected header
        /// </summary>
        Image selected_header;
 
        /// <summary>
        /// Image for sizing grip
        /// </summary>
        Image sizing_grip;
 
        /// <summary>
        /// Color of the shaded color
        /// </summary>
        Color shade_color = Color.FromArgb(247, 247, 247);
 
        SolidBrush shade_color_brush;
 
        /// <summary>
        /// X where the group is written
        /// </summary>
        int GroupStartX = 8;
 
        /// <summary>
        /// Font the group is drawn in
        /// </summary>
        Font GroupDrawFont = new Font("Microsoft Sans Serif", 8, FontStyle.Bold);
 
        /// <summary>
        /// Delete button
        /// </summary>
        public bool DeleteButton = true;
 
        /// <summary>
        /// The delete button is down
        /// </summary>
        public bool DeleteButtonDown = false;
 
        /// <summary>
        /// The mouse is over the delete button
        /// </summary>
        public bool MouseOverDelete = false;
 
        /// <summary>
        /// The index of the item that the mouse is over the delete button of
        /// </summary>
        public int MouseOverDeleteIndex;
 
        /// <summary>
        /// Link button
        /// </summary>
        public bool LinkButton = true;
 
        /// <summary>
        /// The link button is down
        /// </summary>
        public bool LinkButtonDown = false;
 
        /// <summary>
        /// The mouse is over the link button
        /// </summary>
        public bool MouseOverLink = false;
 
        /// <summary>
        /// The index of the item that the mouse is over the link button of
        /// </summary>
        public int MouseOverLinkIndex;
 
        public bool MouseOverCheck = false;
 
        public int MouseOverCheckIndex;
 
        public bool MouseOverGroupStatus = false;
 
        public bool CheckDown = false;
 
        public bool MouseOnFileGrip = false;
        public bool MouseFileGripDown = false;
 
        public bool MouseOnSizeGrip = false;
        public bool MouseSizeGripDown = false;
 
        public bool MouseOnDateGrip = false;
        public bool MouseDateGripDown = false;
 
        public bool MouseOnItemArea = false;
 
        public int MouseDoubleClickIndex;
 
        /// <summary>
        /// Event that occurs when the list has changed
        /// </summary>
        /// <param name="e"></param>
 
        public delegate void ListChangedDelegate(EventArgs e);
 
        public event ListChangedDelegate ListChanged;
 
        /// <summary>
        /// The item whose delete or link button was clicked
        /// </summary>
        public DrawIndex DeleteLinkItem;
 
        public delegate void DeleteButtonClickedDelegate(ItemButtonClickedArgs e);
 
        public event DeleteButtonClickedDelegate DeleteButtonClicked;
 
        public delegate void LinkButtonClickedDelegate(ItemButtonClickedArgs e);
 
        public event LinkButtonClickedDelegate LinkButtonClicked;
 
        public class ItemButtonClickedArgs : EventArgs
        {
            /// <summary>
            /// The index of the item whose button was clicked
            /// </summary>
            public int ItemIndex;
            public int Group, Duplicate;
 
            public ItemButtonClickedArgs(int index, int group, int duplicate)
            {
                ItemIndex = index;
                Group = group;
                Duplicate = duplicate;
            }
        }
 
        public event ItemDoubleClickedDelegate ItemDoubleClicked;
 
        public delegate void ItemDoubleClickedDelegate(ItemDoubleClickedArgs e);
 
        public class ItemDoubleClickedArgs : EventArgs
        {
            /// <summary>
            /// The index of the item whose button was clicked
            /// </summary>
 
            DuplicateObject DuplicateObject;
 
            public ItemDoubleClickedArgs(int index, DrawIndex draw_index)
            {
                if(draw_index.InBounds() == DrawIndex.IndexReturnStatus.Exists)
                    DuplicateObject = draw_index.ReturnDrawableItem();
            }
        }
 
        public event ItemRightClickedDelegate ItemRightClicked;
 
        public delegate void ItemRightClickedDelegate(MouseEventArgs e);
 
        public class ItemCheckedArgs : EventArgs
        {
            /// <summary>
            /// The index of the item whose button was clicked
            /// </summary>
 
            DuplicateObject DuplicateObject;
 
            public ItemCheckedArgs(int index, DrawIndex draw_index)
            {
                DuplicateObject = draw_index.ReturnDrawableItem();
            }
        }
 
        public delegate void ItemCheckedDelegate(ItemCheckedArgs e);
        public event ItemCheckedDelegate ItemChecked;
 
        public bool EnsureVisibleEvent = false;
 
        public ToolTip DuplicateGroupStatus;
 
        public LinearGradientBrush SelectedItemBrush;
 
        bool DataRemoved=false;
 
        // event to notify the main form that the number of checked items has been updated
        public delegate void CheckedItemsUpdatedDelegate(EventArgs e);
 
        public event CheckedItemsUpdatedDelegate CheckedItemsUpdated;
 
        // event to notify the main form that the number of highlighted items has been updated
        public delegate void HighlightedItemsUpdatedDelegate(EventArgs e);
 
        public event HighlightedItemsUpdatedDelegate HighlightedItemsUpdated;
 
        Point LinePointStart = new Point(); // point where the vertical line is drawn beside the filename (only on FilenameThenPath mode)
        Point LinePointEnd = new Point(); // point where the vertical line is drawn beside the filename (only on FilenameThenPath mode)
 
        //
        public DuplicateListView()
        {
            InitializeComponent();
 
            MouseOverBrush = new SolidBrush(MouseOverColor);
 
            header_image = global::DupliDelete.Properties.Resources.header;
 
            selected_header = global::DupliDelete.Properties.Resources.selectedheader;
 
            sizing_grip = global::DupliDelete.Properties.Resources.sizinggrip;
 
            MouseWheel += new MouseEventHandler(DuplicateListView_MouseWheel);
 
            Columns.Add(new Column("File", 850));
            Columns.Add(new Column("Size", 100));
            Columns.Add(new Column("Date Modified", 150));
 
            DuplicateGroupStatus = new ToolTip();
        }
 
        void DuplicateListView_MouseWheel(object sender, MouseEventArgs e)
        {
            if (e.Delta == -120 && verticalScrollbar.Value < verticalScrollbar.Maximum + 4) // scroll down
            {
                if (verticalScrollbar.Value + GlobalBuffers.WheelSkip < 0) // edited 6/6/12
                    verticalScrollbar.Value = 0;
 
                else if (verticalScrollbar.Value + GlobalBuffers.WheelSkip > verticalScrollbar.Maximum)
                    verticalScrollbar.Value = verticalScrollbar.Maximum;
                else
                    verticalScrollbar.Value += GlobalBuffers.WheelSkip;
 
                
            }
            if (e.Delta == 120 && verticalScrollbar.Value > 0) // scroll up
            {
                if (verticalScrollbar.Value - GlobalBuffers.WheelSkip < 0) // edited 6/6/12
                    verticalScrollbar.Value = 0;
 
                else if (verticalScrollbar.Value - GlobalBuffers.WheelSkip > verticalScrollbar.Maximum)
                    verticalScrollbar.Value = verticalScrollbar.Maximum;
                else
                    verticalScrollbar.Value -= GlobalBuffers.WheelSkip;
            }
        }
 
        private void DuplicateListView_Load(object sender, EventArgs e)
        {
            DrawStartIndex = new DrawIndex(0, -1, GlobalBuffers.Duplicates);
 
            HighLightedIndexes = new HighlightedIndexCollection(this);
        }
 
        public void AssociateWithDataProvider(DuplicateGroupCollection data)
        {
            DrawStartIndex = new DrawIndex(0, -1, data);
            verticalScrollbar.Maximum = data.GroupDuplicateTotal;
            verticalScrollbar.Value = 0;
 
            data.DataRemoved += new DuplicateGroupCollection.DataRemovedDelegate(data_DataRemoved);
        }
 
        void data_DataRemoved(DuplicateGroupCollection.ItemRemovedEventArgs e)
        {
            if (DrawStartIndex != null && DrawStartIndex.Data != null)
            {
                if (DrawStartIndex.InBounds() == DrawIndex.IndexReturnStatus.OutOfBounds)
                {
                    while (DrawStartIndex.InBounds() == DrawIndex.IndexReturnStatus.OutOfBounds && !(DrawStartIndex.Group == 0 && DrawStartIndex.Duplicate == -1))
                        DrawStartIndex.Decrement();
 
                    if (DrawStartIndex.Decrement(MaximumVisibleItems() - 1) == DrawIndex.IndexReturnStatus.OutOfBounds)
                    {
                        DrawStartIndex.Group = 0;
                        DrawStartIndex.Duplicate = -1;
                    }
                }
 
            }
 
            if (SelectedItem != null && SelectedItem.Data != null)
            {
                if (SelectedItem.InBounds() == DrawIndex.IndexReturnStatus.OutOfBounds)
                {
                    while (SelectedItem.InBounds() == DrawIndex.IndexReturnStatus.OutOfBounds && !(SelectedItem.Group == 0 && SelectedItem.Duplicate == -1))
                        SelectedItem.Decrement();
                }
 
              //  Invalidate();
            }
 
            HighLightedIndexes.RemoveAt(e.RollingTotal);
 
            DataRemoved = true;
 
            if (ListChanged != null)
                ListChanged(new EventArgs());
 
        }
 
        public DuplicateObject GetItem(int group, int duplicate)
        {
            DrawIndex item_index = new DrawIndex(group, duplicate, DrawStartIndex.Data);
 
            if (item_index.InBounds() == DrawIndex.IndexReturnStatus.Exists)
                return item_index.ReturnDrawableItem();
            else
                return null;
        }
 
        public DuplicateObject GetGroupOfItem(DrawIndex item)
        {
            return GetItem(item.Group, -1);
        }
 
        public bool IsDataIndexVisible(DrawIndex index)
        {
            DrawIndex draw_item = new DrawIndex(DrawStartIndex.Group, DrawStartIndex.Duplicate, DrawStartIndex.Data);
            int i;
 
            for (i = 0; i < MaximumVisibleItems(); i++)
            {
                if (draw_item.Group == index.Group && draw_item.Duplicate == index.Duplicate)
                    return true;
                else
                {
                    if (draw_item.Increment() == DrawIndex.IndexReturnStatus.OutOfBounds)
                        return false;
                }
            }
 
            return false;
        }
 
        public enum RedrawParam
        {
            All, Columns, Items, Item
        }
 
        RedrawParam DrawParam = RedrawParam.All;
 
        DrawIndex paint_start = new DrawIndex();
 
        private void DuplicateListView_Paint(object sender, PaintEventArgs e)
        {
            int i;
            DuplicateObject draw_object;
 
 
 
            int start_x = ItemTextStartX - horizontalScrollbar.Value, start_y = ItemTextStartY;
            paint_start.Group = DrawStartIndex.Group;
            paint_start.Duplicate = DrawStartIndex.Duplicate;
            paint_start.Data = DrawStartIndex.Data;
            int mouse_item = PointToItem(MousePosition);
            Region clipping_region;
            int column_draw_start = 0 - horizontalScrollbar.Value;
            int group_start_x = GroupStartX - horizontalScrollbar.Value;
            int item_start_x = 55 - horizontalScrollbar.Value;
 
            e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            e.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
           
            // paint columns here
 
            // draw the columns
 
           // if (DrawParam == RedrawParam.All || DrawParam == RedrawParam.Columns)
          //  {
                for (i = 0; i < Columns.Count; i++)
                {
                    // exclude everything but the column region
                    clipping_region = new Region(new Rectangle(column_draw_start, 0, Columns[i].Width, 21));
                    e.Graphics.Clip = clipping_region;
 
                    // draw the column
                    // if (i != MouseOverColumn)
                    e.Graphics.DrawImage(header_image, column_draw_start, 0, Columns[i].Width, 21);
                    // else
                    //     e.Graphics.DrawImage(selected_header, column_draw_start, 0, Columns[i].Width + 15, 21);
 
                    // reset the exclusion
                    e.Graphics.ResetClip();
 
                    // draw the sizing grip
                    if (i > 0)
                        e.Graphics.DrawImage(sizing_grip, column_draw_start - 3, 0, sizing_grip.Width, 21);
 
                    // draw the column name
                    e.Graphics.DrawString(Columns[i].Name, DuplicateFont, Brushes.Black, Convert.ToSingle(column_draw_start + 5), Convert.ToSingle(5));
 
                    // shade the columns
                    if (Columns[i].Shaded == true)
                    {
                        e.Graphics.FillRectangle(shade_color_brush, column_draw_start, ItemTextStartY, Columns[i].Width /* - hScrollBar1.Height*/, this.Height - ItemTextStartY);
                    }
 
                    // set up the horizontal scrollbar
                    if (i == Columns.Count - 1 && column_draw_start >= 0)
                    {
                        horizontalScrollbar.Maximum = column_draw_start;
                    }
 
                    // increment the position where the column starts
                    column_draw_start += Columns[i].Width;
 
                    if (i == Columns.Count - 1)
                    {
                        e.Graphics.DrawImage(sizing_grip, column_draw_start, 0, sizing_grip.Width, 21);
                        e.Graphics.DrawImage(header_image, column_draw_start + 2, 0, this.Width - column_draw_start, 21);
                    }
 
                    e.Graphics.ResetClip();
                }
 
                //
                e.Graphics.ResetClip();
           // }
 
          //  if (DrawParam == RedrawParam.Items || DrawParam == RedrawParam.All)
            {
 
                for (i = 0; i < MaximumVisibleItems(); i++)
                {
                    if (DrawStartIndex.InBounds() == DrawIndex.IndexReturnStatus.Exists)
                    {
                        // paint item here
 
                        // get the item to be drawn
                        draw_object = paint_start.ReturnDrawableItem();
 
                        // Fil; the item if it's selected
                        if (ItemSelected(paint_start) == true)
                        {
                            //SelectedItemBrush = new LinearGradientBrush(new Rectangle(0, start_y, this.Width, ItemHeight), SystemColors.Highlight, Color.DeepSkyBlue, LinearGradientMode.Vertical);
                            e.Graphics.FillRectangle(SystemBrushes.Highlight, new Rectangle(0, start_y, this.Width, ItemHeight));
                        }
 
                        // lightly highlight the item if the mouse is over it
                        else if (HighlightMouseOverItems == true && mouse_item == i)
                        {
                            e.Graphics.FillRectangle(MouseOverBrush, new Rectangle(0, start_y, this.Width, ItemHeight));
                        }
 
                       /* else if ( draw_object.ObjectType == DuplicateObject.Type.File)
                        {
                            if (draw_object.DuplicateGroup.Highlighted == true)
                            {
                                e.Graphics.FillRectangle(Brushes.LightSteelBlue, new Rectangle(0, start_y, this.Width, ItemHeight));
                            }
                        }
 
                        else if(draw_object.ObjectType == DuplicateObject.Type.Group)
                        {
                            if(draw_object.DuplicateGroup.Highlighted)
                                 e.Graphics.FillRectangle(Brushes.LightSteelBlue, new Rectangle(0, start_y, this.Width, ItemHeight));
                        }*/
 
                        // draw the item
                        e.Graphics.SetClip(new Rectangle(0 - horizontalScrollbar.Value, start_y, Columns[0].Width, ItemHeight));
 
                        // draw the checkbox
                        if (draw_object.ObjectType == DuplicateObject.Type.Group)
                        {
                            if (MouseOverCheck == true && MouseOverCheckIndex == i)
                            {
                                int group_check_state = draw_object.DuplicateGroup.GetGroupCheckState();
                                if (group_check_state == 1)
                                    CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(group_start_x, start_y + 4), System.Windows.Forms.VisualStyles.CheckBoxState.CheckedHot);
                                else if (group_check_state == 2)
                                    CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(group_start_x, start_y + 4), System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedHot);
                                else if (group_check_state == 3)
                                    CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(group_start_x, start_y + 4), System.Windows.Forms.VisualStyles.CheckBoxState.MixedHot);
                            }
                            else
                            {
                                int group_check_state = draw_object.DuplicateGroup.GetGroupCheckState();
                                if (group_check_state == 1)
                                    CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(group_start_x, start_y + 4), System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal);
                                else if (group_check_state == 2)
                                    CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(group_start_x, start_y + 4), System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
                                else if (group_check_state == 3)
                                    CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(group_start_x, start_y + 4), System.Windows.Forms.VisualStyles.CheckBoxState.MixedNormal);
                            }
                        }
                        else
                        {
                            if (MouseOverCheck == true && MouseOverCheckIndex == i)
                            {
                                if (draw_object.DuplicateFile.Checked == false)
                                    CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(group_start_x + 13, start_y + 4), System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedHot);
                                else
                                    CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(group_start_x + 13, start_y + 4), System.Windows.Forms.VisualStyles.CheckBoxState.CheckedHot);
                            }
                            else
                            {
                                if (draw_object.DuplicateFile.Checked == false)
                                    CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(group_start_x + 13, start_y + 4), System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
                                else
                                    CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(group_start_x + 13, start_y + 4), System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal);
                            }
                        }
 
                        // Draw the group state
                        if (draw_object.ObjectType == DuplicateObject.Type.Group)
                        {
                            switch (draw_object.DuplicateGroup.State)
                            {
                                case DuplicateGroup.GroupState.TrueDuplicate:
                                    e.Graphics.DrawImage(global::DupliDelete.Properties.Resources.bytebybyte, group_start_x + 20, start_y + 2);
                                    break;
                                case DuplicateGroup.GroupState.FalseDuplicate:
                                    e.Graphics.DrawImage(global::DupliDelete.Properties.Resources.nobytebybyte, group_start_x + 20, start_y + 2);
                                    break;
                                case DuplicateGroup.GroupState.Undeterminable:
                                    e.Graphics.DrawImage(global::DupliDelete.Properties.Resources.bytebybyteunknown, group_start_x + 20, start_y + 2);
                                    break;
                            }
 
                            e.Graphics.DrawString(draw_object.DuplicateGroup.GroupName, GroupDrawFont, ItemSelected(paint_start) == true ? Brushes.White : Brushes.Black, group_start_x + 38, start_y + 4);
 
                            // draw delete button
                            if (DeleteButton == true)
                            {
                                if (mouse_item == i)
                                {
                                    e.Graphics.SetClip(new Rectangle(Columns[0].Width + Columns[1].Width + Columns[2].Width + 7 - horizontalScrollbar.Value, start_y, 75, 21));
 
                                    if (DeleteButtonDown == false && MouseOverDelete == true)
                                        ButtonRenderer.DrawButton(e.Graphics, new Rectangle(Columns[0].Width + Columns[1].Width + Columns[2].Width + 7 - horizontalScrollbar.Value, start_y, 75, 21), "Delete", GroupDrawFont, false, System.Windows.Forms.VisualStyles.PushButtonState.Hot);
                                    else if (DeleteButtonDown == true)
                                    {
                                        ButtonRenderer.DrawButton(e.Graphics, new Rectangle(Columns[0].Width + Columns[1].Width + Columns[2].Width + 7 - horizontalScrollbar.Value, start_y, 75, 21), "Delete", GroupDrawFont, false, System.Windows.Forms.VisualStyles.PushButtonState.Pressed);
                                    }
                                    else if (DeleteButtonDown == false && MouseOverDelete == false)
                                    {
                                        ButtonRenderer.DrawButton(e.Graphics, new Rectangle(Columns[0].Width + Columns[1].Width + Columns[2].Width + 7 - horizontalScrollbar.Value, start_y, 75, 21), "Delete", GroupDrawFont, false, System.Windows.Forms.VisualStyles.PushButtonState.Normal);
                                    }
                                }
                            }
 
                        }
                        else
                        {
                            // draw the link icon if needed
                            if (draw_object.DuplicateFile.Link == true)
                                e.Graphics.DrawImage(global::DupliDelete.Properties.Resources.hardlink, item_start_x + 11, start_y + 3);
 
                            // draw the network icon if needed
                            if (draw_object.DuplicateFile.Network == true)
                            {
                                e.Graphics.DrawImage(global::DupliDelete.Properties.Resources.computer_icon, item_start_x - 17, start_y + 3);
                            }
 
                            item_start_x = 55 - horizontalScrollbar.Value;
 
                            // draw the filename
                            if (GlobalBuffers.DisplayStyle == GlobalBuffers.FileNameDisplayStyle.FullPath)
                            {
                                e.Graphics.DrawString(draw_object.DuplicateFile.Network == false ? draw_object.DuplicateFile.Filename : draw_object.DuplicateFile.NetworkIP + ": " + draw_object.DuplicateFile.Filename, DuplicateFont, ItemSelected(paint_start) == true ? Brushes.White : Brushes.Black, item_start_x, start_y + 4);
                            }
                            else
                            {
                                e.Graphics.DrawString(System.IO.Path.GetFileName(draw_object.DuplicateFile.Filename), DuplicateFont, ItemSelected(paint_start) == true ? Brushes.White : Brushes.Black, item_start_x, start_y + 4);
                                item_start_x = item_start_x + Convert.ToInt32(e.Graphics.MeasureString(System.IO.Path.GetFileName(draw_object.DuplicateFile.Filename), DuplicateFont).ToSize().Width) + 15;
 
                                LinePointStart.X = item_start_x;
                                LinePointStart.Y = start_y;
                                LinePointEnd.X = item_start_x + 1;
                                LinePointEnd.Y = start_y;
 
                                e.Graphics.DrawLine(Pens.Black, LinePointStart, LinePointEnd);
 
                                LinePointStart.X += 1;
                                LinePointEnd.X += 1;
 
                                e.Graphics.DrawLine(Pens.LightGray, LinePointStart, LinePointEnd);
 
                                item_start_x += 5;
 
                                e.Graphics.DrawString(System.IO.Path.GetDirectoryName(draw_object.DuplicateFile.Filename), DuplicateFont, ItemSelected(paint_start) == true ? Brushes.White : Brushes.Black, item_start_x, start_y + 4);
 
                            }
 
                            e.Graphics.ResetClip();
 
                            e.Graphics.SetClip(new Rectangle(Columns[0].Width - horizontalScrollbar.Value, start_y, Columns[1].Width, ItemHeight));
 
                            // draw the size
                            e.Graphics.DrawString(FormatSizeString(draw_object.DuplicateFile.Size), DuplicateFont, ItemSelected(paint_start) == true ? Brushes.White : Brushes.Black, Columns[0].Width + 4 - horizontalScrollbar.Value, start_y + 4);
 
                            e.Graphics.ResetClip();
 
                            // draw the date modified
                            e.Graphics.SetClip(new Rectangle(Columns[0].Width + Columns[1].Width - horizontalScrollbar.Value, start_y, Columns[2].Width, ItemHeight));
 
                            e.Graphics.DrawString(FormatDate(draw_object.DuplicateFile.DateModified) + "   " + FormatTime(draw_object.DuplicateFile.DateModified), DuplicateFont, ItemSelected(paint_start) == true ? Brushes.White : Brushes.Black, Columns[0].Width + Columns[1].Width + 4 - horizontalScrollbar.Value, start_y + 4);
 
                            e.Graphics.ResetClip();
 
                            // draw delete button
                            if (DeleteButton == true)
                            {
                                if (mouse_item == i)
                                {
                                    if (DeleteButtonDown == false && MouseOverDelete == true)
                                        ButtonRenderer.DrawButton(e.Graphics, new Rectangle(Columns[0].Width + Columns[1].Width + Columns[2].Width + 7 - horizontalScrollbar.Value, start_y, 75, 21), "Delete", GroupDrawFont, false, System.Windows.Forms.VisualStyles.PushButtonState.Hot);
                                    else if (DeleteButtonDown == true)
                                    {
                                        ButtonRenderer.DrawButton(e.Graphics, new Rectangle(Columns[0].Width + Columns[1].Width + Columns[2].Width + 7 - horizontalScrollbar.Value, start_y, 75, 21), "Delete", GroupDrawFont, false, System.Windows.Forms.VisualStyles.PushButtonState.Pressed);
                                    }
                                    else if (DeleteButtonDown == false && MouseOverDelete == false)
                                    {
                                        ButtonRenderer.DrawButton(e.Graphics, new Rectangle(Columns[0].Width + Columns[1].Width + Columns[2].Width + 7 - horizontalScrollbar.Value, start_y, 75, 21), "Delete", GroupDrawFont, false, System.Windows.Forms.VisualStyles.PushButtonState.Normal);
                                    }
                                }
                            }
 
                            // draw link button
                            if (LinkButton == true)
                            {
                                if (mouse_item == i && draw_object.DuplicateFile.Parent.State == DuplicateGroup.GroupState.TrueDuplicate && draw_object.DuplicateFile.Network == false)
                                {
                                    if (LinkButtonDown == false && MouseOverLink == true)
                                        ButtonRenderer.DrawButton(e.Graphics, new Rectangle(Columns[0].Width + Columns[1].Width + Columns[2].Width + 87 - horizontalScrollbar.Value, start_y, 75, 21), "Link", GroupDrawFont, false, System.Windows.Forms.VisualStyles.PushButtonState.Hot);
                                    else if (LinkButtonDown == true)
                                    {
                                        ButtonRenderer.DrawButton(e.Graphics, new Rectangle(Columns[0].Width + Columns[1].Width + Columns[2].Width + 87 - horizontalScrollbar.Value, start_y, 75, 21), "Link", GroupDrawFont, false, System.Windows.Forms.VisualStyles.PushButtonState.Pressed);
                                    }
                                    else if (LinkButtonDown == false && MouseOverLink == false)
                                    {
                                        ButtonRenderer.DrawButton(e.Graphics, new Rectangle(Columns[0].Width + Columns[1].Width + Columns[2].Width + 87 - horizontalScrollbar.Value, start_y, 75, 21), "Link", GroupDrawFont, false, System.Windows.Forms.VisualStyles.PushButtonState.Normal);
                                    }
                                }
                            }
                        }
 
 
                        //
 
                        // if we drew the last item, break out of the loop
                        if (paint_start.Increment() == DrawIndex.IndexReturnStatus.OutOfBounds)
                        {
                            break;
                        }
 
                        // increment draw position
                        start_y += ItemHeight;
 
                        e.Graphics.ResetClip();
 
                        item_start_x = start_x;
                    }
                    else
                    {
 
                    }
                }
            }
 
 
            if (DrawStartIndex.Data != null)
            {
                verticalScrollbar.Maximum = DrawStartIndex.Data.ComputeRollingTotal(new DrawIndex(DrawStartIndex.Data.Count, 0, DrawStartIndex.Data));
                    //verticalScrollbar.Maximum = DrawStartIndex.Data.GroupDuplicateTotal;// -(MaximumVisibleItems() - 3);
            }
            else
            {
                verticalScrollbar.Value = 0;
            }
 
            if (HighLightedIndexes.Count > 0)
                DrawLineIndexes(e);
 
            DrawParam = RedrawParam.All;
 
        }
 
        public static string FormatSizeString(long size)
        {
            string size_string=null;
 
            if (size == 1)
                size_string = size.ToString() + " byte";
 
            if (size != 1 && size <= 1023)
                size_string = size.ToString() + " bytes";
 
            if (size >= 1024 && size < 1048576)
            {
                size_string = ((double)size / 1024).ToString();
                size_string = size_string.Substring(0, size_string.Contains(".") == true ? size_string.IndexOf(".") + (size_string.IndexOf(".") > size_string.Length - 3 ? 2 : 3) : size_string.Length) + " KB";
            }
 
            if (size >= 1048576 && size < 1073741824)
            {
                size_string = ((double)size / 1024 / 1024).ToString();
                size_string = size_string.Substring(0, size_string.Contains(".") == true ? size_string.IndexOf(".") + (size_string.IndexOf(".") > size_string.Length - 3 ? 2 : 3) : size_string.Length) + " MB";
            }
 
            if (size >= 1073741824 && size < 1099511627776)
            {
                size_string = ((double)size / 1024 / 1024 / 1024).ToString();
                size_string = size_string.Substring(0, size_string.Contains(".") == true ? size_string.IndexOf(".") + (size_string.IndexOf(".") > size_string.Length - 3 ? 2 : 3) : size_string.Length) + " GB";
            }
 
            if (size >= 1099511627776 && size < 1125899906842624)
            {
                size_string = ((double)size / 1024 / 1024 / 1024 / 1024).ToString();
                size_string = size_string.Substring(0, size_string.Contains(".") == true ? size_string.IndexOf(".") + (size_string.IndexOf(".") > size_string.Length - 3 ? 2 : 3) : size_string.Length) + " TB";
            }
 
            return size_string;
        }
 
        private string FormatDate(DateTime dateTime)
        {
            string output;
 
            output = dateTime.ToLocalTime().Month.ToString() + "/" + dateTime.Day.ToString() + "/" + dateTime.Year.ToString();
 
            return output;
        }
 
        private string FormatTime(DateTime dateTime)
        {
            string output;
            string AMPM;
 
            AMPM = (dateTime.Hour > 12 ? " PM" : " AM");
 
            output = (dateTime.Hour == 0 ? 12 : (dateTime.Hour > 12 ? dateTime.Hour - 12 : dateTime.Hour)) + ":" + (dateTime.Minute < 10 ? "0" + dateTime.Minute.ToString() : dateTime.Minute.ToString()) + AMPM;
 
            return output;
        }
 
        public bool ItemSelected(DrawIndex item)
        {
            if (item.Group == SelectedItem.Group && item.Duplicate == SelectedItem.Duplicate)
                return true;
            else
                return false;
        }
 
        public int PointToItem(Point point)
        {
            int i;
            int draw_y = ItemTextStartY;
            DrawIndex test_index = new DrawIndex(DrawStartIndex.Group, DrawStartIndex.Duplicate, DrawStartIndex.Data);
 
            for (i = 0; i < MaximumVisibleItems(); i++)
            {
                if (point.Y >= draw_y && point.Y < draw_y + ItemHeight)
                {
                    if (test_index.InBoundsIncremented(i) !=  DrawIndex.IndexReturnStatus.Exists)
                        return -1;
                    return i;
                }
 
                draw_y += ItemHeight;
            }
 
            return -1;
        }
 
        public int MaximumVisibleItems()
        {
            double output = (double)(this.Height - ItemTextStartY - horizontalScrollbar.Height) / ItemHeight;
            return (int)output;
        }
 
        private void DuplicateListView_MouseMove(object sender, MouseEventArgs e)
        {
 
            MousePosition = e.Location;
            int item_index = PointToItem(e.Location);
 
 
 
            // see if the user is moving the file grip column
 
            if (MouseFileGripDown == true && e.X >= 4 - horizontalScrollbar.Value)
            {
                Columns[0].Width = e.X + horizontalScrollbar.Value;
            }
            else if (Columns[0].Width < 7)
                Columns[0].Width = 6;
 
            // see if the user is moving the size grip column
 
            if (MouseSizeGripDown == true && e.X >= 4 + Columns[0].Width - horizontalScrollbar.Value)
            {
                Columns[1].Width = e.X + horizontalScrollbar.Value - Columns[0].Width;
            }
            else if(Columns[1].Width < 7)
                Columns[1].Width = 6;
 
            // see if the user is moving the date grip column
 
            if (MouseDateGripDown == true && e.X >= 4 + Columns[0].Width + Columns[1].Width)
            {
                Columns[2].Width = e.X + horizontalScrollbar.Value - Columns[1].Width - Columns[0].Width;
            }
            else if (Columns[2].Width < 7)
                Columns[2].Width = 6;
 
            // check to see if the mouse is on the grips
 
            if (e.Y < 21 && e.X >= Columns[0].Width - 4 - horizontalScrollbar.Value && e.X <= Columns[0].Width + 4 - horizontalScrollbar.Value)
            {
                MouseOnFileGrip = true;
                Cursor.Current = Cursors.VSplit;
            }
            else if (e.Y < 21 && e.X >= Columns[0].Width + Columns[1].Width - 4 - horizontalScrollbar.Value && e.X <= Columns[0].Width + Columns[1].Width + 4 - horizontalScrollbar.Value)
            {
                MouseOnSizeGrip = true;
                Cursor.Current = Cursors.VSplit;
            }
            else if (e.Y < 21 && e.X >= Columns[0].Width + Columns[1].Width + Columns[2].Width - 4 - horizontalScrollbar.Value && e.X <= Columns[0].Width + Columns[1].Width + Columns[2].Width + 4 - horizontalScrollbar.Value)
            {
                MouseOnDateGrip = true;
                Cursor.Current = Cursors.VSplit;
            }
            else
            {
                MouseOnFileGrip = false;
                MouseOnSizeGrip = false;
                MouseOnDateGrip = false;
                Cursor.Current = Cursors.Default;
            }
            //
 
            if (DrawStartIndex.Data.Count > 0)
            {
 
                DrawIndex item_draw_index = new DrawIndex(DrawStartIndex.Group, DrawStartIndex.Duplicate, DrawStartIndex.Data);
                item_draw_index.Increment(item_index);
 
                if ((DeleteButtonDown == true && item_index != MouseOverDeleteIndex || LinkButtonDown == true && item_index != MouseOverLinkIndex))
                {
                    DeleteButtonDown = false;
                    LinkButtonDown = false;
                }
 
                else if (DeleteButtonDown == false || LinkButtonDown == false)
                {
                    if (e.X - horizontalScrollbar.Value >= Columns[0].Width + Columns[1].Width + Columns[2].Width + 7 - horizontalScrollbar.Value && e.X - horizontalScrollbar.Value < Columns[0].Width + Columns[1].Width + Columns[2].Width + 7 - horizontalScrollbar.Value + 75)
                    {
                        MouseOverDeleteIndex = item_index;
                        MouseOverDelete = true;
                    }
                    else
                    {
                        MouseOverDelete = false;
                        DeleteButtonDown = false;
                    }
 
                    if (e.X - horizontalScrollbar.Value >= Columns[0].Width + Columns[1].Width + Columns[2].Width + 87 - horizontalScrollbar.Value && e.X - horizontalScrollbar.Value < Columns[0].Width + Columns[1].Width + Columns[2].Width + 162 - horizontalScrollbar.Value)
                    {
                        MouseOverLinkIndex = item_index;
                        MouseOverLink = true;
                    }
                    else
                    {
                        MouseOverLink = false;
                        LinkButtonDown = false;
                    }
                }
 
                if (item_index > -1)
                {
                    if (e.X >= GroupStartX - horizontalScrollbar.Value && e.X < GroupStartX - horizontalScrollbar.Value + 15 && e.Y >= 21 + (ItemHeight * item_index) && e.Y < 21 + (ItemHeight * item_index) + 16 && item_draw_index.ReturnDrawableItem().ObjectType == DuplicateObject.Type.Group)
                    {
                        MouseOverCheck = true;
                        MouseOverCheckIndex = item_index;
                    }
                    else if (e.X >= GroupStartX + 13 - horizontalScrollbar.Value && e.X < GroupStartX + 13 - horizontalScrollbar.Value + 15 && e.Y >= 21 + (ItemHeight * item_index) && e.Y < 21 + (ItemHeight * item_index) + 16 && item_draw_index.ReturnDrawableItem().ObjectType == DuplicateObject.Type.File)
                    {
                        MouseOverCheck = true;
                        MouseOverCheckIndex = item_index;
                    }
                    else
                        MouseOverCheck = false;
                }
                else
                    MouseOverCheck = false;
 
                if (e.X > GroupStartX + 21 && e.X < GroupStartX + 21 + 16)
                {
                    if (item_draw_index.Duplicate == -1)
                    {
                        //DuplicateGroupStatus.SetToolTip(this, "True duplicate group based on actual data");
 
                        if (MouseOverGroupStatus == false)
                        {
                            MouseOverGroupStatus = true;
 
                            if(item_draw_index.Data[item_draw_index.Group].State == DuplicateGroup.GroupState.TrueDuplicate)
                                DuplicateGroupStatus.Show("Verified duplicate group based on actual data", this);
                            else if (item_draw_index.Data[item_draw_index.Group].State == DuplicateGroup.GroupState.FalseDuplicate)
                                DuplicateGroupStatus.Show("Duplicate group only by filename and NOT by actual data", this);
                            else
                                DuplicateGroupStatus.Show("Duplicate group by filename, but actual data status is unknown", this);
                        }
                    }
                }
                else
                {
                    MouseOverGroupStatus = false;
                    DuplicateGroupStatus.Hide(this);
                }
            }
 
            Invalidate();
        }
 
        private void DuplicateListView_MouseDown(object sender, MouseEventArgs e)
        {
            int item_index = PointToItem(e.Location);
            int i;
            DrawIndex item_draw_index = null;
            DuplicateObject duplicate_object= null;
 
            if (DrawStartIndex.Data.Count > 0)
            {
                // get the item the user
                item_draw_index = new DrawIndex(DrawStartIndex.Group, DrawStartIndex.Duplicate, DrawStartIndex.Data);
 
                if(item_draw_index.Increment(item_index) == DrawIndex.IndexReturnStatus.Exists)
                    duplicate_object = item_draw_index.ReturnDrawableItem();
            }
 
            // the user clicked on the File column sizing grip
            if (e.Y < 21 && e.X >= Columns[0].Width - 4 - horizontalScrollbar.Value && e.X <= Columns[0].Width + 4 - horizontalScrollbar.Value)
            {
                MouseOnFileGrip = true;
                MouseFileGripDown = true;
                Cursor.Current = Cursors.VSplit;
            }
 
            // the user clicked on the Size column sizing grip
            else if (e.Y < 21 && e.X >= Columns[0].Width + Columns[1].Width - 4 - horizontalScrollbar.Value && e.X <= Columns[0].Width + Columns[1].Width + 4 - horizontalScrollbar.Value)
            {
                MouseOnSizeGrip = true;
                MouseSizeGripDown = true;
                Cursor.Current = Cursors.VSplit;
            }
 
            // the user clicked on the Date column sizing grip
            else if (e.Y < 21 && e.X >= Columns[0].Width + Columns[1].Width + Columns[2].Width - 4 - horizontalScrollbar.Value && e.X <= Columns[0].Width + Columns[1].Width + Columns[2].Width + 4 - horizontalScrollbar.Value)
            {
                MouseOnDateGrip = true;
                MouseDateGripDown = true;
                Cursor.Current = Cursors.VSplit;
            }
 
            // the mouse isn't on any sizing grip
            else
            {
                MouseOnFileGrip = false;
                MouseOnSizeGrip = false;
                MouseOnDateGrip = false;
                MouseFileGripDown = false;
                MouseSizeGripDown = false;
                MouseDateGripDown = false;
                Cursor.Current = Cursors.Default;
            }
 
            // see if the mouse is down in the item area
            if (e.Y <= 21)
                MouseOnItemArea = false;
            else
                MouseOnItemArea = true;
 
            if(DrawStartIndex.Data.Count > 0)
            {
                // the mouse is over a checkmark of a group
                if (e.X >= GroupStartX - horizontalScrollbar.Value && e.X < GroupStartX - horizontalScrollbar.Value + 15 && e.Y >= 21 + (ItemHeight * item_index) && e.Y < 21 + (ItemHeight * item_index) + 16 && duplicate_object.ObjectType == DuplicateObject.Type.Group)
                {
                    MouseOverCheck = true;
                    MouseOverCheckIndex = item_index;
                    CheckDown = true;
 
                    int check_state = duplicate_object.DuplicateGroup.GetGroupCheckState();
 
                    if (check_state == 1 || check_state == 3)
                    {
                        for (i = 0; i < duplicate_object.DuplicateGroup.Count; i++)
                        {
                            duplicate_object.DuplicateGroup[i].Checked = false;
 
                            if (ItemChecked != null)
                                ItemChecked(new ItemCheckedArgs(item_draw_index.Duplicate, item_draw_index));
                        }
                    }
                    else
                    {
                        for (i = 0; i < duplicate_object.DuplicateGroup.Count; i++)
                        {
                            duplicate_object.DuplicateGroup[i].Checked = true;
 
                            if (ItemChecked != null)
                                ItemChecked(new ItemCheckedArgs(item_draw_index.Duplicate, item_draw_index));
                        }
                    }
 
                    DrawParam = RedrawParam.Items;
                    Invalidate();
 
                    return;
                }
 
                // the mouse is over the checkmark of an item
                else if (e.X >= GroupStartX + 13 - horizontalScrollbar.Value && e.X < GroupStartX + 13 - horizontalScrollbar.Value + 15 && e.Y >= 21 + (ItemHeight * item_index) && e.Y < 21 + (ItemHeight * item_index) + 16 && duplicate_object.ObjectType == DuplicateObject.Type.File)
                {
                    MouseOverCheck = true;
                    MouseOverCheckIndex = item_index;
                    CheckDown = true;
 
                    item_draw_index.ReturnDrawableItem().DuplicateFile.Checked = !item_draw_index.ReturnDrawableItem().DuplicateFile.Checked;
 
                    if (item_draw_index.ReturnDrawableItem().DuplicateFile.Checked == true)
                    {
 
                        if (ItemChecked != null)
                            ItemChecked(new ItemCheckedArgs(item_draw_index.Duplicate, item_draw_index));
                    }
                    else
                    {
 
                        if (ItemChecked != null)
                            ItemChecked(new ItemCheckedArgs(item_draw_index.Duplicate, item_draw_index));
                    }
 
                    DrawParam = RedrawParam.Items;
                    Invalidate();
 
                    return;
                }
 
                // the user clicked the delete button
                if (e.X - horizontalScrollbar.Value >= Columns[0].Width + Columns[1].Width + Columns[2].Width + 7 - horizontalScrollbar.Value && e.X - horizontalScrollbar.Value < Columns[0].Width + Columns[1].Width + Columns[2].Width - horizontalScrollbar.Value + 75)
                {
                    MouseOverDeleteIndex = item_index;
 
                    DeleteLinkItem = new DrawIndex(DrawStartIndex.Group, DrawStartIndex.Duplicate, DrawStartIndex.Data);
                    DeleteLinkItem.Increment(item_index);
 
                    MouseOverDelete = true;
                    DeleteButtonDown = true;
 
                    DrawParam = RedrawParam.Items;
                    Invalidate();
 
                    return;
                }
 
                // the user clicked the link button
                if (e.X - horizontalScrollbar.Value >= Columns[0].Width + Columns[1].Width + Columns[2].Width + 87 - horizontalScrollbar.Value && e.X - horizontalScrollbar.Value < Columns[0].Width + Columns[1].Width + Columns[2].Width + 162 - horizontalScrollbar.Value && duplicate_object.ObjectType == DuplicateObject.Type.File && duplicate_object.DuplicateFile.Parent.State == DuplicateGroup.GroupState.TrueDuplicate)
                {
                    MouseOverLinkIndex = item_index;
 
                    DeleteLinkItem = new DrawIndex(DrawStartIndex.Group, DrawStartIndex.Duplicate, DrawStartIndex.Data);
                    DeleteLinkItem.Increment(item_index);
 
                    MouseOverLink = true;
                    LinkButtonDown = true;
 
                    DrawParam = RedrawParam.Items;
                    Invalidate();
 
                    return;
                }
 
                if (item_index != -1)
                {
 
                    SelectedItem.Group = item_draw_index.Group;
                    SelectedItem.Duplicate = item_draw_index.Duplicate;
                    SelectedItem.Data = DrawStartIndex.Data;
                }
                else
                {
                    if(e.Y > 21)
                    {
                        SelectedItem.Group = -1;
                        SelectedItem.Duplicate = -1;
                    }
                }
        }
 
            Invalidate();
        }
 
        private void DuplicateListView_MouseUp(object sender, MouseEventArgs e)
        {
            if (DeleteButtonDown == true && DeleteButtonClicked != null)
            {
                DeleteButtonClicked(new ItemButtonClickedArgs(MouseOverDeleteIndex, DeleteLinkItem.Group, DeleteLinkItem.Duplicate));
            }
 
            if (LinkButtonDown == true && LinkButtonClicked != null)
            {
                LinkButtonClicked(new ItemButtonClickedArgs(MouseOverDeleteIndex, DeleteLinkItem.Group, DeleteLinkItem.Duplicate));
            }
 
            DeleteButtonDown = false;
            LinkButtonDown = false;
            CheckDown = false;
 
            MouseFileGripDown = false;
            MouseSizeGripDown = false;
            MouseDateGripDown = false;
 
            DrawParam = RedrawParam.Items;
            Invalidate();
        }
 
        private void DuplicateListView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            // don't trigger if the mouse is over the link or delete buttons
            if (ItemDoubleClicked != null && PointToItem(new Point(e.X, e.Y)) != -1)
            {
                if (MouseOverDelete == false && MouseOverLink == false && MouseOverCheck == false)
                {
                    int clicked_index = PointToItem(e.Location);
                    DrawIndex item_index = new DrawIndex(DrawStartIndex.Group, DrawStartIndex.Duplicate, DrawStartIndex.Data);
 
                    item_index.Increment(clicked_index);
 
                    ItemDoubleClicked(new ItemDoubleClickedArgs(clicked_index, item_index));
                }
            }
        }
 
        private void DuplicateListView_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                if(ItemRightClicked != null)
                    ItemRightClicked(e);
            }
        }
 
        private void horizontalScrollbar_ValueChanged(object sender, EventArgs e)
        {
            if (ListChanged != null)
                ListChanged(new EventArgs());
 
            DrawParam = RedrawParam.All;
            Invalidate();
        }
 
        private void verticalScrollbar_ValueChanged(ScrollEventArgs e)
        {
            if (EnsureVisibleEvent == false)
            {
                if (verticalScrollbar.Value == 0)
                {
                    DrawStartIndex.Group = 0;
                    DrawStartIndex.Duplicate = -1;
                }
 
                if (DataRemoved == true)
                    DataRemoved = false;
                else
                {
                    if (verticalScrollbar.Value < OldVerticalScrollBarValue)
                        DrawStartIndex.Decrement(OldVerticalScrollBarValue - verticalScrollbar.Value);
                    else
                        DrawStartIndex.Increment(verticalScrollbar.Value - OldVerticalScrollBarValue);
                }
 
                DrawParam = RedrawParam.All;
                Invalidate();
            }
 
            OldVerticalScrollBarValue = verticalScrollbar.Value;
            EnsureVisibleEvent = false;
        }
 
        private void DuplicateListView_Resize(object sender, EventArgs e)
        {
          //  verticalScrollbar.
          //  verticalScrollbar.StepIncrementer = MaximumVisibleItems();
        }
 
        public void EnsureVisible(DrawIndex index)
        {
            EnsureVisibleEvent = true;
            DrawStartIndex.Group = index.Group;
            DrawStartIndex.Duplicate = index.Duplicate;
 
            this.Invoke((MethodInvoker)delegate
            {
                verticalScrollbar.Value = DrawStartIndex.Data.ComputeRollingTotal(index);
            });
 
            Invalidate();
        }
 
        private void verticalScrollbar_ValueChanged(Object sender, ScrollEventArgs e)
        {
            if (EnsureVisibleEvent == false)
            {
                if (verticalScrollbar.Value == 0)
                {
                    DrawStartIndex.Group = 0;
                    DrawStartIndex.Duplicate = -1;
                }
 
                if (DataRemoved == true)
                    DataRemoved = false;
                else
                {
                    if (verticalScrollbar.Value < OldVerticalScrollBarValue)
                        DrawStartIndex.Decrement(OldVerticalScrollBarValue - verticalScrollbar.Value);
                    else
                        DrawStartIndex.Increment(verticalScrollbar.Value - OldVerticalScrollBarValue);
                }
 
                Invalidate();
            }
            else
            {
                // verticalScrollbar.RedrawOnValueChange = false;
 
            }
 
            OldVerticalScrollBarValue = verticalScrollbar.Value;
            EnsureVisibleEvent = false;
 
            if (ListChanged != null)
                ListChanged(new EventArgs());
        }
 
 
        public HighlightedIndexCollection HighLightedIndexes;
 
        public class HighlightedIndexCollection : ArrayList
        {
            public DuplicateListView Owner;
 
            bool _suspendEventNotification;
            public bool SuspendEventNotification
            {
                get
                {
                    return _suspendEventNotification;
                }
                set
                {
                    _suspendEventNotification = value;
 
                    if (value == false)
                    {
                        if (Owner.HighlightedItemsUpdated != null)
                            Owner.HighlightedItemsUpdated(new EventArgs());
                    }
                }
            }
 
            public int Add(int value)
            {
                if (Owner.DrawStartIndex.Data.Count == 0)
                    Owner.PopoutScrollBar();
 
                int return_val = base.Add(value);
 
                if (_suspendEventNotification == false)
                {
                    Owner.Invalidate();
 
                    if (Owner.HighlightedItemsUpdated != null)
                        Owner.HighlightedItemsUpdated(new EventArgs());
                }
 
                if (Owner.ListChanged != null)
                    Owner.ListChanged(new EventArgs());
 
                return return_val;
            }
 
            public override void Clear()
            {
                if (Owner.DrawStartIndex.Data.Count > 0)
                    Owner.PopinScrollBar();
 
                base.Clear();
 
                if (Owner.ListChanged != null)
                    Owner.ListChanged(new EventArgs());
 
                Owner.Invalidate();
            }
 
            public new int this[int index]
            {
                get
                {
                    return (int)base[index];
                }
                set
                {
                    base[index] = value;
                }
            }
 
            public new void RemoveAt(int index)
            {
                if (Owner.DrawStartIndex.Data.Count > 0)
                    Owner.PopinScrollBar();
 
                if (Owner.ListChanged != null)
                    Owner.ListChanged(new EventArgs());
            }
 
            public HighlightedIndexCollection(DuplicateListView owner)
            {
                Owner = owner;
            }
 
 
        }
 
        public void PopoutScrollBar()
        {
           // verticalScrollbar.Location = new Point(Width - 16, 21);
        }
 
        public void PopinScrollBar()
        {
           // verticalScrollbar.Location = new Point(Width - 32, 21);
        }
 
        private void DrawLineIndexes(PaintEventArgs e)
        {
            int i;
            double position;
 
            e.Graphics.SetClip(new Rectangle(this.Width - 34, 21, 17, this.Height-16));
 
            e.Graphics.Clear(Color.White);
 
 
            for (i = 0; i < HighLightedIndexes.Count; i++)
            {
                position = ConvertIndexToScrollBarPosition(HighLightedIndexes[i]);
               // e.Graphics.DrawLine(Pens.Blue, this.Width - 32, 25 + Convert.ToSingle(position + AdjustScrollBarLine(HighLightedIndexes[i])), this.Width-16, 25 + Convert.ToSingle(position + AdjustScrollBarLine(HighLightedIndexes[i])));
               // e.Graphics.DrawLine(Pens.Blue, this.Width-32, 25 + Convert.ToSingle(position + 1 + AdjustScrollBarLine(HighLightedIndexes[i])), this.Width-16, 25 + Convert.ToSingle(position + 1 + AdjustScrollBarLine(HighLightedIndexes[i])));
 
                e.Graphics.DrawLine(Pens.Blue, this.Width - 32,   Convert.ToSingle(position + AdjustScrollBarLine(HighLightedIndexes[i])), this.Width - 15,  Convert.ToSingle(position + AdjustScrollBarLine(HighLightedIndexes[i])));
                e.Graphics.DrawLine(Pens.Blue, this.Width - 32,   Convert.ToSingle(position + 1 + AdjustScrollBarLine(HighLightedIndexes[i])), this.Width - 15,  Convert.ToSingle(position + 1 + AdjustScrollBarLine(HighLightedIndexes[i])));
            }
 
            e.Graphics.DrawLine(Pens.Gray, new Point(this.Width - 33, 21), new Point(this.Width - 33, this.Height));
            e.Graphics.DrawLine(Pens.LightGray, new Point(this.Width - 32, 21), new Point(this.Width - 32, this.Height));
 
 
        }
 
        private double AdjustScrollBarLine(double position)
        {
            double percentage_position_half;
 
            // get the percentage of the position in relation to half the number of total items
            percentage_position_half = position / (DrawStartIndex.Data.GroupDuplicateTotal / 2);
 
            return 18 - (18 * percentage_position_half);
        }
 
        public double ConvertIndexToScrollBarPosition(int index)
        {
            double percent_of_items = (double)100 / DrawStartIndex.Data.GroupDuplicateTotal * index;
            double percent_of_scrollbar = GetPercentOfScrollBar(percent_of_items);
 
            return percent_of_scrollbar;
        }
 
        public double GetPercentOfScrollBar(double percent)
        {
            int height = Height - 25;
            return height * ((double)percent) / ((double)100);
        }
 
        private void verticalScrollbar_ValueChanged(object sender, EventArgs e)
        {
            if (EnsureVisibleEvent == false)
            {
                if (verticalScrollbar.Value == 0)
                {
                    DrawStartIndex.Group = 0;
                    DrawStartIndex.Duplicate = -1;
                }
 
                if (DataRemoved == true)
                    DataRemoved = false;
                else
                {
                    if (verticalScrollbar.Value < OldVerticalScrollBarValue)
                        DrawStartIndex.Decrement(OldVerticalScrollBarValue - verticalScrollbar.Value);
                    else
                        DrawStartIndex.Increment(verticalScrollbar.Value - OldVerticalScrollBarValue);
                }
 
                Invalidate();
            }
 
            OldVerticalScrollBarValue = verticalScrollbar.Value;
            EnsureVisibleEvent = false;
 
            if (ListChanged != null)
                ListChanged(new EventArgs());
        }
 
        private void DuplicateListView_KeyDown(object sender, KeyEventArgs e)
        {
            if (SelectedItem.InBoundsIncremented(1) == DrawIndex.IndexReturnStatus.Exists && e.KeyCode == Keys.Down)
                SelectedItem.Increment();
            if (SelectedItem.InBoundsDecremented(1) == DrawIndex.IndexReturnStatus.Exists && e.KeyCode == Keys.Up)
                SelectedItem.Decrement();
 
            if (e.KeyCode == Keys.Down && DrawStartIndex.Group + DrawStartIndex.Duplicate + (DrawStartIndex.Duplicate == -1 ? 1 : 0) + MaximumVisibleItems() > SelectedItem.Group + SelectedItem.Duplicate + (SelectedItem.Duplicate == -1 ? 1 : 0))
            {
                EnsureVisibleEvent = true;
                DrawStartIndex = new DrawIndex(SelectedItem.Group, SelectedItem.Duplicate, SelectedItem.Data);
                DrawStartIndex.Decrement(MaximumVisibleItems() - 1);
                if (verticalScrollbar.Value < verticalScrollbar.Maximum)
                    verticalScrollbar.Value += 1;
                EnsureVisibleEvent = false;
            }
            if (e.KeyCode == Keys.Up && DrawStartIndex.Group + DrawStartIndex.Duplicate + (DrawStartIndex.Duplicate == -1 ? 1 : 0) >= SelectedItem.Group + SelectedItem.Duplicate + (SelectedItem.Duplicate == -1 ? 1 : 0))
            {
                EnsureVisibleEvent = true;
                DrawStartIndex = new DrawIndex(SelectedItem.Group, SelectedItem.Duplicate, SelectedItem.Data);
                if(verticalScrollbar.Value > 0)
                    verticalScrollbar.Value -= 1;
                EnsureVisibleEvent = false;
            }
 
            verticalScrollbar.Invalidate();
            Invalidate();
        }
 
        protected override bool IsInputKey(System.Windows.Forms.Keys keyData)
        {
            if (keyData == Keys.Down || keyData == Keys.Up)
                return true;
 
                return base.IsInputKey(keyData);
        }
 
 
    }
 
   
 
}