// GENERATED — DO NOT EDIT

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/class.IMContext.html).
pub type IMContext

///|
pub(open) trait IIMContext {
  fn as_im_context(Self) -> IMContext
  fn delete_surrounding(Self, Int, Int) -> Bool = _
  fn filter_key(
    Self,
    Bool,
    &@gdk.ISurface,
    &@gdk.IDevice,
    UInt,
    UInt,
    @gdk.ModifierType,
    Int,
  ) -> Bool = _
  fn focus_in(Self) -> Unit = _
  fn focus_out(Self) -> Unit = _
  fn get_preedit_string(Self) -> (@pango.AttrList, String, Int) = _
  fn get_surrounding_with_selection(Self) -> (Bool, String, Int, Int) = _
  fn reset(Self) -> Unit = _
  fn set_client_widget(Self, &IWidget?) -> Unit = _
  fn set_cursor_location(Self, @gdk.Rectangle) -> Unit = _
  fn set_surrounding_with_selection(Self, String, Int, Int, Int) -> Unit = _
  fn set_use_preedit(Self, Bool) -> Unit = _
  fn connect_commit(Self, (IMContext, String) -> Unit) -> UInt64 = _
  fn connect_delete_surrounding(Self, (IMContext, Int, Int) -> Bool) -> UInt64 = _
  fn connect_invalid_composition(Self, (IMContext, String) -> Bool) -> UInt64 = _
  fn connect_preedit_changed(Self, (IMContext) -> Unit) -> UInt64 = _
  fn connect_preedit_end(Self, (IMContext) -> Unit) -> UInt64 = _
  fn connect_preedit_start(Self, (IMContext) -> Unit) -> UInt64 = _
  fn connect_retrieve_surrounding(Self, (IMContext) -> Bool) -> UInt64 = _
}

///|
pub impl IIMContext for IMContext with fn as_im_context(self) {
  self
}

///|
/// Implementation contract for IMContext.activate_osk. Self is the retained MoonBit state; the second parameter is the invoked IMContext object.
pub(open) trait VIMContextActivateOsk {
  fn activate_osk(Self, IMContext) -> Unit
}

///|
/// Implementation contract for IMContext.commit. Self is the retained MoonBit state; the second parameter is the invoked IMContext object.
pub(open) trait VIMContextCommit {
  fn commit(Self, IMContext, String) -> Unit
}

///|
/// Implementation contract for IMContext.focus_in. Self is the retained MoonBit state; the second parameter is the invoked IMContext object.
pub(open) trait VIMContextFocusIn {
  fn focus_in(Self, IMContext) -> Unit
}

///|
/// Implementation contract for IMContext.focus_out. Self is the retained MoonBit state; the second parameter is the invoked IMContext object.
pub(open) trait VIMContextFocusOut {
  fn focus_out(Self, IMContext) -> Unit
}

///|
/// Implementation contract for IMContext.preedit_changed. Self is the retained MoonBit state; the second parameter is the invoked IMContext object.
pub(open) trait VIMContextPreeditChanged {
  fn preedit_changed(Self, IMContext) -> Unit
}

///|
/// Implementation contract for IMContext.preedit_end. Self is the retained MoonBit state; the second parameter is the invoked IMContext object.
pub(open) trait VIMContextPreeditEnd {
  fn preedit_end(Self, IMContext) -> Unit
}

///|
/// Implementation contract for IMContext.preedit_start. Self is the retained MoonBit state; the second parameter is the invoked IMContext object.
pub(open) trait VIMContextPreeditStart {
  fn preedit_start(Self, IMContext) -> Unit
}

///|
/// Implementation contract for IMContext.reset. Self is the retained MoonBit state; the second parameter is the invoked IMContext object.
pub(open) trait VIMContextReset {
  fn reset(Self, IMContext) -> Unit
}

///|
/// Implementation contract for IMContext.set_client_widget. Self is the retained MoonBit state; the second parameter is the invoked IMContext object.
pub(open) trait VIMContextSetClientWidget {
  fn set_client_widget(Self, IMContext, &IWidget?) -> Unit
}

