Blame gtk/gtkimcontext.c

Packit Service fb6fa5
/* GTK - The GIMP Toolkit
Packit Service fb6fa5
 * Copyright (C) 2000 Red Hat, Inc.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is free software; you can redistribute it and/or
Packit Service fb6fa5
 * modify it under the terms of the GNU Lesser General Public
Packit Service fb6fa5
 * License as published by the Free Software Foundation; either
Packit Service fb6fa5
 * version 2 of the License, or (at your option) any later version.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is distributed in the hope that it will be useful,
Packit Service fb6fa5
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fb6fa5
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service fb6fa5
 * Lesser General Public License for more details.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * You should have received a copy of the GNU Lesser General Public
Packit Service fb6fa5
 * License along with this library; if not, write to the
Packit Service fb6fa5
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit Service fb6fa5
 * Boston, MA 02111-1307, USA.
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
#include "config.h"
Packit Service fb6fa5
#include <string.h>
Packit Service fb6fa5
#include "gtkimcontext.h"
Packit Service fb6fa5
#include "gtkmain.h"		/* For _gtk_boolean_handled_accumulator */
Packit Service fb6fa5
#include "gtkmarshalers.h"
Packit Service fb6fa5
#include "gtkintl.h"
Packit Service fb6fa5
#include "gtkalias.h"
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * SECTION:gtkimcontext
Packit Service fb6fa5
 * @title: GtkIMContext
Packit Service fb6fa5
 * @short_description: Base class for input method contexts
Packit Service fb6fa5
 * @include: gtk/gtk.h,gtk/gtkimmodule.h
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * #GtkIMContext defines the interface for GTK+ input methods. An input method
Packit Service fb6fa5
 * is used by GTK+ text input widgets like #GtkEntry to map from key events to
Packit Service fb6fa5
 * Unicode character strings.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * The user may change the current input method via a context menu, unless the   
Packit Service fb6fa5
 * #GtkSettings:gtk-show-input-method-menu GtkSettings property is set to FALSE. 
Packit Service fb6fa5
 * The default input method can be set programmatically via the 
Packit Service fb6fa5
 * #GtkSettings:gtk-im-module GtkSettings property. Alternatively, you may set 
Packit Service fb6fa5
 * the GTK_IM_MODULE environment variable as documented in #gtk-running.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * The #GtkEntry #GtkEntry:im-module and #GtkTextView #GtkTextView:im-module 
Packit Service fb6fa5
 * properties may also be used to set input methods for specific widget 
Packit Service fb6fa5
 * instances. For instance, a certain entry widget might be expected to contain 
Packit Service fb6fa5
 * certain characters which would be easier to input with a certain input 
Packit Service fb6fa5
 * method.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * An input method may consume multiple key events in sequence and finally
Packit Service fb6fa5
 * output the composed result. This is called preediting, and an input method
Packit Service fb6fa5
 * may provide feedback about this process by displaying the intermediate
Packit Service fb6fa5
 * composition states as preedit text. For instance, the default GTK+ input
Packit Service fb6fa5
 * method implements the input of arbitrary Unicode code points by holding down
Packit Service fb6fa5
 * the Control and Shift keys and then typing "U" followed by the hexadecimal
Packit Service fb6fa5
 * digits of the code point.  When releasing the Control and Shift keys,
Packit Service fb6fa5
 * preediting ends and the character is inserted as text. Ctrl+Shift+u20AC for
Packit Service fb6fa5
 * example results in the € sign.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Additional input methods can be made available for use by GTK+ widgets as
Packit Service fb6fa5
 * loadable modules. An input method module is a small shared library which
Packit Service fb6fa5
 * implements a subclass of #GtkIMContext or #GtkIMContextSimple and exports
