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)); } }
static void st_entry_clipboard_callback (StClipboard *clipboard, const gchar *text, gpointer data) { ClutterText *ctext = (ClutterText*)((StEntry *) data)->priv->entry; gint cursor_pos; if (!text) return; /* delete the current selection before pasting */ clutter_text_delete_selection (ctext); /* "paste" the clipboard text into the entry */ cursor_pos = clutter_text_get_cursor_position (ctext); clutter_text_insert_text (ctext, text, cursor_pos); }
static gboolean st_entry_key_press_event (ClutterActor *actor, ClutterKeyEvent *event) { StEntryPrivate *priv = ST_ENTRY_PRIV (actor); /* This is expected to handle events that were emitted for the inner ClutterText. They only reach this function if the ClutterText didn't handle them */ /* paste */ if ((event->modifier_state & CLUTTER_CONTROL_MASK) && event->keyval == CLUTTER_v) { StClipboard *clipboard; clipboard = st_clipboard_get_default (); st_clipboard_get_text (clipboard, st_entry_clipboard_callback, actor); return TRUE; } /* copy */ if ((event->modifier_state & CLUTTER_CONTROL_MASK) && event->keyval == CLUTTER_c) { StClipboard *clipboard; gchar *text; clipboard = st_clipboard_get_default (); text = clutter_text_get_selection ((ClutterText*) priv->entry); if (text && strlen (text)) st_clipboard_set_text (clipboard, text); return TRUE; } /* cut */ if ((event->modifier_state & CLUTTER_CONTROL_MASK) && event->keyval == CLUTTER_x) { StClipboard *clipboard; gchar *text; clipboard = st_clipboard_get_default (); text = clutter_text_get_selection ((ClutterText*) priv->entry); if (text && strlen (text)) { st_clipboard_set_text (clipboard, text); /* now delete the text */ clutter_text_delete_selection ((ClutterText *) priv->entry); } return TRUE; } return CLUTTER_ACTOR_CLASS (st_entry_parent_class)->key_press_event (actor, event); }