diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-02-20 14:17:56 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-02-20 14:22:24 +0100 |
| commit | d8367a33368e783c15f2072daa9237b2643526d3 (patch) | |
| tree | b770c2b8d3d6f0b6f6f69676f0e42194af2c053a /src/GraphicObjects | |
| parent | 0ce668c6c13521ebfcb9ed02365556a31a65b6b2 (diff) | |
debug threading with new TemplatedGroup arch, review examples.singleLeveledTemplatedGroup
Diffstat (limited to 'src/GraphicObjects')
| -rw-r--r-- | src/GraphicObjects/DockWindow.cs | 133 | ||||
| -rw-r--r-- | src/GraphicObjects/Docker.cs | 193 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 26 | ||||
| -rw-r--r-- | src/GraphicObjects/Group.cs | 46 | ||||
| -rw-r--r-- | src/GraphicObjects/MessageBox.cs | 4 | ||||
| -rw-r--r-- | src/GraphicObjects/TabItem.cs | 10 | ||||
| -rw-r--r-- | src/GraphicObjects/TabView.cs | 4 | ||||
| -rw-r--r-- | src/GraphicObjects/TemplatedGroup.cs | 14 | ||||
| -rw-r--r-- | src/GraphicObjects/Window.cs | 2 |
9 files changed, 342 insertions, 90 deletions
diff --git a/src/GraphicObjects/DockWindow.cs b/src/GraphicObjects/DockWindow.cs index 5e066f39..b68a3085 100644 --- a/src/GraphicObjects/DockWindow.cs +++ b/src/GraphicObjects/DockWindow.cs @@ -52,63 +52,98 @@ namespace Crow NotifyValueChanged ("IsDocked", isDocked); } } - public override void OnLayoutChanges (LayoutingType layoutType) - { - base.OnLayoutChanges (layoutType); - - if (isDocked) - return; - - Docker dv = Parent as Docker; - if (dv == null) - return; - - Rectangle dvCliRect = dv.ClientRectangle; - - if (layoutType == LayoutingType.X) { - if (Slot.X < dv.DockingThreshold) - dock (Alignment.Left); - else if (Slot.Right > dvCliRect.Width - dv.DockingThreshold) - dock (Alignment.Right); - }else if (layoutType == LayoutingType.Y) { - if (Slot.Y < dv.DockingThreshold) - dock (Alignment.Top); - else if (Slot.Bottom > dvCliRect.Height - dv.DockingThreshold) - dock (Alignment.Bottom); + public Alignment DockingPosition { + get { return docking; } + set { + if (docking == value) + return; + docking = value; + NotifyValueChanged ("DockingPosition", DockingPosition); } } - - public override void onMouseMove (object sender, MouseMoveEventArgs e) + protected override void onDrop (object sender, DragDropEventArgs e) { - lastMousePos = e.Position; + base.onDrop (sender, e); + Docker dv = Parent as Docker; + dv.Dock (this); + } + public override bool PointIsIn (ref Point m) + { + if (!base.PointIsIn(ref m)) + return false; - 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 (); + Group p = Parent as Group; + if (p != null) { + lock (p.Children) { + for (int i = p.Children.Count - 1; i >= 0; i--) { + if (p.Children [i] == this) + break; + if (p.Children [i].Slot.ContainsOrIsEqual (m)) { + return false; + } + } } - return; } - - base.onMouseMove (sender, e); + return Slot.ContainsOrIsEqual(m); } - 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 OnLayoutChanges (LayoutingType layoutType) +// { +// base.OnLayoutChanges (layoutType); +// +// if (isDocked) +// return; + +// Docker dv = Parent as Docker; +// if (dv == null) +// return; +// +// Rectangle dvCliRect = dv.ClientRectangle; +// +// if (layoutType == LayoutingType.X) { +// if (Slot.X < dv.DockingThreshold) +// dock (Alignment.Left); +// else if (Slot.Right > dvCliRect.Width - dv.DockingThreshold) +// dock (Alignment.Right); +// }else if (layoutType == LayoutingType.Y) { +// if (Slot.Y < dv.DockingThreshold) +// dock (Alignment.Top); +// else if (Slot.Bottom > dvCliRect.Height - dv.DockingThreshold) +// dock (Alignment.Bottom); +// } +// } +// +// 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; +// } // protected override void onBorderMouseEnter (object sender, MouseMoveEventArgs e) // { diff --git a/src/GraphicObjects/Docker.cs b/src/GraphicObjects/Docker.cs index 57b49390..3b66eb7e 100644 --- a/src/GraphicObjects/Docker.cs +++ b/src/GraphicObjects/Docker.cs @@ -26,17 +26,45 @@ using System; using System.Xml.Serialization; using System.ComponentModel; +using Crow.IML; namespace Crow { public class Docker : Group { + static Instantiator instStack, instSplit, instSpacer; #region CTOR + static Docker () { + instStack = Instantiator.CreateFromImlFragment(@"<GenericStack Background='Blue' AllowDrop='true' DragEnter='onStackDragEnter'/>"); + instSplit = Instantiator.CreateFromImlFragment(@"<Splitter/>"); + instSpacer = Instantiator.CreateFromImlFragment(@"<GraphicObject Background='Red' IsEnabled='false'/>"); + } public Docker () : base () { } #endregion + GenericStack rootStack = null; + + public override void AddChild (GraphicObject g) + { + DockWindow dw = g as DockWindow; + if (dw == null) + throw new Exception ("Docker accept only DockWindow as child"); + + base.AddChild (g); + + dw.LogicalParent = this; + } + public override void RemoveChild (GraphicObject child) + { + child.LogicalParent = null; + + + base.RemoveChild (child); + } + + GenericStack mainStack = null; int dockingThreshold; [XmlAttributeAttribute][DefaultValue(10)] @@ -51,17 +79,176 @@ namespace Crow } } + bool showDockingTarget = false; + Alignment dockingDirection = Alignment.Center; + int dockingDiv = 5; + public override void onMouseMove (object sender, MouseMoveEventArgs e) { if (CurrentInterface.DragAndDropOperation?.DragSource as DockWindow != null) { DockWindow dw = CurrentInterface.DragAndDropOperation?.DragSource as DockWindow; - if (CurrentInterface.DragAndDropOperation.DragSource.Parent == this && !dw.IsDocked) - dw.MoveAndResize (e.XDelta, e.YDelta); - } + if (CurrentInterface.DragAndDropOperation.DragSource.Parent == this && !dw.IsDocked) + dw.MoveAndResize (e.XDelta, e.YDelta); + Rectangle r = ClientRectangle; + int vTreshold = r.Height / dockingDiv; + int hTreshold = r.Width / dockingDiv; + + + bool showDock = true; + + if (dw.Slot.Left < hTreshold) + dockingDirection = Alignment.Left; + else if (dw.Slot.Right > r.Right - hTreshold) + dockingDirection = Alignment.Right; + else if (dw.Slot.Top < vTreshold) + dockingDirection = Alignment.Top; + else if (dw.Slot.Bottom > r.Bottom - vTreshold) + dockingDirection = Alignment.Bottom; + else { + dockingDirection = Alignment.Center; + showDock = false; + } + + showDockingTarget = showDock; + + RegisterForGraphicUpdate (); + + //System.Diagnostics.Debug.WriteLine ("Dock: {0}", dockingDirection); + } else + showDockingTarget = false; base.onMouseMove (sender, e); } + protected override void onDragEnter (object sender, DragDropEventArgs e) + { + base.onDragEnter (sender, e); + } + void onStackDragEnter (object sender, DragDropEventArgs e) + { + base.onDragEnter (sender, e); + + mainStack = sender as GenericStack; + } + 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 (); + } + + lock (Children) { + foreach (GraphicObject g in Children) { + if (CurrentInterface.DragAndDropOperation?.DragSource == g) + continue; + g.Paint (ref gr); + } + } + + if (showDockingTarget) { + Rectangle r; + if (mainStack == null) + r = ClientRectangle; + else + r = mainStack.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 (); + } + + if (CurrentInterface.DragAndDropOperation != null) + CurrentInterface.DragAndDropOperation.DragSource.Paint (ref gr); + + + gr.Restore (); + } + + public void Dock(DockWindow dw){ + if (dockingDirection == Alignment.Center) + return; + lock (CurrentInterface.UpdateMutex) { + + Splitter splitter = instSplit.CreateInstance<Splitter> (CurrentInterface); + + dw.Resizable = false; + dw.Left = dw.Top = 0; + this.RemoveChild (dw); + + Rectangle r; + if (mainStack == null) { + mainStack = instStack.CreateInstance<GenericStack> (CurrentInterface); + this.AddChild (mainStack); + this.putWidgetOnBottom (mainStack); + r = ClientRectangle; + } else + r = mainStack.ClientRectangle; + + int vTreshold = r.Height / dockingDiv; + int hTreshold = r.Width / dockingDiv; + + switch (dockingDirection) { + case Alignment.Top: + dw.Width = Measure.Stretched; + mainStack.Orientation = Orientation.Vertical; + mainStack.AddChild (dw); + mainStack.AddChild (splitter); + //mainStack.AddChild (instSpacer.CreateInstance (CurrentInterface)); + break; + case Alignment.Bottom: + dw.Width = Measure.Stretched; + mainStack.Orientation = Orientation.Vertical; + //mainStack.AddChild (instSpacer.CreateInstance (CurrentInterface)); + mainStack.AddChild (splitter); + mainStack.AddChild (dw); + break; + case Alignment.Left: + dw.Height = Measure.Stretched; + mainStack.Orientation = Orientation.Horizontal; + mainStack.AddChild (dw); + mainStack.AddChild (splitter); + //mainStack.AddChild (instSpacer.CreateInstance (CurrentInterface)); + break; + case Alignment.Right: + dw.Height = Measure.Stretched; + mainStack.Orientation = Orientation.Horizontal; + //mainStack.AddChild (instSpacer.CreateInstance (CurrentInterface)); + mainStack.AddChild (splitter); + mainStack.AddChild (dw); + break; + } + + } + } + protected override void onDrop (object sender, DragDropEventArgs e) + { + base.onDrop (sender, e); + } } } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 9857d198..d49cbe8f 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -243,10 +243,11 @@ namespace Crow if (parent == value) return; DataSourceChangeEventArgs e = new DataSourceChangeEventArgs (parent, value); - lock (this) + lock (CurrentInterface.LayoutMutex) { parent = value; - - onParentChanged (this, e); + } + onParentChanged (this, e); + } } [XmlIgnore]public ILayoutable LogicalParent { @@ -786,8 +787,9 @@ namespace Crow //prevent setting null causing stack overflow in specific case if (dse.NewDataSource == dse.OldDataSource) return; - - OnDataSourceChanged (this, dse); + lock (CurrentInterface.LayoutMutex) { + OnDataSourceChanged (this, dse); + } NotifyValueChanged ("DataSource", DataSource); } @@ -1097,7 +1099,7 @@ namespace Crow /// fired when drag and drop operation start /// </summary> protected virtual void onStartDrag (object sender, DragDropEventArgs e){ - CurrentInterface.HoverWidget = this.focusParent; + CurrentInterface.HoverWidget = null; IsDragged = true; StartDrag.Raise (this, e); Debug.WriteLine(this.ToString() + " : START DRAG => " + e.ToString()); @@ -1136,11 +1138,13 @@ namespace Crow #if DEBUG_UPDATE Debug.WriteLine (string.Format("ClippingRegistration -> {0}", this.ToString ())); #endif - IsQueueForRedraw = false; - if (Parent == null) - return; - Parent.RegisterClip (LastPaintedSlot); - Parent.RegisterClip (Slot); + lock(CurrentInterface.LayoutMutex){ + IsQueueForRedraw = false; + if (Parent == null) + return; + Parent.RegisterClip (LastPaintedSlot); + Parent.RegisterClip (Slot); + } } /// <summary> /// Add clip rectangle to this.clipping and propagate up to root diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 10d87ab6..1b5847d4 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -62,7 +62,7 @@ namespace Crow set { _multiSelect = value; } } public virtual void AddChild(GraphicObject g){ - lock (children) { + lock (Children) { g.Parent = this; Children.Add (g); } @@ -79,9 +79,8 @@ namespace Crow CurrentInterface.HoverWidget = null; } - lock (children) + lock (Children) Children.Remove(child); - child.Dispose (); if (child == largestChild && Width == Measure.Fit) searchLargestChild (); @@ -89,9 +88,15 @@ namespace Crow searchTallestChild (); this.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); + + } + public virtual void DeleteChild(GraphicObject child) + { + RemoveChild (child); + child.Dispose (); } public virtual void InsertChild (int idx, GraphicObject g) { - lock (children) { + lock (Children) { g.Parent = this; Children.Insert (idx, g); } @@ -99,12 +104,12 @@ namespace Crow g.LayoutChanged += OnChildLayoutChanges; g.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); } - public virtual void RemoveChild (int idx) { - RemoveChild (children[idx]); + public virtual void DeleteChild (int idx) { + DeleteChild (children[idx]); } public virtual void ClearChildren() { - lock (children) { + lock (Children) { while (Children.Count > 0) { GraphicObject g = Children [Children.Count - 1]; g.LayoutChanged -= OnChildLayoutChanges; @@ -123,7 +128,7 @@ namespace Crow { if (Children.Contains(w)) { - lock (children) { + lock (Children) { Children.Remove (w); Children.Add (w); } @@ -133,7 +138,7 @@ namespace Crow { if (Children.Contains(w)) { - lock (children) { + lock (Children) { Children.Remove (w); Children.Insert (0, w); } @@ -144,7 +149,7 @@ namespace Crow public override void OnDataSourceChanged (object sender, DataSourceChangeEventArgs e) { base.OnDataSourceChanged (this, e); - lock (children) { + lock (Children) { foreach (GraphicObject g in children) if (g.localDataSourceIsNull & g.localLogicalParentIsNull) g.OnDataSourceChanged (g, e); @@ -155,7 +160,7 @@ namespace Crow if (Name == nameToFind) return this; GraphicObject tmp = null; - lock (children) { + lock (Children) { foreach (GraphicObject w in Children) { tmp = w.FindByName (nameToFind); if (tmp != null) @@ -234,7 +239,7 @@ namespace Crow gr.Clip (); } - lock (children) { + lock (Children) { foreach (GraphicObject g in Children) { g.Paint (ref gr); } @@ -263,7 +268,7 @@ namespace Crow gr.Clip (); } - lock (children) { + lock (Children) { foreach (GraphicObject c in Children) { if (!c.Visible) continue; @@ -374,6 +379,21 @@ namespace Crow } base.checkHoverWidget (e); } +// public override bool PointIsIn (ref Point m) +// { +// if (!base.PointIsIn (ref m)) +// return false; +// if (CurrentInterface.HoverWidget == this) +// return true; +// lock (Children) { +// for (int i = Children.Count - 1; i >= 0; i--) { +// if (Children [i].Slot.ContainsOrIsEqual (m) && !(bool)CurrentInterface.HoverWidget?.IsOrIsInside(Children[i])) { +// return false; +// } +// } +// } +// return true; +// } #endregion protected override void Dispose (bool disposing) diff --git a/src/GraphicObjects/MessageBox.cs b/src/GraphicObjects/MessageBox.cs index e1c8cc87..c0754eaa 100644 --- a/src/GraphicObjects/MessageBox.cs +++ b/src/GraphicObjects/MessageBox.cs @@ -135,7 +135,7 @@ namespace Crow close (); } public static MessageBox Show (Interface iface, Type msgBoxType, string message, string okMsg = "", string cancelMsg = ""){ - //lock (Interface.CurrentInterface.UpdateMutex) { + lock (iface.UpdateMutex) { MessageBox mb = new MessageBox (iface); mb.CurrentInterface.AddWidget (mb); mb.MsgType = msgBoxType; @@ -145,7 +145,7 @@ namespace Crow if (!string.IsNullOrEmpty(cancelMsg)) mb.CancelMessage = cancelMsg; return mb; - //} + } } } } diff --git a/src/GraphicObjects/TabItem.cs b/src/GraphicObjects/TabItem.cs index 8364aace..eab0cb0d 100644 --- a/src/GraphicObjects/TabItem.cs +++ b/src/GraphicObjects/TabItem.cs @@ -159,13 +159,13 @@ namespace Crow public bool HoldCursor = false; public override bool PointIsIn (ref Point m) { - TabView tv = Parent as TabView; - bool tmp = base.PointIsIn (ref m); + if (!base.PointIsIn (ref m)) + return false; if (m.Y < tabThickness) return TabTitle.Slot.ContainsOrIsEqual (m); else - return this.isSelected && tmp; + return this.isSelected; } public override void onMouseDown (object sender, MouseButtonEventArgs e) { @@ -214,6 +214,10 @@ namespace Crow } public void butCloseTabClick (object sender, MouseButtonEventArgs e){ QueryClose.Raise (this, null); + //if tab is used as a templated item root in a templatedGroup, local datasource + //is not null, in this case, removing the data entries will delete automatically the item + if (localDataSourceIsNull) + (Parent as TabView).DeleteChild (this); } #endregion diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs index 3e776d3a..c5292da7 100644 --- a/src/GraphicObjects/TabView.cs +++ b/src/GraphicObjects/TabView.cs @@ -112,7 +112,7 @@ namespace Crow SelectedTab = ti.ViewIndex = Children.Count - 1; } - public override void RemoveChild (GraphicObject child) + public override void DeleteChild (GraphicObject child) { TabItem ti = child as TabItem; if (ti == null) @@ -124,7 +124,7 @@ namespace Crow if (selectedTab > Children.Count - 2) SelectedTab--; - base.RemoveChild (child); + base.DeleteChild (child); } public override bool ArrangeChildren { get { return true; } } diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs index f2c097a2..8025435d 100644 --- a/src/GraphicObjects/TemplatedGroup.cs +++ b/src/GraphicObjects/TemplatedGroup.cs @@ -216,9 +216,9 @@ namespace Crow if (this.isPaged) { int p = e.Index / itemPerPage; int i = e.Index % itemPerPage; - (items.Children [p] as Group).RemoveChild (i); + (items.Children [p] as Group).DeleteChild (i); } else - items.RemoveChild (e.Index); + items.DeleteChild (e.Index); } void Ol_ListAdd (object sender, ListChangedEventArg e) @@ -268,7 +268,7 @@ namespace Crow public virtual void RemoveItem(GraphicObject g) { g.LogicalParent = null; - items.RemoveChild (g); + items.DeleteChild (g); if (items.Children.Count == 0) NotifyValueChanged ("HasChildren", false); } @@ -375,8 +375,10 @@ namespace Crow // isPaged = true; // } - for (int i = 0; i < _data.Count; i++) { + for (int i = 0; i < _data.Count; i++) { loadItem (_data[i], page, _dataTest); + if (loadingThread.cancelRequested) + break; } // if (page == items) @@ -425,13 +427,13 @@ namespace Crow iTemp = ItemTemplates ["default"]; } - lock (CurrentInterface.LayoutMutex) { + //lock (CurrentInterface.LayoutMutex) { g = iTemp.CreateInstance(CurrentInterface); page.AddChild (g); // if (isPaged) g.LogicalParent = this; g.MouseDown += itemClick; - } + //} if (iTemp.Expand != null && g is Expandable) { (g as Expandable).Expand += iTemp.Expand; diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index b4a5f4c4..bbfb196d 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -424,7 +424,7 @@ namespace Crow if (Parent is Interface) (Parent as Interface).DeleteWidget (this); else if (Parent is Group) - (Parent as Group).RemoveChild (this); + (Parent as Group).DeleteChild (this); else if (Parent is PrivateContainer) (Parent as Container).Child = null; } |