Run rustfmt (#154)
This commit is contained in:
parent
d8e3b52acd
commit
d08f7afd49
|
@ -1,3 +1,3 @@
|
||||||
fn_args_layout = "Compressed"
|
fn_params_layout = "Compressed"
|
||||||
use_small_heuristics = "Max"
|
use_small_heuristics = "Max"
|
||||||
use_field_init_shorthand = true
|
use_field_init_shorthand = true
|
||||||
|
|
|
@ -5,9 +5,8 @@ mod window;
|
||||||
use cocoa::foundation::NSUInteger;
|
use cocoa::foundation::NSUInteger;
|
||||||
pub use window::*;
|
pub use window::*;
|
||||||
|
|
||||||
const NSDragOperationNone: NSUInteger = 0;
|
const NSDragOperationNone: NSUInteger = 0;
|
||||||
const NSDragOperationCopy: NSUInteger = 1;
|
const NSDragOperationCopy: NSUInteger = 1;
|
||||||
const NSDragOperationLink: NSUInteger = 2;
|
const NSDragOperationLink: NSUInteger = 2;
|
||||||
const NSDragOperationGeneric: NSUInteger = 4;
|
const NSDragOperationGeneric: NSUInteger = 4;
|
||||||
const NSDragOperationMove: NSUInteger = 16;
|
const NSDragOperationMove: NSUInteger = 16;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::ffi::c_void;
|
use std::ffi::c_void;
|
||||||
|
|
||||||
use cocoa::appkit::{NSEvent, NSView, NSWindow, NSFilenamesPboardType};
|
use cocoa::appkit::{NSEvent, NSFilenamesPboardType, NSView, NSWindow};
|
||||||
use cocoa::base::{id, nil, BOOL, NO, YES};
|
use cocoa::base::{id, nil, BOOL, NO, YES};
|
||||||
use cocoa::foundation::{NSArray, NSPoint, NSRect, NSSize, NSUInteger};
|
use cocoa::foundation::{NSArray, NSPoint, NSRect, NSSize, NSUInteger};
|
||||||
|
|
||||||
|
@ -15,13 +15,16 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use crate::MouseEvent::{ButtonPressed, ButtonReleased};
|
use crate::MouseEvent::{ButtonPressed, ButtonReleased};
|
||||||
use crate::{
|
use crate::{
|
||||||
Event, EventStatus, MouseButton, MouseEvent, Point, ScrollDelta, Size, WindowEvent, WindowInfo,
|
DropData, DropEffect, Event, EventStatus, MouseButton, MouseEvent, Point, ScrollDelta, Size,
|
||||||
WindowOpenOptions, DropData, DropEffect,
|
WindowEvent, WindowInfo, WindowOpenOptions,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{NSDragOperationGeneric, NSDragOperationCopy, NSDragOperationMove, NSDragOperationLink, NSDragOperationNone};
|
use super::keyboard::{from_nsstring, make_modifiers};
|
||||||
use super::keyboard::{make_modifiers, from_nsstring};
|
|
||||||
use super::window::WindowState;
|
use super::window::WindowState;
|
||||||
|
use super::{
|
||||||
|
NSDragOperationCopy, NSDragOperationGeneric, NSDragOperationLink, NSDragOperationMove,
|
||||||
|
NSDragOperationNone,
|
||||||
|
};
|
||||||
|
|
||||||
/// Name of the field used to store the `WindowState` pointer.
|
/// Name of the field used to store the `WindowState` pointer.
|
||||||
pub(super) const BASEVIEW_STATE_IVAR: &str = "baseview_state";
|
pub(super) const BASEVIEW_STATE_IVAR: &str = "baseview_state";
|
||||||
|
@ -106,7 +109,10 @@ pub(super) unsafe fn create_view(window_options: &WindowOpenOptions) -> id {
|
||||||
|
|
||||||
view.initWithFrame_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(size.width, size.height)));
|
view.initWithFrame_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(size.width, size.height)));
|
||||||
|
|
||||||
let _: id = msg_send![view, registerForDraggedTypes: NSArray::arrayWithObjects(nil, &[NSFilenamesPboardType])];
|
let _: id = msg_send![
|
||||||
|
view,
|
||||||
|
registerForDraggedTypes: NSArray::arrayWithObjects(nil, &[NSFilenamesPboardType])
|
||||||
|
];
|
||||||
|
|
||||||
view
|
view
|
||||||
}
|
}
|
||||||
|
@ -173,10 +179,7 @@ unsafe fn create_view_class() -> &'static Class {
|
||||||
sel!(draggingUpdated:),
|
sel!(draggingUpdated:),
|
||||||
dragging_updated as extern "C" fn(&Object, Sel, id) -> NSUInteger,
|
dragging_updated as extern "C" fn(&Object, Sel, id) -> NSUInteger,
|
||||||
);
|
);
|
||||||
class.add_method(
|
class.add_method(sel!(draggingExited:), dragging_exited as extern "C" fn(&Object, Sel, id));
|
||||||
sel!(draggingExited:),
|
|
||||||
dragging_exited as extern "C" fn(&Object, Sel, id),
|
|
||||||
);
|
|
||||||
|
|
||||||
add_mouse_button_class_method!(class, mouseDown, ButtonPressed, MouseButton::Left);
|
add_mouse_button_class_method!(class, mouseDown, ButtonPressed, MouseButton::Left);
|
||||||
add_mouse_button_class_method!(class, mouseUp, ButtonReleased, MouseButton::Left);
|
add_mouse_button_class_method!(class, mouseUp, ButtonReleased, MouseButton::Left);
|
||||||
|
|
|
@ -2,31 +2,51 @@ use std::ffi::OsString;
|
||||||
use std::mem::transmute;
|
use std::mem::transmute;
|
||||||
use std::os::windows::prelude::OsStringExt;
|
use std::os::windows::prelude::OsStringExt;
|
||||||
use std::ptr::null_mut;
|
use std::ptr::null_mut;
|
||||||
use std::rc::{Weak, Rc};
|
use std::rc::{Rc, Weak};
|
||||||
|
|
||||||
use winapi::Interface;
|
use winapi::shared::guiddef::{IsEqualIID, REFIID};
|
||||||
use winapi::shared::guiddef::{REFIID, IsEqualIID};
|
|
||||||
use winapi::shared::minwindef::{DWORD, WPARAM};
|
use winapi::shared::minwindef::{DWORD, WPARAM};
|
||||||
use winapi::shared::ntdef::{HRESULT, ULONG};
|
use winapi::shared::ntdef::{HRESULT, ULONG};
|
||||||
use winapi::shared::windef::POINTL;
|
use winapi::shared::windef::POINTL;
|
||||||
use winapi::shared::winerror::{S_OK, E_NOINTERFACE, E_UNEXPECTED};
|
use winapi::shared::winerror::{E_NOINTERFACE, E_UNEXPECTED, S_OK};
|
||||||
use winapi::shared::wtypes::DVASPECT_CONTENT;
|
use winapi::shared::wtypes::DVASPECT_CONTENT;
|
||||||
use winapi::um::objidl::{IDataObject, FORMATETC, TYMED_HGLOBAL, STGMEDIUM};
|
use winapi::um::objidl::{IDataObject, FORMATETC, STGMEDIUM, TYMED_HGLOBAL};
|
||||||
use winapi::um::oleidl::{IDropTarget, IDropTargetVtbl, DROPEFFECT_COPY, DROPEFFECT_MOVE, DROPEFFECT_LINK, DROPEFFECT_SCROLL, DROPEFFECT_NONE};
|
use winapi::um::oleidl::{
|
||||||
|
IDropTarget, IDropTargetVtbl, DROPEFFECT_COPY, DROPEFFECT_LINK, DROPEFFECT_MOVE,
|
||||||
|
DROPEFFECT_NONE, DROPEFFECT_SCROLL,
|
||||||
|
};
|
||||||
use winapi::um::shellapi::DragQueryFileW;
|
use winapi::um::shellapi::DragQueryFileW;
|
||||||
use winapi::um::unknwnbase::{IUnknownVtbl, IUnknown};
|
use winapi::um::unknwnbase::{IUnknown, IUnknownVtbl};
|
||||||
use winapi::um::winuser::CF_HDROP;
|
use winapi::um::winuser::CF_HDROP;
|
||||||
|
use winapi::Interface;
|
||||||
|
|
||||||
use crate::{Point, DropData, MouseEvent, Event, EventStatus, DropEffect, PhyPoint};
|
use crate::{DropData, DropEffect, Event, EventStatus, MouseEvent, PhyPoint, Point};
|
||||||
|
|
||||||
use super::WindowState;
|
use super::WindowState;
|
||||||
|
|
||||||
// These function pointers have to be stored in a (const) variable before they can be transmuted
|
// These function pointers have to be stored in a (const) variable before they can be transmuted
|
||||||
// Transmuting is needed because winapi has a bug where the pt parameter has an incorrect
|
// Transmuting is needed because winapi has a bug where the pt parameter has an incorrect
|
||||||
// type `*const POINTL`
|
// type `*const POINTL`
|
||||||
const DRAG_ENTER_PTR: unsafe extern "system" fn(this: *mut IDropTarget, pDataObj: *const IDataObject, grfKeyState: DWORD, pt: POINTL, pdwEffect: *mut DWORD) -> HRESULT = DropTarget::drag_enter;
|
const DRAG_ENTER_PTR: unsafe extern "system" fn(
|
||||||
const DRAG_OVER_PTR: unsafe extern "system" fn(this: *mut IDropTarget, grfKeyState: DWORD, pt: POINTL, pdwEffect: *mut DWORD) -> HRESULT = DropTarget::drag_over;
|
this: *mut IDropTarget,
|
||||||
const DROP_PTR: unsafe extern "system" fn(this: *mut IDropTarget, pDataObj: *const IDataObject, grfKeyState: DWORD, pt: POINTL, pdwEffect: *mut DWORD) -> HRESULT = DropTarget::drop;
|
pDataObj: *const IDataObject,
|
||||||
|
grfKeyState: DWORD,
|
||||||
|
pt: POINTL,
|
||||||
|
pdwEffect: *mut DWORD,
|
||||||
|
) -> HRESULT = DropTarget::drag_enter;
|
||||||
|
const DRAG_OVER_PTR: unsafe extern "system" fn(
|
||||||
|
this: *mut IDropTarget,
|
||||||
|
grfKeyState: DWORD,
|
||||||
|
pt: POINTL,
|
||||||
|
pdwEffect: *mut DWORD,
|
||||||
|
) -> HRESULT = DropTarget::drag_over;
|
||||||
|
const DROP_PTR: unsafe extern "system" fn(
|
||||||
|
this: *mut IDropTarget,
|
||||||
|
pDataObj: *const IDataObject,
|
||||||
|
grfKeyState: DWORD,
|
||||||
|
pt: POINTL,
|
||||||
|
pdwEffect: *mut DWORD,
|
||||||
|
) -> HRESULT = DropTarget::drop;
|
||||||
const DROP_TARGET_VTBL: IDropTargetVtbl = IDropTargetVtbl {
|
const DROP_TARGET_VTBL: IDropTargetVtbl = IDropTargetVtbl {
|
||||||
parent: IUnknownVtbl {
|
parent: IUnknownVtbl {
|
||||||
QueryInterface: DropTarget::query_interface,
|
QueryInterface: DropTarget::query_interface,
|
||||||
|
@ -73,7 +93,8 @@ impl DropTarget {
|
||||||
let mut window = crate::Window::new(&mut window);
|
let mut window = crate::Window::new(&mut window);
|
||||||
|
|
||||||
let event = Event::Mouse(event);
|
let event = Event::Mouse(event);
|
||||||
let event_status = window_state.handler_mut().as_mut().unwrap().on_event(&mut window, event);
|
let event_status =
|
||||||
|
window_state.handler_mut().as_mut().unwrap().on_event(&mut window, event);
|
||||||
|
|
||||||
if let Some(pdwEffect) = pdwEffect {
|
if let Some(pdwEffect) = pdwEffect {
|
||||||
match event_status {
|
match event_status {
|
||||||
|
@ -105,11 +126,7 @@ impl DropTarget {
|
||||||
tymed: TYMED_HGLOBAL,
|
tymed: TYMED_HGLOBAL,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut medium = STGMEDIUM {
|
let mut medium = STGMEDIUM { tymed: 0, u: null_mut(), pUnkForRelease: null_mut() };
|
||||||
tymed: 0,
|
|
||||||
u: null_mut(),
|
|
||||||
pUnkForRelease: null_mut(),
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let hresult = data_object.GetData(&format, &mut medium);
|
let hresult = data_object.GetData(&format, &mut medium);
|
||||||
|
@ -133,7 +150,12 @@ impl DropTarget {
|
||||||
let buffer_size = characters as usize + 1;
|
let buffer_size = characters as usize + 1;
|
||||||
let mut buffer = Vec::<u16>::with_capacity(buffer_size);
|
let mut buffer = Vec::<u16>::with_capacity(buffer_size);
|
||||||
|
|
||||||
DragQueryFileW(hdrop, i, transmute(buffer.spare_capacity_mut().as_mut_ptr()), buffer_size as u32);
|
DragQueryFileW(
|
||||||
|
hdrop,
|
||||||
|
i,
|
||||||
|
transmute(buffer.spare_capacity_mut().as_mut_ptr()),
|
||||||
|
buffer_size as u32,
|
||||||
|
);
|
||||||
buffer.set_len(buffer_size);
|
buffer.set_len(buffer_size);
|
||||||
|
|
||||||
paths.push(OsString::from_wide(&buffer[..characters as usize]).into())
|
paths.push(OsString::from_wide(&buffer[..characters as usize]).into())
|
||||||
|
@ -144,12 +166,9 @@ impl DropTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "system" fn query_interface(
|
unsafe extern "system" fn query_interface(
|
||||||
this: *mut IUnknown,
|
this: *mut IUnknown, riid: REFIID, ppvObject: *mut *mut winapi::ctypes::c_void,
|
||||||
riid: REFIID,
|
) -> HRESULT {
|
||||||
ppvObject: *mut *mut winapi::ctypes::c_void,
|
if IsEqualIID(&*riid, &IUnknown::uuidof()) || IsEqualIID(&*riid, &IDropTarget::uuidof()) {
|
||||||
) -> HRESULT
|
|
||||||
{
|
|
||||||
if IsEqualIID(&*riid, &IUnknown::uuidof()) || IsEqualIID(&*riid, &IDropTarget::uuidof()){
|
|
||||||
Self::add_ref(this);
|
Self::add_ref(this);
|
||||||
*ppvObject = this as *mut winapi::ctypes::c_void;
|
*ppvObject = this as *mut winapi::ctypes::c_void;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
@ -179,19 +198,16 @@ impl DropTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "system" fn drag_enter(
|
unsafe extern "system" fn drag_enter(
|
||||||
this: *mut IDropTarget,
|
this: *mut IDropTarget, pDataObj: *const IDataObject, grfKeyState: DWORD, pt: POINTL,
|
||||||
pDataObj: *const IDataObject,
|
|
||||||
grfKeyState: DWORD,
|
|
||||||
pt: POINTL,
|
|
||||||
pdwEffect: *mut DWORD,
|
pdwEffect: *mut DWORD,
|
||||||
) -> HRESULT
|
) -> HRESULT {
|
||||||
{
|
|
||||||
let drop_target = &mut *(this as *mut DropTarget);
|
let drop_target = &mut *(this as *mut DropTarget);
|
||||||
let Some(window_state) = drop_target.window_state.upgrade() else {
|
let Some(window_state) = drop_target.window_state.upgrade() else {
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
};
|
};
|
||||||
|
|
||||||
let modifiers = window_state.keyboard_state().get_modifiers_from_mouse_wparam(grfKeyState as WPARAM);
|
let modifiers =
|
||||||
|
window_state.keyboard_state().get_modifiers_from_mouse_wparam(grfKeyState as WPARAM);
|
||||||
|
|
||||||
drop_target.parse_coordinates(pt);
|
drop_target.parse_coordinates(pt);
|
||||||
drop_target.parse_drop_data(&*pDataObj);
|
drop_target.parse_drop_data(&*pDataObj);
|
||||||
|
@ -207,18 +223,15 @@ impl DropTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "system" fn drag_over(
|
unsafe extern "system" fn drag_over(
|
||||||
this: *mut IDropTarget,
|
this: *mut IDropTarget, grfKeyState: DWORD, pt: POINTL, pdwEffect: *mut DWORD,
|
||||||
grfKeyState: DWORD,
|
) -> HRESULT {
|
||||||
pt: POINTL,
|
|
||||||
pdwEffect: *mut DWORD,
|
|
||||||
) -> HRESULT
|
|
||||||
{
|
|
||||||
let drop_target = &mut *(this as *mut DropTarget);
|
let drop_target = &mut *(this as *mut DropTarget);
|
||||||
let Some(window_state) = drop_target.window_state.upgrade() else {
|
let Some(window_state) = drop_target.window_state.upgrade() else {
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
};
|
};
|
||||||
|
|
||||||
let modifiers = window_state.keyboard_state().get_modifiers_from_mouse_wparam(grfKeyState as WPARAM);
|
let modifiers =
|
||||||
|
window_state.keyboard_state().get_modifiers_from_mouse_wparam(grfKeyState as WPARAM);
|
||||||
|
|
||||||
drop_target.parse_coordinates(pt);
|
drop_target.parse_coordinates(pt);
|
||||||
|
|
||||||
|
@ -239,19 +252,16 @@ impl DropTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "system" fn drop(
|
unsafe extern "system" fn drop(
|
||||||
this: *mut IDropTarget,
|
this: *mut IDropTarget, pDataObj: *const IDataObject, grfKeyState: DWORD, pt: POINTL,
|
||||||
pDataObj: *const IDataObject,
|
|
||||||
grfKeyState: DWORD,
|
|
||||||
pt: POINTL,
|
|
||||||
pdwEffect: *mut DWORD,
|
pdwEffect: *mut DWORD,
|
||||||
) -> HRESULT
|
) -> HRESULT {
|
||||||
{
|
|
||||||
let drop_target = &mut *(this as *mut DropTarget);
|
let drop_target = &mut *(this as *mut DropTarget);
|
||||||
let Some(window_state) = drop_target.window_state.upgrade() else {
|
let Some(window_state) = drop_target.window_state.upgrade() else {
|
||||||
return E_UNEXPECTED;
|
return E_UNEXPECTED;
|
||||||
};
|
};
|
||||||
|
|
||||||
let modifiers = window_state.keyboard_state().get_modifiers_from_mouse_wparam(grfKeyState as WPARAM);
|
let modifiers =
|
||||||
|
window_state.keyboard_state().get_modifiers_from_mouse_wparam(grfKeyState as WPARAM);
|
||||||
|
|
||||||
drop_target.parse_coordinates(pt);
|
drop_target.parse_coordinates(pt);
|
||||||
drop_target.parse_drop_data(&*pDataObj);
|
drop_target.parse_drop_data(&*pDataObj);
|
||||||
|
|
|
@ -2,7 +2,7 @@ use winapi::shared::guiddef::GUID;
|
||||||
use winapi::shared::minwindef::{ATOM, FALSE, LPARAM, LRESULT, UINT, WPARAM};
|
use winapi::shared::minwindef::{ATOM, FALSE, LPARAM, LRESULT, UINT, WPARAM};
|
||||||
use winapi::shared::windef::{HWND, RECT};
|
use winapi::shared::windef::{HWND, RECT};
|
||||||
use winapi::um::combaseapi::CoCreateGuid;
|
use winapi::um::combaseapi::CoCreateGuid;
|
||||||
use winapi::um::ole2::{RegisterDragDrop, OleInitialize, RevokeDragDrop};
|
use winapi::um::ole2::{OleInitialize, RegisterDragDrop, RevokeDragDrop};
|
||||||
use winapi::um::oleidl::LPDROPTARGET;
|
use winapi::um::oleidl::LPDROPTARGET;
|
||||||
use winapi::um::winuser::{
|
use winapi::um::winuser::{
|
||||||
AdjustWindowRectEx, CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW,
|
AdjustWindowRectEx, CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW,
|
||||||
|
@ -18,7 +18,7 @@ use winapi::um::winuser::{
|
||||||
XBUTTON1, XBUTTON2,
|
XBUTTON1, XBUTTON2,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::cell::{Cell, RefCell, Ref, RefMut};
|
use std::cell::{Cell, Ref, RefCell, RefMut};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::ffi::{c_void, OsStr};
|
use std::ffi::{c_void, OsStr};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
Loading…
Reference in a new issue