Packit Service fb6fa5
 * these four functions:
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * <informalexample><programlisting>
Packit Service fb6fa5
 * void im_module_init(#GTypeModule *module);
Packit Service fb6fa5
 * </programlisting></informalexample>
Packit Service fb6fa5
 * This function should register the #GType of the #GtkIMContext subclass which
Packit Service fb6fa5
 * implements the input method by means of g_type_module_register_type(). Note
Packit Service fb6fa5
 * that g_type_register_static() cannot be used as the type needs to be
Packit Service fb6fa5
 * registered dynamically.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * <informalexample><programlisting>
Packit Service fb6fa5
 * void im_module_exit(void);
Packit Service fb6fa5
 * </programlisting></informalexample>
Packit Service fb6fa5
 * Here goes any cleanup code your input method might require on module unload.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * <informalexample><programlisting>
Packit Service fb6fa5
 * void im_module_list(const #GtkIMContextInfo ***contexts, int *n_contexts)
Packit Service fb6fa5
 * {
Packit Service fb6fa5
 *   *contexts = info_list;
Packit Service fb6fa5
 *   *n_contexts = G_N_ELEMENTS (info_list);
Packit Service fb6fa5
 * }
Packit Service fb6fa5
 * </programlisting></informalexample>
Packit Service fb6fa5
 * This function returns the list of input methods provided by the module. The
Packit Service fb6fa5
 * example implementation above shows a common solution and simply returns a
Packit Service fb6fa5
 * pointer to statically defined array of #GtkIMContextInfo items for each
Packit Service fb6fa5
 * provided input method.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * <informalexample><programlisting>
Packit Service fb6fa5
 * #GtkIMContext * im_module_create(const #gchar *context_id);
Packit Service fb6fa5
 * </programlisting></informalexample>
Packit Service fb6fa5
 * This function should return a pointer to a newly created instance of the
Packit Service fb6fa5
 * #GtkIMContext subclass identified by @context_id. The context ID is the same
Packit Service fb6fa5
 * as specified in the #GtkIMContextInfo array returned by im_module_list().
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * After a new loadable input method module has been installed on the system,
Packit Service fb6fa5
 * the configuration file <filename>immodules.cache</filename> needs to be
Packit Service fb6fa5
 * regenerated by <link linkend="gtk-query-immodules-2.0">gtk-query-immodules-2.0</link>,
Packit Service fb6fa5
 * in order for the new input method to become available to GTK+ applications.
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
enum {
Packit Service fb6fa5
  PREEDIT_START,
Packit Service fb6fa5
  PREEDIT_END,
Packit Service fb6fa5
  PREEDIT_CHANGED,
Packit Service fb6fa5
  COMMIT,
Packit Service fb6fa5
  RETRIEVE_SURROUNDING,
Packit Service fb6fa5
  DELETE_SURROUNDING,
Packit Service fb6fa5
  LAST_SIGNAL
Packit Service fb6fa5
};
Packit Service fb6fa5
Packit Service fb6fa5
static guint im_context_signals[LAST_SIGNAL] = { 0 };
Packit Service fb6fa5
Packit Service fb6fa5
static void     gtk_im_context_real_get_preedit_string (GtkIMContext   *context,
Packit Service fb6fa5
							gchar         **str,
Packit Service fb6fa5
							PangoAttrList **attrs,
Packit Service fb6fa5
							gint           *cursor_pos);
Packit Service fb6fa5
static gboolean gtk_im_context_real_filter_keypress    (GtkIMContext   *context,
Packit Service fb6fa5
							GdkEventKey    *event);
Packit Service fb6fa5
static gboolean gtk_im_context_real_get_surrounding    (GtkIMContext   *context,
Packit Service fb6fa5
							gchar         **text,
Packit Service fb6fa5
							gint           *cursor_index);
Packit Service fb6fa5
static void     gtk_im_context_real_set_surrounding    (GtkIMContext   *context,
Packit Service fb6fa5
							const char     *text,
Packit Service fb6fa5
							gint            len,
Packit Service fb6fa5
							gint            cursor_index);
Packit Service fb6fa5
Packit Service fb6fa5
G_DEFINE_ABSTRACT_TYPE (GtkIMContext, gtk_im_context, G_TYPE_OBJECT)
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * GtkIMContextClass:
Packit Service fb6fa5
 * @preedit_start: Default handler of the #GtkIMContext::preedit-start signal.
Packit Service fb6fa5
 * @preedit_end: Default handler of the #GtkIMContext::preedit-end signal.
Packit Service fb6fa5
 * @preedit_changed: Default handler of the #GtkIMContext::preedit-changed
Packit Service fb6fa5
 *   signal.
Packit Service fb6fa5
 * @commit: Default handler of the #GtkIMContext::commit signal.
Packit Service fb6fa5
 * @retrieve_surrounding: Default handler of the
Packit Service fb6fa5
 *   #GtkIMContext::retrieve-surrounding signal.
Packit Service fb6fa5
 * @delete_surrounding: Default handler of the
Packit Service fb6fa5
 *   #GtkIMContext::delete-surrounding signal.
Packit Service fb6fa5
 * @set_client_window: Called via gtk_im_context_set_client_window() when the
Packit Service fb6fa5
 *   input window where the entered text will appear changes. Override this to
Packit Service fb6fa5
 *   keep track of the current input window, for instance for the purpose of
Packit Service fb6fa5
 *   positioning a status display of your input method.
Packit Service fb6fa5
 * @get_preedit_string: Called via gtk_im_context_get_preedit_string() to
Packit Service fb6fa5
 *   retrieve the text currently being preedited for display at the cursor
Packit Service fb6fa5
 *   position. Any input method which composes complex characters or any
Packit Service fb6fa5
 *   other compositions from multiple sequential key presses should override
Packit Service fb6fa5
 *   this method to provide feedback.
Packit Service fb6fa5
 * @filter_keypress: Called via gtk_im_context_filter_keypress() on every
Packit Service fb6fa5
 *   key press or release event. Every non-trivial input method needs to
Packit Service fb6fa5
 *   override this in order to implement the mapping from key events to text.
Packit Service fb6fa5
 *   A return value of %TRUE indicates to the caller that the event was
Packit Service fb6fa5
 *   consumed by the input method. In that case, the #GtkIMContext::commit
Packit Service fb6fa5
 *   signal should be emitted upon completion of a key sequence to pass the
Packit Service fb6fa5
 *   resulting text back to the input widget. Alternatively, %FALSE may be
Packit Service fb6fa5
 *   returned to indicate that the event wasn't handled by the input method.
Packit Service fb6fa5
 *   If a builtin mapping exists for the key, it is used to produce a
Packit Service fb6fa5
 *   character.
Packit Service fb6fa5
 * @focus_in: Called via gtk_im_context_focus_in() when the input widget
Packit Service fb6fa5
 *   has gained focus. May be overridden to keep track of the current focus.
Packit Service fb6fa5
 * @focus_out: Called via gtk_im_context_focus_in() when the input widget
Packit Service fb6fa5
 *   has lost focus. May be overridden to keep track of the current focus.
Packit Service fb6fa5
 * @reset: Called via gtk_im_context_reset() to signal a change such as a
Packit Service fb6fa5
 *   change in cursor position. An input method that implements preediting
Packit Service fb6fa5
 *   should override this method to clear the preedit state on reset.
Packit Service fb6fa5
 * @set_cursor_location: Called via gtk_im_context_set_cursor_location()
Packit Service fb6fa5
 *   to inform the input method of the current cursor location relative to
Packit Service fb6fa5
 *   the client window. May be overridden to implement the display of popup
Packit Service fb6fa5
 *   windows at the cursor position.
Packit Service fb6fa5
 * @set_use_preedit: Called via gtk_im_context_set_use_preedit() to control
Packit Service fb6fa5
 *   the use of the preedit string. Override this to display feedback by some
Packit Service fb6fa5
 *   other means if turned off.
Packit Service fb6fa5
 * @set_surrounding: Called via gtk_im_context_set_surrounding() in response
Packit Service fb6fa5
 *   to signal #GtkIMContext::retrieve-surrounding to update the input
Packit Service fb6fa5
 *   method's idea of the context around the cursor. It is not necessary to
Packit Service fb6fa5
 *   override this method even with input methods which implement
Packit Service fb6fa5
 *   context-dependent behavior. The base implementation is sufficient for
Packit Service fb6fa5
 *   gtk_im_context_get_surrounding() to work.
Packit Service fb6fa5
 * @get_surrounding: Called via gtk_im_context_get_surrounding() to update
Packit Service fb6fa5
 *   the context around the cursor location. It is not necessary to override
Packit Service fb6fa5
 *   this method even with input methods which implement context-dependent
Packit Service fb6fa5
 *   behavior. The base implementation emits
Packit Service fb6fa5
 *   #GtkIMContext::retrieve-surrounding and records the context received
Packit Service fb6fa5
 *   by the subsequent invocation of @get_surrounding.
Packit Service fb6fa5
 */
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_im_context_class_init (GtkIMContextClass *klass)
Packit Service fb6fa5
{
Packit Service fb6fa5
  klass->get_preedit_string = gtk_im_context_real_get_preedit_string;
Packit Service fb6fa5
  klass->filter_keypress = gtk_im_context_real_filter_keypress;
Packit Service fb6fa5
  klass->get_surrounding = gtk_im_context_real_get_surrounding;
Packit Service fb6fa5
  klass->set_surrounding = gtk_im_context_real_set_surrounding;
Packit Service fb6fa5
Packit Service fb6fa5
  /**
Packit Service fb6fa5
   * GtkIMContext::preedit-start:
Packit Service fb6fa5
   * @context: the object on which the signal is emitted
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * The ::preedit-start signal is emitted when a new preediting sequence
Packit Service fb6fa5
   * starts.
Packit Service fb6fa5
   */
Packit Service fb6fa5
  im_context_signals[PREEDIT_START] =
Packit Service fb6fa5
    g_signal_new (I_("preedit-start"),
Packit Service fb6fa5
		  G_TYPE_FROM_CLASS (klass),
Packit Service fb6fa5
		  G_SIGNAL_RUN_LAST,
Packit Service fb6fa5
		  G_STRUCT_OFFSET (GtkIMContextClass, preedit_start),
Packit Service fb6fa5
		  NULL, NULL,
Packit Service fb6fa5
		  _gtk_marshal_VOID__VOID,
Packit Service fb6fa5
		  G_TYPE_NONE, 0);
Packit Service fb6fa5
  /**
Packit Service fb6fa5
   * GtkIMContext::preedit-end:
Packit Service fb6fa5
   * @context: the object on which the signal is emitted
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * The ::preedit-end signal is emitted when a preediting sequence
Packit Service fb6fa5
   * has been completed or canceled.
Packit Service fb6fa5
   */
Packit Service fb6fa5
  im_context_signals[PREEDIT_END] =
Packit Service fb6fa5
    g_signal_new (I_("preedit-end"),
Packit Service fb6fa5
		  G_TYPE_FROM_CLASS (klass),
Packit Service fb6fa5
		  G_SIGNAL_RUN_LAST,
Packit Service fb6fa5
		  G_STRUCT_OFFSET (GtkIMContextClass, preedit_end),
Packit Service fb6fa5
		  NULL, NULL,
Packit Service fb6fa5
		  _gtk_marshal_VOID__VOID,
Packit Service fb6fa5
		  G_TYPE_NONE, 0);
Packit Service fb6fa5
  /**
Packit Service fb6fa5
   * GtkIMContext::preedit-changed:
Packit Service fb6fa5
   * @context: the object on which the signal is emitted
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * The ::preedit-changed signal is emitted whenever the preedit sequence
Packit Service fb6fa5
   * currently being entered has changed.  It is also emitted at the end of
Packit Service fb6fa5
   * a preedit sequence, in which case
Packit Service fb6fa5
   * gtk_im_context_get_preedit_string() returns the empty string.
Packit Service fb6fa5
   */
Packit Service fb6fa5
  im_context_signals[PREEDIT_CHANGED] =
Packit Service fb6fa5
    g_signal_new (I_("preedit-changed"),
Packit Service fb6fa5
		  G_TYPE_FROM_CLASS (klass),
Packit Service fb6fa5
		  G_SIGNAL_RUN_LAST,
Packit Service fb6fa5
		  G_STRUCT_OFFSET (GtkIMContextClass, preedit_changed),
Packit Service fb6fa5
		  NULL, NULL,
Packit Service fb6fa5
		  _gtk_marshal_VOID__VOID,
Packit Service fb6fa5
		  G_TYPE_NONE, 0);
Packit Service fb6fa5
  /**
Packit Service fb6fa5
   * GtkIMContext::commit:
Packit Service fb6fa5
   * @context: the object on which the signal is emitted
Packit Service fb6fa5
   * @str: the completed character(s) entered by the user
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * The ::commit signal is emitted when a complete input sequence
Packit Service fb6fa5
   * has been entered by the user. This can be a single character
Packit Service fb6fa5
   * immediately after a key press or the final result of preediting.
Packit Service fb6fa5
   */
Packit Service fb6fa5
  im_context_signals[COMMIT] =
Packit Service fb6fa5
    g_signal_new (I_("commit"),
Packit Service fb6fa5
		  G_TYPE_FROM_CLASS (klass),
Packit Service fb6fa5
		  G_SIGNAL_RUN_LAST,
Packit Service fb6fa5
		  G_STRUCT_OFFSET (GtkIMContextClass, commit),
Packit Service fb6fa5
		  NULL, NULL,
Packit Service fb6fa5
		  _gtk_marshal_VOID__STRING,
Packit Service fb6fa5
		  G_TYPE_NONE, 1,
Packit Service fb6fa5
		  G_TYPE_STRING);
Packit Service fb6fa5
  /**
Packit Service fb6fa5
   * GtkIMContext::retrieve-surrounding:
Packit Service fb6fa5
   * @context: the object on which the signal is emitted
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * The ::retrieve-surrounding signal is emitted when the input method
Packit Service fb6fa5
   * requires the context surrounding the cursor.  The callback should set
Packit Service fb6fa5
   * the input method surrounding context by calling the
Packit Service fb6fa5
   * gtk_im_context_set_surrounding() method.
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * Return value: %TRUE if the signal was handled.
Packit Service fb6fa5
   */
Packit Service fb6fa5
  im_context_signals[RETRIEVE_SURROUNDING] =
Packit Service fb6fa5
    g_signal_new (I_("retrieve-surrounding"),
Packit Service fb6fa5
                  G_TYPE_FROM_CLASS (klass),
Packit Service fb6fa5
                  G_SIGNAL_RUN_LAST,
Packit Service fb6fa5
                  G_STRUCT_OFFSET (GtkIMContextClass, retrieve_surrounding),
Packit Service fb6fa5
                  _gtk_boolean_handled_accumulator, NULL,
Packit Service fb6fa5
                  _gtk_marshal_BOOLEAN__VOID,
Packit Service fb6fa5
                  G_TYPE_BOOLEAN, 0);
Packit Service fb6fa5
  /**
Packit Service fb6fa5
   * GtkIMContext::delete-surrounding:
Packit Service fb6fa5
   * @context: the object on which the signal is emitted
Packit Service fb6fa5
   * @offset:  the character offset from the cursor position of the text
Packit Service fb6fa5
   *           to be deleted. A negative value indicates a position before
Packit Service fb6fa5
   *           the cursor.
Packit Service fb6fa5
   * @n_chars: the number of characters to be deleted
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * The ::delete-surrounding signal is emitted when the input method
Packit Service fb6fa5
   * needs to delete all or part of the context surrounding the cursor.
Packit Service fb6fa5
   *
Packit Service fb6fa5
   * Return value: %TRUE if the signal was handled.
Packit Service fb6fa5
   */
Packit Service fb6fa5
  im_context_signals[DELETE_SURROUNDING] =
Packit Service fb6fa5
    g_signal_new (I_("delete-surrounding"),
Packit Service fb6fa5
                  G_TYPE_FROM_CLASS (klass),
Packit Service fb6fa5
                  G_SIGNAL_RUN_LAST,
Packit Service fb6fa5
                  G_STRUCT_OFFSET (GtkIMContextClass, delete_surrounding),
Packit Service fb6fa5
                  _gtk_boolean_handled_accumulator, NULL,
Packit Service fb6fa5
                  _gtk_marshal_BOOLEAN__INT_INT,
Packit Service fb6fa5
                  G_TYPE_BOOLEAN, 2,
Packit Service fb6fa5
                  G_TYPE_INT,
Packit Service fb6fa5
		  G_TYPE_INT);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_im_context_init (GtkIMContext *im_context)
Packit Service fb6fa5
{
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_im_context_real_get_preedit_string (GtkIMContext       *context,
Packit Service fb6fa5
					gchar             **str,
Packit Service fb6fa5
					PangoAttrList     **attrs,
Packit Service fb6fa5
					gint               *cursor_pos)
Packit Service fb6fa5
{
Packit Service fb6fa5
  if (str)
Packit Service fb6fa5
    *str = g_strdup ("");
Packit Service fb6fa5
  if (attrs)
Packit Service fb6fa5
    *attrs = pango_attr_list_new ();
Packit Service fb6fa5
  if (cursor_pos)
Packit Service fb6fa5
    *cursor_pos = 0;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
gtk_im_context_real_filter_keypress (GtkIMContext       *context,
Packit Service fb6fa5
				     GdkEventKey        *event)
Packit Service fb6fa5
{
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
typedef struct
Packit Service fb6fa5
{
Packit Service fb6fa5
  gchar *text;
Packit Service fb6fa5
  gint cursor_index;
Packit Service fb6fa5
} SurroundingInfo;
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_im_context_real_set_surrounding (GtkIMContext  *context,
Packit Service fb6fa5
				     const gchar   *text,
Packit Service fb6fa5
				     gint           len,
Packit Service fb6fa5
				     gint           cursor_index)
Packit Service fb6fa5
{
Packit Service fb6fa5
  SurroundingInfo *info = g_object_get_data (G_OBJECT (context),
Packit Service fb6fa5
                                             "gtk-im-surrounding-info");
Packit Service fb6fa5
Packit Service fb6fa5
  if (info)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_free (info->text);
Packit Service fb6fa5
      info->text = g_strndup (text, len);
Packit Service fb6fa5
      info->cursor_index = cursor_index;
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
gtk_im_context_real_get_surrounding (GtkIMContext *context,
Packit Service fb6fa5
				     gchar       **text,
Packit Service fb6fa5
				     gint         *cursor_index)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gboolean result;
Packit Service fb6fa5
  gboolean info_is_local = FALSE;
Packit Service fb6fa5
  SurroundingInfo local_info = { NULL, 0 };
Packit Service fb6fa5
  SurroundingInfo *info;
Packit Service fb6fa5
  
Packit Service fb6fa5
  info = g_object_get_data (G_OBJECT (context), "gtk-im-surrounding-info");
Packit Service fb6fa5
  if (!info)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      info = &local_info;
Packit Service fb6fa5
      g_object_set_data (G_OBJECT (context), I_("gtk-im-surrounding-info"), info);
Packit Service fb6fa5
      info_is_local = TRUE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_signal_emit (context,
Packit Service fb6fa5
		 im_context_signals[RETRIEVE_SURROUNDING], 0,
Packit Service fb6fa5
		 &result);
Packit Service fb6fa5
Packit Service fb6fa5
  if (result)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      *text = g_strdup (info->text ? info->text : "");
Packit Service fb6fa5
      *cursor_index = info->cursor_index;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  else
Packit Service fb6fa5
    {
Packit Service fb6fa5
      *text = NULL;
Packit Service fb6fa5
      *cursor_index = 0;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  if (info_is_local)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      g_free (info->text);
Packit Service fb6fa5
      g_object_set_data (G_OBJECT (context), I_("gtk-im-surrounding-info"), NULL);
Packit Service fb6fa5
    }
Packit Service fb6fa5
  
Packit Service fb6fa5
  return result;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_im_context_set_client_window:
Packit Service fb6fa5
 * @context: a #GtkIMContext
Packit Service fb6fa5
 * @window: (allow-none):  the client window. This may be %NULL to indicate
Packit Service fb6fa5
 *           that the previous client window no longer exists.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Set the client window for the input context; this is the
Packit Service fb6fa5
 * #GdkWindow in which the input appears. This window is
Packit Service fb6fa5
 * used in order to correctly position status windows, and may
Packit Service fb6fa5
 * also be used for purposes internal to the input method.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_im_context_set_client_window (GtkIMContext *context,
Packit Service fb6fa5
				  GdkWindow    *window)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkIMContextClass *klass;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_IM_CONTEXT (context));
Packit Service fb6fa5
Packit Service fb6fa5
  klass = GTK_IM_CONTEXT_GET_CLASS (context);
Packit Service fb6fa5
  if (klass->set_client_window)
Packit Service fb6fa5
    klass->set_client_window (context, window);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_im_context_get_preedit_string:
Packit Service fb6fa5
 * @context:    a #GtkIMContext
Packit Service fb6fa5
 * @str:        (out) (transfer full): location to store the retrieved
Packit Service fb6fa5
 *              string. The string retrieved must be freed with g_free().
Packit Service fb6fa5
 * @attrs:      (out) (transfer full): location to store the retrieved
Packit Service fb6fa5
 *              attribute list.  When you are done with this list, you
Packit Service fb6fa5
 *              must unreference it with pango_attr_list_unref().
Packit Service fb6fa5
 * @cursor_pos: (out): location to store position of cursor (in characters)
Packit Service fb6fa5
 *              within the preedit string.  
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Retrieve the current preedit string for the input context,
Packit Service fb6fa5
 * and a list of attributes to apply to the string.
Packit Service fb6fa5
 * This string should be displayed inserted at the insertion
Packit Service fb6fa5
 * point.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_im_context_get_preedit_string (GtkIMContext   *context,
Packit Service fb6fa5
				   gchar         **str,
Packit Service fb6fa5
				   PangoAttrList **attrs,
Packit Service fb6fa5
				   gint           *cursor_pos)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkIMContextClass *klass;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_IM_CONTEXT (context));
Packit Service fb6fa5
  
Packit Service fb6fa5
  klass = GTK_IM_CONTEXT_GET_CLASS (context);
Packit Service fb6fa5
  klass->get_preedit_string (context, str, attrs, cursor_pos);
Packit Service fb6fa5
  g_return_if_fail (str == NULL || g_utf8_validate (*str, -1, NULL));
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_im_context_filter_keypress:
Packit Service fb6fa5
 * @context: a #GtkIMContext
Packit Service fb6fa5
 * @event: the key event
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Allow an input method to internally handle key press and release 
Packit Service fb6fa5
 * events. If this function returns %TRUE, then no further processing
Packit Service fb6fa5
 * should be done for this key event.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Return value: %TRUE if the input method handled the key event.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 **/
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_im_context_filter_keypress (GtkIMContext *context,
Packit Service fb6fa5
				GdkEventKey  *key)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkIMContextClass *klass;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_IM_CONTEXT (context), FALSE);
Packit Service fb6fa5
  g_return_val_if_fail (key != NULL, FALSE);
Packit Service fb6fa5
Packit Service fb6fa5
  klass = GTK_IM_CONTEXT_GET_CLASS (context);
Packit Service fb6fa5
  return klass->filter_keypress (context, key);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_im_context_focus_in:
Packit Service fb6fa5
 * @context: a #GtkIMContext
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Notify the input method that the widget to which this
Packit Service fb6fa5
 * input context corresponds has gained focus. The input method
Packit Service fb6fa5
 * may, for example, change the displayed feedback to reflect
Packit Service fb6fa5
 * this change.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_im_context_focus_in (GtkIMContext   *context)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkIMContextClass *klass;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_IM_CONTEXT (context));
Packit Service fb6fa5
  
Packit Service fb6fa5
  klass = GTK_IM_CONTEXT_GET_CLASS (context);
Packit Service fb6fa5
  if (klass->focus_in)
Packit Service fb6fa5
    klass->focus_in (context);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_im_context_focus_out:
Packit Service fb6fa5
 * @context: a #GtkIMContext
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Notify the input method that the widget to which this
Packit Service fb6fa5
 * input context corresponds has lost focus. The input method
Packit Service fb6fa5
 * may, for example, change the displayed feedback or reset the contexts
Packit Service fb6fa5
 * state to reflect this change.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_im_context_focus_out (GtkIMContext   *context)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkIMContextClass *klass;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_IM_CONTEXT (context));
Packit Service fb6fa5
Packit Service fb6fa5
  klass = GTK_IM_CONTEXT_GET_CLASS (context);
Packit Service fb6fa5
  if (klass->focus_out)
Packit Service fb6fa5
    klass->focus_out (context);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_im_context_reset:
Packit Service fb6fa5
 * @context: a #GtkIMContext
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Notify the input method that a change such as a change in cursor
Packit Service fb6fa5
 * position has been made. This will typically cause the input
Packit Service fb6fa5
 * method to clear the preedit state.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_im_context_reset (GtkIMContext   *context)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkIMContextClass *klass;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_IM_CONTEXT (context));
Packit Service fb6fa5
Packit Service fb6fa5
  klass = GTK_IM_CONTEXT_GET_CLASS (context);
Packit Service fb6fa5
  if (klass->reset)
Packit Service fb6fa5
    klass->reset (context);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_im_context_set_cursor_location:
Packit Service fb6fa5
 * @context: a #GtkIMContext
Packit Service fb6fa5
 * @area: new location
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Notify the input method that a change in cursor 
Packit Service fb6fa5
 * position has been made. The location is relative to the client
Packit Service fb6fa5
 * window.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_im_context_set_cursor_location (GtkIMContext       *context,
Packit Service fb6fa5
				    const GdkRectangle *area)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkIMContextClass *klass;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_IM_CONTEXT (context));
