Skip to main content

atk/auto/
value.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::{Range, ffi};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// /refsect1
16    ///
17    /// ## Signals
18    ///
19    ///
20    /// #### `value-changed`
21    ///  The 'value-changed' signal is emitted when the current value
22    /// that represent the object changes. `value` is the numerical
23    /// representation of this new value. `text` is the human
24    /// readable text alternative of `value`, and can be NULL if it is
25    /// not available. Note that if there is a textual description
26    /// associated with the new numeric value, that description
27    /// should be included regardless of whether or not it has also
28    /// changed.
29    ///
30    /// Example: a password meter whose value changes as the user
31    /// types their new password. Appropiate value text would be
32    /// "weak", "acceptable" and "strong".
33    ///
34    ///
35    ///
36    /// # Implements
37    ///
38    /// [`ValueExt`][trait@crate::prelude::ValueExt]
39    #[doc(alias = "AtkValue")]
40    pub struct Value(Interface<ffi::AtkValue, ffi::AtkValueIface>);
41
42    match fn {
43        type_ => || ffi::atk_value_get_type(),
44    }
45}
46
47impl Value {
48    pub const NONE: Option<&'static Value> = None;
49}
50
51/// Trait containing all [`struct@Value`] methods.
52///
53/// # Implementors
54///
55/// [`NoOpObject`][struct@crate::NoOpObject], [`Value`][struct@crate::Value]
56pub trait ValueExt: IsA<Value> + 'static {
57    /// Gets the value of this object.
58    ///
59    /// # Deprecated
60    ///
61    /// Since 2.12. Use [`value_and_text()`][Self::value_and_text()]
62    /// instead.
63    ///
64    /// # Returns
65    ///
66    ///
67    /// ## `value`
68    /// a [`glib::Value`][crate::glib::Value] representing the current accessible value
69    #[doc(alias = "atk_value_get_current_value")]
70    #[doc(alias = "get_current_value")]
71    fn current_value(&self) -> glib::Value {
72        unsafe {
73            let mut value = glib::Value::uninitialized();
74            ffi::atk_value_get_current_value(
75                self.as_ref().to_glib_none().0,
76                value.to_glib_none_mut().0,
77            );
78            value
79        }
80    }
81
82    /// Gets the minimum increment by which the value of this object may be
83    /// changed. If zero, the minimum increment is undefined, which may
84    /// mean that it is limited only by the floating point precision of the
85    /// platform.
86    ///
87    /// # Returns
88    ///
89    /// the minimum increment by which the value of this
90    /// object may be changed. zero if undefined.
91    #[doc(alias = "atk_value_get_increment")]
92    #[doc(alias = "get_increment")]
93    fn increment(&self) -> f64 {
94        unsafe { ffi::atk_value_get_increment(self.as_ref().to_glib_none().0) }
95    }
96
97    /// Gets the maximum value of this object.
98    ///
99    /// # Deprecated
100    ///
101    /// Since 2.12. Use [`range()`][Self::range()] instead.
102    ///
103    /// # Returns
104    ///
105    ///
106    /// ## `value`
107    /// a [`glib::Value`][crate::glib::Value] representing the maximum accessible value
108    #[doc(alias = "atk_value_get_maximum_value")]
109    #[doc(alias = "get_maximum_value")]
110    fn maximum_value(&self) -> glib::Value {
111        unsafe {
112            let mut value = glib::Value::uninitialized();
113            ffi::atk_value_get_maximum_value(
114                self.as_ref().to_glib_none().0,
115                value.to_glib_none_mut().0,
116            );
117            value
118        }
119    }
120
121    /// Gets the minimum increment by which the value of this object may be changed. If zero,
122    /// the minimum increment is undefined, which may mean that it is limited only by the
123    /// floating point precision of the platform.
124    ///
125    /// # Deprecated
126    ///
127    /// Since 2.12. Use [`increment()`][Self::increment()] instead.
128    ///
129    /// # Returns
130    ///
131    ///
132    /// ## `value`
133    /// a [`glib::Value`][crate::glib::Value] representing the minimum increment by which the accessible value may be changed
134    #[doc(alias = "atk_value_get_minimum_increment")]
135    #[doc(alias = "get_minimum_increment")]
136    fn minimum_increment(&self) -> glib::Value {
137        unsafe {
138            let mut value = glib::Value::uninitialized();
139            ffi::atk_value_get_minimum_increment(
140                self.as_ref().to_glib_none().0,
141                value.to_glib_none_mut().0,
142            );
143            value
144        }
145    }
146
147    /// Gets the minimum value of this object.
148    ///
149    /// # Deprecated
150    ///
151    /// Since 2.12. Use [`range()`][Self::range()] instead.
152    ///
153    /// # Returns
154    ///
155    ///
156    /// ## `value`
157    /// a [`glib::Value`][crate::glib::Value] representing the minimum accessible value
158    #[doc(alias = "atk_value_get_minimum_value")]
159    #[doc(alias = "get_minimum_value")]
160    fn minimum_value(&self) -> glib::Value {
161        unsafe {
162            let mut value = glib::Value::uninitialized();
163            ffi::atk_value_get_minimum_value(
164                self.as_ref().to_glib_none().0,
165                value.to_glib_none_mut().0,
166            );
167            value
168        }
169    }
170
171    /// Gets the range of this object.
172    ///
173    /// # Returns
174    ///
175    /// a newly allocated [`Range`][crate::Range]
176    /// that represents the minimum, maximum and descriptor (if available)
177    /// of `self`. NULL if that range is not defined.
178    #[doc(alias = "atk_value_get_range")]
179    #[doc(alias = "get_range")]
180    fn range(&self) -> Option<Range> {
181        unsafe { from_glib_full(ffi::atk_value_get_range(self.as_ref().to_glib_none().0)) }
182    }
183
184    /// Gets the list of subranges defined for this object. See [`Value`][crate::Value]
185    /// introduction for examples of subranges and when to expose them.
186    ///
187    /// # Returns
188    ///
189    /// an `GSList` of
190    /// [`Range`][crate::Range] which each of the subranges defined for this object. Free
191    /// the returns list with `g_slist_free()`.
192    #[doc(alias = "atk_value_get_sub_ranges")]
193    #[doc(alias = "get_sub_ranges")]
194    fn sub_ranges(&self) -> Vec<Range> {
195        unsafe {
196            FromGlibPtrContainer::from_glib_full(ffi::atk_value_get_sub_ranges(
197                self.as_ref().to_glib_none().0,
198            ))
199        }
200    }
201
202    /// Gets the current value and the human readable text alternative of
203    /// `self`. `text` is a newly created string, that must be freed by the
204    /// caller. Can be NULL if no descriptor is available.
205    ///
206    /// # Returns
207    ///
208    ///
209    /// ## `value`
210    /// address of `gdouble` to put the current value of `self`
211    ///
212    /// ## `text`
213    /// address of `gchar` to put the human
214    /// readable text alternative for `value`
215    #[doc(alias = "atk_value_get_value_and_text")]
216    #[doc(alias = "get_value_and_text")]
217    fn value_and_text(&self) -> (f64, glib::GString) {
218        unsafe {
219            let mut value = std::mem::MaybeUninit::uninit();
220            let mut text = std::ptr::null_mut();
221            ffi::atk_value_get_value_and_text(
222                self.as_ref().to_glib_none().0,
223                value.as_mut_ptr(),
224                &mut text,
225            );
226            (value.assume_init(), from_glib_full(text))
227        }
228    }
229
230    /// Sets the value of this object.
231    ///
232    /// # Deprecated
233    ///
234    /// Since 2.12. Use [`set_value()`][Self::set_value()] instead.
235    /// ## `value`
236    /// a [`glib::Value`][crate::glib::Value] which is the desired new accessible value.
237    ///
238    /// # Returns
239    ///
240    /// [`true`] if new value is successfully set, [`false`] otherwise.
241    #[doc(alias = "atk_value_set_current_value")]
242    fn set_current_value(&self, value: &glib::Value) -> bool {
243        unsafe {
244            from_glib(ffi::atk_value_set_current_value(
245                self.as_ref().to_glib_none().0,
246                value.to_glib_none().0,
247            ))
248        }
249    }
250
251    /// Sets the value of this object.
252    ///
253    /// This method is intended to provide a way to change the value of the
254    /// object. In any case, it is possible that the value can't be
255    /// modified (ie: a read-only component). If the value changes due this
256    /// call, it is possible that the text could change, and will trigger
257    /// an [`value-changed`][struct@crate::Value#value-changed] signal emission.
258    ///
259    /// Note for implementors: the deprecated [`set_current_value()`][Self::set_current_value()]
260    /// method returned TRUE or FALSE depending if the value was assigned
261    /// or not. In the practice several implementors were not able to
262    /// decide it, and returned TRUE in any case. For that reason it is not
263    /// required anymore to return if the value was properly assigned or
264    /// not.
265    /// ## `new_value`
266    /// a double which is the desired new accessible value.
267    #[doc(alias = "atk_value_set_value")]
268    fn set_value(&self, new_value: f64) {
269        unsafe {
270            ffi::atk_value_set_value(self.as_ref().to_glib_none().0, new_value);
271        }
272    }
273
274    /// The 'value-changed' signal is emitted when the current value
275    /// that represent the object changes. `value` is the numerical
276    /// representation of this new value. `text` is the human
277    /// readable text alternative of `value`, and can be NULL if it is
278    /// not available. Note that if there is a textual description
279    /// associated with the new numeric value, that description
280    /// should be included regardless of whether or not it has also
281    /// changed.
282    ///
283    /// Example: a password meter whose value changes as the user
284    /// types their new password. Appropiate value text would be
285    /// "weak", "acceptable" and "strong".
286    /// ## `value`
287    /// the new value in a numerical form.
288    /// ## `text`
289    /// human readable text alternative (also called
290    /// description) of this object. NULL if not available.
291    #[doc(alias = "value-changed")]
292    fn connect_value_changed<F: Fn(&Self, f64, &str) + 'static>(&self, f: F) -> SignalHandlerId {
293        unsafe extern "C" fn value_changed_trampoline<
294            P: IsA<Value>,
295            F: Fn(&P, f64, &str) + 'static,
296        >(
297            this: *mut ffi::AtkValue,
298            value: std::ffi::c_double,
299            text: *mut std::ffi::c_char,
300            f: glib::ffi::gpointer,
301        ) {
302            unsafe {
303                let f: &F = &*(f as *const F);
304                f(
305                    Value::from_glib_borrow(this).unsafe_cast_ref(),
306                    value,
307                    &glib::GString::from_glib_borrow(text),
308                )
309            }
310        }
311        unsafe {
312            let f: Box_<F> = Box_::new(f);
313            connect_raw(
314                self.as_ptr() as *mut _,
315                c"value-changed".as_ptr(),
316                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
317                    value_changed_trampoline::<Self, F> as *const (),
318                )),
319                Box_::into_raw(f),
320            )
321        }
322    }
323}
324
325impl<O: IsA<Value>> ValueExt for O {}