OSDN Git Service

一覧ウィンドウを装備に切り替えたときに直前の表示が残ることがあるのを直す
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / ShipListForm.cs
1 // Copyright (C) 2014 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>\r
2 // \r
3 // This program is part of KancolleSniffer.\r
4 //\r
5 // KancolleSniffer is free software: you can redistribute it and/or modify\r
6 // it under the terms of the GNU General Public License as published by\r
7 // the Free Software Foundation, either version 3 of the License, or\r
8 // (at your option) any later version.\r
9 //\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
14 //\r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, see <http://www.gnu.org/licenses/>.\r
17 \r
18 using System;\r
19 using System.Collections.Generic;\r
20 using System.Drawing;\r
21 using System.Linq;\r
22 using System.Windows.Forms;\r
23 using ContentAlignment = System.Drawing.ContentAlignment;\r
24 \r
25 namespace KancolleSniffer\r
26 {\r
27     public partial class ShipListForm : Form\r
28     {\r
29         private readonly Sniffer _sniffer;\r
30         private readonly Config _config;\r
31         private const int LabelHeight = 12;\r
32         private const int LineHeight = 16;\r
33         private const int PanelWidth = 217;\r
34         private ShipStatus[] _shipList;\r
35         private readonly List<ShipLabel[]> _labelList = new List<ShipLabel[]>();\r
36         private readonly List<Panel> _labelPanelList = new List<Panel>();\r
37         private readonly List<CheckBox[]> _checkBoxesList = new List<CheckBox[]>();\r
38         private readonly List<ShipLabel[]> _configLabelList = new List<ShipLabel[]>();\r
39         private readonly List<Panel> _checkBoxPanelList = new List<Panel>();\r
40         private readonly List<ShipLabel[]> _repairLabelList = new List<ShipLabel[]>();\r
41         private readonly List<Panel> _repairPanelList = new List<Panel>();\r
42         public const int GroupCount = 4;\r
43         private readonly HashSet<int>[] _groupSettings = new HashSet<int>[GroupCount];\r
44         private TreeNode _itemTreeNode;\r
45         private ItemStatus[] _prevItemList;\r
46 \r
47         public ShipListForm(Sniffer sniffer, Config config)\r
48         {\r
49             InitializeComponent();\r
50             _sniffer = sniffer;\r
51             _config = config;\r
52         }\r
53 \r
54         public void UpdateList()\r
55         {\r
56             panelItemHeader.Visible = InItemList();\r
57             treeViewItem.Visible = InItemList();\r
58             if (InItemList())\r
59             {\r
60                 HideShipLabels();\r
61                 if (CreateItemList())\r
62                     SetTreeViewItem();\r
63             }\r
64             else\r
65             {\r
66                 CreateShipList();\r
67                 CreateListLabels();\r
68                 SetShipLabels();\r
69             }\r
70         }\r
71 \r
72         private void CreateShipList()\r
73         {\r
74             var ships = InRepairList() ? _sniffer.DamagedShipList : FilterByGroup(_sniffer.ShipList).ToArray();\r
75             if (!_config.ShipList.ShipType)\r
76             {\r
77                 _shipList = ships.OrderBy(s => s, new CompareShip(false, InRepairList())).ToArray();\r
78                 return;\r
79             }\r
80             var types = ships.Select(s => new {Id = s.Spec.ShipType, Name = s.Spec.ShipTypeName}).Distinct().\r
81                 Select(stype =>\r
82                     new ShipStatus\r
83                     {\r
84                         Spec = new ShipSpec {Name = stype.Name, ShipType = stype.Id},\r
85                         Level = 1000,\r
86                         NowHp = -1000\r
87                     });\r
88             _shipList = ships.Concat(types).OrderBy(s => s, new CompareShip(true, InRepairList())).ToArray();\r
89         }\r
90 \r
91         private IEnumerable<ShipStatus> FilterByGroup(IEnumerable<ShipStatus> ships)\r
92         {\r
93             var g = Array.FindIndex(new[] {"A", "B", "C", "D"}, x => x == comboBoxGroup.Text);\r
94             if (g == -1)\r
95                 return ships;\r
96             return from s in ships where _groupSettings[g].Contains(s.Id) select s;\r
97         }\r
98 \r
99         private class CompareShip : IComparer<ShipStatus>\r
100         {\r
101             private readonly bool _type;\r
102             private readonly bool _repair;\r
103 \r
104             public CompareShip(bool type, bool repair)\r
105             {\r
106                 _type = type;\r
107                 _repair = repair;\r
108             }\r
109 \r
110             public int Compare(ShipStatus a, ShipStatus b)\r
111             {\r
112                 if (_type && a.Spec.ShipType != b.Spec.ShipType)\r
113                     return a.Spec.ShipType - b.Spec.ShipType;\r
114                 if (_repair && a.RepairTime != b.RepairTime)\r
115                     return (int)(b.RepairTime - a.RepairTime).TotalSeconds;\r
116                 if (a.Level != b.Level)\r
117                     return b.Level - a.Level;\r
118                 if (a.ExpToNext != b.ExpToNext)\r
119                     return a.ExpToNext - b.ExpToNext;\r
120                 return a.Spec.Id - b.Spec.Id;\r
121             }\r
122         }\r
123 \r
124         private bool CreateItemList()\r
125         {\r
126             var itemList = _sniffer.ItemList;\r
127             if (_prevItemList != null && _prevItemList.SequenceEqual(itemList, new ItemStatusComparer()))\r
128                 return false;\r
129             _prevItemList = itemList.Select(CloneItemStatus).ToArray();\r
130             var grouped = from byId in\r
131                 (from item in itemList where item.Spec.Id != -1\r
132                     orderby item.Spec.Type, item.Spec.Id, item.Level descending, item.Ship.Spec.Id\r
133                     group item by new {item.Spec.Id, item.Level})\r
134                 group byId by byId.First().Spec.Type;\r
135             _itemTreeNode = new TreeNode();\r
136             foreach (var byType in grouped)\r
137             {\r
138                 var typeName = byType.First().First().Spec.TypeName;\r
139                 var typeNode = new TreeNode();\r
140                 typeNode.Name = typeNode.Text = typeName;\r
141                 _itemTreeNode.Nodes.Add(typeNode);\r
142                 foreach (var byItem in byType)\r
143                 {\r
144                     var item = byItem.First();\r
145                     var itemNode = new TreeNode();\r
146                     itemNode.Name = itemNode.Text = item.Spec.Name + (item.Level == 0 ? "" : "★" + item.Level);\r
147                     typeNode.Nodes.Add(itemNode);\r
148 \r
149                     var shipGroup = (from i in byItem group i.Ship by i.Ship.Id).ToArray();\r
150                     foreach (var name in\r
151                         from grp in shipGroup where grp.Key != -1\r
152                         let ship = grp.First()\r
153                         select (ship.Fleet != -1 ? ship.Fleet + 1 + " " : "") +\r
154                                ship.Name + "Lv" + ship.Level + "×" + grp.Count())\r
155                     {\r
156                         itemNode.Nodes.Add(name, name);\r
157                     }\r
158                     foreach (var name in (from grp in shipGroup where grp.Key == -1 select "未装備×" + grp.Count()))\r
159                     {\r
160                         itemNode.Nodes.Add(name, name);\r
161                     }\r
162                 }\r
163             }\r
164             return true;\r
165         }\r
166 \r
167         private ItemStatus CloneItemStatus(ItemStatus org)\r
168         {\r
169             return new ItemStatus\r
170             {\r
171                 Level = org.Level,\r
172                 Spec = org.Spec,\r
173                 Ship = new ShipStatus {Id = org.Ship.Id, Fleet = org.Ship.Fleet}\r
174             };\r
175         }\r
176 \r
177         private class ItemStatusComparer : IEqualityComparer<ItemStatus>\r
178         {\r
179             public bool Equals(ItemStatus x, ItemStatus y)\r
180             {\r
181                 return x.Level == y.Level && x.Spec == y.Spec && x.Ship.Id == y.Ship.Id && x.Ship.Fleet == y.Ship.Fleet;\r
182             }\r
183 \r
184             public int GetHashCode(ItemStatus obj)\r
185             {\r
186                 return obj.Level + obj.Spec.GetHashCode() + obj.Ship.GetHashCode();\r
187             }\r
188         }\r
189 \r
190         private void CreateListLabels()\r
191         {\r
192             panelShipList.SuspendLayout();\r
193             for (var i = _labelList.Count; i < _shipList.Length; i++)\r
194             {\r
195                 CreateConfigComponents(i);\r
196                 CreateRepairLabels(i);\r
197                 CreateShipLabels(i);\r
198             }\r
199             panelShipList.ResumeLayout();\r
200         }\r
201 \r
202         private void CreateConfigComponents(int i)\r
203         {\r
204             var y = 3 + LineHeight * i;\r
205             var cfgp = new Panel\r
206             {\r
207                 Location = new Point(0, y - 2),\r
208                 Size = new Size(PanelWidth, LineHeight - 1),\r
209                 BackColor = ShipInfoLabels.ColumnColors[(i + 1) % 2],\r
210                 Visible = false\r
211             };\r
212             cfgp.Scale(ShipLabel.ScaleFactor);\r
213             cfgp.Tag = cfgp.Location.Y;\r
214             var cfgl = new[]\r
215             {\r
216                 new ShipLabel\r
217                 {\r
218                     Location = new Point(91, 2),\r
219                     Size = new Size(23, LabelHeight),\r
220                     TextAlign = ContentAlignment.MiddleRight,\r
221                 },\r
222                 new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
223                 new ShipLabel {Location = new Point(1, 2), AutoSize = true}\r
224             };\r
225 \r
226             var cb = new CheckBox[GroupCount];\r
227             for (var j = 0; j < cb.Length; j++)\r
228             {\r
229                 cb[j] = new CheckBox\r
230                 {\r
231                     Location = new Point(125 + j * 24, 2),\r
232                     FlatStyle = FlatStyle.Flat,\r
233                     Size = new Size(12, 11),\r
234                     Tag = i * 10 + j\r
235                 };\r
236                 cb[j].Scale(ShipLabel.ScaleFactor);\r
237                 cb[j].CheckedChanged += checkboxGroup_CheckedChanged;\r
238             }\r
239             _configLabelList.Add(cfgl);\r
240             _checkBoxesList.Add(cb);\r
241             _checkBoxPanelList.Add(cfgp);\r
242 // ReSharper disable CoVariantArrayConversion\r
243             cfgp.Controls.AddRange(cfgl);\r
244             cfgp.Controls.AddRange(cb);\r
245             // ReSharper restore CoVariantArrayConversion\r
246             panelShipList.Controls.Add(cfgp);\r
247             foreach (var label in cfgl)\r
248             {\r
249                 label.Scale(ShipLabel.ScaleFactor);\r
250                 label.PresetColor =\r
251                     label.BackColor = ShipInfoLabels.ColumnColors[(i + 1) % 2];\r
252             }\r
253         }\r
254 \r
255         private void CreateRepairLabels(int i)\r
256         {\r
257             var y = 3 + LineHeight * i;\r
258             const int height = LabelHeight;\r
259             var rpp = new Panel\r
260             {\r
261                 Location = new Point(0, y - 2),\r
262                 Size = new Size(PanelWidth, LineHeight - 1),\r
263                 BackColor = ShipInfoLabels.ColumnColors[(i + 1) % 2],\r
264                 Visible = false\r
265             };\r
266             rpp.Scale(ShipLabel.ScaleFactor);\r
267             rpp.Tag = rpp.Location.Y;\r
268             var rpl = new[]\r
269             {\r
270                 new ShipLabel {Location = new Point(118, 2), AutoSize = true, AnchorRight = true},\r
271                 new ShipLabel\r
272                 {\r
273                     Location = new Point(117, 2),\r
274                     Size = new Size(23, height),\r
275                     TextAlign = ContentAlignment.MiddleRight\r
276                 },\r
277                 new ShipLabel {Location = new Point(141, 2), AutoSize = true},\r
278                 new ShipLabel {Location = new Point(186, 2), AutoSize = true},\r
279                 new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
280                 new ShipLabel {Location = new Point(1, 2), AutoSize = true}\r
281             };\r
282             _repairLabelList.Add(rpl);\r
283             _repairPanelList.Add(rpp);\r
284 // ReSharper disable once CoVariantArrayConversion\r
285             rpp.Controls.AddRange(rpl);\r
286             panelShipList.Controls.Add(rpp);\r
287             foreach (var label in rpl)\r
288             {\r
289                 label.Scale(ShipLabel.ScaleFactor);\r
290                 label.PresetColor =\r
291                     label.BackColor = ShipInfoLabels.ColumnColors[(i + 1) % 2];\r
292             }\r
293         }\r
294 \r
295         private void CreateShipLabels(int i)\r
296         {\r
297             var y = 3 + LineHeight * i;\r
298             const int height = LabelHeight;\r
299             var lbp = new Panel\r
300             {\r
301                 Location = new Point(0, y - 2),\r
302                 Size = new Size(PanelWidth, LineHeight - 1),\r
303                 BackColor = ShipInfoLabels.ColumnColors[(i + 1) % 2],\r
304                 Visible = false\r
305             };\r
306             lbp.Scale(ShipLabel.ScaleFactor);\r
307             lbp.Tag = lbp.Location.Y;\r
308             var labels = new[]\r
309             {\r
310                 new ShipLabel {Location = new Point(126, 2), AutoSize = true, AnchorRight = true},\r
311                 new ShipLabel\r
312                 {\r
313                     Location = new Point(129, 2),\r
314                     Size = new Size(23, height),\r
315                     TextAlign = ContentAlignment.MiddleRight\r
316                 },\r
317                 new ShipLabel\r
318                 {\r
319                     Location = new Point(155, 2),\r
320                     Size = new Size(23, height),\r
321                     TextAlign = ContentAlignment.MiddleRight\r
322                 },\r
323                 new ShipLabel\r
324                 {\r
325                     Location = new Point(176, 2),\r
326                     Size = new Size(41, height),\r
327                     TextAlign = ContentAlignment.MiddleRight\r
328                 },\r
329                 new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
330                 new ShipLabel {Location = new Point(1, 2), AutoSize = true}\r
331             };\r
332             _labelList.Add(labels);\r
333             _labelPanelList.Add(lbp);\r
334 // ReSharper disable once CoVariantArrayConversion\r
335             lbp.Controls.AddRange(labels);\r
336             panelShipList.Controls.Add(lbp);\r
337             foreach (var label in labels)\r
338             {\r
339                 label.Scale(ShipLabel.ScaleFactor);\r
340                 label.PresetColor =\r
341                     label.BackColor = ShipInfoLabels.ColumnColors[(i + 1) % 2];\r
342             }\r
343         }\r
344 \r
345         private void SetShipLabels()\r
346         {\r
347             panelGroupHeader.Visible = InGroupConfig();\r
348             panelRepairHeader.Visible = InRepairList();\r
349             panelItemHeader.Visible = InItemList();\r
350             treeViewItem.Visible = InItemList();\r
351             panelShipList.SuspendLayout();\r
352             for (var i = 0; i < _shipList.Length; i++)\r
353             {\r
354                 var lbp = _labelPanelList[i];\r
355                 if (lbp.Visible == false && !InItemList())\r
356                 {\r
357                     lbp.Location = new Point(lbp.Left, (int)lbp.Tag + panelShipList.AutoScrollPosition.Y);\r
358                     lbp.Visible = true;\r
359                 }\r
360                 var cbp = _checkBoxPanelList[i];\r
361                 if (cbp.Visible == false && InGroupConfig())\r
362                 {\r
363                     cbp.Location = new Point(cbp.Left, (int)cbp.Tag + panelShipList.AutoScrollPosition.Y);\r
364                 }\r
365                 var rpp = _repairPanelList[i];\r
366                 if (rpp.Visible == false && InRepairList())\r
367                 {\r
368                     rpp.Location = new Point(rpp.Left, (int)rpp.Tag + panelShipList.AutoScrollPosition.Y);\r
369                 }\r
370                 var s = _shipList[i];\r
371                 var labels = _labelList[i];\r
372                 if (s.Level == 1000)\r
373                 {\r
374                     cbp.Visible = false;\r
375                     rpp.Visible = false;\r
376                     for (var c = 0; c < 6; c++)\r
377                     {\r
378                         labels[c].Text = "";\r
379                         labels[c].BackColor = labels[c].PresetColor;\r
380                     }\r
381                     labels[4].SetName("");\r
382                     labels[5].Text = s.Name;\r
383                     continue;\r
384                 }\r
385                 cbp.Visible = InGroupConfig();\r
386                 rpp.Visible = InRepairList();\r
387                 if (InGroupConfig())\r
388                 {\r
389                     var cfgl = _configLabelList[i];\r
390                     cfgl[0].SetLevel(s);\r
391                     cfgl[1].SetName(s);\r
392                     cfgl[2].SetFleet(s);\r
393                     var cb = _checkBoxesList[i];\r
394                     for (var j = 0; j < cb.Length; j++)\r
395                         cb[j].Checked = _groupSettings[j].Contains(s.Id);\r
396                 }\r
397                 else if (InRepairList())\r
398                 {\r
399                     var rpl = _repairLabelList[i];\r
400                     rpl[0].SetHp(s);\r
401                     rpl[1].SetLevel(s);\r
402                     rpl[2].SetRepairTime(s);\r
403                     rpl[3].Text = TimeSpan.FromSeconds(s.RepairSecPerHp).ToString(@"mm\:ss");\r
404                     rpl[4].SetName(s);\r
405                     rpl[5].SetFleet(s);\r
406                 }\r
407                 else\r
408                 {\r
409                     labels[0].SetHp(s);\r
410                     labels[1].SetCond(s);\r
411                     labels[2].SetLevel(s);\r
412                     labels[3].SetExpToNext(s);\r
413                 }\r
414                 labels[4].SetName(s);\r
415                 labels[5].SetFleet(s);\r
416             }\r
417             for (var i = _shipList.Length; i < _labelPanelList.Count; i++)\r
418             {\r
419                 _labelPanelList[i].Visible = false;\r
420                 _checkBoxPanelList[i].Visible = false;\r
421                 _repairPanelList[i].Visible = false;\r
422             }\r
423             panelShipList.ResumeLayout();\r
424         }\r
425 \r
426         private void HideShipLabels()\r
427         {\r
428             panelShipList.SuspendLayout();\r
429             for (var i = 0; i < _shipList.Length; i++)\r
430                 _labelPanelList[i].Visible = _checkBoxPanelList[i].Visible = _repairPanelList[i].Visible = false;\r
431             panelShipList.ResumeLayout();\r
432         }\r
433 \r
434         private void SetTreeViewItem()\r
435         {\r
436             treeViewItem.BeginUpdate();\r
437             var save = SaveTreeViewState(treeViewItem.Nodes);\r
438             treeViewItem.Nodes.Clear();\r
439             foreach (TreeNode child in _itemTreeNode.Nodes)\r
440                 treeViewItem.Nodes.Add(child);\r
441             RestoreTreeViewState(treeViewItem.Nodes, save.Nodes);\r
442             treeViewItem.EndUpdate();\r
443         }\r
444 \r
445         private TreeNode SaveTreeViewState(TreeNodeCollection nodes)\r
446         {\r
447             var result = new TreeNode();\r
448             foreach (TreeNode child in nodes)\r
449             {\r
450                 var copy = SaveTreeViewState(child.Nodes);\r
451                 if (child.IsExpanded)\r
452                     copy.Expand();\r
453                 copy.Name = child.Name;\r
454                 result.Nodes.Add(copy);\r
455             }\r
456             return result;\r
457         }\r
458 \r
459         private void RestoreTreeViewState(TreeNodeCollection dst, TreeNodeCollection src)\r
460         {\r
461             foreach (TreeNode d in dst)\r
462             {\r
463                 var s = src[d.Name];\r
464                 if (s == null)\r
465                     continue;\r
466                 if (s.IsExpanded)\r
467                     d.Expand();\r
468                 RestoreTreeViewState(d.Nodes, s.Nodes);\r
469             }\r
470         }\r
471 \r
472         private bool InGroupConfig()\r
473         {\r
474             return comboBoxGroup.Text == "分類";\r
475         }\r
476 \r
477         private bool InRepairList()\r
478         {\r
479             return comboBoxGroup.Text == "修復";\r
480         }\r
481 \r
482         private bool InItemList()\r
483         {\r
484             return comboBoxGroup.Text == "装備";\r
485         }\r
486 \r
487         private void ShipListForm_Load(object sender, EventArgs e)\r
488         {\r
489             panelShipList.Width = (int)Math.Round(PanelWidth * ShipLabel.ScaleFactor.Width) + 3 +\r
490                                   SystemInformation.VerticalScrollBarWidth;\r
491             Width = panelShipList.Width + 12 + (Width - ClientSize.Width);\r
492             MinimumSize = new Size(Width, 0);\r
493             MaximumSize = new Size(Width, int.MaxValue);\r
494             var config = _config.ShipList;\r
495             checkBoxShipType.Checked = config.ShipType;\r
496             ActiveControl = panelShipList;\r
497             for (var i = 0; i < GroupCount; i++)\r
498                 _groupSettings[i] = new HashSet<int>(config.ShipGroup[i]);\r
499             comboBoxGroup.SelectedIndex = 0;\r
500             if (config.Location.X == int.MinValue)\r
501                 return;\r
502             var bounds = new Rectangle(config.Location, config.Size);\r
503             if (MainForm.IsVisibleOnAnyScreen(bounds))\r
504                 Location = bounds.Location;\r
505             Height = bounds.Height;\r
506         }\r
507 \r
508         private void ShipListForm_FormClosing(object sender, FormClosingEventArgs e)\r
509         {\r
510             var config = _config.ShipList;\r
511             var all = _sniffer.ShipList.Select(s => s.Id).ToArray();\r
512             for (var i = 0; i < GroupCount; i++)\r
513             {\r
514                 if (_groupSettings[i] == null)\r
515                     break;\r
516                 if (all.Count() > 0)\r
517                     _groupSettings[i].IntersectWith(all);\r
518                 config.ShipGroup[i] = _groupSettings[i].ToList();\r
519             }\r
520             e.Cancel = true;\r
521             if (!Visible)\r
522                 return;\r
523             var bounds = WindowState == FormWindowState.Normal ? Bounds : RestoreBounds;\r
524             config.Location = bounds.Location;\r
525             config.Size = bounds.Size;\r
526             Hide();\r
527         }\r
528 \r
529         public void ShowShip(int id)\r
530         {\r
531             var i = Array.FindIndex(_shipList, s => s.Id == id);\r
532             if (i == -1)\r
533                 return;\r
534             var y = (int)Math.Round(ShipLabel.ScaleFactor.Height * 16 * i);\r
535             panelShipList.AutoScrollPosition = new Point(0, y);\r
536         }\r
537 \r
538         private void checkBoxShipType_CheckedChanged(object sender, EventArgs e)\r
539         {\r
540             _config.ShipList.ShipType = checkBoxShipType.Checked;\r
541             UpdateList();\r
542             SetActiveControl();\r
543         }\r
544 \r
545         private void checkboxGroup_CheckedChanged(object sender, EventArgs e)\r
546         {\r
547             var cb = (CheckBox)sender;\r
548             var group = (int)cb.Tag % 10;\r
549             var idx = (int)cb.Tag / 10;\r
550             if (cb.Checked)\r
551                 _groupSettings[group].Add(_shipList[idx].Id);\r
552             else\r
553                 _groupSettings[group].Remove(_shipList[idx].Id);\r
554         }\r
555 \r
556         private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e)\r
557         {\r
558             UpdateList();\r
559         }\r
560 \r
561         private void comboBoxGroup_DropDownClosed(object sender, EventArgs e)\r
562         {\r
563             SetActiveControl();\r
564         }\r
565 \r
566         private void ShipListForm_KeyPress(object sender, KeyPressEventArgs e)\r
567         {\r
568             var g = Array.FindIndex(new[] {'Z', 'A', 'B', 'C', 'D', 'G', 'R', 'W'}, x => x == char.ToUpper(e.KeyChar));\r
569             if (g == -1)\r
570                 return;\r
571             comboBoxGroup.SelectedIndex = g;\r
572             SetActiveControl();\r
573             e.Handled = true;\r
574         }\r
575 \r
576         // マウスホイールでスクロールするためにコントロールにフォーカスを合わせる。\r
577         private void SetActiveControl()\r
578         {\r
579             ActiveControl = InItemList() ? (Control)treeViewItem : panelShipList;\r
580         }\r
581     }\r
582 }