yangyin
2025-03-25 db33bc6d9a30db6be4b40e45097c9a87a67cc845
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
using DPumpHydr.WinFrmUI.RLT.Docking.Crown;
using DPumpHydr.WinFrmUI.RLT.Forms;
using DPumpHydr.WinFrmUI.RLT.Native;  
 
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using static DPumpHydr.WinFrmUI.RLT.Helper.CrownHelper;
using DPumpHydr.WinFrmUI.Volute.TempCtrl;
 
 
namespace DPumpHydr.WinFrmUI.Volute
{
    public partial class dockCtrl原始 : UserControl
    {
        #region Field Region
 
        private readonly List<CrownDockContent> _toolWindows = new();
 
        private readonly DockProject _dockProject;
        private readonly DockProperties _dockProperties;
        private readonly DockConsole _dockConsole;
        private readonly DockLayers _dockLayers;
        private readonly DockHistory _dockHistory;
 
        private readonly string ConfigFile = "CrownDockPanel.config";
 
        #endregion
 
        #region Constructor Region
 
        public dockCtrl原始()
        {
            InitializeComponent();
 
            // Add the control scroll message filter to re-route all mousewheel events
            // to the control the user is currently hovering over with their cursor.
            Application.AddMessageFilter(new ControlScrollFilter());
 
            // Add the dock content drag message filter to handle moving dock content around.
            Application.AddMessageFilter(DockPanel.DockContentDragFilter);
 
            // Add the dock panel message filter to filter through for dock panel splitter
            // input before letting events pass through to the rest of the application.
            Application.AddMessageFilter(DockPanel.DockResizeFilter);
 
            // Hook in all the UI events manually for clarity.
            HookEvents();
 
            // Build the tool windows and add them to the dock panel
            _dockProject = new DockProject();
            _dockProperties = new DockProperties();
            _dockConsole = new DockConsole();
            _dockLayers = new DockLayers();
            _dockHistory = new DockHistory();
 
            // Add the tool windows to a list
            _toolWindows.Add(_dockProject);
            _toolWindows.Add(_dockProperties);
            _toolWindows.Add(_dockConsole);
            _toolWindows.Add(_dockLayers);
            _toolWindows.Add(_dockHistory);
 
            // Deserialize if a previous state is stored
            if (File.Exists(ConfigFile))
            {
                DeserializeDockPanel(ConfigFile);
            }
            else
            {
                // Add the tool window list contents to the dock panel
                foreach (CrownDockContent toolWindow in _toolWindows)
                {
                    DockPanel.AddContent(toolWindow);
                }
 
                // Add the history panel to the layer panel group
                DockPanel.AddContent(_dockHistory, _dockLayers.DockGroup);
            }
 
            // Check window menu items which are contained in the dock panel
            BuildWindowMenu();
 
            // Add dummy documents to the main document area of the dock panel
            // DockPanel.AddContent(new DockDocument("Document 1", Properties.Resources.document_16xLG));
            // DockPanel.AddContent(new DockDocument("Document 2", Properties.Resources.document_16xLG));
            // DockPanel.AddContent(new DockDocument("Document 3", Properties.Resources.document_16xLG));
        }
 
        #endregion
 
        #region Method Region
 
        private void HookEvents()
        {
            //FormClosing += Form21_FormClosing;
 
            DockPanel.ContentAdded += DockPanel_ContentAdded;
            DockPanel.ContentRemoved += DockPanel_ContentRemoved;
 
            mnuNewFile.Click += NewFile_Click;
            mnuClose.Click += Close_Click;
 
            btnNewFile.Click += NewFile_Click;
 
            mnuDialog.Click += Dialog_Click;
 
            mnuProject.Click += Project_Click;
            mnuProperties.Click += Properties_Click;
            mnuConsole.Click += Console_Click;
            mnuLayers.Click += Layers_Click;
            mnuHistory.Click += History_Click;
        }
 
        private void ToggleToolWindow(CrownToolWindow toolWindow)
        {
            if (toolWindow.DockPanel == null)
            {
                DockPanel.AddContent(toolWindow);
            }
            else
            {
                DockPanel.RemoveContent(toolWindow);
            }
        }
 
        private void BuildWindowMenu()
        {
            mnuProject.Checked = DockPanel.ContainsContent(_dockProject);
            mnuProperties.Checked = DockPanel.ContainsContent(_dockProperties);
            mnuConsole.Checked = DockPanel.ContainsContent(_dockConsole);
            mnuLayers.Checked = DockPanel.Contains(_dockLayers);
            mnuHistory.Checked = DockPanel.Contains(_dockHistory);
        }
 
