[uim-commit] r743 - in trunk: gtk scm

tkng at freedesktop.org tkng at freedesktop.org
Wed Mar 2 23:26:07 PST 2005


Author: tkng
Date: 2005-03-02 23:26:04 -0800 (Wed, 02 Mar 2005)
New Revision: 743

Added:
   trunk/gtk/caret-state-indicator.c
   trunk/gtk/caret-state-indicator.h
Modified:
   trunk/gtk/Makefile.am
   trunk/gtk/gtk-im-uim.c
   trunk/scm/im-custom.scm
Log:
* gtk/gtk-im-uim.c:
 -(UIMContext): Added new struct member caret_state_indicator.
 -(im_uim_set_cursor_location): Call caret_state_indicator_set_cursor_location.
 -(update_prop_label_cb): Call caret_state_indicator_update.

* gtk/caret-state-indicator.c:
 -(caret_state_indicator_new):New function.
 -(caret_state_indicator_update):New function.
 -(caret_state_indicator_set_cursor_location):New function.

* scm/im-custom.scm:
 -(bridge-show-input-state?): New custom item.



Modified: trunk/gtk/Makefile.am
===================================================================
--- trunk/gtk/Makefile.am	2005-03-02 14:51:44 UTC (rev 742)
+++ trunk/gtk/Makefile.am	2005-03-03 07:26:04 UTC (rev 743)
@@ -16,7 +16,8 @@
 
 IM_UIM_SOURCES = \
 	gtk-im-uim.c \
-	uim-cand-win-gtk.c uim-cand-win-gtk.h
+	uim-cand-win-gtk.c uim-cand-win-gtk.h \
+	caret-state-indicator.c caret-state-indicator.h
 
 if EB
 IM_UIM_SOURCES += uim-eb.c uim-eb.h

Added: trunk/gtk/caret-state-indicator.c
===================================================================
--- trunk/gtk/caret-state-indicator.c	2005-03-02 14:51:44 UTC (rev 742)
+++ trunk/gtk/caret-state-indicator.c	2005-03-03 07:26:04 UTC (rev 743)
@@ -0,0 +1,101 @@
+/*
+
+  Copyright (c) 2005 uim Project http://uim.freedesktop.org/
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of authors nor the names of its contributors
+     may be used to endorse or promote products derived from this software
+     without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  SUCH DAMAGE.
+*/
+
+#include <gtk/gtk.h>
+#include "caret-state-indicator.h"
+
+#include <uim/uim.h>
+#include "uim/config.h"
+#include "uim/uim-helper.h"
+#include "uim/uim-compat-scm.h"
+#include "uim/gettext.h"
+
+/*
+ * caret state indicator is a state indicator nearby the caret.
+ */
+
+static gint
+caret_state_indicator_timeout(gpointer data);
+
+GtkWidget *
+caret_state_indicator_new(void)
+{
+  GtkWidget *window;
+  GtkWidget *label;
+
+  window = gtk_window_new(GTK_WINDOW_POPUP);
+  label  = gtk_label_new("");
+  gtk_container_add(GTK_CONTAINER(window), label);
+
+  gtk_window_set_default_size(GTK_WINDOW(window), 20, 20);
+
+  g_object_set_data(G_OBJECT(window), "label", label);
+  return window;
+}
+
+void
+caret_state_indicator_update(GtkWidget *window, gint topwin_x, gint topwin_y, const gchar *str)
+{
+  GtkWidget *label = g_object_get_data(G_OBJECT(window), "label");
+  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"));
+  uim_bool show_state = uim_scm_symbol_value_bool("bridge-show-input-state?");
+  gchar **labels;
+
+  if(show_state == UIM_FALSE) {
+    return;
+  }
+
+  labels = g_strsplit(str, "\t", 2);
+  gtk_window_move(GTK_WINDOW(window), topwin_x + cursor_x, topwin_y + cursor_y + 3);
+  gtk_label_set_text(GTK_LABEL(label), labels[0]);
+  g_strfreev(labels);
+  gtk_widget_show_all(window);
+  g_timeout_add(2000, caret_state_indicator_timeout, (gpointer)window);
+}
+
+void
+caret_state_indicator_set_cursor_location(GtkWidget *window, GdkRectangle *cursor_location)
+{
+  g_object_set_data(G_OBJECT(window), "cursor_x",
+		    GINT_TO_POINTER(cursor_location->x));
+  g_object_set_data(G_OBJECT(window), "cursor_y",
+		    GINT_TO_POINTER(cursor_location->y+cursor_location->height));
+}
+
+static gint
+caret_state_indicator_timeout(gpointer data)
+{
+  GtkWidget *window = GTK_WIDGET(data);
+  gtk_widget_hide(window);
+  return 0;
+}

