plat/win_dnd.rs (Windows)#
Source: lib/plat/win_dnd.rs
win_dnd -- (dnd.rs) drag and drop through OLE: every window is an IDropTarget; DoDragDrop
drags the app's content out with our own IDataObject and IDropSource
register(hwnd, w) -> ok (win_create) OleInitialize once, RegisterDragDrop(hwnd, a target
of window w); false: no OLE on this thread (WM_DROPFILES stays)
revoke(hwnd) (WM_DESTROY) RevokeDragDrop (releases the target)
os_drag_start(data) (dnd.rs drag_start) remember the drag; wait() runs it
run_pending() (wait, top) DoDragDrop of the remembered drag. It is modal: the
UI keeps drawing from the source's QueryContinueDrag (the
wait_refresh closure, dnd_refresh) while events are queued, so
drop targets of the app highlight; then E_DRAG_END (the effect)
and E_UP for the buttons DoDragDrop swallowed
dnd_test_formats(data) / dnd_test_drop(data, w, x, y, keys) / dnd_test_source(esc, keys)
(plattest, no user) our IDataObject read as a drop target reads
it; our IDropTarget fed with it (DragEnter, DragOver, Drop);
the IDropSource's answers
dnd_test_drop_async(..) / dnd_test_async_end() (plattest) the same with a data object in
IDataObjectAsyncCapability's async mode, what EndOperation told it
Target: DragEnter asks the data object which formats it has (QueryGetData: CF_HDROP,
CF_UNICODETEXT / CF_TEXT, "HTML Format", "UniformResourceLocatorW" / "UniformResourceLocator" /
"text/x-moz-url", "PNG" / "image/png" / CF_DIBV5 / CF_DIB), asks the UI (dnd::drag_query with
the client point and MK_SHIFT / MK_CONTROL) and answers that effect; E_DRAG goes to the UI on
enter, on every new point and on leave. Drop reads only the kinds the UI takes (HGLOBAL
media, each at most 256 MiB): the paths of the DROPFILES block (parsed here, wide or ANSI),
text (UTF-16, else bytes), HTML (CF_HTML framing: clip_html_decode), URLs, the image (PNG, else
the DIB as a BMP file: clip_dib_to_bmp), then E_DROP (data = the number of paths). With
dnd::drop_hold on (the UI answers drops itself) and a source whose data object offers
IDataObjectAsyncCapability in async mode (GetAsyncMode TRUE), Drop calls StartOperation and keeps
the object: dnd::drop_finish ends it with EndOperation (S_OK and the effect; not taken: E_ABORT,
DROPEFFECT_NONE) -- the source learns the result after the drop, as Microsoft's "asynchronous data
extraction" has it. Every other source gets Drop's effect at once (IDropTarget::Drop must answer
synchronously); so does an async one when a newer drop comes first.
Source: the data object offers CF_UNICODETEXT (the text, else the URLs), CF_HDROP (DROPFILES,
wide absolute paths), "HTML Format", "UniformResourceLocatorW" + "UniformResourceLocator",
"PNG", CF_DIBV5 + CF_DIB (from DragData::bmp). GetData hands out a new HGLOBAL each time
(TYMED_HGLOBAL only), EnumFormatEtc goes through SHCreateStdEnumFmtEtc, SetData, GetDataHere
and advise sinks are refused. It offers IDataObjectAsyncCapability with async mode off for our
own drags (so targets extract synchronously, DoDragDrop's effect is the result); the tests turn
it on. ole32 / shell32 are loaded on the first window.
fn dnd_test_formats(data: &DragData) -> Option<Vec<(String, Vec<u8>)>>(plattest) our IDataObject ofdataread as a drop target reads it: EnumFormatEtc, then QueryGetData and GetData of every format -> (format name, bytes); None: no OLEfn dnd_test_drop(data: &DragData, w: i32, x: i32, y: i32, keys: u32) -> Option<u32>(plattest) a drop ofdataonto platform window w at client (x, y) as OLE would make it: DragEnter, DragOver, Drop of our IDropTarget with our IDataObject (MK_* keys) -> the effect of the drop (the E_DRAG / E_DROP events are queued, the content waits in drop_data_take); None: no OLEfn dnd_test_drop_async(data: &DragData, w: i32, x: i32, y: i32, keys: u32) -> Option<(u32, bool)>(plattest) dnd_test_drop with a data object in IDataObjectAsyncCapability's async mode (a source that lets the target answer after the drop) -> (the effect Drop answered, the object is in an operation the target started); the object is kept for dnd_test_async_end. None: no OLEfn dnd_test_async_end() -> Option<(bool, bool, i32, u32)>(plattest) the object of the last dnd_test_drop_async: (still in its operation, EndOperation came, its HRESULT, its effect); then it is released. None: there is nonefn dnd_test_source(esc: bool, keys: u32) -> u32(plattest) the IDropSource's answer to QueryContinueDrag(esc, MK_* keys): 0 go on, 1 drop, 2 cancel