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

use crate::Gravity;
use crate::PopupLayout;
use crate::Surface;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    #[doc(alias = "GdkPopup")]
    pub struct Popup(Interface<ffi::GdkPopup, ffi::GdkPopupInterface>) @requires Surface;

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

pub const NONE_POPUP: Option<&Popup> = None;

pub trait PopupExt: 'static {
    #[doc(alias = "gdk_popup_get_autohide")]
    #[doc(alias = "get_autohide")]
    fn is_autohide(&self) -> bool;

    #[doc(alias = "gdk_popup_get_parent")]
    #[doc(alias = "get_parent")]
    fn parent(&self) -> Option<Surface>;

    #[doc(alias = "gdk_popup_get_position_x")]
    #[doc(alias = "get_position_x")]
    fn position_x(&self) -> i32;

    #[doc(alias = "gdk_popup_get_position_y")]
    #[doc(alias = "get_position_y")]
    fn position_y(&self) -> i32;

    #[doc(alias = "gdk_popup_get_rect_anchor")]
    #[doc(alias = "get_rect_anchor")]
    fn rect_anchor(&self) -> Gravity;

    #[doc(alias = "gdk_popup_get_surface_anchor")]
    #[doc(alias = "get_surface_anchor")]
    fn surface_anchor(&self) -> Gravity;

    #[doc(alias = "gdk_popup_present")]
    fn present(&self, width: i32, height: i32, layout: &PopupLayout) -> bool;
}

impl<O: IsA<Popup>> PopupExt for O {
    fn is_autohide(&self) -> bool {
        unsafe { from_glib(ffi::gdk_popup_get_autohide(self.as_ref().to_glib_none().0)) }
    }

    fn parent(&self) -> Option<Surface> {
        unsafe { from_glib_none(ffi::gdk_popup_get_parent(self.as_ref().to_glib_none().0)) }
    }

    fn position_x(&self) -> i32 {
        unsafe { ffi::gdk_popup_get_position_x(self.as_ref().to_glib_none().0) }
    }

    fn position_y(&self) -> i32 {
        unsafe { ffi::gdk_popup_get_position_y(self.as_ref().to_glib_none().0) }
    }

    fn rect_anchor(&self) -> Gravity {
        unsafe {
            from_glib(ffi::gdk_popup_get_rect_anchor(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn surface_anchor(&self) -> Gravity {
        unsafe {
            from_glib(ffi::gdk_popup_get_surface_anchor(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn present(&self, width: i32, height: i32, layout: &PopupLayout) -> bool {
        unsafe {
            from_glib(ffi::gdk_popup_present(
                self.as_ref().to_glib_none().0,
                width,
                height,
                layout.to_glib_none().0,
            ))
        }
    }
}

impl fmt::Display for Popup {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Popup")
    }
}
