/// <summary> /// Implement the single-click behavior for this handle, to toggle the /// expansion state of the <see cref="T:Northwoods.Go.IGoCollapsible" /> that this handle is in. /// </summary> /// <param name="evt"></param> /// <param name="view"></param> /// <returns>true if the parent <see cref="P:Northwoods.Go.IGoCollapsible.Collapsible" /> property is true</returns> /// <remarks> /// If <see cref="P:Northwoods.Go.IGoCollapsible.IsExpanded" /> is true, this calls <see cref="M:Northwoods.Go.IGoCollapsible.Collapse" />; /// otherwise this calls <see cref="M:Northwoods.Go.IGoCollapsible.Expand" />. /// If the view is non-null, this method calls <see cref="M:Northwoods.Go.GoView.StartTransaction" /> /// and <see cref="M:Northwoods.Go.GoView.FinishTransaction(System.String)" />, with a transaction name specified by /// the value of <see cref="F:Northwoods.Go.GoUndoManager.CollapsedName" /> or <see cref="F:Northwoods.Go.GoUndoManager.ExpandedName" />. /// </remarks> public override bool OnSingleClick(GoInputEventArgs evt, GoView view) { IGoCollapsible goCollapsible = FindCollapsible(); if (goCollapsible == null) { return(false); } string tname = null; try { view?.StartTransaction(); if (goCollapsible.IsExpanded) { goCollapsible.Collapse(); tname = "Collapsed"; } else { goCollapsible.Expand(); tname = "Expanded"; } } finally { view?.FinishTransaction(tname); } return(true); }
/// <summary> /// The appearance of this handle depends on the <see cref="P:Northwoods.Go.IGoCollapsible.Collapsible" /> /// and <see cref="P:Northwoods.Go.IGoCollapsible.IsExpanded" /> properties. /// </summary> /// <param name="g"></param> /// <param name="view"></param> /// <remarks> /// If the parent is not <see cref="P:Northwoods.Go.IGoCollapsible.Collapsible" />, /// this draws a circle inside the rectangle. /// Otherwise, the appearance depends on the value of <see cref="P:Northwoods.Go.GoCollapsibleHandle.Style" />. /// </remarks> protected virtual void PaintHandle(Graphics g, GoView view) { IGoCollapsible goCollapsible = FindCollapsible(); if (goCollapsible == null) { return; } RectangleF bounds = Bounds; if (goCollapsible.Collapsible) { float num = bounds.X + bounds.Width / 2f; float num2 = bounds.Y + bounds.Height / 2f; switch (Style) { case GoCollapsibleHandleStyle.PlusMinus: { float num9 = Bordered ? (bounds.Width / 4f) : 0f; float num10 = Bordered ? (bounds.Height / 4f) : 0f; GoShape.DrawLine(g, view, Pen, bounds.X + num9, num2, bounds.X + bounds.Width - num9, num2); if (!goCollapsible.IsExpanded) { GoShape.DrawLine(g, view, Pen, num, bounds.Y + num10, num, bounds.Y + bounds.Height - num10); } break; } case GoCollapsibleHandleStyle.TriangleRight: { float num7 = Bordered ? (bounds.Width / 6f) : 0f; float num8 = Bordered ? (bounds.Height / 6f) : 0f; PointF[] array3 = view.AllocTempPointArray(3); if (goCollapsible.IsExpanded) { array3[0].X = bounds.X + num7; array3[0].Y = bounds.Y + num8; array3[1].X = bounds.X + bounds.Width - num7; array3[1].Y = num2; array3[2].X = bounds.X + num7; array3[2].Y = bounds.Y + bounds.Height - num8; } else { array3[0].X = bounds.X + num7; array3[0].Y = bounds.Y + num8; array3[1].X = bounds.X + bounds.Width - num7; array3[1].Y = bounds.Y + num8; array3[2].X = num; array3[2].Y = bounds.Y + bounds.Height - num8; } SolidBrush solidBrush2 = new SolidBrush(GoShape.GetPenColor(Pen, Color.Black)); GoShape.DrawPolygon(g, view, null, solidBrush2, array3); solidBrush2.Dispose(); view.FreeTempPointArray(array3); break; } case GoCollapsibleHandleStyle.TriangleUp: { float num5 = Bordered ? (bounds.Width / 6f) : 0f; float num6 = Bordered ? (bounds.Height / 6f) : 0f; PointF[] array2 = view.AllocTempPointArray(3); if (goCollapsible.IsExpanded) { array2[0].X = bounds.X + num5; array2[0].Y = bounds.Y + bounds.Height - num6; array2[1].X = bounds.X + bounds.Width - num5; array2[1].Y = bounds.Y + bounds.Height - num6; array2[2].X = num; array2[2].Y = bounds.Y + num6; } else { array2[0].X = bounds.X + num5; array2[0].Y = bounds.Y + num6; array2[1].X = bounds.X + bounds.Width - num5; array2[1].Y = bounds.Y + num6; array2[2].X = num; array2[2].Y = bounds.Y + bounds.Height - num6; } SolidBrush solidBrush = new SolidBrush(GoShape.GetPenColor(Pen, Color.Black)); GoShape.DrawPolygon(g, view, null, solidBrush, array2); solidBrush.Dispose(); view.FreeTempPointArray(array2); break; } case GoCollapsibleHandleStyle.ChevronUp: { float num3 = Bordered ? (bounds.Width / 6f) : 0f; float num4 = Bordered ? (bounds.Height / 6f) : 0f; PointF[] array = view.AllocTempPointArray(3); if (goCollapsible.IsExpanded) { array[0].X = bounds.X + num3; array[0].Y = num2; array[1].X = num; array[1].Y = bounds.Y + num4; array[2].X = bounds.X + bounds.Width - num3; array[2].Y = num2; GoShape.DrawLines(g, view, Pen, array); array[0].X = bounds.X + num3; array[0].Y = bounds.Y + bounds.Height - num4; array[1].X = num; array[1].Y = num2; array[2].X = bounds.X + bounds.Width - num3; array[2].Y = bounds.Y + bounds.Height - num4; GoShape.DrawLines(g, view, Pen, array); } else { array[0].X = bounds.X + num3; array[0].Y = bounds.Y + num4; array[1].X = num; array[1].Y = num2; array[2].X = bounds.X + bounds.Width - num3; array[2].Y = bounds.Y + num4; GoShape.DrawLines(g, view, Pen, array); array[0].X = bounds.X + num3; array[0].Y = num2; array[1].X = num; array[1].Y = bounds.Y + bounds.Height - num4; array[2].X = bounds.X + bounds.Width - num3; array[2].Y = num2; GoShape.DrawLines(g, view, Pen, array); } view.FreeTempPointArray(array); break; } } } else { GoShape.DrawEllipse(g, view, Pen, null, bounds.X + bounds.Width / 4f, bounds.Y + bounds.Height / 4f, bounds.Width / 2f, bounds.Height / 2f); } }
/// <summary> /// The path is the same as a regular rectangle if <see cref="P:Northwoods.Go.GoCollapsibleHandle.Bordered" />, /// but augmented with the shape(s) determined by the <see cref="P:Northwoods.Go.GoCollapsibleHandle.Style" />. /// </summary> /// <returns>a <c>GraphicsPath</c></returns> public override GraphicsPath MakePath() { GraphicsPath graphicsPath = (!Bordered) ? new GraphicsPath(FillMode.Winding) : base.MakePath(); IGoCollapsible goCollapsible = FindCollapsible(); if (goCollapsible != null) { RectangleF bounds = Bounds; if (goCollapsible.Collapsible) { float num = bounds.X + bounds.Width / 2f; float num2 = bounds.Y + bounds.Height / 2f; switch (Style) { case GoCollapsibleHandleStyle.PlusMinus: { float num9 = Bordered ? (bounds.Width / 4f) : 0f; float num10 = Bordered ? (bounds.Height / 4f) : 0f; graphicsPath.StartFigure(); graphicsPath.AddLine(bounds.X + num9, num2, bounds.X + bounds.Width - num9, num2); if (!goCollapsible.IsExpanded) { graphicsPath.StartFigure(); graphicsPath.AddLine(num, bounds.Y + num9, num, bounds.Y + bounds.Height - num10); } break; } case GoCollapsibleHandleStyle.TriangleRight: { float num7 = Bordered ? (bounds.Width / 6f) : 0f; float num8 = Bordered ? (bounds.Height / 6f) : 0f; PointF[] array3 = new PointF[3]; if (goCollapsible.IsExpanded) { array3[0].X = bounds.X + num7; array3[0].Y = bounds.Y + num8; array3[1].X = bounds.X + bounds.Width - num7; array3[1].Y = num2; array3[2].X = bounds.X + num7; array3[2].Y = bounds.Y + bounds.Height - num8; } else { array3[0].X = bounds.X + num7; array3[0].Y = bounds.Y + num8; array3[1].X = bounds.X + bounds.Width - num7; array3[1].Y = bounds.Y + num8; array3[2].X = num; array3[2].Y = bounds.Y + bounds.Height - num8; } graphicsPath.StartFigure(); graphicsPath.AddPolygon(array3); break; } case GoCollapsibleHandleStyle.TriangleUp: { float num5 = Bordered ? (bounds.Width / 6f) : 0f; float num6 = Bordered ? (bounds.Height / 6f) : 0f; PointF[] array2 = new PointF[3]; if (goCollapsible.IsExpanded) { array2[0].X = bounds.X + num5; array2[0].Y = bounds.Y + bounds.Height - num6; array2[1].X = bounds.X + bounds.Width - num5; array2[1].Y = bounds.Y + bounds.Height - num6; array2[2].X = num; array2[2].Y = bounds.Y + num6; } else { array2[0].X = bounds.X + num5; array2[0].Y = bounds.Y + num6; array2[1].X = bounds.X + bounds.Width - num5; array2[1].Y = bounds.Y + num6; array2[2].X = num; array2[2].Y = bounds.Y + bounds.Height - num6; } graphicsPath.StartFigure(); graphicsPath.AddPolygon(array2); break; } case GoCollapsibleHandleStyle.ChevronUp: { float num3 = Bordered ? (bounds.Width / 6f) : 0f; float num4 = Bordered ? (bounds.Height / 6f) : 0f; PointF[] array = new PointF[3]; if (goCollapsible.IsExpanded) { array[0].X = bounds.X + num3; array[0].Y = num2; array[1].X = num; array[1].Y = bounds.Y + num4; array[2].X = bounds.X + bounds.Width - num3; array[2].Y = num2; graphicsPath.StartFigure(); graphicsPath.AddLines(array); array[0].X = bounds.X + num3; array[0].Y = bounds.Y + bounds.Height - num4; array[1].X = num; array[1].Y = num2; array[2].X = bounds.X + bounds.Width - num3; array[2].Y = bounds.Y + bounds.Height - num4; graphicsPath.StartFigure(); graphicsPath.AddLines(array); } else { array[0].X = bounds.X + num3; array[0].Y = bounds.Y + num4; array[1].X = num; array[1].Y = num2; array[2].X = bounds.X + bounds.Width - num3; array[2].Y = bounds.Y + num4; graphicsPath.StartFigure(); graphicsPath.AddLines(array); array[0].X = bounds.X + num3; array[0].Y = num2; array[1].X = num; array[1].Y = bounds.Y + bounds.Height - num4; array[2].X = bounds.X + bounds.Width - num3; array[2].Y = num2; graphicsPath.StartFigure(); graphicsPath.AddLines(array); } break; } } } else { graphicsPath.AddEllipse(bounds.X + bounds.Width / 4f, bounds.Y + bounds.Height / 4f, bounds.Width / 2f, bounds.Height / 2f); } } return(graphicsPath); }