///|
/// Implementation contract for IMContext.set_cursor_location. Self is the retained MoonBit state; the second parameter is the invoked IMContext object.
pub(open) trait VIMContextSetCursorLocation {
  fn set_cursor_location(Self, IMContext, @gdk.Rectangle) -> Unit
}

///|
/// Implementation contract for IMContext.set_surrounding_with_selection. Self is the retained MoonBit state; the second parameter is the invoked IMContext object.
pub(open) trait VIMContextSetSurroundingWithSelection {
  fn set_surrounding_with_selection(Self, IMContext, String, Int, Int, Int) -> Unit
}

///|
/// Implementation contract for IMContext.set_use_preedit. Self is the retained MoonBit state; the second parameter is the invoked IMContext object.
pub(open) trait VIMContextSetUsePreedit {
  fn set_use_preedit(Self, IMContext, Bool) -> Unit
}

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/method.IMContext.delete_surrounding.html).
#borrow(self)
pub extern "c" fn IMContext::delete_surrounding(
  self : IMContext,
  offset : Int,
  n_chars : Int,
) -> Bool = "moonbit_gtk_im_context_delete_surrounding"

///|
#borrow(self_, surface, device)
extern "c" fn moonbit_gtk_im_context_filter_key(
  self_ : IMContext,
  press : Bool,
  surface : @gdk.Surface,
  device : @gdk.Device,
  time : UInt,
  keycode : UInt,
  state : Int,
  group : Int,
) -> Bool = "moonbit_gtk_im_context_filter_key"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/method.IMContext.filter_key.html).
pub fn IMContext::filter_key(
  self : IMContext,
  press : Bool,
  surface : &@gdk.ISurface,
  device : &@gdk.IDevice,
  time : UInt,
  keycode : UInt,
  state : @gdk.ModifierType,
  group : Int,
) -> Bool {
  moonbit_gtk_im_context_filter_key(
    self,
    press,
    surface.as_surface(),
    device.as_device(),
    time,
    keycode,
    state.to_int(),
    group,
  )
}

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/method.IMContext.focus_in.html).
#borrow(self)
pub extern "c" fn IMContext::focus_in(self : IMContext) = "moonbit_gtk_im_context_focus_in"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/method.IMContext.focus_out.html).
#borrow(self)
pub extern "c" fn IMContext::focus_out(self : IMContext) = "moonbit_gtk_im_context_focus_out"

///|
#borrow(self_, str, cursor_pos)
extern "c" fn moonbit_gtk_im_context_get_preedit_string(
  self_ : IMContext,
  str : Ref[@glib.Nullable[Bytes]],
  cursor_pos : Ref[Int],
) -> @pango.AttrList = "moonbit_gtk_im_context_get_preedit_string"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/method.IMContext.get_preedit_string.html).
pub fn IMContext::get_preedit_string(
  self : IMContext,
) -> (@pango.AttrList, String, Int) {
  let str : Ref[@glib.Nullable[Bytes]] = Ref(@glib.Nullable::null())
  let cursor_pos = Ref(0)
  let __result = moonbit_gtk_im_context_get_preedit_string(
    self, str, cursor_pos,
  )
  (
    __result,
    match str.val.to_option() {
      Some(bytes) => @encoding/utf8.decode_lossy(bytes)
      None => ""
    },
    cursor_pos.val,
  )
}

