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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{ResponseType, Window};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// Native dialogs are platform dialogs that don't use [`Dialog`][crate::Dialog].
///
/// They are used in order to integrate better with a platform, by
/// looking the same as other native applications and supporting
/// platform specific features.
///
/// The [`Dialog`][crate::Dialog] functions cannot be used on such objects,
/// but we need a similar API in order to drive them. The [`NativeDialog`][crate::NativeDialog]
/// object is an API that allows you to do this. It allows you to set
/// various common properties on the dialog, as well as show and hide
/// it and get a [`response`][struct@crate::NativeDialog#response] signal when the user
/// finished with the dialog.
///
/// Note that unlike [`Dialog`][crate::Dialog], [`NativeDialog`][crate::NativeDialog] objects are not
/// toplevel widgets, and GTK does not keep them alive. It is your
/// responsibility to keep a reference until you are done with the
/// object.
///
/// This is an Abstract Base Class, you cannot instantiate it.
///
/// ## Properties
///
///
/// #### `modal`
/// Whether the window should be modal with respect to its transient parent.
///
/// Readable | Writeable
///
///
/// #### `title`
/// The title of the dialog window
///
/// Readable | Writeable
///
///
/// #### `transient-for`
/// The transient parent of the dialog, or [`None`] for none.
///
/// Readable | Writeable | Construct
///
///
/// #### `visible`
/// Whether the window is currently visible.
///
/// Readable | Writeable
///
/// ## Signals
///
///
/// #### `response`
/// Emitted when the user responds to the dialog.
///
/// When this is called the dialog has been hidden.
///
/// If you call [`NativeDialogExt::hide()`][crate::prelude::NativeDialogExt::hide()] before the user
/// responds to the dialog this signal will not be emitted.
///
///
///
/// # Implements
///
/// [`NativeDialogExt`][trait@crate::prelude::NativeDialogExt], [`trait@glib::ObjectExt`], [`NativeDialogExtManual`][trait@crate::prelude::NativeDialogExtManual]
#[doc(alias = "GtkNativeDialog")]
pub struct NativeDialog(Object<ffi::GtkNativeDialog, ffi::GtkNativeDialogClass>);
match fn {
type_ => || ffi::gtk_native_dialog_get_type(),
}
}
impl NativeDialog {
pub const NONE: Option<&'static NativeDialog> = None;
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::NativeDialog>> Sealed for T {}
}
/// Trait containing all [`struct@NativeDialog`] methods.
///
/// # Implementors
///
/// [`FileChooserNative`][struct@crate::FileChooserNative], [`NativeDialog`][struct@crate::NativeDialog]
pub trait NativeDialogExt: IsA<NativeDialog> + sealed::Sealed + 'static {
#[doc(alias = "gtk_native_dialog_destroy")]
fn destroy(&self) {
unsafe {
ffi::gtk_native_dialog_destroy(self.as_ref().to_glib_none().0);
}
}
/// Returns whether the dialog is modal.
///
/// # Returns
///
/// [`true`] if the dialog is set to be modal
#[doc(alias = "gtk_native_dialog_get_modal")]
#[doc(alias = "get_modal")]
fn is_modal(&self) -> bool {
unsafe {
from_glib(ffi::gtk_native_dialog_get_modal(
self.as_ref().to_glib_none().0,
))
}
}
/// Gets the title of the [`NativeDialog`][crate::NativeDialog].
///
/// # Returns
///
/// the title of the dialog, or [`None`] if none has
/// been set explicitly. The returned string is owned by the widget
/// and must not be modified or freed.
#[doc(alias = "gtk_native_dialog_get_title")]
#[doc(alias = "get_title")]
fn title(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::gtk_native_dialog_get_title(
self.as_ref().to_glib_none().0,
))
}
}
/// Fetches the transient parent for this window.
///
/// # Returns
///
/// the transient parent for this window,
/// or [`None`] if no transient parent has been set.
#[doc(alias = "gtk_native_dialog_get_transient_for")]
#[doc(alias = "get_transient_for")]
fn transient_for(&self) -> Option<Window> {
unsafe {
from_glib_none(ffi::gtk_native_dialog_get_transient_for(
self.as_ref().to_glib_none().0,
))
}
}
/// Determines whether the dialog is visible.
///
/// # Returns
///
/// [`true`] if the dialog is visible
#[doc(alias = "gtk_native_dialog_get_visible")]
#[doc(alias = "get_visible")]
fn is_visible(&self) -> bool {
unsafe {
from_glib(ffi::gtk_native_dialog_get_visible(
self.as_ref().to_glib_none().0,
))
}
}
/// Hides the dialog if it is visible, aborting any interaction.
///
/// Once this is called the [`response`][struct@crate::NativeDialog#response] signal
/// will *not* be emitted until after the next call to
/// [`show()`][Self::show()].
///
/// If the dialog is not visible this does nothing.
#[doc(alias = "gtk_native_dialog_hide")]
fn hide(&self) {
unsafe {
ffi::gtk_native_dialog_hide(self.as_ref().to_glib_none().0);
}
}
/// Sets a dialog modal or non-modal.
///
/// Modal dialogs prevent interaction with other windows in the same
/// application. To keep modal dialogs on top of main application
/// windows, use [`set_transient_for()`][Self::set_transient_for()] to make
/// the dialog transient for the parent; most window managers will
/// then disallow lowering the dialog below the parent.
/// ## `modal`
/// whether the window is modal
#[doc(alias = "gtk_native_dialog_set_modal")]
fn set_modal(&self, modal: bool) {
unsafe {
ffi::gtk_native_dialog_set_modal(self.as_ref().to_glib_none().0, modal.into_glib());
}
}
/// Sets the title of the [`NativeDialog`][crate::NativeDialog]
/// ## `title`
/// title of the dialog
#[doc(alias = "gtk_native_dialog_set_title")]
fn set_title(&self, title: &str) {
unsafe {
ffi::gtk_native_dialog_set_title(
self.as_ref().to_glib_none().0,
title.to_glib_none().0,
);
}
}
/// Dialog windows should be set transient for the main application
/// window they were spawned from.
///
/// This allows window managers to e.g. keep the dialog on top of the
/// main window, or center the dialog over the main window.
///
/// Passing [`None`] for @parent unsets the current transient window.
/// ## `parent`
/// parent window
#[doc(alias = "gtk_native_dialog_set_transient_for")]
fn set_transient_for(&self, parent: Option<&impl IsA<Window>>) {
unsafe {
ffi::gtk_native_dialog_set_transient_for(
self.as_ref().to_glib_none().0,
parent.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
/// Shows the dialog on the display.
///
/// When the user accepts the state of the dialog the dialog will
/// be automatically hidden and the [`response`][struct@crate::NativeDialog#response]
/// signal will be emitted.
///
/// Multiple calls while the dialog is visible will be ignored.
#[doc(alias = "gtk_native_dialog_show")]
fn show(&self) {
unsafe {
ffi::gtk_native_dialog_show(self.as_ref().to_glib_none().0);
}
}
/// Whether the window is currently visible.
fn set_visible(&self, visible: bool) {
ObjectExt::set_property(self.as_ref(), "visible", visible)
}
/// Emitted when the user responds to the dialog.
///
/// When this is called the dialog has been hidden.
///
/// If you call [`hide()`][Self::hide()] before the user
/// responds to the dialog this signal will not be emitted.
/// ## `response_id`
/// the response ID
#[doc(alias = "response")]
fn connect_response<F: Fn(&Self, ResponseType) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn response_trampoline<
P: IsA<NativeDialog>,
F: Fn(&P, ResponseType) + 'static,
>(
this: *mut ffi::GtkNativeDialog,
response_id: ffi::GtkResponseType,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
NativeDialog::from_glib_borrow(this).unsafe_cast_ref(),
from_glib(response_id),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"response\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
response_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "modal")]
fn connect_modal_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_modal_trampoline<P: IsA<NativeDialog>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkNativeDialog,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::modal\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_modal_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "title")]
fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_title_trampoline<P: IsA<NativeDialog>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkNativeDialog,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::title\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_title_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "transient-for")]
fn connect_transient_for_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_transient_for_trampoline<
P: IsA<NativeDialog>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkNativeDialog,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::transient-for\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_transient_for_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "visible")]
fn connect_visible_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_visible_trampoline<
P: IsA<NativeDialog>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkNativeDialog,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(NativeDialog::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::visible\0".as_ptr() as *const _,
Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
notify_visible_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<NativeDialog>> NativeDialogExt for O {}