1use glib::translate::*;
6use pango_sys;
7use AttrIterator;
8use Attribute;
9
10glib_wrapper! {
11 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
12 pub struct AttrList(Shared<pango_sys::PangoAttrList>);
13
14 match fn {
15 ref => |ptr| pango_sys::pango_attr_list_ref(ptr),
16 unref => |ptr| pango_sys::pango_attr_list_unref(ptr),
17 get_type => || pango_sys::pango_attr_list_get_type(),
18 }
19}
20
21impl AttrList {
22 pub fn new() -> AttrList {
23 unsafe { from_glib_full(pango_sys::pango_attr_list_new()) }
24 }
25
26 pub fn copy(&self) -> Option<AttrList> {
27 unsafe { from_glib_full(pango_sys::pango_attr_list_copy(self.to_glib_none().0)) }
28 }
29
30 pub fn filter<P: FnMut(&Attribute) -> bool>(&self, func: P) -> Option<AttrList> {
31 let func_data: P = func;
32 unsafe extern "C" fn func_func<P: FnMut(&Attribute) -> bool>(
33 attribute: *mut pango_sys::PangoAttribute,
34 user_data: glib_sys::gpointer,
35 ) -> glib_sys::gboolean {
36 let attribute = from_glib_borrow(attribute);
37 let callback: *mut P = user_data as *const _ as usize as *mut P;
38 let res = (*callback)(&attribute);
39 res.to_glib()
40 }
41 let func = Some(func_func::<P> as _);
42 let super_callback0: &P = &func_data;
43 unsafe {
44 from_glib_full(pango_sys::pango_attr_list_filter(
45 self.to_glib_none().0,
46 func,
47 super_callback0 as *const _ as usize as *mut _,
48 ))
49 }
50 }
51
52 pub fn get_iterator(&self) -> Option<AttrIterator> {
53 unsafe {
54 from_glib_full(pango_sys::pango_attr_list_get_iterator(
55 self.to_glib_none().0,
56 ))
57 }
58 }
59
60 pub fn splice(&self, other: &AttrList, pos: i32, len: i32) {
61 unsafe {
62 pango_sys::pango_attr_list_splice(
63 self.to_glib_none().0,
64 other.to_glib_none().0,
65 pos,
66 len,
67 );
68 }
69 }
70}
71
72impl Default for AttrList {
73 fn default() -> Self {
74 Self::new()
75 }
76}