///|
#borrow(self_, text, cursor_index, anchor_index)
extern "c" fn moonbit_gtk_im_context_get_surrounding_with_selection(
  self_ : IMContext,
  text : Ref[@glib.Nullable[Bytes]],
  cursor_index : Ref[Int],
  anchor_index : Ref[Int],
) -> Bool = "moonbit_gtk_im_context_get_surrounding_with_selection"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/method.IMContext.get_surrounding_with_selection.html).
pub fn IMContext::get_surrounding_with_selection(
  self : IMContext,
) -> (Bool, String, Int, Int) {
  let text : Ref[@glib.Nullable[Bytes]] = Ref(@glib.Nullable::null())
  let cursor_index = Ref(0)
  let anchor_index = Ref(0)
  let result = moonbit_gtk_im_context_get_surrounding_with_selection(
    self, text, cursor_index, anchor_index,
  )
  (
    result,
    match text.val.to_option() {
      Some(bytes) => @encoding/utf8.decode_lossy(bytes)
      None => ""
    },
    cursor_index.val,
    anchor_index.val,
  )
}

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/method.IMContext.reset.html).
#borrow(self)
pub extern "c" fn IMContext::reset(self : IMContext) = "moonbit_gtk_im_context_reset"

///|
#borrow(self_, widget)
extern "c" fn moonbit_gtk_im_context_set_client_widget(
  self_ : IMContext,
  widget : @glib.Nullable[Widget],
) = "moonbit_gtk_im_context_set_client_widget"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/method.IMContext.set_client_widget.html).
pub fn IMContext::set_client_widget(
  self : IMContext,
  widget : &IWidget?,
) -> Unit {
  moonbit_gtk_im_context_set_client_widget(
    self,
    match widget {
      Some(v) => @glib.Nullable::some(v.as_widget())
      None => @glib.Nullable::null()
    },
  )
}

///|
#borrow(self_, area)
extern "c" fn moonbit_gtk_im_context_set_cursor_location(
  self_ : IMContext,
  area : @gdk.Rectangle,
) = "moonbit_gtk_im_context_set_cursor_location"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/method.IMContext.set_cursor_location.html).
pub fn IMContext::set_cursor_location(
  self : IMContext,
  area : @gdk.Rectangle,
) -> Unit {
  moonbit_gtk_im_context_set_cursor_location(self, area)
}

///|
#borrow(self_, text)
extern "c" fn moonbit_gtk_im_context_set_surrounding_with_selection(
  self_ : IMContext,
  text : Bytes,
  len : Int,
  cursor_index : Int,
  anchor_index : Int,
) = "moonbit_gtk_im_context_set_surrounding_with_selection"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/method.IMContext.set_surrounding_with_selection.html).
pub fn IMContext::set_surrounding_with_selection(
  self : IMContext,
  text : String,
  len : Int,
  cursor_index : Int,
  anchor_index : Int,
) -> Unit {
  moonbit_gtk_im_context_set_surrounding_with_selection(
    self,
    @encoding/utf8.encode(text),
    len,
    cursor_index,
    anchor_index,
  )
}

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/method.IMContext.set_use_preedit.html).
#borrow(self)
pub extern "c" fn IMContext::set_use_preedit(
  self : IMContext,
  use_preedit : Bool,
) = "moonbit_gtk_im_context_set_use_preedit"

///|
#borrow(instance)
extern "c" fn gtk_im_context_connect_commit(
  instance : IMContext,
  function : FuncRef[(IMContext, Bytes, (IMContext, String) -> Unit) -> Unit],
  closure : (IMContext, String) -> Unit,
) -> UInt64 = "moonbit_gtk_im_context_connect_commit"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/signal.IMContext.commit.html).
pub fn IMContext::connect_commit(
  self : IMContext,
  f : (IMContext, String) -> Unit,
) -> UInt64 {
  gtk_im_context_connect_commit(
    self,
    fn(instance_, str, f) { f(instance_, @encoding/utf8.decode_lossy(str)) },
    f,
  )
}

///|
#borrow(instance)
extern "c" fn gtk_im_context_connect_delete_surrounding(
  instance : IMContext,
  function : FuncRef[
    (IMContext, Int, Int, (IMContext, Int, Int) -> Bool) -> Bool,
  ],
  closure : (IMContext, Int, Int) -> Bool,
) -> UInt64 = "moonbit_gtk_im_context_connect_delete_surrounding"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/signal.IMContext.delete-surrounding.html).
pub fn IMContext::connect_delete_surrounding(
  self : IMContext,
  f : (IMContext, Int, Int) -> Bool,
) -> UInt64 {
  gtk_im_context_connect_delete_surrounding(
    self,
    fn(instance_, offset, n_chars, f) { f(instance_, offset, n_chars) },
    f,
  )
}