        #endregion
 
        #region Event Handler Region
 
        private void Form21_FormClosing(object sender, FormClosingEventArgs e)
        {
            SerializeDockPanel(ConfigFile);
        }
 
        private void DockPanel_ContentAdded(object sender, DockContentEventArgs e)
        {
            if (_toolWindows.Contains(e.Content))
            {
                BuildWindowMenu();
            }
        }
 
        private void DockPanel_ContentRemoved(object sender, DockContentEventArgs e)
        {
            if (_toolWindows.Contains(e.Content))
            {
                BuildWindowMenu();
            }
        }
 
        private void NewFile_Click(object sender, EventArgs e)
        {
            //DockDocument newFile = new("New document", Properties.Resources.document_16xLG);
            //DockPanel.AddContent(newFile);
        }
 
        private void Close_Click(object sender, EventArgs e)
        {
            //Close();
        }
 
        private void Dialog_Click(object sender, EventArgs e)
        {
            //DialogControls test = new();
            //test.ShowDialog();
        }
 
        private void Project_Click(object sender, EventArgs e)
        {
            ToggleToolWindow(_dockProject);
        }
 
        private void Properties_Click(object sender, EventArgs e)
        {
            ToggleToolWindow(_dockProperties);
        }
 
        private void Console_Click(object sender, EventArgs e)
        {
            ToggleToolWindow(_dockConsole);
        }
 
        private void Layers_Click(object sender, EventArgs e)
        {
            ToggleToolWindow(_dockLayers);
        }
 
        private void History_Click(object sender, EventArgs e)
        {
            ToggleToolWindow(_dockHistory);
        }
 
        private void DarkToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThemeProvider.Theme = new DarkTheme();
            BackColor = ThemeProvider.Theme.Colors.GreyBackground;
 
            foreach (ToolStripMenuItem Control in mnuMain.Items)
            {
                Control.BackColor = ThemeProvider.Theme.Colors.GreyBackground;
            }
 
            foreach (ToolStripLabel Control in stripMain.Items)
            {
                Control.ForeColor = ThemeProvider.Theme.Colors.LightText;
            }
 
            foreach (Control Control in DockPanel.ActiveDocument.Controls)
            {
                if (Control.Name == "txtDocument")
                {
                    Control.ForeColor = ThemeProvider.Theme.Colors.LightText;
                    Control.BackColor = Color.FromArgb(43, 43, 43);
                }
            }
 
            Invalidate();
            Refresh();
        }
 
        private void LightToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThemeProvider.Theme = new LightTheme();
            BackColor = ThemeProvider.Theme.Colors.GreyBackground;
 
            foreach (ToolStripMenuItem Control in mnuMain.Items)
            {
                Control.BackColor = ThemeProvider.Theme.Colors.GreyBackground;
            }
 
            foreach (ToolStripLabel Control in stripMain.Items)
            {
                Control.ForeColor = ThemeProvider.Theme.Colors.LightText;
            }
 
            foreach (Control Control in DockPanel.ActiveDocument.Controls)
            {
                if (Control.Name == "txtDocument")
                {
                    Control.ForeColor = ThemeProvider.Theme.Colors.LightText;
                    Control.BackColor = ThemeProvider.Theme.Colors.LightBackground;
                    break;
                }
            }
 
            Invalidate();
            Refresh();
        }
 
        #endregion
 
        #region Serialization Region
 
        private void SerializeDockPanel(string path)
        {
            //DockPanelState state = DockPanel.GetDockPanelState();
            //SerializerHelper.Serialize(state, path);
        }
 
        private void DeserializeDockPanel(string path)
        {
            //DockPanelState state = SerializerHelper.Deserialize<DockPanelState>(path);
            // DockPanel.RestoreDockPanelState(state, GetContentBySerializationKey);
        }
 
        private CrownDockContent GetContentBySerializationKey(string key)
        {
            foreach (CrownDockContent window in _toolWindows)
            {
                if (window.SerializationKey == key)
                {
                    return window;
                }
            }
 
            return null;
        }
 
        #endregion
 
        private void Form21_Load(object sender, EventArgs e)
        {
 
        }
 
        private void testToolStripMenuItem_Click(object sender, EventArgs e)
        {
 
        }
 
        private void lightToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
 
        }
    }
}