[uim-commit] r2639 - branches/1.0/gtk
ekato at freedesktop.org
ekato at freedesktop.org
Sun Dec 18 14:42:54 PST 2005
Author: ekato
Date: 2005-12-18 14:42:51 -0800 (Sun, 18 Dec 2005)
New Revision: 2639
Modified:
branches/1.0/gtk/caret-state-indicator.c
branches/1.0/gtk/caret-state-indicator.h
branches/1.0/gtk/gtk-im-uim.c
Log:
* gtk/gtk-im-uim.c
* gtk/caret-state-indicator.c
* gtk/caret-state-indicator.h
- Port r2638 from trunk.
Modified: branches/1.0/gtk/caret-state-indicator.c
===================================================================
--- branches/1.0/gtk/caret-state-indicator.c 2005-12-18 22:40:26 UTC (rev 2638)
+++ branches/1.0/gtk/caret-state-indicator.c 2005-12-18 22:42:51 UTC (rev 2639)
@@ -33,7 +33,7 @@
#include <gtk/gtk.h>
#include "caret-state-indicator.h"
-#include <uim/uim.h>
+#include "uim/uim.h"
#include "config.h"
#include "uim/uim-helper.h"
#include "uim/gettext.h"
@@ -45,10 +45,8 @@
#define DEFAULT_WINDOW_WIDTH 20
#define DEFAULT_WINDOW_HEIGHT 20
-static gint
-get_current_time(void);
-static gint
-caret_state_indicator_timeout(gpointer data);
+static gint get_current_time(void);
+static gint caret_state_indicator_timeout(gpointer data);
/* This function is not correct, size of tv_sec is glong, not gint */
static gint
@@ -63,13 +61,19 @@
caret_state_indicator_timeout(gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
- gint timeout = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window), "timeout"));
- gint called_time = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window), "called_time"));
- gint current_time = get_current_time();
- if((current_time - called_time)*1000 >= timeout) {
+ gint timeout, called_time, current_time;
+
+ timeout = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window), "timeout"));
+ called_time = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window),
+ "called_time"));
+ current_time = get_current_time();
+
+ if ((current_time - called_time) * 1000 >= timeout)
gtk_widget_hide(window);
- }
- return 0;
+
+ g_object_set_data(G_OBJECT(window), "timeout-tag", GUINT_TO_POINTER(0));
+
+ return FALSE;
}
static gint
@@ -99,11 +103,11 @@
gtk_window_set_default_size(GTK_WINDOW(window),
DEFAULT_WINDOW_WIDTH,
DEFAULT_WINDOW_HEIGHT);
- gtk_widget_set_app_paintable (window, TRUE);
+ gtk_widget_set_app_paintable (window, TRUE);
- g_signal_connect(window, "expose_event",
- G_CALLBACK (caret_state_indicator_paint_window),
- NULL);
+ g_signal_connect(window, "expose_event",
+ G_CALLBACK (caret_state_indicator_paint_window),
+ NULL);
gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
@@ -119,9 +123,8 @@
gint cursor_x = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window), "cursor_x"));
gint cursor_y = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(window), "cursor_y"));
- if(str) {
+ if (str) {
gchar **labels;
-
labels = g_strsplit(str, "\t", 2);
gtk_label_set_text(GTK_LABEL(label), labels[0]);
@@ -139,14 +142,23 @@
GINT_TO_POINTER(cursor_location->y+cursor_location->height));
}
-
void
caret_state_indicator_set_timeout(GtkWidget *window, gint timeout)
{
- gint current_time = get_current_time();
- guint tag = g_timeout_add(timeout, caret_state_indicator_timeout, (gpointer)window);
- g_object_set_data(G_OBJECT(window), "timeout-tag", GINT_TO_POINTER(tag));
+ gint current_time;
+ guint tag, oldtag;
+
+ oldtag = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(window), "timeout-tag"));
+
+ if (oldtag > 0)
+ g_source_remove(oldtag);
+
+ current_time = get_current_time();
+ tag = g_timeout_add(timeout, caret_state_indicator_timeout, (gpointer)window);
+
+ g_object_set_data(G_OBJECT(window), "timeout-tag", GUINT_TO_POINTER(tag));
g_object_set_data(G_OBJECT(window), "timeout", GINT_TO_POINTER(timeout));
- g_object_set_data(G_OBJECT(window), "called_time", GINT_TO_POINTER(current_time));
- /* "called_time" stores the time of last calling of this function */
+ /* "called_time" stores the latest time when this function is called */
+ g_object_set_data(G_OBJECT(window),
+ "called_time", GINT_TO_POINTER(current_time));
}
Modified: branches/1.0/gtk/caret-state-indicator.h
===================================================================
--- branches/1.0/gtk/caret-state-indicator.h 2005-12-18 22:40:26 UTC (rev 2638)
+++ branches/1.0/gtk/caret-state-indicator.h 2005-12-18 22:42:51 UTC (rev 2639)
@@ -32,8 +32,7 @@
#include <gtk/gtk.h>
-GtkWidget *
-caret_state_indicator_new(void);
+GtkWidget *caret_state_indicator_new(void);
void
caret_state_indicator_update(GtkWidget *window, gint topwin_x, gint topwin_y, const gchar *str);
Modified: branches/1.0/gtk/gtk-im-uim.c
===================================================================
--- branches/1.0/gtk/gtk-im-uim.c 2005-12-18 22:40:26 UTC (rev 2638)
+++ branches/1.0/gtk/gtk-im-uim.c 2005-12-18 22:42:51 UTC (rev 2639)
@@ -61,7 +61,6 @@
void im_module_exit(void);
void im_module_init(GTypeModule *type_module);
-/**/
#define NR_CANDIDATES 20
#define DEFAULT_SEPARATOR_STR "|"
@@ -75,7 +74,6 @@
};
typedef struct _IMUIMContext {
- /**/
struct _GtkIMContext parent;
struct _GtkIMContext *slave;
uim_context uc;
@@ -83,13 +81,13 @@
gboolean cwin_is_active;
int nr_psegs;
struct preedit_segment *pseg;
- /**/
+
GtkWidget *menu;
GdkWindow *win;
GdkWindow *toplevel;
GtkWidget *caret_state_indicator;
GdkRectangle preedit_pos; /* preedit_pos not always point the cursor location */
- /**/
+
struct _IMUIMContext *prev, *next;
} IMUIMContext;
@@ -132,7 +130,7 @@
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) im_uim_class_init,
(GClassFinalizeFunc)im_uim_class_finalize,
- NULL,/*for class data*/
+ NULL, /* for class data */
sizeof(IMUIMContext), /* size of instance */
0,
(GInstanceInitFunc) im_uim_init, /* constructor */
@@ -192,7 +190,7 @@
g_return_if_fail(str);
if (!strcmp(str, "")
- && !(attr & (UPreeditAttr_Cursor | UPreeditAttr_Separator)))
+ && !(attr & (UPreeditAttr_Cursor | UPreeditAttr_Separator)))
return;
uic->pseg = realloc(uic->pseg,
@@ -292,7 +290,7 @@
{
IMUIMContext *uic = IM_UIM_CONTEXT(ic);
- /*** Hack for combination of xchat + GTK+ 2.6 ***/
+ /* Hack for combination of xchat + GTK+ 2.6 */
if (snooper_installed == FALSE) {
int rv;
int kv = convert_keyval(key->keyval);
@@ -308,7 +306,7 @@
}
return TRUE;
}
- /*** Hack for combination of xchat + GTK+ 2.6 ***/
+ /* Hack for combination of xchat + GTK+ 2.6 */
return gtk_im_context_filter_keypress(uic->slave, key);
}
@@ -355,16 +353,14 @@
separator_fg_symbol = "separator-foreground";
separator_bg_symbol = "separator-background";
}
- if (get_user_defined_color(&color, separator_fg_symbol))
- {
+ if (get_user_defined_color(&color, separator_fg_symbol)) {
attr = pango_attr_foreground_new(color.red, color.green, color.blue);
attr->start_index = begin;
attr->end_index = end;
pango_attr_list_change(attrs, attr);
}
- if (get_user_defined_color(&color, separator_bg_symbol))
- {
+ if (get_user_defined_color(&color, separator_bg_symbol)) {
attr = pango_attr_background_new(color.red, color.green, color.blue);
attr->start_index = begin;
attr->end_index = end;
@@ -372,8 +368,7 @@
}
} else if (ps->attr & UPreeditAttr_Reverse) {
if (get_user_defined_color(&color, "reversed-preedit-foreground")
- || pango_color_parse(&color, "#fff"))
- {
+ || pango_color_parse(&color, "#fff")) {
attr = pango_attr_foreground_new(color.red, color.green, color.blue);
attr->start_index = begin;
attr->end_index = end;
@@ -381,8 +376,7 @@
}
if (get_user_defined_color(&color, "reversed-preedit-background")
- || pango_color_parse(&color, "#000"))
- {
+ || pango_color_parse(&color, "#000")) {
attr = pango_attr_background_new(color.red, color.green, color.blue);
attr->start_index = begin;
attr->end_index = end;
@@ -557,7 +551,7 @@
if (strlen(str) > 0) {
- gint x,y,w,h;
+ gint x, y, w, h;
PangoLayout *layout;
gtk_label_set_text(GTK_LABEL(preedit_label), str);
@@ -666,9 +660,9 @@
uic->cwin = NULL;
}
if (uic->caret_state_indicator) {
- guint tag = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(uic->caret_state_indicator), "timeout-tag"));
+ guint tag = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(uic->caret_state_indicator), "timeout-tag"));
if (tag > 0)
- g_source_remove(tag);
+ g_source_remove(tag);
gtk_widget_destroy(uic->caret_state_indicator);
uic->caret_state_indicator = NULL;
}
@@ -747,10 +741,12 @@
show_state = uim_scm_symbol_value_bool("bridge-show-input-state?");
if (show_state == UIM_TRUE && uic->win) {
gint timeout;
+
gdk_window_get_origin(uic->win, &x, &y);
caret_state_indicator_update(uic->caret_state_indicator, x, y, str);
timeout = uim_scm_symbol_value_int("bridge-show-input-state-time-length");
- if(timeout != 0)
+
+ if (timeout != 0)
caret_state_indicator_set_timeout(uic->caret_state_indicator, timeout * 1000);
gtk_widget_show_all(uic->caret_state_indicator);
}
@@ -782,13 +778,14 @@
g_string_append(msg, name);
g_string_append(msg, "\t");
- if (lang) g_string_append(msg, lang);
+ if (lang)
+ g_string_append(msg, lang);
g_string_append(msg, "\t");
- if (short_desc) g_string_append(msg, short_desc);
+ if (short_desc)
+ g_string_append(msg, short_desc);
g_string_append(msg, "\t");
- if (strcmp(name, current_im_name) == 0) {
+ if (strcmp(name, current_im_name) == 0)
g_string_append(msg, "selected");
- }
g_string_append(msg, "\n");
}
uim_helper_send_message(im_uim_fd, msg->str);
@@ -820,23 +817,24 @@
gchar **lines = g_strsplit(str, "\n", 0);
gchar *commit_string;
- if(!lines || !lines[0] || !lines[1] || !lines[2]) {
+ if (!lines || !lines[0] || !lines[1] || !lines[2]) {
return; /* Message is broken, do nothing. */
}
- /* If second line exists, assume first line as character encoding.
- This (rotten) convention is influenced by old design mistake (character
- encoding was forgotten!), we would need novel protocol to fix this issue. */
-
- if(strcmp(lines[2], "") != 0) {
+ /*
+ * If second line exists, assume first line as character encoding.
+ * This (rotten) convention is influenced by old design mistake
+ * (character encoding was forgotten!).
+ */
+ if (strcmp(lines[2], "") != 0) {
gchar *encoding, *commit_string_utf8;
encoding = get_charset(lines[1]);
commit_string = lines[2];
commit_string_utf8 = g_convert(commit_string, strlen(commit_string),
"UTF-8", encoding,
NULL, /* gsize *bytes_read */
- NULL, /*size *bytes_written */
- NULL); /* GError **error*/
+ NULL, /* size *bytes_written */
+ NULL); /* GError **error */
g_signal_emit_by_name(focused_context, "commit", commit_string_utf8);
g_free(encoding);
g_free(commit_string_utf8);
@@ -962,8 +960,6 @@
check_helper_connection();
- /**/
-
uim_set_preedit_cb(uic->uc, clear_cb,
pushback_cb, update_cb);
uim_set_prop_list_update_cb(uic->uc,
@@ -978,16 +974,14 @@
uim_prop_list_update(uic->uc);
-
/* slave exists for using gtk+'s table based input method */
uic->slave = g_object_new(GTK_TYPE_IM_CONTEXT_SIMPLE,
NULL);
g_signal_connect(G_OBJECT(uic->slave), "commit",
G_CALLBACK(im_uim_commit_cb), uic);
-
+
uic->caret_state_indicator = caret_state_indicator_new();
- /**/
uic->next = context_list.next;
uic->prev = (IMUIMContext *)&context_list;
context_list.next->prev = uic;
More information about the uim-commit
mailing list