From 7692a427a6d27f438e18dc3555a91eef2f4205ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Wed, 5 May 2010 01:16:55 +0200 Subject: [PATCH] Added api to reset the im context in GtkTextView and GtkEntry Also, added api to allow an input method to internally handle key press and release events in the GtkTextView and GtkEntry cases. This is simply a wrapper to the gtk_im_context_filter_keypress() function, but It's added to not access the ->im_context directly. Based on a Christian Dywan patch Fixes https://bugzilla.gnome.org/show_bug.cgi?id=163251 --- docs/reference/gtk/gtk-sections.txt | 4 ++ gtk/gtk.symbols | 4 ++ gtk/gtkentry.c | 49 +++++++++++++++++++++++ gtk/gtkentry.h | 4 ++ gtk/gtktextview.c | 61 ++++++++++++++++++++++++++++- gtk/gtktextview.h | 4 ++ 6 files changed, 124 insertions(+), 2 deletions(-) diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index 684b30db99..692b05f201 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -1316,6 +1316,8 @@ gtk_entry_get_progress_fraction gtk_entry_set_progress_pulse_step gtk_entry_get_progress_pulse_step gtk_entry_progress_pulse +gtk_entry_im_context_filter_keypress +gtk_entry_reset_im_context GtkEntryIconPosition gtk_entry_set_icon_from_pixbuf gtk_entry_set_icon_from_stock @@ -4129,6 +4131,8 @@ gtk_text_view_get_tabs gtk_text_view_set_accepts_tab gtk_text_view_get_accepts_tab gtk_text_view_get_default_attributes +gtk_text_view_im_context_filter_keypress +gtk_text_view_reset_im_context GTK_TEXT_VIEW_PRIORITY_VALIDATE GTK_TEXT_VIEW diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index a285bfde05..2e1b8f7da5 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -1384,10 +1384,12 @@ gtk_entry_get_type G_GNUC_CONST gtk_entry_get_visibility gtk_entry_get_width_chars gtk_entry_get_text_window +gtk_entry_im_context_filter_keypress gtk_entry_layout_index_to_text_index gtk_entry_new gtk_entry_new_with_buffer gtk_entry_progress_pulse +gtk_entry_reset_im_context gtk_entry_set_activates_default gtk_entry_set_alignment gtk_entry_set_buffer @@ -4286,12 +4288,14 @@ gtk_text_view_get_visible_rect gtk_text_view_get_window gtk_text_view_get_window_type gtk_text_view_get_wrap_mode +gtk_text_view_im_context_filter_keypress gtk_text_view_move_child gtk_text_view_move_mark_onscreen gtk_text_view_move_visually gtk_text_view_new gtk_text_view_new_with_buffer gtk_text_view_place_cursor_onscreen +gtk_text_view_reset_im_context gtk_text_view_scroll_mark_onscreen gtk_text_view_scroll_to_iter gtk_text_view_scroll_to_mark diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 20653b4fca..066fd9cb8a 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -5807,6 +5807,55 @@ _gtk_entry_reset_im_context (GtkEntry *entry) } } +/** + * gtk_entry_reset_im_context: + * @entry: a #GtkEntry + * + * Reset the input method context of the entry if needed. + * + * This can be necessary in the case where modifying the buffer + * would confuse on-going input method behavior. + * + * Since: 2.22 + */ +void +gtk_entry_reset_im_context (GtkEntry *entry) +{ + g_return_if_fail (GTK_IS_ENTRY (entry)); + + _gtk_entry_reset_im_context (entry); +} + +/** + * gtk_entry_im_context_filter_keypress: + * @entry: a #GtkEntry + * @event: the key event + * + * Allow the #GtkEntry input method to internally handle key press + * and release events. If this function returns %TRUE, then no further + * processing should be done for this key event. See + * gtk_im_context_filter_keypress(). + * + * Note that you are expected to call this function from your handler + * when overriding key event handling. This is needed in the case when + * you need to insert your own key handling between the input method + * and the default key event handling of the #GtkEntry. + * See gtk_text_view_reset_im_context() for an example of use. + * + * Return value: %TRUE if the input method handled the key event. + * + * Since: 2.22 + */ +gboolean +gtk_entry_im_context_filter_keypress (GtkEntry *entry, + GdkEventKey *key) +{ + g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE); + + return gtk_im_context_filter_keypress (entry->im_context, key); +} + + static gint gtk_entry_find_position (GtkEntry *entry, gint x) diff --git a/gtk/gtkentry.h b/gtk/gtkentry.h index 0c82c63224..e2044959a6 100644 --- a/gtk/gtkentry.h +++ b/gtk/gtkentry.h @@ -306,6 +306,10 @@ gint gtk_entry_get_current_icon_drag_source (GtkEntry * GdkWindow * gtk_entry_get_icon_window (GtkEntry *entry, GtkEntryIconPosition icon_pos); +gboolean gtk_entry_im_context_filter_keypress (GtkEntry *entry, + GdkEventKey *key); +void gtk_entry_reset_im_context (GtkEntry *entry); + /* Deprecated compatibility functions */ diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index e28610127d..f12621d4ec 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -297,7 +297,6 @@ static void gtk_text_view_set_attributes_from_style (GtkTextView *tex static void gtk_text_view_ensure_layout (GtkTextView *text_view); static void gtk_text_view_destroy_layout (GtkTextView *text_view); static void gtk_text_view_check_keymap_direction (GtkTextView *text_view); -static void gtk_text_view_reset_im_context (GtkTextView *text_view); static void gtk_text_view_start_selection_drag (GtkTextView *text_view, const GtkTextIter *iter, GdkEventButton *event); @@ -6574,9 +6573,22 @@ gtk_text_view_destroy_layout (GtkTextView *text_view) } } -static void +/** + * gtk_text_view_reset_im_context: + * @text_view: a #GtkTextView + * + * Reset the input method context of the text view if needed. + * + * This can be necessary in the case where modifying the buffer + * would confuse on-going input method behavior. + * + * Since: 2.22 + */ +void gtk_text_view_reset_im_context (GtkTextView *text_view) { + g_return_if_fail (GTK_IS_TEXT_VIEW (text_view)); + if (text_view->need_im_reset) { text_view->need_im_reset = FALSE; @@ -6584,6 +6596,51 @@ gtk_text_view_reset_im_context (GtkTextView *text_view) } } +/** + * gtk_text_view_im_context_filter_keypress: + * @text_view: a #GtkTextView + * @event: the key event + * + * Allow the #GtkTextView input method to internally handle key press + * and release events. If this function returns %TRUE, then no further + * processing should be done for this key event. See + * gtk_im_context_filter_keypress(). + * + * Note that you are expected to call this function from your handler + * when overriding key event handling. This is needed in the case when + * you need to insert your own key handling between the input method + * and the default key event handling of the #GtkTextView. + * + * |[ + * static gboolean + * gtk_foo_bar_key_press_event (GtkWidget *widget, + * GdkEventKey *event) + * { + * if ((key->keyval == GDK_Return || key->keyval == GDK_KP_Enter)) + * { + * if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW (view), event)) + * return TRUE; + * } + * + * /* Do some stuff */ + * + * return GTK_WIDGET_CLASS (gtk_foo_bar_parent_class)->key_press_event (widget, event); + * } + * ]| + * + * Return value: %TRUE if the input method handled the key event. + * + * Since: 2.22 + */ +gboolean +gtk_text_view_im_context_filter_keypress (GtkTextView *text_view, + GdkEventKey *key) +{ + g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE); + + return gtk_im_context_filter_keypress (text_view->im_context, key); +} + /* * DND feature */ diff --git a/gtk/gtktextview.h b/gtk/gtktextview.h index 5fe62bac9a..dca0c88a78 100644 --- a/gtk/gtktextview.h +++ b/gtk/gtktextview.h @@ -307,6 +307,10 @@ gboolean gtk_text_view_move_visually (GtkTextView *text_v GtkTextIter *iter, gint count); +gboolean gtk_text_view_im_context_filter_keypress (GtkTextView *text_view, + GdkEventKey *key); +void gtk_text_view_reset_im_context (GtkTextView *text_view); + /* Adding child widgets */ void gtk_text_view_add_child_at_anchor (GtkTextView *text_view, GtkWidget *child,