[uim-commit] r2675 - trunk/gtk

ekato at freedesktop.org ekato at freedesktop.org
Tue Dec 20 14:15:08 PST 2005


Author: ekato
Date: 2005-12-20 14:15:01 -0800 (Tue, 20 Dec 2005)
New Revision: 2675

Modified:
   trunk/gtk/gtk-im-uim.c
Log:
* gtk/gtk-im-uim.c (_IMUIMContext) : Add new member preedit_window
  and preedit_handler_id.
(set_use_preedit) : Enable to switch the mode even within a
  context.
(show_preedit) : Indentation fix.
(im_uim_init) : Initialize preedit_window and preedit_handler_id.
(im_uim_finalize) : Finalize preedit_window and
  preedit_handler_id.


Modified: trunk/gtk/gtk-im-uim.c
===================================================================
--- trunk/gtk/gtk-im-uim.c	2005-12-20 22:08:46 UTC (rev 2674)
+++ trunk/gtk/gtk-im-uim.c	2005-12-20 22:15:01 UTC (rev 2675)
@@ -89,6 +89,10 @@
   GtkWidget *caret_state_indicator;
   GdkRectangle preedit_pos;
 
+  /* following two members are used when use_preedit == FALSE */
+  GtkWidget *preedit_window;
+  gulong preedit_handler_id;
+
   struct _IMUIMContext *prev, *next;
 } IMUIMContext;
 
@@ -540,17 +544,28 @@
 static void
 set_use_preedit(GtkIMContext *ic, gboolean use_preedit)
 {
-  GtkWidget *preedit_window;
-  GtkWidget *preedit_label;
+  IMUIMContext *uic = IM_UIM_CONTEXT(ic);
+  GtkWidget *preedit_label = NULL;
 
   if (use_preedit == FALSE) {
-    preedit_window = gtk_window_new(GTK_WINDOW_POPUP);
-    preedit_label = gtk_label_new("");
-    gtk_container_add(GTK_CONTAINER(preedit_window), preedit_label);
-
-    g_signal_connect(G_OBJECT(ic), "preedit-changed",
-		     G_CALLBACK(show_preedit), preedit_label);
-    gtk_widget_show_all(preedit_window);
+    if (!uic->preedit_window) {
+      uic->preedit_window = gtk_window_new(GTK_WINDOW_POPUP);
+      preedit_label = gtk_label_new("");
+      gtk_container_add(GTK_CONTAINER(uic->preedit_window), preedit_label);
+    }
+    uic->preedit_handler_id =
+      g_signal_connect(G_OBJECT(ic), "preedit-changed",
+		       G_CALLBACK(show_preedit), preedit_label);
+    gtk_widget_show_all(uic->preedit_window);
+  } else {
+    if (uic->preedit_handler_id) {
+      g_signal_handler_disconnect(G_OBJECT(ic), uic->preedit_handler_id);
+      uic->preedit_handler_id = 0;
+    }
+    if (uic->preedit_window) {
+      gtk_widget_destroy(uic->preedit_window);
+      uic->preedit_window = NULL;
+    }
   }
 }
 
@@ -568,30 +583,30 @@
   gtk_im_context_get_preedit_string(ic, &str, &attrs, &cursor_pos);
 
   if (strlen(str) > 0) {
-      gint x, y, w, h;
-      PangoLayout *layout;
+    gint x, y, w, h;
+    PangoLayout *layout;
 
-      gtk_label_set_text(GTK_LABEL(preedit_label), str);
-      gtk_label_set_attributes(GTK_LABEL(preedit_label), attrs);
+    gtk_label_set_text(GTK_LABEL(preedit_label), str);
+    gtk_label_set_attributes(GTK_LABEL(preedit_label), attrs);
 
-      gdk_window_get_origin(uic->win, &x, &y);
+    gdk_window_get_origin(uic->win, &x, &y);
 
-      gtk_window_move(GTK_WINDOW(preedit_window),
-		      x + uic->preedit_pos.x,
-		      y + uic->preedit_pos.y);
+    gtk_window_move(GTK_WINDOW(preedit_window),
+		    x + uic->preedit_pos.x,
+		    y + uic->preedit_pos.y);
 
-      layout = gtk_label_get_layout(GTK_LABEL(preedit_label));
+    layout = gtk_label_get_layout(GTK_LABEL(preedit_label));
 
-      pango_layout_get_cursor_pos(layout, 0, NULL, NULL);
+    pango_layout_get_cursor_pos(layout, 0, NULL, NULL);
 
-      pango_layout_get_pixel_size(layout, &w, &h);
-      gtk_window_resize(GTK_WINDOW(preedit_window), w, h);
+    pango_layout_get_pixel_size(layout, &w, &h);
+    gtk_window_resize(GTK_WINDOW(preedit_window), w, h);
 
-      gtk_widget_show(preedit_window);
+    gtk_widget_show(preedit_window);
   } else {
-      gtk_label_set_text(GTK_LABEL(preedit_label), "");
-      gtk_widget_hide(preedit_window);
-      gtk_window_resize(GTK_WINDOW(preedit_window), 0, 0);
+    gtk_label_set_text(GTK_LABEL(preedit_label), "");
+    gtk_widget_hide(preedit_window);
+    gtk_window_resize(GTK_WINDOW(preedit_window), 0, 0);
   }
   g_free(str);
   pango_attr_list_unref(attrs);
@@ -652,6 +667,8 @@
 
   uic->cwin = uim_cand_win_gtk_new();
   uic->cwin_is_active = FALSE;
+  uic->preedit_window = NULL;
+  uic->preedit_handler_id = 0;
   g_signal_connect(G_OBJECT(uic->cwin), "index-changed",
 		   G_CALLBACK(index_changed_cb), uic);
 }
@@ -684,6 +701,15 @@
     uic->caret_state_indicator = NULL;
   }
 
+  if (uic->preedit_handler_id) {
+    g_signal_handler_disconnect(obj, uic->preedit_handler_id);
+    uic->preedit_handler_id = 0;
+  }
+  if (uic->preedit_window) {
+    gtk_widget_destroy(uic->preedit_window);
+    uic->preedit_window = NULL;
+  }
+
   uim_release_context(uic->uc);
 
   g_signal_handlers_disconnect_by_func(uic->slave, (gpointer)im_uim_commit_cb,



More information about the uim-commit mailing list