gtk4/auto/im_context.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
#![allow(deprecated)]
use crate::{ffi, InputHints, InputPurpose, Widget};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// [`IMContext`][crate::IMContext] defines the interface for GTK input methods.
///
/// [`IMContext`][crate::IMContext] is used by GTK text input widgets like [`Text`][crate::Text]
/// to map from key events to Unicode character strings.
///
/// An input method may consume multiple key events in sequence before finally
/// outputting the composed result. This is called *preediting*, and an input
/// method may provide feedback about this process by displaying the intermediate
/// composition states as preedit text. To do so, the [`IMContext`][crate::IMContext] will emit
/// [`preedit-start`][struct@crate::IMContext#preedit-start], [`preedit-changed`][struct@crate::IMContext#preedit-changed]
/// and [`preedit-end`][struct@crate::IMContext#preedit-end] signals.
///
/// For instance, the built-in GTK input method [`IMContextSimple`][crate::IMContextSimple]
/// implements the input of arbitrary Unicode code points by holding down the
/// <kbd>Control</kbd> and <kbd>Shift</kbd> keys and then typing <kbd>u</kbd>
/// followed by the hexadecimal digits of the code point. When releasing the
/// <kbd>Control</kbd> and <kbd>Shift</kbd> keys, preediting ends and the
/// character is inserted as text. For example,
///
/// Ctrl+Shift+u 2 0 A C
///
/// results in the € sign.
///
/// Additional input methods can be made available for use by GTK widgets as
/// loadable modules. An input method module is a small shared library which
/// provides a `GIOExtension` for the extension point named "gtk-im-module".
///
/// To connect a widget to the users preferred input method, you should use
/// [`IMMulticontext`][crate::IMMulticontext].
///
/// This is an Abstract Base Class, you cannot instantiate it.
///
/// ## Properties
///
///
/// #### `input-hints`
/// Additional hints that allow input methods to fine-tune
/// their behaviour.
///
/// Readable | Writeable
///
///
/// #### `input-purpose`
/// The purpose of the text field that the `GtkIMContext is connected to.
///
/// This property can be used by on-screen keyboards and other input
/// methods to adjust their behaviour.
///
/// Readable | Writeable
///
/// ## Signals
///
///
/// #### `commit`
/// The ::commit signal is emitted when a complete input sequence
/// has been entered by the user.
///
/// If the commit comes after a preediting sequence, the
/// ::commit signal is emitted after ::preedit-end.
///
/// This can be a single character immediately after a key press or
/// the final result of preediting.
///
///
///
///
/// #### `delete-surrounding`
/// The ::delete-surrounding signal is emitted when the input method
/// needs to delete all or part of the context surrounding the cursor.
///
///
///
///
/// #### `preedit-changed`
/// The ::preedit-changed signal is emitted whenever the preedit sequence
/// currently being entered has changed.
///
/// It is also emitted at the end of a preedit sequence, in which case
/// [`IMContextExt::preedit_string()`][crate::prelude::IMContextExt::preedit_string()] returns the empty string.
///
///
///
///
/// #### `preedit-end`
/// The ::preedit-end signal is emitted when a preediting sequence
/// has been completed or canceled.
///
///
///
///
/// #### `preedit-start`
/// The ::preedit-start signal is emitted when a new preediting sequence
/// starts.
///
///
///
///
/// #### `retrieve-surrounding`
/// The ::retrieve-surrounding signal is emitted when the input method
/// requires the context surrounding the cursor.
///
/// The callback should set the input method surrounding context by
/// calling the [`IMContextExt::set_surrounding()`][crate::prelude::IMContextExt::set_surrounding()] method.
///
///
///
/// # Implements
///
/// [`IMContextExt`][trait@crate::prelude::IMContextExt], [`trait@glib::ObjectExt`]
#[doc(alias = "GtkIMContext")]
pub struct IMContext(Object<ffi::GtkIMContext, ffi::GtkIMContextClass>);
match fn {
type_ => || ffi::gtk_im_context_get_type(),
}
}
impl IMContext {
pub const NONE: Option<&'static IMContext> = None;
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::IMContext>> Sealed for T {}
}
/// Trait containing all [`struct@IMContext`] methods.
///
/// # Implementors
///
/// [`IMContextSimple`][struct@crate::IMContextSimple], [`IMContext`][struct@crate::IMContext], [`IMMulticontext`][struct@crate::IMMulticontext]
pub trait IMContextExt: IsA<IMContext> + sealed::Sealed + 'static {
/// Requests the platform to show an on-screen keyboard for user input.
///
/// This method will return [`true`] if this request was actually performed
/// to the platform, other environmental factors may result in an on-screen
/// keyboard effectively not showing up.
/// ## `event`
/// a [`gdk::Event`][crate::gdk::Event]
///
/// # Returns
///
/// [`true`] if an on-screen keyboard could be requested to the platform.
#[cfg(feature = "v4_14")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
#[doc(alias = "gtk_im_context_activate_osk")]
fn activate_osk(&self, event: Option<impl AsRef<gdk::Event>>) -> bool {
unsafe {
from_glib(ffi::gtk_im_context_activate_osk(
self.as_ref().to_glib_none().0,
event.as_ref().map(|p| p.as_ref()).to_glib_none().0,
))
}
}
/// Asks the widget that the input context is attached to delete
/// characters around the cursor position by emitting the
/// `::delete_surrounding` signal.
///
/// Note that @offset and @n_chars are in characters not in bytes
/// which differs from the usage other places in [`IMContext`][crate::IMContext].
///
/// In order to use this function, you should first call
/// [`surrounding()`][Self::surrounding()] to get the current context,
/// and call this function immediately afterwards to make sure that you
/// know what you are deleting. You should also account for the fact
/// that even if the signal was handled, the input context might not
/// have deleted all the characters that were requested to be deleted.
///
/// This function is used by an input method that wants to make
/// substitutions in the existing text in response to new input.
/// It is not useful for applications.
/// ## `offset`
/// offset from cursor position in chars;
/// a negative value means start before the cursor.
/// ## `n_chars`
/// number of characters to delete.
///
/// # Returns
///
/// [`true`] if the signal was handled.
#[doc(alias = "gtk_im_context_delete_surrounding")]
fn delete_surrounding(&self, offset: i32, n_chars: i32) -> bool {
unsafe {
from_glib(ffi::gtk_im_context_delete_surrounding(
self.as_ref().to_glib_none().0,
offset,
n_chars,
))
}
}
/// Allow an input method to forward key press and release events
/// to another input method without necessarily having a [`gdk::Event`][crate::gdk::Event]
/// available.
/// ## `press`
/// whether to forward a key press or release event
/// ## `surface`
/// the surface the event is for
/// ## `device`
/// the device that the event is for
/// ## `time`
/// the timestamp for the event
/// ## `keycode`
/// the keycode for the event
/// ## `state`
/// modifier state for the event
/// ## `group`
/// the active keyboard group for the event
///
/// # Returns
///
/// [`true`] if the input method handled the key event.
#[doc(alias = "gtk_im_context_filter_key")]
fn filter_key(
&self,
press: bool,
surface: &impl IsA<gdk::Surface>,
device: &gdk::Device,
time: u32,
keycode: u32,
state: gdk::ModifierType,
group: i32,
) -> bool {
unsafe {
from_glib(ffi::gtk_im_context_filter_key(
self.as_ref().to_glib_none().0,
press.into_glib(),
surface.as_ref().to_glib_none().0,
device.to_glib_none().0,
time,
keycode,
state.into_glib(),
group,
))
}
}
/// Allow an input method to internally handle key press and release
/// events.
///
/// If this function returns [`true`], then no further processing
/// should be done for this key event.
/// ## `event`
/// the key event
///
/// # Returns
///
/// [`true`] if the input method handled the key event.
#[doc(alias = "gtk_im_context_filter_keypress")]
fn filter_keypress(&self, event: impl AsRef<gdk::Event>) -> bool {
unsafe {
from_glib(ffi::gtk_im_context_filter_keypress(
self.as_ref().to_glib_none().0,
event.as_ref().to_glib_none().0,
))
}
}
/// Notify the input method that the widget to which this
/// input context corresponds has gained focus.
///
/// The input method may, for example, change the displayed
/// feedback to reflect this change.
#[doc(alias = "gtk_im_context_focus_in")]
fn focus_in(&self) {
unsafe {
ffi::gtk_im_context_focus_in(self.as_ref().to_glib_none().0);
}
}
/// Notify the input method that the widget to which this
/// input context corresponds has lost focus.
///
/// The input method may, for example, change the displayed
/// feedback or reset the contexts state to reflect this change.
#[doc(alias = "gtk_im_context_focus_out")]
fn focus_out(&self) {
unsafe {
ffi::gtk_im_context_focus_out(self.as_ref().to_glib_none().0);
}
}
/// Retrieve the current preedit string for the input context,
/// and a list of attributes to apply to the string.
///
/// This string should be displayed inserted at the insertion point.
///
/// # Returns
///
///
/// ## `str`
/// location to store the retrieved
/// string. The string retrieved must be freed with g_free().
///
/// ## `attrs`
/// location to store the retrieved
/// attribute list. When you are done with this list, you
/// must unreference it with `Pango::AttrList::unref()`.
///
/// ## `cursor_pos`
/// location to store position of cursor
/// (in characters) within the preedit string.
#[doc(alias = "gtk_im_context_get_preedit_string")]
#[doc(alias = "get_preedit_string")]
fn preedit_string(&self) -> (glib::GString, pango::AttrList, i32) {
unsafe {
let mut str = std::ptr::null_mut();
let mut attrs = std::ptr::null_mut();
let mut cursor_pos = std::mem::MaybeUninit::uninit();
ffi::gtk_im_context_get_preedit_string(
self.as_ref().to_glib_none().0,
&mut str,
&mut attrs,
cursor_pos.as_mut_ptr(),
);
(
from_glib_full(str),
from_glib_full(attrs),
cursor_pos.assume_init(),
)
}
}
/// Retrieves context around the insertion point.
///
/// Input methods typically want context in order to constrain input text
/// based on existing text; this is important for languages such as Thai
/// where only some sequences of characters are allowed.
///
/// This function is implemented by emitting the
/// [`retrieve-surrounding`][struct@crate::IMContext#retrieve-surrounding] signal on the input method;
/// in response to this signal, a widget should provide as much context as
/// is available, up to an entire paragraph, by calling
/// [`set_surrounding()`][Self::set_surrounding()].
///
/// Note that there is no obligation for a widget to respond to the
/// `::retrieve-surrounding` signal, so input methods must be prepared to
/// function without context.
///
/// # Deprecated since 4.2
///
/// Use [`surrounding_with_selection()`][Self::surrounding_with_selection()] instead.
///
/// # Returns
///
/// `TRUE` if surrounding text was provided; in this case
/// you must free the result stored in `text`.
///
/// ## `text`
/// location to store a UTF-8 encoded
/// string of text holding context around the insertion point.
/// If the function returns [`true`], then you must free the result
/// stored in this location with g_free().
///
/// ## `cursor_index`
/// location to store byte index of the insertion
/// cursor within @text.
#[cfg_attr(feature = "v4_2", deprecated = "Since 4.2")]
#[allow(deprecated)]
#[doc(alias = "gtk_im_context_get_surrounding")]
#[doc(alias = "get_surrounding")]
fn surrounding(&self) -> Option<(glib::GString, i32)> {
unsafe {
let mut text = std::ptr::null_mut();
let mut cursor_index = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gtk_im_context_get_surrounding(
self.as_ref().to_glib_none().0,
&mut text,
cursor_index.as_mut_ptr(),
));
if ret {
Some((from_glib_full(text), cursor_index.assume_init()))
} else {
None
}
}
}
/// Retrieves context around the insertion point.
///
/// Input methods typically want context in order to constrain input
/// text based on existing text; this is important for languages such
/// as Thai where only some sequences of characters are allowed.
///
/// This function is implemented by emitting the
/// [`retrieve-surrounding`][struct@crate::IMContext#retrieve-surrounding] signal on the input method;
/// in response to this signal, a widget should provide as much context as
/// is available, up to an entire paragraph, by calling
/// [`set_surrounding_with_selection()`][Self::set_surrounding_with_selection()].
///
/// Note that there is no obligation for a widget to respond to the
/// `::retrieve-surrounding` signal, so input methods must be prepared to
/// function without context.
///
/// # Returns
///
/// `TRUE` if surrounding text was provided; in this case
/// you must free the result stored in `text`.
///
/// ## `text`
/// location to store a UTF-8 encoded
/// string of text holding context around the insertion point.
/// If the function returns [`true`], then you must free the result
/// stored in this location with g_free().
///
/// ## `cursor_index`
/// location to store byte index of the insertion
/// cursor within @text.
///
/// ## `anchor_index`
/// location to store byte index of the selection
/// bound within @text
#[cfg(feature = "v4_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
#[doc(alias = "gtk_im_context_get_surrounding_with_selection")]
#[doc(alias = "get_surrounding_with_selection")]
fn surrounding_with_selection(&self) -> Option<(glib::GString, i32, i32)> {
unsafe {
let mut text = std::ptr::null_mut();
let mut cursor_index = std::mem::MaybeUninit::uninit();
let mut anchor_index = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gtk_im_context_get_surrounding_with_selection(
self.as_ref().to_glib_none().0,
&mut text,
cursor_index.as_mut_ptr(),
anchor_index.as_mut_ptr(),
));
if ret {
Some((
from_glib_full(text),
cursor_index.assume_init(),
anchor_index.assume_init(),
))
} else {
None
}
}
}
/// Notify the input method that a change such as a change in cursor
/// position has been made.
///
/// This will typically cause the input method to clear the preedit state.
#[doc(alias = "gtk_im_context_reset")]
fn reset(&self) {
unsafe {
ffi::gtk_im_context_reset(self.as_ref().to_glib_none().0);
}
}
/// Set the client widget for the input context.
///
/// This is the [`Widget`][crate::Widget] holding the input focus. This widget is
/// used in order to correctly position status windows, and may
/// also be used for purposes internal to the input method.
/// ## `widget`
/// the client widget. This may be [`None`] to indicate
/// that the previous client widget no longer exists.
#[doc(alias = "gtk_im_context_set_client_widget")]
fn set_client_widget(&self, widget: Option<&impl IsA<Widget>>) {
unsafe {
ffi::gtk_im_context_set_client_widget(
self.as_ref().to_glib_none().0,
widget.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
/// Notify the input method that a change in cursor
/// position has been made.
///
/// The location is relative to the client widget.
/// ## `area`
/// new location
#[doc(alias = "gtk_im_context_set_cursor_location")]
fn set_cursor_location(&self, area: &gdk::Rectangle) {
unsafe {
ffi::gtk_im_context_set_cursor_location(
self.as_ref().to_glib_none().0,
area.to_glib_none().0,
);
}
}
/// Sets surrounding context around the insertion point and preedit
/// string.
///
/// This function is expected to be called in response to the
/// [`retrieve-surrounding`][struct@crate::IMContext#retrieve-surrounding] signal, and will
/// likely have no effect if called at other times.
///
/// # Deprecated since 4.2
///
/// Use [`set_surrounding_with_selection()`][Self::set_surrounding_with_selection()] instead
/// ## `text`
/// text surrounding the insertion point, as UTF-8.
/// the preedit string should not be included within @text
/// ## `len`
/// the length of @text, or -1 if @text is nul-terminated
/// ## `cursor_index`
/// the byte index of the insertion cursor within @text.
#[cfg_attr(feature = "v4_2", deprecated = "Since 4.2")]
#[allow(deprecated)]
#[doc(alias = "gtk_im_context_set_surrounding")]
fn set_surrounding(&self, text: &str, cursor_index: i32) {
let len = text.len() as _;
unsafe {
ffi::gtk_im_context_set_surrounding(
self.as_ref().to_glib_none().0,
text.to_glib_none().0,
len,
cursor_index,
);
}
}
/// Sets surrounding context around the insertion point and preedit
/// string. This function is expected to be called in response to the
/// [`retrieve_surrounding`][struct@crate::IMContext#retrieve_surrounding] signal, and will likely
/// have no effect if called at other times.
/// ## `text`
/// text surrounding the insertion point, as UTF-8.
/// the preedit string should not be included within @text
/// ## `len`
/// the length of @text, or -1 if @text is nul-terminated
/// ## `cursor_index`
/// the byte index of the insertion cursor within @text
/// ## `anchor_index`
/// the byte index of the selection bound within @text
#[cfg(feature = "v4_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
#[doc(alias = "gtk_im_context_set_surrounding_with_selection")]
fn set_surrounding_with_selection(&self, text: &str, cursor_index: i32, anchor_index: i32) {
let len = text.len() as _;
unsafe {
ffi::gtk_im_context_set_surrounding_with_selection(
self.as_ref().to_glib_none().0,
text.to_glib_none().0,
len,
cursor_index,
anchor_index,
);
}
}
/// Sets whether the IM context should use the preedit string
/// to display feedback.
///
/// If @use_preedit is [`false`] (default is [`true`]), then the IM context
/// may use some other method to display feedback, such as displaying
/// it in a child of the root window.
/// ## `use_preedit`
/// whether the IM context should use the preedit string.
#[doc(alias = "gtk_im_context_set_use_preedit")]
fn set_use_preedit(&self, use_preedit: bool) {
unsafe {
ffi::gtk_im_context_set_use_preedit(
self.as_ref().to_glib_none().0,
use_preedit.into_glib(),
);
}
}
/// Additional hints that allow input methods to fine-tune
/// their behaviour.
#[doc(alias = "input-hints")]
fn input_hints(&self) -> InputHints {
ObjectExt::property(self.as_ref(), "input-hints")
}
/// Additional hints that allow input methods to fine-tune
/// their behaviour.
#[doc(alias = "input-hints")]
fn set_input_hints(&self, input_hints: InputHints) {
ObjectExt::set_property(self.as_ref(), "input-hints", input_hints)
}
/// The purpose of the text field that the `GtkIMContext is connected to.
///
/// This property can be used by on-screen keyboards and other input
/// methods to adjust their behaviour.
#[doc(alias = "input-purpose")]
fn input_purpose(&self) -> InputPurpose {
ObjectExt::property(self.as_ref(), "input-purpose")
}
/// The purpose of the text field that the `GtkIMContext is connected to.
///
/// This property can be used by on-screen keyboards and other input
/// methods to adjust their behaviour.
#[doc(alias = "input-purpose")]
fn set_input_purpose(&self, input_purpose: InputPurpose) {
ObjectExt::set_property(self.as_ref(), "input-purpose", input_purpose)
}
/// The ::commit signal is emitted when a complete input sequence
/// has been entered by the user.
///
/// If the commit comes after a preediting sequence, the
/// ::commit signal is emitted after ::preedit-end.
///
/// This can be a single character immediately after a key press or
/// the final result of preediting.
/// ## `str`
/// the completed character(s) entered by the user
#[doc(alias = "commit")]
fn connect_commit<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn commit_trampoline<P: IsA<IMContext>, F: Fn(&P, &str) + 'static>(
this: *mut ffi::GtkIMContext,
str: *mut std::ffi::c_char,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(
IMContext::from_glib_borrow(this).unsafe_cast_ref(),
&glib::GString::from_glib_borrow(str),
)
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"commit\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
commit_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
/// The ::delete-surrounding signal is emitted when the input method
/// needs to delete all or part of the context surrounding the cursor.
/// ## `offset`
/// the character offset from the cursor position of the text
/// to be deleted. A negative value indicates a position before
/// the cursor.
/// ## `n_chars`
/// the number of characters to be deleted
///
/// # Returns
///
/// [`true`] if the signal was handled.
#[doc(alias = "delete-surrounding")]
fn connect_delete_surrounding<F: Fn(&Self, i32, i32) -> bool + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn delete_surrounding_trampoline<
P: IsA<IMContext>,
F: Fn(&P, i32, i32) -> bool + 'static,
>(
this: *mut ffi::GtkIMContext,
offset: std::ffi::c_int,
n_chars: std::ffi::c_int,
f: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let f: &F = &*(f as *const F);
f(
IMContext::from_glib_borrow(this).unsafe_cast_ref(),
offset,
n_chars,
)
.into_glib()
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"delete-surrounding\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
delete_surrounding_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
/// The ::preedit-changed signal is emitted whenever the preedit sequence
/// currently being entered has changed.
///
/// It is also emitted at the end of a preedit sequence, in which case
/// [`preedit_string()`][Self::preedit_string()] returns the empty string.
#[doc(alias = "preedit-changed")]
fn connect_preedit_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn preedit_changed_trampoline<P: IsA<IMContext>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkIMContext,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"preedit-changed\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
preedit_changed_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
/// The ::preedit-end signal is emitted when a preediting sequence
/// has been completed or canceled.
#[doc(alias = "preedit-end")]
fn connect_preedit_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn preedit_end_trampoline<P: IsA<IMContext>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkIMContext,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"preedit-end\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
preedit_end_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
/// The ::preedit-start signal is emitted when a new preediting sequence
/// starts.
#[doc(alias = "preedit-start")]
fn connect_preedit_start<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn preedit_start_trampoline<P: IsA<IMContext>, F: Fn(&P) + 'static>(
this: *mut ffi::GtkIMContext,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"preedit-start\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
preedit_start_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
/// The ::retrieve-surrounding signal is emitted when the input method
/// requires the context surrounding the cursor.
///
/// The callback should set the input method surrounding context by
/// calling the [`set_surrounding()`][Self::set_surrounding()] method.
///
/// # Returns
///
/// [`true`] if the signal was handled.
#[doc(alias = "retrieve-surrounding")]
fn connect_retrieve_surrounding<F: Fn(&Self) -> bool + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn retrieve_surrounding_trampoline<
P: IsA<IMContext>,
F: Fn(&P) -> bool + 'static,
>(
this: *mut ffi::GtkIMContext,
f: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let f: &F = &*(f as *const F);
f(IMContext::from_glib_borrow(this).unsafe_cast_ref()).into_glib()
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"retrieve-surrounding\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
retrieve_surrounding_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "input-hints")]
fn connect_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_input_hints_trampoline<
P: IsA<IMContext>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkIMContext,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::input-hints\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_input_hints_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "input-purpose")]
fn connect_input_purpose_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_input_purpose_trampoline<
P: IsA<IMContext>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::GtkIMContext,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(IMContext::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::input-purpose\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_input_purpose_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<IMContext>> IMContextExt for O {}