]> O.S.I.I.S - jp/crow.git/commitdiff
docker wip
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 4 Mar 2018 13:46:02 +0000 (14:46 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 4 Mar 2018 13:46:02 +0000 (14:46 +0100)
Default.style
src/ExtensionsMethods.cs
src/GraphicObjects/DockStack.cs
src/GraphicObjects/Docker.cs
src/GraphicObjects/GenericStack.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs

index 3714b922fc1d711a8e9fb8040cbfa312fbf0e0b2..2b905e3fc44517245fa969eac3e6bb5f7422206f 100644 (file)
@@ -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}";
index 6697be626de71f83754b1996899083aa79b87df7..dfb90f0ea3808b4ee2e7cdbbe754d180f502d908 100644 (file)
@@ -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)
index bb5bf3a49b7adc6ff5d08fee755df7a006ec8487..7d5baf327b1d31befc077d39f11e357d18829d73 100644 (file)
@@ -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 (@"<DockStack/>");
+                       instSplit = IFace.CreateITorFromIMLFragment (@"<Splitter/>");
+                       //instSpacer = IFace.CreateITorFromIMLFragment (@"<GraphicObject Background='Transparent' IsEnabled='false'/>");
+               }
+
+               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<Splitter> ();
                        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<DockStack> ();
-                               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 (@"<DockStack/>");
-                       instSplit = IFace.CreateITorFromIMLFragment (@"<Splitter/>");
-                       instSpacer = IFace.CreateITorFromIMLFragment (@"<GraphicObject Background='Transparent' IsEnabled='false'/>");
-               }
-
        }
 }
 
index f61269d39916454596ba47d1affcb8a8c45f9c90..a14d70bed511f0207d6685ca4f26db4647e33b92 100644 (file)
@@ -42,17 +42,10 @@ namespace Crow
                }
                #endregion
 
-               //GenericStack rootStack = null;
-               public DockStack SubStack = null;
                int dockingThreshold;
 
-               List<DockWindow> windows = new List<DockWindow>();
-
-               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<Splitter> ();
-                               Rectangle r = ClientRectangle;
-
-                               if (stack == null) {
-                                       stack = instStack.CreateInstance<GenericStack> ();
-                                       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;
-                               }
-                       }
-               }*/
        }
 }
 
index 0dbaedd1e1277b453aa68dd166001827a29e8ae8..19c70076c0cd32c150402cec97d7a47403b184be 100644 (file)
@@ -234,6 +234,7 @@ namespace Crow
                {
                        base.RemoveChild (child);
                        if (child == stretchedGO) {
+                               stretchedGO.LastSlots = default(Rectangle);
                                stretchedGO = null;
                                RegisterForLayouting (LayoutingType.Sizing);
                                return;
index a70f04a1e3516bc741d3dd9fddfbcd6ba1adf059..8ba8788d789f0757750510bdabc8c0484bef5ec2 100644 (file)
@@ -247,13 +247,13 @@ namespace Crow
                        Initialize ();
                }
                #endregion
-               internal bool initialized = false;
+               //internal bool initialized = false;
                /// <summary>
                /// Initialize this Graphic object instance by setting style and default values and loading template if required
                /// </summary>
                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;
                /// <summary>Occurs when the enabled state this object is set to false</summary>
                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
+
+               /// <summary>
+               /// Occurs when default value and styling are loaded, and for templated control,
+               /// template is also loaded. Bindings should be functionnal as well.
+               /// </summary>
+               public event EventHandler Initialized;
+
                /// <summary>Occurs when one part of the rendering slot changed</summary>
                public event EventHandler<LayoutingEventArgs> LayoutChanged;
                /// <summary>Occurs when DataSource changed</summary>
@@ -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<Style> styling,
                        out string expression){
index 11bf16fba09057e59a7be57d8a4f0f5c78acc1c2..43f0819844b8d676a31aace5f2f61bab15a5ff58 100644 (file)
@@ -115,7 +115,6 @@ namespace Crow
 
                        Children.Remove(child);
                        child.Parent = null;
-                       //child.ResetSlots ();
 
                        childrenRWLock.ExitWriteLock ();