-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathConfigView.cs
More file actions
141 lines (116 loc) · 3.89 KB
/
Copy pathConfigView.cs
File metadata and controls
141 lines (116 loc) · 3.89 KB
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using MW5.Plugins.Concrete;
using MW5.Plugins.Enums;
using MW5.Plugins.Interfaces;
using MW5.Services.Config;
using MW5.Shared;
using MW5.UI.Forms;
using MW5.Views;
using MW5.Views.Abstract;
using Syncfusion.Drawing;
namespace MW5.Views
{
public partial class ConfigView : ConfigViewBase, IConfigView, IMessageFilter
{
public event Action SaveClicked;
public event Action PageShown;
public ConfigView()
{
InitializeComponent();
Application.AddMessageFilter(this);
MouseWheel += (s, e) => configPageControl1.HandleMouseWheel(e);
btnSave.Click += (s, e) => Invoke(SaveClicked);
FormClosed += ConfigView_FormClosed;
InitTreeViewStyle();
}
private void InitTreeViewStyle()
{
_treeViewAdv1.SelectedNodeBackground = new BrushInfo(Color.FromKnownColor(KnownColor.Control));
_treeViewAdv1.FullRowSelect = true;
}
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == 0x20a)
{
var pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16);
var panel = configPageControl1.Panel;
Point p1 = panel.PointToScreen(Point.Empty);
Point p2 = panel.PointToScreen(new Point(configPageControl1.Width, configPageControl1.Height));
if (pos.X >= p1.X && pos.X <= p2.X && pos.Y >= p1.Y && pos.Y <= p2.Y)
{
Win32Api.SendMessage(panel.Handle, m.Msg, m.WParam, m.LParam);
return true;
}
}
return false;
}
public void Initialize()
{
_treeViewAdv1.Initialize(Model);
_treeViewAdv1.AfterSelect += (s, e) => DisplaySelectedPage();
if (Model.UseSelectedPage)
{
_treeViewAdv1.SetSelectedPage(Model.SelectedPage);
}
else
{
_treeViewAdv1.RestoreSelectedNode(AppConfig.Instance.LastConfigPage);
}
}
private IConfigPage SelectedPage
{
get
{
var node = _treeViewAdv1.SelectedNode;
if (node != null)
{
return node.Tag as IConfigPage;
}
return null;
}
}
private void ConfigView_FormClosed(object sender, FormClosedEventArgs e)
{
var page = SelectedPage;
if (page != null)
{
AppConfig.Instance.LastConfigPage = page.PageName;
}
Application.RemoveMessageFilter(this);
}
private void DisplaySelectedPage()
{
var page = SelectedPage;
var ctrl = page as Control;
if (page == null || ctrl == null) return;
if (page.OriginalSize == default(Size))
{
page.OriginalSize = ctrl.Size;
}
configPageControl1.Description = SelectedPage.Description;
configPageControl1.Icon = SelectedPage.Icon;
configPageControl1.ConfigPage = ctrl;
ctrl.Dock = DockStyle.Fill;
ctrl.BringToFront();
Invoke(PageShown);
_treeViewAdv1.SelectedNode.Expand();
}
public ButtonBase OkButton
{
get { return btnOk; }
}
public IEnumerable<ToolStripItemCollection> ToolStrips
{
get { yield return toolOptions.DropDownItems; }
}
public IEnumerable<Control> Buttons
{
get { yield return btnSave; }
}
}
public class ConfigViewBase : MapWindowView<ConfigViewModel> { }
}