Skip to main content

gtk/auto/
functions.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6    AccelGroup, Orientation, PageSetup, PositionType, PrintSettings, SelectionData, StyleContext,
7    TextBuffer, TextDirection, TreeModel, TreePath, Widget, Window,
8};
9use glib::{prelude::*, translate::*};
10use std::{boxed::Box as Box_, mem, ptr};
11
12/// Finds the first accelerator in any [`AccelGroup`][crate::AccelGroup] attached
13/// to `object` that matches `accel_key` and `accel_mods`, and
14/// activates that accelerator.
15/// ## `object`
16/// the [`glib::Object`][crate::glib::Object], usually a [`Window`][crate::Window], on which
17///  to activate the accelerator
18/// ## `accel_key`
19/// accelerator keyval from a key event
20/// ## `accel_mods`
21/// keyboard state mask from a key event
22///
23/// # Returns
24///
25/// [`true`] if an accelerator was activated and handled
26///  this keypress
27#[doc(alias = "gtk_accel_groups_activate")]
28pub fn accel_groups_activate(
29    object: &impl IsA<glib::Object>,
30    accel_key: u32,
31    accel_mods: gdk::ModifierType,
32) -> bool {
33    assert_initialized_main_thread!();
34    unsafe {
35        from_glib(ffi::gtk_accel_groups_activate(
36            object.as_ref().to_glib_none().0,
37            accel_key,
38            accel_mods.into_glib(),
39        ))
40    }
41}
42
43/// Gets a list of all accel groups which are attached to `object`.
44/// ## `object`
45/// a [`glib::Object`][crate::glib::Object], usually a [`Window`][crate::Window]
46///
47/// # Returns
48///
49/// a list of
50///  all accel groups which are attached to `object`
51#[doc(alias = "gtk_accel_groups_from_object")]
52pub fn accel_groups_from_object(object: &impl IsA<glib::Object>) -> Vec<AccelGroup> {
53    assert_initialized_main_thread!();
54    unsafe {
55        FromGlibPtrContainer::from_glib_none(ffi::gtk_accel_groups_from_object(
56            object.as_ref().to_glib_none().0,
57        ))
58    }
59}
60
61/// Gets the modifier mask.
62///
63/// The modifier mask determines which modifiers are considered significant
64/// for keyboard accelerators. See [`accelerator_set_default_mod_mask()`][crate::accelerator_set_default_mod_mask()].
65///
66/// # Returns
67///
68/// the default accelerator modifier mask
69#[doc(alias = "gtk_accelerator_get_default_mod_mask")]
70pub fn accelerator_get_default_mod_mask() -> gdk::ModifierType {
71    assert_initialized_main_thread!();
72    unsafe { from_glib(ffi::gtk_accelerator_get_default_mod_mask()) }
73}
74
75/// Converts an accelerator keyval and modifier mask into a string
76/// which can be used to represent the accelerator to the user.
77/// ## `accelerator_key`
78/// accelerator keyval
79/// ## `accelerator_mods`
80/// accelerator modifier mask
81///
82/// # Returns
83///
84/// a newly-allocated string representing the accelerator.
85#[doc(alias = "gtk_accelerator_get_label")]
86pub fn accelerator_get_label(
87    accelerator_key: u32,
88    accelerator_mods: gdk::ModifierType,
89) -> Option<glib::GString> {
90    assert_initialized_main_thread!();
91    unsafe {
92        from_glib_full(ffi::gtk_accelerator_get_label(
93            accelerator_key,
94            accelerator_mods.into_glib(),
95        ))
96    }
97}
98
99/// Converts an accelerator keyval and modifier mask
100/// into a (possibly translated) string that can be displayed to
101/// a user, similarly to [`accelerator_get_label()`][crate::accelerator_get_label()], but handling
102/// keycodes.
103///
104/// This is only useful for system-level components, applications
105/// should use [`accelerator_parse()`][crate::accelerator_parse()] instead.
106/// ## `display`
107/// a [`gdk::Display`][crate::gdk::Display] or [`None`] to use the default display
108/// ## `accelerator_key`
109/// accelerator keyval
110/// ## `keycode`
111/// accelerator keycode
112/// ## `accelerator_mods`
113/// accelerator modifier mask
114///
115/// # Returns
116///
117/// a newly-allocated string representing the accelerator.
118#[doc(alias = "gtk_accelerator_get_label_with_keycode")]
119pub fn accelerator_get_label_with_keycode(
120    display: Option<&gdk::Display>,
121    accelerator_key: u32,
122    keycode: u32,
123    accelerator_mods: gdk::ModifierType,
124) -> Option<glib::GString> {
125    assert_initialized_main_thread!();
126    unsafe {
127        from_glib_full(ffi::gtk_accelerator_get_label_with_keycode(
128            display.to_glib_none().0,
129            accelerator_key,
130            keycode,
131            accelerator_mods.into_glib(),
132        ))
133    }
134}
135
136/// Converts an accelerator keyval and modifier mask into a string
137/// parseable by [`accelerator_parse()`][crate::accelerator_parse()]. For example, if you pass in
138/// `GDK_KEY_q` and [`gdk::ModifierType::CONTROL_MASK`][crate::gdk::ModifierType::CONTROL_MASK], this function returns “`<Control>`q”.
139///
140/// If you need to display accelerators in the user interface,
141/// see [`accelerator_get_label()`][crate::accelerator_get_label()].
142/// ## `accelerator_key`
143/// accelerator keyval
144/// ## `accelerator_mods`
145/// accelerator modifier mask
146///
147/// # Returns
148///
149/// a newly-allocated accelerator name
150#[doc(alias = "gtk_accelerator_name")]
151pub fn accelerator_name(
152    accelerator_key: u32,
153    accelerator_mods: gdk::ModifierType,
154) -> Option<glib::GString> {
155    assert_initialized_main_thread!();
156    unsafe {
157        from_glib_full(ffi::gtk_accelerator_name(
158            accelerator_key,
159            accelerator_mods.into_glib(),
160        ))
161    }
162}
163
164/// Converts an accelerator keyval and modifier mask
165/// into a string parseable by [`accelerator_parse_with_keycode()`][crate::accelerator_parse_with_keycode()],
166/// similarly to [`accelerator_name()`][crate::accelerator_name()] but handling keycodes.
167/// This is only useful for system-level components, applications
168/// should use [`accelerator_parse()`][crate::accelerator_parse()] instead.
169/// ## `display`
170/// a [`gdk::Display`][crate::gdk::Display] or [`None`] to use the default display
171/// ## `accelerator_key`
172/// accelerator keyval
173/// ## `keycode`
174/// accelerator keycode
175/// ## `accelerator_mods`
176/// accelerator modifier mask
177///
178/// # Returns
179///
180/// a newly allocated accelerator name.
181#[doc(alias = "gtk_accelerator_name_with_keycode")]
182pub fn accelerator_name_with_keycode(
183    display: Option<&gdk::Display>,
184    accelerator_key: u32,
185    keycode: u32,
186    accelerator_mods: gdk::ModifierType,
187) -> Option<glib::GString> {
188    assert_initialized_main_thread!();
189    unsafe {
190        from_glib_full(ffi::gtk_accelerator_name_with_keycode(
191            display.to_glib_none().0,
192            accelerator_key,
193            keycode,
194            accelerator_mods.into_glib(),
195        ))
196    }
197}
198
199/// Parses a string representing an accelerator. The format looks like
200/// “`<Control>`a” or “`<Shift>``<Alt>`F1” or “`<Release>`z” (the last one is
201/// for key release).
202///
203/// The parser is fairly liberal and allows lower or upper case, and also
204/// abbreviations such as “`<Ctl>`” and “`<Ctrl>`”. Key names are parsed using
205/// `gdk_keyval_from_name()`. For character keys the name is not the symbol,
206/// but the lowercase name, e.g. one would use “`<Ctrl>`minus” instead of
207/// “`<Ctrl>`-”.
208///
209/// If the parse fails, `accelerator_key` and `accelerator_mods` will
210/// be set to 0 (zero).
211/// ## `accelerator`
212/// string representing an accelerator
213///
214/// # Returns
215///
216///
217/// ## `accelerator_key`
218/// return location for accelerator
219///  keyval, or [`None`]
220///
221/// ## `accelerator_mods`
222/// return location for accelerator
223///  modifier mask, [`None`]
224#[doc(alias = "gtk_accelerator_parse")]
225pub fn accelerator_parse(accelerator: &str) -> (u32, gdk::ModifierType) {
226    assert_initialized_main_thread!();
227    unsafe {
228        let mut accelerator_key = mem::MaybeUninit::uninit();
229        let mut accelerator_mods = mem::MaybeUninit::uninit();
230        ffi::gtk_accelerator_parse(
231            accelerator.to_glib_none().0,
232            accelerator_key.as_mut_ptr(),
233            accelerator_mods.as_mut_ptr(),
234        );
235        (
236            accelerator_key.assume_init(),
237            from_glib(accelerator_mods.assume_init()),
238        )
239    }
240}
241
242/// Sets the modifiers that will be considered significant for keyboard
243/// accelerators. The default mod mask depends on the GDK backend in use,
244/// but will typically include [`gdk::ModifierType::CONTROL_MASK`][crate::gdk::ModifierType::CONTROL_MASK] | [`gdk::ModifierType::SHIFT_MASK`][crate::gdk::ModifierType::SHIFT_MASK] |
245/// [`gdk::ModifierType::MOD1_MASK`][crate::gdk::ModifierType::MOD1_MASK] | [`gdk::ModifierType::SUPER_MASK`][crate::gdk::ModifierType::SUPER_MASK] | [`gdk::ModifierType::HYPER_MASK`][crate::gdk::ModifierType::HYPER_MASK] | [`gdk::ModifierType::META_MASK`][crate::gdk::ModifierType::META_MASK].
246/// In other words, Control, Shift, Alt, Super, Hyper and Meta. Other
247/// modifiers will by default be ignored by [`AccelGroup`][crate::AccelGroup].
248///
249/// You must include at least the three modifiers Control, Shift
250/// and Alt in any value you pass to this function.
251///
252/// The default mod mask should be changed on application startup,
253/// before using any accelerator groups.
254/// ## `default_mod_mask`
255/// accelerator modifier mask
256#[doc(alias = "gtk_accelerator_set_default_mod_mask")]
257pub fn accelerator_set_default_mod_mask(default_mod_mask: gdk::ModifierType) {
258    assert_initialized_main_thread!();
259    unsafe {
260        ffi::gtk_accelerator_set_default_mod_mask(default_mod_mask.into_glib());
261    }
262}
263
264/// Determines whether a given keyval and modifier mask constitute
265/// a valid keyboard accelerator. For example, the `GDK_KEY_a` keyval
266/// plus [`gdk::ModifierType::CONTROL_MASK`][crate::gdk::ModifierType::CONTROL_MASK] is valid - this is a “Ctrl+a” accelerator.
267/// But, you can't, for instance, use the `GDK_KEY_Control_L` keyval
268/// as an accelerator.
269/// ## `keyval`
270/// a GDK keyval
271/// ## `modifiers`
272/// modifier mask
273///
274/// # Returns
275///
276/// [`true`] if the accelerator is valid
277#[doc(alias = "gtk_accelerator_valid")]
278pub fn accelerator_valid(keyval: u32, modifiers: gdk::ModifierType) -> bool {
279    assert_initialized_main_thread!();
280    unsafe { from_glib(ffi::gtk_accelerator_valid(keyval, modifiers.into_glib())) }
281}
282
283/// Find a key binding matching `keyval` and `modifiers` and activate the
284/// binding on `object`.
285/// ## `object`
286/// object to activate when binding found
287/// ## `keyval`
288/// key value of the binding
289/// ## `modifiers`
290/// key modifier of the binding
291///
292/// # Returns
293///
294/// [`true`] if a binding was found and activated
295#[doc(alias = "gtk_bindings_activate")]
296pub fn bindings_activate(
297    object: &impl IsA<glib::Object>,
298    keyval: u32,
299    modifiers: gdk::ModifierType,
300) -> bool {
301    assert_initialized_main_thread!();
302    unsafe {
303        from_glib(ffi::gtk_bindings_activate(
304            object.as_ref().to_glib_none().0,
305            keyval,
306            modifiers.into_glib(),
307        ))
308    }
309}
310
311/// Looks up key bindings for `object` to find one matching
312/// `event`, and if one was found, activate it.
313/// ## `object`
314/// a [`glib::Object`][crate::glib::Object] (generally must be a widget)
315/// ## `event`
316/// a [`gdk::EventKey`][crate::gdk::EventKey]
317///
318/// # Returns
319///
320/// [`true`] if a matching key binding was found
321#[doc(alias = "gtk_bindings_activate_event")]
322pub fn bindings_activate_event(object: &impl IsA<glib::Object>, event: &mut gdk::EventKey) -> bool {
323    assert_initialized_main_thread!();
324    unsafe {
325        from_glib(ffi::gtk_bindings_activate_event(
326            object.as_ref().to_glib_none().0,
327            event.to_glib_none_mut().0,
328        ))
329    }
330}
331
332/// This function is supposed to be called in [`draw`][struct@crate::Widget#draw]
333/// implementations for widgets that support multiple windows.
334/// `cr` must be untransformed from invoking of the draw function.
335/// This function will return [`true`] if the contents of the given
336/// `window` are supposed to be drawn and [`false`] otherwise. Note
337/// that when the drawing was not initiated by the windowing
338/// system this function will return [`true`] for all windows, so
339/// you need to draw the bottommost window first. Also, do not
340/// use “else if” statements to check which window should be drawn.
341/// ## `cr`
342/// a cairo context
343/// ## `window`
344/// the window to check. `window` may not be an input-only
345///  window.
346///
347/// # Returns
348///
349/// [`true`] if `window` should be drawn
350#[doc(alias = "gtk_cairo_should_draw_window")]
351pub fn cairo_should_draw_window(cr: &cairo::Context, window: &gdk::Window) -> bool {
352    assert_initialized_main_thread!();
353    unsafe {
354        from_glib(ffi::gtk_cairo_should_draw_window(
355            mut_override(cr.to_glib_none().0),
356            window.to_glib_none().0,
357        ))
358    }
359}
360
361/// Transforms the given cairo context `cr` that from `widget`-relative
362/// coordinates to `window`-relative coordinates.
363/// If the `widget`’s window is not an ancestor of `window`, no
364/// modification will be applied.
365///
366/// This is the inverse to the transformation GTK applies when
367/// preparing an expose event to be emitted with the [`draw`][struct@crate::Widget#draw]
368/// signal. It is intended to help porting multiwindow widgets from
369/// GTK+ 2 to the rendering architecture of GTK+ 3.
370/// ## `cr`
371/// the cairo context to transform
372/// ## `widget`
373/// the widget the context is currently centered for
374/// ## `window`
375/// the window to transform the context to
376#[doc(alias = "gtk_cairo_transform_to_window")]
377pub fn cairo_transform_to_window(
378    cr: &cairo::Context,
379    widget: &impl IsA<Widget>,
380    window: &gdk::Window,
381) {
382    skip_assert_initialized!();
383    unsafe {
384        ffi::gtk_cairo_transform_to_window(
385            mut_override(cr.to_glib_none().0),
386            widget.as_ref().to_glib_none().0,
387            window.to_glib_none().0,
388        );
389    }
390}
391
392/// Checks that the GTK+ library in use is compatible with the
393/// given version. Generally you would pass in the constants
394/// `GTK_MAJOR_VERSION`, `GTK_MINOR_VERSION`, `GTK_MICRO_VERSION`
395/// as the three arguments to this function; that produces
396/// a check that the library in use is compatible with
397/// the version of GTK+ the application or module was compiled
398/// against.
399///
400/// Compatibility is defined by two things: first the version
401/// of the running library is newer than the version
402/// `required_major`.`required_micro`. Second
403/// the running library must be binary compatible with the
404/// version `required_major`.`required_micro`
405/// (same major version.)
406///
407/// This function is primarily for GTK+ modules; the module
408/// can call this function to check that it wasn’t loaded
409/// into an incompatible version of GTK+. However, such a
410/// check isn’t completely reliable, since the module may be
411/// linked against an old version of GTK+ and calling the
412/// old version of [`check_version()`][crate::check_version()], but still get loaded
413/// into an application using a newer version of GTK+.
414/// ## `required_major`
415/// the required major version
416/// ## `required_minor`
417/// the required minor version
418/// ## `required_micro`
419/// the required micro version
420///
421/// # Returns
422///
423/// [`None`] if the GTK+ library is compatible with the
424///  given version, or a string describing the version mismatch.
425///  The returned string is owned by GTK+ and should not be modified
426///  or freed.
427#[doc(alias = "gtk_check_version")]
428pub fn check_version(
429    required_major: u32,
430    required_minor: u32,
431    required_micro: u32,
432) -> Option<glib::GString> {
433    skip_assert_initialized!();
434    unsafe {
435        from_glib_none(ffi::gtk_check_version(
436            required_major,
437            required_minor,
438            required_micro,
439        ))
440    }
441}
442
443/// Adds a GTK+ grab on `device`, so all the events on `device` and its
444/// associated pointer or keyboard (if any) are delivered to `widget`.
445/// If the `block_others` parameter is [`true`], any other devices will be
446/// unable to interact with `widget` during the grab.
447/// ## `widget`
448/// a [`Widget`][crate::Widget]
449/// ## `device`
450/// a [`gdk::Device`][crate::gdk::Device] to grab on.
451/// ## `block_others`
452/// [`true`] to prevent other devices to interact with `widget`.
453#[doc(alias = "gtk_device_grab_add")]
454pub fn device_grab_add(widget: &impl IsA<Widget>, device: &gdk::Device, block_others: bool) {
455    skip_assert_initialized!();
456    unsafe {
457        ffi::gtk_device_grab_add(
458            widget.as_ref().to_glib_none().0,
459            device.to_glib_none().0,
460            block_others.into_glib(),
461        );
462    }
463}
464
465/// Removes a device grab from the given widget.
466///
467/// You have to pair calls to [`device_grab_add()`][crate::device_grab_add()] and
468/// [`device_grab_remove()`][crate::device_grab_remove()].
469/// ## `widget`
470/// a [`Widget`][crate::Widget]
471/// ## `device`
472/// a [`gdk::Device`][crate::gdk::Device]
473#[doc(alias = "gtk_device_grab_remove")]
474pub fn device_grab_remove(widget: &impl IsA<Widget>, device: &gdk::Device) {
475    skip_assert_initialized!();
476    unsafe {
477        ffi::gtk_device_grab_remove(widget.as_ref().to_glib_none().0, device.to_glib_none().0);
478    }
479}
480
481/// Prevents `gtk_init()`, `gtk_init_check()`, `gtk_init_with_args()` and
482/// `gtk_parse_args()` from automatically
483/// calling `setlocale (LC_ALL, "")`. You would
484/// want to use this function if you wanted to set the locale for
485/// your program to something other than the user’s locale, or if
486/// you wanted to set different values for different locale categories.
487///
488/// Most programs should not need to call this function.
489#[doc(alias = "gtk_disable_setlocale")]
490pub fn disable_setlocale() {
491    assert_not_initialized!();
492    unsafe {
493        ffi::gtk_disable_setlocale();
494    }
495}
496
497//#[doc(alias = "gtk_distribute_natural_allocation")]
498//pub fn distribute_natural_allocation(extra_space: i32, n_requested_sizes: u32, sizes: /*Ignored*/&mut RequestedSize) -> i32 {
499//    unsafe { TODO: call ffi:gtk_distribute_natural_allocation() }
500//}
501
502/// Checks if any events are pending.
503///
504/// This can be used to update the UI and invoke timeouts etc.
505/// while doing some time intensive computation.
506///
507/// ## Updating the UI during a long computation
508///
509///
510///
511/// **⚠️ The following code is in C ⚠️**
512///
513/// ```C
514///  // computation going on...
515///
516///  while (gtk_events_pending ())
517///    gtk_main_iteration ();
518///
519///  // ...computation continued
520/// ```
521///
522/// # Returns
523///
524/// [`true`] if any events are pending, [`false`] otherwise
525#[doc(alias = "gtk_events_pending")]
526pub fn events_pending() -> bool {
527    assert_initialized_main_thread!();
528    unsafe { from_glib(ffi::gtk_events_pending()) }
529}
530
531#[doc(alias = "gtk_false")]
532#[doc(alias = "false")]
533pub fn false_() -> bool {
534    assert_initialized_main_thread!();
535    unsafe { from_glib(ffi::gtk_false()) }
536}
537
538/// Returns the binary age as passed to `libtool`
539/// when building the GTK+ library the process is running against.
540/// If `libtool` means nothing to you, don't
541/// worry about it.
542///
543/// # Returns
544///
545/// the binary age of the GTK+ library
546#[doc(alias = "gtk_get_binary_age")]
547#[doc(alias = "get_binary_age")]
548pub fn binary_age() -> u32 {
549    skip_assert_initialized!();
550    unsafe { ffi::gtk_get_binary_age() }
551}
552
553/// Obtains a copy of the event currently being processed by GTK+.
554///
555/// For example, if you are handling a [`clicked`][struct@crate::Button#clicked] signal,
556/// the current event will be the [`gdk::EventButton`][crate::gdk::EventButton] that triggered
557/// the ::clicked signal.
558///
559/// # Returns
560///
561/// a copy of the current event, or
562///  [`None`] if there is no current event. The returned event must be
563///  freed with `gdk_event_free()`.
564#[doc(alias = "gtk_get_current_event")]
565#[doc(alias = "get_current_event")]
566pub fn current_event() -> Option<gdk::Event> {
567    assert_initialized_main_thread!();
568    unsafe { from_glib_full(ffi::gtk_get_current_event()) }
569}
570
571/// If there is a current event and it has a device, return that
572/// device, otherwise return [`None`].
573///
574/// # Returns
575///
576/// a [`gdk::Device`][crate::gdk::Device], or [`None`]
577#[doc(alias = "gtk_get_current_event_device")]
578#[doc(alias = "get_current_event_device")]
579pub fn current_event_device() -> Option<gdk::Device> {
580    assert_initialized_main_thread!();
581    unsafe { from_glib_none(ffi::gtk_get_current_event_device()) }
582}
583
584/// If there is a current event and it has a state field, place
585/// that state field in `state` and return [`true`], otherwise return
586/// [`false`].
587///
588/// # Returns
589///
590/// [`true`] if there was a current event and it
591///  had a state field
592///
593/// ## `state`
594/// a location to store the state of the current event
595#[doc(alias = "gtk_get_current_event_state")]
596#[doc(alias = "get_current_event_state")]
597pub fn current_event_state() -> Option<gdk::ModifierType> {
598    assert_initialized_main_thread!();
599    unsafe {
600        let mut state = mem::MaybeUninit::uninit();
601        let ret = from_glib(ffi::gtk_get_current_event_state(state.as_mut_ptr()));
602        if ret {
603            Some(from_glib(state.assume_init()))
604        } else {
605            None
606        }
607    }
608}
609
610/// If there is a current event and it has a timestamp,
611/// return that timestamp, otherwise return `GDK_CURRENT_TIME`.
612///
613/// # Returns
614///
615/// the timestamp from the current event,
616///  or `GDK_CURRENT_TIME`.
617#[doc(alias = "gtk_get_current_event_time")]
618#[doc(alias = "get_current_event_time")]
619pub fn current_event_time() -> u32 {
620    assert_initialized_main_thread!();
621    unsafe { ffi::gtk_get_current_event_time() }
622}
623
624/// Returns the GTK+ debug flags.
625///
626/// This function is intended for GTK+ modules that want
627/// to adjust their debug output based on GTK+ debug flags.
628///
629/// # Returns
630///
631/// the GTK+ debug flags.
632#[doc(alias = "gtk_get_debug_flags")]
633#[doc(alias = "get_debug_flags")]
634pub fn debug_flags() -> u32 {
635    assert_initialized_main_thread!();
636    unsafe { ffi::gtk_get_debug_flags() }
637}
638
639/// Returns the [`pango::Language`][crate::pango::Language] for the default language currently in
640/// effect. (Note that this can change over the life of an
641/// application.) The default language is derived from the current
642/// locale. It determines, for example, whether GTK+ uses the
643/// right-to-left or left-to-right text direction.
644///
645/// This function is equivalent to [`pango::Language::default()`][crate::pango::Language::default()].
646/// See that function for details.
647///
648/// # Returns
649///
650/// the default language as a [`pango::Language`][crate::pango::Language],
651///  must not be freed
652#[doc(alias = "gtk_get_default_language")]
653#[doc(alias = "get_default_language")]
654pub fn default_language() -> Option<pango::Language> {
655    assert_initialized_main_thread!();
656    unsafe { from_glib_none(ffi::gtk_get_default_language()) }
657}
658
659/// If `event` is [`None`] or the event was not associated with any widget,
660/// returns [`None`], otherwise returns the widget that received the event
661/// originally.
662/// ## `event`
663/// a `GdkEvent`
664///
665/// # Returns
666///
667/// the widget that originally
668///  received `event`, or [`None`]
669#[doc(alias = "gtk_get_event_widget")]
670#[doc(alias = "get_event_widget")]
671pub fn event_widget(event: &mut gdk::Event) -> Option<Widget> {
672    assert_initialized_main_thread!();
673    unsafe { from_glib_none(ffi::gtk_get_event_widget(event.to_glib_none_mut().0)) }
674}
675
676/// Returns the interface age as passed to `libtool`
677/// when building the GTK+ library the process is running against.
678/// If `libtool` means nothing to you, don't
679/// worry about it.
680///
681/// # Returns
682///
683/// the interface age of the GTK+ library
684#[doc(alias = "gtk_get_interface_age")]
685#[doc(alias = "get_interface_age")]
686pub fn interface_age() -> u32 {
687    skip_assert_initialized!();
688    unsafe { ffi::gtk_get_interface_age() }
689}
690
691/// Get the direction of the current locale. This is the expected
692/// reading direction for text and UI.
693///
694/// This function depends on the current locale being set with
695/// `setlocale()` and will default to setting the [`TextDirection::Ltr`][crate::TextDirection::Ltr]
696/// direction otherwise. [`TextDirection::None`][crate::TextDirection::None] will never be returned.
697///
698/// GTK+ sets the default text direction according to the locale
699/// during `gtk_init()`, and you should normally use
700/// [`WidgetExt::direction()`][crate::prelude::WidgetExt::direction()] or [`Widget::default_direction()`][crate::Widget::default_direction()]
701/// to obtain the current direcion.
702///
703/// This function is only needed rare cases when the locale is
704/// changed after GTK+ has already been initialized. In this case,
705/// you can use it to update the default text direction as follows:
706///
707///
708///
709/// **⚠️ The following code is in C ⚠️**
710///
711/// ```C
712/// setlocale (LC_ALL, new_locale);
713/// direction = gtk_get_locale_direction ();
714/// gtk_widget_set_default_direction (direction);
715/// ```
716///
717/// # Returns
718///
719/// the [`TextDirection`][crate::TextDirection] of the current locale
720#[doc(alias = "gtk_get_locale_direction")]
721#[doc(alias = "get_locale_direction")]
722pub fn locale_direction() -> TextDirection {
723    assert_initialized_main_thread!();
724    unsafe { from_glib(ffi::gtk_get_locale_direction()) }
725}
726
727/// Returns the major version number of the GTK+ library.
728/// (e.g. in GTK+ version 3.1.5 this is 3.)
729///
730/// This function is in the library, so it represents the GTK+ library
731/// your code is running against. Contrast with the `GTK_MAJOR_VERSION`
732/// macro, which represents the major version of the GTK+ headers you
733/// have included when compiling your code.
734///
735/// # Returns
736///
737/// the major version number of the GTK+ library
738#[doc(alias = "gtk_get_major_version")]
739#[doc(alias = "get_major_version")]
740pub fn major_version() -> u32 {
741    skip_assert_initialized!();
742    unsafe { ffi::gtk_get_major_version() }
743}
744
745/// Returns the micro version number of the GTK+ library.
746/// (e.g. in GTK+ version 3.1.5 this is 5.)
747///
748/// This function is in the library, so it represents the GTK+ library
749/// your code is are running against. Contrast with the
750/// `GTK_MICRO_VERSION` macro, which represents the micro version of the
751/// GTK+ headers you have included when compiling your code.
752///
753/// # Returns
754///
755/// the micro version number of the GTK+ library
756#[doc(alias = "gtk_get_micro_version")]
757#[doc(alias = "get_micro_version")]
758pub fn micro_version() -> u32 {
759    skip_assert_initialized!();
760    unsafe { ffi::gtk_get_micro_version() }
761}
762
763/// Returns the minor version number of the GTK+ library.
764/// (e.g. in GTK+ version 3.1.5 this is 1.)
765///
766/// This function is in the library, so it represents the GTK+ library
767/// your code is are running against. Contrast with the
768/// `GTK_MINOR_VERSION` macro, which represents the minor version of the
769/// GTK+ headers you have included when compiling your code.
770///
771/// # Returns
772///
773/// the minor version number of the GTK+ library
774#[doc(alias = "gtk_get_minor_version")]
775#[doc(alias = "get_minor_version")]
776pub fn minor_version() -> u32 {
777    skip_assert_initialized!();
778    unsafe { ffi::gtk_get_minor_version() }
779}
780
781//#[doc(alias = "gtk_get_option_group")]
782//#[doc(alias = "get_option_group")]
783//pub fn option_group(open_default_display: bool) -> /*Ignored*/Option<glib::OptionGroup> {
784//    unsafe { TODO: call ffi:gtk_get_option_group() }
785//}
786
787/// Queries the current grab of the default window group.
788///
789/// # Returns
790///
791/// The widget which currently
792///  has the grab or [`None`] if no grab is active
793#[doc(alias = "gtk_grab_get_current")]
794pub fn grab_get_current() -> Option<Widget> {
795    assert_initialized_main_thread!();
796    unsafe { from_glib_none(ffi::gtk_grab_get_current()) }
797}
798
799/// Runs the main loop until `gtk_main_quit()` is called.
800///
801/// You can nest calls to [`main()`][crate::main()]. In that case `gtk_main_quit()`
802/// will make the innermost invocation of the main loop return.
803#[doc(alias = "gtk_main")]
804pub fn main() {
805    assert_initialized_main_thread!();
806    unsafe {
807        ffi::gtk_main();
808    }
809}
810
811/// Processes a single GDK event.
812///
813/// This is public only to allow filtering of events between GDK and GTK+.
814/// You will not usually need to call this function directly.
815///
816/// While you should not call this function directly, you might want to
817/// know how exactly events are handled. So here is what this function
818/// does with the event:
819///
820/// 1. Compress enter/leave notify events. If the event passed build an
821///  enter/leave pair together with the next event (peeked from GDK), both
822///  events are thrown away. This is to avoid a backlog of (de-)highlighting
823///  widgets crossed by the pointer.
824///
825/// 2. Find the widget which got the event. If the widget can’t be determined
826///  the event is thrown away unless it belongs to a INCR transaction.
827///
828/// 3. Then the event is pushed onto a stack so you can query the currently
829///  handled event with [`current_event()`][crate::current_event()].
830///
831/// 4. The event is sent to a widget. If a grab is active all events for widgets
832///  that are not in the contained in the grab widget are sent to the latter
833///  with a few exceptions:
834///  - Deletion and destruction events are still sent to the event widget for
835///  obvious reasons.
836///  - Events which directly relate to the visual representation of the event
837///  widget.
838///  - Leave events are delivered to the event widget if there was an enter
839///  event delivered to it before without the paired leave event.
840///  - Drag events are not redirected because it is unclear what the semantics
841///  of that would be.
842///  Another point of interest might be that all key events are first passed
843///  through the key snooper functions if there are any. Read the description
844///  of `gtk_key_snooper_install()` if you need this feature.
845///
846/// 5. After finishing the delivery the event is popped from the event stack.
847/// ## `event`
848/// An event to process (normally passed by GDK)
849#[doc(alias = "gtk_main_do_event")]
850pub fn main_do_event(event: &mut gdk::Event) {
851    assert_initialized_main_thread!();
852    unsafe {
853        ffi::gtk_main_do_event(event.to_glib_none_mut().0);
854    }
855}
856
857/// Runs a single iteration of the mainloop.
858///
859/// If no events are waiting to be processed GTK+ will block
860/// until the next event is noticed. If you don’t want to block
861/// look at [`main_iteration_do()`][crate::main_iteration_do()] or check if any events are
862/// pending with [`events_pending()`][crate::events_pending()] first.
863///
864/// # Returns
865///
866/// [`true`] if `gtk_main_quit()` has been called for the
867///  innermost mainloop
868#[doc(alias = "gtk_main_iteration")]
869pub fn main_iteration() -> bool {
870    assert_initialized_main_thread!();
871    unsafe { from_glib(ffi::gtk_main_iteration()) }
872}
873
874/// Runs a single iteration of the mainloop.
875/// If no events are available either return or block depending on
876/// the value of `blocking`.
877/// ## `blocking`
878/// [`true`] if you want GTK+ to block if no events are pending
879///
880/// # Returns
881///
882/// [`true`] if `gtk_main_quit()` has been called for the
883///  innermost mainloop
884#[doc(alias = "gtk_main_iteration_do")]
885pub fn main_iteration_do(blocking: bool) -> bool {
886    assert_initialized_main_thread!();
887    unsafe { from_glib(ffi::gtk_main_iteration_do(blocking.into_glib())) }
888}
889
890/// Asks for the current nesting level of the main loop.
891///
892/// # Returns
893///
894/// the nesting level of the current invocation
895///  of the main loop
896#[doc(alias = "gtk_main_level")]
897pub fn main_level() -> u32 {
898    assert_initialized_main_thread!();
899    unsafe { ffi::gtk_main_level() }
900}
901
902/// Runs a page setup dialog, letting the user modify the values from
903/// `page_setup`. If the user cancels the dialog, the returned [`PageSetup`][crate::PageSetup]
904/// is identical to the passed in `page_setup`, otherwise it contains the
905/// modifications done in the dialog.
906///
907/// Note that this function may use a recursive mainloop to show the page
908/// setup dialog. See [`print_run_page_setup_dialog_async()`][crate::print_run_page_setup_dialog_async()] if this is
909/// a problem.
910/// ## `parent`
911/// transient parent
912/// ## `page_setup`
913/// an existing [`PageSetup`][crate::PageSetup]
914/// ## `settings`
915/// a [`PrintSettings`][crate::PrintSettings]
916///
917/// # Returns
918///
919/// a new [`PageSetup`][crate::PageSetup]
920#[doc(alias = "gtk_print_run_page_setup_dialog")]
921pub fn print_run_page_setup_dialog(
922    parent: Option<&impl IsA<Window>>,
923    page_setup: Option<&PageSetup>,
924    settings: &PrintSettings,
925) -> Option<PageSetup> {
926    skip_assert_initialized!();
927    unsafe {
928        from_glib_full(ffi::gtk_print_run_page_setup_dialog(
929            parent.map(|p| p.as_ref()).to_glib_none().0,
930            page_setup.to_glib_none().0,
931            settings.to_glib_none().0,
932        ))
933    }
934}
935
936/// Runs a page setup dialog, letting the user modify the values from `page_setup`.
937///
938/// In contrast to [`print_run_page_setup_dialog()`][crate::print_run_page_setup_dialog()], this function returns after
939/// showing the page setup dialog on platforms that support this, and calls `done_cb`
940/// from a signal handler for the ::response signal of the dialog.
941/// ## `parent`
942/// transient parent, or [`None`]
943/// ## `page_setup`
944/// an existing [`PageSetup`][crate::PageSetup], or [`None`]
945/// ## `settings`
946/// a [`PrintSettings`][crate::PrintSettings]
947/// ## `done_cb`
948/// a function to call when the user saves
949///  the modified page setup
950#[doc(alias = "gtk_print_run_page_setup_dialog_async")]
951pub fn print_run_page_setup_dialog_async<P: FnOnce(&PageSetup) + Send + Sync + 'static>(
952    parent: Option<&impl IsA<Window>>,
953    page_setup: Option<&PageSetup>,
954    settings: &PrintSettings,
955    done_cb: P,
956) {
957    skip_assert_initialized!();
958    let done_cb_data: Box_<P> = Box_::new(done_cb);
959    unsafe extern "C" fn done_cb_func<P: FnOnce(&PageSetup) + Send + Sync + 'static>(
960        page_setup: *mut ffi::GtkPageSetup,
961        data: glib::ffi::gpointer,
962    ) {
963        let page_setup = from_glib_borrow(page_setup);
964        let callback: Box_<P> = Box_::from_raw(data as *mut _);
965        (*callback)(&page_setup)
966    }
967    let done_cb = Some(done_cb_func::<P> as _);
968    let super_callback0: Box_<P> = done_cb_data;
969    unsafe {
970        ffi::gtk_print_run_page_setup_dialog_async(
971            parent.map(|p| p.as_ref()).to_glib_none().0,
972            page_setup.to_glib_none().0,
973            settings.to_glib_none().0,
974            done_cb,
975            Box_::into_raw(super_callback0) as *mut _,
976        );
977    }
978}
979
980/// Sends an event to a widget, propagating the event to parent widgets
981/// if the event remains unhandled.
982///
983/// Events received by GTK+ from GDK normally begin in [`main_do_event()`][crate::main_do_event()].
984/// Depending on the type of event, existence of modal dialogs, grabs, etc.,
985/// the event may be propagated; if so, this function is used.
986///
987/// [`propagate_event()`][crate::propagate_event()] calls [`WidgetExt::event()`][crate::prelude::WidgetExt::event()] on each widget it
988/// decides to send the event to. So [`WidgetExt::event()`][crate::prelude::WidgetExt::event()] is the lowest-level
989/// function; it simply emits the [`event`][struct@crate::Widget#event] and possibly an
990/// event-specific signal on a widget. [`propagate_event()`][crate::propagate_event()] is a bit
991/// higher-level, and [`main_do_event()`][crate::main_do_event()] is the highest level.
992///
993/// All that said, you most likely don’t want to use any of these
994/// functions; synthesizing events is rarely needed. There are almost
995/// certainly better ways to achieve your goals. For example, use
996/// [`Window::invalidate_rect()`][crate::gdk::Window::invalidate_rect()] or [`WidgetExt::queue_draw()`][crate::prelude::WidgetExt::queue_draw()] instead
997/// of making up expose events.
998/// ## `widget`
999/// a [`Widget`][crate::Widget]
1000/// ## `event`
1001/// an event
1002#[doc(alias = "gtk_propagate_event")]
1003pub fn propagate_event(widget: &impl IsA<Widget>, event: &mut gdk::Event) {
1004    skip_assert_initialized!();
1005    unsafe {
1006        ffi::gtk_propagate_event(widget.as_ref().to_glib_none().0, event.to_glib_none_mut().0);
1007    }
1008}
1009
1010/// Renders an activity indicator (such as in [`Spinner`][crate::Spinner]).
1011/// The state [`StateFlags::CHECKED`][crate::StateFlags::CHECKED] determines whether there is
1012/// activity going on.
1013/// ## `context`
1014/// a [`StyleContext`][crate::StyleContext]
1015/// ## `cr`
1016/// a [`cairo::Context`][crate::cairo::Context]
1017/// ## `x`
1018/// X origin of the rectangle
1019/// ## `y`
1020/// Y origin of the rectangle
1021/// ## `width`
1022/// rectangle width
1023/// ## `height`
1024/// rectangle height
1025#[doc(alias = "gtk_render_activity")]
1026pub fn render_activity(
1027    context: &impl IsA<StyleContext>,
1028    cr: &cairo::Context,
1029    x: f64,
1030    y: f64,
1031    width: f64,
1032    height: f64,
1033) {
1034    skip_assert_initialized!();
1035    unsafe {
1036        ffi::gtk_render_activity(
1037            context.as_ref().to_glib_none().0,
1038            mut_override(cr.to_glib_none().0),
1039            x,
1040            y,
1041            width,
1042            height,
1043        );
1044    }
1045}
1046
1047/// Renders an arrow pointing to `angle`.
1048///
1049/// Typical arrow rendering at 0, 1⁄2 π;, π; and 3⁄2 π:
1050///
1051/// ![](arrows.png)
1052/// ## `context`
1053/// a [`StyleContext`][crate::StyleContext]
1054/// ## `cr`
1055/// a [`cairo::Context`][crate::cairo::Context]
1056/// ## `angle`
1057/// arrow angle from 0 to 2 * `G_PI`, being 0 the arrow pointing to the north
1058/// ## `x`
1059/// X origin of the render area
1060/// ## `y`
1061/// Y origin of the render area
1062/// ## `size`
1063/// square side for render area
1064#[doc(alias = "gtk_render_arrow")]
1065pub fn render_arrow(
1066    context: &impl IsA<StyleContext>,
1067    cr: &cairo::Context,
1068    angle: f64,
1069    x: f64,
1070    y: f64,
1071    size: f64,
1072) {
1073    skip_assert_initialized!();
1074    unsafe {
1075        ffi::gtk_render_arrow(
1076            context.as_ref().to_glib_none().0,
1077            mut_override(cr.to_glib_none().0),
1078            angle,
1079            x,
1080            y,
1081            size,
1082        );
1083    }
1084}
1085
1086/// Renders the background of an element.
1087///
1088/// Typical background rendering, showing the effect of
1089/// `background-image`, `border-width` and `border-radius`:
1090///
1091/// ![](background.png)
1092/// ## `context`
1093/// a [`StyleContext`][crate::StyleContext]
1094/// ## `cr`
1095/// a [`cairo::Context`][crate::cairo::Context]
1096/// ## `x`
1097/// X origin of the rectangle
1098/// ## `y`
1099/// Y origin of the rectangle
1100/// ## `width`
1101/// rectangle width
1102/// ## `height`
1103/// rectangle height
1104#[doc(alias = "gtk_render_background")]
1105pub fn render_background(
1106    context: &impl IsA<StyleContext>,
1107    cr: &cairo::Context,
1108    x: f64,
1109    y: f64,
1110    width: f64,
1111    height: f64,
1112) {
1113    skip_assert_initialized!();
1114    unsafe {
1115        ffi::gtk_render_background(
1116            context.as_ref().to_glib_none().0,
1117            mut_override(cr.to_glib_none().0),
1118            x,
1119            y,
1120            width,
1121            height,
1122        );
1123    }
1124}
1125
1126/// Returns the area that will be affected (i.e. drawn to) when
1127/// calling [`render_background()`][crate::render_background()] for the given `context` and
1128/// rectangle.
1129/// ## `context`
1130/// a [`StyleContext`][crate::StyleContext]
1131/// ## `x`
1132/// X origin of the rectangle
1133/// ## `y`
1134/// Y origin of the rectangle
1135/// ## `width`
1136/// rectangle width
1137/// ## `height`
1138/// rectangle height
1139///
1140/// # Returns
1141///
1142///
1143/// ## `out_clip`
1144/// return location for the clip
1145#[doc(alias = "gtk_render_background_get_clip")]
1146pub fn render_background_get_clip(
1147    context: &impl IsA<StyleContext>,
1148    x: f64,
1149    y: f64,
1150    width: f64,
1151    height: f64,
1152) -> gdk::Rectangle {
1153    skip_assert_initialized!();
1154    unsafe {
1155        let mut out_clip = gdk::Rectangle::uninitialized();
1156        ffi::gtk_render_background_get_clip(
1157            context.as_ref().to_glib_none().0,
1158            x,
1159            y,
1160            width,
1161            height,
1162            out_clip.to_glib_none_mut().0,
1163        );
1164        out_clip
1165    }
1166}
1167
1168/// Renders a checkmark (as in a [`CheckButton`][crate::CheckButton]).
1169///
1170/// The [`StateFlags::CHECKED`][crate::StateFlags::CHECKED] state determines whether the check is
1171/// on or off, and [`StateFlags::INCONSISTENT`][crate::StateFlags::INCONSISTENT] determines whether it
1172/// should be marked as undefined.
1173///
1174/// Typical checkmark rendering:
1175///
1176/// ![](checks.png)
1177/// ## `context`
1178/// a [`StyleContext`][crate::StyleContext]
1179/// ## `cr`
1180/// a [`cairo::Context`][crate::cairo::Context]
1181/// ## `x`
1182/// X origin of the rectangle
1183/// ## `y`
1184/// Y origin of the rectangle
1185/// ## `width`
1186/// rectangle width
1187/// ## `height`
1188/// rectangle height
1189#[doc(alias = "gtk_render_check")]
1190pub fn render_check(
1191    context: &impl IsA<StyleContext>,
1192    cr: &cairo::Context,
1193    x: f64,
1194    y: f64,
1195    width: f64,
1196    height: f64,
1197) {
1198    skip_assert_initialized!();
1199    unsafe {
1200        ffi::gtk_render_check(
1201            context.as_ref().to_glib_none().0,
1202            mut_override(cr.to_glib_none().0),
1203            x,
1204            y,
1205            width,
1206            height,
1207        );
1208    }
1209}
1210
1211/// Renders an expander (as used in [`TreeView`][crate::TreeView] and [`Expander`][crate::Expander]) in the area
1212/// defined by `x`, `y`, `width`, `height`. The state [`StateFlags::CHECKED`][crate::StateFlags::CHECKED]
1213/// determines whether the expander is collapsed or expanded.
1214///
1215/// Typical expander rendering:
1216///
1217/// ![](expanders.png)
1218/// ## `context`
1219/// a [`StyleContext`][crate::StyleContext]
1220/// ## `cr`
1221/// a [`cairo::Context`][crate::cairo::Context]
1222/// ## `x`
1223/// X origin of the rectangle
1224/// ## `y`
1225/// Y origin of the rectangle
1226/// ## `width`
1227/// rectangle width
1228/// ## `height`
1229/// rectangle height
1230#[doc(alias = "gtk_render_expander")]
1231pub fn render_expander(
1232    context: &impl IsA<StyleContext>,
1233    cr: &cairo::Context,
1234    x: f64,
1235    y: f64,
1236    width: f64,
1237    height: f64,
1238) {
1239    skip_assert_initialized!();
1240    unsafe {
1241        ffi::gtk_render_expander(
1242            context.as_ref().to_glib_none().0,
1243            mut_override(cr.to_glib_none().0),
1244            x,
1245            y,
1246            width,
1247            height,
1248        );
1249    }
1250}
1251
1252/// Renders a extension (as in a [`Notebook`][crate::Notebook] tab) in the rectangle
1253/// defined by `x`, `y`, `width`, `height`. The side where the extension
1254/// connects to is defined by `gap_side`.
1255///
1256/// Typical extension rendering:
1257///
1258/// ![](extensions.png)
1259/// ## `context`
1260/// a [`StyleContext`][crate::StyleContext]
1261/// ## `cr`
1262/// a [`cairo::Context`][crate::cairo::Context]
1263/// ## `x`
1264/// X origin of the rectangle
1265/// ## `y`
1266/// Y origin of the rectangle
1267/// ## `width`
1268/// rectangle width
1269/// ## `height`
1270/// rectangle height
1271/// ## `gap_side`
1272/// side where the gap is
1273#[doc(alias = "gtk_render_extension")]
1274pub fn render_extension(
1275    context: &impl IsA<StyleContext>,
1276    cr: &cairo::Context,
1277    x: f64,
1278    y: f64,
1279    width: f64,
1280    height: f64,
1281    gap_side: PositionType,
1282) {
1283    skip_assert_initialized!();
1284    unsafe {
1285        ffi::gtk_render_extension(
1286            context.as_ref().to_glib_none().0,
1287            mut_override(cr.to_glib_none().0),
1288            x,
1289            y,
1290            width,
1291            height,
1292            gap_side.into_glib(),
1293        );
1294    }
1295}
1296
1297/// Renders a focus indicator on the rectangle determined by `x`, `y`, `width`, `height`.
1298///
1299/// Typical focus rendering:
1300///
1301/// ![](focus.png)
1302/// ## `context`
1303/// a [`StyleContext`][crate::StyleContext]
1304/// ## `cr`
1305/// a [`cairo::Context`][crate::cairo::Context]
1306/// ## `x`
1307/// X origin of the rectangle
1308/// ## `y`
1309/// Y origin of the rectangle
1310/// ## `width`
1311/// rectangle width
1312/// ## `height`
1313/// rectangle height
1314#[doc(alias = "gtk_render_focus")]
1315pub fn render_focus(
1316    context: &impl IsA<StyleContext>,
1317    cr: &cairo::Context,
1318    x: f64,
1319    y: f64,
1320    width: f64,
1321    height: f64,
1322) {
1323    skip_assert_initialized!();
1324    unsafe {
1325        ffi::gtk_render_focus(
1326            context.as_ref().to_glib_none().0,
1327            mut_override(cr.to_glib_none().0),
1328            x,
1329            y,
1330            width,
1331            height,
1332        );
1333    }
1334}
1335
1336/// Renders a frame around the rectangle defined by `x`, `y`, `width`, `height`.
1337///
1338/// Examples of frame rendering, showing the effect of `border-image`,
1339/// `border-color`, `border-width`, `border-radius` and junctions:
1340///
1341/// ![](frames.png)
1342/// ## `context`
1343/// a [`StyleContext`][crate::StyleContext]
1344/// ## `cr`
1345/// a [`cairo::Context`][crate::cairo::Context]
1346/// ## `x`
1347/// X origin of the rectangle
1348/// ## `y`
1349/// Y origin of the rectangle
1350/// ## `width`
1351/// rectangle width
1352/// ## `height`
1353/// rectangle height
1354#[doc(alias = "gtk_render_frame")]
1355pub fn render_frame(
1356    context: &impl IsA<StyleContext>,
1357    cr: &cairo::Context,
1358    x: f64,
1359    y: f64,
1360    width: f64,
1361    height: f64,
1362) {
1363    skip_assert_initialized!();
1364    unsafe {
1365        ffi::gtk_render_frame(
1366            context.as_ref().to_glib_none().0,
1367            mut_override(cr.to_glib_none().0),
1368            x,
1369            y,
1370            width,
1371            height,
1372        );
1373    }
1374}
1375
1376/// Renders a frame around the rectangle defined by (`x`, `y`, `width`, `height`),
1377/// leaving a gap on one side. `xy0_gap` and `xy1_gap` will mean X coordinates
1378/// for [`PositionType::Top`][crate::PositionType::Top] and [`PositionType::Bottom`][crate::PositionType::Bottom] gap sides, and Y coordinates for
1379/// [`PositionType::Left`][crate::PositionType::Left] and [`PositionType::Right`][crate::PositionType::Right].
1380///
1381/// Typical rendering of a frame with a gap:
1382///
1383/// ![](frame-gap.png)
1384///
1385/// # Deprecated since 3.24
1386///
1387/// Use [`render_frame()`][crate::render_frame()] instead. Themes can create gaps
1388///  by omitting borders via CSS.
1389/// ## `context`
1390/// a [`StyleContext`][crate::StyleContext]
1391/// ## `cr`
1392/// a [`cairo::Context`][crate::cairo::Context]
1393/// ## `x`
1394/// X origin of the rectangle
1395/// ## `y`
1396/// Y origin of the rectangle
1397/// ## `width`
1398/// rectangle width
1399/// ## `height`
1400/// rectangle height
1401/// ## `gap_side`
1402/// side where the gap is
1403/// ## `xy0_gap`
1404/// initial coordinate (X or Y depending on `gap_side`) for the gap
1405/// ## `xy1_gap`
1406/// end coordinate (X or Y depending on `gap_side`) for the gap
1407#[cfg_attr(feature = "v3_24", deprecated = "Since 3.24")]
1408#[allow(deprecated)]
1409#[doc(alias = "gtk_render_frame_gap")]
1410pub fn render_frame_gap(
1411    context: &impl IsA<StyleContext>,
1412    cr: &cairo::Context,
1413    x: f64,
1414    y: f64,
1415    width: f64,
1416    height: f64,
1417    gap_side: PositionType,
1418    xy0_gap: f64,
1419    xy1_gap: f64,
1420) {
1421    skip_assert_initialized!();
1422    unsafe {
1423        ffi::gtk_render_frame_gap(
1424            context.as_ref().to_glib_none().0,
1425            mut_override(cr.to_glib_none().0),
1426            x,
1427            y,
1428            width,
1429            height,
1430            gap_side.into_glib(),
1431            xy0_gap,
1432            xy1_gap,
1433        );
1434    }
1435}
1436
1437/// Renders a handle (as in `GtkHandleBox`, [`Paned`][crate::Paned] and
1438/// [`Window`][crate::Window]’s resize grip), in the rectangle
1439/// determined by `x`, `y`, `width`, `height`.
1440///
1441/// Handles rendered for the paned and grip classes:
1442///
1443/// ![](handles.png)
1444/// ## `context`
1445/// a [`StyleContext`][crate::StyleContext]
1446/// ## `cr`
1447/// a [`cairo::Context`][crate::cairo::Context]
1448/// ## `x`
1449/// X origin of the rectangle
1450/// ## `y`
1451/// Y origin of the rectangle
1452/// ## `width`
1453/// rectangle width
1454/// ## `height`
1455/// rectangle height
1456#[doc(alias = "gtk_render_handle")]
1457pub fn render_handle(
1458    context: &impl IsA<StyleContext>,
1459    cr: &cairo::Context,
1460    x: f64,
1461    y: f64,
1462    width: f64,
1463    height: f64,
1464) {
1465    skip_assert_initialized!();
1466    unsafe {
1467        ffi::gtk_render_handle(
1468            context.as_ref().to_glib_none().0,
1469            mut_override(cr.to_glib_none().0),
1470            x,
1471            y,
1472            width,
1473            height,
1474        );
1475    }
1476}
1477
1478/// Renders the icon in `pixbuf` at the specified `x` and `y` coordinates.
1479///
1480/// This function will render the icon in `pixbuf` at exactly its size,
1481/// regardless of scaling factors, which may not be appropriate when
1482/// drawing on displays with high pixel densities.
1483///
1484/// You probably want to use [`render_icon_surface()`][crate::render_icon_surface()] instead, if you
1485/// already have a Cairo surface.
1486/// ## `context`
1487/// a [`StyleContext`][crate::StyleContext]
1488/// ## `cr`
1489/// a [`cairo::Context`][crate::cairo::Context]
1490/// ## `pixbuf`
1491/// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] containing the icon to draw
1492/// ## `x`
1493/// X position for the `pixbuf`
1494/// ## `y`
1495/// Y position for the `pixbuf`
1496#[doc(alias = "gtk_render_icon")]
1497pub fn render_icon(
1498    context: &impl IsA<StyleContext>,
1499    cr: &cairo::Context,
1500    pixbuf: &gdk_pixbuf::Pixbuf,
1501    x: f64,
1502    y: f64,
1503) {
1504    skip_assert_initialized!();
1505    unsafe {
1506        ffi::gtk_render_icon(
1507            context.as_ref().to_glib_none().0,
1508            mut_override(cr.to_glib_none().0),
1509            pixbuf.to_glib_none().0,
1510            x,
1511            y,
1512        );
1513    }
1514}
1515
1516/// Renders the icon in `surface` at the specified `x` and `y` coordinates.
1517/// ## `context`
1518/// a [`StyleContext`][crate::StyleContext]
1519/// ## `cr`
1520/// a [`cairo::Context`][crate::cairo::Context]
1521/// ## `surface`
1522/// a [`cairo::Surface`][crate::cairo::Surface] containing the icon to draw
1523/// ## `x`
1524/// X position for the `icon`
1525/// ## `y`
1526/// Y position for the `incon`
1527#[doc(alias = "gtk_render_icon_surface")]
1528pub fn render_icon_surface(
1529    context: &impl IsA<StyleContext>,
1530    cr: &cairo::Context,
1531    surface: &cairo::Surface,
1532    x: f64,
1533    y: f64,
1534) {
1535    skip_assert_initialized!();
1536    unsafe {
1537        ffi::gtk_render_icon_surface(
1538            context.as_ref().to_glib_none().0,
1539            mut_override(cr.to_glib_none().0),
1540            mut_override(surface.to_glib_none().0),
1541            x,
1542            y,
1543        );
1544    }
1545}
1546
1547/// Draws a text caret on `cr` at the specified index of `layout`.
1548/// ## `context`
1549/// a [`StyleContext`][crate::StyleContext]
1550/// ## `cr`
1551/// a [`cairo::Context`][crate::cairo::Context]
1552/// ## `x`
1553/// X origin
1554/// ## `y`
1555/// Y origin
1556/// ## `layout`
1557/// the [`pango::Layout`][crate::pango::Layout] of the text
1558/// ## `index`
1559/// the index in the [`pango::Layout`][crate::pango::Layout]
1560/// ## `direction`
1561/// the [`pango::Direction`][crate::pango::Direction] of the text
1562#[doc(alias = "gtk_render_insertion_cursor")]
1563pub fn render_insertion_cursor(
1564    context: &impl IsA<StyleContext>,
1565    cr: &cairo::Context,
1566    x: f64,
1567    y: f64,
1568    layout: &pango::Layout,
1569    index: i32,
1570    direction: pango::Direction,
1571) {
1572    skip_assert_initialized!();
1573    unsafe {
1574        ffi::gtk_render_insertion_cursor(
1575            context.as_ref().to_glib_none().0,
1576            mut_override(cr.to_glib_none().0),
1577            x,
1578            y,
1579            layout.to_glib_none().0,
1580            index,
1581            direction.into_glib(),
1582        );
1583    }
1584}
1585
1586/// Renders `layout` on the coordinates `x`, `y`
1587/// ## `context`
1588/// a [`StyleContext`][crate::StyleContext]
1589/// ## `cr`
1590/// a [`cairo::Context`][crate::cairo::Context]
1591/// ## `x`
1592/// X origin
1593/// ## `y`
1594/// Y origin
1595/// ## `layout`
1596/// the [`pango::Layout`][crate::pango::Layout] to render
1597#[doc(alias = "gtk_render_layout")]
1598pub fn render_layout(
1599    context: &impl IsA<StyleContext>,
1600    cr: &cairo::Context,
1601    x: f64,
1602    y: f64,
1603    layout: &pango::Layout,
1604) {
1605    skip_assert_initialized!();
1606    unsafe {
1607        ffi::gtk_render_layout(
1608            context.as_ref().to_glib_none().0,
1609            mut_override(cr.to_glib_none().0),
1610            x,
1611            y,
1612            layout.to_glib_none().0,
1613        );
1614    }
1615}
1616
1617/// Renders a line from (x0, y0) to (x1, y1).
1618/// ## `context`
1619/// a [`StyleContext`][crate::StyleContext]
1620/// ## `cr`
1621/// a [`cairo::Context`][crate::cairo::Context]
1622/// ## `x0`
1623/// X coordinate for the origin of the line
1624/// ## `y0`
1625/// Y coordinate for the origin of the line
1626/// ## `x1`
1627/// X coordinate for the end of the line
1628/// ## `y1`
1629/// Y coordinate for the end of the line
1630#[doc(alias = "gtk_render_line")]
1631pub fn render_line(
1632    context: &impl IsA<StyleContext>,
1633    cr: &cairo::Context,
1634    x0: f64,
1635    y0: f64,
1636    x1: f64,
1637    y1: f64,
1638) {
1639    skip_assert_initialized!();
1640    unsafe {
1641        ffi::gtk_render_line(
1642            context.as_ref().to_glib_none().0,
1643            mut_override(cr.to_glib_none().0),
1644            x0,
1645            y0,
1646            x1,
1647            y1,
1648        );
1649    }
1650}
1651
1652/// Renders an option mark (as in a [`RadioButton`][crate::RadioButton]), the [`StateFlags::CHECKED`][crate::StateFlags::CHECKED]
1653/// state will determine whether the option is on or off, and
1654/// [`StateFlags::INCONSISTENT`][crate::StateFlags::INCONSISTENT] whether it should be marked as undefined.
1655///
1656/// Typical option mark rendering:
1657///
1658/// ![](options.png)
1659/// ## `context`
1660/// a [`StyleContext`][crate::StyleContext]
1661/// ## `cr`
1662/// a [`cairo::Context`][crate::cairo::Context]
1663/// ## `x`
1664/// X origin of the rectangle
1665/// ## `y`
1666/// Y origin of the rectangle
1667/// ## `width`
1668/// rectangle width
1669/// ## `height`
1670/// rectangle height
1671#[doc(alias = "gtk_render_option")]
1672pub fn render_option(
1673    context: &impl IsA<StyleContext>,
1674    cr: &cairo::Context,
1675    x: f64,
1676    y: f64,
1677    width: f64,
1678    height: f64,
1679) {
1680    skip_assert_initialized!();
1681    unsafe {
1682        ffi::gtk_render_option(
1683            context.as_ref().to_glib_none().0,
1684            mut_override(cr.to_glib_none().0),
1685            x,
1686            y,
1687            width,
1688            height,
1689        );
1690    }
1691}
1692
1693/// Renders a slider (as in [`Scale`][crate::Scale]) in the rectangle defined by `x`, `y`,
1694/// `width`, `height`. `orientation` defines whether the slider is vertical
1695/// or horizontal.
1696///
1697/// Typical slider rendering:
1698///
1699/// ![](sliders.png)
1700/// ## `context`
1701/// a [`StyleContext`][crate::StyleContext]
1702/// ## `cr`
1703/// a [`cairo::Context`][crate::cairo::Context]
1704/// ## `x`
1705/// X origin of the rectangle
1706/// ## `y`
1707/// Y origin of the rectangle
1708/// ## `width`
1709/// rectangle width
1710/// ## `height`
1711/// rectangle height
1712/// ## `orientation`
1713/// orientation of the slider
1714#[doc(alias = "gtk_render_slider")]
1715pub fn render_slider(
1716    context: &impl IsA<StyleContext>,
1717    cr: &cairo::Context,
1718    x: f64,
1719    y: f64,
1720    width: f64,
1721    height: f64,
1722    orientation: Orientation,
1723) {
1724    skip_assert_initialized!();
1725    unsafe {
1726        ffi::gtk_render_slider(
1727            context.as_ref().to_glib_none().0,
1728            mut_override(cr.to_glib_none().0),
1729            x,
1730            y,
1731            width,
1732            height,
1733            orientation.into_glib(),
1734        );
1735    }
1736}
1737
1738/// Converts a color from RGB space to HSV.
1739///
1740/// Input values must be in the [0.0, 1.0] range;
1741/// output values will be in the same range.
1742/// ## `r`
1743/// Red
1744/// ## `g`
1745/// Green
1746/// ## `b`
1747/// Blue
1748///
1749/// # Returns
1750///
1751///
1752/// ## `h`
1753/// Return value for the hue component
1754///
1755/// ## `s`
1756/// Return value for the saturation component
1757///
1758/// ## `v`
1759/// Return value for the value component
1760#[doc(alias = "gtk_rgb_to_hsv")]
1761pub fn rgb_to_hsv(r: f64, g: f64, b: f64) -> (f64, f64, f64) {
1762    assert_initialized_main_thread!();
1763    unsafe {
1764        let mut h = mem::MaybeUninit::uninit();
1765        let mut s = mem::MaybeUninit::uninit();
1766        let mut v = mem::MaybeUninit::uninit();
1767        ffi::gtk_rgb_to_hsv(r, g, b, h.as_mut_ptr(), s.as_mut_ptr(), v.as_mut_ptr());
1768        (h.assume_init(), s.assume_init(), v.assume_init())
1769    }
1770}
1771
1772/// Appends a specified target to the list of supported targets for a
1773/// given widget and selection.
1774/// ## `widget`
1775/// a [`Widget`][crate::Widget]
1776/// ## `selection`
1777/// the selection
1778/// ## `target`
1779/// target to add.
1780/// ## `info`
1781/// A unsigned integer which will be passed back to the application.
1782#[doc(alias = "gtk_selection_add_target")]
1783pub fn selection_add_target(
1784    widget: &impl IsA<Widget>,
1785    selection: &gdk::Atom,
1786    target: &gdk::Atom,
1787    info: u32,
1788) {
1789    skip_assert_initialized!();
1790    unsafe {
1791        ffi::gtk_selection_add_target(
1792            widget.as_ref().to_glib_none().0,
1793            selection.to_glib_none().0,
1794            target.to_glib_none().0,
1795            info,
1796        );
1797    }
1798}
1799
1800/// Remove all targets registered for the given selection for the
1801/// widget.
1802/// ## `widget`
1803/// a [`Widget`][crate::Widget]
1804/// ## `selection`
1805/// an atom representing a selection
1806#[doc(alias = "gtk_selection_clear_targets")]
1807pub fn selection_clear_targets(widget: &impl IsA<Widget>, selection: &gdk::Atom) {
1808    skip_assert_initialized!();
1809    unsafe {
1810        ffi::gtk_selection_clear_targets(
1811            widget.as_ref().to_glib_none().0,
1812            selection.to_glib_none().0,
1813        );
1814    }
1815}
1816
1817/// Requests the contents of a selection. When received,
1818/// a “selection-received” signal will be generated.
1819/// ## `widget`
1820/// The widget which acts as requestor
1821/// ## `selection`
1822/// Which selection to get
1823/// ## `target`
1824/// Form of information desired (e.g., STRING)
1825/// ## `time_`
1826/// Time of request (usually of triggering event)
1827///  In emergency, you could use `GDK_CURRENT_TIME`
1828///
1829/// # Returns
1830///
1831/// [`true`] if requested succeeded. [`false`] if we could not process
1832///  request. (e.g., there was already a request in process for
1833///  this widget).
1834#[doc(alias = "gtk_selection_convert")]
1835pub fn selection_convert(
1836    widget: &impl IsA<Widget>,
1837    selection: &gdk::Atom,
1838    target: &gdk::Atom,
1839    time_: u32,
1840) -> bool {
1841    skip_assert_initialized!();
1842    unsafe {
1843        from_glib(ffi::gtk_selection_convert(
1844            widget.as_ref().to_glib_none().0,
1845            selection.to_glib_none().0,
1846            target.to_glib_none().0,
1847            time_,
1848        ))
1849    }
1850}
1851
1852/// Claims ownership of a given selection for a particular widget,
1853/// or, if `widget` is [`None`], release ownership of the selection.
1854/// ## `widget`
1855/// a [`Widget`][crate::Widget], or [`None`].
1856/// ## `selection`
1857/// an interned atom representing the selection to claim
1858/// ## `time_`
1859/// timestamp with which to claim the selection
1860///
1861/// # Returns
1862///
1863/// [`true`] if the operation succeeded
1864#[doc(alias = "gtk_selection_owner_set")]
1865pub fn selection_owner_set(
1866    widget: Option<&impl IsA<Widget>>,
1867    selection: &gdk::Atom,
1868    time_: u32,
1869) -> bool {
1870    assert_initialized_main_thread!();
1871    unsafe {
1872        from_glib(ffi::gtk_selection_owner_set(
1873            widget.map(|p| p.as_ref()).to_glib_none().0,
1874            selection.to_glib_none().0,
1875            time_,
1876        ))
1877    }
1878}
1879
1880/// Claim ownership of a given selection for a particular widget, or,
1881/// if `widget` is [`None`], release ownership of the selection.
1882/// ## `display`
1883/// the [`gdk::Display`][crate::gdk::Display] where the selection is set
1884/// ## `widget`
1885/// new selection owner (a [`Widget`][crate::Widget]), or [`None`].
1886/// ## `selection`
1887/// an interned atom representing the selection to claim.
1888/// ## `time_`
1889/// timestamp with which to claim the selection
1890///
1891/// # Returns
1892///
1893/// TRUE if the operation succeeded
1894#[doc(alias = "gtk_selection_owner_set_for_display")]
1895pub fn selection_owner_set_for_display(
1896    display: &gdk::Display,
1897    widget: Option<&impl IsA<Widget>>,
1898    selection: &gdk::Atom,
1899    time_: u32,
1900) -> bool {
1901    assert_initialized_main_thread!();
1902    unsafe {
1903        from_glib(ffi::gtk_selection_owner_set_for_display(
1904            display.to_glib_none().0,
1905            widget.map(|p| p.as_ref()).to_glib_none().0,
1906            selection.to_glib_none().0,
1907            time_,
1908        ))
1909    }
1910}
1911
1912/// Removes all handlers and unsets ownership of all
1913/// selections for a widget. Called when widget is being
1914/// destroyed. This function will not generally be
1915/// called by applications.
1916/// ## `widget`
1917/// a [`Widget`][crate::Widget]
1918#[doc(alias = "gtk_selection_remove_all")]
1919pub fn selection_remove_all(widget: &impl IsA<Widget>) {
1920    skip_assert_initialized!();
1921    unsafe {
1922        ffi::gtk_selection_remove_all(widget.as_ref().to_glib_none().0);
1923    }
1924}
1925
1926/// Sets the GTK+ debug flags.
1927#[doc(alias = "gtk_set_debug_flags")]
1928pub fn set_debug_flags(flags: u32) {
1929    assert_initialized_main_thread!();
1930    unsafe {
1931        ffi::gtk_set_debug_flags(flags);
1932    }
1933}
1934
1935//#[doc(alias = "gtk_show_about_dialog")]
1936//pub fn show_about_dialog(parent: Option<&impl IsA<Window>>, first_property_name: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
1937//    unsafe { TODO: call ffi:gtk_show_about_dialog() }
1938//}
1939
1940/// This is a convenience function for launching the default application
1941/// to show the uri. The uri must be of a form understood by GIO (i.e. you
1942/// need to install gvfs to get support for uri schemes such as http://
1943/// or ftp://, as only local files are handled by GIO itself).
1944/// Typical examples are
1945/// - `file:///home/gnome/pict.jpg`
1946/// - `http://www.gnome.org`
1947/// - `mailto:me`gnome``
1948///
1949/// Ideally the timestamp is taken from the event triggering
1950/// the `gtk_show_uri()` call. If timestamp is not known you can take
1951/// `GDK_CURRENT_TIME`.
1952///
1953/// This is the recommended call to be used as it passes information
1954/// necessary for sandbox helpers to parent their dialogs properly.
1955/// ## `parent`
1956/// parent window
1957/// ## `uri`
1958/// the uri to show
1959/// ## `timestamp`
1960/// a timestamp to prevent focus stealing
1961///
1962/// # Returns
1963///
1964/// [`true`] on success, [`false`] on error
1965#[doc(alias = "gtk_show_uri_on_window")]
1966pub fn show_uri_on_window(
1967    parent: Option<&impl IsA<Window>>,
1968    uri: &str,
1969    timestamp: u32,
1970) -> Result<(), glib::Error> {
1971    assert_initialized_main_thread!();
1972    unsafe {
1973        let mut error = ptr::null_mut();
1974        let is_ok = ffi::gtk_show_uri_on_window(
1975            parent.map(|p| p.as_ref()).to_glib_none().0,
1976            uri.to_glib_none().0,
1977            timestamp,
1978            &mut error,
1979        );
1980        debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1981        if error.is_null() {
1982            Ok(())
1983        } else {
1984            Err(from_glib_full(error))
1985        }
1986    }
1987}
1988
1989/// Determines if any of the targets in `targets` can be used to
1990/// provide a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf].
1991/// ## `targets`
1992/// an array of `GdkAtoms`
1993/// ## `writable`
1994/// whether to accept only targets for which GTK+ knows
1995///  how to convert a pixbuf into the format
1996///
1997/// # Returns
1998///
1999/// [`true`] if `targets` include a suitable target for images,
2000///  otherwise [`false`].
2001#[doc(alias = "gtk_targets_include_image")]
2002pub fn targets_include_image(targets: &[gdk::Atom], writable: bool) -> bool {
2003    assert_initialized_main_thread!();
2004    let n_targets = targets.len() as _;
2005    unsafe {
2006        from_glib(ffi::gtk_targets_include_image(
2007            targets.to_glib_none().0,
2008            n_targets,
2009            writable.into_glib(),
2010        ))
2011    }
2012}
2013
2014/// Determines if any of the targets in `targets` can be used to
2015/// provide rich text.
2016/// ## `targets`
2017/// an array of `GdkAtoms`
2018/// ## `buffer`
2019/// a [`TextBuffer`][crate::TextBuffer]
2020///
2021/// # Returns
2022///
2023/// [`true`] if `targets` include a suitable target for rich text,
2024///  otherwise [`false`].
2025#[doc(alias = "gtk_targets_include_rich_text")]
2026pub fn targets_include_rich_text(targets: &[gdk::Atom], buffer: &impl IsA<TextBuffer>) -> bool {
2027    skip_assert_initialized!();
2028    let n_targets = targets.len() as _;
2029    unsafe {
2030        from_glib(ffi::gtk_targets_include_rich_text(
2031            targets.to_glib_none().0,
2032            n_targets,
2033            buffer.as_ref().to_glib_none().0,
2034        ))
2035    }
2036}
2037
2038/// Determines if any of the targets in `targets` can be used to
2039/// provide text.
2040/// ## `targets`
2041/// an array of `GdkAtoms`
2042///
2043/// # Returns
2044///
2045/// [`true`] if `targets` include a suitable target for text,
2046///  otherwise [`false`].
2047#[doc(alias = "gtk_targets_include_text")]
2048pub fn targets_include_text(targets: &[gdk::Atom]) -> bool {
2049    assert_initialized_main_thread!();
2050    let n_targets = targets.len() as _;
2051    unsafe {
2052        from_glib(ffi::gtk_targets_include_text(
2053            targets.to_glib_none().0,
2054            n_targets,
2055        ))
2056    }
2057}
2058
2059/// Determines if any of the targets in `targets` can be used to
2060/// provide an uri list.
2061/// ## `targets`
2062/// an array of `GdkAtoms`
2063///
2064/// # Returns
2065///
2066/// [`true`] if `targets` include a suitable target for uri lists,
2067///  otherwise [`false`].
2068#[doc(alias = "gtk_targets_include_uri")]
2069pub fn targets_include_uri(targets: &[gdk::Atom]) -> bool {
2070    assert_initialized_main_thread!();
2071    let n_targets = targets.len() as _;
2072    unsafe {
2073        from_glib(ffi::gtk_targets_include_uri(
2074            targets.to_glib_none().0,
2075            n_targets,
2076        ))
2077    }
2078}
2079
2080/// This function will search `widget` and all its descendants for a GtkLabel
2081/// widget with a text string matching `label_pattern`.
2082/// The `label_pattern` may contain asterisks “*” and question marks “?” as
2083/// placeholders, `g_pattern_match()` is used for the matching.
2084/// Note that locales other than "C“ tend to alter (translate” label strings,
2085/// so this function is genrally only useful in test programs with
2086/// predetermined locales, see `gtk_test_init()` for more details.
2087/// ## `widget`
2088/// Valid label or container widget.
2089/// ## `label_pattern`
2090/// Shell-glob pattern to match a label string.
2091///
2092/// # Returns
2093///
2094/// a GtkLabel widget if any is found.
2095#[doc(alias = "gtk_test_find_label")]
2096pub fn test_find_label(widget: &impl IsA<Widget>, label_pattern: &str) -> Option<Widget> {
2097    skip_assert_initialized!();
2098    unsafe {
2099        from_glib_none(ffi::gtk_test_find_label(
2100            widget.as_ref().to_glib_none().0,
2101            label_pattern.to_glib_none().0,
2102        ))
2103    }
2104}
2105
2106/// This function will search siblings of `base_widget` and siblings of its
2107/// ancestors for all widgets matching `widget_type`.
2108/// Of the matching widgets, the one that is geometrically closest to
2109/// `base_widget` will be returned.
2110/// The general purpose of this function is to find the most likely “action”
2111/// widget, relative to another labeling widget. Such as finding a
2112/// button or text entry widget, given its corresponding label widget.
2113/// ## `base_widget`
2114/// Valid widget, part of a widget hierarchy
2115/// ## `widget_type`
2116/// Type of a aearched for sibling widget
2117///
2118/// # Returns
2119///
2120/// a widget of type `widget_type` if any is found.
2121#[doc(alias = "gtk_test_find_sibling")]
2122pub fn test_find_sibling(
2123    base_widget: &impl IsA<Widget>,
2124    widget_type: glib::types::Type,
2125) -> Option<Widget> {
2126    skip_assert_initialized!();
2127    unsafe {
2128        from_glib_none(ffi::gtk_test_find_sibling(
2129            base_widget.as_ref().to_glib_none().0,
2130            widget_type.into_glib(),
2131        ))
2132    }
2133}
2134
2135/// This function will search the descendants of `widget` for a widget
2136/// of type `widget_type` that has a label matching `label_pattern` next
2137/// to it. This is most useful for automated GUI testing, e.g. to find
2138/// the “OK” button in a dialog and synthesize clicks on it.
2139/// However see [`test_find_label()`][crate::test_find_label()], [`test_find_sibling()`][crate::test_find_sibling()] and
2140/// `gtk_test_widget_click()` for possible caveats involving the search of
2141/// such widgets and synthesizing widget events.
2142/// ## `widget`
2143/// Container widget, usually a GtkWindow.
2144/// ## `label_pattern`
2145/// Shell-glob pattern to match a label string.
2146/// ## `widget_type`
2147/// Type of a aearched for label sibling widget.
2148///
2149/// # Returns
2150///
2151/// a valid widget if any is found or [`None`].
2152#[doc(alias = "gtk_test_find_widget")]
2153pub fn test_find_widget(
2154    widget: &impl IsA<Widget>,
2155    label_pattern: &str,
2156    widget_type: glib::types::Type,
2157) -> Option<Widget> {
2158    skip_assert_initialized!();
2159    unsafe {
2160        from_glib_none(ffi::gtk_test_find_widget(
2161            widget.as_ref().to_glib_none().0,
2162            label_pattern.to_glib_none().0,
2163            widget_type.into_glib(),
2164        ))
2165    }
2166}
2167
2168//#[doc(alias = "gtk_test_list_all_types")]
2169//pub fn test_list_all_types() -> /*Unimplemented*/CArray TypeId { ns_id: 0, id: 30 } {
2170//    unsafe { TODO: call ffi:gtk_test_list_all_types() }
2171//}
2172
2173/// Force registration of all core Gtk+ and Gdk object types.
2174/// This allowes to refer to any of those object types via
2175/// `g_type_from_name()` after calling this function.
2176#[doc(alias = "gtk_test_register_all_types")]
2177pub fn test_register_all_types() {
2178    assert_initialized_main_thread!();
2179    unsafe {
2180        ffi::gtk_test_register_all_types();
2181    }
2182}
2183
2184/// This function will generate keyboard press and release events in
2185/// the middle of the first GdkWindow found that belongs to `widget`.
2186/// For windowless widgets like [`Button`][crate::Button] (which returns [`false`] from
2187/// [`WidgetExt::has_window()`][crate::prelude::WidgetExt::has_window()]), this will often be an
2188/// input-only event window. For other widgets, this is usually widget->window.
2189/// Certain caveats should be considered when using this function, in
2190/// particular because the mouse pointer is warped to the key press
2191/// location, see `gdk_test_simulate_key()` for details.
2192/// ## `widget`
2193/// Widget to generate a key press and release on.
2194/// ## `keyval`
2195/// A Gdk keyboard value.
2196/// ## `modifiers`
2197/// Keyboard modifiers the event is setup with.
2198///
2199/// # Returns
2200///
2201/// whether all actions neccessary for the key event simulation were carried out successfully.
2202#[doc(alias = "gtk_test_widget_send_key")]
2203pub fn test_widget_send_key(
2204    widget: &impl IsA<Widget>,
2205    keyval: u32,
2206    modifiers: gdk::ModifierType,
2207) -> bool {
2208    skip_assert_initialized!();
2209    unsafe {
2210        from_glib(ffi::gtk_test_widget_send_key(
2211            widget.as_ref().to_glib_none().0,
2212            keyval,
2213            modifiers.into_glib(),
2214        ))
2215    }
2216}
2217
2218/// Enters the main loop and waits for `widget` to be “drawn”. In this
2219/// context that means it waits for the frame clock of `widget` to have
2220/// run a full styling, layout and drawing cycle.
2221///
2222/// This function is intended to be used for syncing with actions that
2223/// depend on `widget` relayouting or on interaction with the display
2224/// server.
2225/// ## `widget`
2226/// the widget to wait for
2227#[doc(alias = "gtk_test_widget_wait_for_draw")]
2228pub fn test_widget_wait_for_draw(widget: &impl IsA<Widget>) {
2229    skip_assert_initialized!();
2230    unsafe {
2231        ffi::gtk_test_widget_wait_for_draw(widget.as_ref().to_glib_none().0);
2232    }
2233}
2234
2235/// Obtains a `tree_model` and `path` from selection data of target type
2236/// `GTK_TREE_MODEL_ROW`. Normally called from a drag_data_received handler.
2237/// This function can only be used if `selection_data` originates from the same
2238/// process that’s calling this function, because a pointer to the tree model
2239/// is being passed around. If you aren’t in the same process, then you'll
2240/// get memory corruption. In the [`TreeDragDest`][crate::TreeDragDest] drag_data_received handler,
2241/// you can assume that selection data of type `GTK_TREE_MODEL_ROW` is
2242/// in from the current process. The returned path must be freed with
2243/// `gtk_tree_path_free()`.
2244/// ## `selection_data`
2245/// a [`SelectionData`][crate::SelectionData]
2246///
2247/// # Returns
2248///
2249/// [`true`] if `selection_data` had target type `GTK_TREE_MODEL_ROW` and
2250///  is otherwise valid
2251///
2252/// ## `tree_model`
2253/// a [`TreeModel`][crate::TreeModel]
2254///
2255/// ## `path`
2256/// row in `tree_model`
2257#[doc(alias = "gtk_tree_get_row_drag_data")]
2258pub fn tree_get_row_drag_data(
2259    selection_data: &SelectionData,
2260) -> Option<(Option<TreeModel>, Option<TreePath>)> {
2261    assert_initialized_main_thread!();
2262    unsafe {
2263        let mut tree_model = ptr::null_mut();
2264        let mut path = ptr::null_mut();
2265        let ret = from_glib(ffi::gtk_tree_get_row_drag_data(
2266            mut_override(selection_data.to_glib_none().0),
2267            &mut tree_model,
2268            &mut path,
2269        ));
2270        if ret {
2271            Some((from_glib_none(tree_model), from_glib_full(path)))
2272        } else {
2273            None
2274        }
2275    }
2276}
2277
2278/// Sets selection data of target type `GTK_TREE_MODEL_ROW`. Normally used
2279/// in a drag_data_get handler.
2280/// ## `selection_data`
2281/// some [`SelectionData`][crate::SelectionData]
2282/// ## `tree_model`
2283/// a [`TreeModel`][crate::TreeModel]
2284/// ## `path`
2285/// a row in `tree_model`
2286///
2287/// # Returns
2288///
2289/// [`true`] if the [`SelectionData`][crate::SelectionData] had the proper target type to allow us to set a tree row
2290#[doc(alias = "gtk_tree_set_row_drag_data")]
2291pub fn tree_set_row_drag_data(
2292    selection_data: &SelectionData,
2293    tree_model: &impl IsA<TreeModel>,
2294    path: &mut TreePath,
2295) -> bool {
2296    skip_assert_initialized!();
2297    unsafe {
2298        from_glib(ffi::gtk_tree_set_row_drag_data(
2299            mut_override(selection_data.to_glib_none().0),
2300            tree_model.as_ref().to_glib_none().0,
2301            path.to_glib_none_mut().0,
2302        ))
2303    }
2304}
2305
2306#[doc(alias = "gtk_true")]
2307#[doc(alias = "true")]
2308pub fn true_() -> bool {
2309    assert_initialized_main_thread!();
2310    unsafe { from_glib(ffi::gtk_true()) }
2311}