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, ffi,
8};
9use glib::{prelude::*, translate::*};
10use std::boxed::Box as Box_;
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 = std::mem::MaybeUninit::uninit();
229 let mut accelerator_mods = std::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/// Analogical to [`true_()`][crate::true_()], this function does nothing
532/// but always returns [`false`].
533///
534/// # Returns
535///
536/// [`false`]
537#[doc(alias = "gtk_false")]
538#[doc(alias = "false")]
539pub fn false_() -> bool {
540 assert_initialized_main_thread!();
541 unsafe { from_glib(ffi::gtk_false()) }
542}
543
544/// Returns the binary age as passed to `libtool`
545/// when building the GTK+ library the process is running against.
546/// If `libtool` means nothing to you, don't
547/// worry about it.
548///
549/// # Returns
550///
551/// the binary age of the GTK+ library
552#[doc(alias = "gtk_get_binary_age")]
553#[doc(alias = "get_binary_age")]
554pub fn binary_age() -> u32 {
555 skip_assert_initialized!();
556 unsafe { ffi::gtk_get_binary_age() }
557}
558
559/// Obtains a copy of the event currently being processed by GTK+.
560///
561/// For example, if you are handling a [`clicked`][struct@crate::Button#clicked] signal,
562/// the current event will be the [`gdk::EventButton`][crate::gdk::EventButton] that triggered
563/// the ::clicked signal.
564///
565/// # Returns
566///
567/// a copy of the current event, or
568/// [`None`] if there is no current event. The returned event must be
569/// freed with `gdk_event_free()`.
570#[doc(alias = "gtk_get_current_event")]
571#[doc(alias = "get_current_event")]
572pub fn current_event() -> Option<gdk::Event> {
573 assert_initialized_main_thread!();
574 unsafe { from_glib_full(ffi::gtk_get_current_event()) }
575}
576
577/// If there is a current event and it has a device, return that
578/// device, otherwise return [`None`].
579///
580/// # Returns
581///
582/// a [`gdk::Device`][crate::gdk::Device], or [`None`]
583#[doc(alias = "gtk_get_current_event_device")]
584#[doc(alias = "get_current_event_device")]
585pub fn current_event_device() -> Option<gdk::Device> {
586 assert_initialized_main_thread!();
587 unsafe { from_glib_none(ffi::gtk_get_current_event_device()) }
588}
589
590/// If there is a current event and it has a state field, place
591/// that state field in `state` and return [`true`], otherwise return
592/// [`false`].
593///
594/// # Returns
595///
596/// [`true`] if there was a current event and it
597/// had a state field
598///
599/// ## `state`
600/// a location to store the state of the current event
601#[doc(alias = "gtk_get_current_event_state")]
602#[doc(alias = "get_current_event_state")]
603pub fn current_event_state() -> Option<gdk::ModifierType> {
604 assert_initialized_main_thread!();
605 unsafe {
606 let mut state = std::mem::MaybeUninit::uninit();
607 let ret = from_glib(ffi::gtk_get_current_event_state(state.as_mut_ptr()));
608 if ret {
609 Some(from_glib(state.assume_init()))
610 } else {
611 None
612 }
613 }
614}
615
616/// If there is a current event and it has a timestamp,
617/// return that timestamp, otherwise return `GDK_CURRENT_TIME`.
618///
619/// # Returns
620///
621/// the timestamp from the current event,
622/// or `GDK_CURRENT_TIME`.
623#[doc(alias = "gtk_get_current_event_time")]
624#[doc(alias = "get_current_event_time")]
625pub fn current_event_time() -> u32 {
626 assert_initialized_main_thread!();
627 unsafe { ffi::gtk_get_current_event_time() }
628}
629
630/// Returns the GTK+ debug flags.
631///
632/// This function is intended for GTK+ modules that want
633/// to adjust their debug output based on GTK+ debug flags.
634///
635/// # Returns
636///
637/// the GTK+ debug flags.
638#[doc(alias = "gtk_get_debug_flags")]
639#[doc(alias = "get_debug_flags")]
640pub fn debug_flags() -> u32 {
641 assert_initialized_main_thread!();
642 unsafe { ffi::gtk_get_debug_flags() }
643}
644
645/// Returns the [`pango::Language`][crate::pango::Language] for the default language currently in
646/// effect. (Note that this can change over the life of an
647/// application.) The default language is derived from the current
648/// locale. It determines, for example, whether GTK+ uses the
649/// right-to-left or left-to-right text direction.
650///
651/// This function is equivalent to [`pango::Language::default()`][crate::pango::Language::default()].
652/// See that function for details.
653///
654/// # Returns
655///
656/// the default language as a [`pango::Language`][crate::pango::Language],
657/// must not be freed
658#[doc(alias = "gtk_get_default_language")]
659#[doc(alias = "get_default_language")]
660pub fn default_language() -> Option<pango::Language> {
661 assert_initialized_main_thread!();
662 unsafe { from_glib_none(ffi::gtk_get_default_language()) }
663}
664
665/// If `event` is [`None`] or the event was not associated with any widget,
666/// returns [`None`], otherwise returns the widget that received the event
667/// originally.
668/// ## `event`
669/// a `GdkEvent`
670///
671/// # Returns
672///
673/// the widget that originally
674/// received `event`, or [`None`]
675#[doc(alias = "gtk_get_event_widget")]
676#[doc(alias = "get_event_widget")]
677pub fn event_widget(event: &mut gdk::Event) -> Option<Widget> {
678 assert_initialized_main_thread!();
679 unsafe { from_glib_none(ffi::gtk_get_event_widget(event.to_glib_none_mut().0)) }
680}
681
682/// Returns the interface age as passed to `libtool`
683/// when building the GTK+ library the process is running against.
684/// If `libtool` means nothing to you, don't
685/// worry about it.
686///
687/// # Returns
688///
689/// the interface age of the GTK+ library
690#[doc(alias = "gtk_get_interface_age")]
691#[doc(alias = "get_interface_age")]
692pub fn interface_age() -> u32 {
693 skip_assert_initialized!();
694 unsafe { ffi::gtk_get_interface_age() }
695}
696
697/// Get the direction of the current locale. This is the expected
698/// reading direction for text and UI.
699///
700/// This function depends on the current locale being set with
701/// `setlocale()` and will default to setting the [`TextDirection::Ltr`][crate::TextDirection::Ltr]
702/// direction otherwise. [`TextDirection::None`][crate::TextDirection::None] will never be returned.
703///
704/// GTK+ sets the default text direction according to the locale
705/// during `gtk_init()`, and you should normally use
706/// [`WidgetExt::direction()`][crate::prelude::WidgetExt::direction()] or [`Widget::default_direction()`][crate::Widget::default_direction()]
707/// to obtain the current direcion.
708///
709/// This function is only needed rare cases when the locale is
710/// changed after GTK+ has already been initialized. In this case,
711/// you can use it to update the default text direction as follows:
712///
713///
714///
715/// **⚠️ The following code is in C ⚠️**
716///
717/// ```C
718/// setlocale (LC_ALL, new_locale);
719/// direction = gtk_get_locale_direction ();
720/// gtk_widget_set_default_direction (direction);
721/// ```
722///
723/// # Returns
724///
725/// the [`TextDirection`][crate::TextDirection] of the current locale
726#[doc(alias = "gtk_get_locale_direction")]
727#[doc(alias = "get_locale_direction")]
728pub fn locale_direction() -> TextDirection {
729 assert_initialized_main_thread!();
730 unsafe { from_glib(ffi::gtk_get_locale_direction()) }
731}
732
733/// Returns the major version number of the GTK+ library.
734/// (e.g. in GTK+ version 3.1.5 this is 3.)
735///
736/// This function is in the library, so it represents the GTK+ library
737/// your code is running against. Contrast with the `GTK_MAJOR_VERSION`
738/// macro, which represents the major version of the GTK+ headers you
739/// have included when compiling your code.
740///
741/// # Returns
742///
743/// the major version number of the GTK+ library
744#[doc(alias = "gtk_get_major_version")]
745#[doc(alias = "get_major_version")]
746pub fn major_version() -> u32 {
747 skip_assert_initialized!();
748 unsafe { ffi::gtk_get_major_version() }
749}
750
751/// Returns the micro version number of the GTK+ library.
752/// (e.g. in GTK+ version 3.1.5 this is 5.)
753///
754/// This function is in the library, so it represents the GTK+ library
755/// your code is are running against. Contrast with the
756/// `GTK_MICRO_VERSION` macro, which represents the micro version of the
757/// GTK+ headers you have included when compiling your code.
758///
759/// # Returns
760///
761/// the micro version number of the GTK+ library
762#[doc(alias = "gtk_get_micro_version")]
763#[doc(alias = "get_micro_version")]
764pub fn micro_version() -> u32 {
765 skip_assert_initialized!();
766 unsafe { ffi::gtk_get_micro_version() }
767}
768
769/// Returns the minor version number of the GTK+ library.
770/// (e.g. in GTK+ version 3.1.5 this is 1.)
771///
772/// This function is in the library, so it represents the GTK+ library
773/// your code is are running against. Contrast with the
774/// `GTK_MINOR_VERSION` macro, which represents the minor version of the
775/// GTK+ headers you have included when compiling your code.
776///
777/// # Returns
778///
779/// the minor version number of the GTK+ library
780#[doc(alias = "gtk_get_minor_version")]
781#[doc(alias = "get_minor_version")]
782pub fn minor_version() -> u32 {
783 skip_assert_initialized!();
784 unsafe { ffi::gtk_get_minor_version() }
785}
786
787//#[doc(alias = "gtk_get_option_group")]
788//#[doc(alias = "get_option_group")]
789//pub fn option_group(open_default_display: bool) -> /*Ignored*/Option<glib::OptionGroup> {
790// unsafe { TODO: call ffi:gtk_get_option_group() }
791//}
792
793/// Queries the current grab of the default window group.
794///
795/// # Returns
796///
797/// The widget which currently
798/// has the grab or [`None`] if no grab is active
799#[doc(alias = "gtk_grab_get_current")]
800pub fn grab_get_current() -> Option<Widget> {
801 assert_initialized_main_thread!();
802 unsafe { from_glib_none(ffi::gtk_grab_get_current()) }
803}
804
805/// Runs the main loop until `gtk_main_quit()` is called.
806///
807/// You can nest calls to [`main()`][crate::main()]. In that case `gtk_main_quit()`
808/// will make the innermost invocation of the main loop return.
809#[doc(alias = "gtk_main")]
810pub fn main() {
811 assert_initialized_main_thread!();
812 unsafe {
813 ffi::gtk_main();
814 }
815}
816
817/// Processes a single GDK event.
818///
819/// This is public only to allow filtering of events between GDK and GTK+.
820/// You will not usually need to call this function directly.
821///
822/// While you should not call this function directly, you might want to
823/// know how exactly events are handled. So here is what this function
824/// does with the event:
825///
826/// 1. Compress enter/leave notify events. If the event passed build an
827/// enter/leave pair together with the next event (peeked from GDK), both
828/// events are thrown away. This is to avoid a backlog of (de-)highlighting
829/// widgets crossed by the pointer.
830///
831/// 2. Find the widget which got the event. If the widget can’t be determined
832/// the event is thrown away unless it belongs to a INCR transaction.
833///
834/// 3. Then the event is pushed onto a stack so you can query the currently
835/// handled event with [`current_event()`][crate::current_event()].
836///
837/// 4. The event is sent to a widget. If a grab is active all events for widgets
838/// that are not in the contained in the grab widget are sent to the latter
839/// with a few exceptions:
840/// - Deletion and destruction events are still sent to the event widget for
841/// obvious reasons.
842/// - Events which directly relate to the visual representation of the event
843/// widget.
844/// - Leave events are delivered to the event widget if there was an enter
845/// event delivered to it before without the paired leave event.
846/// - Drag events are not redirected because it is unclear what the semantics
847/// of that would be.
848/// Another point of interest might be that all key events are first passed
849/// through the key snooper functions if there are any. Read the description
850/// of `gtk_key_snooper_install()` if you need this feature.
851///
852/// 5. After finishing the delivery the event is popped from the event stack.
853/// ## `event`
854/// An event to process (normally passed by GDK)
855#[doc(alias = "gtk_main_do_event")]
856pub fn main_do_event(event: &mut gdk::Event) {
857 assert_initialized_main_thread!();
858 unsafe {
859 ffi::gtk_main_do_event(event.to_glib_none_mut().0);
860 }
861}
862
863/// Runs a single iteration of the mainloop.
864///
865/// If no events are waiting to be processed GTK+ will block
866/// until the next event is noticed. If you don’t want to block
867/// look at [`main_iteration_do()`][crate::main_iteration_do()] or check if any events are
868/// pending with [`events_pending()`][crate::events_pending()] first.
869///
870/// # Returns
871///
872/// [`true`] if `gtk_main_quit()` has been called for the
873/// innermost mainloop
874#[doc(alias = "gtk_main_iteration")]
875pub fn main_iteration() -> bool {
876 assert_initialized_main_thread!();
877 unsafe { from_glib(ffi::gtk_main_iteration()) }
878}
879
880/// Runs a single iteration of the mainloop.
881/// If no events are available either return or block depending on
882/// the value of `blocking`.
883/// ## `blocking`
884/// [`true`] if you want GTK+ to block if no events are pending
885///
886/// # Returns
887///
888/// [`true`] if `gtk_main_quit()` has been called for the
889/// innermost mainloop
890#[doc(alias = "gtk_main_iteration_do")]
891pub fn main_iteration_do(blocking: bool) -> bool {
892 assert_initialized_main_thread!();
893 unsafe { from_glib(ffi::gtk_main_iteration_do(blocking.into_glib())) }
894}
895
896/// Asks for the current nesting level of the main loop.
897///
898/// # Returns
899///
900/// the nesting level of the current invocation
901/// of the main loop
902#[doc(alias = "gtk_main_level")]
903pub fn main_level() -> u32 {
904 assert_initialized_main_thread!();
905 unsafe { ffi::gtk_main_level() }
906}
907
908/// Runs a page setup dialog, letting the user modify the values from
909/// `page_setup`. If the user cancels the dialog, the returned [`PageSetup`][crate::PageSetup]
910/// is identical to the passed in `page_setup`, otherwise it contains the
911/// modifications done in the dialog.
912///
913/// Note that this function may use a recursive mainloop to show the page
914/// setup dialog. See [`print_run_page_setup_dialog_async()`][crate::print_run_page_setup_dialog_async()] if this is
915/// a problem.
916/// ## `parent`
917/// transient parent
918/// ## `page_setup`
919/// an existing [`PageSetup`][crate::PageSetup]
920/// ## `settings`
921/// a [`PrintSettings`][crate::PrintSettings]
922///
923/// # Returns
924///
925/// a new [`PageSetup`][crate::PageSetup]
926#[doc(alias = "gtk_print_run_page_setup_dialog")]
927pub fn print_run_page_setup_dialog(
928 parent: Option<&impl IsA<Window>>,
929 page_setup: Option<&PageSetup>,
930 settings: &PrintSettings,
931) -> Option<PageSetup> {
932 skip_assert_initialized!();
933 unsafe {
934 from_glib_full(ffi::gtk_print_run_page_setup_dialog(
935 parent.map(|p| p.as_ref()).to_glib_none().0,
936 page_setup.to_glib_none().0,
937 settings.to_glib_none().0,
938 ))
939 }
940}
941
942/// Runs a page setup dialog, letting the user modify the values from `page_setup`.
943///
944/// In contrast to [`print_run_page_setup_dialog()`][crate::print_run_page_setup_dialog()], this function returns after
945/// showing the page setup dialog on platforms that support this, and calls `done_cb`
946/// from a signal handler for the ::response signal of the dialog.
947/// ## `parent`
948/// transient parent, or [`None`]
949/// ## `page_setup`
950/// an existing [`PageSetup`][crate::PageSetup], or [`None`]
951/// ## `settings`
952/// a [`PrintSettings`][crate::PrintSettings]
953/// ## `done_cb`
954/// a function to call when the user saves
955/// the modified page setup
956#[doc(alias = "gtk_print_run_page_setup_dialog_async")]
957pub fn print_run_page_setup_dialog_async<P: FnOnce(&PageSetup) + Send + Sync + 'static>(
958 parent: Option<&impl IsA<Window>>,
959 page_setup: Option<&PageSetup>,
960 settings: &PrintSettings,
961 done_cb: P,
962) {
963 skip_assert_initialized!();
964 let done_cb_data: Box_<P> = Box_::new(done_cb);
965 unsafe extern "C" fn done_cb_func<P: FnOnce(&PageSetup) + Send + Sync + 'static>(
966 page_setup: *mut ffi::GtkPageSetup,
967 data: glib::ffi::gpointer,
968 ) {
969 unsafe {
970 let page_setup = from_glib_borrow(page_setup);
971 let callback = Box_::from_raw(data as *mut P);
972 (*callback)(&page_setup)
973 }
974 }
975 let done_cb = Some(done_cb_func::<P> as _);
976 let super_callback0: Box_<P> = done_cb_data;
977 unsafe {
978 ffi::gtk_print_run_page_setup_dialog_async(
979 parent.map(|p| p.as_ref()).to_glib_none().0,
980 page_setup.to_glib_none().0,
981 settings.to_glib_none().0,
982 done_cb,
983 Box_::into_raw(super_callback0) as *mut _,
984 );
985 }
986}
987
988/// Sends an event to a widget, propagating the event to parent widgets
989/// if the event remains unhandled.
990///
991/// Events received by GTK+ from GDK normally begin in [`main_do_event()`][crate::main_do_event()].
992/// Depending on the type of event, existence of modal dialogs, grabs, etc.,
993/// the event may be propagated; if so, this function is used.
994///
995/// [`propagate_event()`][crate::propagate_event()] calls [`WidgetExt::event()`][crate::prelude::WidgetExt::event()] on each widget it
996/// decides to send the event to. So [`WidgetExt::event()`][crate::prelude::WidgetExt::event()] is the lowest-level
997/// function; it simply emits the [`event`][struct@crate::Widget#event] and possibly an
998/// event-specific signal on a widget. [`propagate_event()`][crate::propagate_event()] is a bit
999/// higher-level, and [`main_do_event()`][crate::main_do_event()] is the highest level.
1000///
1001/// All that said, you most likely don’t want to use any of these
1002/// functions; synthesizing events is rarely needed. There are almost
1003/// certainly better ways to achieve your goals. For example, use
1004/// [`Window::invalidate_rect()`][crate::gdk::Window::invalidate_rect()] or [`WidgetExt::queue_draw()`][crate::prelude::WidgetExt::queue_draw()] instead
1005/// of making up expose events.
1006/// ## `widget`
1007/// a [`Widget`][crate::Widget]
1008/// ## `event`
1009/// an event
1010#[doc(alias = "gtk_propagate_event")]
1011pub fn propagate_event(widget: &impl IsA<Widget>, event: &mut gdk::Event) {
1012 skip_assert_initialized!();
1013 unsafe {
1014 ffi::gtk_propagate_event(widget.as_ref().to_glib_none().0, event.to_glib_none_mut().0);
1015 }
1016}
1017
1018/// Renders an activity indicator (such as in [`Spinner`][crate::Spinner]).
1019/// The state [`StateFlags::CHECKED`][crate::StateFlags::CHECKED] determines whether there is
1020/// activity going on.
1021/// ## `context`
1022/// a [`StyleContext`][crate::StyleContext]
1023/// ## `cr`
1024/// a [`cairo::Context`][crate::cairo::Context]
1025/// ## `x`
1026/// X origin of the rectangle
1027/// ## `y`
1028/// Y origin of the rectangle
1029/// ## `width`
1030/// rectangle width
1031/// ## `height`
1032/// rectangle height
1033#[doc(alias = "gtk_render_activity")]
1034pub fn render_activity(
1035 context: &impl IsA<StyleContext>,
1036 cr: &cairo::Context,
1037 x: f64,
1038 y: f64,
1039 width: f64,
1040 height: f64,
1041) {
1042 skip_assert_initialized!();
1043 unsafe {
1044 ffi::gtk_render_activity(
1045 context.as_ref().to_glib_none().0,
1046 mut_override(cr.to_glib_none().0),
1047 x,
1048 y,
1049 width,
1050 height,
1051 );
1052 }
1053}
1054
1055/// Renders an arrow pointing to `angle`.
1056///
1057/// Typical arrow rendering at 0, 1⁄2 π;, π; and 3⁄2 π:
1058///
1059/// 
1060/// ## `context`
1061/// a [`StyleContext`][crate::StyleContext]
1062/// ## `cr`
1063/// a [`cairo::Context`][crate::cairo::Context]
1064/// ## `angle`
1065/// arrow angle from 0 to 2 * `G_PI`, being 0 the arrow pointing to the north
1066/// ## `x`
1067/// X origin of the render area
1068/// ## `y`
1069/// Y origin of the render area
1070/// ## `size`
1071/// square side for render area
1072#[doc(alias = "gtk_render_arrow")]
1073pub fn render_arrow(
1074 context: &impl IsA<StyleContext>,
1075 cr: &cairo::Context,
1076 angle: f64,
1077 x: f64,
1078 y: f64,
1079 size: f64,
1080) {
1081 skip_assert_initialized!();
1082 unsafe {
1083 ffi::gtk_render_arrow(
1084 context.as_ref().to_glib_none().0,
1085 mut_override(cr.to_glib_none().0),
1086 angle,
1087 x,
1088 y,
1089 size,
1090 );
1091 }
1092}
1093
1094/// Renders the background of an element.
1095///
1096/// Typical background rendering, showing the effect of
1097/// `background-image`, `border-width` and `border-radius`:
1098///
1099/// 
1100/// ## `context`
1101/// a [`StyleContext`][crate::StyleContext]
1102/// ## `cr`
1103/// a [`cairo::Context`][crate::cairo::Context]
1104/// ## `x`
1105/// X origin of the rectangle
1106/// ## `y`
1107/// Y origin of the rectangle
1108/// ## `width`
1109/// rectangle width
1110/// ## `height`
1111/// rectangle height
1112#[doc(alias = "gtk_render_background")]
1113pub fn render_background(
1114 context: &impl IsA<StyleContext>,
1115 cr: &cairo::Context,
1116 x: f64,
1117 y: f64,
1118 width: f64,
1119 height: f64,
1120) {
1121 skip_assert_initialized!();
1122 unsafe {
1123 ffi::gtk_render_background(
1124 context.as_ref().to_glib_none().0,
1125 mut_override(cr.to_glib_none().0),
1126 x,
1127 y,
1128 width,
1129 height,
1130 );
1131 }
1132}
1133
1134/// Returns the area that will be affected (i.e. drawn to) when
1135/// calling [`render_background()`][crate::render_background()] for the given `context` and
1136/// rectangle.
1137/// ## `context`
1138/// a [`StyleContext`][crate::StyleContext]
1139/// ## `x`
1140/// X origin of the rectangle
1141/// ## `y`
1142/// Y origin of the rectangle
1143/// ## `width`
1144/// rectangle width
1145/// ## `height`
1146/// rectangle height
1147///
1148/// # Returns
1149///
1150///
1151/// ## `out_clip`
1152/// return location for the clip
1153#[doc(alias = "gtk_render_background_get_clip")]
1154pub fn render_background_get_clip(
1155 context: &impl IsA<StyleContext>,
1156 x: f64,
1157 y: f64,
1158 width: f64,
1159 height: f64,
1160) -> gdk::Rectangle {
1161 skip_assert_initialized!();
1162 unsafe {
1163 let mut out_clip = gdk::Rectangle::uninitialized();
1164 ffi::gtk_render_background_get_clip(
1165 context.as_ref().to_glib_none().0,
1166 x,
1167 y,
1168 width,
1169 height,
1170 out_clip.to_glib_none_mut().0,
1171 );
1172 out_clip
1173 }
1174}
1175
1176/// Renders a checkmark (as in a [`CheckButton`][crate::CheckButton]).
1177///
1178/// The [`StateFlags::CHECKED`][crate::StateFlags::CHECKED] state determines whether the check is
1179/// on or off, and [`StateFlags::INCONSISTENT`][crate::StateFlags::INCONSISTENT] determines whether it
1180/// should be marked as undefined.
1181///
1182/// Typical checkmark rendering:
1183///
1184/// 
1185/// ## `context`
1186/// a [`StyleContext`][crate::StyleContext]
1187/// ## `cr`
1188/// a [`cairo::Context`][crate::cairo::Context]
1189/// ## `x`
1190/// X origin of the rectangle
1191/// ## `y`
1192/// Y origin of the rectangle
1193/// ## `width`
1194/// rectangle width
1195/// ## `height`
1196/// rectangle height
1197#[doc(alias = "gtk_render_check")]
1198pub fn render_check(
1199 context: &impl IsA<StyleContext>,
1200 cr: &cairo::Context,
1201 x: f64,
1202 y: f64,
1203 width: f64,
1204 height: f64,
1205) {
1206 skip_assert_initialized!();
1207 unsafe {
1208 ffi::gtk_render_check(
1209 context.as_ref().to_glib_none().0,
1210 mut_override(cr.to_glib_none().0),
1211 x,
1212 y,
1213 width,
1214 height,
1215 );
1216 }
1217}
1218
1219/// Renders an expander (as used in [`TreeView`][crate::TreeView] and [`Expander`][crate::Expander]) in the area
1220/// defined by `x`, `y`, `width`, `height`. The state [`StateFlags::CHECKED`][crate::StateFlags::CHECKED]
1221/// determines whether the expander is collapsed or expanded.
1222///
1223/// Typical expander rendering:
1224///
1225/// 
1226/// ## `context`
1227/// a [`StyleContext`][crate::StyleContext]
1228/// ## `cr`
1229/// a [`cairo::Context`][crate::cairo::Context]
1230/// ## `x`
1231/// X origin of the rectangle
1232/// ## `y`
1233/// Y origin of the rectangle
1234/// ## `width`
1235/// rectangle width
1236/// ## `height`
1237/// rectangle height
1238#[doc(alias = "gtk_render_expander")]
1239pub fn render_expander(
1240 context: &impl IsA<StyleContext>,
1241 cr: &cairo::Context,
1242 x: f64,
1243 y: f64,
1244 width: f64,
1245 height: f64,
1246) {
1247 skip_assert_initialized!();
1248 unsafe {
1249 ffi::gtk_render_expander(
1250 context.as_ref().to_glib_none().0,
1251 mut_override(cr.to_glib_none().0),
1252 x,
1253 y,
1254 width,
1255 height,
1256 );
1257 }
1258}
1259
1260/// Renders a extension (as in a [`Notebook`][crate::Notebook] tab) in the rectangle
1261/// defined by `x`, `y`, `width`, `height`. The side where the extension
1262/// connects to is defined by `gap_side`.
1263///
1264/// Typical extension rendering:
1265///
1266/// 
1267/// ## `context`
1268/// a [`StyleContext`][crate::StyleContext]
1269/// ## `cr`
1270/// a [`cairo::Context`][crate::cairo::Context]
1271/// ## `x`
1272/// X origin of the rectangle
1273/// ## `y`
1274/// Y origin of the rectangle
1275/// ## `width`
1276/// rectangle width
1277/// ## `height`
1278/// rectangle height
1279/// ## `gap_side`
1280/// side where the gap is
1281#[doc(alias = "gtk_render_extension")]
1282pub fn render_extension(
1283 context: &impl IsA<StyleContext>,
1284 cr: &cairo::Context,
1285 x: f64,
1286 y: f64,
1287 width: f64,
1288 height: f64,
1289 gap_side: PositionType,
1290) {
1291 skip_assert_initialized!();
1292 unsafe {
1293 ffi::gtk_render_extension(
1294 context.as_ref().to_glib_none().0,
1295 mut_override(cr.to_glib_none().0),
1296 x,
1297 y,
1298 width,
1299 height,
1300 gap_side.into_glib(),
1301 );
1302 }
1303}
1304
1305/// Renders a focus indicator on the rectangle determined by `x`, `y`, `width`, `height`.
1306///
1307/// Typical focus rendering:
1308///
1309/// 
1310/// ## `context`
1311/// a [`StyleContext`][crate::StyleContext]
1312/// ## `cr`
1313/// a [`cairo::Context`][crate::cairo::Context]
1314/// ## `x`
1315/// X origin of the rectangle
1316/// ## `y`
1317/// Y origin of the rectangle
1318/// ## `width`
1319/// rectangle width
1320/// ## `height`
1321/// rectangle height
1322#[doc(alias = "gtk_render_focus")]
1323pub fn render_focus(
1324 context: &impl IsA<StyleContext>,
1325 cr: &cairo::Context,
1326 x: f64,
1327 y: f64,
1328 width: f64,
1329 height: f64,
1330) {
1331 skip_assert_initialized!();
1332 unsafe {
1333 ffi::gtk_render_focus(
1334 context.as_ref().to_glib_none().0,
1335 mut_override(cr.to_glib_none().0),
1336 x,
1337 y,
1338 width,
1339 height,
1340 );
1341 }
1342}
1343
1344/// Renders a frame around the rectangle defined by `x`, `y`, `width`, `height`.
1345///
1346/// Examples of frame rendering, showing the effect of `border-image`,
1347/// `border-color`, `border-width`, `border-radius` and junctions:
1348///
1349/// 
1350/// ## `context`
1351/// a [`StyleContext`][crate::StyleContext]
1352/// ## `cr`
1353/// a [`cairo::Context`][crate::cairo::Context]
1354/// ## `x`
1355/// X origin of the rectangle
1356/// ## `y`
1357/// Y origin of the rectangle
1358/// ## `width`
1359/// rectangle width
1360/// ## `height`
1361/// rectangle height
1362#[doc(alias = "gtk_render_frame")]
1363pub fn render_frame(
1364 context: &impl IsA<StyleContext>,
1365 cr: &cairo::Context,
1366 x: f64,
1367 y: f64,
1368 width: f64,
1369 height: f64,
1370) {
1371 skip_assert_initialized!();
1372 unsafe {
1373 ffi::gtk_render_frame(
1374 context.as_ref().to_glib_none().0,
1375 mut_override(cr.to_glib_none().0),
1376 x,
1377 y,
1378 width,
1379 height,
1380 );
1381 }
1382}
1383
1384/// Renders a frame around the rectangle defined by (`x`, `y`, `width`, `height`),
1385/// leaving a gap on one side. `xy0_gap` and `xy1_gap` will mean X coordinates
1386/// for [`PositionType::Top`][crate::PositionType::Top] and [`PositionType::Bottom`][crate::PositionType::Bottom] gap sides, and Y coordinates for
1387/// [`PositionType::Left`][crate::PositionType::Left] and [`PositionType::Right`][crate::PositionType::Right].
1388///
1389/// Typical rendering of a frame with a gap:
1390///
1391/// 
1392///
1393/// # Deprecated since 3.24
1394///
1395/// Use [`render_frame()`][crate::render_frame()] instead. Themes can create gaps
1396/// by omitting borders via CSS.
1397/// ## `context`
1398/// a [`StyleContext`][crate::StyleContext]
1399/// ## `cr`
1400/// a [`cairo::Context`][crate::cairo::Context]
1401/// ## `x`
1402/// X origin of the rectangle
1403/// ## `y`
1404/// Y origin of the rectangle
1405/// ## `width`
1406/// rectangle width
1407/// ## `height`
1408/// rectangle height
1409/// ## `gap_side`
1410/// side where the gap is
1411/// ## `xy0_gap`
1412/// initial coordinate (X or Y depending on `gap_side`) for the gap
1413/// ## `xy1_gap`
1414/// end coordinate (X or Y depending on `gap_side`) for the gap
1415#[cfg_attr(feature = "v3_24", deprecated = "Since 3.24")]
1416#[allow(deprecated)]
1417#[doc(alias = "gtk_render_frame_gap")]
1418pub fn render_frame_gap(
1419 context: &impl IsA<StyleContext>,
1420 cr: &cairo::Context,
1421 x: f64,
1422 y: f64,
1423 width: f64,
1424 height: f64,
1425 gap_side: PositionType,
1426 xy0_gap: f64,
1427 xy1_gap: f64,
1428) {
1429 skip_assert_initialized!();
1430 unsafe {
1431 ffi::gtk_render_frame_gap(
1432 context.as_ref().to_glib_none().0,
1433 mut_override(cr.to_glib_none().0),
1434 x,
1435 y,
1436 width,
1437 height,
1438 gap_side.into_glib(),
1439 xy0_gap,
1440 xy1_gap,
1441 );
1442 }
1443}
1444
1445/// Renders a handle (as in `GtkHandleBox`, [`Paned`][crate::Paned] and
1446/// [`Window`][crate::Window]’s resize grip), in the rectangle
1447/// determined by `x`, `y`, `width`, `height`.
1448///
1449/// Handles rendered for the paned and grip classes:
1450///
1451/// 
1452/// ## `context`
1453/// a [`StyleContext`][crate::StyleContext]
1454/// ## `cr`
1455/// a [`cairo::Context`][crate::cairo::Context]
1456/// ## `x`
1457/// X origin of the rectangle
1458/// ## `y`
1459/// Y origin of the rectangle
1460/// ## `width`
1461/// rectangle width
1462/// ## `height`
1463/// rectangle height
1464#[doc(alias = "gtk_render_handle")]
1465pub fn render_handle(
1466 context: &impl IsA<StyleContext>,
1467 cr: &cairo::Context,
1468 x: f64,
1469 y: f64,
1470 width: f64,
1471 height: f64,
1472) {
1473 skip_assert_initialized!();
1474 unsafe {
1475 ffi::gtk_render_handle(
1476 context.as_ref().to_glib_none().0,
1477 mut_override(cr.to_glib_none().0),
1478 x,
1479 y,
1480 width,
1481 height,
1482 );
1483 }
1484}
1485
1486/// Renders the icon in `pixbuf` at the specified `x` and `y` coordinates.
1487///
1488/// This function will render the icon in `pixbuf` at exactly its size,
1489/// regardless of scaling factors, which may not be appropriate when
1490/// drawing on displays with high pixel densities.
1491///
1492/// You probably want to use [`render_icon_surface()`][crate::render_icon_surface()] instead, if you
1493/// already have a Cairo surface.
1494/// ## `context`
1495/// a [`StyleContext`][crate::StyleContext]
1496/// ## `cr`
1497/// a [`cairo::Context`][crate::cairo::Context]
1498/// ## `pixbuf`
1499/// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] containing the icon to draw
1500/// ## `x`
1501/// X position for the `pixbuf`
1502/// ## `y`
1503/// Y position for the `pixbuf`
1504#[doc(alias = "gtk_render_icon")]
1505pub fn render_icon(
1506 context: &impl IsA<StyleContext>,
1507 cr: &cairo::Context,
1508 pixbuf: &gdk_pixbuf::Pixbuf,
1509 x: f64,
1510 y: f64,
1511) {
1512 skip_assert_initialized!();
1513 unsafe {
1514 ffi::gtk_render_icon(
1515 context.as_ref().to_glib_none().0,
1516 mut_override(cr.to_glib_none().0),
1517 pixbuf.to_glib_none().0,
1518 x,
1519 y,
1520 );
1521 }
1522}
1523
1524/// Renders the icon in `surface` at the specified `x` and `y` coordinates.
1525/// ## `context`
1526/// a [`StyleContext`][crate::StyleContext]
1527/// ## `cr`
1528/// a [`cairo::Context`][crate::cairo::Context]
1529/// ## `surface`
1530/// a [`cairo::Surface`][crate::cairo::Surface] containing the icon to draw
1531/// ## `x`
1532/// X position for the `icon`
1533/// ## `y`
1534/// Y position for the `incon`
1535#[doc(alias = "gtk_render_icon_surface")]
1536pub fn render_icon_surface(
1537 context: &impl IsA<StyleContext>,
1538 cr: &cairo::Context,
1539 surface: &cairo::Surface,
1540 x: f64,
1541 y: f64,
1542) {
1543 skip_assert_initialized!();
1544 unsafe {
1545 ffi::gtk_render_icon_surface(
1546 context.as_ref().to_glib_none().0,
1547 mut_override(cr.to_glib_none().0),
1548 mut_override(surface.to_glib_none().0),
1549 x,
1550 y,
1551 );
1552 }
1553}
1554
1555/// Draws a text caret on `cr` at the specified index of `layout`.
1556/// ## `context`
1557/// a [`StyleContext`][crate::StyleContext]
1558/// ## `cr`
1559/// a [`cairo::Context`][crate::cairo::Context]
1560/// ## `x`
1561/// X origin
1562/// ## `y`
1563/// Y origin
1564/// ## `layout`
1565/// the [`pango::Layout`][crate::pango::Layout] of the text
1566/// ## `index`
1567/// the index in the [`pango::Layout`][crate::pango::Layout]
1568/// ## `direction`
1569/// the [`pango::Direction`][crate::pango::Direction] of the text
1570#[doc(alias = "gtk_render_insertion_cursor")]
1571pub fn render_insertion_cursor(
1572 context: &impl IsA<StyleContext>,
1573 cr: &cairo::Context,
1574 x: f64,
1575 y: f64,
1576 layout: &pango::Layout,
1577 index: i32,
1578 direction: pango::Direction,
1579) {
1580 skip_assert_initialized!();
1581 unsafe {
1582 ffi::gtk_render_insertion_cursor(
1583 context.as_ref().to_glib_none().0,
1584 mut_override(cr.to_glib_none().0),
1585 x,
1586 y,
1587 layout.to_glib_none().0,
1588 index,
1589 direction.into_glib(),
1590 );
1591 }
1592}
1593
1594/// Renders `layout` on the coordinates `x`, `y`
1595/// ## `context`
1596/// a [`StyleContext`][crate::StyleContext]
1597/// ## `cr`
1598/// a [`cairo::Context`][crate::cairo::Context]
1599/// ## `x`
1600/// X origin
1601/// ## `y`
1602/// Y origin
1603/// ## `layout`
1604/// the [`pango::Layout`][crate::pango::Layout] to render
1605#[doc(alias = "gtk_render_layout")]
1606pub fn render_layout(
1607 context: &impl IsA<StyleContext>,
1608 cr: &cairo::Context,
1609 x: f64,
1610 y: f64,
1611 layout: &pango::Layout,
1612) {
1613 skip_assert_initialized!();
1614 unsafe {
1615 ffi::gtk_render_layout(
1616 context.as_ref().to_glib_none().0,
1617 mut_override(cr.to_glib_none().0),
1618 x,
1619 y,
1620 layout.to_glib_none().0,
1621 );
1622 }
1623}
1624
1625/// Renders a line from (x0, y0) to (x1, y1).
1626/// ## `context`
1627/// a [`StyleContext`][crate::StyleContext]
1628/// ## `cr`
1629/// a [`cairo::Context`][crate::cairo::Context]
1630/// ## `x0`
1631/// X coordinate for the origin of the line
1632/// ## `y0`
1633/// Y coordinate for the origin of the line
1634/// ## `x1`
1635/// X coordinate for the end of the line
1636/// ## `y1`
1637/// Y coordinate for the end of the line
1638#[doc(alias = "gtk_render_line")]
1639pub fn render_line(
1640 context: &impl IsA<StyleContext>,
1641 cr: &cairo::Context,
1642 x0: f64,
1643 y0: f64,
1644 x1: f64,
1645 y1: f64,
1646) {
1647 skip_assert_initialized!();
1648 unsafe {
1649 ffi::gtk_render_line(
1650 context.as_ref().to_glib_none().0,
1651 mut_override(cr.to_glib_none().0),
1652 x0,
1653 y0,
1654 x1,
1655 y1,
1656 );
1657 }
1658}
1659
1660/// Renders an option mark (as in a [`RadioButton`][crate::RadioButton]), the [`StateFlags::CHECKED`][crate::StateFlags::CHECKED]
1661/// state will determine whether the option is on or off, and
1662/// [`StateFlags::INCONSISTENT`][crate::StateFlags::INCONSISTENT] whether it should be marked as undefined.
1663///
1664/// Typical option mark rendering:
1665///
1666/// 
1667/// ## `context`
1668/// a [`StyleContext`][crate::StyleContext]
1669/// ## `cr`
1670/// a [`cairo::Context`][crate::cairo::Context]
1671/// ## `x`
1672/// X origin of the rectangle
1673/// ## `y`
1674/// Y origin of the rectangle
1675/// ## `width`
1676/// rectangle width
1677/// ## `height`
1678/// rectangle height
1679#[doc(alias = "gtk_render_option")]
1680pub fn render_option(
1681 context: &impl IsA<StyleContext>,
1682 cr: &cairo::Context,
1683 x: f64,
1684 y: f64,
1685 width: f64,
1686 height: f64,
1687) {
1688 skip_assert_initialized!();
1689 unsafe {
1690 ffi::gtk_render_option(
1691 context.as_ref().to_glib_none().0,
1692 mut_override(cr.to_glib_none().0),
1693 x,
1694 y,
1695 width,
1696 height,
1697 );
1698 }
1699}
1700
1701/// Renders a slider (as in [`Scale`][crate::Scale]) in the rectangle defined by `x`, `y`,
1702/// `width`, `height`. `orientation` defines whether the slider is vertical
1703/// or horizontal.
1704///
1705/// Typical slider rendering:
1706///
1707/// 
1708/// ## `context`
1709/// a [`StyleContext`][crate::StyleContext]
1710/// ## `cr`
1711/// a [`cairo::Context`][crate::cairo::Context]
1712/// ## `x`
1713/// X origin of the rectangle
1714/// ## `y`
1715/// Y origin of the rectangle
1716/// ## `width`
1717/// rectangle width
1718/// ## `height`
1719/// rectangle height
1720/// ## `orientation`
1721/// orientation of the slider
1722#[doc(alias = "gtk_render_slider")]
1723pub fn render_slider(
1724 context: &impl IsA<StyleContext>,
1725 cr: &cairo::Context,
1726 x: f64,
1727 y: f64,
1728 width: f64,
1729 height: f64,
1730 orientation: Orientation,
1731) {
1732 skip_assert_initialized!();
1733 unsafe {
1734 ffi::gtk_render_slider(
1735 context.as_ref().to_glib_none().0,
1736 mut_override(cr.to_glib_none().0),
1737 x,
1738 y,
1739 width,
1740 height,
1741 orientation.into_glib(),
1742 );
1743 }
1744}
1745
1746/// Converts a color from RGB space to HSV.
1747///
1748/// Input values must be in the [0.0, 1.0] range;
1749/// output values will be in the same range.
1750/// ## `r`
1751/// Red
1752/// ## `g`
1753/// Green
1754/// ## `b`
1755/// Blue
1756///
1757/// # Returns
1758///
1759///
1760/// ## `h`
1761/// Return value for the hue component
1762///
1763/// ## `s`
1764/// Return value for the saturation component
1765///
1766/// ## `v`
1767/// Return value for the value component
1768#[doc(alias = "gtk_rgb_to_hsv")]
1769pub fn rgb_to_hsv(r: f64, g: f64, b: f64) -> (f64, f64, f64) {
1770 assert_initialized_main_thread!();
1771 unsafe {
1772 let mut h = std::mem::MaybeUninit::uninit();
1773 let mut s = std::mem::MaybeUninit::uninit();
1774 let mut v = std::mem::MaybeUninit::uninit();
1775 ffi::gtk_rgb_to_hsv(r, g, b, h.as_mut_ptr(), s.as_mut_ptr(), v.as_mut_ptr());
1776 (h.assume_init(), s.assume_init(), v.assume_init())
1777 }
1778}
1779
1780/// Appends a specified target to the list of supported targets for a
1781/// given widget and selection.
1782/// ## `widget`
1783/// a [`Widget`][crate::Widget]
1784/// ## `selection`
1785/// the selection
1786/// ## `target`
1787/// target to add.
1788/// ## `info`
1789/// A unsigned integer which will be passed back to the application.
1790#[doc(alias = "gtk_selection_add_target")]
1791pub fn selection_add_target(
1792 widget: &impl IsA<Widget>,
1793 selection: &gdk::Atom,
1794 target: &gdk::Atom,
1795 info: u32,
1796) {
1797 skip_assert_initialized!();
1798 unsafe {
1799 ffi::gtk_selection_add_target(
1800 widget.as_ref().to_glib_none().0,
1801 selection.to_glib_none().0,
1802 target.to_glib_none().0,
1803 info,
1804 );
1805 }
1806}
1807
1808/// Remove all targets registered for the given selection for the
1809/// widget.
1810/// ## `widget`
1811/// a [`Widget`][crate::Widget]
1812/// ## `selection`
1813/// an atom representing a selection
1814#[doc(alias = "gtk_selection_clear_targets")]
1815pub fn selection_clear_targets(widget: &impl IsA<Widget>, selection: &gdk::Atom) {
1816 skip_assert_initialized!();
1817 unsafe {
1818 ffi::gtk_selection_clear_targets(
1819 widget.as_ref().to_glib_none().0,
1820 selection.to_glib_none().0,
1821 );
1822 }
1823}
1824
1825/// Requests the contents of a selection. When received,
1826/// a “selection-received” signal will be generated.
1827/// ## `widget`
1828/// The widget which acts as requestor
1829/// ## `selection`
1830/// Which selection to get
1831/// ## `target`
1832/// Form of information desired (e.g., STRING)
1833/// ## `time_`
1834/// Time of request (usually of triggering event)
1835/// In emergency, you could use `GDK_CURRENT_TIME`
1836///
1837/// # Returns
1838///
1839/// [`true`] if requested succeeded. [`false`] if we could not process
1840/// request. (e.g., there was already a request in process for
1841/// this widget).
1842#[doc(alias = "gtk_selection_convert")]
1843pub fn selection_convert(
1844 widget: &impl IsA<Widget>,
1845 selection: &gdk::Atom,
1846 target: &gdk::Atom,
1847 time_: u32,
1848) -> bool {
1849 skip_assert_initialized!();
1850 unsafe {
1851 from_glib(ffi::gtk_selection_convert(
1852 widget.as_ref().to_glib_none().0,
1853 selection.to_glib_none().0,
1854 target.to_glib_none().0,
1855 time_,
1856 ))
1857 }
1858}
1859
1860/// Claims ownership of a given selection for a particular widget,
1861/// or, if `widget` is [`None`], release ownership of the selection.
1862/// ## `widget`
1863/// a [`Widget`][crate::Widget], or [`None`].
1864/// ## `selection`
1865/// an interned atom representing the selection to claim
1866/// ## `time_`
1867/// timestamp with which to claim the selection
1868///
1869/// # Returns
1870///
1871/// [`true`] if the operation succeeded
1872#[doc(alias = "gtk_selection_owner_set")]
1873pub fn selection_owner_set(
1874 widget: Option<&impl IsA<Widget>>,
1875 selection: &gdk::Atom,
1876 time_: u32,
1877) -> bool {
1878 assert_initialized_main_thread!();
1879 unsafe {
1880 from_glib(ffi::gtk_selection_owner_set(
1881 widget.map(|p| p.as_ref()).to_glib_none().0,
1882 selection.to_glib_none().0,
1883 time_,
1884 ))
1885 }
1886}
1887
1888/// Claim ownership of a given selection for a particular widget, or,
1889/// if `widget` is [`None`], release ownership of the selection.
1890/// ## `display`
1891/// the [`gdk::Display`][crate::gdk::Display] where the selection is set
1892/// ## `widget`
1893/// new selection owner (a [`Widget`][crate::Widget]), or [`None`].
1894/// ## `selection`
1895/// an interned atom representing the selection to claim.
1896/// ## `time_`
1897/// timestamp with which to claim the selection
1898///
1899/// # Returns
1900///
1901/// TRUE if the operation succeeded
1902#[doc(alias = "gtk_selection_owner_set_for_display")]
1903pub fn selection_owner_set_for_display(
1904 display: &gdk::Display,
1905 widget: Option<&impl IsA<Widget>>,
1906 selection: &gdk::Atom,
1907 time_: u32,
1908) -> bool {
1909 assert_initialized_main_thread!();
1910 unsafe {
1911 from_glib(ffi::gtk_selection_owner_set_for_display(
1912 display.to_glib_none().0,
1913 widget.map(|p| p.as_ref()).to_glib_none().0,
1914 selection.to_glib_none().0,
1915 time_,
1916 ))
1917 }
1918}
1919
1920/// Removes all handlers and unsets ownership of all
1921/// selections for a widget. Called when widget is being
1922/// destroyed. This function will not generally be
1923/// called by applications.
1924/// ## `widget`
1925/// a [`Widget`][crate::Widget]
1926#[doc(alias = "gtk_selection_remove_all")]
1927pub fn selection_remove_all(widget: &impl IsA<Widget>) {
1928 skip_assert_initialized!();
1929 unsafe {
1930 ffi::gtk_selection_remove_all(widget.as_ref().to_glib_none().0);
1931 }
1932}
1933
1934/// Sets the GTK+ debug flags.
1935#[doc(alias = "gtk_set_debug_flags")]
1936pub fn set_debug_flags(flags: u32) {
1937 assert_initialized_main_thread!();
1938 unsafe {
1939 ffi::gtk_set_debug_flags(flags);
1940 }
1941}
1942
1943//#[doc(alias = "gtk_show_about_dialog")]
1944//pub fn show_about_dialog(parent: Option<&impl IsA<Window>>, first_property_name: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
1945// unsafe { TODO: call ffi:gtk_show_about_dialog() }
1946//}
1947
1948/// This is a convenience function for launching the default application
1949/// to show the uri. The uri must be of a form understood by GIO (i.e. you
1950/// need to install gvfs to get support for uri schemes such as http://
1951/// or ftp://, as only local files are handled by GIO itself).
1952/// Typical examples are
1953/// - `file:///home/gnome/pict.jpg`
1954/// - `http://www.gnome.org`
1955/// - `mailto:me`gnome``
1956///
1957/// Ideally the timestamp is taken from the event triggering
1958/// the `gtk_show_uri()` call. If timestamp is not known you can take
1959/// `GDK_CURRENT_TIME`.
1960///
1961/// This is the recommended call to be used as it passes information
1962/// necessary for sandbox helpers to parent their dialogs properly.
1963/// ## `parent`
1964/// parent window
1965/// ## `uri`
1966/// the uri to show
1967/// ## `timestamp`
1968/// a timestamp to prevent focus stealing
1969///
1970/// # Returns
1971///
1972/// [`true`] on success, [`false`] on error
1973#[doc(alias = "gtk_show_uri_on_window")]
1974pub fn show_uri_on_window(
1975 parent: Option<&impl IsA<Window>>,
1976 uri: &str,
1977 timestamp: u32,
1978) -> Result<(), glib::Error> {
1979 assert_initialized_main_thread!();
1980 unsafe {
1981 let mut error = std::ptr::null_mut();
1982 let is_ok = ffi::gtk_show_uri_on_window(
1983 parent.map(|p| p.as_ref()).to_glib_none().0,
1984 uri.to_glib_none().0,
1985 timestamp,
1986 &mut error,
1987 );
1988 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1989 if error.is_null() {
1990 Ok(())
1991 } else {
1992 Err(from_glib_full(error))
1993 }
1994 }
1995}
1996
1997/// Determines if any of the targets in `targets` can be used to
1998/// provide a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf].
1999/// ## `targets`
2000/// an array of `GdkAtoms`
2001/// ## `writable`
2002/// whether to accept only targets for which GTK+ knows
2003/// how to convert a pixbuf into the format
2004///
2005/// # Returns
2006///
2007/// [`true`] if `targets` include a suitable target for images,
2008/// otherwise [`false`].
2009#[doc(alias = "gtk_targets_include_image")]
2010pub fn targets_include_image(targets: &[gdk::Atom], writable: bool) -> bool {
2011 assert_initialized_main_thread!();
2012 let n_targets = targets.len() as _;
2013 unsafe {
2014 from_glib(ffi::gtk_targets_include_image(
2015 targets.to_glib_none().0,
2016 n_targets,
2017 writable.into_glib(),
2018 ))
2019 }
2020}
2021
2022/// Determines if any of the targets in `targets` can be used to
2023/// provide rich text.
2024/// ## `targets`
2025/// an array of `GdkAtoms`
2026/// ## `buffer`
2027/// a [`TextBuffer`][crate::TextBuffer]
2028///
2029/// # Returns
2030///
2031/// [`true`] if `targets` include a suitable target for rich text,
2032/// otherwise [`false`].
2033#[doc(alias = "gtk_targets_include_rich_text")]
2034pub fn targets_include_rich_text(targets: &[gdk::Atom], buffer: &impl IsA<TextBuffer>) -> bool {
2035 skip_assert_initialized!();
2036 let n_targets = targets.len() as _;
2037 unsafe {
2038 from_glib(ffi::gtk_targets_include_rich_text(
2039 targets.to_glib_none().0,
2040 n_targets,
2041 buffer.as_ref().to_glib_none().0,
2042 ))
2043 }
2044}
2045
2046/// Determines if any of the targets in `targets` can be used to
2047/// provide text.
2048/// ## `targets`
2049/// an array of `GdkAtoms`
2050///
2051/// # Returns
2052///
2053/// [`true`] if `targets` include a suitable target for text,
2054/// otherwise [`false`].
2055#[doc(alias = "gtk_targets_include_text")]
2056pub fn targets_include_text(targets: &[gdk::Atom]) -> bool {
2057 assert_initialized_main_thread!();
2058 let n_targets = targets.len() as _;
2059 unsafe {
2060 from_glib(ffi::gtk_targets_include_text(
2061 targets.to_glib_none().0,
2062 n_targets,
2063 ))
2064 }
2065}
2066
2067/// Determines if any of the targets in `targets` can be used to
2068/// provide an uri list.
2069/// ## `targets`
2070/// an array of `GdkAtoms`
2071///
2072/// # Returns
2073///
2074/// [`true`] if `targets` include a suitable target for uri lists,
2075/// otherwise [`false`].
2076#[doc(alias = "gtk_targets_include_uri")]
2077pub fn targets_include_uri(targets: &[gdk::Atom]) -> bool {
2078 assert_initialized_main_thread!();
2079 let n_targets = targets.len() as _;
2080 unsafe {
2081 from_glib(ffi::gtk_targets_include_uri(
2082 targets.to_glib_none().0,
2083 n_targets,
2084 ))
2085 }
2086}
2087
2088/// This function will search `widget` and all its descendants for a GtkLabel
2089/// widget with a text string matching `label_pattern`.
2090/// The `label_pattern` may contain asterisks “*” and question marks “?” as
2091/// placeholders, `g_pattern_match()` is used for the matching.
2092/// Note that locales other than "C“ tend to alter (translate” label strings,
2093/// so this function is genrally only useful in test programs with
2094/// predetermined locales, see `gtk_test_init()` for more details.
2095/// ## `widget`
2096/// Valid label or container widget.
2097/// ## `label_pattern`
2098/// Shell-glob pattern to match a label string.
2099///
2100/// # Returns
2101///
2102/// a GtkLabel widget if any is found.
2103#[doc(alias = "gtk_test_find_label")]
2104pub fn test_find_label(widget: &impl IsA<Widget>, label_pattern: &str) -> Option<Widget> {
2105 skip_assert_initialized!();
2106 unsafe {
2107 from_glib_none(ffi::gtk_test_find_label(
2108 widget.as_ref().to_glib_none().0,
2109 label_pattern.to_glib_none().0,
2110 ))
2111 }
2112}
2113
2114/// This function will search siblings of `base_widget` and siblings of its
2115/// ancestors for all widgets matching `widget_type`.
2116/// Of the matching widgets, the one that is geometrically closest to
2117/// `base_widget` will be returned.
2118/// The general purpose of this function is to find the most likely “action”
2119/// widget, relative to another labeling widget. Such as finding a
2120/// button or text entry widget, given its corresponding label widget.
2121/// ## `base_widget`
2122/// Valid widget, part of a widget hierarchy
2123/// ## `widget_type`
2124/// Type of a aearched for sibling widget
2125///
2126/// # Returns
2127///
2128/// a widget of type `widget_type` if any is found.
2129#[doc(alias = "gtk_test_find_sibling")]
2130pub fn test_find_sibling(
2131 base_widget: &impl IsA<Widget>,
2132 widget_type: glib::types::Type,
2133) -> Option<Widget> {
2134 skip_assert_initialized!();
2135 unsafe {
2136 from_glib_none(ffi::gtk_test_find_sibling(
2137 base_widget.as_ref().to_glib_none().0,
2138 widget_type.into_glib(),
2139 ))
2140 }
2141}
2142
2143/// This function will search the descendants of `widget` for a widget
2144/// of type `widget_type` that has a label matching `label_pattern` next
2145/// to it. This is most useful for automated GUI testing, e.g. to find
2146/// the “OK” button in a dialog and synthesize clicks on it.
2147/// However see [`test_find_label()`][crate::test_find_label()], [`test_find_sibling()`][crate::test_find_sibling()] and
2148/// `gtk_test_widget_click()` for possible caveats involving the search of
2149/// such widgets and synthesizing widget events.
2150/// ## `widget`
2151/// Container widget, usually a GtkWindow.
2152/// ## `label_pattern`
2153/// Shell-glob pattern to match a label string.
2154/// ## `widget_type`
2155/// Type of a aearched for label sibling widget.
2156///
2157/// # Returns
2158///
2159/// a valid widget if any is found or [`None`].
2160#[doc(alias = "gtk_test_find_widget")]
2161pub fn test_find_widget(
2162 widget: &impl IsA<Widget>,
2163 label_pattern: &str,
2164 widget_type: glib::types::Type,
2165) -> Option<Widget> {
2166 skip_assert_initialized!();
2167 unsafe {
2168 from_glib_none(ffi::gtk_test_find_widget(
2169 widget.as_ref().to_glib_none().0,
2170 label_pattern.to_glib_none().0,
2171 widget_type.into_glib(),
2172 ))
2173 }
2174}
2175
2176//#[doc(alias = "gtk_test_list_all_types")]
2177//pub fn test_list_all_types() -> /*Unimplemented*/CArray TypeId { ns_id: 0, id: 30 } {
2178// unsafe { TODO: call ffi:gtk_test_list_all_types() }
2179//}
2180
2181/// Force registration of all core Gtk+ and Gdk object types.
2182/// This allowes to refer to any of those object types via
2183/// `g_type_from_name()` after calling this function.
2184#[doc(alias = "gtk_test_register_all_types")]
2185pub fn test_register_all_types() {
2186 assert_initialized_main_thread!();
2187 unsafe {
2188 ffi::gtk_test_register_all_types();
2189 }
2190}
2191
2192/// This function will generate keyboard press and release events in
2193/// the middle of the first GdkWindow found that belongs to `widget`.
2194/// For windowless widgets like [`Button`][crate::Button] (which returns [`false`] from
2195/// [`WidgetExt::has_window()`][crate::prelude::WidgetExt::has_window()]), this will often be an
2196/// input-only event window. For other widgets, this is usually widget->window.
2197/// Certain caveats should be considered when using this function, in
2198/// particular because the mouse pointer is warped to the key press
2199/// location, see `gdk_test_simulate_key()` for details.
2200/// ## `widget`
2201/// Widget to generate a key press and release on.
2202/// ## `keyval`
2203/// A Gdk keyboard value.
2204/// ## `modifiers`
2205/// Keyboard modifiers the event is setup with.
2206///
2207/// # Returns
2208///
2209/// whether all actions neccessary for the key event simulation were carried out successfully.
2210#[doc(alias = "gtk_test_widget_send_key")]
2211pub fn test_widget_send_key(
2212 widget: &impl IsA<Widget>,
2213 keyval: u32,
2214 modifiers: gdk::ModifierType,
2215) -> bool {
2216 skip_assert_initialized!();
2217 unsafe {
2218 from_glib(ffi::gtk_test_widget_send_key(
2219 widget.as_ref().to_glib_none().0,
2220 keyval,
2221 modifiers.into_glib(),
2222 ))
2223 }
2224}
2225
2226/// Enters the main loop and waits for `widget` to be “drawn”. In this
2227/// context that means it waits for the frame clock of `widget` to have
2228/// run a full styling, layout and drawing cycle.
2229///
2230/// This function is intended to be used for syncing with actions that
2231/// depend on `widget` relayouting or on interaction with the display
2232/// server.
2233/// ## `widget`
2234/// the widget to wait for
2235#[doc(alias = "gtk_test_widget_wait_for_draw")]
2236pub fn test_widget_wait_for_draw(widget: &impl IsA<Widget>) {
2237 skip_assert_initialized!();
2238 unsafe {
2239 ffi::gtk_test_widget_wait_for_draw(widget.as_ref().to_glib_none().0);
2240 }
2241}
2242
2243/// Obtains a `tree_model` and `path` from selection data of target type
2244/// `GTK_TREE_MODEL_ROW`. Normally called from a drag_data_received handler.
2245/// This function can only be used if `selection_data` originates from the same
2246/// process that’s calling this function, because a pointer to the tree model
2247/// is being passed around. If you aren’t in the same process, then you'll
2248/// get memory corruption. In the [`TreeDragDest`][crate::TreeDragDest] drag_data_received handler,
2249/// you can assume that selection data of type `GTK_TREE_MODEL_ROW` is
2250/// in from the current process. The returned path must be freed with
2251/// `gtk_tree_path_free()`.
2252/// ## `selection_data`
2253/// a [`SelectionData`][crate::SelectionData]
2254///
2255/// # Returns
2256///
2257/// [`true`] if `selection_data` had target type `GTK_TREE_MODEL_ROW` and
2258/// is otherwise valid
2259///
2260/// ## `tree_model`
2261/// a [`TreeModel`][crate::TreeModel]
2262///
2263/// ## `path`
2264/// row in `tree_model`
2265#[doc(alias = "gtk_tree_get_row_drag_data")]
2266pub fn tree_get_row_drag_data(
2267 selection_data: &SelectionData,
2268) -> Option<(Option<TreeModel>, Option<TreePath>)> {
2269 assert_initialized_main_thread!();
2270 unsafe {
2271 let mut tree_model = std::ptr::null_mut();
2272 let mut path = std::ptr::null_mut();
2273 let ret = from_glib(ffi::gtk_tree_get_row_drag_data(
2274 mut_override(selection_data.to_glib_none().0),
2275 &mut tree_model,
2276 &mut path,
2277 ));
2278 if ret {
2279 Some((from_glib_none(tree_model), from_glib_full(path)))
2280 } else {
2281 None
2282 }
2283 }
2284}
2285
2286/// Sets selection data of target type `GTK_TREE_MODEL_ROW`. Normally used
2287/// in a drag_data_get handler.
2288/// ## `selection_data`
2289/// some [`SelectionData`][crate::SelectionData]
2290/// ## `tree_model`
2291/// a [`TreeModel`][crate::TreeModel]
2292/// ## `path`
2293/// a row in `tree_model`
2294///
2295/// # Returns
2296///
2297/// [`true`] if the [`SelectionData`][crate::SelectionData] had the proper target type to allow us to set a tree row
2298#[doc(alias = "gtk_tree_set_row_drag_data")]
2299pub fn tree_set_row_drag_data(
2300 selection_data: &SelectionData,
2301 tree_model: &impl IsA<TreeModel>,
2302 path: &mut TreePath,
2303) -> bool {
2304 skip_assert_initialized!();
2305 unsafe {
2306 from_glib(ffi::gtk_tree_set_row_drag_data(
2307 mut_override(selection_data.to_glib_none().0),
2308 tree_model.as_ref().to_glib_none().0,
2309 path.to_glib_none_mut().0,
2310 ))
2311 }
2312}
2313
2314/// All this function does it to return [`true`].
2315///
2316/// This can be useful for example if you want to inhibit the deletion
2317/// of a window. Of course you should not do this as the user expects
2318/// a reaction from clicking the close icon of the window...
2319///
2320/// ## A persistent window
2321///
2322///
2323///
2324/// **⚠️ The following code is in C ⚠️**
2325///
2326/// ```C
2327/// #include <gtk/gtk.h>
2328///
2329/// int
2330/// main (int argc, char **argv)
2331/// {
2332/// GtkWidget *win, *but;
2333/// const char *text = "Close yourself. I mean it!";
2334///
2335/// gtk_init (&argc, &argv);
2336///
2337/// win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
2338/// g_signal_connect (win,
2339/// "delete-event",
2340/// G_CALLBACK (gtk_true),
2341/// NULL);
2342/// g_signal_connect (win, "destroy",
2343/// G_CALLBACK (gtk_main_quit),
2344/// NULL);
2345///
2346/// but = gtk_button_new_with_label (text);
2347/// g_signal_connect_swapped (but, "clicked",
2348/// G_CALLBACK (gtk_object_destroy),
2349/// win);
2350/// gtk_container_add (GTK_CONTAINER (win), but);
2351///
2352/// gtk_widget_show_all (win);
2353///
2354/// gtk_main ();
2355///
2356/// return 0;
2357/// }
2358/// ```
2359///
2360/// # Returns
2361///
2362/// [`true`]
2363#[doc(alias = "gtk_true")]
2364#[doc(alias = "true")]
2365pub fn true_() -> bool {
2366 assert_initialized_main_thread!();
2367 unsafe { from_glib(ffi::gtk_true()) }
2368}