use super::{DataObject, DragResult};
use crate::prelude::WxWidget;
use wxdragon_sys as ffi;
pub struct DropSource {
ptr: *mut ffi::wxd_DropSource_t,
}
impl DropSource {
pub fn new<W: WxWidget>(window: &W) -> Self {
let ptr = unsafe { ffi::wxd_DropSource_Create(window.handle_ptr()) };
DropSource { ptr }
}
pub fn set_data<D: DataObject>(&self, data: &D) {
unsafe {
ffi::wxd_DropSource_SetData(self.ptr, data.as_data_object_ptr());
}
}
pub fn do_drag_drop(&self, allow_move: bool) -> DragResult {
let result: ffi::wxd_DragResult = unsafe { ffi::wxd_DropSource_DoDragDrop(self.ptr, allow_move) };
DragResult::from(result)
}
}
impl Drop for DropSource {
fn drop(&mut self) {
if !self.ptr.is_null() {
unsafe {
ffi::wxd_DropSource_Destroy(self.ptr);
}
self.ptr = std::ptr::null_mut();
}
}
}