]> O.S.I.I.S - jp/crow.git/commitdiff
debug mouse leave, move recursive test back into interface instead of go.MouseLeave
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 31 Aug 2016 10:26:16 +0000 (12:26 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Thu, 1 Sep 2016 10:44:39 +0000 (12:44 +0200)
Menu IsOpen handling
MenuItem Open and Close events

Default.style
Templates/MenuItem.template
Tests/Interfaces/TemplatedGroup/0.crow
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Menu.cs
src/GraphicObjects/MenuItem.cs
src/GraphicObjects/Popper.cs
src/GraphicObjects/TemplatedContainer.cs
src/GraphicObjects/TemplatedGroup.cs
src/Interface.cs

index f79ded376ba6b52d714df26e0f1b84c6c2f2e896..933f89fea790969ea9c31f80c03e03d0ea71588d 100644 (file)
@@ -26,6 +26,8 @@ MenuItem {
        Width = Fit;
        Background = Transparent;
        Foreground = LightGray;
+       Open = {Background = Mantis;Foreground=Jet;}
+       Close = {Foreground=LightGray;Background=Transparent;}
 }
 MessageBox {
        Width=200;
index 4d96405bbb5bb0784a79fa6b47fff609f4c27673..c03cc27d32af9e048eca66d81bdd194db3180822 100644 (file)
@@ -1,9 +1,7 @@
 <?xml version="1.0"?>
 <Popper Caption="{./Caption}"  Background="{./Background}" PopDirection="{./PopDirection}"
        Foreground = "{./Foreground}" CanPop="{./HasChildren}" MouseClick="./onMI_Click"
-       Unpop = "{Foreground=LightGray;Background=Transparent}"
-       Pop = "{Background = Mantis;Foreground=Jet}"
-       >
+       IsPopped="{²./IsOpened}">
        <Template>
                <Border Name="border1"
                                MouseEnter="{Foreground=vgradient|0:White|0.2:Gray|0.9:Gray|1:Black}"
index 1ab5f9add288b2ba57de1851ba8a786f746ecd34..c502e63a513a0b54b5d9fb515c2f577dd0c70385 100755 (executable)
@@ -6,11 +6,16 @@
                <MenuItem Caption="Save"/>
                <MenuItem Caption="Quit"/>
        </MenuItem>
-       <MenuItem Caption="Edit">
+       <MenuItem Caption="Edit" Name="edit">
                <MenuItem Caption="Cut"/>
                <MenuItem Caption="Copy"/>
                <MenuItem Caption="Paste"/>
-               <MenuItem Caption="Special">
+               <MenuItem Caption="Special" Name="special">
+                       <MenuItem Caption="Cut"/>
+                       <MenuItem Caption="Copy"/>
+                       <MenuItem Caption="Paste"/>
+               </MenuItem>
+               <MenuItem Caption="Special2" Name="special">
                        <MenuItem Caption="Cut"/>
                        <MenuItem Caption="Copy"/>
                        <MenuItem Caption="Paste"/>
index f5b19bb07add54829c31a80d018b000ea67bed54..6572ba52b08cd63ca8ceaf40e52f67ff3cbe181d 100644 (file)
@@ -1176,17 +1176,6 @@ namespace Crow
                        Debug.WriteLine("MouseLeave => " + this.ToString());
                        #endif
                        MouseLeave.Raise (this, e);
-
-                       GraphicObject p = Parent as GraphicObject;
-                       CurrentInterface.HoverWidget = p;
-
-                       if (p == null)
-                               return;
-
-                       if (p.MouseIsIn (e.Position)&&e!=null)
-                               p.checkHoverWidget (e);
-                       else
-                               p.onMouseLeave (sender, e);
                }
                #endregion
 
index f3759c68f572ff63afa02fcadacd479f9e329463..765925e960df4541a8d7e5307eeb501b3e6a022a 100644 (file)
@@ -38,6 +38,16 @@ namespace Crow
                                NotifyValueChanged ("Orientation", orientation);
                        }
                }
+               bool isOpened = false;
+               public bool IsOpened
+               {
+                       get { return isOpened; }
+                       set
+                       {
+                               isOpened = value;
+                               System.Diagnostics.Debug.WriteLine ("is opened = " + isOpened);
+                       }
+               }
 
                public Menu () : base()
                {
@@ -52,5 +62,11 @@ namespace Crow
                        else
                                g.NotifyValueChanged ("PopDirection", Alignment.Right);
                }
+               public override void onMouseLeave (object sender, MouseMoveEventArgs e)
+               {
+                       base.onMouseLeave (sender, e);
+                       IsOpened = false;
+               }
        }
 }
