private void Swap(int r, int c, int or, int oc) { Plotting.Graph tmp = d_children[r, c]; d_children[r, c] = d_children[or, oc]; d_children[or, oc] = tmp; ReallocateOne(r, c); ReallocateOne(or, oc); }
private void Compact() { List <int> rows = new List <int>(); /* Remove empty rows and columns */ for (int r = 0; r < d_rows; ++r) { if (!EmptyRow(r)) { rows.Add(r); } } List <int> cols = new List <int>(); for (int c = 0; c < d_columns; ++c) { if (!EmptyColumn(c)) { cols.Add(c); } } if (cols.Count == d_columns && rows.Count == d_rows) { return; } Plotting.Graph[,] children = new Plotting.Graph[rows.Count, cols.Count]; for (int r = 0; r < rows.Count; ++r) { for (int c = 0; c < cols.Count; ++c) { children[r, c] = d_children[rows[r], cols[c]]; } } d_children = children; d_rows = rows.Count; d_columns = cols.Count; Reallocate(); }
private void ConnectChild(Plotting.Graph graph) { Gtk.Drag.SourceSet(graph, Gdk.ModifierType.Button1Mask | Gdk.ModifierType.ControlMask, new Gtk.TargetEntry[] { new Gtk.TargetEntry("Cdn.Studio.TableItem", Gtk.TargetFlags.App, 1), new Gtk.TargetEntry("Plot.Renderer", Gtk.TargetFlags.App, 2) }, Gdk.DragAction.Move); graph.DragBegin += delegate(object source, Gtk.DragBeginArgs args) { DoDragBegin(graph, args.Context); }; graph.DragEnd += delegate(object source, Gtk.DragEndArgs args) { DoDragEnd(graph, args.Context); }; graph.ButtonPressEvent += delegate(object source, Gtk.ButtonPressEventArgs args) { d_lastPress = new Point(args.Event.X, args.Event.Y); }; }
public void Add(Plotting.Graph widget, int row, int col) { if (row < 0 || col < 0) { EmptyCell(out row, out col, true); } Resize(row + 1, col + 1); if (d_children[row, col] != null) { return; } d_children[row, col] = widget; widget.Parent = this; ReallocateOne(row, col); ConnectChild(widget); }
public void Resize(int rows, int columns) { int nonempty = d_rows; while (rows < nonempty && nonempty > 0) { if (!EmptyRow(nonempty - 1)) { rows = nonempty; break; } --nonempty; } nonempty = d_columns; while (columns < nonempty && nonempty > 0) { if (!EmptyColumn(nonempty - 1)) { columns = nonempty; break; } --nonempty; } if (rows != d_rows || columns != d_columns) { Plotting.Graph[,] nc = new Plotting.Graph[rows, columns]; CopyChildren(nc); d_children = nc; d_rows = rows; d_columns = columns; Reallocate(); } }
private void DoDragBegin(Gtk.Widget child, Gdk.DragContext context) { Gdk.Pixbuf icon; Plotting.Graph graph = (Plotting.Graph)child; d_dragRenderer = null; d_unmerged = null; d_dragHighlight = null; // Check if this is going to drag a label if (graph.Canvas.Graph.LabelHitTest(new Point(d_lastPress), out d_dragRenderer)) { icon = PixbufForRenderer(graph.Canvas.Graph, d_dragRenderer); } else { icon = graph.CreateDragIcon(); } if (icon != null) { Gtk.Drag.SetIconPixbuf(context, icon, icon.Width / 2, icon.Height / 2); } d_dragging = graph; IndexOf(child, out d_dragRow, out d_dragColumn); Gdk.EventMotion evnt = Utils.GetCurrentEvent() as Gdk.EventMotion; d_dragmerge = (evnt != null && (evnt.State & Gdk.ModifierType.ShiftMask) != 0); IndexOf(child, out d_dragRow, out d_dragColumn); QueueDraw(); }
private void DoDragEnd(Gtk.Widget child, Gdk.DragContext context) { d_dragging = null; QueueDraw(); }
private bool DoUpdateDragging(int x, int y) { // We have the child in d_dragging which was dragged from d_dragPos. We need to // determine the child position under the cursor at x, y and swap accordingly int r; int c; if (!CellAtPixel(x, y, out r, out c)) { return(false); } if (ExpandFromDrag(x, y)) { CellAtPixel(x, y, out r, out c); } // Do nothing when what we drag is already in this cell Plotting.Graph dragging = d_unmerged != null ? d_unmerged : d_dragging; if (d_children[r, c] == dragging) { return(true); } bool colprio = System.Math.Abs(d_dragColumn - c) > System.Math.Abs(d_dragRow - r); if (d_unmerged == null && d_dragRenderer != null) { // Here we are going to unmerge the renderer in a new graph in fact Plotting.Graph ng = CreateGraph(); ng.Parent = this; d_dragging.Canvas.Graph.Remove(d_dragRenderer); ng.Canvas.Graph.Add(d_dragRenderer); d_unmerged = ng; dragging = d_unmerged; ConnectChild(ng); if (d_children[r, c] != null) { // Make some space if (colprio) { // Add column Resize(d_rows, d_columns + 1); // Move right Shift(r, d_columns - 1, r, c, 0, -1); } else { // Add row Resize(d_rows, d_columns + 1); // Move down Shift(d_rows - 1, c, r, c, -1, 0); } } } else { if (colprio) { // First shift left, then up Shift(d_dragRow, d_dragColumn, d_dragRow, c, 0, System.Math.Sign(c - d_dragColumn)); Shift(d_dragRow, d_dragColumn, r, d_dragColumn, System.Math.Sign(r - d_dragRow), 0); } else { // First shift up, then left Shift(d_dragRow, d_dragColumn, r, d_dragColumn, System.Math.Sign(r - d_dragRow), 0); Shift(d_dragRow, d_dragColumn, d_dragRow, c, 0, System.Math.Sign(c - d_dragColumn)); } } d_dragRow = r; d_dragColumn = c; d_children[r, c] = dragging; ReallocateOne(r, c); return(true); }
public void Add(Plotting.Graph widget) { base.Add(widget); }