Packit Service fb6fa5
Packit Service fb6fa5
  klass = GTK_IM_CONTEXT_GET_CLASS (context);
Packit Service fb6fa5
  if (klass->set_cursor_location)
Packit Service fb6fa5
    klass->set_cursor_location (context, (GdkRectangle *) area);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_im_context_set_use_preedit:
Packit Service fb6fa5
 * @context: a #GtkIMContext
Packit Service fb6fa5
 * @use_preedit: whether the IM context should use the preedit string.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Sets whether the IM context should use the preedit string
Packit Service fb6fa5
 * to display feedback. If @use_preedit is FALSE (default
Packit Service fb6fa5
 * is TRUE), then the IM context may use some other method to display
Packit Service fb6fa5
 * feedback, such as displaying it in a child of the root window.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_im_context_set_use_preedit (GtkIMContext *context,
Packit Service fb6fa5
				gboolean      use_preedit)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkIMContextClass *klass;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_IM_CONTEXT (context));
Packit Service fb6fa5
Packit Service fb6fa5
  klass = GTK_IM_CONTEXT_GET_CLASS (context);
Packit Service fb6fa5
  if (klass->set_use_preedit)
Packit Service fb6fa5
    klass->set_use_preedit (context, use_preedit);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_im_context_set_surrounding:
