public override MaskedSurface TryGetMaskedSurface(IWin32Window window, IPdnDataObject clipData) { using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction = PaintDotNet.SystemLayer.Clipboard.Open(window)) { return(ClipboardUtil.ClipboardRetriever.ConvertToMaskedSurface(ref transaction.TryGetEmf(), true)); } }
public bool PerformAction() { bool flag2; try { if (this.documentWorkspace.ApplyFunction(new AddNewBlankLayerFunction()) == HistoryFunctionResult.Success) { PasteAction action = new PasteAction(this.documentWorkspace, this.clipData, this.maskedSurface); if (!action.PerformAction()) { using (new WaitCursorChanger(this.documentWorkspace)) { this.documentWorkspace.History.StepBackward(this.documentWorkspace.AppWorkspace); goto Label_006E; } } return(true); } Label_006E: flag2 = false; } finally { this.clipData = null; this.maskedSurface = null; } return(flag2); }
public override bool IsDataMaybeAvailable(IWin32Window window, IPdnDataObject clipData) { if (!clipData.GetDataPresent(PdnDataObjectFormats.Bitmap, true)) { return(clipData.GetDataPresent(PdnDataObjectFormats.EnhancedMetafile, true)); } return(true); }
public static MaskedSurface TryGetClipboardImage(IWin32Window currentWindow, IPdnDataObject clipData) { try { return(GetClipboardImageImpl(currentWindow, clipData)); } finally { } }
public override bool IsDataMaybeAvailable(IWin32Window window, IPdnDataObject clipData) { using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction = PaintDotNet.SystemLayer.Clipboard.Open(window)) { if (transaction.IsManagedDataPresent(typeof(MaskedSurface))) { return(clipData.GetDataPresent(typeof(MaskedSurface))); } } return(false); }
public static SizeInt32?TryGetClipboardImageSize(IWin32Window currentWindow, IPdnDataObject clipData) { try { return(TryGetClipboardImageSizeImpl(currentWindow, clipData)); } catch (Exception) { return(null); } }
public override void PerformAction(AppWorkspace appWorkspace) { if (appWorkspace.CanSetActiveWorkspace) { using (NewFileDialog dialog = new NewFileDialog()) { SizeInt32?clipboardImageSize; SizeInt32 newDocumentSize = appWorkspace.GetNewDocumentSize(); using (new WaitCursorChanger(appWorkspace)) { CleanupManager.RequestCleanup(); try { IPdnDataObject dataObject = PdnClipboard.GetDataObject(); clipboardImageSize = ClipboardUtil.GetClipboardImageSize(appWorkspace, dataObject); dataObject = null; } catch (Exception) { clipboardImageSize = null; } CleanupManager.RequestCleanup(); } if (clipboardImageSize.HasValue) { newDocumentSize = clipboardImageSize.Value; } dialog.OriginalSize = new Size(newDocumentSize.Width, newDocumentSize.Height); dialog.OriginalDpuUnit = AppSettings.Instance.Workspace.LastNonPixelUnits.Value; dialog.OriginalDpu = Document.GetDefaultDpu(dialog.OriginalDpuUnit); dialog.Units = dialog.OriginalDpuUnit; dialog.Resolution = dialog.OriginalDpu; dialog.ConstrainToAspect = AppSettings.Instance.Workspace.LastMaintainAspectRatioNF.Value; if ((((dialog.ShowDialog(appWorkspace) == DialogResult.OK) && (dialog.ImageWidth > 0)) && ((dialog.ImageHeight > 0) && dialog.Resolution.IsFinite())) && (dialog.Resolution > 0.0)) { SizeInt32 size = new SizeInt32(dialog.ImageWidth, dialog.ImageHeight); if (appWorkspace.CreateBlankDocumentInNewWorkspace(size, dialog.Units, dialog.Resolution, false)) { appWorkspace.ActiveDocumentWorkspace.ZoomBasis = ZoomBasis.FitToWindow; AppSettings.Instance.Workspace.LastMaintainAspectRatioNF.Value = dialog.ConstrainToAspect; if (dialog.Units != MeasurementUnit.Pixel) { AppSettings.Instance.Workspace.LastNonPixelUnits.Value = dialog.Units; } if (appWorkspace.Units != MeasurementUnit.Pixel) { appWorkspace.Units = dialog.Units; } } } } } }
public override bool IsDataMaybeAvailable(IWin32Window window, IPdnDataObject clipData) { string[] strArray; if (!clipData.GetDataPresent(PdnDataObjectFormats.FileDrop)) { return(false); } using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction = PaintDotNet.SystemLayer.Clipboard.Open(window)) { strArray = transaction.TryGetFileDropData(); } return(((strArray != null) && (strArray.Length == 1)) && (IsImageFileName(strArray[0]) && File.Exists(strArray[0]))); }
public bool PerformAction() { bool flag; try { flag = this.PerformActionImpl(); } finally { this.clipData = null; this.maskedSurface = null; } return(flag); }
public override MaskedSurface TryGetMaskedSurface(IWin32Window window, IPdnDataObject clipData) { using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction = PaintDotNet.SystemLayer.Clipboard.Open(window)) { MaskedSurface surface = transaction.TryGetManagedData(typeof(MaskedSurface)) as MaskedSurface; if (surface == null) { return(null); } if (surface.IsDisposed) { return(null); } return(surface); } }
public override MaskedSurface TryGetMaskedSurface(IWin32Window window, IPdnDataObject clipData) { using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction = PaintDotNet.SystemLayer.Clipboard.Open(window)) { uint formatID = PaintDotNet.SystemLayer.Clipboard.RegisterFormat("PNG"); Image image = null; if (!transaction.TryGetRawNativeData(formatID, delegate(Stream stream) { image = Image.FromStream(stream, false, true); })) { return(null); } if (image != null) { return(ClipboardUtil.ClipboardRetriever.ConvertToMaskedSurface(ref image, false)); } } return(null); }
public override MaskedSurface TryGetMaskedSurface(IWin32Window window, IPdnDataObject clipData) { string[] strArray; using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction = PaintDotNet.SystemLayer.Clipboard.Open(window)) { strArray = transaction.TryGetFileDropData(); } if (strArray == null) { return(null); } if (strArray.Length != 1) { return(null); } string fileName = strArray[0]; if (!IsImageFileName(fileName)) { return(null); } File.Exists(fileName); return(ClipboardUtil.ClipboardRetriever.ConvertToMaskedSurface(ref Image.FromFile(fileName), false)); }
public PasteAction(DocumentWorkspace documentWorkspace, IPdnDataObject clipData, MaskedSurface maskedSurface) { this.documentWorkspace = documentWorkspace; this.clipData = clipData; this.maskedSurface = maskedSurface; }
public TestEffect() : base("Test", null, "ArgusTest") { this._clipboard = PdnClipboard.GetDataObject(); }
private bool PerformActionImpl() { PointInt32 num2; RectInt32 num3; if (this.clipData == null) { try { using (new WaitCursorChanger(this.documentWorkspace)) { CleanupManager.RequestCleanup(); this.clipData = PdnClipboard.GetDataObject(); } } catch (OutOfMemoryException exception) { ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception); return(false); } catch (Exception exception2) { ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception2); return(false); } } bool handled = false; if (this.documentWorkspace.Tool != null) { this.documentWorkspace.Tool.PerformPaste(this.clipData, out handled); } if (handled) { return(true); } if (this.maskedSurface == null) { try { using (new WaitCursorChanger(this.documentWorkspace)) { this.maskedSurface = ClipboardUtil.GetClipboardImage(this.documentWorkspace, this.clipData); } } catch (OutOfMemoryException exception3) { ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.OutOfMemory"), exception3); return(false); } catch (Exception exception4) { ExceptionDialog.ShowErrorDialog(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.TransferFromClipboard"), exception4); return(false); } } if (this.maskedSurface == null) { MessageBoxUtil.ErrorBox(this.documentWorkspace, PdnResources.GetString("PasteAction.Error.NoImage")); return(false); } RectInt32 cachedGeometryMaskScansBounds = this.maskedSurface.GetCachedGeometryMaskScansBounds(); if ((cachedGeometryMaskScansBounds.Width > this.documentWorkspace.Document.Width) || (cachedGeometryMaskScansBounds.Height > this.documentWorkspace.Document.Height)) { Surface surface; try { using (new WaitCursorChanger(this.documentWorkspace)) { surface = CreateThumbnail(this.maskedSurface); } } catch (OutOfMemoryException) { surface = null; } DialogResult result = ShowExpandCanvasTaskDialog(this.documentWorkspace, surface); int activeLayerIndex = this.documentWorkspace.ActiveLayerIndex; ColorBgra background = this.documentWorkspace.ToolSettings.SecondaryColor.Value; if (result != DialogResult.Cancel) { if (result != DialogResult.Yes) { if (result != DialogResult.No) { throw ExceptionUtil.InvalidEnumArgumentException <DialogResult>(result, "dr"); } goto Label_031D; } using (new PushNullToolMode(this.documentWorkspace)) { int width = Math.Max(cachedGeometryMaskScansBounds.Width, this.documentWorkspace.Document.Width); Size newSize = new Size(width, Math.Max(cachedGeometryMaskScansBounds.Height, this.documentWorkspace.Document.Height)); Document document = CanvasSizeAction.ResizeDocument(this.documentWorkspace.Document, newSize, AnchorEdge.TopLeft, background); if (document == null) { return(false); } SelectionHistoryMemento memento = new SelectionHistoryMemento(null, null, this.documentWorkspace); ReplaceDocumentHistoryMemento memento2 = new ReplaceDocumentHistoryMemento(CanvasSizeAction.StaticName, CanvasSizeAction.StaticImage, this.documentWorkspace); this.documentWorkspace.Document = document; HistoryMemento[] actions = new HistoryMemento[] { memento, memento2 }; CompoundHistoryMemento memento3 = new CompoundHistoryMemento(CanvasSizeAction.StaticName, CanvasSizeAction.StaticImage, actions); this.documentWorkspace.History.PushNewMemento(memento3); this.documentWorkspace.ActiveLayer = (Layer)this.documentWorkspace.Document.Layers[activeLayerIndex]; goto Label_031D; } } return(false); } Label_031D: num3 = this.documentWorkspace.Document.Bounds(); RectDouble visibleDocumentRect = this.documentWorkspace.VisibleDocumentRect; RectInt32? nullable = visibleDocumentRect.Int32Inset(); RectDouble num5 = nullable.HasValue ? ((RectDouble)nullable.Value) : visibleDocumentRect; RectInt32 num6 = num5.Int32Bound; if (num5.Contains(cachedGeometryMaskScansBounds)) { num2 = new PointInt32(0, 0); } else { int num12; int num13; int num16; int num17; if (cachedGeometryMaskScansBounds.X < num5.Left) { num12 = -cachedGeometryMaskScansBounds.X + num6.X; } else if (cachedGeometryMaskScansBounds.Right > num6.Right) { num12 = (-cachedGeometryMaskScansBounds.X + num6.Right) - cachedGeometryMaskScansBounds.Width; } else { num12 = 0; } if (cachedGeometryMaskScansBounds.Y < num5.Top) { num13 = -cachedGeometryMaskScansBounds.Y + num6.Y; } else if (cachedGeometryMaskScansBounds.Bottom > num6.Bottom) { num13 = (-cachedGeometryMaskScansBounds.Y + num6.Bottom) - cachedGeometryMaskScansBounds.Height; } else { num13 = 0; } PointInt32 num14 = new PointInt32(num12, num13); RectInt32 num15 = new RectInt32(cachedGeometryMaskScansBounds.X + num14.X, cachedGeometryMaskScansBounds.Y + num14.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height); if (num15.X < 0) { num16 = num12 - num15.X; } else { num16 = num12; } if (num15.Y < 0) { num17 = num13 - num15.Y; } else { num17 = num13; } PointInt32 num18 = new PointInt32(num16, num17); RectInt32 rect = new RectInt32(cachedGeometryMaskScansBounds.X + num18.X, cachedGeometryMaskScansBounds.Y + num18.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height); if (num3.Contains(rect)) { num2 = num18; } else { PointInt32 num20 = num18; if (rect.Right > num3.Right) { int num21 = rect.Right - num3.Right; int num22 = Math.Min(num21, rect.Left); num20.X -= num22; } if (rect.Bottom > num3.Bottom) { int num23 = rect.Bottom - num3.Bottom; int num24 = Math.Min(num23, rect.Top); num20.Y -= num24; } num2 = num20; } } RectInt32 b = this.documentWorkspace.VisibleDocumentRect.Int32Bound; RectInt32 a = new RectInt32(cachedGeometryMaskScansBounds.X + num2.X, cachedGeometryMaskScansBounds.Y + num2.Y, cachedGeometryMaskScansBounds.Width, cachedGeometryMaskScansBounds.Height); bool hasZeroArea = RectInt32.Intersect(a, b).HasZeroArea; MoveTool.BeginPaste(this.documentWorkspace, PdnResources.GetString("CommonAction.Paste"), PdnResources.GetImageResource("Icons.MenuEditPasteIcon.png"), this.maskedSurface.SurfaceReadOnly, this.maskedSurface.GeometryMask, num2); if (hasZeroArea) { PointInt32 num25 = new PointInt32(b.Left + (b.Width / 2), b.Top + (b.Height / 2)); PointInt32 num26 = new PointInt32(a.Left + (a.Width / 2), a.Top + (a.Height / 2)); SizeInt32 num27 = new SizeInt32(num26.X - num25.X, num26.Y - num25.Y); PointDouble documentScrollPosition = this.documentWorkspace.DocumentScrollPosition; PointDouble num29 = new PointDouble(documentScrollPosition.X + num27.Width, documentScrollPosition.Y + num27.Height); this.documentWorkspace.DocumentScrollPosition = num29; } return(true); }
public static bool IsClipboardImageMaybeAvailable(IWin32Window currentWindow, IPdnDataObject clipData) { try { bool flag = false; foreach (ClipboardRetriever retriever in retrievers) { if (retriever.IsDataMaybeAvailable(currentWindow, clipData)) { flag = true; } } return(flag); } catch (Exception) { return(false); } }
private static MaskedSurface GetClipboardImageImpl(IWin32Window currentWindow, IPdnDataObject clipData) { CleanupManager.RequestCleanup(); using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction = PaintDotNet.SystemLayer.Clipboard.Open(currentWindow)) { if (transaction.IsManagedDataPresent(typeof(MaskedSurface))) { try { MaskedSurface surface2 = transaction.TryGetManagedData(typeof(MaskedSurface)) as MaskedSurface; if ((surface2 != null) && !surface2.IsDisposed) { return(surface2); } if (surface2 != null) { bool isDisposed = surface2.IsDisposed; } } catch (OutOfMemoryException) { throw; } catch (Exception) { } } } Surface clipboardImageAsSurface = GetClipboardImageAsSurface(currentWindow, clipData); if (clipboardImageAsSurface != null) { return(new MaskedSurface(ref clipboardImageAsSurface, true)); } return(null); }
public override bool IsDataMaybeAvailable(IWin32Window window, IPdnDataObject clipData) => clipData.GetDataPresent("PNG", false);
public abstract bool IsDataMaybeAvailable(IWin32Window window, IPdnDataObject clipData);
public static bool IsClipboardImageMaybeAvailable(IWin32Window currentWindow, IPdnDataObject clipData) { try { bool flag3; bool flag = false; using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction = PaintDotNet.SystemLayer.Clipboard.Open(currentWindow)) { if (transaction.IsManagedDataPresent(typeof(MaskedSurface))) { flag = clipData.GetDataPresent(typeof(MaskedSurface)); } } if (!clipData.GetDataPresent(PdnDataObjectFormats.FileDrop)) { flag3 = false; } else { string[] data = clipData.GetData(PdnDataObjectFormats.FileDrop) as string[]; if (((data != null) && (data.Length == 1)) && (IsImageFileName(data[0]) && File.Exists(data[0]))) { flag3 = true; } else { flag3 = false; } } bool dataPresent = clipData.GetDataPresent(PdnDataObjectFormats.Bitmap, true); bool flag5 = clipData.GetDataPresent(PdnDataObjectFormats.Dib, true); bool flag6 = clipData.GetDataPresent(PdnDataObjectFormats.EnhancedMetafile, true); bool flag7 = clipData.GetDataPresent("PNG", false); return(((((flag | flag3) | dataPresent) | flag5) | flag6) | flag7); } catch (Exception) { return(false); } }
private static void ClipDataDebugging(IPdnDataObject clipData) { }
public abstract MaskedSurface TryGetMaskedSurface(IWin32Window window, IPdnDataObject clipData);
public override MaskedSurface TryGetMaskedSurface(IWin32Window window, IPdnDataObject clipData) { Image data = clipData.GetData(PdnDataObjectFormats.Bitmap, true) as Image; return(ClipboardUtil.ClipboardRetriever.ConvertToMaskedSurface(ref data, true)); }
private static unsafe Surface GetClipboardImageAsSurface(IWin32Window currentWindow, IPdnDataObject clipData) { Image image = null; Surface surface = null; if (((image == null) && (surface == null)) && clipData.GetDataPresent(PdnDataObjectFormats.FileDrop)) { try { string[] strArray = null; using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction = PaintDotNet.SystemLayer.Clipboard.Open(currentWindow)) { strArray = transaction.TryGetFileDropData(); } if ((strArray != null) && (strArray.Length == 1)) { string fileName = strArray[0]; if (IsImageFileName(fileName) && File.Exists(fileName)) { image = Image.FromFile(fileName); surface = Surface.CopyFromGdipImage(image, false); image.Dispose(); image = null; } } } catch (OutOfMemoryException) { throw; } catch (Exception) { } } if (((image == null) && (surface == null)) && clipData.GetDataPresent(PdnDataObjectFormats.Dib, true)) { try { using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction2 = PaintDotNet.SystemLayer.Clipboard.Open(currentWindow)) { bool flag = transaction2.TryGetRawNativeData(8, delegate(UnsafeBufferLock buffer) { Size size; byte *pBitmapInfo = (byte *)buffer.Address; int ncbBitmapInfo = (int)buffer.Size; if (PdnGraphics.TryGetBitmapInfoSize(pBitmapInfo, ncbBitmapInfo, out size)) { surface = new Surface(size.Width, size.Height); bool flag = false; try { using (Bitmap bitmap = surface.CreateAliasedBitmap(true)) { flag = PdnGraphics.TryCopyFromBitmapInfo(bitmap, pBitmapInfo, ncbBitmapInfo); } surface.DetectAndFixDishonestAlpha(); } finally { if ((surface != null) && !flag) { surface.Dispose(); surface = null; } } } }); } } catch (OutOfMemoryException) { throw; } catch (Exception) { } } if (((image == null) && (surface == null)) && (clipData.GetDataPresent(PdnDataObjectFormats.Bitmap, true) || clipData.GetDataPresent(PdnDataObjectFormats.EnhancedMetafile, true))) { try { image = clipData.GetData(PdnDataObjectFormats.Bitmap, true) as Image; } catch (OutOfMemoryException) { throw; } catch (Exception) { } if (image == null) { try { using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction3 = PaintDotNet.SystemLayer.Clipboard.Open(currentWindow)) { image = transaction3.TryGetEmf(); Image image1 = image; } } catch (OutOfMemoryException) { throw; } catch (Exception) { } } } if (((image == null) && (surface == null)) && clipData.GetDataPresent("PNG", false)) { try { bool flag2 = false; using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction4 = PaintDotNet.SystemLayer.Clipboard.Open(currentWindow)) { uint formatID = PaintDotNet.SystemLayer.Clipboard.RegisterFormat("PNG"); flag2 = transaction4.TryGetRawNativeData(formatID, delegate(Stream stream) { image = Image.FromStream(stream, false, true); }); } if (flag2 && (image != null)) { surface = Surface.CopyFromGdipImage(image, false); DisposableUtil.Free <Image>(ref image); } } catch (OutOfMemoryException) { throw; } catch (Exception) { } } if ((surface != null) && (image != null)) { throw new InternalErrorException("both surface and image are non-null"); } if ((surface == null) && (image != null)) { surface = Surface.CopyFromGdipImage(image, true); } return(surface); }
public void PerformPasteQuery(IPdnDataObject data, out bool canHandle) { this.PasteQuery(data, out canHandle); }
private static MaskedSurface GetClipboardImageImpl(IWin32Window currentWindow, IPdnDataObject clipData) { List <Exception> source = null; for (int i = 0; i < retrievers.Length; i++) { ClipboardRetriever retriever = retrievers[i]; for (int j = 1; j <= 2; j++) { try { if (retriever.IsDataMaybeAvailable(currentWindow, clipData)) { MaskedSurface surface = retriever.TryGetMaskedSurface(currentWindow, clipData); if ((surface != null) && !surface.IsDisposed) { return(surface); } } } catch (Exception exception) { if (exception is OutOfMemoryException) { CleanupManager.RequestCleanup(); CleanupManager.WaitForPendingCleanup(); } else { j = 2; } source = source ?? new List <Exception>(); source.Add(exception); } } } if (source == null) { return(null); } if (source.Count == 1) { if (source[0] is OutOfMemoryException) { throw new OutOfMemoryException(source[0].Message, source[0]); } throw new Exception(source[0].Message, source[0]); } if (source.All <Exception>(ex => ex is OutOfMemoryException)) { throw new OutOfMemoryException(new OutOfMemoryException().Message, new AggregateException(source)); } throw new AggregateException(source); }
public override unsafe MaskedSurface TryGetMaskedSurface(IWin32Window window, IPdnDataObject clipData) { Surface result = null; using (PaintDotNet.SystemLayer.Clipboard.Transaction transaction = PaintDotNet.SystemLayer.Clipboard.Open(window)) { bool flag = transaction.TryGetRawNativeData(8, delegate(UnsafeBufferLock buffer) { Size size; byte *pBitmapInfo = (byte *)buffer.Address; int ncbBitmapInfo = (int)buffer.Size; if (PdnGraphics.TryGetBitmapInfoSize(pBitmapInfo, ncbBitmapInfo, out size)) { Surface disposeMe = new Surface(size.Width, size.Height); bool flag = false; try { using (Bitmap bitmap = disposeMe.CreateAliasedBitmap(true)) { flag = PdnGraphics.TryCopyFromBitmapInfo(bitmap, pBitmapInfo, ncbBitmapInfo); } disposeMe.DetectAndFixDishonestAlpha(); } finally { if (flag) { result = disposeMe; } else { DisposableUtil.Free <Surface>(ref disposeMe); } } } }); } return(ClipboardUtil.ClipboardRetriever.ConvertToMaskedSurface(ref result)); }
public override bool IsDataMaybeAvailable(IWin32Window window, IPdnDataObject clipData) => clipData.GetDataPresent(PdnDataObjectFormats.Dib, true);
public void PerformPaste(IPdnDataObject data, out bool handled) { this.Paste(data, out handled); }
private static SizeInt32?TryGetClipboardImageSizeImpl(IWin32Window currentWindow, IPdnDataObject clipData) { using (MaskedSurface surface = TryGetClipboardImage(currentWindow, clipData)) { if (surface != null) { return(new SizeInt32?(surface.GetCachedGeometryMaskScansBounds().Size)); } } return(null); }