# -*- coding: utf-8 -*-
# This file has been autogenerated by the pywayland scanner

# Copyright © 2012, 2013 Intel Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from pywayland.interface import Interface
from ..wayland.keyboard import Keyboard as wl_Keyboard


class InputMethodContextV1(Interface):
    """Input method context

    Corresponds to a text input on input method side. An input method context
    is created on text input activation on the input method side. It allows to
    receive information about the text input from the application via events.
    Input method contexts do not keep state after deactivation and should be
    destroyed after deactivation is handled.

    Text is generally UTF-8 encoded, indices and lengths are in bytes.

    Serials are used to synchronize the state between the text input and an
    input method. New serials are sent by the text input in the commit_state
    request and are used by the input method to indicate the known text input
    state in events like preedit_string, commit_string, and keysym. The text
    input can then ignore events from the input method which are based on an
    outdated state (for example after a reset).

    Warning! The protocol described in this file is experimental and backward
    incompatible changes may be made. Backward compatible changes may be added
    together with the corresponding interface version bump. Backward
    incompatible changes are done by bumping the version number in the protocol
    and interface names and resetting the interface version. Once the protocol
    is to be declared stable, the 'z' prefix and the version number in the
    protocol and interface names are removed and the interface version number
    is reset.
    """
    name = "zwp_input_method_context_v1"
    version = 1


@InputMethodContextV1.request("", [])
def destroy(self):
    """destroy
    """
    self._marshal(0)
    self._destroy()


@InputMethodContextV1.request("us", [None, None])
def commit_string(self, serial, text):
    """Commit string

    Send the commit string text for insertion to the application.

    The text to commit could be either just a single character after a key
    press or the result of some composing (pre-edit). It could be also an empty
    text when some text should be removed (see delete_surrounding_text) or when
    the input cursor should be moved (see cursor_position).

    Any previously set composing text will be removed.

    :param serial: serial of the latest known text input state
    :type serial: `uint`
    :param text:
    :type text: `string`
    """
    self._marshal(1, serial, text)


@InputMethodContextV1.request("uss", [None, None, None])
def preedit_string(self, serial, text, commit):
    """Pre-edit string

    Send the pre-edit string text to the application text input.

    The commit text can be used to replace the preedit text on reset (for
    example on unfocus).

    Also previously sent preedit_style and preedit_cursor requests are
    processed bt the text_input also.

    :param serial: serial of the latest known text input state
    :type serial: `uint`
    :param text:
    :type text: `string`
    :param commit:
    :type commit: `string`
    """
    self._marshal(2, serial, text, commit)


@InputMethodContextV1.request("uuu", [None, None, None])
def preedit_styling(self, index, length, style):
    """Pre-edit styling

    Sets styling information on composing text. The style is applied for length
    in bytes from index relative to the beginning of the composing text (as
    byte offset). Multiple styles can be applied to a composing text.

    This request should be sent before sending preedit_string request.

    :param index:
    :type index: `uint`
    :param length:
    :type length: `uint`
    :param style:
    :type style: `uint`
    """
    self._marshal(3, index, length, style)


@InputMethodContextV1.request("i", [None])
def preedit_cursor(self, index):
    """Pre-edit cursor

    Sets the cursor position inside the composing text (as byte offset)
    relative to the start of the composing text.

    When index is negative no cursor should be displayed.

    This request should be sent before sending preedit_string request.

    :param index:
    :type index: `int`
    """
    self._marshal(4, index)


@InputMethodContextV1.request("iu", [None, None])
def delete_surrounding_text(self, index, length):
    """Delete text

    This request will be handled on text_input side as part of a directly
    following commit_string request.

    :param index:
    :type index: `int`
    :param length:
    :type length: `uint`
    """
    self._marshal(5, index, length)


@InputMethodContextV1.request("ii", [None, None])
def cursor_position(self, index, anchor):
    """Set cursor to a new position

    Sets the cursor and anchor to a new position. Index is the new cursor
    position in bytes (when >= 0 relative to the end of inserted text else
    relative to beginning of inserted text). Anchor is the new anchor position
    in bytes (when >= 0 relative to the end of inserted text, else relative to
    beginning of inserted text). When there should be no selected text anchor
    should be the same as index.

    This request will be handled on text_input side as part of a directly
    following commit_string request.

    :param index:
    :type index: `int`
    :param anchor:
    :type anchor: `int`
    """
    self._marshal(6, index, anchor)


@InputMethodContextV1.request("a", [None])
def modifiers_map(self, map):
    """modifiers_map

    :param map:
    :type map: `array`
    """
    self._marshal(7, map)


@InputMethodContextV1.request("uuuuu", [None, None, None, None, None])
def keysym(self, serial, time, sym, state, modifiers):
    """Keysym

    Notify when a key event was sent. Key events should not be used for normal
    text input operations, which should be done with commit_string,
    delete_surrounfing_text, etc. The key event follows the
    :class:`~pywayland.protocol.wayland.keyboard.Keyboard` key event
    convention. Sym is a XKB keysym, state a
    :class:`~pywayland.protocol.wayland.keyboard.Keyboard` key_state.

    :param serial: serial of the latest known text input state
    :type serial: `uint`
    :param time:
    :type time: `uint`
    :param sym:
    :type sym: `uint`
    :param state:
    :type state: `uint`
    :param modifiers:
    :type modifiers: `uint`
    """
    self._marshal(8, serial, time, sym, state, modifiers)


