Skip to content

Commit

Permalink
Add keyboard modifiers to drag events
Browse files Browse the repository at this point in the history
Remove fields from DragLeft
  • Loading branch information
ilmai committed Jun 5, 2023
1 parent e9a1460 commit fe03957
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
14 changes: 10 additions & 4 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
Expand Down
23 changes: 16 additions & 7 deletions src/win/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};

Expand All @@ -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(),
};

Expand All @@ -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
}

Expand All @@ -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(),
};

Expand Down

0 comments on commit fe03957

Please sign in to comment.