webkit6/auto/
editor_state.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// from webkit-gir-files
4// DO NOT EDIT
5
6use crate::ffi;
7#[cfg(feature = "v2_44")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v2_44")))]
9use glib::object::ObjectType as _;
10use glib::{
11    prelude::*,
12    signal::{connect_raw, SignalHandlerId},
13    translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18    /// Web editor state.
19    ///
20    /// WebKitEditorState represents the state of a #WebKitWebView editor.
21    /// Use webkit_web_view_get_editor_state() to get the WebKitEditorState
22    /// of a #WebKitWebView.
23    ///
24    /// ## Properties
25    ///
26    ///
27    /// #### `typing-attributes`
28    ///  Bitmask of #WebKitEditorTypingAttributes flags.
29    /// See webkit_editor_state_get_typing_attributes() for more information.
30    ///
31    /// Readable
32    ///
33    /// ## Signals
34    ///
35    ///
36    /// #### `changed`
37    ///  Emitted when the #WebKitEdtorState is changed.
38    ///
39    ///
40    #[doc(alias = "WebKitEditorState")]
41    pub struct EditorState(Object<ffi::WebKitEditorState, ffi::WebKitEditorStateClass>);
42
43    match fn {
44        type_ => || ffi::webkit_editor_state_get_type(),
45    }
46}
47
48impl EditorState {
49    /// Gets the typing attributes at the current cursor position.
50    ///
51    /// If there is a selection, this returns the typing attributes
52    /// of the selected text. Note that in case of a selection,
53    /// typing attributes are considered active only when they are
54    /// present throughout the selection.
55    ///
56    /// # Returns
57    ///
58    /// a bitmask of #WebKitEditorTypingAttributes flags
59    #[doc(alias = "webkit_editor_state_get_typing_attributes")]
60    #[doc(alias = "get_typing_attributes")]
61    #[doc(alias = "typing-attributes")]
62    pub fn typing_attributes(&self) -> u32 {
63        unsafe { ffi::webkit_editor_state_get_typing_attributes(self.to_glib_none().0) }
64    }
65
66    /// Gets whether a copy command can be issued.
67    ///
68    /// # Returns
69    ///
70    /// [`true`] if copy is currently available
71    #[doc(alias = "webkit_editor_state_is_copy_available")]
72    pub fn is_copy_available(&self) -> bool {
73        unsafe {
74            from_glib(ffi::webkit_editor_state_is_copy_available(
75                self.to_glib_none().0,
76            ))
77        }
78    }
79
80    /// Gets whether a cut command can be issued.
81    ///
82    /// # Returns
83    ///
84    /// [`true`] if cut is currently available
85    #[doc(alias = "webkit_editor_state_is_cut_available")]
86    pub fn is_cut_available(&self) -> bool {
87        unsafe {
88            from_glib(ffi::webkit_editor_state_is_cut_available(
89                self.to_glib_none().0,
90            ))
91        }
92    }
93
94    /// Gets whether a paste command can be issued.
95    ///
96    /// # Returns
97    ///
98    /// [`true`] if paste is currently available
99    #[doc(alias = "webkit_editor_state_is_paste_available")]
100    pub fn is_paste_available(&self) -> bool {
101        unsafe {
102            from_glib(ffi::webkit_editor_state_is_paste_available(
103                self.to_glib_none().0,
104            ))
105        }
106    }
107
108    /// Gets whether a redo command can be issued.
109    ///
110    /// # Returns
111    ///
112    /// [`true`] if redo is currently available
113    #[doc(alias = "webkit_editor_state_is_redo_available")]
114    pub fn is_redo_available(&self) -> bool {
115        unsafe {
116            from_glib(ffi::webkit_editor_state_is_redo_available(
117                self.to_glib_none().0,
118            ))
119        }
120    }
121
122    /// Gets whether an undo command can be issued.
123    ///
124    /// # Returns
125    ///
126    /// [`true`] if undo is currently available
127    #[doc(alias = "webkit_editor_state_is_undo_available")]
128    pub fn is_undo_available(&self) -> bool {
129        unsafe {
130            from_glib(ffi::webkit_editor_state_is_undo_available(
131                self.to_glib_none().0,
132            ))
133        }
134    }
135
136    /// Emitted when the #WebKitEdtorState is changed.
137    #[cfg(feature = "v2_44")]
138    #[cfg_attr(docsrs, doc(cfg(feature = "v2_44")))]
139    #[doc(alias = "changed")]
140    pub fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
141        unsafe extern "C" fn changed_trampoline<F: Fn(&EditorState) + 'static>(
142            this: *mut ffi::WebKitEditorState,
143            f: glib::ffi::gpointer,
144        ) {
145            let f: &F = &*(f as *const F);
146            f(&from_glib_borrow(this))
147        }
148        unsafe {
149            let f: Box_<F> = Box_::new(f);
150            connect_raw(
151                self.as_ptr() as *mut _,
152                c"changed".as_ptr() as *const _,
153                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
154                    changed_trampoline::<F> as *const (),
155                )),
156                Box_::into_raw(f),
157            )
158        }
159    }
160
161    #[doc(alias = "typing-attributes")]
162    pub fn connect_typing_attributes_notify<F: Fn(&Self) + 'static>(
163        &self,
164        f: F,
165    ) -> SignalHandlerId {
166        unsafe extern "C" fn notify_typing_attributes_trampoline<F: Fn(&EditorState) + 'static>(
167            this: *mut ffi::WebKitEditorState,
168            _param_spec: glib::ffi::gpointer,
169            f: glib::ffi::gpointer,
170        ) {
171            let f: &F = &*(f as *const F);
172            f(&from_glib_borrow(this))
173        }
174        unsafe {
175            let f: Box_<F> = Box_::new(f);
176            connect_raw(
177                self.as_ptr() as *mut _,
178                c"notify::typing-attributes".as_ptr() as *const _,
179                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
180                    notify_typing_attributes_trampoline::<F> as *const (),
181                )),
182                Box_::into_raw(f),
183            )
184        }
185    }
186}