plat/apple_mac_dnd.rs (Apple)#
Source: lib/plat/apple_mac_dnd.rs
apple_mac_dnd -- (dnd.rs) drag and drop on macOS: every window's view is a dragging destination;
drag_start drags the app's content out through a dragging session of the view
register(view) (win_create) registerForDraggedTypes: file URLs, URLs, text, HTML, PNG,
TIFF
the view's methods draggingEntered: / draggingUpdated: ask the UI (dnd::drag_query at the
point, px) and answer its effect; E_DRAG on enter and on every new
point, data 0 on draggingExited:; performDragOperation: reads only the
kinds the UI takes (file URLs as paths, text, HTML, other URLs, the PNG
or a TIFF as PNG), then E_DROP (data = the number of paths)
os_drag_start(data) (dnd.rs drag_start) remember the drag; wait() starts it (run_pending):
beginDraggingSessionWithItems:event:source: with the last left-button
event of a window (note_mouse). The session ends in
draggingSession:endedAtPoint:operation: -> E_DRAG_END (the effect) and
the E_UP the session took
writers(data) what a drag (and dnd_test_formats) puts on the pasteboard: an NSURL per
file, one NSPasteboardItem with the text (else the first URL), HTML, the
PNG (else one made of the BMP, and the BMP) and the URL; further URLs as
NSURLs
dnd_test_formats(data) / dnd_test_drop(data, w, x, y, mask) (plattest, no user) the writers on
a private pasteboard: its types and bytes; the view's destination
methods fed with it through a stand-in NSDraggingInfo (mask: the
NSDragOperation bits the source offers, as AppKit hands them on)
Effects: AppKit narrows the source's mask by the modifier keys itself (Option copy, Command move),
so the UI's pick gets no keys; NSDragOperationGeneric counts as a move. Everything a drop brings
is bounded by dnd.rs / clipdrop.rs (drop_add, drop_set_*).
fn dnd_test_formats(data: &DragData) -> Option<Vec<(String, Vec<u8>)>>(plattest) the pasteboard a drag of data fills: (type, bytes) of each item's typesfn dnd_test_drop(data: &DragData, w: i32, x: i32, y: i32, mask: u64) -> Option<u32>(plattest) a drop of data at px x, y of window w, the source offeringmask(NSDragOperation bits): draggingEntered:, draggingUpdated:, then performDragOperation: (or draggingExited: when refused) of the view, with a stand-in NSDraggingInfo -> the effect (0 refused); None: no window