+
index 9055fc5bdf10bc6fa01d0da21d438bbf8c9f0d35..6023336192fbbc74788b583e464dc8f6809f36d4 100644 (file)
@@ -30,12 +30,34 @@ namespace Crow
                public MenuItem () : base() {}
                #endregion
 
+               public event EventHandler Open;
+               public event EventHandler Close;
                public event EventHandler Execute;
 
                string caption;
                Command command;//TODO
+               bool isOpened;
 
-               [XmlAttributeAttribute()][DefaultValue(null)]
+               [XmlAttributeAttribute][DefaultValue(false)]
+               public bool IsOpened {
+                       //get { return MenuRoot == null ? false : MenuRoot.IsOpened; }
+                       get { return isOpened; }
+                       set {
+                               if (isOpened == value)
+                                       return;
+                               isOpened = value;
+                               NotifyValueChanged ("IsOpened", isOpened);
+
+                               if (isOpened) {
+                                       onOpen (this, null);
+                                       if (MenuRoot != null)
+                                               MenuRoot.IsOpened = true;
+                               }else
+                                       onClose (this, null);
+                       }
+               }
+
+               [XmlAttributeAttribute][DefaultValue(null)]
                public virtual Command Command {
                        get { return command; }
                        set {
@@ -59,11 +81,11 @@ namespace Crow
 
                [XmlIgnore]Menu MenuRoot {
                        get {
-                               ILayoutable tmp = Parent;
+                               ILayoutable tmp = LogicalParent;
                                while (tmp != null) {
                                        if (tmp is Menu)
                                                return tmp as Menu;
-                                       tmp = tmp.Parent;
+                                       tmp = tmp.LogicalParent;
                                }
                                return null;
                        }
@@ -79,6 +101,21 @@ namespace Crow
                {
                        Execute.Raise (this, null);
                }
+               void onOpen (object sender, EventArgs e){
+                       MenuRoot.IsOpened = true;
+                       Open.Raise (this, null);
+               }
+               void onClose (object sender, EventArgs e){
+                       //MenuRoot.IsOpened = true;
+                       Close.Raise (this, null);
+               }
+               public override void onMouseEnter (object sender, MouseMoveEventArgs e)
+               {
+                       base.onMouseEnter (sender, e);
+                       if (MenuRoot == null || Items.Count == 0)
+                               return;
+                       IsOpened = MenuRoot.IsOpened;
+               }
        }
 }
 
index e0da009674a22a5bc087a2a18b31aa598258c3e3..1bfdf19ce89e5c14590ad1a7dd18d7c83571e078 100644 (file)
@@ -27,11 +27,11 @@ using OpenTK.Input;
 namespace Crow
 {
     public class Popper : TemplatedContainer
-    {          
+    {
                #region CTOR
                public Popper() : base()
                {
-               }       
+               }
                #endregion
 
                bool _isPopped, _canPop;
@@ -45,11 +45,11 @@ namespace Crow
                #region Public Properties
                [XmlAttributeAttribute()][DefaultValue("Popper")]
                public string Caption {
-                       get { return caption; } 
+                       get { return caption; }
                        set {
                                if (caption == value)
                                        return;
-                               caption = value; 
+                               caption = value;
                                NotifyValueChanged ("Caption", caption);
                        }
                }
@@ -99,14 +99,13 @@ namespace Crow
 
                public override GraphicObject Content {
                        get { return _content; }
-                       set { 
+                       set {
                                if (_content != null) {
                                        _content.LogicalParent = null;
                                        _content.LayoutChanged -= _content_LayoutChanged;
-                                       _content.MouseLeave -= onMouseLeave;
                                }
-                               
-                               _content = value; 
+
+                               _content = value;
 
                                if (_content == null)
                                        return;
@@ -115,7 +114,6 @@ namespace Crow
                                _content.HorizontalAlignment = HorizontalAlignment.Left;
                                _content.VerticalAlignment = VerticalAlignment.Top;
                                _content.LayoutChanged += _content_LayoutChanged;
-                               _content.MouseLeave += onMouseLeave;
                        }
                }
 
@@ -172,9 +170,9 @@ namespace Crow
 
                        if (_content == null)
                                return;
-                       
+
                        if (layoutType == LayoutingType.Width)
-                               _content.MinimumSize = new Size (this.Slot.Width, _content.MinimumSize.Height);                 
+                               _content.MinimumSize = new Size (this.Slot.Width, _content.MinimumSize.Height);
                }
 
                public override void ClearBinding ()
@@ -201,11 +199,21 @@ namespace Crow
                }
                public override void onMouseLeave (object sender, MouseMoveEventArgs e)
                {
-                       base.onMouseLeave (sender, e);
-                       IsPopped = false;
+                       if (!_isPopped || _content == null) {
+                               base.onMouseLeave (sender, e);
+                               System.Diagnostics.Debug.WriteLine ("NotPopped***popper mouse leave:"+ this.ToString());
+                               return;
+                       }
+
+                       if (!_content.MouseIsIn (e.Position)) {
+                               base.onMouseLeave (sender, e);
+                               System.Diagnostics.Debug.WriteLine ("***popper mouse leave:"+ this.ToString());
+                               IsPopped = false;
+                               return;
+                       }
                }
                #endregion
-                       
+
                public virtual void onPop(object sender, EventArgs e)
                {
                        if (Content != null) {
index 18977cf9416f3a0542d1699f8c3e926eccbb21a2..7a4649a495212fd4761044b3484901b8a75aac6c 100644 (file)
@@ -54,6 +54,15 @@ namespace Crow
 
                        return Content == null ? null : Content.FindByName (nameToFind);
                }
+               public override bool Contains (GraphicObject goToFind)
+               {
+                       if (Content == null)
+                               return base.Contains (goToFind);
+
+                       if (Content == goToFind)
+                               return true;
+                       return Content.Contains (goToFind);
+               }
                #endregion
 
                #region IXmlSerialisation Overrides
@@ -66,7 +75,7 @@ namespace Crow
                                //seek for template tag
                                using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
                                        xr.Read ();
-                                       base.ReadXml (xr);              
+                                       base.ReadXml (xr);
                                }
                                //process content
                                using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
@@ -77,7 +86,7 @@ namespace Crow
 
                                                if (!xr.IsStartElement ())
                                                        continue;
-                                               
+
                                                if (xr.Name == "Template"){
                                                        xr.Skip ();
                                                        if (!xr.IsStartElement ())
@@ -94,8 +103,8 @@ namespace Crow
                                                }
                                                if (t == null)
                                                        throw new Exception (xr.Name + " type not found");
-                                               
-                                               GraphicObject go = (GraphicObject)Activator.CreateInstance (t);                                
+
+                                               GraphicObject go = (GraphicObject)Activator.CreateInstance (t);
 
                                                (go as IXmlSerializable).ReadXml (xr);
 
index f7f849c063856fd66a883aa6c8338cbc9a8ca146..0d48b9eb24089d5248efd46293ee4fd6f48774a5 100644 (file)
@@ -87,7 +87,7 @@ namespace Crow
                                if (w.Contains (goToFind))
                                        return true;
                        }
-                       return false;
+                       return base.Contains(goToFind);
                }
 //             public override void ClearBinding ()
 //             {
