+
+/**
+ * gtk_im_context_set_surrounding:
+ * @context: a #GtkIMContext
+ * @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.
+ *
+ * Sets surrounding context around the insertion point and preedit
+ * string. This function is expected to be called in response to the
+ * GtkIMContext::retrieve_surrounding signal, and will likely have no
+ * effect if called at other times.
+ **/
+void
+gtk_im_context_set_surrounding (GtkIMContext *context,
+ const gchar *text,
+ gint len,
+ gint cursor_index)
+{
+ GtkIMContextClass *klass;
+
+ g_return_if_fail (GTK_IS_IM_CONTEXT (context));
+ g_return_if_fail (text != NULL || len == 0);
+
+ if (text == NULL && len == 0)
+ text = "";
+ if (len < 0)
+ len = strlen (text);
+
+ g_return_if_fail (cursor_index >= 0 && cursor_index <= len);
+
+ klass = GTK_IM_CONTEXT_GET_CLASS (context);
+ if (klass->set_surrounding)
+ klass->set_surrounding (context, text, len, cursor_index);
+}
+
+/**
+ * gtk_im_context_get_surrounding:
+ * @context: a #GtkIMContext
+ * @text: (out) (transfer full): 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: (out): location to store byte index of the insertion
+ * cursor within @text.
+ *
+ * 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
+ * GtkIMContext::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
+ * gtk_im_context_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.
+ *
+ * Return value: %TRUE if surrounding text was provided; in this case
+ * you must free the result stored in *text.
+ **/
+gboolean
+gtk_im_context_get_surrounding (GtkIMContext *context,
+ gchar **text,
+ gint *cursor_index)
+{
+ GtkIMContextClass *klass;
+ gchar *local_text = NULL;
+ gint local_index;
+ gboolean result = FALSE;
+
+ g_return_val_if_fail (GTK_IS_IM_CONTEXT (context), FALSE);
+
+ klass = GTK_IM_CONTEXT_GET_CLASS (context);
+ if (klass->get_surrounding)
+ result = klass->get_surrounding (context,
+ text ? text : &local_text,
+ cursor_index ? cursor_index : &local_index);
+
+ if (result)
+ g_free (local_text);
+
+ return result;
+}
+
+/**
+ * gtk_im_context_delete_surrounding:
+ * @context: a #GtkIMContext
+ * @offset: offset from cursor position in chars;
+ * a negative value means start before the cursor.
+ * @n_chars: number of characters to delete.
+ *
+ * Asks the widget that the input context is attached to to delete
+ * characters around the cursor position by emitting the
+ * GtkIMContext::delete_surrounding signal. Note that @offset and @n_chars
+ * are in characters not in bytes which differs from the usage other
+ * places in #GtkIMContext.
+ *
+ * In order to use this function, you should first call
+ * gtk_im_context_get_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
+ * subsitutions in the existing text in response to new input. It is
+ * not useful for applications.
+ *
+ * Return value: %TRUE if the signal was handled.
+ **/
+gboolean
+gtk_im_context_delete_surrounding (GtkIMContext *context,
+ gint offset,
+ gint n_chars)
+{
+ gboolean result;
+
+ g_return_val_if_fail (GTK_IS_IM_CONTEXT (context), FALSE);
+
+ g_signal_emit (context,
+ im_context_signals[DELETE_SURROUNDING], 0,
+ offset, n_chars, &result);
+
+ return result;
+}
+
+static void
+gtk_im_context_get_property (GObject *obj,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkIMContextPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj, GTK_TYPE_IM_CONTEXT, GtkIMContextPrivate);
+
+ switch (property_id)
+ {
+ case PROP_INPUT_PURPOSE:
+ g_value_set_enum (value, priv->purpose);
+ break;
+ case PROP_INPUT_HINTS:
+ g_value_set_flags (value, priv->hints);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_im_context_set_property (GObject *obj,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtkIMContextPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj, GTK_TYPE_IM_CONTEXT, GtkIMContextPrivate);
+
+ switch (property_id)
+ {
+ case PROP_INPUT_PURPOSE:
+ priv->purpose = g_value_get_enum (value);
+ break;
+ case PROP_INPUT_HINTS:
+ priv->hints = g_value_get_flags (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
+ break;
+ }
+}