@InputMethodContextV1.request("n", [wl_Keyboard])
def grab_keyboard(self):
    """Grab hardware keyboard

    Allows an input method to receive hardware keyboard input and process key
    events to generate text events (with pre-edit) over the wire. This allows
    input methods which compose multiple key events for inputting text like it
    is done for CJK languages.

    :returns: :class:`~pywayland.protocol.wayland.keyboard.Keyboard`
    """
    keyboard = self._marshal_constructor(9, wl_Keyboard)
    return keyboard


@InputMethodContextV1.request("uuuu", [None, None, None, None])
def key(self, serial, time, key, state):
    """Forward key event

    Should be used when filtering key events with grab_keyboard.

    When the :class:`~pywayland.protocol.wayland.keyboard.Keyboard`::key event
    is not processed by the input method itself and should be sent to the
    client instead, forward it with this request. The arguments should be the
    ones from the :class:`~pywayland.protocol.wayland.keyboard.Keyboard`::key
    event.

    For generating custom key events use the keysym request instead.

    :param serial: serial from :class:`~pywayland.protocol.wayland.keyboard.Keyboard`::key
    :type serial: `uint`
    :param time: time from :class:`~pywayland.protocol.wayland.keyboard.Keyboard`::key
    :type time: `uint`
    :param key: key from :class:`~pywayland.protocol.wayland.keyboard.Keyboard`::key
    :type key: `uint`
    :param state: state from :class:`~pywayland.protocol.wayland.keyboard.Keyboard`::key
    :type state: `uint`
    """
    self._marshal(10, serial, time, key, state)


@InputMethodContextV1.request("uuuuu", [None, None, None, None, None])
def modifiers(self, serial, mods_depressed, mods_latched, mods_locked, group):
    """Forward modifiers event

    Should be used when filtering key events with grab_keyboard.

    When the :class:`~pywayland.protocol.wayland.keyboard.Keyboard`::modifiers
    event should be also send to the client, forward it with this request. The
    arguments should be the ones from the
    :class:`~pywayland.protocol.wayland.keyboard.Keyboard`::modifiers event.

    :param serial: serial from :class:`~pywayland.protocol.wayland.keyboard.Keyboard`::modifiers
    :type serial: `uint`
    :param mods_depressed: mods_depressed from :class:`~pywayland.protocol.wayland.keyboard.Keyboard`::modifiers
    :type mods_depressed: `uint`
    :param mods_latched: mods_latched from :class:`~pywayland.protocol.wayland.keyboard.Keyboard`::modifiers
    :type mods_latched: `uint`
    :param mods_locked: mods_locked from :class:`~pywayland.protocol.wayland.keyboard.Keyboard`::modifiers
    :type mods_locked: `uint`
    :param group: group from :class:`~pywayland.protocol.wayland.keyboard.Keyboard`::modifiers
    :type group: `uint`
    """
    self._marshal(11, serial, mods_depressed, mods_latched, mods_locked, group)


@InputMethodContextV1.request("us", [None, None])
def language(self, serial, language):
    """language

    :param serial: serial of the latest known text input state
    :type serial: `uint`
    :param language:
    :type language: `string`
    """
    self._marshal(12, serial, language)


@InputMethodContextV1.request("uu", [None, None])
def text_direction(self, serial, direction):
    """text_direction

    :param serial: serial of the latest known text input state
    :type serial: `uint`
    :param direction:
    :type direction: `uint`
    """
    self._marshal(13, serial, direction)


@InputMethodContextV1.event("suu", [None, None, None])
def surrounding_text(self, text, cursor, anchor):
    """Surrounding text event

    The plain surrounding text around the input position. Cursor is the
    position in bytes within the surrounding text relative to the beginning of
    the text. Anchor is the position in bytes of the selection anchor within
    the surrounding text relative to the beginning of the text. If there is no
    selected text anchor is the same as cursor.

    :param text:
    :type text: `string`
    :param cursor:
    :type cursor: `uint`
    :param anchor:
    :type anchor: `uint`
    """
    self._post_event(0, text, cursor, anchor)


@InputMethodContextV1.event("", [])
def reset(self):
    """reset
    """
    self._post_event(1)


@InputMethodContextV1.event("uu", [None, None])
def content_type(self, hint, purpose):
    """content_type

    :param hint:
    :type hint: `uint`
    :param purpose:
    :type purpose: `uint`
    """
    self._post_event(2, hint, purpose)


@InputMethodContextV1.event("uu", [None, None])
def invoke_action(self, button, index):
    """invoke_action

    :param button:
    :type button: `uint`
    :param index:
    :type index: `uint`
    """
    self._post_event(3, button, index)


@InputMethodContextV1.event("u", [None])
def commit_state(self, serial):
    """commit_state

    :param serial: serial of text input state
    :type serial: `uint`
    """
    self._post_event(4, serial)


@InputMethodContextV1.event("s", [None])
def preferred_language(self, language):
    """preferred_language

    :param language:
    :type language: `string`
    """
    self._post_event(5, language)


InputMethodContextV1._gen_c()
