protected IDragTarget CreateHostFigureDragTarget() { var ret = MouseOperatableFactory.CreateDragTarget(); ret.DragOver += (sender, e) => { e.Effect = DragDropEffects.None; var data = e.Data; if (data.GetDataPresent(typeof(MemoInfo[]))) { if (DragDropUtil.IsLinkAllowed(e)) { e.Effect = DragDropEffects.Link; ShowHostFigureDropTextFeedback(new Point(e.X, e.Y)); } } else if (data.GetDataPresent(StyledTextConsts.BlocksAndInlinesFormat.Name)) { if (DragDropUtil.IsControlPressed(e)) { if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; ShowHostFigureDropTextFeedback(new Point(e.X, e.Y)); } else { e.Effect = DragDropEffects.Move; ShowHostFigureDropTextFeedback(new Point(e.X, e.Y)); } } else { if (DragDropUtil.IsMoveAllowed(e)) { e.Effect = DragDropEffects.Move; ShowHostFigureDropTextFeedback(new Point(e.X, e.Y)); } else if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; ShowHostFigureDropTextFeedback(new Point(e.X, e.Y)); } } } if (data.GetDataPresent("UniformResourceLocator") && data.GetDataPresent(DataFormats.UnicodeText)) { if (DragDropUtil.IsLinkAllowed(e)) { e.Effect = DragDropEffects.Link; ShowHostFigureDropTextFeedback(new Point(e.X, e.Y)); } } else if (data.GetDataPresent(DataFormats.UnicodeText)) { if (DragDropUtil.IsControlPressed(e)) { if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; ShowHostFigureDropTextFeedback(new Point(e.X, e.Y)); } else { e.Effect = DragDropEffects.Move; ShowHostFigureDropTextFeedback(new Point(e.X, e.Y)); } } else { if (DragDropUtil.IsMoveAllowed(e)) { e.Effect = DragDropEffects.Move; ShowHostFigureDropTextFeedback(new Point(e.X, e.Y)); } else if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; ShowHostFigureDropTextFeedback(new Point(e.X, e.Y)); } } } }; ret.DragLeave += (sender, e) => { /// feedbackを隠す Host.HideFeedback(new DropTextRequest(Rectangle.Empty)); }; ret.DragDrop += (sender, e) => { if (DragDropUtil.IsNone(e)) { return; } var data = e.Data; var loc = new Point(e.X, e.Y); var focus = Host.Focus as StyledTextFocus; if (data.GetDataPresent(typeof(MemoInfo[]))) { /// MemoInfo[] if (DragDropUtil.IsLink(e)) { Host.RequestSelect(SelectKind.True, true); Host.RequestFocus(FocusKind.Begin, loc); if (focus != null) { var infos = (MemoInfo[])data.GetData(typeof(MemoInfo[])); foreach (var info in infos) { var text = info.Title; var url = UriUtil.GetUri(info); var charIndex = focus.Referer.CaretIndex; focus.InsertText(text, false); /// set link focus.Selection.Range = new Range(charIndex, text.Length); focus.SetLink(url, null); focus.Selection.Range = Range.Empty; } } Host.HideFeedback(new DropTextRequest(Rectangle.Empty)); Host.Site.EditorCanvas.Select(); } } else if (data.GetDataPresent(StyledTextConsts.BlocksAndInlinesFormat.Name)) { /// StyledText flows if (DragDropUtil.IsCopy(e) || DragDropUtil.IsMove(e)) { Host.RequestSelect(SelectKind.True, true); Host.RequestFocus(FocusKind.Begin, loc); if (focus != null) { var flows = (IEnumerable <Flow>)data.GetData(StyledTextConsts.BlocksAndInlinesFormat.Name); focus.InsertBlocksAndInlines(flows); } Host.HideFeedback(new DropTextRequest(Rectangle.Empty)); Host.Site.EditorCanvas.Select(); } } else if (data.GetDataPresent("UniformResourceLocator") && data.GetDataPresent(DataFormats.UnicodeText)) { /// URL if (DragDropUtil.IsLink(e)) { Host.RequestSelect(SelectKind.True, true); Host.RequestFocus(FocusKind.Begin, loc); if (focus != null) { var charIndex = focus.Referer.CaretIndex; var url = (string)data.GetData(DataFormats.UnicodeText); var len = url.Length; focus.InsertText(url, false); /// set link focus.Selection.Range = new Range(charIndex, len); focus.SetLink(url, null); focus.Selection.Range = Range.Empty; } Host.HideFeedback(new DropTextRequest(Rectangle.Empty)); Host.Site.EditorCanvas.Select(); } } else if (data.GetDataPresent(DataFormats.UnicodeText)) { /// Text if (DragDropUtil.IsCopy(e) | DragDropUtil.IsMove(e)) { Host.RequestSelect(SelectKind.True, true); Host.RequestFocus(FocusKind.Begin, loc); if (focus != null) { focus.InsertText((string)data.GetData(DataFormats.UnicodeText), false); } Host.HideFeedback(new DropTextRequest(Rectangle.Empty)); Host.Site.EditorCanvas.Select(); } } }; return(ret); }
protected IDragTarget CreateFocusFigureDragTarget() { var ret = MouseOperatableFactory.CreateDragTarget(); ret.DragOver += (sender, e) => { e.Effect = DragDropEffects.None; var data = e.Data; if (data.GetDataPresent(typeof(MemoInfo[]))) { if (DragDropUtil.IsLinkAllowed(e)) { e.Effect = DragDropEffects.Link; ShowFocusFigureDropTextFeedback(new Point(e.X, e.Y)); } } else if (data.GetDataPresent(StyledTextConsts.BlocksAndInlinesFormat.Name)) { if (DragDropUtil.IsControlPressed(e)) { if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; ShowFocusFigureDropTextFeedback(new Point(e.X, e.Y)); } else { e.Effect = DragDropEffects.Move; ShowFocusFigureDropTextFeedback(new Point(e.X, e.Y)); } } else { if (DragDropUtil.IsMoveAllowed(e)) { e.Effect = DragDropEffects.Move; ShowFocusFigureDropTextFeedback(new Point(e.X, e.Y)); } else if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; ShowFocusFigureDropTextFeedback(new Point(e.X, e.Y)); } } } if (data.GetDataPresent("UniformResourceLocator") && data.GetDataPresent(DataFormats.UnicodeText)) { if (DragDropUtil.IsLinkAllowed(e)) { e.Effect = DragDropEffects.Link; ShowFocusFigureDropTextFeedback(new Point(e.X, e.Y)); } } else if (data.GetDataPresent(DataFormats.UnicodeText)) { if (DragDropUtil.IsControlPressed(e)) { if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; ShowFocusFigureDropTextFeedback(new Point(e.X, e.Y)); } else { e.Effect = DragDropEffects.Move; ShowFocusFigureDropTextFeedback(new Point(e.X, e.Y)); } } else { if (DragDropUtil.IsMoveAllowed(e)) { e.Effect = DragDropEffects.Move; ShowFocusFigureDropTextFeedback(new Point(e.X, e.Y)); } else if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; ShowFocusFigureDropTextFeedback(new Point(e.X, e.Y)); } } } }; ret.DragLeave += (sender, e) => { /// feedbackを隠す Host.HideFeedback(new DropTextRequest(Rectangle.Empty)); }; ret.DragDrop += (sender, e) => { if (DragDropUtil.IsNone(e)) { return; } var data = e.Data; var loc = new Point(e.X, e.Y); var focus = Host.Focus as StyledTextFocus; if (data.GetDataPresent(typeof(MemoInfo[]))) { if (DragDropUtil.IsLink(e)) { if (focus != null && Host.Figure.Root != null) { var infos = (MemoInfo[])data.GetData(typeof(MemoInfo[])); focus.Selection.Range = Range.Empty; var charIndex = focus.Figure.GetCharIndexAt(loc); foreach (var info in infos) { var text = info.Title; var url = UriUtil.GetUri(info); focus.Referer.CaretIndex = charIndex; focus.InsertText(text, false); /// set link focus.Selection.Range = new Range(charIndex, text.Length); focus.SetLink(url, null); focus.Selection.Range = Range.Empty; } } Host.HideFeedback(new DropTextRequest(Rectangle.Empty)); Host.Site.EditorCanvas.Select(); } } else if (data.GetDataPresent(StyledTextConsts.BlocksAndInlinesFormat.Name)) { /// StyledText flows if (DragDropUtil.IsCopy(e) || DragDropUtil.IsMove(e)) { if (focus != null && Host.Figure.Root != null) { var charIndex = focus.Figure.GetCharIndexAt(loc); if (!_selectionRangeOnDragStart.Contains(charIndex)) { /// Moveの場合はこのタイミングでremoveしてしまう。 /// DragFinishでやろうとすると大変。 if (!_selectionRangeOnDragStart.IsEmpty && DragDropUtil.IsMove(e)) { focus.RemoveForward(); } focus.Selection.Range = Range.Empty; if (charIndex >= _selectionRangeOnDragStart.End) { charIndex -= _selectionRangeOnDragStart.Length; } focus.Referer.CaretIndex = charIndex; var flows = (IEnumerable <Flow>)data.GetData(StyledTextConsts.BlocksAndInlinesFormat.Name); focus.InsertBlocksAndInlines(flows); } } Host.HideFeedback(new DropTextRequest(Rectangle.Empty)); Host.Site.EditorCanvas.Select(); } } else if (data.GetDataPresent("UniformResourceLocator") && data.GetDataPresent(DataFormats.UnicodeText)) { if (DragDropUtil.IsLink(e)) { if (focus != null && Host.Figure.Root != null) { focus.Selection.Range = Range.Empty; var url = (string)data.GetData(DataFormats.UnicodeText); var len = url.Length; var charIndex = focus.Figure.GetCharIndexAt(loc); focus.Referer.CaretIndex = charIndex; focus.InsertText(url, false); /// set link focus.Selection.Range = new Range(charIndex, len); focus.SetLink(url, null); focus.Selection.Range = Range.Empty; } Host.HideFeedback(new DropTextRequest(Rectangle.Empty)); Host.Site.EditorCanvas.Select(); } } else if (data.GetDataPresent(DataFormats.UnicodeText)) { if (DragDropUtil.IsCopy(e) || DragDropUtil.IsMove(e)) { if (focus != null && Host.Figure.Root != null) { focus.Selection.Range = Range.Empty; var charIndex = focus.Figure.GetCharIndexAt(loc); focus.Referer.CaretIndex = charIndex; var text = (string)data.GetData(DataFormats.UnicodeText); focus.InsertText(text, false); } Host.HideFeedback(new DropTextRequest(Rectangle.Empty)); Host.Site.EditorCanvas.Select(); } } }; return(ret); }
// ------------------------------ // private // ------------------------------ private IDragTarget CreateDragTarget() { var ret = MouseOperatableFactory.CreateDragTarget(); var app = MemopadApplication.Instance; ret.DragOver += (sender, e) => { e.Effect = DragDropEffects.None; var data = e.Data; if (data.GetDataPresent(typeof(MemoInfo[]))) { if (DragDropUtil.IsLinkAllowed(e)) { e.Effect = DragDropEffects.Link; } } else if (data.GetDataPresent(DataFormats.FileDrop)) { if (DragDropUtil.IsControlPressed(e)) { if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; } } else { if (DragDropUtil.IsLinkAllowed(e)) { e.Effect = DragDropEffects.Link; } } } else if (data.GetDataPresent(StyledTextConsts.BlocksAndInlinesFormat.Name)) { if (DragDropUtil.IsControlPressed(e)) { if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; } else if (DragDropUtil.IsMoveAllowed(e)) { e.Effect = DragDropEffects.Move; } } else { if (DragDropUtil.IsMoveAllowed(e)) { e.Effect = DragDropEffects.Move; } else if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; } } } else if (data.GetDataPresent(DataFormats.Html)) { if (DragDropUtil.IsControlPressed(e)) { if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; } else if (DragDropUtil.IsMoveAllowed(e)) { e.Effect = DragDropEffects.Move; } } else { if (DragDropUtil.IsMoveAllowed(e)) { e.Effect = DragDropEffects.Move; } else if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; } } } else if (data.GetDataPresent("UniformResourceLocator") && data.GetDataPresent(DataFormats.UnicodeText)) { if (DragDropUtil.IsLinkAllowed(e)) { e.Effect = DragDropEffects.Link; } } else if (data.GetDataPresent(DataFormats.UnicodeText)) { if (DragDropUtil.IsControlPressed(e)) { if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; } else if (DragDropUtil.IsMoveAllowed(e)) { e.Effect = DragDropEffects.Move; } } else { if (DragDropUtil.IsMoveAllowed(e)) { e.Effect = DragDropEffects.Move; } else if (DragDropUtil.IsCopyAllowed(e)) { e.Effect = DragDropEffects.Copy; } } } }; ret.DragDrop += (sender, e) => { if (DragDropUtil.IsNone(e)) { return; } var oldCursor = Host.Site.EditorCanvas.Cursor; Host.Site.EditorCanvas.Cursor = Cursors.WaitCursor; try { var data = e.Data; var loc = Host.Site.GridService.GetAdjustedPoint(new Point(e.X, e.Y)); if (data.GetDataPresent(typeof(MemoInfo[]))) { /// MemoInfo[] if (DragDropUtil.IsLink(e)) { var infos = (MemoInfo[])data.GetData(typeof(MemoInfo[])); foreach (var info in infos) { var text = info.Title; var uri = UriUtil.GetUri(info); var created = MemoEditorHelper.AddTextAsLink(Host, loc, text, uri, null); } Host.Site.EditorCanvas.Select(); } } else if (data.GetDataPresent(DataFormats.FileDrop)) { /// FileDrop if (DragDropUtil.IsCopy(e) || DragDropUtil.IsLink(e)) { MemoEditorHelper.AddFileDrops( Host, loc, (string[])data.GetData(DataFormats.FileDrop), e.Effect == DragDropEffects.Copy, true, false ); Host.Site.EditorCanvas.Select(); } } else if (data.GetDataPresent(StyledTextConsts.BlocksAndInlinesFormat.Name)) { /// StyledText flows if (DragDropUtil.IsCopy(e) || DragDropUtil.IsMove(e)) { MemoEditorHelper.AddBlocksAndInlines( Host, loc, data.GetData(StyledTextConsts.BlocksAndInlinesFormat.Name) as IEnumerable <Flow>, true ); Host.Site.EditorCanvas.Select(); } } else if (data.GetDataPresent(DataFormats.Html)) { /// Html if (DragDropUtil.IsCopy(e) || DragDropUtil.IsMove(e)) { var html = Common.Forms.Clipboard.ClipboardUtil.GetCFHtmlFromDataObject(data); MemoEditorHelper.AddHtml( Host, loc, html, true ); Host.Site.EditorCanvas.Select(); } } else if (data.GetDataPresent("UniformResourceLocator") && data.GetDataPresent(DataFormats.UnicodeText)) { /// URL if (DragDropUtil.IsLink(e)) { var url = (string)data.GetData(DataFormats.UnicodeText); var created = MemoEditorHelper.AddTextAsLink(Host, loc, url, url, null); Host.Site.EditorCanvas.Select(); } } else if (data.GetDataPresent(DataFormats.UnicodeText)) { /// text if (DragDropUtil.IsCopy(e) || DragDropUtil.IsMove(e)) { MemoEditorHelper.AddText(Host, loc, (string)data.GetData(DataFormats.UnicodeText), false); Host.Site.EditorCanvas.Select(); } } } finally { Host.Site.EditorCanvas.Cursor = oldCursor; } }; return(ret); }