[uim-commit] r3125 - in trunk: gtk uim xim

ekato at freedesktop.org ekato at freedesktop.org
Sat Feb 18 12:17:55 PST 2006


Author: ekato
Date: 2006-02-18 12:17:51 -0800 (Sat, 18 Feb 2006)
New Revision: 3125

Modified:
   trunk/gtk/caret-state-indicator.c
   trunk/gtk/gtk-im-uim.c
   trunk/uim/uim.c
   trunk/xim/main.cpp
   trunk/xim/ximserver.cpp
   trunk/xim/ximserver.h
Log:
* uim/uim.c (uim_prop_list_update) : Add sanity check.
(uim_prop_label_update) : Ditto.

* xim/ximserver.cpp (InputContext::createUimContext) : Obsolete
  prop_label.
(InputContext::get_caret_state_label_from_prop_list) : New.
(InputContext::update_prop_list) : Simplify with
  get_caret_state_label_from_prop_list().
* xim/main.cpp (xEventRead) : Remove redundant XFlush().
* xim/ximserver.h (class InputContext) : Add
  get_caret_state_label_from_prop_list() private member.

* gtk/gtk-im-uim.c (get_caret_state_label_from_prop_list) : New.
(update_prop_list_cb) : Set caret state indicator with this
  callback.
* gtk/caret-state-indicator.c : Include <string.h> for strcmp(3).
(caret_state_indicator_paint_window) : Bug fix.
(caret_state_indicator_new) : Use hbox as a container of state
  labels.
(caret_state_indicator_update) : Add each label into the hbox
  separately.


Modified: trunk/gtk/caret-state-indicator.c
===================================================================
--- trunk/gtk/caret-state-indicator.c	2006-02-18 17:10:51 UTC (rev 3124)
+++ trunk/gtk/caret-state-indicator.c	2006-02-18 20:17:51 UTC (rev 3125)
@@ -31,6 +31,7 @@
 */
 
 #include <gtk/gtk.h>
+#include <string.h>
 #include "caret-state-indicator.h"
 
 #include "config.h"
@@ -80,12 +81,9 @@
 static gint
 caret_state_indicator_paint_window(GtkWidget *window)
 {
-  GtkRequisition req;
-
-  gtk_widget_size_request(window, &req);
   gtk_paint_flat_box(window->style, window->window, GTK_STATE_NORMAL,
 		     GTK_SHADOW_OUT, NULL, GTK_WIDGET(window), "tooltip",
-		     0, 0, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT);
+		     0, 0, -1, -1);
 
   return FALSE;
 }
@@ -93,12 +91,14 @@
 GtkWidget *
 caret_state_indicator_new(void)
 {
-  GtkWidget *window;
-  GtkWidget *label;
+  GtkWidget *window, *label, *hbox;
+  GList *label_list = NULL;
 
   window = gtk_window_new(GTK_WINDOW_POPUP);
   label  = gtk_label_new("");
-  gtk_container_add(GTK_CONTAINER(window), label);
+  hbox = gtk_hbox_new(TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+  gtk_container_add(GTK_CONTAINER(window), hbox);
 
   gtk_window_set_default_size(GTK_WINDOW(window),
 			      DEFAULT_WINDOW_WIDTH,
@@ -106,12 +106,14 @@
   gtk_widget_set_app_paintable(window, TRUE);
 
   g_signal_connect(window, "expose_event",
-		   G_CALLBACK (caret_state_indicator_paint_window), 
+		   G_CALLBACK(caret_state_indicator_paint_window), 
 		   NULL);
 
   gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
 
-  g_object_set_data(G_OBJECT(window), "label", label);
+  label_list = g_list_append(label_list, label);
+  g_object_set_data(G_OBJECT(window), "labels", label_list);
+  g_object_set_data(G_OBJECT(window), "hbox", hbox);
 
   return window;
 }
@@ -119,22 +121,48 @@
 void
 caret_state_indicator_update(GtkWidget *window, gint topwin_x, gint topwin_y, const gchar *str)
 {
-  GtkWidget *label;
   gint cursor_x, cursor_y;
 
   g_return_if_fail(window != NULL);
 
-  label = g_object_get_data(G_OBJECT(window), "label");
   cursor_x = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window), "cursor_x"));
   cursor_y = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window), "cursor_y"));
 
   if (str) {
-    gchar **labels;
+    gchar **cols;
+    GtkWidget *label, *hbox;
+    GList *label_list, *list;
+    gint i;
 
-    labels = g_strsplit(str, "\t", 2);
-    gtk_label_set_text(GTK_LABEL(label), labels[0]);
-    g_strfreev(labels);
+    list = label_list = g_object_get_data(G_OBJECT(window), "labels");
+    hbox = g_object_get_data(G_OBJECT(window), "hbox");
+
+    cols = g_strsplit(str, "\t", 0);
+    for (i = 0; cols[i] && strcmp("", cols[i]); i++) {
+      if (label_list) {
+        label = label_list->data;
+        gtk_label_set_text(GTK_LABEL(label), cols[i]);
+      } else {
+        label = gtk_label_new(cols[i]);
+	gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
+	list = g_list_append(list, label);
+        g_object_set_data(G_OBJECT(window), "labels", list);
+	label_list = g_list_find(list, label);
+      }
+      label_list = label_list->next;
+    }
+
+    while (label_list) {
+      label = label_list->data;
+      label_list = label_list->next;
+      gtk_container_remove(GTK_CONTAINER(hbox), label);
+      g_list_remove(list, label);
+      g_object_set_data(G_OBJECT(window), "labels", list);
+    }
+
+    g_strfreev(cols);
   }
