]> O.S.I.I.S - jp/crow.git/commitdiff
drag&drop in progress, replace BubblingEvents with focusGiven boolean in currentInterface
authorjpbruyere <jp.bruyere@hotmail.com>
Tue, 2 May 2017 09:46:26 +0000 (11:46 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 1 Feb 2018 06:42:26 +0000 (07:42 +0100)
Crow.csproj
src/BubblingMouseButtonEventArgs.cs [deleted file]
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/MenuItem.cs
src/GraphicObjects/TabItem.cs
src/GraphicObjects/Window.cs
src/Interface.cs

index 4ca2f5d006b4cf1b666a4a268c0e7a7888d68fac..751f5cb74f9878975ad26e875f6dfb91b22716c5 100644 (file)
@@ -97,7 +97,6 @@
     <Compile Include="src\GraphicObjects\ComboBox.cs" />
     <Compile Include="src\GraphicObjects\GroupBox.cs" />
     <Compile Include="src\GraphicObjects\ScrollBar.cs" />
-    <Compile Include="src\BubblingMouseButtonEventArgs.cs" />
     <Compile Include="src\SolidColor.cs" />
     <Compile Include="src\Gradient.cs" />
     <Compile Include="src\Fill\Fill.cs" />
diff --git a/src/BubblingMouseButtonEventArgs.cs b/src/BubblingMouseButtonEventArgs.cs
deleted file mode 100644 (file)
index 0c8afd2..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-//
-// BubblingMouseButtonEventArgs.cs
-//
-// Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-using System;
-
-namespace Crow
-{
-       public class BubblingMouseButtonEventArg: MouseButtonEventArgs
-       {
-               public GraphicObject Focused;
-               public BubblingMouseButtonEventArg(MouseButtonEventArgs mbe) : base(mbe){
-                       
-               }
-       }
-}
-
index feea75207e0e4861ba34d3125c9acb0d461ee8d4..d45ed304ab8186ad8a6d6f06fd847c23be88956a 100644 (file)
@@ -188,6 +188,9 @@ namespace Crow
                protected object dataSource;
                string style;
                object tag;
+               bool isDragged;
+               bool allowDrag;
+
                #endregion
 
                #region public fields
@@ -1008,6 +1011,45 @@ namespace Crow
                        return false;
                }
 
+               #region Drag&Drop
+               [XmlAttributeAttribute()][DefaultValue(false)]
+               public virtual bool AllowDrag {
+                       get { return allowDrag; }
+                       set {
+                               if (allowDrag == value)
+                                       return;
+                               allowDrag = value;
+                               NotifyValueChanged ("AllowDrag", allowDrag);
+                       }
+               }
+
+               public List<Type> AllowedDroppedTypes;
+
+               [XmlIgnore]public virtual bool AllowDrop {
+                       get { return AllowedDroppedTypes?.Count>0; }
+               }
+               [XmlIgnore]public virtual bool IsDragged {
+                       get { return isDragged; }
+                       set {
+                               if (isDragged == value)
+                                       return;
+                               isDragged = value;
+
+                               if (isDragged)
+                                       currentInterface.HoverWidget = null;
+
+                               NotifyValueChanged ("IsDrag", IsDragged);
+                       }
+               }
+
+               public void AddAllowedDroppedType (Type newType){
+                       if (AllowedDroppedTypes == null)
+                               AllowedDroppedTypes = new List<Type> ();
+                       AllowedDroppedTypes.Add (newType);
+                       NotifyValueChanged ("AllowDrop", AllowDrop);
+               }
+               #endregion
+
                #region Queuing
                /// <summary>
                /// Register old and new slot for clipping
