Pasting with Offset


#1

What’s the easiest way to get pasted selections to be offset from the originals rather than being right on top of them?


#2

The easiest thing to do is define a GoView.ClipboardPasted event handler, and call GoView.MoveSelection on the view’s Selection.
The most general thing to do would be to override GoView.PasteFromClipboard and replace the hardcoded offset of 1x1 argument in the call to GoDocument.CopyFromCollection with an offset that suits your purposes. Here’s the definition of GoView.PasteFromClipboard:
public virtual GoCopyDictionary PasteFromClipboard() {
GoDocument thisdoc = this.Document;
if (thisdoc == null) return null;
IDataObject data = Clipboard.GetDataObject();
if (data == null) return null;
// try GoDocument format
Object docobj = data.GetData(thisdoc.DataFormat);
if (docobj != null && docobj is GoDocument) {
GoDocument clipdoc = (GoDocument)docobj;
// copy objects from selection into this document
return thisdoc.CopyFromCollection(clipdoc, false, false, new SizeF(1, 1), null);
}
return null;
}


#3

Nice. Thank you. I went the route of overriding GoView.PasteFromClipboard.
One wrinkle to this is that if you want it to behave like MS PowerPoint (i.e. continue to paste in a different location if you paste multiple times), you need to keep track of the paste offset and increment it each time you paste. The paste offset needs to be reset when you either copy or cut to the clipboard. FWIW, I did this by overriding GoView.EditCut and GoView.EditCopy.
Mike D