+
   gtk_window_move(GTK_WINDOW(window), topwin_x + cursor_x,
 		  topwin_y + cursor_y + 3);
 }

Modified: trunk/gtk/gtk-im-uim.c
===================================================================
--- trunk/gtk/gtk-im-uim.c	2006-02-18 17:10:51 UTC (rev 3124)
+++ trunk/gtk/gtk-im-uim.c	2006-02-18 20:17:51 UTC (rev 3125)
@@ -536,8 +536,37 @@
 }
 #endif
 
+static GString *
+get_caret_state_label_from_prop_list(const char *str)
+{
+  gchar **lines;
+  GString *label;
+  int i;
 
+  label = g_string_new("");
+  lines = g_strsplit(str, "\n", 0);
+  for (i = 0; lines[i] && strcmp("", lines[i]); i++) {
+    gchar **cols;
 
+    cols = g_strsplit(lines[i], "\t", 0);
+    if (cols && cols[0]) {
+      if (!strcmp("branch", cols[0])) {
+	gchar *iconic_label = cols[2];
+
+	if (strcmp(label->str, ""))
+	  g_string_append(label, "\t");
+	g_string_append(label, iconic_label);
+      }
+    }
+    g_strfreev(cols);
+  }
+  g_strfreev(lines);
+
+  return label;
+}
+
+
+
 /* callback functions for libuim */
 
 static void
@@ -597,6 +626,7 @@
 {
   IMUIMContext *uic = (IMUIMContext *)ptr;
   GString *prop_list;
+  uim_bool show_state;
 
   if (uic != focused_context || disable_focused_context)
     return;
@@ -606,6 +636,24 @@
 
   uim_helper_send_message(im_uim_fd, prop_list->str);
   g_string_free(prop_list, TRUE);
+
+  show_state = uim_scm_symbol_value_bool("bridge-show-input-state?");
+  if (show_state && uic->win) {
+    gint timeout;
+    gint x, y;
+    GString *label;
+
+    gdk_window_get_origin(uic->win, &x, &y);
+    label = get_caret_state_label_from_prop_list(str);
+    caret_state_indicator_update(uic->caret_state_indicator, x, y, label->str);
+    g_string_free(label, TRUE);
+    timeout = uim_scm_symbol_value_int("bridge-show-input-state-time-length");
+
+    if (timeout != 0)
+      caret_state_indicator_set_timeout(uic->caret_state_indicator,
+					timeout * 1000);
+    gtk_widget_show_all(uic->caret_state_indicator);
+  }
 }
 
 #if 0

Modified: trunk/uim/uim.c
===================================================================
--- trunk/uim/uim.c	2006-02-18 17:10:51 UTC (rev 3124)
+++ trunk/uim/uim.c	2006-02-18 20:17:51 UTC (rev 3125)
@@ -390,14 +390,14 @@
 void
 uim_prop_list_update(uim_context uc)
 {
-  if (uc && uc->propstr)
+  if (uc && uc->propstr && uc->prop_list_update_cb)
     uc->prop_list_update_cb(uc->ptr, uc->propstr);
 }
 
 void
 uim_prop_label_update(uim_context uc)
 {
-  if (uc && uc->proplabelstr)
+  if (uc && uc->proplabelstr && uc->prop_label_update_cb)
     uc->prop_label_update_cb(uc->ptr, uc->proplabelstr);
 }
 

