window_clipboard/dnd/
mod.rs
1use std::borrow::Cow;
2
3use ::dnd::{DndAction, DndDestinationRectangle, Sender};
4use dnd::{DndSurface, Icon};
5use mime::{AllowedMimeTypes, AsMimeTypes};
6
7pub trait DndProvider {
8 fn init_dnd(
10 &self,
11 _tx: Box<dyn dnd::Sender<DndSurface> + Send + Sync + 'static>,
12 ) {
13 }
14
15 fn start_dnd<D: AsMimeTypes + Send + 'static>(
17 &self,
18 _internal: bool,
19 _source_surface: DndSurface,
20 _icon_surface: Option<Icon>,
21 _content: D,
22 _actions: DndAction,
23 ) {
24 }
25
26 fn end_dnd(&self) {}
28
29 fn register_dnd_destination(
34 &self,
35 _surface: DndSurface,
36 _rectangles: Vec<DndDestinationRectangle>,
37 ) {
38 }
39
40 fn set_action(&self, _action: DndAction) {}
42
43 fn peek_offer<D: AllowedMimeTypes + 'static>(
45 &self,
46 _mime_type: Option<Cow<'static, str>>,
47 ) -> std::io::Result<D> {
48 Err(std::io::Error::new(
49 std::io::ErrorKind::Other,
50 "DnD not supported",
51 ))
52 }
53}
54
55impl<C: DndProvider> DndProvider for crate::PlatformClipboard<C> {
56 fn init_dnd(
57 &self,
58 tx: Box<dyn Sender<DndSurface> + Send + Sync + 'static>,
59 ) {
60 self.raw.init_dnd(tx);
61 }
62
63 fn start_dnd<D: AsMimeTypes + Send + 'static>(
64 &self,
65 internal: bool,
66 source_surface: DndSurface,
67 icon_surface: Option<Icon>,
68 content: D,
69 actions: DndAction,
70 ) {
71 self.raw.start_dnd(
72 internal,
73 source_surface,
74 icon_surface,
75 content,
76 actions,
77 );
78 }
79
80 fn end_dnd(&self) {
81 self.raw.end_dnd();
82 }
83
84 fn register_dnd_destination(
85 &self,
86 surface: DndSurface,
87 rectangles: Vec<DndDestinationRectangle>,
88 ) {
89 self.raw.register_dnd_destination(surface, rectangles);
90 }
91
92 fn set_action(&self, action: DndAction) {
93 self.raw.set_action(action);
94 }
95
96 fn peek_offer<D: AllowedMimeTypes + 'static>(
97 &self,
98 mime_type: Option<Cow<'static, str>>,
99 ) -> std::io::Result<D> {
100 self.raw.peek_offer::<D>(mime_type)
101 }
102}