2009-10-05 20:33:19 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
/*
|
2010-11-10 22:00:45 +00:00
|
|
|
* st-im-text.c: Text widget with input method support
|
|
|
|
*
|
|
|
|
* Copyright 2009 Red Hat, Inc.
|
2009-10-05 20:33:19 +00:00
|
|
|
*
|
|
|
|
* This started as a copy of ClutterIMText converted to use
|
|
|
|
* GtkIMContext rather than ClutterIMContext. Original code:
|
|
|
|
*
|
|
|
|
* Author: raymond liu <raymond.liu@intel.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009, Intel Corporation.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* version 2.1 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
2010-11-10 22:00:45 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-10-05 20:33:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2011-11-02 16:24:49 +00:00
|
|
|
* SECTION:st-im-text
|
2009-10-05 20:33:19 +00:00
|
|
|
* @short_description: Text widget with input method support
|
|
|
|
* @stability: Unstable
|
|
|
|
* @see_also: #ClutterText
|
|
|
|
* @include: st-imtext/st-imtext.h
|
|
|
|
*
|
|
|
|
* #StIMText derives from ClutterText and hooks up better text input
|
|
|
|
* via #GtkIMContext. It is meant to be a drop-in replacement for
|
|
|
|
* ClutterIMText but using GtkIMContext rather than ClutterIMContext.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
2010-12-22 21:26:08 +00:00
|
|
|
#include <gdk/gdkx.h>
|
2009-10-05 20:33:19 +00:00
|
|
|
#include <X11/extensions/XKB.h>
|
|
|
|
|
|
|
|
#include "st-im-text.h"
|
|
|
|
|
2013-01-09 08:27:20 +00:00
|
|
|
/* properties */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_INPUT_PURPOSE,
|
|
|
|
PROP_INPUT_HINTS,
|
|
|
|
};
|
|
|
|
|
2009-10-05 20:33:19 +00:00
|
|
|
struct _StIMTextPrivate
|
|
|
|
{
|
|
|
|
GtkIMContext *im_context;
|
|
|
|
GdkWindow *window;
|
|
|
|
|
|
|
|
guint need_im_reset : 1;
|
2015-02-26 18:21:52 +00:00
|
|
|
guint has_preedit : 1;
|
2009-10-05 20:33:19 +00:00
|
|
|
};
|
|
|
|
|
2015-09-24 16:04:48 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (StIMText, st_im_text, CLUTTER_TYPE_TEXT)
|
2009-10-05 20:33:19 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
st_im_text_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
StIMTextPrivate *priv = ST_IM_TEXT (object)->priv;
|
|
|
|
|
2010-03-10 23:22:06 +00:00
|
|
|
G_OBJECT_CLASS (st_im_text_parent_class)->dispose (object);
|
2012-10-12 10:28:36 +00:00
|
|
|
|
|
|
|
g_clear_object (&priv->im_context);
|
2009-10-05 20:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-10 14:31:39 +00:00
|
|
|
st_im_text_cursor_event (ClutterText *self,
|
|
|
|
const ClutterGeometry *geometry)
|
2009-10-05 20:33:19 +00:00
|
|
|
{
|
2013-04-10 14:31:39 +00:00
|
|
|
StIMTextPrivate *priv = ST_IM_TEXT (self)->priv;
|
2009-10-05 20:33:19 +00:00
|
|
|
gfloat actor_x, actor_y;
|
|
|
|
GdkRectangle area;
|
|
|
|
|
2011-04-05 14:55:27 +00:00
|
|
|
clutter_actor_get_transformed_position (CLUTTER_ACTOR (self), &actor_x, &actor_y);
|
2009-10-05 20:33:19 +00:00
|
|
|
|
2013-04-10 14:31:39 +00:00
|
|
|
area.x = (int)(0.5 + geometry->x + actor_x);
|
|
|
|
area.y = (int)(0.5 + geometry->y + actor_y);
|
|
|
|
area.width = geometry->width;
|
|
|
|
area.height = geometry->height;
|
2009-10-05 20:33:19 +00:00
|
|
|
|
|
|
|
gtk_im_context_set_cursor_location (priv->im_context, &area);
|
2013-04-10 14:31:39 +00:00
|
|
|
|
|
|
|
if (CLUTTER_TEXT_CLASS (st_im_text_parent_class)->cursor_event)
|
|
|
|
CLUTTER_TEXT_CLASS (st_im_text_parent_class)->cursor_event (self, geometry);
|
2009-10-05 20:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_im_text_commit_cb (GtkIMContext *context,
|
|
|
|
const gchar *str,
|
|
|
|
StIMText *imtext)
|
|
|
|
{
|
|
|
|
ClutterText *clutter_text = CLUTTER_TEXT (imtext);
|
|
|
|
|
|
|
|
if (clutter_text_get_editable (clutter_text))
|
|
|
|
{
|
|
|
|
clutter_text_delete_selection (clutter_text);
|
|
|
|
clutter_text_insert_text (clutter_text, str,
|
|
|
|
clutter_text_get_cursor_position (clutter_text));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:59:45 +00:00
|
|
|
static void
|
|
|
|
st_im_text_preedit_changed_cb (GtkIMContext *context,
|
|
|
|
StIMText *imtext)
|
|
|
|
{
|
|
|
|
ClutterText *clutter_text = CLUTTER_TEXT (imtext);
|
|
|
|
gchar *preedit_str = NULL;
|
|
|
|
PangoAttrList *preedit_attrs = NULL;
|
|
|
|
gint cursor_pos = 0;
|
|
|
|
|
|
|
|
gtk_im_context_get_preedit_string (context,
|
|
|
|
&preedit_str,
|
|
|
|
&preedit_attrs,
|
|
|
|
&cursor_pos);
|
|
|
|
|
|
|
|
clutter_text_set_preedit_string (clutter_text,
|
|
|
|
preedit_str,
|
|
|
|
preedit_attrs,
|
|
|
|
cursor_pos);
|
|
|
|
|
2015-02-26 18:21:52 +00:00
|
|
|
imtext->priv->has_preedit = preedit_str && *preedit_str;
|
|
|
|
|
2012-08-22 08:59:45 +00:00
|
|
|
g_free (preedit_str);
|
|
|
|
pango_attr_list_unref (preedit_attrs);
|
|
|
|
}
|
|
|
|
|
2012-08-30 03:25:55 +00:00
|
|
|
static gboolean
|
|
|
|
st_im_text_retrieve_surrounding_cb (GtkIMContext *context,
|
|
|
|
StIMText *imtext)
|
|
|
|
{
|
|
|
|
ClutterText *clutter_text = CLUTTER_TEXT (imtext);
|
|
|
|
ClutterTextBuffer *buffer;
|
|
|
|
const gchar *text;
|
|
|
|
gint cursor_pos;
|
|
|
|
|
|
|
|
buffer = clutter_text_get_buffer (clutter_text);
|
|
|
|
text = clutter_text_buffer_get_text (buffer);
|
|
|
|
|
|
|
|
cursor_pos = clutter_text_get_cursor_position (clutter_text);
|
|
|
|
if (cursor_pos < 0)
|
|
|
|
cursor_pos = clutter_text_buffer_get_length (buffer);
|
|
|
|
|
|
|
|
gtk_im_context_set_surrounding (context, text,
|
|
|
|
/* length and cursor_index are in bytes */
|
|
|
|
clutter_text_buffer_get_bytes (buffer),
|
|
|
|
g_utf8_offset_to_pointer (text, cursor_pos) - text);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
st_im_text_delete_surrounding_cb (GtkIMContext *context,
|
|
|
|
gint offset,
|
|
|
|
gint n_chars,
|
|
|
|
StIMText *imtext)
|
|
|
|
{
|
|
|
|
ClutterText *clutter_text = CLUTTER_TEXT (imtext);
|
|
|
|
|
|
|
|
if (clutter_text_get_editable (clutter_text))
|
|
|
|
{
|
|
|
|
gint cursor_pos = clutter_text_get_cursor_position (clutter_text);
|
|
|
|
clutter_text_delete_text (clutter_text,
|
|
|
|
cursor_pos + offset,
|
|
|
|
cursor_pos + offset + n_chars);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-10-05 20:33:19 +00:00
|
|
|
static void
|
|
|
|
reset_im_context (StIMText *self)
|
|
|
|
{
|
|
|
|
StIMTextPrivate *priv = self->priv;
|
|
|
|
|
|
|
|
if (priv->need_im_reset)
|
|
|
|
{
|
|
|
|
gtk_im_context_reset (priv->im_context);
|
|
|
|
priv->need_im_reset = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-13 12:59:41 +00:00
|
|
|
static gboolean
|
|
|
|
st_im_text_get_paint_volume (ClutterActor *self,
|
|
|
|
ClutterPaintVolume *volume)
|
|
|
|
{
|
|
|
|
return clutter_paint_volume_set_from_allocation (volume, self);
|
|
|
|
}
|
|
|
|
|
2017-06-06 21:27:00 +00:00
|
|
|
static GdkWindow *event_window = NULL;
|
2009-10-05 20:33:19 +00:00
|
|
|
|
2013-09-11 15:44:24 +00:00
|
|
|
void
|
|
|
|
st_im_text_set_event_window (GdkWindow *window)
|
|
|
|
{
|
|
|
|
g_assert (event_window == NULL);
|
2009-10-05 20:33:19 +00:00
|
|
|
|
2013-09-11 15:44:24 +00:00
|
|
|
event_window = window;
|
2009-10-05 20:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_im_text_realize (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
StIMTextPrivate *priv = ST_IM_TEXT (actor)->priv;
|
|
|
|
|
2017-06-06 21:27:55 +00:00
|
|
|
if (event_window != NULL)
|
|
|
|
{
|
|
|
|
priv->window = g_object_ref (event_window);
|
|
|
|
gtk_im_context_set_client_window (priv->im_context, priv->window);
|
|
|
|
}
|
2009-10-05 20:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_im_text_unrealize (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
StIMText *self = ST_IM_TEXT (actor);
|
|
|
|
StIMTextPrivate *priv = self->priv;
|
|
|
|
|
|
|
|
reset_im_context (self);
|
|
|
|
gtk_im_context_set_client_window (priv->im_context, NULL);
|
2017-06-06 21:27:55 +00:00
|
|
|
|
|
|
|
if (priv->window != NULL)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->window);
|
|
|
|
priv->window = NULL;
|
|
|
|
}
|
2009-10-05 20:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
key_is_modifier (guint16 keyval)
|
|
|
|
{
|
|
|
|
/* See gdkkeys-x11.c:_gdk_keymap_key_is_modifier() for how this
|
|
|
|
* really should be implemented */
|
|
|
|
|
|
|
|
switch (keyval)
|
|
|
|
{
|
2010-09-09 14:25:30 +00:00
|
|
|
case GDK_KEY_Shift_L:
|
|
|
|
case GDK_KEY_Shift_R:
|
|
|
|
case GDK_KEY_Control_L:
|
|
|
|
case GDK_KEY_Control_R:
|
|
|
|
case GDK_KEY_Caps_Lock:
|
|
|
|
case GDK_KEY_Shift_Lock:
|
|
|
|
case GDK_KEY_Meta_L:
|
|
|
|
case GDK_KEY_Meta_R:
|
|
|
|
case GDK_KEY_Alt_L:
|
|
|
|
case GDK_KEY_Alt_R:
|
|
|
|
case GDK_KEY_Super_L:
|
|
|
|
case GDK_KEY_Super_R:
|
|
|
|
case GDK_KEY_Hyper_L:
|
|
|
|
case GDK_KEY_Hyper_R:
|
|
|
|
case GDK_KEY_ISO_Lock:
|
|
|
|
case GDK_KEY_ISO_Level2_Latch:
|
|
|
|
case GDK_KEY_ISO_Level3_Shift:
|
|
|
|
case GDK_KEY_ISO_Level3_Latch:
|
|
|
|
case GDK_KEY_ISO_Level3_Lock:
|
|
|
|
case GDK_KEY_ISO_Level5_Shift:
|
|
|
|
case GDK_KEY_ISO_Level5_Latch:
|
|
|
|
case GDK_KEY_ISO_Level5_Lock:
|
|
|
|
case GDK_KEY_ISO_Group_Shift:
|
|
|
|
case GDK_KEY_ISO_Group_Latch:
|
|
|
|
case GDK_KEY_ISO_Group_Lock:
|
2009-10-05 20:33:19 +00:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkEventKey *
|
|
|
|
key_event_to_gdk (ClutterKeyEvent *event_clutter)
|
|
|
|
{
|
|
|
|
GdkEventKey *event_gdk;
|
2017-06-06 21:27:55 +00:00
|
|
|
|
|
|
|
if (event_window == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2009-10-05 20:33:19 +00:00
|
|
|
event_gdk = (GdkEventKey *)gdk_event_new ((event_clutter->type == CLUTTER_KEY_PRESS) ?
|
|
|
|
GDK_KEY_PRESS : GDK_KEY_RELEASE);
|
2013-09-11 15:44:24 +00:00
|
|
|
event_gdk->window = g_object_ref (event_window);
|
2009-10-05 20:33:19 +00:00
|
|
|
event_gdk->send_event = FALSE;
|
|
|
|
event_gdk->time = event_clutter->time;
|
|
|
|
/* This depends on ClutterModifierType and GdkModifierType being
|
|
|
|
* identical, which they are currently. (They both match the X
|
|
|
|
* modifier state in the low 16-bits and have the same extensions.) */
|
|
|
|
event_gdk->state = event_clutter->modifier_state;
|
|
|
|
event_gdk->keyval = event_clutter->keyval;
|
|
|
|
event_gdk->hardware_keycode = event_clutter->hardware_keycode;
|
|
|
|
/* For non-proper non-XKB support, we'd need a huge cut-and-paste
|
|
|
|
* from gdkkeys-x11.c; this is a macro that just shifts a few bits
|
|
|
|
* out of state, so won't make the situation worse if the server
|
|
|
|
* doesn't support XKB; we'll just end up with group == 0 */
|
|
|
|
event_gdk->group = XkbGroupForCoreState (event_gdk->state);
|
|
|
|
|
|
|
|
if (event_clutter->unicode_value)
|
|
|
|
{
|
|
|
|
/* This is not particularly close to what GDK does - event_gdk->string
|
|
|
|
* is supposed to be in the locale encoding, and have control keys
|
|
|
|
* as control characters, etc. See gdkevents-x11.c:translate_key_event().
|
|
|
|
* Hopefully no input method is using event.string.
|
|
|
|
*/
|
|
|
|
char buf[6];
|
|
|
|
|
|
|
|
event_gdk->length = g_unichar_to_utf8 (event_clutter->unicode_value, buf);
|
|
|
|
event_gdk->string = g_strndup (buf, event_gdk->length);
|
|
|
|
}
|
|
|
|
|
|
|
|
event_gdk->is_modifier = key_is_modifier (event_gdk->keyval);
|
|
|
|
|
|
|
|
return event_gdk;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
st_im_text_button_press_event (ClutterActor *actor,
|
|
|
|
ClutterButtonEvent *event)
|
|
|
|
{
|
|
|
|
/* The button press indicates the user moving the cursor, or selecting
|
|
|
|
* etc, so we should abort any current preedit operation. ClutterText
|
|
|
|
* treats all buttons identically, so so do we.
|
|
|
|
*/
|
|
|
|
reset_im_context (ST_IM_TEXT (actor));
|
|
|
|
|
|
|
|
if (CLUTTER_ACTOR_CLASS (st_im_text_parent_class)->button_press_event)
|
|
|
|
return CLUTTER_ACTOR_CLASS (st_im_text_parent_class)->button_press_event (actor, event);
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-12 12:35:52 +00:00
|
|
|
st_im_text_captured_event (ClutterActor *actor,
|
|
|
|
ClutterEvent *event)
|
2009-10-05 20:33:19 +00:00
|
|
|
{
|
|
|
|
StIMText *self = ST_IM_TEXT (actor);
|
|
|
|
StIMTextPrivate *priv = self->priv;
|
|
|
|
ClutterText *clutter_text = CLUTTER_TEXT (actor);
|
2012-09-12 12:35:52 +00:00
|
|
|
ClutterEventType type = clutter_event_type (event);
|
2009-10-05 20:33:19 +00:00
|
|
|
gboolean result = FALSE;
|
|
|
|
int old_position;
|
|
|
|
|
2012-09-12 12:35:52 +00:00
|
|
|
if (type != CLUTTER_KEY_PRESS && type != CLUTTER_KEY_RELEASE)
|
|
|
|
return FALSE;
|
|
|
|
|
2009-10-05 20:33:19 +00:00
|
|
|
if (clutter_text_get_editable (clutter_text))
|
|
|
|
{
|
2012-09-12 12:35:52 +00:00
|
|
|
GdkEventKey *event_gdk = key_event_to_gdk ((ClutterKeyEvent *)event);
|
2009-10-05 20:33:19 +00:00
|
|
|
|
2017-06-06 21:27:55 +00:00
|
|
|
if (event_gdk && gtk_im_context_filter_keypress (priv->im_context, event_gdk))
|
2009-10-05 20:33:19 +00:00
|
|
|
{
|
|
|
|
priv->need_im_reset = TRUE;
|
|
|
|
result = TRUE;
|
|
|
|
}
|
|
|
|
|
2017-06-06 21:27:55 +00:00
|
|
|
if (event_gdk)
|
|
|
|
gdk_event_free ((GdkEvent *)event_gdk);
|
2009-10-05 20:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
old_position = clutter_text_get_cursor_position (clutter_text);
|
|
|
|
|
|
|
|
if (!result &&
|
2012-09-12 12:35:52 +00:00
|
|
|
CLUTTER_ACTOR_CLASS (st_im_text_parent_class)->captured_event)
|
|
|
|
result = CLUTTER_ACTOR_CLASS (st_im_text_parent_class)->captured_event (actor, event);
|
2009-10-05 20:33:19 +00:00
|
|
|
|
2012-09-12 12:35:52 +00:00
|
|
|
if (type == CLUTTER_KEY_PRESS &&
|
|
|
|
clutter_text_get_cursor_position (clutter_text) != old_position)
|
2009-10-05 20:33:19 +00:00
|
|
|
reset_im_context (self);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_im_text_key_focus_in (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
StIMTextPrivate *priv = ST_IM_TEXT (actor)->priv;
|
|
|
|
ClutterText *clutter_text = CLUTTER_TEXT (actor);
|
|
|
|
|
|
|
|
if (clutter_text_get_editable (clutter_text))
|
|
|
|
{
|
|
|
|
priv->need_im_reset = TRUE;
|
|
|
|
gtk_im_context_focus_in (priv->im_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CLUTTER_ACTOR_CLASS (st_im_text_parent_class)->key_focus_in)
|
|
|
|
CLUTTER_ACTOR_CLASS (st_im_text_parent_class)->key_focus_in (actor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_im_text_key_focus_out (ClutterActor *actor)
|
|
|
|
{
|
|
|
|
StIMTextPrivate *priv = ST_IM_TEXT (actor)->priv;
|
|
|
|
ClutterText *clutter_text = CLUTTER_TEXT (actor);
|
|
|
|
|
|
|
|
if (clutter_text_get_editable (clutter_text))
|
|
|
|
{
|
|
|
|
priv->need_im_reset = TRUE;
|
|
|
|
gtk_im_context_focus_out (priv->im_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CLUTTER_ACTOR_CLASS (st_im_text_parent_class)->key_focus_out)
|
|
|
|
CLUTTER_ACTOR_CLASS (st_im_text_parent_class)->key_focus_out (actor);
|
|
|
|
}
|
|
|
|
|
2013-01-09 08:27:20 +00:00
|
|
|
static void
|
|
|
|
st_im_text_set_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
StIMText *imtext = ST_IM_TEXT (gobject);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_INPUT_PURPOSE:
|
|
|
|
st_im_text_set_input_purpose (imtext, g_value_get_enum (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_INPUT_HINTS:
|
|
|
|
st_im_text_set_input_hints (imtext, g_value_get_flags (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_im_text_get_property (GObject *gobject,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
StIMText *imtext = ST_IM_TEXT (gobject);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_INPUT_PURPOSE:
|
|
|
|
g_value_set_enum (value, st_im_text_get_input_purpose (imtext));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_INPUT_HINTS:
|
|
|
|
g_value_set_flags (value, st_im_text_get_input_hints (imtext));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-05 20:33:19 +00:00
|
|
|
static void
|
|
|
|
st_im_text_class_init (StIMTextClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
|
2013-04-10 14:31:39 +00:00
|
|
|
ClutterTextClass *text_class = CLUTTER_TEXT_CLASS (klass);
|
2013-01-09 08:27:20 +00:00
|
|
|
GParamSpec *pspec;
|
2009-10-05 20:33:19 +00:00
|
|
|
|
|
|
|
object_class->dispose = st_im_text_dispose;
|
2013-01-09 08:27:20 +00:00
|
|
|
object_class->set_property = st_im_text_set_property;
|
|
|
|
object_class->get_property = st_im_text_get_property;
|
2009-10-05 20:33:19 +00:00
|
|
|
|
2010-11-13 12:59:41 +00:00
|
|
|
actor_class->get_paint_volume = st_im_text_get_paint_volume;
|
2009-10-05 20:33:19 +00:00
|
|
|
actor_class->realize = st_im_text_realize;
|
|
|
|
actor_class->unrealize = st_im_text_unrealize;
|
|
|
|
|
|
|
|
actor_class->button_press_event = st_im_text_button_press_event;
|
2012-09-12 12:35:52 +00:00
|
|
|
actor_class->captured_event = st_im_text_captured_event;
|
2009-10-05 20:33:19 +00:00
|
|
|
actor_class->key_focus_in = st_im_text_key_focus_in;
|
|
|
|
actor_class->key_focus_out = st_im_text_key_focus_out;
|
2013-04-10 14:31:39 +00:00
|
|
|
|
|
|
|
text_class->cursor_event = st_im_text_cursor_event;
|
2013-01-09 08:27:20 +00:00
|
|
|
|
|
|
|
pspec = g_param_spec_enum ("input-purpose",
|
|
|
|
"Purpose",
|
|
|
|
"Purpose of the text field",
|
|
|
|
GTK_TYPE_INPUT_PURPOSE,
|
|
|
|
GTK_INPUT_PURPOSE_FREE_FORM,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_INPUT_PURPOSE,
|
|
|
|
pspec);
|
|
|
|
|
|
|
|
pspec = g_param_spec_flags ("input-hints",
|
|
|
|
"hints",
|
|
|
|
"Hints for the text field behaviour",
|
|
|
|
GTK_TYPE_INPUT_HINTS,
|
|
|
|
GTK_INPUT_HINT_NONE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_INPUT_HINTS,
|
|
|
|
pspec);
|
2009-10-05 20:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
st_im_text_init (StIMText *self)
|
|
|
|
{
|
|
|
|
StIMTextPrivate *priv;
|
|
|
|
|
2015-09-24 16:04:48 +00:00
|
|
|
self->priv = priv = st_im_text_get_instance_private (self);
|
2009-10-05 20:33:19 +00:00
|
|
|
|
|
|
|
priv->im_context = gtk_im_multicontext_new ();
|
|
|
|
g_signal_connect (priv->im_context, "commit",
|
|
|
|
G_CALLBACK (st_im_text_commit_cb), self);
|
2012-08-22 08:59:45 +00:00
|
|
|
g_signal_connect (priv->im_context, "preedit-changed",
|
|
|
|
G_CALLBACK (st_im_text_preedit_changed_cb), self);
|
2012-08-30 03:25:55 +00:00
|
|
|
g_signal_connect (priv->im_context, "retrieve-surrounding",
|
|
|
|
G_CALLBACK (st_im_text_retrieve_surrounding_cb), self);
|
|
|
|
g_signal_connect (priv->im_context, "delete-surrounding",
|
|
|
|
G_CALLBACK (st_im_text_delete_surrounding_cb), self);
|
2009-10-05 20:33:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_im_text_new:
|
|
|
|
* @text: text to set to
|
|
|
|
*
|
|
|
|
* Create a new #StIMText with the specified text
|
|
|
|
*
|
|
|
|
* Returns: a new #ClutterActor
|
|
|
|
*/
|
|
|
|
ClutterActor *
|
|
|
|
st_im_text_new (const gchar *text)
|
|
|
|
{
|
|
|
|
return g_object_new (ST_TYPE_IM_TEXT,
|
|
|
|
"text", text,
|
|
|
|
NULL);
|
|
|
|
}
|
2013-01-09 08:27:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* st_im_text_set_input_purpose:
|
|
|
|
* @imtext: a #StIMText
|
|
|
|
* @purpose: the purpose
|
|
|
|
*
|
|
|
|
* Sets the #StIMText:input-purpose property which
|
|
|
|
* can be used by on-screen keyboards and other input
|
|
|
|
* methods to adjust their behaviour.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
st_im_text_set_input_purpose (StIMText *imtext,
|
|
|
|
GtkInputPurpose purpose)
|
|
|
|
{
|
|
|
|
g_return_if_fail (ST_IS_IM_TEXT (imtext));
|
|
|
|
|
|
|
|
if (st_im_text_get_input_purpose (imtext) != purpose)
|
|
|
|
{
|
|
|
|
g_object_set (G_OBJECT (imtext->priv->im_context),
|
|
|
|
"input-purpose", purpose,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (imtext->priv->im_context),
|
|
|
|
"input-purpose", &purpose,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (imtext), "input-purpose");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_im_text_get_input_purpose:
|
|
|
|
* @imtext: a #StIMText
|
|
|
|
*
|
|
|
|
* Gets the value of the #StIMText:input-purpose property.
|
|
|
|
*/
|
|
|
|
GtkInputPurpose
|
|
|
|
st_im_text_get_input_purpose (StIMText *imtext)
|
|
|
|
{
|
|
|
|
GtkInputPurpose purpose;
|
|
|
|
|
|
|
|
g_return_val_if_fail (ST_IS_IM_TEXT (imtext), GTK_INPUT_PURPOSE_FREE_FORM);
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (imtext->priv->im_context),
|
|
|
|
"input-purpose", &purpose,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return purpose;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_im_text_set_input_hints:
|
|
|
|
* @imtext: a #StIMText
|
|
|
|
* @hints: the hints
|
|
|
|
*
|
|
|
|
* Sets the #StIMText:input-hints property, which
|
|
|
|
* allows input methods to fine-tune their behaviour.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
st_im_text_set_input_hints (StIMText *imtext,
|
|
|
|
GtkInputHints hints)
|
|
|
|
{
|
|
|
|
g_return_if_fail (ST_IS_IM_TEXT (imtext));
|
|
|
|
|
|
|
|
if (st_im_text_get_input_hints (imtext) != hints)
|
|
|
|
{
|
|
|
|
g_object_set (G_OBJECT (imtext->priv->im_context),
|
|
|
|
"input-hints", hints,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (imtext), "input-hints");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* st_im_text_get_input_hints:
|
|
|
|
* @imtext: a #StIMText
|
|
|
|
*
|
|
|
|
* Gets the value of the #StIMText:input-hints property.
|
|
|
|
*/
|
|
|
|
GtkInputHints
|
|
|
|
st_im_text_get_input_hints (StIMText *imtext)
|
|
|
|
{
|
|
|
|
GtkInputHints hints;
|
|
|
|
|
|
|
|
g_return_val_if_fail (ST_IS_IM_TEXT (imtext), GTK_INPUT_HINT_NONE);
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (imtext->priv->im_context),
|
|
|
|
"input-hints", &hints,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return hints;
|
|
|
|
}
|
2015-02-26 18:21:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* st_im_text_has_preedit:
|
|
|
|
* @imtext: a #StIMText
|
|
|
|
*
|
|
|
|
* Returns: wether @imtext currently has preedit text
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
st_im_text_has_preedit (StIMText *imtext)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (ST_IS_IM_TEXT (imtext), FALSE);
|
|
|
|
|
|
|
|
return imtext->priv->has_preedit;
|
|
|
|
}
|