Packit Service fb6fa5
 * @context: a #GtkIMContext 
Packit Service fb6fa5
 * @text: text surrounding the insertion point, as UTF-8.
Packit Service fb6fa5
 *        the preedit string should not be included within
Packit Service fb6fa5
 *        @text.
Packit Service fb6fa5
 * @len: the length of @text, or -1 if @text is nul-terminated
Packit Service fb6fa5
 * @cursor_index: the byte index of the insertion cursor within @text.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Sets surrounding context around the insertion point and preedit
Packit Service fb6fa5
 * string. This function is expected to be called in response to the
Packit Service fb6fa5
 * GtkIMContext::retrieve_surrounding signal, and will likely have no
Packit Service fb6fa5
 * effect if called at other times.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_im_context_set_surrounding (GtkIMContext  *context,
Packit Service fb6fa5
				const gchar   *text,
Packit Service fb6fa5
				gint           len,
Packit Service fb6fa5
				gint           cursor_index)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkIMContextClass *klass;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_IM_CONTEXT (context));
Packit Service fb6fa5
  g_return_if_fail (text != NULL || len == 0);
Packit Service fb6fa5
Packit Service fb6fa5
  if (text == NULL && len == 0)
Packit Service fb6fa5
    text = "";
Packit Service fb6fa5
  if (len < 0)
