From: jpbruyere Date: Tue, 15 Sep 2015 16:23:30 +0000 (+0200) Subject: Improved popper, Position popped window smartly, hide it when mouse X-Git-Tag: 0.2~7 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=4684df8a9c356e824b103cefa804af09c1b6198b;p=jp%2Fcrow.git Improved popper, Position popped window smartly, hide it when mouse leave it, and when popper is removed from rendering hierarchy --- diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index 76a12f58..1ec6e37a 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -31,12 +31,69 @@ namespace go public override GraphicObject Content { get { return _content; } - set { _content = value; } + set { + if (_content != null) { + _content.LayoutChanged -= _content_LayoutChanged; + _content.MouseLeave -= _content_MouseLeave; + } + + _content = value; + + if (_content == null) + return; + + _content.Focusable = true; + _content.LayoutChanged += _content_LayoutChanged; + _content.MouseLeave += _content_MouseLeave; + } + } + + void _content_MouseLeave (object sender, MouseMoveEventArgs e) + { + IsPopped = false; + } + + void _content_LayoutChanged (object sender, LayoutChangeEventArgs e) + { + ILayoutable tc = Content.Parent as ILayoutable; + if (tc == null) + return; + Rectangle r = this.ScreenCoordinates (this.Slot); + if (e.LayoutType == LayoutingType.Width) { + if (Content.Slot.Width < tc.ClientRectangle.Width) { + if (r.Left + Content.Slot.Width > tc.ClientRectangle.Right) + Content.Left = tc.ClientRectangle.Right - Content.Slot.Width; + else + Content.Left = r.Left; + }else + Content.Left = 0; + }else if (e.LayoutType == LayoutingType.Height) { + if (Content.Slot.Height < tc.ClientRectangle.Height) { + if (r.Bottom + Content.Slot.Height > tc.ClientRectangle.Bottom) + Content.Top = r.Top - Content.Slot.Height; + else + Content.Top = r.Bottom; + }else + Content.Top = 0; + } } public Popper() : base() { } - + public override void ClearBinding () + { + //ensure popped window is cleared + if (Content != null) { + if (Content.Parent != null) { + IGOLibHost tc = Content.Parent as IGOLibHost; + if (tc != null) + tc.DeleteWidget (Content); + } + } + + base.ClearBinding (); + } + [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true public override bool Focusable { @@ -95,10 +152,7 @@ namespace go if (tc == null) return; if (Content != null) { - Rectangle r = this.ScreenCoordinates (this.Slot); Content.Visible = true; - Content.Left = r.Left; - Content.Top = r.Bottom; tc.AddWidget (Content); } Pop.Raise (this, e);