aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/DockWindow.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/GraphicObjects/DockWindow.cs')
-rw-r--r--src/GraphicObjects/DockWindow.cs191
1 files changed, 68 insertions, 123 deletions
diff --git a/src/GraphicObjects/DockWindow.cs b/src/GraphicObjects/DockWindow.cs
index b68a3085..4c71c92d 100644
--- a/src/GraphicObjects/DockWindow.cs
+++ b/src/GraphicObjects/DockWindow.cs
@@ -35,6 +35,7 @@ namespace Crow
}
#endregion
+ int undockThreshold = 10;
bool isDocked = false;
Alignment docking = Alignment.Center;
@@ -43,6 +44,8 @@ namespace Crow
Rectangle savedSlot; //last undocked slot recalled when view is undocked
bool wasResizable;
+ public Docker RootDock { get { return LogicalParent as Docker; }}
+
public bool IsDocked {
get { return isDocked; }
set {
@@ -61,12 +64,7 @@ namespace Crow
NotifyValueChanged ("DockingPosition", DockingPosition);
}
}
- protected override void onDrop (object sender, DragDropEventArgs e)
- {
- base.onDrop (sender, e);
- Docker dv = Parent as Docker;
- dv.Dock (this);
- }
+
public override bool PointIsIn (ref Point m)
{
if (!base.PointIsIn(ref m))
@@ -78,6 +76,8 @@ namespace Crow
for (int i = p.Children.Count - 1; i >= 0; i--) {
if (p.Children [i] == this)
break;
+ if (p.Children [i].IsDragged)
+ continue;
if (p.Children [i].Slot.ContainsOrIsEqual (m)) {
return false;
}
@@ -113,130 +113,75 @@ namespace Crow
// }
// }
//
-// public override void onMouseMove (object sender, MouseMoveEventArgs e)
-// {
-// lastMousePos = e.Position;
-//
-// if (this.HasFocus && e.Mouse.IsButtonDown (MouseButton.Left) && IsDocked) {
-// Docker dv = Parent as Docker;
-// if (docking == Alignment.Left) {
-// if (lastMousePos.X - undockingMousePosOrig.X > dv.DockingThreshold)
-// undock ();
-// } else if (docking == Alignment.Right) {
-// if (undockingMousePosOrig.X - lastMousePos.X > dv.DockingThreshold)
-// undock ();
-// } else if (docking == Alignment.Top) {
-// if (lastMousePos.Y - undockingMousePosOrig.Y > dv.DockingThreshold)
-// undock ();
-// } else if (docking == Alignment.Bottom) {
-// if (undockingMousePosOrig.Y - lastMousePos.Y > dv.DockingThreshold)
-// undock ();
-// }
-// return;
-// }
-//
-// base.onMouseMove (sender, e);
-// }
-// public override void onMouseDown (object sender, MouseButtonEventArgs e)
-// {
-// base.onMouseDown (sender, e);
-//
-// if (this.HasFocus && IsDocked && e.Button == MouseButton.Left)
-// undockingMousePosOrig = lastMousePos;
-// }
+ public override void onMouseMove (object sender, MouseMoveEventArgs e)
+ {
+ lastMousePos = e.Position;
-// protected override void onBorderMouseEnter (object sender, MouseMoveEventArgs e)
-// {
-// base.onBorderMouseEnter (sender, e);
-//
-// if (isDocked) {
-// switch (docking) {
-// case Alignment.Top:
-// if (this.currentDirection != Window.Direction.S)
-// onBorderMouseLeave (this, null);
-// break;
-// case Alignment.Left:
-// if (this.currentDirection != Window.Direction.E)
-// onBorderMouseLeave (this, null);
-// break;
-// case Alignment.TopLeft:
-// break;
-// case Alignment.Right:
-// if (this.currentDirection != Window.Direction.W)
-// onBorderMouseLeave (this, null);
-// break;
-// case Alignment.TopRight:
-// break;
-// case Alignment.Bottom:
-// if (this.currentDirection != Window.Direction.N)
-// onBorderMouseLeave (this, null);
-// break;
-// case Alignment.BottomLeft:
-// break;
-// case Alignment.BottomRight:
-// break;
-// case Alignment.Center:
-// break;
-// default:
-// break;
-// }
-// }
-// }
+ if (this.HasFocus && e.Mouse.IsButtonDown (MouseButton.Left) && IsDocked) {
+ if (Math.Abs (e.Position.X - undockingMousePosOrig.X) > 10 ||
+ Math.Abs (e.Position.X - undockingMousePosOrig.X) > 10)
+ Undock ();
+ }
- void undock () {
- this.Left = savedSlot.Left;
- this.Top = savedSlot.Top;
- this.Width = savedSlot.Width;
- this.Height = savedSlot.Height;
+ base.onMouseMove (sender, e);
+ }
+ public override void onMouseDown (object sender, MouseButtonEventArgs e)
+ {
+ base.onMouseDown (sender, e);
- IsDocked = false;
- Resizable = wasResizable;
+ if (this.HasFocus && IsDocked && e.Button == MouseButton.Left)
+ undockingMousePosOrig = e.Position;
+ }
+ public bool CheckUndock (Point mousePos) {
+ if (Math.Abs (mousePos.X - undockingMousePosOrig.X) < undockThreshold ||
+ Math.Abs (mousePos.X - undockingMousePosOrig.X) < undockThreshold)
+ return false;
+ Undock ();
+ return true;
}
- void dock (Alignment align){
- IsDocked = true;
- docking = align;
- undockingMousePosOrig = lastMousePos;
- savedSlot = this.LastPaintedSlot;
- wasResizable = Resizable;
- Resizable = false;
- this.Left = this.Top = 0;
+ protected override void onStartDrag (object sender, DragDropEventArgs e)
+ {
+ base.onStartDrag (sender, e);
- switch (align) {
- case Alignment.Top:
- this.HorizontalAlignment = HorizontalAlignment.Left;
- this.VerticalAlignment = VerticalAlignment.Top;
- this.Width = Measure.Stretched;
- break;
- case Alignment.Left:
- this.HorizontalAlignment = HorizontalAlignment.Left;
- this.VerticalAlignment = VerticalAlignment.Top;
- this.Height = Measure.Stretched;
- break;
- case Alignment.TopLeft:
- break;
- case Alignment.Right:
- this.HorizontalAlignment = HorizontalAlignment.Right;
- this.VerticalAlignment = VerticalAlignment.Top;
- this.Height = Measure.Stretched;
- break;
- case Alignment.TopRight:
- break;
- case Alignment.Bottom:
- this.HorizontalAlignment = HorizontalAlignment.Left;
- this.VerticalAlignment = VerticalAlignment.Bottom;
- this.Width = Measure.Stretched;
- break;
- case Alignment.BottomLeft:
- break;
- case Alignment.BottomRight:
- break;
- case Alignment.Center:
- break;
- default:
- break;
+ undockingMousePosOrig = IFace.Mouse.Position;
+ }
+ protected override void onDrop (object sender, DragDropEventArgs e)
+ {
+ if (!isDocked && DockingPosition != Alignment.Center)
+ dock (e.DropTarget as DockStack);
+ base.onDrop (sender, e);
+ }
+ public void Undock () {
+ lock (IFace.UpdateMutex) {
+ DockStack ds = Parent as DockStack;
+ ds.Undock (this);
+
+ RootDock.AddChild (this);
+
+ this.Left = savedSlot.Left;
+ this.Top = savedSlot.Top;
+ this.Width = savedSlot.Width;
+ this.Height = savedSlot.Height;
+
+ IsDocked = false;
+ Resizable = wasResizable;
+ }
+ }
+ void dock (DockStack target){
+ lock (IFace.UpdateMutex) {
+ IsDocked = true;
+ undockingMousePosOrig = lastMousePos;
+ savedSlot = this.LastPaintedSlot;
+ wasResizable = Resizable;
+ Resizable = false;
+ LastSlots = LastPaintedSlot = Slot = default(Rectangle);
+ Left = Top = 0;
+
+ RootDock.RemoveChild (this);
+
+ target.Dock (this);
}
-
}
}
}