Modified: trunk/xim/main.cpp
===================================================================
--- trunk/xim/main.cpp	2006-02-18 17:10:51 UTC (rev 3124)
+++ trunk/xim/main.cpp	2006-02-18 20:17:51 UTC (rev 3125)
@@ -339,7 +339,6 @@
 static void
 xEventRead(int /* fd */, int /* ev */)
 {
-    XFlush(XimServer::gDpy);
     check_pending_xevent();
 }
 

Modified: trunk/xim/ximserver.cpp
===================================================================
--- trunk/xim/ximserver.cpp	2006-02-18 17:10:51 UTC (rev 3124)
+++ trunk/xim/ximserver.cpp	2006-02-18 20:17:51 UTC (rev 3125)
@@ -407,8 +407,10 @@
 			InputContext::candidate_deactivate_cb);
 	uim_set_prop_list_update_cb(uc,
 			InputContext::update_prop_list_cb);
+#if 0
 	uim_set_prop_label_update_cb(uc,
 			InputContext::update_prop_label_cb);
+#endif
 	uim_set_configuration_changed_cb(uc,
 			InputContext::configuration_changed_cb);
 
@@ -840,6 +842,43 @@
     }
 }
 
+char *InputContext::get_caret_state_label_from_prop_list(const char *str)
+{
+    const char *p, *q;
+    char *state_label = NULL;
+    char label[10];
+    int len, state_label_len = 0;
+
+    p = str;
+    while ((p = strstr(p, "branch\t"))) {
+	p = strchr(p + 7, '\t');
+	if (p) {
+	    p++;
+	    q = strchr(p, '\t');
+	    len = q - p;
+	    if (q && len < 10) {
+		strncpy(label, p, len);
+		label[len] = '\0';
+		if (!state_label) {
+		    state_label_len = len;
+		    state_label = strdup(label);
+		} else {
+		    state_label_len += (len + 1);
+		    state_label = (char *)realloc(state_label,
+						      state_label_len + 1);
+		    if (state_label) {
+			strcat(state_label, "\t");
+			strcat(state_label, label);
+			state_label[state_label_len] = '\0';
+		    }
+		}
+	    }
+	}
+    }
+
+    return state_label;
+}
+
 void InputContext::update_prop_list(const char *str)
 {
     char *buf;
@@ -857,22 +896,16 @@
     uim_bool show_caret_state =
 	uim_scm_symbol_value_bool("bridge-show-input-state?");
     if (show_caret_state == UIM_TRUE) {
-	char *p, *q;
-	char label[10];
-	int len, timeout;
+	char *label;
+	int timeout;
 	Canddisp *disp = canddisp_singleton();
 
-	timeout = uim_scm_symbol_value_int("bridge-show-input-state-time-length");
-	if ((p = strstr(str, "branch\t"))) {
-	    q = strchr(p + 7, '\t');
-	    len = q - (p + 7);
-	    if (q && len < 10) {
-		strncpy(label, p + 7, len);
-		label[len] = '\0';
-		disp->show_caret_state(label, timeout);
-		mCaretStateShown = true;
-	    }
-	}
+	timeout =
+	    uim_scm_symbol_value_int("bridge-show-input-state-time-length");
+	label = get_caret_state_label_from_prop_list(str);
+	disp->show_caret_state(label, timeout);
+	free(label);
+	mCaretStateShown = true;
     }
 #endif
 }

Modified: trunk/xim/ximserver.h
===================================================================
--- trunk/xim/ximserver.h	2006-02-18 17:10:51 UTC (rev 3124)
+++ trunk/xim/ximserver.h	2006-02-18 20:17:51 UTC (rev 3125)
@@ -197,6 +197,7 @@
     void commit_string(char *);
     void clear_pe_stat();
     void review_im(const char *engine);
+    char *get_caret_state_label_from_prop_list(const char *str);
 
     XimIC *mXic;
     XimServer *mServer;



More information about the uim-commit mailing list