Packit Service fb6fa5
    len = strlen (text);
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_if_fail (cursor_index >= 0 && cursor_index <= len);
Packit Service fb6fa5
Packit Service fb6fa5
  klass = GTK_IM_CONTEXT_GET_CLASS (context);
Packit Service fb6fa5
  if (klass->set_surrounding)
Packit Service fb6fa5
    klass->set_surrounding (context, text, len, cursor_index);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_im_context_get_surrounding:
Packit Service fb6fa5
 * @context: a #GtkIMContext
Packit Service fb6fa5
 * @text: (out) (transfer full): location to store a UTF-8 encoded
Packit Service fb6fa5
 *        string of text holding context around the insertion point.
Packit Service fb6fa5
 *        If the function returns %TRUE, then you must free the result
Packit Service fb6fa5
 *        stored in this location with g_free().
Packit Service fb6fa5
 * @cursor_index: (out) location to store byte index of the insertion
Packit Service fb6fa5
 *        cursor within @text.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Retrieves context around the insertion point. Input methods
Packit Service fb6fa5
 * typically want context in order to constrain input text based on
Packit Service fb6fa5
 * existing text; this is important for languages such as Thai where
Packit Service fb6fa5
 * only some sequences of characters are allowed.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This function is implemented by emitting the
Packit Service fb6fa5
 * GtkIMContext::retrieve_surrounding signal on the input method; in
