1
0
Fork 0

Drop effect is now set based on EventStatus

This commit is contained in:
Jussi Viiri 2023-06-03 22:50:39 +03:00
parent 0eff674319
commit d8ffd4abc6
2 changed files with 36 additions and 11 deletions

View file

@ -98,6 +98,14 @@ pub enum Event {
Window(WindowEvent), Window(WindowEvent),
} }
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum DropEffect {
Copy,
Move,
Link,
Scroll,
}
/// Return value for [WindowHandler::on_event](`crate::WindowHandler::on_event()`), /// Return value for [WindowHandler::on_event](`crate::WindowHandler::on_event()`),
/// indicating whether the event was handled by your window or should be passed /// indicating whether the event was handled by your window or should be passed
/// back to the platform. /// back to the platform.
@ -117,4 +125,6 @@ pub enum EventStatus {
/// DAW functionality for playing piano keys with the keyboard while a /// DAW functionality for playing piano keys with the keyboard while a
/// plugin window is in focus. /// plugin window is in focus.
Ignored, Ignored,
// TODO: Document
AcceptDrop(DropEffect),
} }

View file

@ -7,7 +7,7 @@ use winapi::shared::winerror::{S_OK, E_NOINTERFACE};
use winapi::um::combaseapi::CoCreateGuid; use winapi::um::combaseapi::CoCreateGuid;
use winapi::um::objidl::IDataObject; use winapi::um::objidl::IDataObject;
use winapi::um::ole2::{RegisterDragDrop, OleInitialize}; use winapi::um::ole2::{RegisterDragDrop, OleInitialize};
use winapi::um::oleidl::{IDropTarget, IDropTargetVtbl, LPDROPTARGET, DROPEFFECT_COPY}; use winapi::um::oleidl::{IDropTarget, IDropTargetVtbl, LPDROPTARGET, DROPEFFECT_COPY, DROPEFFECT_NONE, DROPEFFECT_MOVE, DROPEFFECT_LINK, DROPEFFECT_SCROLL};
use winapi::um::unknwnbase::{IUnknownVtbl, IUnknown}; use winapi::um::unknwnbase::{IUnknownVtbl, IUnknown};
use winapi::um::winuser::{ use winapi::um::winuser::{
AdjustWindowRectEx, CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW, AdjustWindowRectEx, CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW,
@ -39,7 +39,7 @@ const BV_WINDOW_MUST_CLOSE: UINT = WM_USER + 1;
use crate::{ use crate::{
Event, MouseButton, MouseEvent, PhyPoint, PhySize, ScrollDelta, Size, WindowEvent, Event, MouseButton, MouseEvent, PhyPoint, PhySize, ScrollDelta, Size, WindowEvent,
WindowHandler, WindowInfo, WindowOpenOptions, WindowScalePolicy, WindowHandler, WindowInfo, WindowOpenOptions, WindowScalePolicy, DropEffect, EventStatus,
}; };
use super::keyboard::KeyboardState; use super::keyboard::KeyboardState;
@ -872,9 +872,14 @@ impl DropTarget {
let mut window = crate::Window::new(&mut window); let mut window = crate::Window::new(&mut window);
let event = Event::Mouse(MouseEvent::DragEntered {}); let event = Event::Mouse(MouseEvent::DragEntered {});
window_state.handler.borrow_mut().as_mut().unwrap().on_event(&mut window, event); let event_status = window_state.handler.borrow_mut().as_mut().unwrap().on_event(&mut window, event);
match event_status {
*pdwEffect = DROPEFFECT_COPY; EventStatus::AcceptDrop(DropEffect::Copy) => *pdwEffect = DROPEFFECT_COPY,
EventStatus::AcceptDrop(DropEffect::Move) => *pdwEffect = DROPEFFECT_MOVE,
EventStatus::AcceptDrop(DropEffect::Link) => *pdwEffect = DROPEFFECT_LINK,
EventStatus::AcceptDrop(DropEffect::Scroll) => *pdwEffect = DROPEFFECT_SCROLL,
_ => *pdwEffect = DROPEFFECT_NONE,
}
S_OK S_OK
} }
@ -892,9 +897,14 @@ impl DropTarget {
let mut window = crate::Window::new(&mut window); let mut window = crate::Window::new(&mut window);
let event = Event::Mouse(MouseEvent::DragMoved {}); let event = Event::Mouse(MouseEvent::DragMoved {});
window_state.handler.borrow_mut().as_mut().unwrap().on_event(&mut window, event); let event_status = window_state.handler.borrow_mut().as_mut().unwrap().on_event(&mut window, event);
match event_status {
*pdwEffect = DROPEFFECT_COPY; EventStatus::AcceptDrop(DropEffect::Copy) => *pdwEffect = DROPEFFECT_COPY,
EventStatus::AcceptDrop(DropEffect::Move) => *pdwEffect = DROPEFFECT_MOVE,
EventStatus::AcceptDrop(DropEffect::Link) => *pdwEffect = DROPEFFECT_LINK,
EventStatus::AcceptDrop(DropEffect::Scroll) => *pdwEffect = DROPEFFECT_SCROLL,
_ => *pdwEffect = DROPEFFECT_NONE,
}
S_OK S_OK
} }
@ -926,9 +936,14 @@ impl DropTarget {
let mut window = crate::Window::new(&mut window); let mut window = crate::Window::new(&mut window);
let event = Event::Mouse(MouseEvent::DragDropped {}); let event = Event::Mouse(MouseEvent::DragDropped {});
window_state.handler.borrow_mut().as_mut().unwrap().on_event(&mut window, event); let event_status = window_state.handler.borrow_mut().as_mut().unwrap().on_event(&mut window, event);
match event_status {
*pdwEffect = DROPEFFECT_COPY; EventStatus::AcceptDrop(DropEffect::Copy) => *pdwEffect = DROPEFFECT_COPY,
EventStatus::AcceptDrop(DropEffect::Move) => *pdwEffect = DROPEFFECT_MOVE,
EventStatus::AcceptDrop(DropEffect::Link) => *pdwEffect = DROPEFFECT_LINK,
EventStatus::AcceptDrop(DropEffect::Scroll) => *pdwEffect = DROPEFFECT_SCROLL,
_ => *pdwEffect = DROPEFFECT_NONE,
}
S_OK S_OK
} }