/// <summary> /// Returns a <c>GraphicsPath</c> representation of what will be drawn. /// </summary> /// <returns></returns> public override GraphicsPath MakePath() { GraphicsPath graphicsPath = new GraphicsPath(FillMode.Winding); int pointsCount = PointsCount; PointF[] array = new PointF[pointsCount]; for (int i = 0; i < pointsCount; i = checked (i + 1)) { array[i] = GetPoint(i); } bool flag = Style == GoPolygonStyle.Bezier; if (flag && pointsCount % 3 != 1) { GoObject.Trace("Polygon has wrong number of points: " + pointsCount.ToString(NumberFormatInfo.InvariantInfo) + "; should have 3n+1 points"); flag = false; } if (flag) { graphicsPath.AddBeziers(array); } else { graphicsPath.AddLines(array); } graphicsPath.CloseAllFigures(); return(graphicsPath); }
/// <summary> /// Restore the state of some documents to after the current <see cref="T:Northwoods.Go.IGoUndoableEdit" />. /// </summary> /// <remarks> /// This calls <see cref="M:Northwoods.Go.IGoUndoableEdit.Redo" /> on the current <see cref="P:Northwoods.Go.GoUndoManager.EditToRedo" />. /// This will raise a <see cref="E:Northwoods.Go.GoDocument.Changed" /> event with a hint of /// <see cref="F:Northwoods.Go.GoDocument.StartingRedo" /> before actually performing the redo, and will raise a /// Changed event with a hint of <see cref="F:Northwoods.Go.GoDocument.FinishedRedo" /> afterwards. /// The <see cref="T:Northwoods.Go.GoChangedEventArgs" />.<see cref="P:Northwoods.Go.GoChangedEventArgs.Object" /> /// is the <see cref="T:Northwoods.Go.GoUndoManagerCompoundEdit" /> that was the value of /// <see cref="P:Northwoods.Go.GoUndoManager.EditToRedo" /> before calling Redo. /// </remarks> /// <seealso cref="M:Northwoods.Go.GoUndoManager.CanRedo" /> public virtual void Redo() { checked { if (CanRedo()) { IGoUndoableEdit editToRedo = EditToRedo; try { foreach (GoDocument document in Documents) { document.RaiseChanged(109, 0, editToRedo, 0, null, GoObject.NullRect, 0, null, GoObject.NullRect); } myIsRedoing = true; myCurrentEditIndex++; editToRedo.Redo(); } catch (Exception ex) { GoObject.Trace("Redo: " + ex.ToString()); throw; } finally { myIsRedoing = false; foreach (GoDocument document2 in Documents) { document2.RaiseChanged(110, 0, editToRedo, 0, null, GoObject.NullRect, 0, null, GoObject.NullRect); } } } } }
/// <summary> /// Create an <see cref="T:Northwoods.Go.IGoUndoableEdit" /> for a <see cref="T:Northwoods.Go.GoDocument" /> Changed event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks> /// This calls <see cref="M:Northwoods.Go.GoUndoManager.SkipEvent(Northwoods.Go.GoChangedEventArgs)" /> if for some reason we should ignore /// the <paramref name="e" />. /// This then creates a <see cref="T:Northwoods.Go.GoChangedEventArgs" /> and adds it to the /// <see cref="P:Northwoods.Go.GoUndoManager.CurrentEdit" />, a <see cref="T:Northwoods.Go.GoUndoManagerCompoundEdit" /> which it allocates /// if needed. /// This method always ignores all Changed events while we are performing an /// <see cref="M:Northwoods.Go.GoUndoManager.Undo" /> or <see cref="M:Northwoods.Go.GoUndoManager.Redo" />. /// </remarks> public virtual void DocumentChanged(object sender, GoChangedEventArgs e) { if (!IsUndoing && !IsRedoing && !SkipEvent(e)) { GoUndoManagerCompoundEdit goUndoManagerCompoundEdit = CurrentEdit; if (goUndoManagerCompoundEdit == null || goUndoManagerCompoundEdit.IsComplete) { goUndoManagerCompoundEdit = (CurrentEdit = new GoUndoManagerCompoundEdit()); } GoChangedEventArgs goChangedEventArgs = new GoChangedEventArgs(e); goUndoManagerCompoundEdit.AddEdit(goChangedEventArgs); if (ChecksTransactionLevel && TransactionLevel <= 0) { GoObject.Trace("Change not within a transaction: " + goChangedEventArgs.ToString()); } } }
/// <summary> /// This method is responsible for getting an Image. /// </summary> /// <returns> /// An <c>Image</c>. /// </returns> /// <remarks> /// <para> /// The normal behavior is to try to use the <see cref="P:Northwoods.Go.GoImage.Index" /> /// value, if non-negative, to find an Image in the <see cref="P:Northwoods.Go.GoImage.ImageList" />. /// If there is no ImageList, we try using the <see cref="P:Northwoods.Go.GoImage.DefaultImageList" />. /// </para> /// <para> /// If the index value is negative, we use the <see cref="P:Northwoods.Go.GoImage.Name" /> /// to get an Image object from the <see cref="P:Northwoods.Go.GoImage.ResourceManager" />. /// If there is no ResourceManager, we try using the /// <see cref="P:Northwoods.Go.GoImage.DefaultResourceManager" />, and if that fails, we /// try treating the name as a filename. /// </para> /// <para> /// The resulting Image is normally cached by this object as the /// <see cref="P:Northwoods.Go.GoImage.Image" /> property. If it loads the image from a file, /// the file may remain locked until the image is garbage collected. /// </para> /// <para> /// If an exception occurs trying to load an image, the message /// is sent to trace listeners. Also, if <see cref="P:Northwoods.Go.GoImage.ThrowsExceptions" /> /// is true, the catch handler will rethrow the exception. /// If the <see cref="P:Northwoods.Go.GoImage.Index" /> is out-of-bounds for the <see cref="P:Northwoods.Go.GoImage.ImageList" />, /// or if the <see cref="P:Northwoods.Go.GoImage.Name" /> is not found in the <see cref="P:Northwoods.Go.GoImage.ResourceManager" />, /// this will fail silently--no exception is thrown. /// </para> /// </remarks> /// <seealso cref="M:Northwoods.Go.GoImage.UnloadImage" /> public virtual Image LoadImage() { int index = Index; if (index >= 0) { Image image = null; ImageList imageList = ImageList; if (imageList != null) { image = FindCachedImage(imageList, index, null, CultureInfo.InvariantCulture); if (image != null) { return(image); } } ImageList defaultImageList = DefaultImageList; if (defaultImageList != null && defaultImageList != imageList) { image = FindCachedImage(defaultImageList, index, null, CultureInfo.InvariantCulture); if (image != null) { return(image); } } if (imageList != null && index < imageList.Images.Count) { image = imageList.Images[index]; } if (image != null) { SaveCachedImage(imageList, index, null, CultureInfo.InvariantCulture, image); return(image); } if (defaultImageList != null && defaultImageList != imageList && index < defaultImageList.Images.Count) { image = defaultImageList.Images[index]; } if (image != null) { SaveCachedImage(defaultImageList, index, null, CultureInfo.InvariantCulture, image); return(image); } if (image != null) { return(image); } } string name = Name; if (name != null && name != "") { Image image2 = null; ResourceManager resourceManager = ResourceManager; if (resourceManager != null) { image2 = FindCachedImage(resourceManager, 0, name, CultureInfo.CurrentCulture); if (image2 != null) { return(image2); } } ResourceManager defaultResourceManager = DefaultResourceManager; if (defaultResourceManager != null && defaultResourceManager != resourceManager) { image2 = FindCachedImage(defaultResourceManager, 0, name, CultureInfo.CurrentCulture); if (image2 != null) { return(image2); } } image2 = FindCachedImage(null, 0, name, CultureInfo.InvariantCulture); if (image2 != null) { return(image2); } if (resourceManager != null) { try { object @object = resourceManager.GetObject(name, CultureInfo.CurrentCulture); image2 = ConvertObjectToImage(@object); } catch (MissingManifestResourceException) { } } if (image2 != null) { SaveCachedImage(resourceManager, 0, name, CultureInfo.CurrentCulture, image2); return(image2); } if (defaultResourceManager != null && defaultResourceManager != resourceManager) { try { object object2 = defaultResourceManager.GetObject(name, CultureInfo.CurrentCulture); image2 = ConvertObjectToImage(object2); } catch (MissingManifestResourceException) { } } if (image2 != null) { SaveCachedImage(defaultResourceManager, 0, name, CultureInfo.CurrentCulture, image2); return(image2); } try { if (NameIsUri) { WebClient webClient = new WebClient(); Stream stream = webClient.OpenRead(name); image2 = Image.FromStream(stream); stream.Close(); webClient.Dispose(); } else { image2 = Image.FromFile(name); } base.InternalFlags &= -4194305; } catch (Exception ex3) { if ((base.InternalFlags & 0x400000) == 0) { base.InternalFlags |= 4194304; GoObject.Trace("GoImage.LoadImage: " + ex3.ToString()); } if (ThrowsExceptions) { throw; } } if (image2 != null) { SaveCachedImage(null, 0, name, CultureInfo.InvariantCulture, image2); return(image2); } } return(null); }
/// <summary> /// Draw this Image within the bounds of this object. /// </summary> /// <param name="g"></param> /// <param name="view"></param> /// <remarks> /// If the value of <see cref="P:Northwoods.Go.GoImage.Image" /> is null and the value /// of <see cref="P:Northwoods.Go.GoImage.Index" /> is non-negative, we try to draw an <c>Image</c> /// from the view's <see cref="P:Northwoods.Go.GoView.ImageList" />. /// </remarks> public override void Paint(Graphics g, GoView view) { RectangleF bounds = Bounds; Image image = Image; int index = Index; if (image == null && index >= 0) { ImageList imageList = view.ImageList; if (imageList != null && index < imageList.Images.Count) { image = imageList.Images[index]; } } if (image != null) { try { if (Shadowed) { SizeF shadowOffset = GetShadowOffset(view); ColorMatrix colorMatrix = new ColorMatrix(); colorMatrix.Matrix00 = 0f; colorMatrix.Matrix11 = 0f; colorMatrix.Matrix22 = 0f; SolidBrush solidBrush = GetShadowBrush(view) as SolidBrush; if (solidBrush != null) { Color color = solidBrush.Color; colorMatrix.Matrix30 = (float)(int)color.R / 255f; colorMatrix.Matrix31 = (float)(int)color.G / 255f; colorMatrix.Matrix32 = (float)(int)color.B / 255f; colorMatrix.Matrix33 = (float)(int)color.A / 255f; } else { colorMatrix.Matrix30 = 0.5f; colorMatrix.Matrix31 = 0.5f; colorMatrix.Matrix32 = 0.5f; colorMatrix.Matrix33 = 0.5f; } ImageAttributes imageAttributes = new ImageAttributes(); imageAttributes.SetColorMatrix(colorMatrix); g.DrawImage(image, checked (new Rectangle((int)(bounds.X + shadowOffset.Width), (int)(bounds.Y + shadowOffset.Height), (int)bounds.Width, (int)bounds.Height)), 0, 0, image.Size.Width, image.Size.Height, GraphicsUnit.Pixel, imageAttributes); } g.DrawImage(image, bounds); base.InternalFlags &= -4194305; } catch (Exception ex) { if ((base.InternalFlags & 0x400000) == 0) { base.InternalFlags |= 4194304; GoObject.Trace("GoImage.Paint: " + ex.ToString()); } if (ThrowsExceptions) { throw; } } } }
/// <summary> /// Start a drag-and-drop operation. /// </summary> /// <remarks> /// <para> /// This first remembers the <see cref="P:Northwoods.Go.GoToolDragging.MoveOffset" /> between the <see cref="P:Northwoods.Go.GoTool.CurrentObject" />'s /// position and the mouse point (the first input event point). /// It removes any selection handles, so those do not need to be dragged along. /// It also starts a transaction. /// If the view's <see cref="P:Northwoods.Go.GoView.AllowDragOut" /> property is true, we call /// <c>Control.DoDragDrop</c> to start the standard modal drag-and-drop process. /// </para> /// <para> /// This depends on the cooperation of <see cref="M:Northwoods.Go.GoView.OnDragOver(System.Windows.Forms.DragEventArgs)" />, <see cref="M:Northwoods.Go.GoView.OnDragDrop(System.Windows.Forms.DragEventArgs)" />, /// and <see cref="M:Northwoods.Go.GoView.OnQueryContinueDrag(System.Windows.Forms.QueryContinueDragEventArgs)" /> to call <see cref="M:Northwoods.Go.GoToolDragging.DoMouseMove" />, /// <see cref="M:Northwoods.Go.GoToolDragging.DoMouseUp" />, and <see cref="M:Northwoods.Go.GoToolDragging.DoCancelMouse" /> appropriately when the /// drop target is the same view as the drag source. /// If the view's <see cref="P:Northwoods.Go.GoView.AllowDragOut" /> property is false, the /// normal calls to <see cref="M:Northwoods.Go.GoToolDragging.DoMouseMove" />, <see cref="M:Northwoods.Go.GoToolDragging.DoMouseUp" />, and /// <see cref="M:Northwoods.Go.GoToolDragging.DoCancelMouse" /> occur. /// </para> /// <para> /// If <see cref="P:Northwoods.Go.GoToolDragging.SelectsWhenStarts" /> is false, this method does not /// modify the current selection and does not set /// <see cref="P:Northwoods.Go.GoTool.CurrentObject" /> or <see cref="P:Northwoods.Go.GoToolDragging.MoveOffset" />. /// </para> /// </remarks> public override void Start() { if (SelectsWhenStarts) { base.CurrentObject = base.View.PickObject(doc: true, view: false, base.FirstInput.DocPoint, selectableOnly: true); if (base.CurrentObject == null) { return; } MoveOffset = GoTool.SubtractPoints(base.FirstInput.DocPoint, base.CurrentObject.Position); } StartTransaction(); if (SelectsWhenStarts && !base.Selection.Contains(base.CurrentObject)) { if (base.FirstInput.Shift || base.FirstInput.Control) { base.Selection.Add(base.CurrentObject); } else { base.Selection.Select(base.CurrentObject); } } if (!base.View.DragRoutesRealtime && base.View.DragsRealtime) { base.View.Document.SuspendsRouting = true; } if (HidesSelectionHandles) { mySelectionHidden = true; base.Selection.RemoveAllSelectionHandles(); } if (base.View.AllowDragOut) { myModalDropped = false; try { if (base.Selection.Primary != null) { SizeF hotSpot = GoTool.SubtractPoints(base.LastInput.DocPoint, base.Selection.Primary.Position); base.Selection.HotSpot = hotSpot; } DoDragDrop(base.Selection, DragDropEffects.All); } catch (VerificationException ex) { GoObject.Trace("GoToolDragging Start: " + ex.ToString()); } catch (SecurityException ex2) { GoObject.Trace("GoToolDragging Start: " + ex2.ToString()); } finally { if (!myModalDropped) { DoCancelMouse(); } else { StopTool(); } base.Selection.HotSpot = default(SizeF); } } }