///|
#borrow(instance)
extern "c" fn gtk_im_context_connect_invalid_composition(
  instance : IMContext,
  function : FuncRef[(IMContext, Bytes, (IMContext, String) -> Bool) -> Bool],
  closure : (IMContext, String) -> Bool,
) -> UInt64 = "moonbit_gtk_im_context_connect_invalid_composition"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/signal.IMContext.invalid-composition.html).
pub fn IMContext::connect_invalid_composition(
  self : IMContext,
  f : (IMContext, String) -> Bool,
) -> UInt64 {
  gtk_im_context_connect_invalid_composition(
    self,
    fn(instance_, str, f) { f(instance_, @encoding/utf8.decode_lossy(str)) },
    f,
  )
}

///|
#borrow(instance)
extern "c" fn gtk_im_context_connect_preedit_changed(
  instance : IMContext,
  function : FuncRef[(IMContext, (IMContext) -> Unit) -> Unit],
  closure : (IMContext) -> Unit,
) -> UInt64 = "moonbit_gtk_im_context_connect_preedit_changed"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/signal.IMContext.preedit-changed.html).
pub fn IMContext::connect_preedit_changed(
  self : IMContext,
  f : (IMContext) -> Unit,
) -> UInt64 {
  gtk_im_context_connect_preedit_changed(
    self,
    fn(instance_, f) { f(instance_) },
    f,
  )
}

///|
#borrow(instance)
extern "c" fn gtk_im_context_connect_preedit_end(
  instance : IMContext,
  function : FuncRef[(IMContext, (IMContext) -> Unit) -> Unit],
  closure : (IMContext) -> Unit,
) -> UInt64 = "moonbit_gtk_im_context_connect_preedit_end"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/signal.IMContext.preedit-end.html).
pub fn IMContext::connect_preedit_end(
  self : IMContext,
  f : (IMContext) -> Unit,
) -> UInt64 {
  gtk_im_context_connect_preedit_end(self, fn(instance_, f) { f(instance_) }, f)
}

///|
#borrow(instance)
extern "c" fn gtk_im_context_connect_preedit_start(
  instance : IMContext,
  function : FuncRef[(IMContext, (IMContext) -> Unit) -> Unit],
  closure : (IMContext) -> Unit,
) -> UInt64 = "moonbit_gtk_im_context_connect_preedit_start"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/signal.IMContext.preedit-start.html).
pub fn IMContext::connect_preedit_start(
  self : IMContext,
  f : (IMContext) -> Unit,
) -> UInt64 {
  gtk_im_context_connect_preedit_start(
    self,
    fn(instance_, f) { f(instance_) },
    f,
  )
}

///|
#borrow(instance)
extern "c" fn gtk_im_context_connect_retrieve_surrounding(
  instance : IMContext,
  function : FuncRef[(IMContext, (IMContext) -> Bool) -> Bool],
  closure : (IMContext) -> Bool,
) -> UInt64 = "moonbit_gtk_im_context_connect_retrieve_surrounding"

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/signal.IMContext.retrieve-surrounding.html).
pub fn IMContext::connect_retrieve_surrounding(
  self : IMContext,
  f : (IMContext) -> Bool,
) -> UInt64 {
  gtk_im_context_connect_retrieve_surrounding(
    self,
    fn(instance_, f) { f(instance_) },
    f,
  )
}

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/property.IMContext.input-hints.html).
#borrow(self_)
extern "c" fn __ffi_moonbit_gtk_im_context_get_input_hints(
  self_ : IMContext,
) -> Int = "moonbit_gtk_im_context_get_input_hints"

///|
pub fn IMContext::get_input_hints(self : IMContext) -> InputHints {
  InputHints::from_int(__ffi_moonbit_gtk_im_context_get_input_hints(self))
}

