]> O.S.I.I.S - jp/crow.git/commitdiff
dragndrop of GObjs
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 14 Mar 2018 11:33:40 +0000 (12:33 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 14 Mar 2018 11:33:40 +0000 (12:33 +0100)
17 files changed:
CrowIDE/src/Editors/ImlVisualEditor.cs
CrowIDE/src/GraphicObjectDesignContainer.cs
CrowIDE/src/MemberView/PropertyContainer.cs
CrowIDE/ui/CrowIDE.crow
CrowIDE/ui/DockWindows/winToolbox.crow
CrowIDE/ui/IDE.style
CrowIDE/ui/Options.crow
CrowIDE/ui/ProjectTree.template
CrowIDE/ui/editors/IMLEdit.itemp
Images/screenshot2.png [new file with mode: 0644]
Tests/BasicTests.cs
src/Colors.cs
src/ExtensionsMethods.cs
src/GraphicObjects/GenericStack.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/PrivateContainer.cs

index 76cb40094ddbeb8a51910252e29fdaa61081f2e4..94f71716f608f12cc9c586c9144678d442a237b9 100644 (file)
@@ -29,6 +29,7 @@ using Crow.IML;
 using System.Text;
 using System.Xml;
 using System.Diagnostics;
+using Cairo;
 
 namespace Crow.Coding
 {
@@ -38,19 +39,29 @@ namespace Crow.Coding
                public ImlVisualEditor () : base()
                {
                        imlVE = new DesignInterface ();
+                       initCommands ();
                }
                #endregion
 
                DesignInterface imlVE;
                GraphicObject selectedItem;
                ImlProjectItem imlProjFile;
-               Exception imlError = null;
 
+               bool editorIsDirty = false;//needed when tree is empty
                bool drawGrid, snapToGrid;
                int gridSpacing, zoom = 100;
                Measure designWidth, designHeight;
                bool updateEnabled;
 
+               public List<Crow.Command> Commands;
+               Crow.Command cmdDelete;
+
+               void initCommands () {
+                       cmdDelete = new Crow.Command (new Action (() => deleteObject (SelectedItem)))
+                               { Caption = "Delete", Icon = new SvgPicture ("#Crow.Coding.icons.save.svg"), CanExecute = true };
+                       Commands = new List<Crow.Command> (new Crow.Command[] { cmdDelete });
+               }
+
                [DefaultValue(true)]
                public bool DrawGrid {
                        get { return drawGrid; }
@@ -107,7 +118,7 @@ namespace Crow.Coding
                                Width = (int)(designWidth * zoom / 100.0);
                        }
                }
-               [DefaultValue("512")]
+               [DefaultValue("400")]
                public Measure DesignHeight {
                        get { return designHeight; }
                        set {
@@ -125,20 +136,14 @@ namespace Crow.Coding
                                if (selectedItem == value)
                                        return;
                                selectedItem = value;
+
+                               if (selectedItem == null)
+                                       cmdDelete.CanExecute = false;
+                               else
+                                       cmdDelete.CanExecute = true;
+                               
                                NotifyValueChanged ("SelectedItem", selectedItem);
-                               RegisterForRedraw ();
-                       }
-               }
-               /// <summary>
-               /// use to disable update if tab is not the visible one
-               /// </summary>
-               public bool UpdateEnabled {
-                       get { return updateEnabled; }
-                       set { 
-                               if (value == updateEnabled)
-                                       return;
-                               updateEnabled = value;
-                               NotifyValueChanged ("UpdateEnabled", updateEnabled);
+                               RegisterForGraphicUpdate ();
                        }
                }
                /// <summary>PoinprojFilever the widget</summary>
@@ -148,20 +153,33 @@ namespace Crow.Coding
                        set {
                                if (HoverWidget == value)
                                        return;
-                               
+
                                imlVE.HoverWidget = value;
 
                                NotifyValueChanged ("HoverWidget", HoverWidget);
                        }
                }
