[gimp] app: fix IM context reset



commit a8a732f7533ee16b5184add854e0a5c3589869c4
Author: Michael Natterer <mitch gimp org>
Date:   Fri Feb 19 16:05:48 2010 +0100

    app: fix IM context reset
    
    - Reset the IM context in much more situations, like on button_press
      and when the text editor is initialized and halted (pretty much what
      GtkTextView does).
    - As a consequence, halt the rectangle text tool after the text tool
      in control() because cancelling the IM preedit might cause a
      re-framing of the layer because it resized.
    - pause()/resume() the draw tool around gimp_text_tool_halt() so we
      definitely avoid drawing atrifacts when the text tool is shut down
      in the middle of an IM preedit. That pause/resume pair should have
      been there from the beginning actually.

 app/tools/gimptexttool-editor.c |   37 ++++++++++++++++++++++++-------------
 app/tools/gimptexttool-editor.h |    2 ++
 app/tools/gimptexttool.c        |   12 +++++++++---
 3 files changed, 35 insertions(+), 16 deletions(-)
---
diff --git a/app/tools/gimptexttool-editor.c b/app/tools/gimptexttool-editor.c
index 625418b..eb93154 100644
--- a/app/tools/gimptexttool-editor.c
+++ b/app/tools/gimptexttool-editor.c
@@ -71,7 +71,6 @@ static void   gimp_text_tool_options_notify     (GimpTextOptions *options,
 static void   gimp_text_tool_editor_dialog      (GimpTextTool    *text_tool);
 static void   gimp_text_tool_enter_text         (GimpTextTool    *text_tool,
                                                  const gchar     *str);
-static void   gimp_text_tool_reset_im_context   (GimpTextTool    *text_tool);
 static void   gimp_text_tool_commit_cb          (GtkIMContext    *context,
                                                  const gchar     *str,
                                                  GimpTextTool    *text_tool);
@@ -121,6 +120,9 @@ gimp_text_tool_editor_start (GimpTextTool *text_tool)
   gtk_im_context_set_client_window (text_tool->im_context,
                                     gtk_widget_get_window (shell->canvas));
 
+  text_tool->needs_im_reset = TRUE;
+  gimp_text_tool_reset_im_context (text_tool);
+
   gtk_im_context_focus_in (text_tool->im_context);
 
   if (text_tool->text)
@@ -156,6 +158,9 @@ gimp_text_tool_editor_halt (GimpTextTool *text_tool)
       text_tool->proxy_text_view = NULL;
     }
 
+  text_tool->needs_im_reset = TRUE;
+  gimp_text_tool_reset_im_context (text_tool);
+
   gtk_im_context_focus_out (text_tool->im_context);
 
   gtk_im_context_set_client_window (text_tool->im_context, NULL);
