gtk4/subclass/
tree_drag_dest.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3// rustdoc-stripper-ignore-next
4//! Traits intended for implementing the [`TreeDragDest`] interface.
5
6use glib::{translate::*, Value};
7
8use crate::{ffi, prelude::*, subclass::prelude::*, TreeDragDest, TreePath};
9
10#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
11#[allow(deprecated)]
12pub trait TreeDragDestImpl: ObjectImpl + ObjectSubclass<Type: IsA<TreeDragDest>> {
13    fn drag_data_received(&self, dest: &TreePath, value: Value) -> bool;
14    fn row_drop_possible(&self, dest: &TreePath, value: Value) -> bool;
15}
16
17#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
18#[allow(deprecated)]
19pub trait TreeDragDestImplExt: TreeDragDestImpl {
20    fn parent_drag_data_received(&self, dest: &TreePath, value: Value) -> bool {
21        unsafe {
22            let type_data = Self::type_data();
23            let parent_iface = type_data.as_ref().parent_interface::<TreeDragDest>()
24                as *const ffi::GtkTreeDragDestIface;
25
26            let func = (*parent_iface)
27                .drag_data_received
28                .expect("no parent \"drag_data_received\" implementation");
29
30            from_glib(func(
31                self.obj()
32                    .unsafe_cast_ref::<TreeDragDest>()
33                    .to_glib_none()
34                    .0,
35                mut_override(dest.to_glib_none().0),
36                value.to_glib_none().0,
37            ))
38        }
39    }
40
41    fn parent_row_drop_possible(&self, dest: &TreePath, value: Value) -> bool {
42        unsafe {
43            let type_data = Self::type_data();
44            let parent_iface = type_data.as_ref().parent_interface::<TreeDragDest>()
45                as *const ffi::GtkTreeDragDestIface;
46
47            let func = (*parent_iface)
48                .drag_data_received
49                .expect("no parent \"drag_data_received\" implementation");
50
51            from_glib(func(
52                self.obj()
53                    .unsafe_cast_ref::<TreeDragDest>()
54                    .to_glib_none()
55                    .0,
56                mut_override(dest.to_glib_none().0),
57                value.to_glib_none().0,
58            ))
59        }
60    }
61}
62
63impl<T: TreeDragDestImpl> TreeDragDestImplExt for T {}
64
65unsafe impl<T: TreeDragDestImpl> IsImplementable<T> for TreeDragDest {
66    fn interface_init(iface: &mut glib::Interface<Self>) {
67        let iface = iface.as_mut();
68
69        assert_initialized_main_thread!();
70
71        iface.drag_data_received = Some(tree_drag_dest_drag_data_received::<T>);
72        iface.row_drop_possible = Some(tree_drag_dest_row_drop_possible::<T>);
73    }
74}
75
76unsafe extern "C" fn tree_drag_dest_drag_data_received<T: TreeDragDestImpl>(
77    tree_drag_dest: *mut ffi::GtkTreeDragDest,
78    destptr: *mut ffi::GtkTreePath,
79    valueptr: *const glib::gobject_ffi::GValue,
80) -> glib::ffi::gboolean {
81    let instance = &*(tree_drag_dest as *mut T::Instance);
82    let imp = instance.imp();
83
84    let dest: Borrowed<TreePath> = from_glib_borrow(destptr);
85    let value: Value = from_glib_none(valueptr);
86
87    imp.drag_data_received(&dest, value).into_glib()
88}
89
90unsafe extern "C" fn tree_drag_dest_row_drop_possible<T: TreeDragDestImpl>(
91    tree_drag_dest: *mut ffi::GtkTreeDragDest,
92    destptr: *mut ffi::GtkTreePath,
93    valueptr: *const glib::gobject_ffi::GValue,
94) -> glib::ffi::gboolean {
95    let instance = &*(tree_drag_dest as *mut T::Instance);
96    let imp = instance.imp();
97    let dest: Borrowed<TreePath> = from_glib_borrow(destptr);
98    let value: Value = from_glib_none(valueptr);
99
100    imp.row_drop_possible(&dest, value).into_glib()
101}