@@ -1410,7 +1452,7 @@ namespace Crow
                public virtual bool MouseIsIn(Point m)
                {
                        try {
-                               if (!(Visible & isEnabled))
+                               if (!(Visible & isEnabled)||IsDragged)
                                        return false;
                                if (ScreenCoordinates (Slot).ContainsOrIsEqual (m)) {
                                        Scroller scr = Parent as Scroller;
@@ -1453,12 +1495,9 @@ namespace Crow
 
                        if (CurrentInterface.ActiveWidget == null)
                                CurrentInterface.ActiveWidget = this;
-                       if (this.Focusable && !Interface.FocusOnHover) {
-                               BubblingMouseButtonEventArg be = e as BubblingMouseButtonEventArg;
-                               if (be.Focused == null) {
-                                       be.Focused = this;
-                                       CurrentInterface.FocusedWidget = this;
-                               }
+                       if (this.Focusable && !(Interface.FocusOnHover || currentInterface.focusGiven)) {
+                               CurrentInterface.FocusedWidget = this;
+                               currentInterface.focusGiven = true;
                        }
                        //bubble event to the top
                        GraphicObject p = Parent as GraphicObject;
index 551db8892dbbae92a7ec5b053dfe7150b0b8df05..edb6a88e622cbc72a949d3d93c9966c4c7943326 100644 (file)
@@ -70,7 +70,7 @@ namespace Crow
                        g.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren);
                        g.LayoutChanged += OnChildLayoutChanges;
                }
-        public virtual void RemoveChild(GraphicObject child)        
+        public virtual void RemoveChild(GraphicObject child)
                {
                        child.LayoutChanged -= OnChildLayoutChanges;
                        //check if HoverWidget is removed from Tree
@@ -87,7 +87,7 @@ namespace Crow
                                searchLargestChild ();
                        if (child == tallestChild && Height == Measure.Fit)
                                searchTallestChild ();
-                       
+
                        this.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren);
         }
                public virtual void ClearChildren()
@@ -107,16 +107,22 @@ namespace Crow
                        ChildrenCleared.Raise (this, new EventArgs ());
                }
 
-//             public void putWidgetOnTop(GraphicObject w)
-//             {
-//                     if (Children.Contains(w))
-//                     {
-//                             lock (children) {
-//                                     Children.Remove (w);
-//                                     Children.Add (w);
-//                             }
-//                     }
-//             }
+               public void PutWidgetOnTop(GraphicObject w)
+               {
+                       if (this.ArrangeChildren) {
+                               Debug.WriteLine ("Can't raise widget in group that has ArrangeChildren set to true.");
+                               return;
+                       }
+                       if (Children.Contains(w))
+                       {
+                               lock (children) {
+                                       Children.Remove (w);
+                                       Children.Add (w);
+                               }
+                               lock (CurrentInterface.UpdateMutex)
+                                       CurrentInterface.EnqueueForRepaint (w);
+                       }
+               }
 //             public void putWidgetOnBottom(GraphicObject w)
 //             {
 //                     if (Children.Contains(w))
@@ -185,7 +191,7 @@ namespace Crow
                        }
                        return base.measureRawSize (lt);
                }
-                       
+
                public override void OnLayoutChanges (LayoutingType layoutType)
                {
                        base.OnLayoutChanges (layoutType);
@@ -345,7 +351,7 @@ namespace Crow
                        }
                }
 