Packit Service fb6fa5
 * response to this signal, a widget should provide as much context as
Packit Service fb6fa5
 * is available, up to an entire paragraph, by calling
Packit Service fb6fa5
 * gtk_im_context_set_surrounding(). Note that there is no obligation
Packit Service fb6fa5
 * for a widget to respond to the ::retrieve_surrounding signal, so input
Packit Service fb6fa5
 * methods must be prepared to function without context.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: %TRUE if surrounding text was provided; in this case
Packit Service fb6fa5
 *    you must free the result stored in *text.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_im_context_get_surrounding (GtkIMContext *context,
Packit Service fb6fa5
				gchar       **text,
Packit Service fb6fa5
				gint         *cursor_index)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkIMContextClass *klass;
Packit Service fb6fa5
  gchar *local_text = NULL;
Packit Service fb6fa5
  gint local_index;
Packit Service fb6fa5
  gboolean result = FALSE;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_IM_CONTEXT (context), FALSE);
Packit Service fb6fa5
Packit Service fb6fa5
  klass = GTK_IM_CONTEXT_GET_CLASS (context);
Packit Service fb6fa5
  if (klass->get_surrounding)
Packit Service fb6fa5
    result = klass->get_surrounding (context,
Packit Service fb6fa5
				     text ? text : &local_text,
Packit Service fb6fa5
				     cursor_index ? cursor_index : &local_index);
