Skip to main content

ferroui_base/input/raw/
raw_drag_event.rs

1use super::raw_input_event_args::raw_input_event_args;
2use super::{IDragDropDevice, RawDragEventType, RawInputEventArgs};
3use crate::input::{DragDropEffects, IDataTransfer, IInputRoot, KeyModifiers, RawInputModifiers};
4use crate::Point;
5use std::cell::Cell;
6use std::rc::Rc;
7
8/// A raw drag event: a drag-and-drop operation of the platform entering,
9/// moving over, leaving or dropping on an input root.
10///
11/// This is an implementation detail of the platform backends.
12pub struct RawDragEvent {
13    base: RawInputEventArgs,
14    location: Cell<Point>,
15    data_transfer: Rc<dyn IDataTransfer>,
16    effects: Cell<DragDropEffects>,
17    type_: RawDragEventType,
18    key_modifiers: KeyModifiers,
19}
20
21raw_input_event_args!(RawDragEvent: RawInputEventArgs);
22
23impl RawDragEvent {
24    /// Creates a raw drag event.
25    pub fn new(
26        input_device: Rc<dyn IDragDropDevice>,
27        type_: RawDragEventType,
28        root: Rc<dyn IInputRoot>,
29        location: Point,
30        data_transfer: Rc<dyn IDataTransfer>,
31        effects: DragDropEffects,
32        modifiers: RawInputModifiers,
33    ) -> Self {
34        Self {
35            base: RawInputEventArgs::new(input_device, 0, root),
36            location: Cell::new(location),
37            data_transfer,
38            effects: Cell::new(effects),
39            type_,
40            key_modifiers: modifiers.to_key_modifiers(),
41        }
42    }
43
44    /// The location of the pointer, in the coordinates of the root.
45    #[inline]
46    pub fn location(&self) -> Point {
47        self.location.get()
48    }
49
50    /// Sets the location of the pointer.
51    #[inline]
52    pub fn set_location(&self, value: Point) {
53        self.location.set(value)
54    }
55
56    /// The data being dragged.
57    #[inline]
58    pub fn data_transfer(&self) -> &Rc<dyn IDataTransfer> {
59        &self.data_transfer
60    }
61
62    /// The effects of the operation: the allowed effects when the event is
63    /// sent, the effects accepted by the target once it has been processed.
64    #[inline]
65    pub fn effects(&self) -> DragDropEffects {
66        self.effects.get()
67    }
68
69    /// Sets the effects of the operation.
70    #[inline]
71    pub fn set_effects(&self, value: DragDropEffects) {
72        self.effects.set(value)
73    }
74
75    /// The type of the event.
76    #[inline]
77    pub fn type_(&self) -> RawDragEventType {
78        self.type_
79    }
80
81    /// The key modifiers held down during the event.
82    #[inline]
83    pub fn key_modifiers(&self) -> KeyModifiers {
84        self.key_modifiers
85    }
86}