// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::{ViewStackPage, ffi};
use glib::{
    prelude::*,
    signal::{SignalHandlerId, connect_raw},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "AdwViewStackPages")]
    pub struct ViewStackPages(Object<ffi::AdwViewStackPages, ffi::AdwViewStackPagesClass>) @implements gio::ListModel, gtk::SelectionModel;

    match fn {
        type_ => || ffi::adw_view_stack_pages_get_type(),
    }
}

impl ViewStackPages {
    #[doc(alias = "adw_view_stack_pages_get_selected_page")]
    #[doc(alias = "get_selected_page")]
    #[doc(alias = "selected-page")]
    pub fn selected_page(&self) -> Option<ViewStackPage> {
        unsafe {
            from_glib_none(ffi::adw_view_stack_pages_get_selected_page(
                self.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "adw_view_stack_pages_set_selected_page")]
    #[doc(alias = "selected-page")]
    pub fn set_selected_page(&self, page: &ViewStackPage) {
        unsafe {
            ffi::adw_view_stack_pages_set_selected_page(
                self.to_glib_none().0,
                page.to_glib_none().0,
            );
        }
    }

    #[cfg(feature = "v1_4")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
    #[doc(alias = "selected-page")]
    pub fn connect_selected_page_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_selected_page_trampoline<F: Fn(&ViewStackPages) + 'static>(
            this: *mut ffi::AdwViewStackPages,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"notify::selected-page".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_selected_page_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}