Packit Service fb6fa5
Packit Service fb6fa5
  if (result)
Packit Service fb6fa5
    g_free (local_text);
Packit Service fb6fa5
Packit Service fb6fa5
  return result;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_im_context_delete_surrounding:
Packit Service fb6fa5
 * @context: a #GtkIMContext
Packit Service fb6fa5
 * @offset: offset from cursor position in chars;
Packit Service fb6fa5
 *    a negative value means start before the cursor.
Packit Service fb6fa5
 * @n_chars: number of characters to delete.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Asks the widget that the input context is attached to to delete
Packit Service fb6fa5
 * characters around the cursor position by emitting the
Packit Service fb6fa5
 * GtkIMContext::delete_surrounding signal. Note that @offset and @n_chars
Packit Service fb6fa5
 * are in characters not in bytes which differs from the usage other
Packit Service fb6fa5
 * places in #GtkIMContext.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * In order to use this function, you should first call
Packit Service fb6fa5
 * gtk_im_context_get_surrounding() to get the current context, and
Packit Service fb6fa5
 * call this function immediately afterwards to make sure that you
Packit Service fb6fa5
 * know what you are deleting. You should also account for the fact
Packit Service fb6fa5
 * that even if the signal was handled, the input context might not
Packit Service fb6fa5
 * have deleted all the characters that were requested to be deleted.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This function is used by an input method that wants to make
Packit Service fb6fa5
 * subsitutions in the existing text in response to new input. It is
Packit Service fb6fa5
 * not useful for applications.
Packit Service fb6fa5
 * 
Packit Service fb6fa5
 * Return value: %TRUE if the signal was handled.
Packit Service fb6fa5
 **/
Packit Service fb6fa5
gboolean
Packit Service fb6fa5
gtk_im_context_delete_surrounding (GtkIMContext *context,
Packit Service fb6fa5
				   gint          offset,
Packit Service fb6fa5
				   gint          n_chars)
Packit Service fb6fa5
{
Packit Service fb6fa5
  gboolean result;
Packit Service fb6fa5
  
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_IM_CONTEXT (context), FALSE);
Packit Service fb6fa5
Packit Service fb6fa5
  g_signal_emit (context,
Packit Service fb6fa5
		 im_context_signals[DELETE_SURROUNDING], 0,
Packit Service fb6fa5
		 offset, n_chars, &result);
Packit Service fb6fa5
Packit Service fb6fa5
  return result;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
#define __GTK_IM_CONTEXT_C__
Packit Service fb6fa5
#include "gtkaliasdef.c"