@@ -3,6 +3,8 @@ use std::os::windows::ffi::OsStringExt;
3
3
use std:: path:: PathBuf ;
4
4
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
5
5
use std:: { mem, ptr} ;
6
+ use std:: rc:: Rc ;
7
+ use std:: cell:: RefCell ;
6
8
7
9
use winapi:: ctypes:: c_void;
8
10
use winapi:: shared:: guiddef:: REFIID ;
@@ -14,7 +16,6 @@ use winapi::um::oleidl::{IDropTarget, IDropTargetVtbl};
14
16
use winapi:: um:: winnt:: HRESULT ;
15
17
use winapi:: um:: { shellapi, unknwnbase} ;
16
18
17
- use platform:: platform:: events_loop:: send_event;
18
19
use platform:: platform:: WindowId ;
19
20
20
21
use { Event , WindowId as SuperWindowId } ;
@@ -24,6 +25,7 @@ pub struct FileDropHandlerData {
24
25
pub interface : IDropTarget ,
25
26
refcount : AtomicUsize ,
26
27
window : HWND ,
28
+ event_queue : Rc < RefCell < Vec < Event > > > ,
27
29
}
28
30
29
31
pub struct FileDropHandler {
@@ -32,13 +34,14 @@ pub struct FileDropHandler {
32
34
33
35
#[ allow( non_snake_case) ]
34
36
impl FileDropHandler {
35
- pub fn new ( window : HWND ) -> FileDropHandler {
37
+ pub fn new ( window : HWND , event_queue : Rc < RefCell < Vec < Event > > > ) -> FileDropHandler {
36
38
let data = Box :: new ( FileDropHandlerData {
37
39
interface : IDropTarget {
38
40
lpVtbl : & DROP_TARGET_VTBL as * const IDropTargetVtbl ,
39
41
} ,
40
42
refcount : AtomicUsize :: new ( 1 ) ,
41
43
window,
44
+ event_queue,
42
45
} ) ;
43
46
FileDropHandler {
44
47
data : Box :: into_raw ( data) ,
@@ -82,7 +85,7 @@ impl FileDropHandler {
82
85
use events:: WindowEvent :: HoveredFile ;
83
86
let drop_handler = Self :: from_interface ( this) ;
84
87
Self :: iterate_filenames ( pDataObj, |filename| {
85
- send_event ( Event :: WindowEvent {
88
+ drop_handler . send_event ( Event :: WindowEvent {
86
89
window_id : SuperWindowId ( WindowId ( drop_handler. window ) ) ,
87
90
event : HoveredFile ( filename) ,
88
91
} ) ;
@@ -103,7 +106,7 @@ impl FileDropHandler {
103
106
pub unsafe extern "system" fn DragLeave ( this : * mut IDropTarget ) -> HRESULT {
104
107
use events:: WindowEvent :: HoveredFileCancelled ;
105
108
let drop_handler = Self :: from_interface ( this) ;
106
- send_event ( Event :: WindowEvent {
109
+ drop_handler . send_event ( Event :: WindowEvent {
107
110
window_id : SuperWindowId ( WindowId ( drop_handler. window ) ) ,
108
111
event : HoveredFileCancelled ,
109
112
} ) ;
@@ -121,7 +124,7 @@ impl FileDropHandler {
121
124
use events:: WindowEvent :: DroppedFile ;
122
125
let drop_handler = Self :: from_interface ( this) ;
123
126
let hdrop = Self :: iterate_filenames ( pDataObj, |filename| {
124
- send_event ( Event :: WindowEvent {
127
+ drop_handler . send_event ( Event :: WindowEvent {
125
128
window_id : SuperWindowId ( WindowId ( drop_handler. window ) ) ,
126
129
event : DroppedFile ( filename) ,
127
130
} ) ;
@@ -182,6 +185,12 @@ impl FileDropHandler {
182
185
}
183
186
}
184
187
188
+ impl FileDropHandlerData {
189
+ fn send_event ( & self , event : Event ) {
190
+ self . event_queue . borrow_mut ( ) . push ( event) ;
191
+ }
192
+ }
193
+
185
194
impl Drop for FileDropHandler {
186
195
fn drop ( & mut self ) {
187
196
unsafe {
0 commit comments