Added: trunk/gtk/caret-state-indicator.h
===================================================================
--- trunk/gtk/caret-state-indicator.h	2005-03-02 14:51:44 UTC (rev 742)
+++ trunk/gtk/caret-state-indicator.h	2005-03-03 07:26:04 UTC (rev 743)
@@ -0,0 +1,42 @@
+/*
+
+  Copyright (c) 2005 uim Project http://uim.freedesktop.org/
+
+  All rights reserved.
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in the
+     documentation and/or other materials provided with the distribution.
+  3. Neither the name of authors nor the names of its contributors
+     may be used to endorse or promote products derived from this software
+     without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+  SUCH DAMAGE.
+*/
+
+#include <gtk/gtk.h>
+
+GtkWidget *
+caret_state_indicator_new(void);
+
+void
+caret_state_indicator_update(GtkWidget *window, gint topwin_x, gint topwin_y, const gchar *str);
+
+void
+caret_state_indicator_set_cursor_location(GtkWidget *window, GdkRectangle *cursor_location);

Modified: trunk/gtk/gtk-im-uim.c
===================================================================
--- trunk/gtk/gtk-im-uim.c	2005-03-02 14:51:44 UTC (rev 742)
+++ trunk/gtk/gtk-im-uim.c	2005-03-03 07:26:04 UTC (rev 743)
@@ -52,6 +52,7 @@
 #include "uim/config.h"
 #include "uim/gettext.h"
 #include "uim-cand-win-gtk.h"
+#include "caret-state-indicator.h"
 
 /* exported symbols */
 GtkIMContext *im_module_create(const gchar *context_id);
@@ -85,6 +86,7 @@
   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;
@@ -425,6 +427,7 @@
 
   uic->preedit_pos = *area;
   uim_cand_win_gtk_set_cursor_location(uic->cwin, area);
+  caret_state_indicator_set_cursor_location(uic->caret_state_indicator, area);
 }
 
 
@@ -711,6 +714,7 @@
 {
   IMUIMContext *uic = (IMUIMContext *)ptr;
   GString *tmp;
+  gint x, y;
 
   if (uic != focused_context)
     return;
@@ -720,6 +724,9 @@
 
   uim_helper_send_message(im_uim_fd, tmp->str);
   g_string_free(tmp, TRUE);
+
+  gdk_window_get_origin(uic->win, &x, &y);
+  caret_state_indicator_update(uic->caret_state_indicator, x, y, str);
 }
 
 static void
@@ -896,6 +903,8 @@
 			    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;

Modified: trunk/scm/im-custom.scm
===================================================================
--- trunk/scm/im-custom.scm	2005-03-02 14:51:44 UTC (rev 742)
+++ trunk/scm/im-custom.scm	2005-03-03 07:26:04 UTC (rev 743)
@@ -337,6 +337,11 @@
   (_ "Show uim help button on toolbar")
   (_ "long description will be here."))
 
+(define-custom 'bridge-show-input-state? #f
+  '(global visual-preference)
+  '(boolean)
+  (_ "Show input state nearby the caret")
+  (_ "long description will be here."))
 
 ;; EB Library support
 ;; 2005-02-08 Takuro Ashie <ashie at homa.ne.jp>



More information about the Uim-commit mailing list