///|
#borrow(self_)
extern "c" fn __ffi_moonbit_gtk_im_context_set_input_hints(
  self_ : IMContext,
  value : Int,
) -> Unit = "moonbit_gtk_im_context_set_input_hints"

///|
pub fn IMContext::set_input_hints(self : IMContext, value : InputHints) -> Unit {
  __ffi_moonbit_gtk_im_context_set_input_hints(self, value.to_int())
}

///|
/// [Upstream documentation](https://docs.gtk.org/gtk4/property.IMContext.input-purpose.html).
#borrow(self_)
pub extern "c" fn IMContext::get_input_purpose(
  self_ : IMContext,
) -> InputPurpose = "moonbit_gtk_im_context_get_input_purpose"

///|
#borrow(self_)
pub extern "c" fn IMContext::set_input_purpose(
  self_ : IMContext,
  value : InputPurpose,
) = "moonbit_gtk_im_context_set_input_purpose"

///|
impl IIMContext with fn delete_surrounding(self, offset, n_chars) -> Bool {
  self.as_im_context().delete_surrounding(offset, n_chars)
}

///|
impl IIMContext with fn filter_key(
  self,
  press,
  surface,
  device,
  time,
  keycode,
  state,
  group,
) -> Bool {
  self
  .as_im_context()
  .filter_key(press, surface, device, time, keycode, state, group)
}

///|
impl IIMContext with fn focus_in(self) -> Unit {
  self.as_im_context().focus_in()
}

///|
impl IIMContext with fn focus_out(self) -> Unit {
  self.as_im_context().focus_out()
}

///|
impl IIMContext with fn get_preedit_string(self) -> (
  @pango.AttrList,
  String,
  Int,
) {
  self.as_im_context().get_preedit_string()
}

///|
impl IIMContext with fn get_surrounding_with_selection(self) -> (
  Bool,
  String,
  Int,
  Int,
) {
  self.as_im_context().get_surrounding_with_selection()
}

///|
impl IIMContext with fn reset(self) -> Unit {
  self.as_im_context().reset()
}

///|
impl IIMContext with fn set_client_widget(self, widget) -> Unit {
  self.as_im_context().set_client_widget(widget)
}

///|
impl IIMContext with fn set_cursor_location(self, area) -> Unit {
  self.as_im_context().set_cursor_location(area)
}

///|
impl IIMContext with fn set_surrounding_with_selection(
  self,
  text,
  len,
  cursor_index,
  anchor_index,
) -> Unit {
  self
  .as_im_context()
  .set_surrounding_with_selection(text, len, cursor_index, anchor_index)
}

///|
impl IIMContext with fn set_use_preedit(self, use_preedit) -> Unit {
  self.as_im_context().set_use_preedit(use_preedit)
}

///|
impl IIMContext with fn connect_commit(self, f) -> UInt64 {
  self.as_im_context().connect_commit(f)
}

///|
impl IIMContext with fn connect_delete_surrounding(self, f) -> UInt64 {
  self.as_im_context().connect_delete_surrounding(f)
}

///|
impl IIMContext with fn connect_invalid_composition(self, f) -> UInt64 {
  self.as_im_context().connect_invalid_composition(f)
}

///|
impl IIMContext with fn connect_preedit_changed(self, f) -> UInt64 {
  self.as_im_context().connect_preedit_changed(f)
}

///|
impl IIMContext with fn connect_preedit_end(self, f) -> UInt64 {
  self.as_im_context().connect_preedit_end(f)
}

///|
impl IIMContext with fn connect_preedit_start(self, f) -> UInt64 {
  self.as_im_context().connect_preedit_start(f)
}

///|
impl IIMContext with fn connect_retrieve_surrounding(self, f) -> UInt64 {
  self.as_im_context().connect_retrieve_surrounding(f)
}

///|
pub fn IMContext::as_gobject_object(self : IMContext) -> @gobject.Object = "%identity"

///|
pub impl @gobject.IObject for IMContext with fn as_object(self) {
  self.as_gobject_object()
}