atk/auto/text.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
5#[cfg(feature = "v2_32")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v2_32")))]
7use crate::ScrollType;
8use crate::{
9 CoordType, TextBoundary, TextClipType, TextGranularity, TextRange, TextRectangle, ffi,
10};
11use glib::{
12 object::ObjectType as _,
13 prelude::*,
14 signal::{SignalHandlerId, connect_raw},
15 translate::*,
16};
17use std::boxed::Box as Box_;
18
19glib::wrapper! {
20 /// The ATK interface implemented by components with text content.
21 ///
22 /// [`Text`][crate::Text] should be implemented by `AtkObjects` on behalf of widgets
23 /// that have text content which is either attributed or otherwise
24 /// non-trivial. `AtkObjects` whose text content is simple,
25 /// unattributed, and very brief may expose that content via
26 /// `atk_object_get_name` instead; however if the text is editable,
27 /// multi-line, typically longer than three or four words, attributed,
28 /// selectable, or if the object already uses the 'name' ATK property
29 /// for other information, the [`Text`][crate::Text] interface should be used to
30 /// expose the text content. In the case of editable text content,
31 /// [`EditableText`][crate::EditableText] (a subtype of the [`Text`][crate::Text] interface) should be
32 /// implemented instead.
33 ///
34 /// [`Text`][crate::Text] provides not only traversal facilities and change
35 /// notification for text content, but also caret tracking and glyph
36 /// bounding box calculations. Note that the text strings are exposed
37 /// as UTF-8, and are therefore potentially multi-byte, and
38 /// caret-to-byte offset mapping makes no assumptions about the
39 /// character length; also bounding box glyph-to-offset mapping may be
40 /// complex for languages which use ligatures.
41 ///
42 /// ## Signals
43 ///
44 ///
45 /// #### `text-attributes-changed`
46 /// The "text-attributes-changed" signal is emitted when the text
47 /// attributes of the text of an object which implements AtkText
48 /// changes.
49 ///
50 ///
51 ///
52 ///
53 /// #### `text-caret-moved`
54 /// The "text-caret-moved" signal is emitted when the caret
55 /// position of the text of an object which implements AtkText
56 /// changes.
57 ///
58 ///
59 ///
60 ///
61 /// #### `text-changed`
62 /// The "text-changed" signal is emitted when the text of the
63 /// object which implements the AtkText interface changes, This
64 /// signal will have a detail which is either "insert" or
65 /// "delete" which identifies whether the text change was an
66 /// insertion or a deletion.
67 ///
68 /// Detailed
69 ///
70 ///
71 /// #### `text-insert`
72 /// The "text-insert" signal is emitted when a new text is
73 /// inserted. If the signal was not triggered by the user
74 /// (e.g. typing or pasting text), the "system" detail should be
75 /// included.
76 ///
77 /// Detailed
78 ///
79 ///
80 /// #### `text-remove`
81 /// The "text-remove" signal is emitted when a new text is
82 /// removed. If the signal was not triggered by the user
83 /// (e.g. typing or pasting text), the "system" detail should be
84 /// included.
85 ///
86 /// Detailed
87 ///
88 ///
89 /// #### `text-selection-changed`
90 /// The "text-selection-changed" signal is emitted when the
91 /// selected text of an object which implements AtkText changes.
92 ///
93 ///
94 ///
95 /// # Implements
96 ///
97 /// [`TextExt`][trait@crate::prelude::TextExt]
98 #[doc(alias = "AtkText")]
99 pub struct Text(Interface<ffi::AtkText, ffi::AtkTextIface>);
100
101 match fn {
102 type_ => || ffi::atk_text_get_type(),
103 }
104}
105
106impl Text {
107 pub const NONE: Option<&'static Text> = None;
108}
109
110/// Trait containing all [`struct@Text`] methods.
111///
112/// # Implementors
113///
114/// [`NoOpObject`][struct@crate::NoOpObject], [`Text`][struct@crate::Text]
115pub trait TextExt: IsA<Text> + 'static {
116 /// Adds a selection bounded by the specified offsets.
117 /// ## `start_offset`
118 /// the starting character offset of the selected region
119 /// ## `end_offset`
120 /// the offset of the first character after the selected region.
121 ///
122 /// # Returns
123 ///
124 /// [`true`] if successful, [`false`] otherwise
125 #[doc(alias = "atk_text_add_selection")]
126 fn add_selection(&self, start_offset: i32, end_offset: i32) -> bool {
127 unsafe {
128 from_glib(ffi::atk_text_add_selection(
129 self.as_ref().to_glib_none().0,
130 start_offset,
131 end_offset,
132 ))
133 }
134 }
135
136 /// Get the ranges of text in the specified bounding box.
137 /// ## `rect`
138 /// An AtkTextRectangle giving the dimensions of the bounding box.
139 /// ## `coord_type`
140 /// Specify whether coordinates are relative to the screen or widget window.
141 /// ## `x_clip_type`
142 /// Specify the horizontal clip type.
143 /// ## `y_clip_type`
144 /// Specify the vertical clip type.
145 ///
146 /// # Returns
147 ///
148 /// Array of AtkTextRange. The last
149 /// element of the array returned by this function will be NULL.
150 #[doc(alias = "atk_text_get_bounded_ranges")]
151 #[doc(alias = "get_bounded_ranges")]
152 fn bounded_ranges(
153 &self,
154 rect: &mut TextRectangle,
155 coord_type: CoordType,
156 x_clip_type: TextClipType,
157 y_clip_type: TextClipType,
158 ) -> Vec<TextRange> {
159 unsafe {
160 FromGlibPtrContainer::from_glib_full(ffi::atk_text_get_bounded_ranges(
161 self.as_ref().to_glib_none().0,
162 rect.to_glib_none_mut().0,
163 coord_type.into_glib(),
164 x_clip_type.into_glib(),
165 y_clip_type.into_glib(),
166 ))
167 }
168 }
169
170 /// Gets the offset of the position of the caret (cursor).
171 ///
172 /// # Returns
173 ///
174 /// the character offset of the position of the caret or -1 if
175 /// the caret is not located inside the element or in the case of
176 /// any other failure.
177 #[doc(alias = "atk_text_get_caret_offset")]
178 #[doc(alias = "get_caret_offset")]
179 fn caret_offset(&self) -> i32 {
180 unsafe { ffi::atk_text_get_caret_offset(self.as_ref().to_glib_none().0) }
181 }
182
183 /// Gets the specified text.
184 /// ## `offset`
185 /// a character offset within `self`
186 ///
187 /// # Returns
188 ///
189 /// the character at `offset` or 0 in the case of failure.
190 #[doc(alias = "atk_text_get_character_at_offset")]
191 #[doc(alias = "get_character_at_offset")]
192 fn character_at_offset(&self, offset: i32) -> char {
193 unsafe {
194 std::convert::TryFrom::try_from(ffi::atk_text_get_character_at_offset(
195 self.as_ref().to_glib_none().0,
196 offset,
197 ))
198 .expect("conversion from an invalid Unicode value attempted")
199 }
200 }
201
202 /// Gets the character count.
203 ///
204 /// # Returns
205 ///
206 /// the number of characters or -1 in case of failure.
207 #[doc(alias = "atk_text_get_character_count")]
208 #[doc(alias = "get_character_count")]
209 fn character_count(&self) -> i32 {
210 unsafe { ffi::atk_text_get_character_count(self.as_ref().to_glib_none().0) }
211 }
212
213 /// If the extent can not be obtained (e.g. missing support), all of x, y, width,
214 /// height are set to -1.
215 ///
216 /// Get the bounding box containing the glyph representing the character at
217 /// a particular text offset.
218 /// ## `offset`
219 /// The offset of the text character for which bounding information is required.
220 /// ## `coords`
221 /// specify whether coordinates are relative to the screen or widget window
222 ///
223 /// # Returns
224 ///
225 ///
226 /// ## `x`
227 /// Pointer for the x coordinate of the bounding box
228 ///
229 /// ## `y`
230 /// Pointer for the y coordinate of the bounding box
231 ///
232 /// ## `width`
233 /// Pointer for the width of the bounding box
234 ///
235 /// ## `height`
236 /// Pointer for the height of the bounding box
237 #[doc(alias = "atk_text_get_character_extents")]
238 #[doc(alias = "get_character_extents")]
239 fn character_extents(&self, offset: i32, coords: CoordType) -> (i32, i32, i32, i32) {
240 unsafe {
241 let mut x = std::mem::MaybeUninit::uninit();
242 let mut y = std::mem::MaybeUninit::uninit();
243 let mut width = std::mem::MaybeUninit::uninit();
244 let mut height = std::mem::MaybeUninit::uninit();
245 ffi::atk_text_get_character_extents(
246 self.as_ref().to_glib_none().0,
247 offset,
248 x.as_mut_ptr(),
249 y.as_mut_ptr(),
250 width.as_mut_ptr(),
251 height.as_mut_ptr(),
252 coords.into_glib(),
253 );
254 (
255 x.assume_init(),
256 y.assume_init(),
257 width.assume_init(),
258 height.assume_init(),
259 )
260 }
261 }
262
263 //#[doc(alias = "atk_text_get_default_attributes")]
264 //#[doc(alias = "get_default_attributes")]
265 //fn default_attributes(&self) -> /*Ignored*/Option<AttributeSet> {
266 // unsafe { TODO: call ffi:atk_text_get_default_attributes() }
267 //}
268
269 /// Gets the number of selected regions.
270 ///
271 /// # Returns
272 ///
273 /// The number of selected regions, or -1 in the case of failure.
274 #[doc(alias = "atk_text_get_n_selections")]
275 #[doc(alias = "get_n_selections")]
276 fn n_selections(&self) -> i32 {
277 unsafe { ffi::atk_text_get_n_selections(self.as_ref().to_glib_none().0) }
278 }
279
280 /// Gets the offset of the character located at coordinates `x` and `y`. `x` and `y`
281 /// are interpreted as being relative to the screen or this widget's window
282 /// depending on `coords`.
283 /// ## `x`
284 /// screen x-position of character
285 /// ## `y`
286 /// screen y-position of character
287 /// ## `coords`
288 /// specify whether coordinates are relative to the screen or
289 /// widget window
290 ///
291 /// # Returns
292 ///
293 /// the offset to the character which is located at the specified
294 /// `x` and `y` coordinates of -1 in case of failure.
295 #[doc(alias = "atk_text_get_offset_at_point")]
296 #[doc(alias = "get_offset_at_point")]
297 fn offset_at_point(&self, x: i32, y: i32, coords: CoordType) -> i32 {
298 unsafe {
299 ffi::atk_text_get_offset_at_point(
300 self.as_ref().to_glib_none().0,
301 x,
302 y,
303 coords.into_glib(),
304 )
305 }
306 }
307
308 /// Get the bounding box for text within the specified range.
309 ///
310 /// If the extents can not be obtained (e.g. or missing support), the rectangle
311 /// fields are set to -1.
312 /// ## `start_offset`
313 /// The offset of the first text character for which boundary
314 /// information is required.
315 /// ## `end_offset`
316 /// The offset of the text character after the last character
317 /// for which boundary information is required.
318 /// ## `coord_type`
319 /// Specify whether coordinates are relative to the screen or widget window.
320 ///
321 /// # Returns
322 ///
323 ///
324 /// ## `rect`
325 /// A pointer to a AtkTextRectangle which is filled in by this function.
326 #[doc(alias = "atk_text_get_range_extents")]
327 #[doc(alias = "get_range_extents")]
328 fn range_extents(
329 &self,
330 start_offset: i32,
331 end_offset: i32,
332 coord_type: CoordType,
333 ) -> TextRectangle {
334 unsafe {
335 let mut rect = TextRectangle::uninitialized();
336 ffi::atk_text_get_range_extents(
337 self.as_ref().to_glib_none().0,
338 start_offset,
339 end_offset,
340 coord_type.into_glib(),
341 rect.to_glib_none_mut().0,
342 );
343 rect
344 }
345 }
346
347 //#[doc(alias = "atk_text_get_run_attributes")]
348 //#[doc(alias = "get_run_attributes")]
349 //fn run_attributes(&self, offset: i32) -> (/*Ignored*/AttributeSet, i32, i32) {
350 // unsafe { TODO: call ffi:atk_text_get_run_attributes() }
351 //}
352
353 /// Gets the text from the specified selection.
354 /// ## `selection_num`
355 /// The selection number. The selected regions are
356 /// assigned numbers that correspond to how far the region is from the
357 /// start of the text. The selected region closest to the beginning
358 /// of the text region is assigned the number 0, etc. Note that adding,
359 /// moving or deleting a selected region can change the numbering.
360 ///
361 /// # Returns
362 ///
363 /// a newly allocated string containing the selected text. Use `g_free()`
364 /// to free the returned string.
365 ///
366 /// ## `start_offset`
367 /// passes back the starting character offset of the selected region
368 ///
369 /// ## `end_offset`
370 /// passes back the ending character offset (offset immediately past)
371 /// of the selected region
372 #[doc(alias = "atk_text_get_selection")]
373 #[doc(alias = "get_selection")]
374 fn selection(&self, selection_num: i32) -> (glib::GString, i32, i32) {
375 unsafe {
376 let mut start_offset = std::mem::MaybeUninit::uninit();
377 let mut end_offset = std::mem::MaybeUninit::uninit();
378 let ret = from_glib_full(ffi::atk_text_get_selection(
379 self.as_ref().to_glib_none().0,
380 selection_num,
381 start_offset.as_mut_ptr(),
382 end_offset.as_mut_ptr(),
383 ));
384 (ret, start_offset.assume_init(), end_offset.assume_init())
385 }
386 }
387
388 /// Gets a portion of the text exposed through an [`Text`][crate::Text] according to a given `offset`
389 /// and a specific `granularity`, along with the start and end offsets defining the
390 /// boundaries of such a portion of text.
391 ///
392 /// If `granularity` is ATK_TEXT_GRANULARITY_CHAR the character at the
393 /// offset is returned.
394 ///
395 /// If `granularity` is ATK_TEXT_GRANULARITY_WORD the returned string
396 /// is from the word start at or before the offset to the word start after
397 /// the offset.
398 ///
399 /// The returned string will contain the word at the offset if the offset
400 /// is inside a word and will contain the word before the offset if the
401 /// offset is not inside a word.
402 ///
403 /// If `granularity` is ATK_TEXT_GRANULARITY_SENTENCE the returned string
404 /// is from the sentence start at or before the offset to the sentence
405 /// start after the offset.
406 ///
407 /// The returned string will contain the sentence at the offset if the offset
408 /// is inside a sentence and will contain the sentence before the offset
409 /// if the offset is not inside a sentence.
410 ///
411 /// If `granularity` is ATK_TEXT_GRANULARITY_LINE the returned string
412 /// is from the line start at or before the offset to the line
413 /// start after the offset.
414 ///
415 /// If `granularity` is ATK_TEXT_GRANULARITY_PARAGRAPH the returned string
416 /// is from the start of the paragraph at or before the offset to the start
417 /// of the following paragraph after the offset.
418 /// ## `offset`
419 /// position
420 /// ## `granularity`
421 /// An [`TextGranularity`][crate::TextGranularity]
422 ///
423 /// # Returns
424 ///
425 /// a newly allocated string containing the text at
426 /// the `offset` bounded by the specified `granularity`. Use `g_free()`
427 /// to free the returned string. Returns [`None`] if the offset is invalid
428 /// or no implementation is available.
429 ///
430 /// ## `start_offset`
431 /// the starting character offset of the returned string, or -1
432 /// in the case of error (e.g. invalid offset, not implemented)
433 ///
434 /// ## `end_offset`
435 /// the offset of the first character after the returned string,
436 /// or -1 in the case of error (e.g. invalid offset, not implemented)
437 #[doc(alias = "atk_text_get_string_at_offset")]
438 #[doc(alias = "get_string_at_offset")]
439 fn string_at_offset(
440 &self,
441 offset: i32,
442 granularity: TextGranularity,
443 ) -> (Option<glib::GString>, i32, i32) {
444 unsafe {
445 let mut start_offset = std::mem::MaybeUninit::uninit();
446 let mut end_offset = std::mem::MaybeUninit::uninit();
447 let ret = from_glib_full(ffi::atk_text_get_string_at_offset(
448 self.as_ref().to_glib_none().0,
449 offset,
450 granularity.into_glib(),
451 start_offset.as_mut_ptr(),
452 end_offset.as_mut_ptr(),
453 ));
454 (ret, start_offset.assume_init(), end_offset.assume_init())
455 }
456 }
457
458 /// Gets the specified text.
459 /// ## `start_offset`
460 /// a starting character offset within `self`
461 /// ## `end_offset`
462 /// an ending character offset within `self`, or -1 for the end of the string.
463 ///
464 /// # Returns
465 ///
466 /// a newly allocated string containing the text from `start_offset` up
467 /// to, but not including `end_offset`. Use `g_free()` to free the returned
468 /// string.
469 #[doc(alias = "atk_text_get_text")]
470 #[doc(alias = "get_text")]
471 fn text(&self, start_offset: i32, end_offset: i32) -> Option<glib::GString> {
472 unsafe {
473 from_glib_full(ffi::atk_text_get_text(
474 self.as_ref().to_glib_none().0,
475 start_offset,
476 end_offset,
477 ))
478 }
479 }
480
481 /// Gets the specified text.
482 ///
483 /// If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
484 /// offset is returned.
485 ///
486 /// If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
487 /// is from the word start at or before the offset to the word start after
488 /// the offset.
489 ///
490 /// The returned string will contain the word at the offset if the offset
491 /// is inside a word and will contain the word before the offset if the
492 /// offset is not inside a word.
493 ///
494 /// If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
495 /// string is from the sentence start at or before the offset to the sentence
496 /// start after the offset.
497 ///
498 /// The returned string will contain the sentence at the offset if the offset
499 /// is inside a sentence and will contain the sentence before the offset
500 /// if the offset is not inside a sentence.
501 ///
502 /// If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
503 /// string is from the line start at or before the offset to the line
504 /// start after the offset.
505 ///
506 /// # Deprecated
507 ///
508 /// This method is deprecated since ATK version
509 /// 2.9.4. Please use [`string_at_offset()`][Self::string_at_offset()] instead.
510 /// ## `offset`
511 /// position
512 /// ## `boundary_type`
513 /// An [`TextBoundary`][crate::TextBoundary]
514 ///
515 /// # Returns
516 ///
517 /// a newly allocated string containing the text at `offset` bounded
518 /// by the specified `boundary_type`. Use `g_free()` to free the returned
519 /// string.
520 ///
521 /// ## `start_offset`
522 /// the starting character offset of the returned string
523 ///
524 /// ## `end_offset`
525 /// the offset of the first character after the
526 /// returned substring
527 #[doc(alias = "atk_text_get_text_at_offset")]
528 #[doc(alias = "get_text_at_offset")]
529 fn text_at_offset(
530 &self,
531 offset: i32,
532 boundary_type: TextBoundary,
533 ) -> (glib::GString, i32, i32) {
534 unsafe {
535 let mut start_offset = std::mem::MaybeUninit::uninit();
536 let mut end_offset = std::mem::MaybeUninit::uninit();
537 let ret = from_glib_full(ffi::atk_text_get_text_at_offset(
538 self.as_ref().to_glib_none().0,
539 offset,
540 boundary_type.into_glib(),
541 start_offset.as_mut_ptr(),
542 end_offset.as_mut_ptr(),
543 ));
544 (ret, start_offset.assume_init(), end_offset.assume_init())
545 }
546 }
547
548 /// Removes the specified selection.
549 /// ## `selection_num`
550 /// The selection number. The selected regions are
551 /// assigned numbers that correspond to how far the region is from the
552 /// start of the text. The selected region closest to the beginning
553 /// of the text region is assigned the number 0, etc. Note that adding,
554 /// moving or deleting a selected region can change the numbering.
555 ///
556 /// # Returns
557 ///
558 /// [`true`] if successful, [`false`] otherwise
559 #[doc(alias = "atk_text_remove_selection")]
560 fn remove_selection(&self, selection_num: i32) -> bool {
561 unsafe {
562 from_glib(ffi::atk_text_remove_selection(
563 self.as_ref().to_glib_none().0,
564 selection_num,
565 ))
566 }
567 }
568
569 /// Makes a substring of `self` visible on the screen by scrolling all necessary parents.
570 /// ## `start_offset`
571 /// start offset in the `self`
572 /// ## `end_offset`
573 /// end offset in the `self`, or -1 for the end of the text.
574 /// ## `type_`
575 /// specify where the object should be made visible.
576 ///
577 /// # Returns
578 ///
579 /// whether scrolling was successful.
580 #[cfg(feature = "v2_32")]
581 #[cfg_attr(docsrs, doc(cfg(feature = "v2_32")))]
582 #[doc(alias = "atk_text_scroll_substring_to")]
583 fn scroll_substring_to(&self, start_offset: i32, end_offset: i32, type_: ScrollType) -> bool {
584 unsafe {
585 from_glib(ffi::atk_text_scroll_substring_to(
586 self.as_ref().to_glib_none().0,
587 start_offset,
588 end_offset,
589 type_.into_glib(),
590 ))
591 }
592 }
593
594 /// Move the top-left of a substring of `self` to a given position of the screen
595 /// by scrolling all necessary parents.
596 /// ## `start_offset`
597 /// start offset in the `self`
598 /// ## `end_offset`
599 /// end offset in the `self`, or -1 for the end of the text.
600 /// ## `coords`
601 /// specify whether coordinates are relative to the screen or to the
602 /// parent object.
603 /// ## `x`
604 /// x-position where to scroll to
605 /// ## `y`
606 /// y-position where to scroll to
607 ///
608 /// # Returns
609 ///
610 /// whether scrolling was successful.
611 #[cfg(feature = "v2_32")]
612 #[cfg_attr(docsrs, doc(cfg(feature = "v2_32")))]
613 #[doc(alias = "atk_text_scroll_substring_to_point")]
614 fn scroll_substring_to_point(
615 &self,
616 start_offset: i32,
617 end_offset: i32,
618 coords: CoordType,
619 x: i32,
620 y: i32,
621 ) -> bool {
622 unsafe {
623 from_glib(ffi::atk_text_scroll_substring_to_point(
624 self.as_ref().to_glib_none().0,
625 start_offset,
626 end_offset,
627 coords.into_glib(),
628 x,
629 y,
630 ))
631 }
632 }
633
634 /// Sets the caret (cursor) position to the specified `offset`.
635 ///
636 /// In the case of rich-text content, this method should either grab focus
637 /// or move the sequential focus navigation starting point (if the application
638 /// supports this concept) as if the user had clicked on the new caret position.
639 /// Typically, this means that the target of this operation is the node containing
640 /// the new caret position or one of its ancestors. In other words, after this
641 /// method is called, if the user advances focus, it should move to the first
642 /// focusable node following the new caret position.
643 ///
644 /// Calling this method should also scroll the application viewport in a way
645 /// that matches the behavior of the application's typical caret motion or tab
646 /// navigation as closely as possible. This also means that if the application's
647 /// caret motion or focus navigation does not trigger a scroll operation, this
648 /// method should not trigger one either. If the application does not have a caret
649 /// motion or focus navigation operation, this method should try to scroll the new
650 /// caret position into view while minimizing unnecessary scroll motion.
651 /// ## `offset`
652 /// the character offset of the new caret position
653 ///
654 /// # Returns
655 ///
656 /// [`true`] if successful, [`false`] otherwise.
657 #[doc(alias = "atk_text_set_caret_offset")]
658 fn set_caret_offset(&self, offset: i32) -> bool {
659 unsafe {
660 from_glib(ffi::atk_text_set_caret_offset(
661 self.as_ref().to_glib_none().0,
662 offset,
663 ))
664 }
665 }
666
667 /// Changes the start and end offset of the specified selection.
668 /// ## `selection_num`
669 /// The selection number. The selected regions are
670 /// assigned numbers that correspond to how far the region is from the
671 /// start of the text. The selected region closest to the beginning
672 /// of the text region is assigned the number 0, etc. Note that adding,
673 /// moving or deleting a selected region can change the numbering.
674 /// ## `start_offset`
675 /// the new starting character offset of the selection
676 /// ## `end_offset`
677 /// the new end position of (e.g. offset immediately past)
678 /// the selection
679 ///
680 /// # Returns
681 ///
682 /// [`true`] if successful, [`false`] otherwise
683 #[doc(alias = "atk_text_set_selection")]
684 fn set_selection(&self, selection_num: i32, start_offset: i32, end_offset: i32) -> bool {
685 unsafe {
686 from_glib(ffi::atk_text_set_selection(
687 self.as_ref().to_glib_none().0,
688 selection_num,
689 start_offset,
690 end_offset,
691 ))
692 }
693 }
694
695 /// The "text-attributes-changed" signal is emitted when the text
696 /// attributes of the text of an object which implements AtkText
697 /// changes.
698 #[doc(alias = "text-attributes-changed")]
699 fn connect_text_attributes_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
700 unsafe extern "C" fn text_attributes_changed_trampoline<
701 P: IsA<Text>,
702 F: Fn(&P) + 'static,
703 >(
704 this: *mut ffi::AtkText,
705 f: glib::ffi::gpointer,
706 ) {
707 unsafe {
708 let f: &F = &*(f as *const F);
709 f(Text::from_glib_borrow(this).unsafe_cast_ref())
710 }
711 }
712 unsafe {
713 let f: Box_<F> = Box_::new(f);
714 connect_raw(
715 self.as_ptr() as *mut _,
716 c"text-attributes-changed".as_ptr(),
717 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
718 text_attributes_changed_trampoline::<Self, F> as *const (),
719 )),
720 Box_::into_raw(f),
721 )
722 }
723 }
724
725 /// The "text-caret-moved" signal is emitted when the caret
726 /// position of the text of an object which implements AtkText
727 /// changes.
728 /// ## `arg1`
729 /// The new position of the text caret.
730 #[doc(alias = "text-caret-moved")]
731 fn connect_text_caret_moved<F: Fn(&Self, i32) + 'static>(&self, f: F) -> SignalHandlerId {
732 unsafe extern "C" fn text_caret_moved_trampoline<P: IsA<Text>, F: Fn(&P, i32) + 'static>(
733 this: *mut ffi::AtkText,
734 arg1: std::ffi::c_int,
735 f: glib::ffi::gpointer,
736 ) {
737 unsafe {
738 let f: &F = &*(f as *const F);
739 f(Text::from_glib_borrow(this).unsafe_cast_ref(), arg1)
740 }
741 }
742 unsafe {
743 let f: Box_<F> = Box_::new(f);
744 connect_raw(
745 self.as_ptr() as *mut _,
746 c"text-caret-moved".as_ptr(),
747 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
748 text_caret_moved_trampoline::<Self, F> as *const (),
749 )),
750 Box_::into_raw(f),
751 )
752 }
753 }
754
755 /// The "text-insert" signal is emitted when a new text is
756 /// inserted. If the signal was not triggered by the user
757 /// (e.g. typing or pasting text), the "system" detail should be
758 /// included.
759 /// ## `arg1`
760 /// The position (character offset) of the insertion.
761 /// ## `arg2`
762 /// The length (in characters) of text inserted.
763 /// ## `arg3`
764 /// The new text inserted
765 #[doc(alias = "text-insert")]
766 fn connect_text_insert<F: Fn(&Self, i32, i32, &str) + 'static>(
767 &self,
768 detail: Option<&str>,
769 f: F,
770 ) -> SignalHandlerId {
771 unsafe extern "C" fn text_insert_trampoline<
772 P: IsA<Text>,
773 F: Fn(&P, i32, i32, &str) + 'static,
774 >(
775 this: *mut ffi::AtkText,
776 arg1: std::ffi::c_int,
777 arg2: std::ffi::c_int,
778 arg3: *mut std::ffi::c_char,
779 f: glib::ffi::gpointer,
780 ) {
781 unsafe {
782 let f: &F = &*(f as *const F);
783 f(
784 Text::from_glib_borrow(this).unsafe_cast_ref(),
785 arg1,
786 arg2,
787 &glib::GString::from_glib_borrow(arg3),
788 )
789 }
790 }
791 unsafe {
792 let f: Box_<F> = Box_::new(f);
793 let detailed_signal_name = detail.map(|name| format!("text-insert::{name}\0"));
794 let signal_name = detailed_signal_name.as_ref().map_or(c"text-insert", |n| {
795 std::ffi::CStr::from_bytes_with_nul_unchecked(n.as_bytes())
796 });
797 connect_raw(
798 self.as_ptr() as *mut _,
799 signal_name.as_ptr(),
800 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
801 text_insert_trampoline::<Self, F> as *const (),
802 )),
803 Box_::into_raw(f),
804 )
805 }
806 }
807
808 /// The "text-remove" signal is emitted when a new text is
809 /// removed. If the signal was not triggered by the user
810 /// (e.g. typing or pasting text), the "system" detail should be
811 /// included.
812 /// ## `arg1`
813 /// The position (character offset) of the removal.
814 /// ## `arg2`
815 /// The length (in characters) of text removed.
816 /// ## `arg3`
817 /// The old text removed
818 #[doc(alias = "text-remove")]
819 fn connect_text_remove<F: Fn(&Self, i32, i32, &str) + 'static>(
820 &self,
821 detail: Option<&str>,
822 f: F,
823 ) -> SignalHandlerId {
824 unsafe extern "C" fn text_remove_trampoline<
825 P: IsA<Text>,
826 F: Fn(&P, i32, i32, &str) + 'static,
827 >(
828 this: *mut ffi::AtkText,
829 arg1: std::ffi::c_int,
830 arg2: std::ffi::c_int,
831 arg3: *mut std::ffi::c_char,
832 f: glib::ffi::gpointer,
833 ) {
834 unsafe {
835 let f: &F = &*(f as *const F);
836 f(
837 Text::from_glib_borrow(this).unsafe_cast_ref(),
838 arg1,
839 arg2,
840 &glib::GString::from_glib_borrow(arg3),
841 )
842 }
843 }
844 unsafe {
845 let f: Box_<F> = Box_::new(f);
846 let detailed_signal_name = detail.map(|name| format!("text-remove::{name}\0"));
847 let signal_name = detailed_signal_name.as_ref().map_or(c"text-remove", |n| {
848 std::ffi::CStr::from_bytes_with_nul_unchecked(n.as_bytes())
849 });
850 connect_raw(
851 self.as_ptr() as *mut _,
852 signal_name.as_ptr(),
853 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
854 text_remove_trampoline::<Self, F> as *const (),
855 )),
856 Box_::into_raw(f),
857 )
858 }
859 }
860
861 /// The "text-selection-changed" signal is emitted when the
862 /// selected text of an object which implements AtkText changes.
863 #[doc(alias = "text-selection-changed")]
864 fn connect_text_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
865 unsafe extern "C" fn text_selection_changed_trampoline<
866 P: IsA<Text>,
867 F: Fn(&P) + 'static,
868 >(
869 this: *mut ffi::AtkText,
870 f: glib::ffi::gpointer,
871 ) {
872 unsafe {
873 let f: &F = &*(f as *const F);
874 f(Text::from_glib_borrow(this).unsafe_cast_ref())
875 }
876 }
877 unsafe {
878 let f: Box_<F> = Box_::new(f);
879 connect_raw(
880 self.as_ptr() as *mut _,
881 c"text-selection-changed".as_ptr(),
882 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
883 text_selection_changed_trampoline::<Self, F> as *const (),
884 )),
885 Box_::into_raw(f),
886 )
887 }
888 }
889}
890
891impl<O: IsA<Text>> TextExt for O {}