-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPictureViewPanel.cs
119 lines (104 loc) · 3.66 KB
/
PictureViewPanel.cs
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PhotoPrinter
{
public enum PictureSelectionMode
{
None,
All,
Inverse
}
public class PictureViewPanel : FlowLayoutPanel
{
PictureViewBox m_lastSelected = null;
public PictureViewPanel()
{
this.MouseClick += new MouseEventHandler((object sender, MouseEventArgs e) => {
});
}
public bool Add(string filename)
{
PictureViewBox pvb = PictureViewBox.Create(filename);
if (pvb != null)
{
pvb.SelectionChangeRequested += new PictureViewBoxSelectionChangedEventHandler((PictureViewBox sender) => {
HandlePictureViewBoxSelectionChangeEvent(sender);
});
this.Controls.Add(pvb);
}
return (pvb != null);
}
public void Select(PictureSelectionMode selectionMode)
{
foreach (Control control in this.Controls)
{
PictureViewBox pvb = (PictureViewBox)control;
switch (selectionMode)
{
case PictureSelectionMode.All:
pvb.Select(true);
break;
case PictureSelectionMode.Inverse:
pvb.Select(!pvb.IsSelected);
break;
case PictureSelectionMode.None:
pvb.Select(false);
break;
}
}
}
public IEnumerable<PictureViewBox> GetSelected()
{
foreach (Control control in this.Controls)
{
PictureViewBox pvb = (PictureViewBox)control;
if (pvb.IsSelected)
{
yield return pvb;
}
}
}
private void HandlePictureViewBoxSelectionChangeEvent(PictureViewBox pvb)
{
if (Control.ModifierKeys == Keys.None || m_lastSelected == null)
{
this.Select(PictureSelectionMode.None);
pvb.Select(true);
}
else
{
if (Control.ModifierKeys.HasFlag(Keys.Shift))
{
int indexOfLastSelected = this.Controls.IndexOf(m_lastSelected);
int indexOfNextSelected = this.Controls.IndexOf(pvb);
if (indexOfLastSelected < indexOfNextSelected)
{
for (int current_pvb_index = indexOfLastSelected + 1; current_pvb_index <= indexOfNextSelected; current_pvb_index++)
{
PictureViewBox current_pvb = (PictureViewBox)this.Controls[current_pvb_index];
current_pvb.Select(true);
}
}
else
{
for (int current_pvb_index = indexOfLastSelected - 1; current_pvb_index >= indexOfNextSelected; current_pvb_index--)
{
PictureViewBox current_pvb = (PictureViewBox)this.Controls[current_pvb_index];
current_pvb.Select(true);
}
}
}
else if (Control.ModifierKeys.HasFlag(Keys.Control))
{
pvb.Select(!pvb.IsSelected);
}
}
m_lastSelected = pvb;
}
}
}