@@ -202,15 +207,15 @@ gimp_text_tool_editor_key_press (GimpTextTool *text_tool,
     case GDK_Return:
     case GDK_KP_Enter:
     case GDK_ISO_Enter:
-      gimp_text_tool_enter_text (text_tool, "\n");
       gimp_text_tool_reset_im_context (text_tool);
+      gimp_text_tool_enter_text (text_tool, "\n");
       break;
 
     case GDK_Tab:
     case GDK_KP_Tab:
     case GDK_ISO_Left_Tab:
-      gimp_text_tool_enter_text (text_tool, "\t");
       gimp_text_tool_reset_im_context (text_tool);
+      gimp_text_tool_enter_text (text_tool, "\t");
       break;
 
     case GDK_Escape:
@@ -255,6 +260,16 @@ gimp_text_tool_editor_key_release (GimpTextTool *text_tool,
   return FALSE;
 }
 
+void
+gimp_text_tool_reset_im_context (GimpTextTool *text_tool)
+{
+  if (text_tool->needs_im_reset)
+    {
+      text_tool->needs_im_reset = FALSE;
+      gtk_im_context_reset (text_tool->im_context);
+    }
+}
+
 gchar *
 gimp_text_tool_editor_get_text (GimpTextTool *text_tool)
 {
@@ -550,6 +565,8 @@ gimp_text_tool_move_cursor (GimpTextTool    *text_tool,
 
   gimp_draw_tool_pause (GIMP_DRAW_TOOL (text_tool));
 
+  gimp_text_tool_reset_im_context (text_tool);
+
   gtk_text_buffer_select_range (buffer, &cursor, sel_start);
 
   gimp_draw_tool_resume (GIMP_DRAW_TOOL (text_tool));
@@ -608,6 +625,8 @@ gimp_text_tool_delete_from_cursor (GimpTextTool  *text_tool,
                               type)->value_name,
             count);
 
+  gimp_text_tool_reset_im_context (text_tool);
+
   gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
                                     gtk_text_buffer_get_insert (buffer));
   end = cursor;
@@ -688,6 +707,8 @@ gimp_text_tool_backspace (GimpTextTool *text_tool)
 {
   GtkTextBuffer *buffer = text_tool->text_buffer;
 
+  gimp_text_tool_reset_im_context (text_tool);
+
   if (gtk_text_buffer_get_has_selection (buffer))
     {
       gtk_text_buffer_delete_selection (buffer, TRUE, TRUE);
@@ -827,16 +848,6 @@ gimp_text_tool_enter_text (GimpTextTool *text_tool,
 }
 
 static void
-gimp_text_tool_reset_im_context (GimpTextTool *text_tool)
-{
-  if (text_tool->needs_im_reset)
-    {
-      text_tool->needs_im_reset = FALSE;
-      gtk_im_context_reset (text_tool->im_context);
-    }
-}
-
-static void
 gimp_text_tool_commit_cb (GtkIMContext *context,
                           const gchar  *str,
                           GimpTextTool *text_tool)
diff --git a/app/tools/gimptexttool-editor.h b/app/tools/gimptexttool-editor.h
index 6e243eb..b3d4b03 100644
--- a/app/tools/gimptexttool-editor.h
+++ b/app/tools/gimptexttool-editor.h
@@ -37,6 +37,8 @@ gboolean   gimp_text_tool_editor_key_release (GimpTextTool *text_tool,
                                               GdkEventKey  *kevent,
                                               GimpDisplay  *display);
 
+void       gimp_text_tool_reset_im_context   (GimpTextTool *text_tool);
+
 gchar    * gimp_text_tool_editor_get_text    (GimpTextTool *text_tool);
 
 
diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c
index 9d329c0..1e2edd5 100644
--- a/app/tools/gimptexttool.c
+++ b/app/tools/gimptexttool.c
@@ -345,8 +345,6 @@ gimp_text_tool_control (GimpTool       *tool,
 {
   GimpTextTool *text_tool = GIMP_TEXT_TOOL (tool);
 
-  gimp_rectangle_tool_control (tool, action, display);
-
   switch (action)
     {
     case GIMP_TOOL_ACTION_PAUSE:
@@ -358,6 +356,8 @@ gimp_text_tool_control (GimpTool       *tool,
       break;
     }
 
+  gimp_rectangle_tool_control (tool, action, display);
+
   GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
 }
 
@@ -379,6 +379,8 @@ gimp_text_tool_button_press (GimpTool            *tool,
 
   if (press_type == GIMP_BUTTON_PRESS_NORMAL)
     {
+      gimp_text_tool_reset_im_context (text_tool);
+
       text_tool->selecting = FALSE;
 
       if (gimp_rectangle_tool_point_in_rectangle (rect_tool,
@@ -1217,9 +1219,13 @@ gimp_text_tool_rectangle_change_complete (GimpRectangleTool *rect_tool)
 static void
 gimp_text_tool_halt (GimpTextTool *text_tool)
 {
-  gimp_text_tool_set_drawable (text_tool, NULL, FALSE);
+  gimp_draw_tool_pause (GIMP_DRAW_TOOL (text_tool));
 
   gimp_text_tool_editor_halt (text_tool);
+
+  gimp_text_tool_set_drawable (text_tool, NULL, FALSE);
+
+  gimp_draw_tool_resume (GIMP_DRAW_TOOL (text_tool));
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]