-       
+
                #region Mouse handling
                public override void checkHoverWidget (MouseMoveEventArgs e)
                {
index 5565ace3ac652ada353f7e7daefb60e3c86898b3..cd2a54a8aebb730014779025bce8c6ff9a320c40 100644 (file)
@@ -156,7 +156,7 @@ namespace Crow
                }
                public override bool MouseIsIn (Point m)
                {
-                       return IsEnabled ? base.MouseIsIn (m) || child.MouseIsIn (m) : false;
+                       return IsEnabled && !IsDragged ? base.MouseIsIn (m) || child.MouseIsIn (m) : false;
                }
                public override void onMouseEnter (object sender, MouseMoveEventArgs e)
                {
index afafb0f191d4efe7da873266b2be37f46ad843c9..2fdc3802bb0a0b4144d626b8db7c39ba79351dee 100644 (file)
@@ -140,7 +140,7 @@ namespace Crow
                #region Mouse Handling
                public override bool MouseIsIn (Point m)
                {
-                       if (!Visible)
+                       if (!(Visible & IsEnabled) || IsDragged)
                                return false;
 
                        bool mouseIsInTitle = TabTitle.ScreenCoordinates (TabTitle.Slot).ContainsOrIsEqual (m);
index d1f3437483c4f7a550572667fde44014b3d846d3..ecbdb22aa30475b910af5a59f1cde45ef667be67 100644 (file)
@@ -171,7 +171,33 @@ namespace Crow
 //             } 
                #endregion
 
+               public void Raise (){
+                       Group g = LogicalParent as Group;
+                       if (g != null) {
+                               g.PutWidgetOnTop (this);
+                               return;
+                       }
+                       Interface i = LogicalParent as Interface;
+                       if (i != null)
+                               i.PutOnTop (this);
+               }
+
                #region GraphicObject Overrides
+               protected override void onFocused (object sender, EventArgs e)
+               {
+                       if (Interface.RaiseWhenFocused)
+                               this.Raise ();
+
+                       base.onFocused (sender, e);
+               }
+               public override void onMouseEnter (object sender, MouseMoveEventArgs e)
+               {
+                       if (Interface.FocusOnHover && !CurrentInterface.focusGiven) {
+                               CurrentInterface.FocusedWidget = this;
+                               CurrentInterface.focusGiven = true;
+                       }
+                       base.onMouseEnter (sender, e);
+               }
                public override void onMouseMove (object sender, MouseMoveEventArgs e)
                {
                        base.onMouseMove (sender, e);
index 7d6911523d8afb6e255cafd47514d08b93bd2333..2dab2c854e82a3471f4f1a18fdbedafbb2653a35 100644 (file)
@@ -96,6 +96,8 @@ namespace Crow
                public static string CrowConfigRoot;
                /// <summary>If true, mouse focus is given when mouse is over control</summary>
                public static bool FocusOnHover = false;
+               /// <summary>Raise widget when it got focus </summary>
+               public static bool RaiseWhenFocused = true;
                /// <summary> Threshold to catch borders for sizing </summary>
                public static int BorderThreshold = 5;
                /// <summary>Double click threshold in milisecond</summary>
@@ -129,6 +131,11 @@ namespace Crow
                internal static Interface CurrentInterface;
                internal Stopwatch clickTimer = new Stopwatch();
                internal GraphicObject eligibleForDoubleClick = null;
+               /// <summary>
+               /// each time a processMouseEvent is called at the top level, the focusGiven is set to false, and if while bubbling up the event
+               /// give the focus to a new widget, this boolean is set to true to prevent giving focus multiple times for a single mouse event.
+               /// </summary>
+               internal bool focusGiven = false;
                #endregion
 
                #region Events
@@ -738,6 +745,8 @@ namespace Crow
                /// <returns>true if mouse is in the interface</returns>
                public bool ProcessMouseMove(int x, int y)
                {
+                       focusGiven = false;
+
                        int deltaX = x - Mouse.X;
                        int deltaY = y - Mouse.Y;
                        Mouse.X = x;
@@ -802,8 +811,6 @@ namespace Crow
                                        GraphicObject g = GraphicTree [i];
                                        if (g.MouseIsIn (e.Position)) {
                                                g.checkHoverWidget (e);
-                                               if (g is Window)
-                                                       PutOnTop (g);
                                                return true;
                                        }
                                }
@@ -818,6 +825,8 @@ namespace Crow
                /// <param name="button">Button index</param>
                public bool ProcessMouseButtonUp(int button)
                {
+                       focusGiven = false;
+
                        Mouse.DisableBit (button);
                        MouseButtonEventArgs e = new MouseButtonEventArgs () { Mouse = Mouse };
 
@@ -841,13 +850,15 @@ namespace Crow
                /// <param name="button">Button index</param>
                public bool ProcessMouseButtonDown(int button)
                {
+                       focusGiven = false;
+
                        Mouse.EnableBit (button);
                        MouseButtonEventArgs e = new MouseButtonEventArgs () { Mouse = Mouse };
 
                        if (HoverWidget == null)
                                return false;
 
-                       HoverWidget.onMouseDown(HoverWidget,new BubblingMouseButtonEventArg(e));
+                       HoverWidget.onMouseDown(HoverWidget, e);
 
                        if (FocusedWidget == null)
                                return true;