mirror of
https://gitee.com/csharpui/CPF.git
synced 2025-04-05 17:37:51 +08:00
1
This commit is contained in:
parent
507e844275
commit
807cbdf300
@ -1,6 +1,7 @@
|
||||
using CPF.Controls;
|
||||
using CPF.Drawing;
|
||||
using CPF.Platform;
|
||||
using CPF.Shapes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@ -46,17 +47,18 @@ namespace CPF.Toolkit.Controls
|
||||
this.host.UIElementAdded += Host_UIElementAdded;
|
||||
this.host.UIElementRemoved += Host_UIElementRemoved;
|
||||
}
|
||||
|
||||
Dictionary<UIElement, MdiWindowRect> normalRect = new Dictionary<UIElement, MdiWindowRect>();
|
||||
readonly Panel host = new Panel { Size = SizeField.Fill };
|
||||
Collection<UIElement> TaskBarList { get => GetValue<Collection<UIElement>>(); set => SetValue(value); }
|
||||
public new UIElementCollection Children => host.Children;
|
||||
UIElement SelectWindow { get => GetValue<UIElement>(); set => SetValue(value); }
|
||||
public MdiWindow SelectWindow { get => GetValue<MdiWindow>(); set => SetValue(value); }
|
||||
|
||||
protected override void OnPropertyChanged(string propertyName, object oldValue, object newValue, PropertyMetadataAttribute propertyMetadata)
|
||||
{
|
||||
if (propertyName == nameof(this.SelectWindow))
|
||||
if (propertyName == nameof(this.SelectWindow) && this.SelectWindow != null)
|
||||
{
|
||||
this.Topping(this.SelectWindow);
|
||||
this.SelectWindow.WindowState = this.normalRect[this.SelectWindow].OldState;
|
||||
}
|
||||
base.OnPropertyChanged(propertyName, oldValue, newValue, propertyMetadata);
|
||||
}
|
||||
@ -87,21 +89,23 @@ namespace CPF.Toolkit.Controls
|
||||
e.Element.PropertyChanged -= Element_PropertyChanged;
|
||||
e.Element.PreviewMouseDown -= Element_PreviewMouseDown;
|
||||
this.TaskBarList.Remove(e.Element);
|
||||
this.normalRect.Remove(e.Element);
|
||||
}
|
||||
|
||||
private void Host_UIElementAdded(object sender, UIElementAddedEventArgs e)
|
||||
{
|
||||
var view = e.Element as MdiWindow;
|
||||
this.normalRect.Add(e.Element, new MdiWindowRect { Left = 0, Top = 0, Height = 500, Width = 500 });
|
||||
view.PropertyChanged += Element_PropertyChanged;
|
||||
view.PreviewMouseDown += Element_PreviewMouseDown;
|
||||
this.TaskBarList.Add(view);
|
||||
e.Element.ZIndex = this.host.Children.Max(x => x.ZIndex) + 1;
|
||||
this.Topping(e.Element);
|
||||
this.Topping(view);
|
||||
}
|
||||
|
||||
private void Element_PreviewMouseDown(object sender, Input.MouseButtonEventArgs e)
|
||||
{
|
||||
var ele = (UIElement)sender;
|
||||
var ele = (MdiWindow)sender;
|
||||
this.Topping(ele);
|
||||
}
|
||||
|
||||
@ -111,9 +115,26 @@ namespace CPF.Toolkit.Controls
|
||||
switch (e.PropertyName)
|
||||
{
|
||||
case nameof(MdiWindow.WindowState):
|
||||
if ((WindowState)e.NewValue == WindowState.Minimized)
|
||||
|
||||
switch ((WindowState)e.NewValue)
|
||||
{
|
||||
this.SelectWindow = this.host.Children.FindLast(x => x.Visibility == Visibility.Visible);
|
||||
case WindowState.Normal:
|
||||
var rect = this.normalRect[view];
|
||||
view.Size = new SizeField(rect.Width, rect.Height);
|
||||
view.MarginLeft = rect.Left;
|
||||
view.MarginTop = rect.Top;
|
||||
break;
|
||||
case WindowState.Minimized:
|
||||
view.Visibility = Visibility.Collapsed;
|
||||
this.SelectWindow = this.host.Children.FindLast(x => x.Visibility == Visibility.Visible) as MdiWindow;
|
||||
this.normalRect[view].OldState = (WindowState)e.OldValue;
|
||||
break;
|
||||
case WindowState.Maximized:
|
||||
case WindowState.FullScreen:
|
||||
view.Size = SizeField.Fill;
|
||||
view.MarginLeft = 0;
|
||||
view.MarginTop = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -121,10 +142,43 @@ namespace CPF.Toolkit.Controls
|
||||
this.SelectWindow = view;
|
||||
this.SelectWindow.Visibility = Visibility.Visible;
|
||||
break;
|
||||
|
||||
case nameof(MarginLeft):
|
||||
if (view.WindowState == WindowState.Normal)
|
||||
{
|
||||
var left = (FloatField)e.NewValue;
|
||||
if (left.Value <= 0) view.MarginLeft = 0;
|
||||
this.normalRect[view].Left = view.MarginLeft.Value;
|
||||
}
|
||||
break;
|
||||
case nameof(MarginTop):
|
||||
if (view.WindowState == WindowState.Normal)
|
||||
{
|
||||
var top = (FloatField)e.NewValue;
|
||||
if (top.Value <= 0) view.MarginTop = 0;
|
||||
this.normalRect[view].Top = view.MarginTop.Value;
|
||||
}
|
||||
break;
|
||||
|
||||
case nameof(Width):
|
||||
if (view.WindowState == WindowState.Normal)
|
||||
{
|
||||
var size = (FloatField)e.NewValue;
|
||||
this.normalRect[view].Width = size.Value;
|
||||
}
|
||||
break;
|
||||
|
||||
case nameof(Height):
|
||||
if (view.WindowState == WindowState.Normal)
|
||||
{
|
||||
var size = (FloatField)e.NewValue;
|
||||
this.normalRect[view].Height = size.Value;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Topping(UIElement ele)
|
||||
public void Topping(MdiWindow ele)
|
||||
{
|
||||
if (ele == null) return;
|
||||
var index = this.host.Children.Max(x => x.ZIndex);
|
||||
|
@ -19,30 +19,31 @@ namespace CPF.Toolkit.Controls
|
||||
{
|
||||
public class MdiWindow : Control
|
||||
{
|
||||
[PropertyMetadata(typeof(WindowState), "0")]
|
||||
public WindowState WindowState { get => GetValue<WindowState>(); set => SetValue(value); }
|
||||
[PropertyMetadata("title")]
|
||||
public string Title { get => GetValue<string>(); set => SetValue(value); }
|
||||
public UIElement Content { get => GetValue<UIElement>(); set => SetValue(value); }
|
||||
|
||||
[PropertyMetadata("Title")]
|
||||
public string Title { get => GetValue<string>(); set => SetValue(value); }
|
||||
|
||||
[PropertyMetadata(true)]
|
||||
public bool MaximizeBox { get { return GetValue<bool>(); } set { SetValue(value); } }
|
||||
|
||||
[PropertyMetadata(true)]
|
||||
public bool MinimizeBox { get { return GetValue<bool>(); } set { SetValue(value); } }
|
||||
|
||||
[PropertyMetadata(true)]
|
||||
public bool CloseBox { get { return GetValue<bool>(); } set { SetValue(value); } }
|
||||
|
||||
[UIPropertyMetadata((byte)5, UIPropertyOptions.AffectsMeasure)]
|
||||
public byte ShadowBlur { get { return GetValue<byte>(); } set { SetValue(value); } }
|
||||
|
||||
public event EventHandler<ClosingEventArgs> Closing;
|
||||
|
||||
WindowState oldState;
|
||||
SizeField normalSize = new SizeField(500, 500);
|
||||
Point normalPos = new Point(0, 0);
|
||||
protected override void InitializeComponent()
|
||||
{
|
||||
var bar = (ViewFill)"154,180,208";
|
||||
var thubmEnabled = new BindingDescribe(this, nameof(WindowState), BindingMode.OneWay, b => ((WindowState)b) == WindowState.Normal);
|
||||
this.Size = normalSize;
|
||||
this.Size = new SizeField(500, 500);
|
||||
this.Background = null;
|
||||
this.MarginLeft = 0;
|
||||
this.MarginTop = 0;
|
||||
@ -322,7 +323,6 @@ namespace CPF.Toolkit.Controls
|
||||
var arge = e as DragDeltaEventArgs;
|
||||
this.MarginLeft += arge.HorizontalChange;
|
||||
this.MarginTop += arge.VerticalChange;
|
||||
this.normalPos = new Point(this.MarginLeft.Value, this.MarginTop.Value);
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -354,86 +354,16 @@ namespace CPF.Toolkit.Controls
|
||||
[nameof(Border.ShadowBlur)] = new BindingDescribe(this,
|
||||
nameof(WindowState),
|
||||
BindingMode.OneWay,
|
||||
a => ((WindowState)a).Or(WindowState.Maximized, WindowState.FullScreen,WindowState.Minimized) ? 0 : ShadowBlur),
|
||||
a => ((WindowState)a).Or(WindowState.Maximized, WindowState.FullScreen) ? 0 : ShadowBlur),
|
||||
});
|
||||
|
||||
this.Content.Margin = "0";
|
||||
this.Content.ClipToBounds = true;
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(string propertyName, object oldValue, object newValue, PropertyMetadataAttribute propertyMetadata)
|
||||
{
|
||||
switch (propertyName)
|
||||
{
|
||||
case nameof(WindowState):
|
||||
{
|
||||
switch (this.WindowState)
|
||||
{
|
||||
case WindowState.Normal:
|
||||
this.Size = this.normalSize;
|
||||
this.MarginLeft = this.normalPos.X;
|
||||
this.MarginTop = this.normalPos.Y;
|
||||
break;
|
||||
case WindowState.Minimized:
|
||||
this.Visibility = Visibility.Collapsed;
|
||||
this.oldState = (WindowState)oldValue;
|
||||
break;
|
||||
case WindowState.Maximized:
|
||||
case WindowState.FullScreen:
|
||||
this.Size = SizeField.Fill;
|
||||
this.MarginLeft = 0;
|
||||
this.MarginTop = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case nameof(Size):
|
||||
case nameof(Width):
|
||||
case nameof(Height):
|
||||
case nameof(ActualSize):
|
||||
switch (this.WindowState)
|
||||
{
|
||||
case WindowState.Normal:
|
||||
this.normalSize = this.Size;
|
||||
break;
|
||||
case WindowState.Minimized:
|
||||
//this.Width = this.MinWidth;
|
||||
//this.Height = this.MinHeight;
|
||||
break;
|
||||
case WindowState.Maximized:
|
||||
case WindowState.FullScreen:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case nameof(MarginLeft):
|
||||
{
|
||||
if (this.MarginLeft.Value <= 0)
|
||||
{
|
||||
this.MarginLeft = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case nameof(MarginTop):
|
||||
if (MarginTop.Value <= 0)
|
||||
{
|
||||
this.MarginTop = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
base.OnPropertyChanged(propertyName, oldValue, newValue, propertyMetadata);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Title;
|
||||
}
|
||||
|
||||
public void ReWindowState()
|
||||
{
|
||||
this.WindowState = this.oldState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
34
CPF.Toolkit/Controls/MdiWindowRect.cs
Normal file
34
CPF.Toolkit/Controls/MdiWindowRect.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using CPF.Controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace CPF.Toolkit.Controls
|
||||
{
|
||||
internal class MdiWindowRect
|
||||
{
|
||||
public MdiWindowRect()
|
||||
{
|
||||
|
||||
}
|
||||
public MdiWindowRect(float left, float top, float width, float height)
|
||||
{
|
||||
this.Left = left;
|
||||
this.Top = top;
|
||||
this.Width = width;
|
||||
this.Height = height;
|
||||
}
|
||||
public float Left { get; set; }
|
||||
public float Top { get; set; }
|
||||
public float Width { get; set; }
|
||||
public float Height { get; set; }
|
||||
|
||||
public WindowState OldState { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"left:{this.Left} top:{this.Top} width:{this.Width} height:{this.Height}";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user