-               [XmlIgnore]public List<LQIList> LQIs {
-                       get { return imlVE.LQIs; }
+               /// <summary>
+               /// use to disable update if tab is not the visible one
+               /// </summary>
+               public bool UpdateEnabled {
+                       get { return updateEnabled; }
+                       set { 
+                               if (value == updateEnabled)
+                                       return;
+                               updateEnabled = value;
+                               NotifyValueChanged ("UpdateEnabled", updateEnabled);
+                       }
                }
 
                public List<GraphicObject> GraphicTree {
                        get { return imlVE.GraphicTree; }
                }
 
+               [XmlIgnore]public List<LQIList> LQIs {
+                       get { return imlVE.LQIs; }
+               }
+
                #region editor overrides
                public override ProjectFile ProjectNode {
                        get {
@@ -173,10 +191,15 @@ namespace Crow.Coding
                                imlVE.ProjFile = imlProjFile;
                        }
                }
+
                protected override bool EditorIsDirty {
                        get { return imlProjFile == null ? false :
-                               imlProjFile.Instance == null ? false : imlProjFile.Instance.design_HasChanged; }
+                               imlProjFile.Instance == null ? editorIsDirty :
+                               imlProjFile.Instance.design_HasChanged | editorIsDirty; }
                        set {
+                               editorIsDirty = value;
+                               if (GraphicTree.Count == 0)
+                                       return;
                                if (GraphicTree [0] != null)
                                        GraphicTree [0].design_HasChanged = value;                      
                        }
@@ -189,7 +212,10 @@ namespace Crow.Coding
                {
                        Debug.WriteLine("\t\tImlEditor updateProjFileFromEditor");
                        try {
-                               projFile.UpdateSource(this, imlProjFile.Instance.GetIML());
+                               if (imlProjFile.Instance == null)
+                                       projFile.UpdateSource(this, @"<?xml version=""1.0""?>");
+                               else
+                                       projFile.UpdateSource(this, imlProjFile.Instance.GetIML());
                        } catch (Exception ex) {
                                Error = ex.InnerException;
                                if (Monitor.IsEntered(imlVE.UpdateMutex))
@@ -267,6 +293,7 @@ namespace Crow.Coding
                                break;
                        }
                }
+
                public override void onMouseMove (object sender, MouseMoveEventArgs e)
                {
                        base.onMouseMove (sender, e);
@@ -275,22 +302,57 @@ namespace Crow.Coding
                        Rectangle scr = this.ScreenCoordinates (this.getSlot ());
                        ProcessMouseMove (e.X - scr.X, e.Y - scr.Y);
 
-                       if (oldHW == HoverWidget)
-                               return;
+                       GraphicObject newHW = HoverWidget;
 
                        if (draggedObj != null) {
-                               if (isPossibleContainer (HoverWidget) && draggedObjContainer != HoverWidget) {
-                                       removeDraggedObjFrom ();
-                                       tryAddDraggedObjTo (HoverWidget);
+                               if (draggedObj.Parent == null) {
+                                       if (tryAddObjectTo (newHW, draggedObj)) {
+                                               RegisterForRedraw ();
+                                               return;
+                                       }
+                               } else if (newHW != draggedObj) {
+                                       //lock (imlVE.UpdateMutex) {
+                                       ILayoutable possibleParent = getPossibleParent (newHW, draggedObj);
+                                       if (possibleParent == null) {
+                                               Group g = newHW.Parent as Group;
+                                               if (g != null && g != draggedObj) {
+                                                       removeObject (draggedObj);
+                                                       g.InsertChild (g.Children.IndexOf (newHW), draggedObj);
+                                                       RegisterForRedraw ();
+                                                       return;
+                                               }
+                                       } else if (possibleParent != draggedObj.Parent) {
+                                               removeObject (draggedObj);
+                                               if (tryAddObjectTo (possibleParent, draggedObj)) {
+                                                       RegisterForRedraw ();
+                                                       return;
+                                               }
+                                       }
+                                       //}
                                }
-                       }
+                       }                       
 
+                       if (oldHW == newHW)
+                               return;
                        RegisterForRedraw ();
 
                }
+               public override void onMouseEnter (object sender, MouseMoveEventArgs e)
+               {
+                       base.onMouseEnter (sender, e);
+                       IFace.FocusedWidget = this;
+               }
+               public override void onMouseLeave (object sender, MouseMoveEventArgs e)
+               {
+                       base.onMouseLeave (sender, e);
+                       IFace.FocusedWidget = null;
+               }
                public override void onMouseDown (object sender, MouseButtonEventArgs e)
                {
-                       //base.onMouseDown (sender, e);
+                       if (e.Mouse.RightButton == ButtonState.Pressed) {
+                               base.onMouseDown (sender, e);
+                               return;
+                       }
                        SelectedItem = HoverWidget;
 
                        if (SelectedItem != null && projFile != null) {
@@ -349,27 +411,69 @@ namespace Crow.Coding
                        Rectangle hr;
                        if (HoverWidget != null) {
                                hr = HoverWidget.ScreenCoordinates (HoverWidget.getSlot ());
-//                     gr.SetSourceColor (Color.LightGray);
-//                     gr.DrawCote (new Cairo.PointD (hr.X, hr.Center.Y), new Cairo.PointD (hr.Right, hr.Center.Y));
-//                     gr.DrawCote (new Cairo.PointD (hr.Center.X, hr.Y), new Cairo.PointD (hr.Center.X, hr.Bottom));
-                               //hr.Inflate (2);
-                               gr.SetSourceColor (Color.LightGray);
-                               gr.SetDash (new double[]{ 3.0, 3.0 }, 0.0);
-                               gr.Rectangle (hr, 1.0);
+                               gr.SetSourceColor (Color.White);
+                               //gr.SetDash (new double[]{ 5.0, 3.0 }, 0.0);
+                               gr.Rectangle (hr, 0.4 / z);
                        }
 
                        if (SelectedItem?.Parent != null) {
-                               
-                               hr = SelectedItem.ScreenCoordinates (SelectedItem.getSlot ());
-                               hr.Inflate (1);
-                               gr.LineWidth = 2;
-                               gr.SetSourceColor (Color.Yellow);
-                               gr.SetDash (new double[]{ 5.0, 3.0 }, 0.0);
-                               gr.Rectangle (hr, 1.0);
+                               GraphicObject g = SelectedItem;
+                               hr = g.ScreenCoordinates (g.getSlot ());
+
+
+                               //gr.SetDash (new double[]{ 2.0, 2.0 }, 0.0);
+                               gr.SetSourceColor (Color.Black);
+                               //gr.Operator = Operator.Add;
+                               drawDesignOverlay (gr, g, cb, hr, 1.0 / z, 4.0);
+                               gr.SetSourceColor (Color.White);
+                               drawDesignOverlay (gr, g, cb, hr, 1.0 / z, 4.5);
                        }
                        gr.Restore ();
                }
+               void drawDesignOverlay (Context gr, GraphicObject g, Rectangle cb, Rectangle hr, double coteStroke, double space = 4.5){
+                       double z = zoom / 100.0;
+                       double coteW = 3, coteL = 5;
+                       bool fill = true;
+                       Cairo.PointD p1 = new Cairo.PointD (hr.X + 0.5, hr.Y - space);
+                       Cairo.PointD p2 = new Cairo.PointD (hr.Right - 0.5, hr.Y - space);
+
+                       if (p1.Y < cb.Top) {
+                               if (hr.Bottom > cb.Bottom - space)
+                                       p1.Y = p2.Y = hr.Bottom - space;
+                               else
+                                       p1.Y = p2.Y = hr.Bottom + space;
+                       }
 
+                       if (g.Width.IsFit)
+                               gr.DrawCoteInverse (p1, p2, coteStroke, fill, coteW, coteL);
+                       else if (g.Width.IsRelativeToParent)
+                               gr.DrawCote (p1, p2, coteStroke, fill, coteW, coteL);
+                       else if (g.Width.IsFixed)
+                               gr.DrawCoteFixed(p1, p2, coteStroke * 2.0, coteW);
+
+                       p1 = new Cairo.PointD (hr.X - space, hr.Top + 0.5);
+                       p2 = new Cairo.PointD (hr.X - space, hr.Bottom - 0.5);
+
+                       if (p1.X < cb.Left) {
+                               if (hr.Right > cb.Right - space)
+                                       p1.X = p2.X = hr.Right - space;
+                               else
+                                       p1.X = p2.X = hr.Right + space;
+                       } 
+                       if (g.Height.IsFit)
+                               gr.DrawCoteInverse (p1, p2, coteStroke, fill, coteW, coteL);
+                       else if (g.Height.IsRelativeToParent)
+                               gr.DrawCote (p1, p2, coteStroke, fill, coteW, coteL);
+                       else if (g.Width.IsFixed)
+                               gr.DrawCoteFixed(p1, p2, coteStroke * 2.0, coteW);
+
+                       //                              hr.Inflate (2);
+                       //gr.SetDash (new double[]{ 1.0, 4.0 }, 0.0);
+                       //gr.SetSourceColor (Color.Gray);
+//                     gr.Rectangle (hr,coteStroke);
+//                     gr.Stroke ();
+                       gr.Operator = Operator.Over;                    
+               }
                protected override void onDragEnter (object sender, DragDropEventArgs e)
                {
                        base.onDragEnter (sender, e);
@@ -381,75 +485,173 @@ namespace Crow.Coding
                protected override void onDragLeave (object sender, DragDropEventArgs e)
                {
                        base.onDragLeave (sender, e);
-
+                       GraphicObjectDesignContainer godc = e.DragSource.DataSource as GraphicObjectDesignContainer;
+                       if (godc == null)
+                               return;
                        ClearDraggedObj ();
                }
+
+               protected override void onStartDrag (object sender, DragDropEventArgs e)
+               {
+                       base.onStartDrag (sender, e);
+                       if (SelectedItem == null)
+                               return;
+                       
+                       GraphicObject dumy = new GraphicObject (IFace);
+                       dumy.EndDrag += dumyOnEndDrag;
+                       dumy.Drop += dumyOnDrop;
+                       dumy.IsDragged = true;
+                       IFace.ActiveWidget = dumy;
+                       e.DragSource.IsDragged = false;
+                       IFace.DragAndDropOperation.DragSource = dumy;
+                       draggedObj = SelectedItem;
+                       int dragIconSize = 48;
+                       lock (IFace.UpdateMutex) {
+                               IFace.DragImageHeight = dragIconSize;
+                               IFace.DragImageWidth = dragIconSize;
+                               IFace.DragImage = draggedObj.CreateIcon(dragIconSize);
+                       }                                       
+                       removeObject (draggedObj);
+                       SelectedItem = null;
+                       HoverWidget = null;
+               }
+               void dumyOnEndDrag (object sender, DragDropEventArgs e)
+               {                       
+                       IFace.ClearDragImage ();
+               }
+               void dumyOnDrop (object sender, DragDropEventArgs e)
+               {
+                       ClearDraggedObj (false);
+                       IFace.ClearDragImage ();
+               }
                #endregion
 
+
                #region draggedObj handling
+
                public GraphicObject draggedObj = null;
-               public GraphicObject draggedObjContainer = null;
 
-               bool tryAddDraggedObjTo(GraphicObject g){
-                       lock (imlVE.UpdateMutex) {
-                               if (g.GetType ().IsSubclassOf (typeof(Container))) {
-                                       Container c = g as Container;
-                                       c.SetChild (draggedObj);
-                                       EditorIsDirty = true;
-                               } else if (g.GetType ().IsSubclassOf (typeof(Group))) {
-                                       Group c = g as Group;
-                                       c.AddChild (draggedObj);
-                               } else
-                                       return false;
-                               EditorIsDirty = true;
-                               draggedObjContainer = g;
-                       }
-                       return true;
-               }
-               bool isPossibleContainer (GraphicObject g){
-                       if (g.GetType().IsSubclassOf(typeof(Container))){
-                               Container c = g as Container;
-                               return c.Child == null;
-                       }
-                       return g.GetType ().IsSubclassOf (typeof(Group));
-               }
-               void removeDraggedObjFrom(){
-                       if (draggedObjContainer == null)
-                               return;
-                       lock (imlVE.UpdateMutex) {
-                               if (draggedObjContainer.GetType().IsSubclassOf(typeof(Container))){
-                                       Container c = draggedObjContainer as Container;
-                                       c.SetChild (null);
-                                       EditorIsDirty = true;
-                                       //Console.WriteLine ("remove {0} from {1}", draggedObj, c);
-                               }else if (draggedObjContainer.GetType().IsSubclassOf(typeof(Group))){
-                                       Group c = draggedObjContainer as Group;
-                                       c.RemoveChild (draggedObj);
-                                       EditorIsDirty = true;
-                                       //Console.WriteLine ("remove {0} from {1}", draggedObj, c);
-                               }//else
-                               //      Console.WriteLine ("Error removing dragged obj");
-                       }
-                       draggedObjContainer = null;
-               }
                void createDraggedObj (Type crowType) {
                        lock (imlVE.UpdateMutex) {
                                draggedObj = imlVE.CreateITorFromIMLFragment ("<" + crowType.Name + "/>").CreateInstance ();
                        }
                }
+
                public void ClearDraggedObj (bool removeFromTree = true) {
-                       //Console.WriteLine ("Clear dragged obj {0}, remove from tree = {1}", draggedObj, removeFromTree);
-                       if (removeFromTree)
-                               removeDraggedObjFrom ();
-                       draggedObjContainer = null;
-                       if (draggedObj == null)
-                               return;
                        if (removeFromTree)
-                               draggedObj.Dispose ();
+                               deleteObject (draggedObj);                      
                        draggedObj = null;
                }
                #endregion
 
+               void removeObject (GraphicObject go) {
+                       if (go == null)
+                               return;
+                       if (go.Parent == null)
+                               return;         
+//                     lock (imlVE.UpdateMutex) {
+                               Interface i = go.Parent as Interface;
+                               if (i != null) {
+                                       i.RemoveWidget (go);
+                                       imlProjFile.Instance = null;
+                               } else {
+                                       Container c = go.Parent as Container;
+                                       if (c != null) 
+                                               c.SetChild (null);
+                                       else {
+                                               TemplatedContainer tc = go.Parent as TemplatedContainer;
+                                               if (tc != null)
+                                                       tc.Content = null;
+                                               else {
+                                                       Group g = go.Parent as Group;
+                                                       if (g != null)
+                                                               g.RemoveChild (go);
+                                               }
+                                       }
+                               }                                       
+                               EditorIsDirty = true;
+                       //}
+               }
+               void deleteObject (GraphicObject go) {
+                       if (go == null)
+                               return;
+                       //lock (imlVE.UpdateMutex) {
+                               removeObject (go);
+                               go.Dispose ();
+                       //}
+               }
+
+               ILayoutable getPossibleParent (ILayoutable parent, GraphicObject go) {
+                       if (go == null)
+                               return null;
+//                     lock (imlVE.UpdateMutex) {
+                               
+                               Interface i = null;
+                               if (parent == null)
+                                       i = imlVE;
+                               else
+                                       i = parent as Interface;
+                               if (i != null)
+                                       return i.GraphicTree.Count > 0 ? null : i;
+                               
+                               Container c = parent as Container;
+                               if (c != null)
+                                       return c.Child == null || c.Child == go ? c : null;                                             
+                               
+                               TemplatedContainer tc = parent as TemplatedContainer;
+                               if (tc != null)
+                                       return tc.Content == null || tc.Content == go? tc : null;
+                               
+                               return parent as Group;
+//                     }
+               }
+               bool tryAddObjectTo (ILayoutable parent, GraphicObject go) {
+                       if (go == null)
+                               return false;
+//                     lock (imlVE.UpdateMutex) {
+                       Interface i = null;
+                       if (parent == null)
+                               i = imlVE;
+                       else
+                               i = parent as Interface;
+                       if (i != null) {
+                               if (i.GraphicTree.Count > 0)
+                                       return false;
+                               i.AddWidget (go);
+                               imlProjFile.Instance = go;
+                               EditorIsDirty = true;
+                               return true;
+                       }
+                       Container c = parent as Container;
+                       if (c != null) {
+                               if (c.Child != null)
+                                       return false;
+                                       //return tryAddObjectTo (c.Parent, go);
+                               c.SetChild (go);
+                               EditorIsDirty = true;
+                               return true;
+                       }
+                       TemplatedContainer tc = parent as TemplatedContainer;
+                       if (tc != null) {
+                               if (tc.Content != null)
+                                       return false;
+                               //return tryAddObjectTo (c.Parent, go);
+                               tc.Content = (go);
+                               EditorIsDirty = true;
+                               return true;
+                       }
+                       Group g = parent as Group;
+                       if (g != null) {
+                               g.AddChild (go);
+                               EditorIsDirty = true;
+                               return true;
+                       }
+                       return false;//tryAddObjectTo (parent.Parent, go);
+//                     }
+               }
+
+
+
                void WidgetCheckOver (GraphicObject go, MouseMoveEventArgs e){
                        Type tGo = go.GetType();
                        if (typeof(TemplatedGroup).IsAssignableFrom (tGo)) {
@@ -510,21 +712,22 @@ namespace Crow.Coding
                                GraphicObject topc = null;
                                while (tmp is GraphicObject) {
                                        topc = tmp;
-                                       tmp = tmp.focusParent;
+                                       tmp = tmp.LogicalParent as GraphicObject;
                                }
                                int idxhw = imlVE.GraphicTree.IndexOf (topc);
                                if (idxhw != 0) {
                                        int i = 0;
-                                       while (i < idxhw) {                                             
-                                               if (GraphicTree [i].MouseIsIn (e.Position)) {
-                                                       while (HoverWidget != null) {
-                                                               WidgetMouseLeave (imlVE.HoverWidget, e);
-                                                               HoverWidget = HoverWidget.focusParent;
+                                       while (i < idxhw) {
+                                               if (imlVE.GraphicTree [i].LogicalParent == imlVE.GraphicTree [i].Parent) {
+                                                       if (imlVE.GraphicTree [i].MouseIsIn (e.Position)) {
+                                                               while (imlVE.HoverWidget != null) {
+                                                                       WidgetMouseLeave (imlVE.HoverWidget, e);
+                                                                       imlVE.HoverWidget = imlVE.HoverWidget.LogicalParent as GraphicObject;
+                                                               }
+
+                                                               WidgetCheckOver (GraphicTree [i], e);
+                                                               return true;
                                                        }
-
-                                                       GraphicTree [i].checkHoverWidget (e);
-                                                       WidgetMouseMove (imlVE.HoverWidget, e);
-                                                       return true;
                                                }
                                                i++;
                                        }
@@ -533,16 +736,14 @@ namespace Crow.Coding
 
                                if (imlVE.HoverWidget.MouseIsIn (e.Position)) {
                                        WidgetCheckOver (imlVE.HoverWidget, (e));
-                                       WidgetMouseMove (imlVE.HoverWidget, e);
                                        return true;
                                } else {
                                        WidgetMouseLeave (imlVE.HoverWidget, e);
                                        //seek upward from last focused graph obj's
-                                       while (imlVE.HoverWidget.focusParent != null) {
+                                       while (imlVE.HoverWidget.LogicalParent as GraphicObject != null) {
                                                imlVE.HoverWidget = imlVE.HoverWidget.LogicalParent as GraphicObject;
                                                if (imlVE.HoverWidget.MouseIsIn (e.Position)) {
                                                        WidgetCheckOver (imlVE.HoverWidget, e);
-                                                       WidgetMouseMove (imlVE.HoverWidget, e);
                                                        return true;
                                                } else
                                                        WidgetMouseLeave (imlVE.HoverWidget, e);
@@ -556,7 +757,6 @@ namespace Crow.Coding
                                        GraphicObject g = imlVE.GraphicTree [i];
                                        if (g.MouseIsIn (e.Position)) {
                                                WidgetCheckOver (g, e);
-                                               WidgetMouseMove (imlVE.HoverWidget, e);
                                                return true;
                                        }
                                }
@@ -565,10 +765,101 @@ namespace Crow.Coding
                        return false;
 
                }
+//             public bool ProcessMouseMove(int x, int y)
+//             {
+//                     int deltaX = x - imlVE.Mouse.X;
+//                     int deltaY = y - imlVE.Mouse.Y;
+//                     imlVE.Mouse.X = x;
+//                     imlVE.Mouse.Y = y;
+//                     MouseMoveEventArgs e = new MouseMoveEventArgs (x, y, deltaX, deltaY);
+//                     e.Mouse = imlVE.Mouse;
+//
+//                     if (imlVE.ActiveWidget != null) {
+//                             //TODO, ensure object is still in the graphic tree
+//                             //send move evt even if mouse move outside bounds
+//                             WidgetMouseMove (imlVE.ActiveWidget, e);
+//                             return true;
+//                     }
+//
+//                     if (HoverWidget != null) {
+//                             //TODO, ensure object is still in the graphic tree
+//                             //check topmost graphicobject first
+//                             GraphicObject tmp = HoverWidget;
+//                             GraphicObject topc = null;
+//                             while (tmp is GraphicObject) {
+//                                     topc = tmp;
+//                                     tmp = tmp.LogicalParent as GraphicObject;
+//                             }
+//                             int idxhw = imlVE.GraphicTree.IndexOf (topc);
+//                             if (idxhw != 0) {
+//                                     int i = 0;
+//                                     while (i < idxhw) {                                             
+//                                             if (GraphicTree [i].MouseIsIn (e.Position)) {
+//                                                     while (HoverWidget != null) {
+//                                                             WidgetMouseLeave (imlVE.HoverWidget, e);
+//                                                             HoverWidget = HoverWidget.focusParent;
+//                                                     }
+//
+//                                                     GraphicTree [i].checkHoverWidget (e);
+//                                                     WidgetMouseMove (imlVE.HoverWidget, e);
+//                                                     return true;
+//                                             }
+//                                             i++;
+//                                     }
+//                             }
+//
+//
+//                             if (imlVE.HoverWidget.MouseIsIn (e.Position)) {
+//                                     WidgetCheckOver (imlVE.HoverWidget, (e));
+//                                     WidgetMouseMove (imlVE.HoverWidget, e);
+//                                     return true;
+//                             } else {
+//                                     WidgetMouseLeave (imlVE.HoverWidget, e);
+//                                     //seek upward from last focused graph obj's
+//                                     while (imlVE.HoverWidget.focusParent != null) {
+//                                             imlVE.HoverWidget = imlVE.HoverWidget.LogicalParent as GraphicObject;
+//                                             if (imlVE.HoverWidget.MouseIsIn (e.Position)) {
+//                                                     WidgetCheckOver (imlVE.HoverWidget, e);
+//                                                     WidgetMouseMove (imlVE.HoverWidget, e);
+//                                                     return true;
+//                                             } else
+//                                                     WidgetMouseLeave (imlVE.HoverWidget, e);
+//                                     }
+//                             }
+//                     }
+//
+//                     //top level graphic obj's parsing
+//                     lock (imlVE.GraphicTree) {
+//                             for (int i = 0; i < imlVE.GraphicTree.Count; i++) {
+//                                     GraphicObject g = imlVE.GraphicTree [i];
+//                                     if (g.MouseIsIn (e.Position)) {
+//                                             WidgetCheckOver (g, e);
+//                                             WidgetMouseMove (imlVE.HoverWidget, e);
+//                                             return true;
+//                                     }
+//                             }
+//                     }
+//                     imlVE.HoverWidget = null;
+//                     return false;
+//
+//             }
 
                void GTView_SelectedItemChanged (object sender, SelectionChangeEventArgs e)
                {
                        SelectedItem = e.NewValue as GraphicObject;
                }
+
+
+               public override void onKeyDown (object sender, KeyboardKeyEventArgs e)
+               {
+               
+                       switch (e.Key) {
+                       case Key.Delete:
+                               if (selectedItem == null)
+                                       return;
+                               deleteObject (selectedItem);
+                               break;
+                       }
+               }
        }
 }
index e7776d26a563cdd0ad1662ccb63a78ac79d2924c..4540898baf3518063cc109ef074c793bc4cc4e26 100644 (file)
@@ -30,6 +30,14 @@ namespace Crow.Coding
 {
        public class GraphicObjectDesignContainer
        {
+               #region CTOR
+               public GraphicObjectDesignContainer (Type crowType)
+               {
+                       CrowType = crowType;
+               }
+               #endregion
+
+               int dragIconSize = 32;
                public Type CrowType;
 
                public string IconPath {
@@ -38,24 +46,18 @@ namespace Crow.Coding
                public string DisplayName {
                        get { return CrowType.Name; }
                }
-                       
-               public GraphicObjectDesignContainer (Type crowType)
-               {
-                       CrowType = crowType;
-               }
-               int dis = 32;
                void onStartDrag (object sender, EventArgs e)
                {
                        GraphicObject go = sender as GraphicObject;
 
                        lock (go.IFace.UpdateMutex) {                           
-                               go.IFace.DragImageHeight = dis;
-                               go.IFace.DragImageWidth = dis;
+                               go.IFace.DragImageHeight = dragIconSize;
+                               go.IFace.DragImageWidth = dragIconSize;
                                SvgPicture pic = new SvgPicture ();
                                pic.Load (go.IFace, IconPath);
-                               ImageSurface img = new ImageSurface (Format.Argb32, dis, dis);
+                               ImageSurface img = new ImageSurface (Format.Argb32, dragIconSize, dragIconSize);
                                using (Context ctx = new Context (img)) {
-                                       Rectangle r = new Rectangle (0, 0, dis, dis);
+                                       Rectangle r = new Rectangle (0, 0, dragIconSize, dragIconSize);
                                        pic.Paint (ctx, r);     
                                        ctx.Operator = Operator.In;
                                        ctx.SetSourceRGBA (1.0, 1.0, 1.0, 1.0);
index 19f4ed7f4fb1c8a5bb1c9969c20e4c9a2c41a27e..c2dc28997a4b94ce0a0d243e301cf7729f386915 100644 (file)
@@ -69,7 +69,7 @@ namespace Crow.Coding
                public string Name { get { return pi.Name; }}
                public object Value {
                        get {
-                               return mview.ProjectNode.SelectedItem == null ? null : pi.GetValue(mview.ProjectNode.SelectedItem);
+                               return mview.ProjectNode?.SelectedItem == null ? null : pi.GetValue(mview.ProjectNode.SelectedItem);
                        }
                        set {
                                try {
index bc2a926a628f48cbd9cd29745db75b7aa95a8a2b..9e1b110e2ce3d073cff080f265828824d36a9dd9 100644 (file)
@@ -37,7 +37,7 @@
                                <MenuItem Command="{CMDHelp}"/>
                        </MenuItem>
                </Menu>
-               <Label DataSource="{CurrentSolution}" Text="{SelectedItemElement}" Width="Stretched"/>
+<!--           <Label DataSource="{CurrentSolution}" Text="{SelectedItemElement}" Width="Stretched"/>-->
                <Docker Name="mainDock">
                        <DockStack />
 <!--                   <DockWindow DataSource="{CurrentSolution}" Name="winEditor" Caption="Edit View" Width="70%" Height="80%">
index da41e0116fb0997e11cb5e85fee8506305e0a6ff..6c755c3a8b0bcba7b8e12706a463c44967d53c87 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<DockWindow DataSource="{CurrentSolution}" Name="winToolbox" Caption="Toolbox" Width="20%">
+<DockWindow DataSource="{CurrentSolution}" Name="winToolbox" Caption="Toolbox" Width="60">
        <ListBox Margin="3" Data="{ToolboxItems}" SelectionBackground="SkyBlue">
                <Template>
                        <Wrapper Name="ItemsContainer" Orientation="Vertical" Spacing="0"/>
index 4a1e106fca5ed73df6b7cb2176933f4b1599169f..22387808ee70097a96bc26ee6e87a4deaf9d74e9 100644 (file)
@@ -32,6 +32,7 @@ WinSchema {
        Height = "Fit";
 }
 TabItem {
+       AllowDrag="false";
        Background="Jet";
 }
 TreeItemBorder {
index 569d0100b779b26873d1187f4bc48f1c5df7ffb6..4f0443ba3611e400a8d75cb59c0f347dfc17a14d 100644 (file)
@@ -1,10 +1,24 @@
 <?xml version="1.0"?>
-<Window Caption="Crow IDE Options" Width="80%" Height="70%" Background="DimGray">
+<Window Caption="Crow IDE Options" Width="80%" Height="70%" Background="DimGray" Modal="true">
        <TabView>
-               <TabItem Caption="Editor">
+               <TabItem Caption="IML Visual Editor">
                        <VerticalStack Margin="10">
-                               <CheckBox Caption="Print Line Numbers" IsChecked="False"/>
+                               <CheckBox Caption="Print Line Numbers" IsChecked="True"/>
+                               <CheckBox Caption="Print Line Numbers" IsChecked="True"/>
+                               <CheckBox Caption="Print Line Numbers" IsChecked="True"/>
+                               <CheckBox Caption="Print Line Numbers" IsChecked="True"/>
+                               <CheckBox Caption="Print Line Numbers" IsChecked="True"/>
                        </VerticalStack>
                </TabItem>
+               <TabItem Caption="Text Editor">
+                       <VerticalStack Margin="10">
+                               <CheckBox Caption="Print Line Numbers" IsChecked="True"/>
+                               <CheckBox Caption="Print Line Numbers" IsChecked="True"/>
+                               <CheckBox Caption="Print Line Numbers" IsChecked="True"/>
+                               <CheckBox Caption="Print Line Numbers" IsChecked="True"/>
+                               <CheckBox Caption="Print Line Numbers" IsChecked="True"/>
+                       </VerticalStack>
+               </TabItem>
+
        </TabView>
 </Window>
index 8b9b1e571b973e54d8d9eee83d8064c0708c3c19..e3aa462a270f22252415f6397f5cecb6657271cd 100644 (file)
@@ -6,7 +6,7 @@
        <Expandable Caption="{Name}" ContextCommands="{Commands}" IsExpanded="{²IsExpanded}">
                <Template>
                        <VerticalStack>
-                               <Border Style="TreeItemBorder" MouseDoubleClick="./onClickForExpand">
+                               <Border Style="TreeItemBorder" Focusable="false" MouseDoubleClick="./onClickForExpand">
                                        <HorizontalStack Spacing="1">
                                                <Image Margin="1" Width="9" Height="9" Focusable="true" MouseDown="./onClickForExpand"
                                                        Path="{./Image}"
index a24aa29068523b2b99cca7de52808f920be957aa..9bdf5514b0dcb6c2a870b6c5798ec84c8e8adb31 100644 (file)
@@ -20,7 +20,7 @@
                        </HorizontalStack>
                        <HorizontalStack Width="Fit" Spacing="1">
                                <Label Text="Grid Spacing:"/>
-                               <Slider Value="{²../../../editor.GridSpacing}" Width="150" Height="10" Minimum="1" Maximum="100"/>
+                               <Slider Value="{²../../../editor.GridSpacing}" Width="150" Height="10" Minimum="5" Maximum="100"/>
                                <TextBox Text="{../../../editor.GridSpacing}"/>
                        </HorizontalStack>
                </HorizontalStack>
@@ -31,8 +31,9 @@
                                                Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}">
                                        <ImlVisualEditor  Foreground="SkyBlue" Name="editor" Background="Gray"                                          
                                                VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10"
-                                               Width="512" Height="512"
-                                               AllowDrop="true" UpdateEnabled="{../../../../../IsSelected}"
+                                               Width="512" Height="512" ContextCommands="{/Commands}"
+                                               AllowDrop="true" AllowDrag="true" Focusable="true"
+                                               UpdateEnabled="{../../../../../IsSelected}"
                                                ProjectNode="{}" SelectedItem="{²SelectedItem}"/>
                                </Scroller>
                                <ScrollBar Name="scrollbar1" Value="{²../scroller1.ScrollY}"
diff --git a/Images/screenshot2.png b/Images/screenshot2.png
new file mode 100644 (file)
index 0000000..46a7bec
Binary files /dev/null and b/Images/screenshot2.png differ
index e17f15401abc445bf903dcccf303a8ab9eae6884..09db62314f8015ebb17d84f51c07f5c1f532c590 100644 (file)
@@ -159,13 +159,13 @@ namespace Tests
                protected override void OnLoad (EventArgs e)
                {
                        base.OnLoad (e);
-
-                       foreach (Color c in Color.ColorDic.Values) {
-                               if (string.IsNullOrEmpty(c.htmlCode))
-                                       Console.WriteLine ("no htmlcode for {0}", c.Name);
-                               else if (c.htmlCode.Substring(1) != c.HtmlCode)
-                                       Console.WriteLine ("{2} orig: {0} comp: {1}",c.htmlCode, c.HtmlCode, c.Name);
-                       }
+//
+//                     foreach (Color c in Color.ColorDic.Values) {
+//                             if (string.IsNullOrEmpty(c.htmlCode))
+//                                     Console.WriteLine ("no htmlcode for {0}", c.Name);
+//                             else if (c.htmlCode.Substring(1) != c.HtmlCode)
+//                                     Console.WriteLine ("{2} orig: {0} comp: {1}",c.htmlCode, c.HtmlCode, c.Name);
+//                     }
 
 
                        Commands = new List<Crow.Command> (new Crow.Command[] {
@@ -177,8 +177,8 @@ namespace Tests
 
                        this.KeyDown += KeyboardKeyDown1;
 
-                       //testFiles = new string [] { @"Interfaces/Divers/welcome.crow" };
-                       testFiles = new string [] { @"Interfaces/Divers/colorPicker.crow" };
+                       testFiles = new string [] { @"Interfaces/Divers/welcome.crow" };
+                       //testFiles = new string [] { @"Interfaces/Divers/colorPicker.crow" };
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Container", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Group", "*.crow")).ToArray ();
index 6bc380ccc5985ac4e0a97c6da38e75634fe18198..0b1b3ad7383fbcf988cb438a18482da50e0f8675 100644 (file)
@@ -110,6 +110,8 @@ namespace Crow
                                cc.B = int.Parse (s.Substring (5, 2), System.Globalization.NumberStyles.HexNumber) / 255.0;
                                if (s.Length > 7)
                                        cc.A = int.Parse (s.Substring (7, 2), System.Globalization.NumberStyles.HexNumber) / 255.0;
+                               else
+                                       cc.A = 1.0;
                                return cc;
                        }
 
index cb662c51dc2aaebd9f6781896422867c5b28584e..231964049762627083976048ffa776a0100cd843 100644 (file)
@@ -64,11 +64,9 @@ namespace Crow
                public static Cairo.PointD Multiply(this Cairo.PointD p1, double v){
                        return new Cairo.PointD(p1.X * v, p1.Y * v);
                }
-               public static void DrawCote(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2, double stroke = 1.0)
-               {
-                       const double arrowWidth = 4.0;
-                       const double arrowLength = 10.0;
-
+               public static void DrawCote(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2,
+                       double stroke = 1.0, bool fill = false, double arrowWidth = 3.0, double arrowLength = 7.0)
+               {                       
                        Cairo.PointD vDir = p2.Substract(p1);
                        vDir = vDir.GetNormalized ();
                        Cairo.PointD vPerp = vDir.GetPerp ();
@@ -80,21 +78,77 @@ namespace Crow
 
                        ctx.MoveTo (p1);
                        ctx.LineTo (pA0.Add (vA));
-                       ctx.LineTo (pA0.Substract (vA));
+                       if (fill)
+                               ctx.LineTo (pA0.Substract (vA));
+                       else
+                               ctx.MoveTo (pA0.Substract (vA));
+                       
                        ctx.LineTo (p1);
 
                        ctx.MoveTo (p2);
                        ctx.LineTo (pA1.Add (vA));
-                       ctx.LineTo (pA1.Substract (vA));
+                       if (fill)
+                               ctx.LineTo (pA1.Substract (vA));
+                       else
+                               ctx.MoveTo (pA1.Substract (vA));
                        ctx.LineTo (p2);
 
-                       ctx.Fill ();
+                       if (fill)
+                               ctx.Fill ();
 
                        ctx.MoveTo (p1);
                        ctx.LineTo (p2);
                        ctx.LineWidth = stroke;
                        ctx.Stroke ();
+               }
+               public static void DrawCoteInverse(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2,
+                       double stroke = 1.0, bool fill = false, double arrowWidth = 3.0, double arrowLength = 7.0)
+               {                       
+                       Cairo.PointD vDir = p2.Substract(p1);
+                       vDir = vDir.GetNormalized ();
+                       Cairo.PointD vPerp = vDir.GetPerp ();
+
+                       Cairo.PointD pA0 = p1.Add(vDir.Multiply(arrowLength));
+                       Cairo.PointD pA1 = p2.Substract(vDir.Multiply(arrowLength));
+
+                       Cairo.PointD vA = vPerp.Multiply (arrowWidth);
+
+                       ctx.MoveTo (p1.Add (vA));
+                       ctx.LineTo (pA0);
+                       ctx.LineTo (p1.Substract (vA));
+                       if (fill)
+                               ctx.LineTo (p1.Add (vA));
+
+                       ctx.MoveTo (p2.Add (vA));
+                       ctx.LineTo (pA1);
+                       ctx.LineTo (p2.Substract (vA));
+
+                       if (fill) {
+                               ctx.LineTo (p2.Add (vA));
+                               ctx.Fill ();
+                       }
+
+                       ctx.MoveTo (pA0);
+                       ctx.LineTo (pA1);
+                       ctx.LineWidth = stroke;
+                       ctx.Stroke ();
+               }
+               public static void DrawCoteFixed(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2,
+                       double stroke = 1.0, double coteWidth = 3.0)
+               {                       
+                       Cairo.PointD vDir = p2.Substract(p1);
+                       vDir = vDir.GetNormalized ();
+                       Cairo.PointD vPerp = vDir.GetPerp ();
+                       Cairo.PointD vA = vPerp.Multiply (coteWidth);
 
+                       ctx.MoveTo (p1.Add (vA));
+                       ctx.LineTo (p1.Substract (vA));
+                       ctx.MoveTo (p2.Add (vA));
+                       ctx.LineTo (p2.Substract (vA));
+                       ctx.MoveTo (p1);
+                       ctx.LineTo (p2);
+                       ctx.LineWidth = stroke;
+                       ctx.Stroke ();
                }
                public static void SetSourceColor(this Cairo.Context ctx, Color c)
                {
index 181c41c29e2e1e47c540a24ad8ec7e3d9ec68e2b..64841d4b79415dac9f5f9eff1da73b851390b6a3 100644 (file)
@@ -227,20 +227,20 @@ namespace Crow
 
        public override void RemoveChild (GraphicObject child)
                {
+                       if (child != stretchedGO) {
+                               if (Orientation == Orientation.Horizontal)
+                                       contentSize.Width -= child.LastSlots.Width;
+                               else 
+                                       contentSize.Height -= child.LastSlots.Height;                           
+                       }
                        base.RemoveChild (child);
                        if (child == stretchedGO) {
-                               //stretchedGO.LastSlots = default(Rectangle);
                                stretchedGO = null;
                                RegisterForLayouting (LayoutingType.Sizing);
-                               return;
-                       }
-                       if (Orientation == Orientation.Horizontal) {
-                               contentSize.Width -= child.LastSlots.Width;
+                       }else if (Orientation == Orientation.Horizontal)                                
                                adjustStretchedGo (LayoutingType.Width);
-                       } else {
-                               contentSize.Height -= child.LastSlots.Height;
-                               adjustStretchedGo (LayoutingType.Height);
-                       }
+                       else                            
+                               adjustStretchedGo (LayoutingType.Height);                       
                }
        }
 }
index 9e5e440195c74fbcf67865bff22fbdcfe4ddf765..2ca07975b0c4373dd700c40471c77f0a7b6cc9d2 100644 (file)
@@ -126,7 +126,24 @@ namespace Crow
 
                        parentElem.AppendChild (xe);
                }
-
+               public Surface CreateIcon (int dragIconSize = 32) {
+                       ImageSurface di = new ImageSurface (Format.Argb32, dragIconSize, dragIconSize);
+                       using (Context ctx = new Context (di)) {
+                               double div = Math.Max (LastPaintedSlot.Width, LastPaintedSlot.Height);
+                               double s = (double)dragIconSize / div;
+                               ctx.Scale (s, s);
+                               if (bmp == null)
+                                       this.onDraw (ctx);
+                               else {
+                                       if (LastPaintedSlot.Width>LastPaintedSlot.Height)
+                                               ctx.SetSourceSurface (bmp, 0, (LastPaintedSlot.Width-LastPaintedSlot.Height)/2);
+                                       else
+                                               ctx.SetSourceSurface (bmp, (LastPaintedSlot.Height-LastPaintedSlot.Width)/2, 0);
+                                       ctx.Paint ();
+                               }
+                       }
+                       return di;
+               }                       
                #endif
 
                #region IDisposable implementation
@@ -337,7 +354,7 @@ namespace Crow
 
                                parentRWLock.EnterWriteLock();
                                parent = value;
-                               Slot = default(Rectangle);
+                               Slot = LastSlots = default(Rectangle);
                                parentRWLock.ExitWriteLock();
                                                                        
                                onParentChanged (this, e);
@@ -374,8 +391,13 @@ namespace Crow
                                Parent.ContextCoordinates (r);
                }
                public virtual Rectangle ScreenCoordinates (Rectangle r){
-                       return
-                               Parent.ScreenCoordinates(r) + Parent.getSlot().Position + Parent.ClientRectangle.Position;
+                       try {
+                               return
+                                       Parent.ScreenCoordinates(r) + Parent.getSlot().Position + Parent.ClientRectangle.Position;                              
+                       } catch (Exception ex) {
+                               Debug.WriteLine (ex);
+                               return default(Rectangle);
+                       }
                }
                public virtual Rectangle getSlot () { return Slot;}
                #endregion
index 9cedec81e766d1909bf897186e1573aa01475f53..a90947a56cedcce61bca0d052d24cd39c9fbd7b3 100644 (file)
@@ -64,7 +64,7 @@ namespace Crow
                }
                #endif
 
-               protected ReaderWriterLockSlim childrenRWLock = new ReaderWriterLockSlim();
+               protected ReaderWriterLockSlim childrenRWLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
 
                #region CTOR
                public Group () : base() {}
index 668ba45284d047e8428c46b7d6ebc8e1a87cb3b4..d66372475240fbacfb659e84be0946d95178e8be 100644 (file)
@@ -75,7 +75,6 @@ namespace Crow
                        if (child != null) {
                                child.Parent = this;
                                child.LayoutChanged += OnChildLayoutChanges;
-                               child.Slot = child.LastSlots = default(Rectangle);
                                contentSize = child.Slot.Size;
                                child.RegisteredLayoutings = LayoutingType.None;
                                child.RegisterForLayouting (LayoutingType.Sizing);