From fe03957514aec10f206be9f64ff227598e589a74 Mon Sep 17 00:00:00 2001 From: Jussi Viiri Date: Mon, 5 Jun 2023 21:00:19 +0300 Subject: [PATCH] Add keyboard modifiers to drag events Remove fields from DragLeft --- src/event.rs | 14 ++++++++++---- src/win/window.rs | 23 ++++++++++++++++------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/event.rs b/src/event.rs index c3882e8..f83a75e 100644 --- a/src/event.rs +++ b/src/event.rs @@ -80,22 +80,28 @@ pub enum MouseEvent { // TODO: Document DragEntered { + /// The logical coordinates of the mouse position position: Point, + /// The modifiers that were held down just before the event. + modifiers: Modifiers, data: DropData, }, DragMoved { + /// The logical coordinates of the mouse position position: Point, + /// The modifiers that were held down just before the event. + modifiers: Modifiers, data: DropData, }, - DragLeft { - position: Point, - data: DropData, - }, + DragLeft, DragDropped { + /// The logical coordinates of the mouse position position: Point, + /// The modifiers that were held down just before the event. + modifiers: Modifiers, data: DropData, }, } diff --git a/src/win/window.rs b/src/win/window.rs index 71045c2..8efac98 100644 --- a/src/win/window.rs +++ b/src/win/window.rs @@ -958,12 +958,17 @@ impl DropTarget { ) -> HRESULT { let drop_target = &mut *(this as *mut DropTarget); + let window_state = unsafe { &*drop_target.window_state }; drop_target.parse_coordinates(pt); drop_target.parse_drop_data(&*pDataObj); let event = MouseEvent::DragEntered { position: drop_target.drag_position, + modifiers: window_state + .keyboard_state + .borrow() + .get_modifiers_from_mouse_wparam(grfKeyState as WPARAM), data: drop_target.drop_data.clone(), }; @@ -979,11 +984,16 @@ impl DropTarget { ) -> HRESULT { let drop_target = &mut *(this as *mut DropTarget); + let window_state = unsafe { &*drop_target.window_state }; drop_target.parse_coordinates(pt); let event = MouseEvent::DragMoved { position: drop_target.drag_position, + modifiers: window_state + .keyboard_state + .borrow() + .get_modifiers_from_mouse_wparam(grfKeyState as WPARAM), data: drop_target.drop_data.clone(), }; @@ -993,13 +1003,7 @@ impl DropTarget { unsafe extern "system" fn drag_leave(this: *mut IDropTarget) -> HRESULT { let drop_target = &mut *(this as *mut DropTarget); - - let event = MouseEvent::DragLeft { - position: drop_target.drag_position, - data: drop_target.drop_data.clone(), - }; - - drop_target.on_event(None, event); + drop_target.on_event(None, MouseEvent::DragLeft); S_OK } @@ -1012,12 +1016,17 @@ impl DropTarget { ) -> HRESULT { let drop_target = &mut *(this as *mut DropTarget); + let window_state = unsafe { &*drop_target.window_state }; drop_target.parse_coordinates(pt); drop_target.parse_drop_data(&*pDataObj); let event = MouseEvent::DragDropped { position: drop_target.drag_position, + modifiers: window_state + .keyboard_state + .borrow() + .get_modifiers_from_mouse_wparam(grfKeyState as WPARAM), data: drop_target.drop_data.clone(), };