1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
use crate::subclass::prelude::*;
use crate::{TreeDragDest, TreePath};
use glib::translate::*;
use glib::{Cast, Value};
pub trait TreeDragDestImpl: ObjectImpl {
fn drag_data_received(
&self,
tree_drag_dest: &Self::Type,
dest: &TreePath,
value: Value,
) -> bool;
fn row_drop_possible(&self, tree_drag_dest: &Self::Type, dest: &TreePath, value: Value)
-> bool;
}
pub trait TreeDragDestImplExt: ObjectSubclass {
fn parent_drag_data_received(
&self,
tree_drag_dest: &Self::Type,
dest: &TreePath,
value: Value,
) -> bool;
fn parent_row_drop_possible(
&self,
tree_drag_dest: &Self::Type,
dest: &TreePath,
value: Value,
) -> bool;
}
impl<T: TreeDragDestImpl> TreeDragDestImplExt for T {
fn parent_drag_data_received(
&self,
tree_drag_dest: &Self::Type,
dest: &TreePath,
value: Value,
) -> bool {
unsafe {
let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<TreeDragDest>()
as *const ffi::GtkTreeDragDestIface;
let func = (*parent_iface)
.drag_data_received
.expect("no parent \"drag_data_received\" implementation");
from_glib(func(
tree_drag_dest
.unsafe_cast_ref::<TreeDragDest>()
.to_glib_none()
.0,
mut_override(dest.to_glib_none().0),
value.to_glib_none().0,
))
}
}
fn parent_row_drop_possible(
&self,
tree_drag_dest: &Self::Type,
dest: &TreePath,
value: Value,
) -> bool {
unsafe {
let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<TreeDragDest>()
as *const ffi::GtkTreeDragDestIface;
let func = (*parent_iface)
.drag_data_received
.expect("no parent \"drag_data_received\" implementation");
from_glib(func(
tree_drag_dest
.unsafe_cast_ref::<TreeDragDest>()
.to_glib_none()
.0,
mut_override(dest.to_glib_none().0),
value.to_glib_none().0,
))
}
}
}
unsafe impl<T: TreeDragDestImpl> IsImplementable<T> for TreeDragDest {
fn interface_init(iface: &mut glib::Interface<Self>) {
let iface = iface.as_mut();
assert!(
crate::rt::is_initialized(),
"GTK has to be initialized first"
);
iface.drag_data_received = Some(tree_drag_dest_drag_data_received::<T>);
iface.row_drop_possible = Some(tree_drag_dest_row_drop_possible::<T>);
}
}
unsafe extern "C" fn tree_drag_dest_drag_data_received<T: TreeDragDestImpl>(
tree_drag_dest: *mut ffi::GtkTreeDragDest,
destptr: *mut ffi::GtkTreePath,
valueptr: *const glib::gobject_ffi::GValue,
) -> glib::ffi::gboolean {
let instance = &*(tree_drag_dest as *mut T::Instance);
let imp = instance.imp();
let dest: Borrowed<TreePath> = from_glib_borrow(destptr);
let value: Value = from_glib_none(valueptr);
imp.drag_data_received(
from_glib_borrow::<_, TreeDragDest>(tree_drag_dest).unsafe_cast_ref(),
&dest,
value,
)
.into_glib()
}
unsafe extern "C" fn tree_drag_dest_row_drop_possible<T: TreeDragDestImpl>(
tree_drag_dest: *mut ffi::GtkTreeDragDest,
destptr: *mut ffi::GtkTreePath,
valueptr: *const glib::gobject_ffi::GValue,
) -> glib::ffi::gboolean {
let instance = &*(tree_drag_dest as *mut T::Instance);
let imp = instance.imp();
let dest: Borrowed<TreePath> = from_glib_borrow(destptr);
let value: Value = from_glib_none(valueptr);
imp.row_drop_possible(
from_glib_borrow::<_, TreeDragDest>(tree_drag_dest).unsafe_cast_ref(),
&dest,
value,
)
.into_glib()
}