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
This commit is contained in:
Javier Jardón 2010-05-05 01:16:55 +02:00
parent 501098e946
commit fc35cd9bfe
6 changed files with 124 additions and 2 deletions

View File

@ -1315,6 +1315,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
@ -4120,6 +4122,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
<SUBSECTION Standard>
GTK_TEXT_VIEW

View File

@ -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
@ -4273,12 +4275,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

View File

@ -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)

View File

@ -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
*/

View File

@ -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;
* }
*
* /&ast; Do some stuff &ast;/
*
* 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
*/

View File

@ -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,