Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Problem about Drag & Drop #6

Closed
ZaltaisHornblend opened this issue May 7, 2015 · 9 comments
Closed

Problem about Drag & Drop #6

ZaltaisHornblend opened this issue May 7, 2015 · 9 comments

Comments

@ZaltaisHornblend
Copy link

Hello,
I use ScintillaNet and I would like to implement a drag & drop between TreeView and Scintilla.

I developed ItemDrag event for TreeView and DragEnter and DragDrop events for ScintillaNet.
I have verified that the "allowdrop" property is true.
But my problem is that the DragDrop event does not fire.
I do not know what to try...

Thank you for your help.

ps : sorry for my English

@jacobslusser
Copy link
Owner

I haven't specifically implemented Drag & Drop in ScintillaNET v3 yet and based on your experience, it doesn't look like we're getting it for free from Windows Forms. Let me investigate and get back to you.

@jacobslusser
Copy link
Owner

So I'm looking into this a bit and I don't seem to have any problems dragging items from a TreeView to ScintillaNET.

Is the issue that you can't drag items from the TreeView to ScintillaNET? Or is the issue that some of the events are not firing?

@ZaltaisHornblend
Copy link
Author

Thank you for your answers.

My issue is that DragEnter event and DragDrop event does not fire.
With visual studio I debug my application and I see that the ItemDrag event fires but not the other two.
After taking a node in the TreeView and I move my mouse in the control ScintillaNet nothing happens. The mouse cursor tells me I can not. I took a screenshot to be more clear.

scintilladragdrop

I know the Drag & Drop event is inherited from Windows.Forms and I don't understand why it's not working.
my code :

// TreeView ItemDrag
private void treeView1_ItemDrag(object sender, ItemDragEventArgs e) {
treeView1.DoDragDrop(e.Item, DragDropEffects.All);
}

// ScintillaNET events
private void scintilla1_DragEnter(object sender, DragEventArgs e) {
e.Effect = DragDropEffects.Copy;
}

private void scintilla1_DragDrop(object sender, DragEventArgs e) {
if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
{
scintilla1.Text = scintilla1.Text.Insert(1, ((TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode")).Text);
}
}

@ZaltaisHornblend
Copy link
Author

I just do some additional tests. I just noticed that the problem is not the Drag & Drop.
Indeed, I tried to implement the click event and other event and they too do not fire.

So the origin of my issue is elsewhere... Something has to interfere with the correct operation of ScintillaNET. Any ideas ?

I'll get ... and I hope to find.

Thank you for your time. I appreciate.

@jacobslusser
Copy link
Owner

Try:

private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
{
    treeView1.DoDragDrop(((TreeNode)e.Item).Text, DragDropEffects.Copy);
}

I have a pretty good idea why the Drag events aren't firing as you expect, but this should get you what you want for now.

BTW - Scintilla events are different from standard Windows Forms control events. Version 3 of ScintillaNET tries to recognize and accept that fact. It isn't a standard Windows Forms control so we shouldn't treat it as such. That being said, I'll see what I can do. :)

@jacobslusser
Copy link
Owner

I remember fixing this exact issue in ScintillaNET v2.x so I knew where to look. The issue is that the native Scintilla control automatically registers itself as a drag and drop target before the Windows Forms framework does. The result is that the native Scintilla control handles the drag and drop events instead of raising the Windows Forms DragEnter, DragDrop, etc... events. The fix I decided to go with was to revoke drag and drop support after the native Scintilla control is created but before the Windows Forms framework does registration so that Windows Forms still thinks it is the first one to the party when it registers the control.

Unfortunately this means the built-in support that the native Scintilla control already has is no longer being used. It puts a larger burden on ScintillaNET developers to handle the drag and drop events, but it allows more flexibility and so I think it's the right thing to do.

@ZaltaisHornblend
Copy link
Author

Okay I understand your explanation.

I tried your code and changed my event as you have indicated above me. Now my Drag & Drop works well.

Thank you for the solution and for your time. :)
The Scintilla project is impressive. 👍

@jacobslusser
Copy link
Owner

P.S. Commit 02336ec adds support for CharPositionFromPoint[Close], PointXFromPosition, and PointYFromPosition methods which make it possible to convert mouse coordinates to document positions and vice versa.

This should help you identify the proper document and caret position in your drag and drop operations.

@ZaltaisHornblend
Copy link
Author

These methods save my life, thank you ! :)

GerHobbelt pushed a commit to GerHobbelt/ScintillaNET that referenced this issue Nov 13, 2021
…tion

Update types in the SCNotification struct
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants