Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding a drag & drop event #496

Closed
thelink2012 opened this issue Jun 21, 2015 · 7 comments
Closed

Consider adding a drag & drop event #496

thelink2012 opened this issue Jun 21, 2015 · 7 comments

Comments

@thelink2012
Copy link
Contributor

GLFW as of 3.1 provides a callback to queue dropped files and afaik SDL2 also has such event.

@mitchmindtree
Copy link
Contributor

Just an update: It looks like this event has been added, but is only implemented for the win32 api so far.

@mitchmindtree
Copy link
Contributor

mitchmindtree commented Jun 24, 2016

I've been looking into how to get this working for cocoa.

In order to receive drag events, cocoa requires implementing the NSDraggingDestination protocol. It seems this involves subclassing NSWindow and then implementing the performDragOperation method which gets called when a drag is released over the window. We could use this callback to add an event to the VecDeque of pending_events. I found a simple example of implementing the NSDraggingDestination protocol in obj c here.

Once implemented, we will have to register the window as a dragging destination for the specific types of files that we can want to handle (in our case, all of them). To do this, we have to call the registerForDraggedTypes method on our window after we have created it and ensured that it is non_nil. This will probably look something like this:

// Register the window as a dragging destination for creating `DroppedFile` events.
msg_send![*window, registerForDraggedTypes:NSArray::arrayWithObject(nil, appkit::NSFilenamesPboardType)];

@mitchmindtree
Copy link
Contributor

The cocoa API supports handling multiple dropped files at once. When this occurs, we could either:

  • emit multiple DroppedFile events or
  • change DroppedFile(PathBuf) to DroppedFile(Vec<PathBuf>)

The second option might be useful for applications that need to know when multiple files are dropped at once though would be a breaking change. The first option is probably simplest to implement in the meantime.

bors-servo pushed a commit to servo/cocoa-rs that referenced this issue Jun 24, 2016
Add missing "Types for Standard Data" constants.

This adds bindings to cocoa's "Types for Standard Data". I believe these are necessary for registering an `NSDraggingDestination` as a receiver for certain kinds of data types.

Here are the cocoa references for:
- [Types for Standard Data (OS X v10.6 and later)](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSPasteboard_Class/#//apple_ref/doc/constant_group/Types_for_Standard_Data_OS_X_v10.6_and_later_)
- [Types for Standard Data (OS X v10.5 and earlier)](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSPasteboard_Class/#//apple_ref/doc/constant_group/Types_for_Standard_Data_OS_X_v10.5_and_earlier_)

Relevant to rust-windowing/glutin#496

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/cocoa-rs/133)
<!-- Reviewable:end -->
@thelink2012
Copy link
Contributor Author

As a side note, Win32 also supports the event of many files at once (and that's what's used in my impl), however I still opted for triggering many events, seems less intrusive imo.

@retep998
Copy link
Contributor

It is possible to support more advanced drag and drop, where the window receives notification of the thing being dragged onto it before it is dropped. This allows for visual feedback to be displayed to the user, such as displaying where the dropped thing will be inserted or whether dropping is allowed.

https://msdn.microsoft.com/en-us/library/windows/desktop/bb776905(v=vs.85).aspx

@retep998
Copy link
Contributor

retep998 commented Jul 11, 2016

Also for the record the current Windows implementation only accepts paths that can fit in[u16; winapi::MAX_PATH], which is actually rather small because MAX_PATH is only 255 while in reality paths can be up to 32767 long.

@tomaka
Copy link
Contributor

tomaka commented Nov 3, 2016

Closing for rust-windowing/winit#44

@tomaka tomaka closed this as completed Nov 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants