]> O.S.I.I.S - jp/crow.git/commitdiff
menuItem derived from Menu + automatic opening when sibling opens
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 4 Jan 2017 19:18:18 +0000 (20:18 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 4 Jan 2017 19:18:18 +0000 (20:18 +0100)
src/GraphicObjects/Menu.cs
src/GraphicObjects/MenuItem.cs

index 5726afdfb07cde3c4e102f09ffcafccdc1f22320..1a7a3f95e2a3e5ce3d4600705a89158875d03f80 100644 (file)
@@ -26,10 +26,14 @@ namespace Crow
 {
        public class Menu : TemplatedGroup
        {
+               #region CTOR
+               public Menu () : base() {}
+               #endregion
+
                Orientation orientation;
 
                [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)]
-               public virtual Orientation Orientation {
+               public Orientation Orientation {
                        get { return orientation; }
                        set {
                                if (orientation == value)
@@ -38,23 +42,15 @@ 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()
+               bool autoOpen = false;
+               [XmlIgnore]public bool AutomaticOpenning
                {
+                       get { return autoOpen; }
+                       set     { autoOpen = value;     }
                }
 
                public override void AddItem (GraphicObject g)
-               {
+               {                       
                        base.AddItem (g);
 
                        if (orientation == Orientation.Horizontal)
@@ -65,7 +61,7 @@ namespace Crow
                public override void onMouseLeave (object sender, MouseMoveEventArgs e)
                {
                        base.onMouseLeave (sender, e);
-                       //IsOpened = false;
+                       AutomaticOpenning = false;
                }
        }
 }
index 87744ef9b911a701254a0e52552a0e340a02ec91..80b5759da97bd5078e532dcaf47e39da29afda20 100644 (file)
@@ -24,7 +24,7 @@ using System.ComponentModel;
 
 namespace Crow
 {
-       public class MenuItem : TemplatedGroup
+       public class MenuItem : Menu
        {
                #region CTOR
                public MenuItem () : base() {}
@@ -47,9 +47,10 @@ namespace Crow
                                isOpened = value;
                                NotifyValueChanged ("IsOpened", isOpened);
 
-                               if (isOpened)
+                               if (isOpened) {
                                        onOpen (this, null);
-                               else
+                                       (LogicalParent as Menu).AutomaticOpenning = true;
+                               }else
                                        onClose (this, null);
                        }
                }
@@ -75,19 +76,7 @@ namespace Crow
                                NotifyValueChanged ("Caption", caption);
                        }
                }
-
-               [XmlIgnore]Menu MenuRoot {
-                       get {
-                               ILayoutable tmp = LogicalParent;
-                               while (tmp != null) {
-                                       if (tmp is Menu)
-                                               return tmp as Menu;
-                                       tmp = tmp.LogicalParent;
-                               }
-                               return null;
-                       }
-               }
-
+                       
                public override void AddItem (GraphicObject g)
                {
                        base.AddItem (g);
@@ -97,6 +86,8 @@ namespace Crow
                void onMI_Click (object sender, MouseButtonEventArgs e)
                {
                        Execute.Raise (this, null);
+                       if(!IsOpened)
+                               (LogicalParent as Menu).AutomaticOpenning = false;
                }
                protected virtual void onOpen (object sender, EventArgs e){
                        Open.Raise (this, null);
@@ -108,6 +99,12 @@ namespace Crow
                {
                        return base.MouseIsIn (m) || child.MouseIsIn (m);
                }
+               public override void onMouseEnter (object sender, MouseMoveEventArgs e)
+               {
+                       base.onMouseEnter (sender, e);
+                       if ((LogicalParent as Menu).AutomaticOpenning && items.Children.Count>0)
+                               IsOpened = true;
+               }
                public override void onMouseLeave (object sender, MouseMoveEventArgs e)
                {
                        if (IsOpened)