index 73f44a6aec5bd0a397f888c55840ec46de6ff268..d01d2e8fdcb11f5cbbe19d57fa8306eca397a441 100644 (file)
@@ -572,8 +572,15 @@ namespace Crow
                                        int i = 0;
                                        while (i < idxhw) {
                                                if (GraphicTree [i].MouseIsIn (e.Position)) {
-                                                       //set evtarg to null to force mouseLeave without checking mouse pos
-                                                       HoverWidget.onMouseLeave (HoverWidget, null);
+                                                       while (HoverWidget != null) {
+                                                               if (HoverWidget is Popper) {
+                                                                       if ((HoverWidget as Popper).Content == GraphicTree[i])
+                                                                               break;
+                                                               }
+                                                               HoverWidget.onMouseLeave (HoverWidget, e);
+                                                               HoverWidget = HoverWidget.LogicalParent as GraphicObject;
+                                                       }
+
                                                        GraphicTree [i].checkHoverWidget (e);
                                                        return true;
                                                }
@@ -587,8 +594,15 @@ namespace Crow
                                        return true;
                                } else {
                                        HoverWidget.onMouseLeave (HoverWidget, e);
-                                       if (HoverWidget != null)
-                                               return true;
+                                       //seek upward from last focused graph obj's
+                                       while (HoverWidget.LogicalParent as GraphicObject != null) {
+                                               HoverWidget = HoverWidget.LogicalParent as GraphicObject;
+                                               if (HoverWidget.MouseIsIn (e.Position)) {
+                                                       HoverWidget.checkHoverWidget (e);
+                                                       return true;
+                                               } else
+                                                       HoverWidget.onMouseLeave (HoverWidget, e);
+                                       }
                                }
                        }