From: jpbruyere Date: Tue, 24 Jan 2017 00:54:22 +0000 (+0100) Subject: maximize and minimize for window X-Git-Tag: v0.5.1~28^2~8 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=425ae6f5b03719e5db82a80d712685f43a31a717;p=jp%2Fcrow.git maximize and minimize for window --- diff --git a/Crow.csproj b/Crow.csproj index b541152c..d66d6f66 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -290,6 +290,12 @@ Crow.ColorPicker.template + + Crow.ToolWindow.template + + + + diff --git a/Default.style b/Default.style index dc8abd86..de3e8d8c 100644 --- a/Default.style +++ b/Default.style @@ -61,6 +61,13 @@ TextBox { Margin = 1; } Window { + Focusable = true; + MinimumSize=5,5; + Width = 150; + Height = 150; +} +ToolWindow { + Template = #Crow.ToolWindow.template; Focusable = true; MinimumSize=50,50; Width = 150; diff --git a/Images/Icons/exit.svg b/Images/Icons/exit.svg index 3d688cc7..cb8d1c27 100644 --- a/Images/Icons/exit.svg +++ b/Images/Icons/exit.svg @@ -1,62 +1,10 @@ - - - - - - - - image/svg+xml - - - - - - + viewBox="0 0 64 64"> + + + diff --git a/Images/Icons/minimize.svg b/Images/Icons/minimize.svg new file mode 100644 index 00000000..dc3dcd2e --- /dev/null +++ b/Images/Icons/minimize.svg @@ -0,0 +1,11 @@ + + + + diff --git a/Images/Icons/normalize.svg b/Images/Icons/normalize.svg new file mode 100644 index 00000000..b8b44bd5 --- /dev/null +++ b/Images/Icons/normalize.svg @@ -0,0 +1,22 @@ + + + + + + diff --git a/Templates/ToolWindow.template b/Templates/ToolWindow.template new file mode 100755 index 00000000..7325193c --- /dev/null +++ b/Templates/ToolWindow.template @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + diff --git a/Templates/Window.template b/Templates/Window.template index 7325193c..d729021c 100755 --- a/Templates/Window.template +++ b/Templates/Window.template @@ -10,15 +10,30 @@ Name="hs" Margin="2" Spacing="0" Height="Fit"> - - + - + + + + + + + + + - + diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index 86f05d86..0b203dfd 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -46,15 +46,19 @@ namespace Crow bool _resizable; bool _movable; bool hoverBorder = false; - bool isMaximized = false; - Measure savedH, savedW; + + Rectangle savedBounds; + bool _minimized = false; Container _contentContainer; Direction currentDirection = Direction.None; + #region Events public event EventHandler Closing; public event EventHandler Maximized; public event EventHandler Unmaximized; + public event EventHandler Minimize; + #endregion #region CTOR public Window () : base() { @@ -64,73 +68,98 @@ namespace Crow #region TemplatedContainer overrides public override GraphicObject Content { - get { - return _contentContainer == null ? null : _contentContainer.Child; - } - set { - _contentContainer.SetChild(value); - } + get { return _contentContainer == null ? null : _contentContainer.Child; } + set { _contentContainer.SetChild(value); } } protected override void loadTemplate(GraphicObject template = null) { base.loadTemplate (template); _contentContainer = this.child.FindByName ("Content") as Container; + + NotifyValueChanged ("ShowNormal", false); + NotifyValueChanged ("ShowMinimize", true); + NotifyValueChanged ("ShowMaximize", true); } #endregion #region public properties - [XmlAttributeAttribute()][DefaultValue("Window")] + [XmlAttributeAttribute][DefaultValue("Window")] public string Title { get { return _title; } set { + if (_title == value) + return; _title = value; NotifyValueChanged ("Title", _title); } } - [XmlAttributeAttribute()][DefaultValue("#Crow.Images.Icons.crow.png")] + [XmlAttributeAttribute][DefaultValue("#Crow.Images.Icons.crow.png")] public string Icon { get { return _icon; } set { + if (_icon == value) + return; _icon = value; NotifyValueChanged ("Icon", _icon); } } - [XmlAttributeAttribute()][DefaultValue(true)] + [XmlAttributeAttribute][DefaultValue(true)] public bool Resizable { get { return _resizable; } set { + if (_resizable == value) + return; _resizable = value; NotifyValueChanged ("Resizable", _resizable); } } - [XmlAttributeAttribute()][DefaultValue(true)] + [XmlAttributeAttribute][DefaultValue(true)] public bool Movable { get { return _movable; } set { + if (_movable == value) + return; _movable = value; NotifyValueChanged ("Movable", _movable); } } - [XmlAttributeAttribute()][DefaultValue(false)] - public bool IsMaximized { - get { return isMaximized; } + [XmlAttributeAttribute][DefaultValue(false)] + public bool IsMinimized { + get { return _minimized; } set{ - if (value == isMaximized) + if (value == IsMinimized) return; - isMaximized = value; - if (isMaximized) - onMaximized (this, null); - else - onUnmaximized (this, null); + _minimized = value; + _contentContainer.Visible = !_minimized; - NotifyValueChanged ("IsMaximized", isMaximized); + NotifyValueChanged ("IsMinimized", _minimized); } } + [XmlIgnore]public bool IsMaximized { + get { return Width == Measure.Stretched & Height == Measure.Stretched & !_minimized; } + } + [XmlIgnore]public bool IsNormal { + get { return !(IsMaximized|_minimized); } + } +// [XmlAttributeAttribute()][DefaultValue(WindowState.Normal)] +// public virtual WindowState State { +// get { return _state; } +// set { +// if (_state == value) +// return; +// _state = value; +// NotifyValueChanged ("State", _state); +// NotifyValueChanged ("IsNormal", IsNormal); +// NotifyValueChanged ("IsMaximized", IsMaximized); +// NotifyValueChanged ("IsMinimized", IsMinimized); +// NotifyValueChanged ("IsNotMinimized", IsNotMinimized); +// } +// } #endregion #region GraphicObject Overrides @@ -219,14 +248,6 @@ namespace Crow return; } } -// GraphicObject firstFocusableAncestor = otkgw.hoverWidget; -// while (firstFocusableAncestor != this) { -// if (firstFocusableAncestor == null) -// return; -// if (firstFocusableAncestor.Focusable) -// return; -// firstFocusableAncestor = firstFocusableAncestor.Parent as GraphicObject; -// } if (Resizable) { Direction lastDir = currentDirection; @@ -289,21 +310,56 @@ namespace Crow base.onMouseDown (sender, e); } #endregion + protected void onMaximized (object sender, EventArgs e){ - savedW = this.Width; - savedH = this.Height; - this.Width = Measure.Stretched; - this.Height = Measure.Stretched; + lock (CurrentInterface.LayoutMutex) { + if (!IsMinimized) + savedBounds = this.LastPaintedSlot; + this.Left = this.Top = 0; + this.RegisterForLayouting (LayoutingType.Positioning); + this.Width = this.Height = Measure.Stretched; + IsMinimized = false; + Resizable = false; + NotifyValueChanged ("ShowNormal", true); + NotifyValueChanged ("ShowMinimize", true); + NotifyValueChanged ("ShowMaximize", false); + } Maximized.Raise (sender, e); + + + } protected void onUnmaximized (object sender, EventArgs e){ - this.Width = savedW; - this.Height = savedH; + lock (CurrentInterface.LayoutMutex) { + this.Left = savedBounds.Left; + this.Top = savedBounds.Top; + this.Width = savedBounds.Width; + this.Height = savedBounds.Height; + IsMinimized = false; + Resizable = true; + NotifyValueChanged ("ShowNormal", false); + NotifyValueChanged ("ShowMinimize", true); + NotifyValueChanged ("ShowMaximize", true); + } Unmaximized.Raise (sender, e); } + protected void onMinimized (object sender, EventArgs e){ + lock (CurrentInterface.LayoutMutex) { + if (IsNormal) + savedBounds = this.LastPaintedSlot; + Width = 200; + Height = 20; + Resizable = false; + IsMinimized = true; + NotifyValueChanged ("ShowNormal", true); + NotifyValueChanged ("ShowMinimize", false); + NotifyValueChanged ("ShowMaximize", true); + } + Minimize.Raise (sender, e); + } protected void onBorderMouseLeave (object sender, MouseMoveEventArgs e) { hoverBorder = false; @@ -316,9 +372,6 @@ namespace Crow } - protected void butMaximizePress (object sender, MouseButtonEventArgs e){ - IsMaximized = !IsMaximized; - } protected void butQuitPress (object sender, MouseButtonEventArgs e) { CurrentInterface.MouseCursor = XCursor.Default;