From: Jean-Philippe Bruyère Date: Sun, 4 Mar 2018 13:46:02 +0000 (+0100) Subject: docker wip X-Git-Tag: 0.7.3~4^2~30 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=6df32af090b1fc7f99ce5852523766dd012b9f19;p=jp%2Fcrow.git docker wip --- diff --git a/Default.style b/Default.style index 3714b922..2b905e3f 100644 --- a/Default.style +++ b/Default.style @@ -111,11 +111,11 @@ ToolWindow { } Docker { AllowDrop = "false"; - Margin="0"; + Margin="5"; Focusable="true"; } DockStack { - Margin="1"; + Margin="5"; AllowDrop = "true"; Focusable="true"; //DragEnter="{Background=DarkBlue}"; diff --git a/src/ExtensionsMethods.cs b/src/ExtensionsMethods.cs index 6697be62..dfb90f0e 100644 --- a/src/ExtensionsMethods.cs +++ b/src/ExtensionsMethods.cs @@ -106,6 +106,9 @@ namespace Crow } #endregion + public static Orientation GetOrientation(this Alignment a){ + return (a==Alignment.Left) ||(a==Alignment.Right) ? Orientation.Horizontal : Orientation.Vertical; + } public static void Raise(this EventHandler handler, object sender, EventArgs e) { if(handler != null) diff --git a/src/GraphicObjects/DockStack.cs b/src/GraphicObjects/DockStack.cs index bb5bf3a4..7d5baf32 100644 --- a/src/GraphicObjects/DockStack.cs +++ b/src/GraphicObjects/DockStack.cs @@ -30,18 +30,41 @@ namespace Crow { public class DockStack : GenericStack { - internal static Instantiator instStack, instSplit, instSpacer; + internal static Instantiator instStack, instSplit;//, instSpacer; int dockingDiv = 5; - GraphicObject subStack = null; + + Docker rootDock { get { return LogicalParent as Docker; }} + public GraphicObject SubStack { get { return subStack;} set{ subStack=value; } } + #region CTor public DockStack () {} public DockStack (Interface iface) : base (iface) {} + #endregion + + protected override void onInitialized (object sender, EventArgs e) + { + base.onInitialized (sender, e); + instStack = IFace.CreateITorFromIMLFragment (@""); + instSplit = IFace.CreateITorFromIMLFragment (@""); + //instSpacer = IFace.CreateITorFromIMLFragment (@""); + } + + public override void AddChild (GraphicObject g) + { + base.AddChild (g); + g.LogicalParent = this.LogicalParent; + } + public override void InsertChild (int idx, GraphicObject g) + { + base.InsertChild (idx, g); + g.LogicalParent = this.LogicalParent; + } public override bool PointIsIn (ref Point m) { @@ -64,16 +87,6 @@ namespace Crow } return Slot.ContainsOrIsEqual(m); } -// protected override void onDragEnter (object sender, DragDropEventArgs e) -// { -// base.onDragEnter (sender, e); -// showDock = true; -// } -// protected override void onDragLeave (object sender, DragDropEventArgs e) -// { -// base.onDragLeave (sender, e); -// showDock = false; -// } public override void onMouseMove (object sender, MouseMoveEventArgs e) { if (IsDropTarget) { @@ -108,9 +121,18 @@ namespace Crow } base.onMouseMove (sender, e); } - static Orientation GetOrientation (Alignment a){ - return (a==Alignment.Left) ||(a==Alignment.Right) ? Orientation.Horizontal : Orientation.Vertical; + + protected override void onDragEnter (object sender, DragDropEventArgs e) + { + base.onDragEnter (sender, e); + RegisterForGraphicUpdate (); } + protected override void onDragLeave (object sender, DragDropEventArgs e) + { + base.onDragLeave (sender, e); + RegisterForGraphicUpdate (); + } + protected override void onDraw (Cairo.Context gr) { gr.Save (); @@ -145,7 +167,7 @@ namespace Crow Rectangle r; - if (GetOrientation (dw.DockingPosition) == Orientation || SubStack == null) + if (dw.DockingPosition.GetOrientation() == Orientation || SubStack == null) r = ClientRectangle; else r = SubStack.ClientRectangle + SubStack.Slot.Position + ClientRectangle.TopLeft; @@ -172,13 +194,16 @@ namespace Crow } gr.Restore (); } + public void Undock (DockWindow dw){ + int dwIdx = Children.IndexOf(dw); + RemoveChild(dw); if (dw.DockingPosition == Alignment.Left || dw.DockingPosition == Alignment.Top) - RemoveChild (0); + RemoveChild (dwIdx); else - RemoveChild (Children.Count - 1); + RemoveChild (dwIdx - 1); if (Children.Count > 1) return; @@ -200,22 +225,8 @@ namespace Crow dsp.RemoveChild (this); dsp.InsertChild (i, g); dsp.SubStack = g; -// if (SubStack is DockStack) { -// -// } else { -// int i = p.Children.IndexOf (this); -// p.RemoveChild (this); -// if (p is DockStack) { -// DockStack dsp = p as DockStack; -// dsp.SubStack = instSpacer.CreateInstance (); -// dsp.AddChild (dsp.SubStack); -// } -// } - } public void Dock(DockWindow dw){ - checkInstantiators(); - Splitter splitter = instSplit.CreateInstance (); Rectangle r = ClientRectangle; @@ -226,12 +237,12 @@ namespace Crow if (SubStack == null) { activeStack = this; - SubStack = instSpacer.CreateInstance (); - }else if (GetOrientation (dw.DockingPosition) != Orientation) { + SubStack = rootDock.CenterDockedObj; + }else if (dw.DockingPosition.GetOrientation() != Orientation) { int i = Children.IndexOf (SubStack); RemoveChild (SubStack); activeStack = instStack.CreateInstance (); - activeStack.SubStack = instSpacer.CreateInstance (); + activeStack.SubStack = rootDock.CenterDockedObj; SubStack = activeStack; InsertChild(i, activeStack); } @@ -247,7 +258,7 @@ namespace Crow activeStack.AddChild (activeStack.SubStack); } else { activeStack.InsertChild (0, dw); - activeStack.InsertChild (0, splitter); + activeStack.InsertChild (1, splitter); } break; case Alignment.Bottom: @@ -291,15 +302,6 @@ namespace Crow break; } } - - void checkInstantiators () { - if (instStack != null) - return; - instStack = IFace.CreateITorFromIMLFragment (@""); - instSplit = IFace.CreateITorFromIMLFragment (@""); - instSpacer = IFace.CreateITorFromIMLFragment (@""); - } - } } diff --git a/src/GraphicObjects/Docker.cs b/src/GraphicObjects/Docker.cs index f61269d3..a14d70be 100644 --- a/src/GraphicObjects/Docker.cs +++ b/src/GraphicObjects/Docker.cs @@ -42,17 +42,10 @@ namespace Crow } #endregion - //GenericStack rootStack = null; - public DockStack SubStack = null; int dockingThreshold; - List windows = new List(); - - public override void AddChild (GraphicObject g) - { - base.AddChild (g); - g.LogicalParent = this; - } + public DockStack SubStack = null; + public GraphicObject CenterDockedObj = null; [XmlAttributeAttribute][DefaultValue(10)] public virtual int DockingThreshold { @@ -66,10 +59,17 @@ namespace Crow } } - //bool showDockingTarget = false; - //Alignment dockingDirection = Alignment.Center; - //int dockingDiv = 8; - //bool showDock = false; + protected override void onInitialized (object sender, EventArgs e) + { + base.onInitialized (sender, e); + CenterDockedObj = new GraphicObject (IFace) { IsEnabled = false }; + } + + public override void AddChild (GraphicObject g) + { + base.AddChild (g); + g.LogicalParent = this; + } public override void onMouseMove (object sender, MouseMoveEventArgs e) { @@ -85,151 +85,6 @@ namespace Crow } base.onMouseMove (sender, e); } - /* - protected override void onDragEnter (object sender, DragDropEventArgs e) - { - base.onDragEnter (sender, e); - showDock = true; - Console.WriteLine ("showdock=" + showDock); - } - protected override void onDragLeave (object sender, DragDropEventArgs e) - { - base.onDragLeave (sender, e); - showDock = false; - Console.WriteLine ("showdock=" + showDock); - } - - protected override void onDraw (Cairo.Context gr) - { - gr.Save (); - - Rectangle rBack = new Rectangle (Slot.Size); - - Background.SetAsSource (gr, rBack); - CairoHelpers.CairoRectangle (gr, rBack, CornerRadius); - gr.Fill (); - - if (ClipToClientRect) { - //clip to client zone - CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); - gr.Clip (); - } - - childrenRWLock.EnterReadLock (); - - foreach (GraphicObject g in Children) { -// if (IFace.DragAndDropOperation?.DragSource == g) -// continue; - g.Paint (ref gr); - } - - childrenRWLock.ExitReadLock (); - - if (showDockingTarget) { - Rectangle r; - if (stack == null) - r = ClientRectangle; - else - r = stack.ClientRectangle; - - switch (dockingDirection) { - case Alignment.Top: - gr.Rectangle (r.Left, r.Top, r.Width, r.Height / dockingDiv); - break; - case Alignment.Bottom: - gr.Rectangle (r.Left, r.Bottom - r.Height / dockingDiv, r.Width, r.Height / dockingDiv); - break; - case Alignment.Left: - gr.Rectangle (r.Left, r.Top, r.Width / dockingDiv, r.Height); - break; - case Alignment.Right: - gr.Rectangle (r.Right - r.Width / dockingDiv, r.Top, r.Width / dockingDiv, r.Height); - break; - } - gr.LineWidth = 1; - gr.SetSourceRGBA (0.4, 0.4, 0.9, 0.4); - gr.FillPreserve (); - gr.SetSourceRGBA (0.9, 0.9, 1.0, 0.8); - gr.Stroke (); - } - - gr.Restore (); - } -*/ - - /* - public void Dock(DockWindow dw){ - checkInstantiators(); - - if (dockingDirection == Alignment.Center) - return; - - lock (IFace.UpdateMutex) { - - Splitter splitter = instSplit.CreateInstance (); - Rectangle r = ClientRectangle; - - if (stack == null) { - stack = instStack.CreateInstance (); - this.AddChild (stack); - this.putWidgetOnBottom (stack); - } - - int vTreshold = r.Height / dockingDiv; - int hTreshold = r.Width / dockingDiv; - - switch (dockingDirection) { - case Alignment.Top: - dw.Height = vTreshold; - stack.Orientation = Orientation.Vertical; - if (stack.Children.Count == 0) { - stack.AddChild (dw); - stack.AddChild (splitter); - stack.AddChild (instSpacer.CreateInstance ()); - } else { - stack.AddChild (splitter); - stack.AddChild (dw); - } - break; - case Alignment.Bottom: - dw.Height = vTreshold; - stack.Orientation = Orientation.Vertical; - if (stack.Children.Count == 0) { - stack.AddChild (instSpacer.CreateInstance ()); - stack.AddChild (splitter); - stack.AddChild (dw); - } else { - stack.InsertChild (0, dw); - stack.InsertChild (0, splitter); - } - break; - case Alignment.Left: - dw.Width = hTreshold; - stack.Orientation = Orientation.Horizontal; - if (stack.Children.Count == 0) { - stack.AddChild (dw); - stack.AddChild (splitter); - stack.AddChild (instSpacer.CreateInstance ()); - } else { - stack.AddChild (splitter); - stack.AddChild (dw); - } - break; - case Alignment.Right: - dw.Width = hTreshold; - stack.Orientation = Orientation.Horizontal; - if (stack.Children.Count == 0) { - stack.AddChild (instSpacer.CreateInstance ()); - stack.AddChild (splitter); - stack.AddChild (dw); - } else { - stack.InsertChild (0, dw); - stack.InsertChild (0, splitter); - } - break; - } - } - }*/ } } diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 0dbaedd1..19c70076 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -234,6 +234,7 @@ namespace Crow { base.RemoveChild (child); if (child == stretchedGO) { + stretchedGO.LastSlots = default(Rectangle); stretchedGO = null; RegisterForLayouting (LayoutingType.Sizing); return; diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index a70f04a1..8ba8788d 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -247,13 +247,13 @@ namespace Crow Initialize (); } #endregion - internal bool initialized = false; + //internal bool initialized = false; /// /// Initialize this Graphic object instance by setting style and default values and loading template if required /// public virtual void Initialize(){ loadDefaultValues (); - initialized = true; + //initialized = true; } #region private fields LayoutingType registeredLayoutings = LayoutingType.All; @@ -321,9 +321,6 @@ namespace Crow internal Size contentSize; #endregion - public void ResetSlots () { - LastSlots = LastPaintedSlot = Slot = default(Rectangle); - } #region ILayoutable [XmlIgnore]public LayoutingType RegisteredLayoutings { get { return registeredLayoutings; } set { registeredLayoutings = value; } } //TODO: it would save the recurent cost of a cast in event bubbling if parent type was GraphicObject @@ -426,11 +423,21 @@ namespace Crow public event EventHandler Enabled; /// Occurs when the enabled state this object is set to false public event EventHandler Disabled; + + #region DragAndDrop Events public event EventHandler StartDrag; public event EventHandler DragEnter; public event EventHandler DragLeave; public event EventHandler EndDrag; public event EventHandler Drop; + #endregion + + /// + /// Occurs when default value and styling are loaded, and for templated control, + /// template is also loaded. Bindings should be functionnal as well. + /// + public event EventHandler Initialized; + /// Occurs when one part of the rendering slot changed public event EventHandler LayoutChanged; /// Occurs when DataSource changed @@ -1143,6 +1150,10 @@ namespace Crow } catch (Exception ex) { throw new Exception ("Error applying style <" + styleKey + ">:", ex); } + onInitialized (this, null); + } + protected virtual void onInitialized (object sender, EventArgs e){ + Initialized.Raise(sender, e); } bool getDefaultEvent(EventInfo ei, List