]> O.S.I.I.S - jp/crow.git/commitdiff
center docking
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 4 Mar 2018 18:59:29 +0000 (19:59 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 4 Mar 2018 18:59:29 +0000 (19:59 +0100)
src/Enums.cs
src/GraphicObjects/DockStack.cs
src/GraphicObjects/DockWindow.cs
src/GraphicObjects/Docker.cs
src/GraphicObjects/GraphicObject.cs

index 6249135b7ccee812937f6468f7824fac6954b768..8b90d6ea54da15caacc5f28cdd75468163628b82 100644 (file)
@@ -47,7 +47,8 @@ namespace Crow
                Bottom = 0x08,
         BottomLeft = 0x0a,
         BottomRight = 0x0c,
-               Center = 0x10
+               Center = 0x10,
+               Undefined = 0x40
     }
     public enum HorizontalAlignment
     {
index 7d5baf327b1d31befc077d39f11e357d18829d73..2c99a8b61dc5e3dfbfddfd725d5b12ef02849cd1 100644 (file)
@@ -113,8 +113,13 @@ namespace Crow
                                        dw.DockingPosition = Alignment.Top;
                                else if (lm.Y > r.Bottom - vTreshold)
                                        dw.DockingPosition = Alignment.Bottom;
-                               else
-                                       dw.DockingPosition = Alignment.Center;
+                               else {
+                                       r.Inflate (-r.Width / 3, -r.Height / 3);
+                                       if (r.ContainsOrIsEqual(lm))
+                                               dw.DockingPosition = Alignment.Center;
+                                       else
+                                               dw.DockingPosition = Alignment.Undefined;
+                               }
 
                                if (curDockPos != dw.DockingPosition)
                                        RegisterForGraphicUpdate ();
@@ -167,10 +172,13 @@ namespace Crow
                                
                                Rectangle r;
 
-                               if (dw.DockingPosition.GetOrientation() == Orientation || SubStack == null)
+                               if ((dw.DockingPosition.GetOrientation () == Orientation || SubStack == null)&&dw.DockingPosition != Alignment.Center) {
                                        r = ClientRectangle;
-                               else
-                                       r = SubStack.ClientRectangle + SubStack.Slot.Position + ClientRectangle.TopLeft;
+                                       Console.WriteLine ("Same rect substack=" + SubStack);
+                               }else {
+                                       r = subStack.ClientRectangle + subStack.Slot.Position + ClientRectangle.TopLeft;
+                                       Console.WriteLine ("sub rect");
+                               }
                                
                                switch (dw.DockingPosition) {
                                case Alignment.Top:
@@ -185,6 +193,10 @@ namespace Crow
                                case Alignment.Right:
                                        gr.Rectangle (r.Right - r.Width / dockingDiv, r.Top, r.Width / dockingDiv, r.Height);
                                        break;
+                               case Alignment.Center:
+                                       r.Inflate (-Math.Min (r.Width, r.Height) / dockingDiv);
+                                       gr.Rectangle (r);
+                                       break;
                                }
                                gr.LineWidth = 1;
                                gr.SetSourceRGBA (0.4, 0.4, 0.9, 0.4);
@@ -196,35 +208,53 @@ namespace Crow
                }
 
                public void Undock (DockWindow dw){
-                       int dwIdx = Children.IndexOf(dw);
+                       int idx = Children.IndexOf(dw);
 
                        RemoveChild(dw);
 
-                       if (dw.DockingPosition == Alignment.Left || dw.DockingPosition == Alignment.Top)                                
-                               RemoveChild (dwIdx);
-                        else
-                               RemoveChild (dwIdx - 1);
+                       if (rootDock.CenterDockedObj == dw) {                           
+                               rootDock.CenterDockedObj = new GraphicObject (IFace) { IsEnabled = false, Background = Color.AmberSaeEce.AdjustAlpha(0.3) };
+                               InsertChild (idx, rootDock.CenterDockedObj);
+                               SubStack = rootDock.CenterDockedObj;
+                       }else if (dw.DockingPosition == Alignment.Left || dw.DockingPosition == Alignment.Top)                          
+                               RemoveChild (idx);
+                       else
+                               RemoveChild (idx - 1);
 
                        if (Children.Count > 1)
                                return;
+
                        DockStack dsp = Parent as DockStack;
-                       if (dsp == null) {
-                               RemoveChild (0);
-                               if (SubStack is DockStack) {
-                                       Docker dk = Parent as Docker;
-                                       dk.RemoveChild (this);
-                                       dk.InsertChild (0, SubStack);
-                                       dk.SubStack = SubStack as DockStack;
-                               }
-                               SubStack = null;
+                       if (dsp == null)
                                return;
-                       }
-                       GraphicObject g = Children [0];
-                       RemoveChild (g);
-                       int i = dsp.Children.IndexOf (this);
+
+                       RemoveChild (0);
+                       idx = dsp.Children.IndexOf (this);
                        dsp.RemoveChild (this);
-                       dsp.InsertChild (i, g);
-                       dsp.SubStack = g;
+                       dsp.InsertChild (idx, SubStack);
+                       dsp.SubStack = SubStack;
+                       return;
+
+//                     Docker dk = Parent as Docker;
+//                     dk.RemoveChild (this);
+//                     dk.AddChild (SubStack);
+//                     dk.SubStack = SubStack;
+
+//                             if (SubStack is DockStack) {
+//                                     Docker dk = Parent as Docker;
+//                                     dk.RemoveChild (this);
+//                                     dk.InsertChild (0, SubStack);
+//                                     dk.SubStack = SubStack as DockStack;
+//                             }
+//                             SubStack = null;
+//                             return;
+//                     }
+//                     GraphicObject g = Children [0];
+//                     RemoveChild (g);
+//                     int i = dsp.Children.IndexOf (this);
+//                     dsp.RemoveChild (this);
+//                     dsp.InsertChild (i, g);
+//                     dsp.SubStack = g;
                }
                public void Dock(DockWindow dw){
                        Splitter splitter = instSplit.CreateInstance<Splitter> ();
@@ -235,70 +265,52 @@ namespace Crow
 
                        DockStack activeStack = this;
 
-                       if (SubStack == null) {
+                       if (Children.Count == 1) {
                                activeStack = this;
-                               SubStack = rootDock.CenterDockedObj;
+                               Orientation = dw.DockingPosition.GetOrientation ();
                        }else if (dw.DockingPosition.GetOrientation() != Orientation) {
-                               int i = Children.IndexOf (SubStack);
-                               RemoveChild (SubStack);
+                               int i = Children.IndexOf (rootDock.CenterDockedObj);
+                               RemoveChild (rootDock.CenterDockedObj);
                                activeStack = instStack.CreateInstance<DockStack> ();
                                activeStack.SubStack = rootDock.CenterDockedObj;
                                SubStack = activeStack;
-                               InsertChild(i, activeStack);                             
+                               InsertChild(i, activeStack);
+                               activeStack.AddChild (rootDock.CenterDockedObj);
+                               activeStack.Orientation = dw.DockingPosition.GetOrientation ();
                        }
 
                        switch (dw.DockingPosition) {
                        case Alignment.Top:                                             
                                dw.Height = vTreshold;
                                dw.Width = Measure.Stretched;
-                               if (activeStack.Children.Count == 0) {
-                                       activeStack.Orientation = Orientation.Vertical;
-                                       activeStack.AddChild (dw);
-                                       activeStack.AddChild (splitter);
-                                       activeStack.AddChild (activeStack.SubStack);
-                               } else {
-                                       activeStack.InsertChild (0, dw);
-                                       activeStack.InsertChild (1, splitter);
-                               }
+                               activeStack.InsertChild (0, dw);
+                               activeStack.InsertChild (1, splitter);
                                break;
                        case Alignment.Bottom:
                                dw.Height = vTreshold;
                                dw.Width = Measure.Stretched;
-                               if (activeStack.Children.Count == 0) {
-                                       activeStack.Orientation = Orientation.Vertical;
-                                       activeStack.AddChild (activeStack.SubStack);
-                                       activeStack.AddChild (splitter);
-                                       activeStack.AddChild (dw);
-                               } else {
-                                       activeStack.AddChild (splitter);
-                                       activeStack.AddChild (dw);
-                               }
+                               activeStack.AddChild (splitter);
+                               activeStack.AddChild (dw);
                                break;
                        case Alignment.Left:
                                dw.Width = hTreshold;
                                dw.Height = Measure.Stretched;
-                               if (activeStack.Children.Count == 0) {
-                                       activeStack.Orientation = Orientation.Horizontal;
-                                       activeStack.AddChild (dw);
-                                       activeStack.AddChild (splitter);
-                                       activeStack.AddChild (activeStack.SubStack);
-                               } else {
-                                       activeStack.InsertChild (0, dw);
-                                       activeStack.InsertChild (1, splitter);
-                               }
+                               activeStack.InsertChild (0, dw);
+                               activeStack.InsertChild (1, splitter);
                                break;
                        case Alignment.Right:
                                dw.Width = hTreshold;
                                dw.Height = Measure.Stretched;
-                               if (activeStack.Children.Count == 0) {
-                                       activeStack.Orientation = Orientation.Horizontal;
-                                       activeStack.AddChild (activeStack.SubStack);
-                                       activeStack.AddChild (splitter);
-                                       activeStack.AddChild (dw);
-                               } else {
-                                       activeStack.AddChild (splitter);
-                                       activeStack.AddChild (dw);
-                               }
+                               activeStack.AddChild (splitter);
+                               activeStack.AddChild (dw);
+                               break;
+                       case Alignment.Center:
+                               dw.Width = dw.Height = Measure.Stretched;                                
+                               int i = activeStack.Children.IndexOf (rootDock.CenterDockedObj);
+                               activeStack.DeleteChild (i);
+                               activeStack.InsertChild (i, dw);
+                               activeStack.SubStack = dw;
+                               rootDock.CenterDockedObj= dw;
                                break;
                        }
                }
index 3617f5b91faabeea8593df326be8e5f646d3c921..c793411492918cce218d806630454f4d3606b6e1 100644 (file)
@@ -37,7 +37,7 @@ namespace Crow
 
                int undockThreshold = 4;
                bool isDocked = false;
-               Alignment docking = Alignment.Center;
+               Alignment docking = Alignment.Undefined;
 
                Point lastMousePos;     //last known mouse pos in this control
                Point undockingMousePosOrig; //mouse pos when docking was donne, use for undocking on mouse move
@@ -148,7 +148,7 @@ namespace Crow
                }
                protected override void onDrop (object sender, DragDropEventArgs e)
                {
-                       if (!isDocked && DockingPosition != Alignment.Center)
+                       if (!isDocked && DockingPosition != Alignment.Undefined)
                                dock (e.DropTarget as DockStack);
                        base.onDrop (sender, e);
                }
