chr
2024-03-01 e0b72976c15d99c2972d20925bf438c0c7055ad6
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
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using WPFProject.Controls;
using WPFProject.Models;
using WPFProject.UI.Test;
using WPFProject.Utils;
 
namespace WPFProject.UI
{
    /// <summary>
    /// WorkControl.xaml 的交互逻辑
    /// </summary>
    public partial class WorkControl : UserControl,IPlugin
    {
        public WorkControl()
        {
            InitializeComponent();
            Loaded += UserControl_Loaded;
        }
 
        private List<CanvasPosition> InitGridSize()
        {
            List<CanvasPosition> result = new List<CanvasPosition>();
            result.Add(new CanvasPosition
            {
                Left = 0,
                Top = 0,
                Width = 0.1 * ActualWidth -2,
                Height = 0.5 * ActualHeight - 2
            });
            result.Add(new CanvasPosition
            {
                Left = 0.1*ActualWidth +2,
                Top = 0,
                Width = 0.5* ActualWidth -4,
                Height = ActualHeight,
            });
 
            result.Add(new CanvasPosition
            {
                Left = 0.6*ActualWidth+2,
                Top = 0,
                Width = 0.4*ActualWidth-2,
                Height = 0.5 * ActualHeight - 2
            });
 
            result.Add(new CanvasPosition
            {
                Left = 0,
                Top = 0.5*ActualHeight+2,
                Width = 0.1 * ActualWidth - 2,
                Height = 0.5 * ActualHeight - 2
            });
 
            result.Add(new CanvasPosition
            {
                Left = 0.6 * ActualWidth + 2,
                Top = 0.5 * ActualHeight + 2,
                Width = 0.4 * ActualWidth - 2,
                Height = 0.5 * ActualHeight - 2
            });
 
            return result;
        }
 
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            List<CanvasPosition> pos = InitGridSize();
            ProgramList programList = new ProgramList();
            InnerWindow p = new InnerWindow(pos[0])
            {
                Title = "程序列表",
                Content = programList
            };
            HandleInnerWindow(p);
 
            InnerWindow p1 = new InnerWindow(pos[1])
            {
                Title = "图片",
            };
            HandleInnerWindow(p1);
 
            SequnceList sequnceList = new SequnceList();
            programList.ProgramChanged += sequnceList.Selected_Program_Changed;
 
            InnerWindow p2 = new InnerWindow(pos[2])
            {
                Title = "序列",
                Content = sequnceList
            };
            HandleInnerWindow(p2);
 
            FunctionSetting functionSetting = new FunctionSetting();
            InnerWindow p3 = new InnerWindow(pos[3])
            {
                Title = "函数",
                Content = functionSetting
            };
            HandleInnerWindow(p3);
 
            StepSetting stepSetting = new StepSetting();
            InnerWindow p4 = new InnerWindow(pos[4])
            {
                Title = "单步设置",
                Content = stepSetting
            };
            HandleInnerWindow(p4);
 
 
            SizeChanged += WorkControl_SizeChanged;
            Loaded -= UserControl_Loaded;
 
        }
 
        public int CanvasChildrenCount { get; private set; } = 0;
        private void HandleInnerWindow(InnerWindow inner)
        {
            inner.MinEvent += InnerWindowMin;
            inner.MaxEvent += InnerWindowMax;
            inner.ZIndexEvent += Inner_ZIndexEvent;
            inner.GotFocus += Inner_GotFocus;
            inner.AttachToCanvas(WorkArea);
            inner.Zindex = CanvasChildrenCount++;
        }
 
        private void Inner_GotFocus(object sender, RoutedEventArgs e)
        {
            CanvasHelper.SetTopZIndex(sender as InnerWindow, WorkArea, typeof(InnerWindow));
        }
 
        private void Inner_ZIndexEvent(object sender, EventArgs e)
        {
            CanvasHelper.SetTopZIndex(sender as InnerWindow, WorkArea, typeof(InnerWindow));
        }
 
        private void HandleMinInnerWindow(InnerWindow inner)
        {
            MinInnerWindow min = new MinInnerWindow(inner);
            min.MaxEvent += MinInnerWindowMax;
            min.CloseEvent += MinInnerWindowClose;
            BottomBar.AddMinWindow(min);
        }
 
        private void InnerWindowMin(object sender, System.EventArgs e)
        {
            InnerWindow inner = sender as InnerWindow;
            inner.Visibility = Visibility.Collapsed;
            HandleMinInnerWindow(inner);
        }
 
        private void InnerWindowMax(object sender, System.EventArgs e)
        {
            InnerWindow inner = sender as InnerWindow;
            if (inner.WindowState == WindowState.Maximized)
            {
                Canvas.SetLeft(inner, inner.canvasPosition.Left);
                Canvas.SetTop(inner, inner.canvasPosition.Top);
 
                inner.Width = inner.canvasPosition.Width;
                inner.Height = inner.canvasPosition.Height;
                inner.WindowState = WindowState.Normal;
            }
            else{
                Canvas.SetLeft(inner, 0);
                Canvas.SetTop(inner, 0);
                inner.Width = WorkArea.ActualWidth;
                inner.Height = WorkArea.ActualHeight;
                inner.WindowState = WindowState.Maximized;
            }
        }
 
        private void MinInnerWindowMax(object sender, System.EventArgs e)
        {
            MinInnerWindow min = sender as MinInnerWindow;
            min.Inner.Visibility = Visibility.Visible;
            CanvasHelper.SetTopZIndex(min.Inner, WorkArea, typeof(InnerWindow));
            BottomBar.RemoveMinWindow(min);
        }
 
        private void MinInnerWindowClose(object sender, System.EventArgs e)
        {
            MinInnerWindow min = sender as MinInnerWindow;
            BottomBar.RemoveMinWindow(min);
        }
 
 
        private void WorkControl_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            Size newSize = e.NewSize;
            Size previousSize = e.PreviousSize;
 
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(WorkArea); i++)
            {
                UIElement child = VisualTreeHelper.GetChild(WorkArea, i) as UIElement;
                if (Canvas.GetLeft(child) >= newSize.Width)
                {
                    Canvas.SetLeft(child, Canvas.GetLeft(child) + newSize.Width - previousSize.Width);
                }
                if (Canvas.GetTop(child) >= newSize.Height)
                {
                    Canvas.SetTop(child, Canvas.GetTop(child) + newSize.Height - previousSize.Height);
                }
            }
        }
 
 
        public void OnTabChange(object sender, SelectionChangedEventArgs args)
        {
            if (args.AddedItems.Count > 0)
            {
                IconTabItem newTab = args.AddedItems[0] as IconTabItem;
                if (newTab != null && newTab.Content == this)
                { 
                    
                }
            }
 
            if (args.RemovedItems.Count > 0)
            {
                IconTabItem oldTab = args.RemovedItems[0] as IconTabItem;
                if (oldTab != null && oldTab.Content == this)
                {
 
                }
            }
        }
    }
}