@@ -165,10 +165,13 @@ namespace Crow
                                this.Height = savedSlot.Height;
 
                                IsDocked = false;
+                               DockingPosition = Alignment.Undefined;
                                Resizable = wasResizable;
                        }
                }
-               void dock (DockStack target){                   
+               void dock (DockStack target){
+                       if (RootDock.CenterDockedObj is DockWindow && DockingPosition == Alignment.Center)
+                               return;
                        lock (IFace.UpdateMutex) {
                                IsDocked = true;
                                undockingMousePosOrig = lastMousePos;
index a14d70bed511f0207d6685ca4f26db4647e33b92..f189907c2bb5ba6cded2aab4ea5d33e7665a4666 100644 (file)
@@ -55,14 +55,13 @@ namespace Crow
                                        return;
                                dockingThreshold = value; 
                                NotifyValueChanged ("DockingThreshold", dockingThreshold);
-
                        }
                }
 
                protected override void onInitialized (object sender, EventArgs e)
                {
                        base.onInitialized (sender, e);
-                       CenterDockedObj = new GraphicObject (IFace) { IsEnabled = false };
+                       CenterDockedObj = new GraphicObject (IFace) { IsEnabled = false, Background = Color.Cobalt };
                }
 
                public override void AddChild (GraphicObject g)
@@ -77,10 +76,13 @@ namespace Crow
                                DockWindow dw = IFace.DragAndDropOperation.DragSource as DockWindow;
                                if (!dw.IsDocked)
                                        dw.MoveAndResize (e.XDelta, e.YDelta);
-                               if (SubStack == null) {                         
-                                       SubStack = new DockStack (IFace);
+                               if (SubStack == null) {
+                                       DockStack ds = new DockStack (IFace);
+                                       SubStack = ds;
                                        InsertChild (0, SubStack);
-                                       SubStack.LogicalParent = this;
+                                       ds.LogicalParent = this;
+                                       ds.AddChild (CenterDockedObj);
+                                       ds.SubStack = CenterDockedObj;
                                }
                        }
                        base.onMouseMove (sender, e);
index 8ba8788d789f0757750510bdabc8c0484bef5ec2..f6778e34bf4e8d9f5e90de2a0414d9fb6f7053c9 100644 (file)
@@ -1806,9 +1806,17 @@ namespace Crow
                        Debug.WriteLine("MouseHover => " + this.ToString());
                        #endif
                        if (IFace.DragAndDropOperation != null) {
-                               if (this.AllowDrop) {
-                                       if (IFace.DragAndDropOperation.DragSource != this && IFace.DragAndDropOperation.DropTarget != this)
-                                               onDragEnter (this, IFace.DragAndDropOperation);                                 
+                               GraphicObject g = this;
+                               while (g != null) {
+                                       if (g.AllowDrop) {
+                                               if (IFace.DragAndDropOperation.DragSource != this && IFace.DragAndDropOperation.DropTarget != this) {
+                                                       if (IFace.DragAndDropOperation.DropTarget != null)
+                                                               IFace.DragAndDropOperation.DropTarget.onDragLeave (this, IFace.DragAndDropOperation);
+                                                       g.onDragEnter (this, IFace.DragAndDropOperation);
+                                               }
+                                               break;
+                                       }
+                                       g = g.focusParent;
                                }
                        }
                        Hover.Raise (this, e);
@@ -1818,10 +1826,6 @@ namespace Crow
                        #if DEBUG_FOCUS
                        Debug.WriteLine("MouseUnHover => " + this.ToString());
                        #endif
-                       if (IFace.DragAndDropOperation != null) {
-                               if (IFace.DragAndDropOperation.DropTarget == this)
-                                       onDragLeave (this, IFace.DragAndDropOperation);
-                       }
                        UnHover.Raise (this, e);
                }
                #endregion