Revision: 6331
Author: ek.kato
Date: Tue Apr 20 12:14:41 2010
Log: - Support annotation with uim-xim. This should be revised
after the discussion of uim-en. Sub-window with qt is not
ported yet.
* doc/HELPER-CANDWIN : Update specification of activate and
set_page_candidates.
* xim/ximserver.cpp
- (InputContext::candidate_activate) : Follow the change.
- (InputContext::prepare_page_candidates) : Ditto.
* qt/candwin-qt.cpp
- (CandidateWindow::activateCand) : Ditto.
- (CandidateWindow::setPageCandidates) : Ditto.
* helper/candwin-gtk.c
- Ditto.
- Port sub-window from uim-gtk.
* Helper/Makefile.am : Support eb.
http://code.google.com/p/uim/source/detail?r=6331
Modified:
/trunk/doc/HELPER-CANDWIN
/trunk/helper/Makefile.am
/trunk/helper/candwin-gtk.c
/trunk/qt/candwin-qt.cpp
/trunk/qt4/candwin/qt4.cpp
/trunk/xim/ximserver.cpp
=======================================
--- /trunk/doc/HELPER-CANDWIN Tue Oct 7 04:37:15 2008
+++ /trunk/doc/HELPER-CANDWIN Tue Apr 20 12:14:41 2010
@@ -30,7 +30,7 @@
charset_specifier = "charset=" charset "\n"
charset = "UTF-8" | "EUC-JP" | "GB18030" |
<or any name that can be specified as iconv_open(3) argument>
- str = str <any characters except for '\0', '\t', or '\n'> | ""
+ str = str <any characters except for '\0', '\a', or '\n'> | ""
num = /[0-9]+/
1. activate
@@ -43,9 +43,10 @@
display_limit_str = display_limit_label num
display_limit_label = "display_limit="
candidate_strs = candidate_str candidate_str candidate_str ....
- candidate_str = cand_head "\t" cand_candidate "\n"
+ candidate_str = cand_head "\a" cand_candidate "\a" cand_annotation "\n"
cand_head = str
cand_candidate = str
+ cand_annotation = str
2. select
Selecting the specified candidate in helper-candwin window.
@@ -93,9 +94,10 @@
page_str = page_label num
page_label = "page="
candidate_strs = candidate_str candidate_str candidate_str ....
- candidate_str = cand_head "\t" cand_candidate "\n"
+ candidate_str = cand_head "\a" cand_candidate "\a" cand_annotation "\n"
cand_head = str
cand_candidate = str
+ cand_annotation = str
9. show_page
Selecting the specified page of the candidate window.
=======================================
--- /trunk/helper/Makefile.am Mon Apr 12 20:32:57 2010
+++ /trunk/helper/Makefile.am Tue Apr 20 12:14:41 2010
@@ -62,6 +62,16 @@
$(top_builddir)/uim/libuim.la
uim_candwin_gtk_CPPFLAGS = -I$(top_srcdir)
uim_candwin_gtk_CFLAGS = @GTK2_CFLAGS@
+if EB
+uim_candwin_gtk_CPPFLAGS += @EBCONF_EBINCS@ @EBCONF_ZLIBINCS@ \
+ @EBCONF_PTHREAD_CPPFLAGS@ \
+ @EBCONF_INTLINCS@
+uim_candwin_gtk_CFLAGS += @EBCONF_PTHREAD_CFLAGS@
+uim_candwin_gtk_LDFLAGS = @EBCONF_PTHREAD_LDFLAGS@
+uim_candwin_gtk_LDADD += ../uim/lib-eb-static.la \
+ @EBCONF_EBLIBS@ @EBCONF_ZLIBLIBS@ \
+ @EBCONF_INTLLIBS@
+endif
uim_toolbar_gtk_SOURCES = toolbar-standalone-gtk.c toolbar-common-gtk.c
uim_toolbar_gtk_LDADD = @GTK2_LIBS@ $(top_builddir)/uim/libuim-scm.la \
=======================================
--- /trunk/helper/candwin-gtk.c Sun Apr 4 20:35:54 2010
+++ /trunk/helper/candwin-gtk.c Tue Apr 20 12:14:41 2010
@@ -36,6 +36,12 @@
#endif
#include <uim/uim.h>
#include <uim/uim-helper.h>
+#if HAVE_EBLIB
+#include <uim/uim-scm.h>
+#include "uim/uim-eb.h"
+#define UIM_ANNOTATION_WIN_WIDTH 200
+#define UIM_ANNOTATION_WIN_HEIGHT 230
+#endif /* HAVE_EBLIB */
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <glib.h>
@@ -78,6 +84,14 @@
gboolean is_active;
gboolean need_hilite;
+
+ /* sub window */
+ struct sub_window {
+ GtkWidget *window;
+ GtkWidget *scrolled_window;
+ GtkWidget *text_view;
+ gboolean active;
+ } sub_window;
};
struct _UIMCandidateWindowClass {
@@ -97,6 +111,8 @@
static void uim_cand_win_gtk_set_index(UIMCandidateWindow *cwin, gint
index);
static void uim_cand_win_gtk_set_page(UIMCandidateWindow *cwin, gint page);
static void uim_cand_win_gtk_set_page_candidates(UIMCandidateWindow *cwin,
guint page, GSList *candidates);
+static void uim_cand_win_gtk_create_sub_window(UIMCandidateWindow *cwin);
+static void uim_cand_win_gtk_layout_sub_window(UIMCandidateWindow *cwin);
static void uim_cand_win_gtk_layout(void);
@@ -111,16 +127,20 @@
enum {
TERMINATOR = -1,
COLUMN_HEADING,
- COLUMN_CANDIDATE
+ COLUMN_CANDIDATE,
+ COLUMN_ANNOTATION,
+ NR_COLUMNS
};
static void candidate_window_init(UIMCandidateWindow *cwin);
static void candidate_window_class_init(UIMCandidateWindowClass *klass);
+static gboolean tree_selection_change(GtkTreeSelection *selection,
+ GtkTreeModel *model,
+ GtkTreePath *path,
+ gboolean path_currently_selected,
+ gpointer data);
static gboolean tree_selection_changed(GtkTreeSelection *selection,
- GtkTreeModel *model,
- GtkTreePath *path,
- gboolean path_currently_selected,
gpointer data);
#if 0
@@ -210,11 +230,11 @@
/* copied from uim-cand-win-gtk.c */
static gboolean
-tree_selection_changed(GtkTreeSelection *selection,
- GtkTreeModel *model,
- GtkTreePath *path,
- gboolean path_currently_selected,
- gpointer data)
+tree_selection_change(GtkTreeSelection *selection,
+ GtkTreeModel *model,
+ GtkTreePath *path,
+ gboolean path_currently_selected,
+ gpointer data)
{
/* candidate_window *cwin = data; */
gint *indicies;
@@ -246,6 +266,72 @@
return TRUE;
}
}
+
+/* copied from uim-cand-win-gtk.c */
+static gboolean
+tree_selection_changed(GtkTreeSelection *selection,
+ gpointer data)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ /* UIMCandidateWindow *cwin = UIM_CANDIDATE_WINDOW(data); */
+
+ if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
+ char *annotation = NULL;
+#if HAVE_EBLIB
+ /* FIXME! This is a ad-hoc solution to advance
+ annotation related discussion. */
+ if (uim_scm_symbol_value_bool("eb-enable-for-annotation?")) {
+ gchar *cand = NULL;
+
+ gtk_tree_model_get(model, &iter,
+ COLUMN_CANDIDATE, &cand,
+ -1);
+ if (cand && *cand) {
+ char *book;
+ uim_eb *ueb = NULL;
+ book = uim_scm_symbol_value_str("eb-dic-path");
+ if (book && *book)
+ ueb = uim_eb_new(book);
+ if (ueb) {
+ annotation = uim_eb_search_text(ueb, cand);
+ uim_eb_destroy(ueb);
+ }
+ free(book);
+ }
+ g_free(cand);
+ }
+#else
+ gtk_tree_model_get(model, &iter,
+ COLUMN_ANNOTATION, &annotation,
+ -1);
+#endif /* HAVE_EB_LIB */
+
+ if (annotation && *annotation) {
+ if (!cwin->sub_window.window)
+ uim_cand_win_gtk_create_sub_window(cwin);
+ gtk_text_buffer_set_text(
+
gtk_text_view_get_buffer(GTK_TEXT_VIEW(cwin->sub_window.text_view)),
+ annotation, -1);
+ uim_cand_win_gtk_layout_sub_window(cwin);
+ gtk_widget_show(cwin->sub_window.window);
+ cwin->sub_window.active = TRUE;
+ } else {
+ if (cwin->sub_window.window) {
+ gtk_widget_hide(cwin->sub_window.window);
+ cwin->sub_window.active = FALSE;
+ }
+ }
+ free(annotation);
+ } else {
+ if (cwin->sub_window.window) {
+ gtk_widget_hide(cwin->sub_window.window);
+ cwin->sub_window.active = FALSE;
+ }
+ }
+
+ return TRUE;
+}
#if 0
/* copied from uim-cand-win-gtk.c */
@@ -347,9 +433,11 @@
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cwin->view));
gtk_tree_selection_set_select_function(selection,
- tree_selection_changed,
+ tree_selection_change,
cwin,
NULL);
+ g_signal_connect(G_OBJECT(selection), "changed",
+ G_CALLBACK(tree_selection_changed), cwin);
renderer = gtk_cell_renderer_text_new();
g_object_set(renderer, "scale", 0.8, NULL);
@@ -392,6 +480,11 @@
cursor_location.y = 0;
cursor_location.height = 0;
caret_state_indicator_set_cursor_location(cwin->caret_state_indicator,
&cursor_location);
+
+ cwin->sub_window.window = NULL;
+ cwin->sub_window.scrolled_window = NULL;
+ cwin->sub_window.text_view = NULL;
+ cwin->sub_window.active = FALSE;
}
static void
@@ -462,7 +555,7 @@
/* create GtkListStores, and set candidates */
for (i = 0; i < nr_stores; i++) {
- GtkListStore *store = gtk_list_store_new(2, G_TYPE_STRING,
G_TYPE_STRING);
+ GtkListStore *store = gtk_list_store_new(NR_COLUMNS, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING);
GSList *node;
g_ptr_array_add(cwin->stores, store);
@@ -475,11 +568,12 @@
GtkTreeIter ti;
if (node) {
gchar *str = node->data;
- gchar **column = g_strsplit(str, "\t", 2);
+ gchar **column = g_strsplit(str, "\a", 3);
gtk_list_store_append(store, &ti);
gtk_list_store_set(store, &ti,
COLUMN_HEADING, column[0],
COLUMN_CANDIDATE, column[1],
+ COLUMN_ANNOTATION, column[2],
TERMINATOR);
g_strfreev(column);
g_free(str);
@@ -520,8 +614,11 @@
static void
candwin_show(void)
{
- if (cwin->is_active)
+ if (cwin->is_active) {
gtk_widget_show_all(GTK_WIDGET(cwin));
+ if (cwin->sub_window.active)
+ gtk_widget_show(cwin->sub_window.window);
+ }
}
static void
@@ -529,6 +626,8 @@
{
gtk_widget_hide(GTK_WIDGET(cwin));
cwin->is_active = FALSE;
+ if (cwin->sub_window.window)
+ gtk_widget_hide(cwin->sub_window.window);
}
static void
@@ -666,6 +765,8 @@
candwin_show();
} else if (strcmp("hide", command) == 0) {
gtk_widget_hide_all(GTK_WIDGET(cwin));
+ if (cwin->sub_window.window)
+ gtk_widget_hide(cwin->sub_window.window);
} else if (strcmp("move", command) == 0) {
candwin_move(tmp);
} else if (strcmp("deactivate", command) == 0) {
@@ -727,8 +828,13 @@
{
GIOChannel *channel;
+ /* disable uim context in annotation window */
+ setenv("GTK_IM_MODULE", "gtk-im-context-simple", 1);
+
gtk_set_locale();
gtk_init(&argc, &argv);
+ if (uim_init() < 0)
+ return 0;
init_candidate_win();
@@ -738,6 +844,8 @@
g_io_channel_unref(channel);
gtk_main();
+ uim_quit();
+
return 0;
}
@@ -851,10 +959,11 @@
if (candidates == NULL)
return;
+ cwin->sub_window.active = FALSE;
len = g_slist_length(candidates);
/* create GtkListStores, and set candidates */
- store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
+ store = gtk_list_store_new(NR_COLUMNS, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING);
cwin->stores->pdata[page] = store;
/* set candidates */
@@ -866,11 +975,12 @@
if (node) {
gchar *str = node->data;
- gchar **column = g_strsplit(str, "\t", 2);
+ gchar **column = g_strsplit(str, "\a", 3);
gtk_list_store_append(store, &ti);
gtk_list_store_set(store, &ti,
COLUMN_HEADING, column[0],
COLUMN_CANDIDATE, column[1],
+ COLUMN_ANNOTATION, column[2],
TERMINATOR);
g_strfreev(column);
@@ -900,6 +1010,60 @@
y = cwin->pos_y;
gtk_window_move(GTK_WINDOW(cwin), x, y);
+
+ uim_cand_win_gtk_layout_sub_window(cwin);
+}
+
+/* copied from uim-cand-win-gtk.c */
+static void
+uim_cand_win_gtk_create_sub_window(UIMCandidateWindow *cwin)
+{
+ GtkWidget *window, *scrwin, *text_view;
+
+ if (cwin->sub_window.window)
+ return;
+
+ cwin->sub_window.window = window = gtk_window_new(GTK_WINDOW_POPUP);
+ gtk_window_set_default_size(GTK_WINDOW(window),
UIM_ANNOTATION_WIN_WIDTH, UIM_ANNOTATION_WIN_HEIGHT);
+
+ cwin->sub_window.scrolled_window = scrwin =
gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrwin),
+ GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+
+ cwin->sub_window.text_view = text_view = gtk_text_view_new();
+ gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view), FALSE);
+ gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_view), GTK_WRAP_WORD);
+ gtk_widget_show(text_view);
+
+ gtk_container_add(GTK_CONTAINER(scrwin), text_view);
+ gtk_container_add(GTK_CONTAINER(window), scrwin);
+ gtk_widget_show(scrwin);
+ gtk_widget_show(text_view);
+}
+
+/* copied from uim-cand-win-gtk.c */
+static void
+uim_cand_win_gtk_layout_sub_window(UIMCandidateWindow *cwin)
+{
+ gint x, y, w, h, d, sw, sh, x2, y2, w2, h2, d2;
+
+ if (!cwin->sub_window.window)
+ return;
+
+ gdk_window_get_geometry(GTK_WIDGET(cwin)->window,
+ &x, &y, &w, &h, &d);
+ gdk_window_get_origin(GTK_WIDGET(cwin)->window, &x, &y);
+
+ sw = gdk_screen_get_width (gdk_screen_get_default ());
+ sh = gdk_screen_get_height (gdk_screen_get_default ());
+ gdk_window_get_geometry(cwin->sub_window.window->window,
+ &x2, &y2, &w2, &h2, &d2);
+ if (x + w + w2 > sw)
+ x = x - w2;
+ else
+ x = x + w;
+
+ gtk_window_move(GTK_WINDOW(cwin->sub_window.window), x, y);
}
static gboolean
=======================================
--- /trunk/qt/candwin-qt.cpp Sun Apr 4 20:35:54 2010
+++ /trunk/qt/candwin-qt.cpp Tue Apr 20 12:14:41 2010
@@ -115,7 +115,7 @@
qDebug( "uim-candwin-qt: activateCand()" );
#endif
/**
- * format:
activate\ncharset=$charset\ndisplay_limit=$value\nhead1\tcand1\nhead2\tcand2\nhead3\tcand3\n
+ * format:
activate\ncharset=$charset\ndisplay_limit=$value\nhead1\acand1\aannot1\nhead2\acand2\aannot2\nhead3\acand3\aannot3\n
*/
// remove old data
@@ -144,7 +144,7 @@
break;
// split heading_label and cand_str
- QStringList l = QStringList::split( "\t", list [ i ], true );
+ QStringList l = QStringList::split( "\a", list [ i ], true );
// store data
CandData d;
@@ -156,17 +156,17 @@
d.label = headString;
- // XXX Current prime (0.4.6) may return candidate string
- // containing "\t", and we can't handle annotation in another
- // window yet.
l.pop_front();
- QString candString = l.join( "\t" );
+ QString candString = l [ 0 ];
if ( codec )
d.str = codec->toUnicode( candString );
else
d.str = candString;
+ l.pop_front();
+ QString annotString = l [ 0 ];
+
stores.append( d );
}
@@ -279,7 +279,7 @@
qDebug( "uim-candwin-qt: setPageCandidates()" );
#endif
/**
- * format:
set_page_candidates\ncharset=$charset\npage=$value\nhead1\tcand1\nhead2\tcand2\nhead3\tcand3\n
+ * format:
set_page_candidates\ncharset=$charset\npage=$value\nhead1\acand1\aannot1\nhead2\acand2\aannot2\nhead3\acand3\aannot3\n
*/
int page = 0;
@@ -306,7 +306,7 @@
break;
// split heading_label and cand_str
- QStringList l = QStringList::split( "\t", list [ i ], true );
+ QStringList l = QStringList::split( "\a", list [ i ], true );
// store data
CandData &d = stores[page * displayLimit + i - 3];
@@ -318,16 +318,16 @@
d.label = headString;
- // XXX Current prime (0.4.6) may return candidate string
- // containing "\t", and we can't handle annotation in another
- // window yet.
l.pop_front();
- QString candString = l.join( "\t" );
+ QString candString = l [ 0 ];
if ( codec )
d.str = codec->toUnicode( candString );
else
d.str = candString;
+
+ l.pop_front();
+ QString annotString = l [ 0 ];
}
}
void CandidateWindow::showPage( const QStringList &list )
=======================================
--- /trunk/qt4/candwin/qt4.cpp Mon Apr 19 06:48:33 2010
+++ /trunk/qt4/candwin/qt4.cpp Tue Apr 20 12:14:41 2010
@@ -126,7 +126,7 @@
qDebug( "uim-candwin-qt4: activateCand()" );
#endif
/**
- * format:
activate\ncharset=$charset\ndisplay_limit=$value\nhead1\tcand1\nhead2\tcand2\nhead3\tcand3\n
+ * format:
activate\ncharset=$charset\ndisplay_limit=$value\nhead1\acand1\aannot1\nhead2\acand2\aannot2\nhead3\acand3\aannot3\n
*/
// remove old data
@@ -158,7 +158,7 @@
break;
// split heading_label and cand_str
- QStringList l = list[ i ].split( '\t' );
+ QStringList l = list[ i ].split( '\a' );
// store data
CandData d;
@@ -170,17 +170,17 @@
d.label = headString;
- // XXX Current prime (0.4.6) may return candidate string
- // containing "\t", and we can't handle annotation in another
- // window yet.
l.pop_front();
- QString candString = l.join( "\t" );
+ QString candString = l [ 0 ];
if ( codec )
d.str = codec->toUnicode( candString.toAscii() );
else
d.str = candString;
+ l.pop_front();
+ QString annotString = l [ 0 ];
+
stores.append( d );
}
@@ -294,7 +294,7 @@
qDebug( "uim-candwin-qt: setPageCandidates()" );
#endif
/**
- * format:
set_page_candidates\ncharset=$charset\npage=$value\nhead1\tcand1\nhead2\tcand2\nhead3\tcand3\n
+ * format:
set_page_candidates\ncharset=$charset\npage=$value\nhead1\acand1\aannot1\nhead2\acand2\aannot2\nhead3\acand3\aannot3\n
*/
int page = 0;
@@ -324,7 +324,7 @@
break;
// split heading_label and cand_str
- QStringList l = list [ i ].split( '\t' );
+ QStringList l = list [ i ].split( '\a' );
// store data
CandData &d = stores[page * displayLimit + i - 3];
@@ -336,16 +336,16 @@
d.label = headString;
- // XXX Current prime (0.4.6) may return candidate string
- // containing "\t", and we can't handle annotation in another
- // window yet.
l.pop_front();
- QString candString = l.join( "\t" );
+ QString candString = l [ 0 ];
if ( codec )
d.str = codec->toUnicode( candString.toAscii() );
else
d.str = candString;
+
+ l.pop_front();
+ QString annotString = l [ 0 ];
}
}
void CandidateWindow::showPage( const QStringList &list )
=======================================
--- /trunk/xim/ximserver.cpp Sun Apr 4 20:35:54 2010
+++ /trunk/xim/ximserver.cpp Tue Apr 20 12:14:41 2010
@@ -808,6 +808,7 @@
#if !UIM_XIM_USE_NEW_PAGE_HANDLING
const char *cand_str;
const char *heading_label;
+ const char *annotation_str;
char *str;
#else
std::vector<CandList>::iterator slot_it;
@@ -835,15 +836,15 @@
display_limit ? i % display_limit : i);
cand_str = uim_candidate_get_cand_str(cand);
heading_label = uim_candidate_get_heading_label(cand);
- //annotation_str = uim_candidate_get_annotation(cand);
- if (cand_str && heading_label) {
- str = (char *)malloc(strlen(cand_str) + strlen(heading_label) + 2);
- sprintf(str, "%s\t%s", heading_label, cand_str);
+ annotation_str = uim_candidate_get_annotation(cand);
+ if (cand_str && heading_label && annotation_str) {
+ str = (char *)malloc(strlen(cand_str) + strlen(heading_label) +
strlen(annotation_str) + 3);
+ sprintf(str, "%s\a%s\a%s", heading_label, cand_str, annotation_str);
candidates.push_back((const char *)str);
}
else {
fprintf(stderr, "Warning: cand_str at %d is NULL\n", i);
- candidates.push_back((const char *)strdup("\t"));
+ candidates.push_back((const char *)strdup("\a\a"));
}
uim_candidate_free(cand);
}
@@ -901,6 +902,7 @@
int page_nr, start;
const char *cand_str;
const char *heading_label;
+ const char *annotation_str;
char *str;
CandList candidates;
@@ -923,15 +925,15 @@
(i + start));
cand_str = uim_candidate_get_cand_str(cand);
heading_label = uim_candidate_get_heading_label(cand);
- //annotation_str = uim_candidate_get_annotation(cand);
- if (cand_str && heading_label) {
- str = (char *)malloc(strlen(cand_str) + strlen(heading_label) + 2);
- sprintf(str, "%s\t%s", heading_label, cand_str);
+ annotation_str = uim_candidate_get_annotation_str(cand);
+ if (cand_str && heading_label && annotation_str) {
+ str = (char *)malloc(strlen(cand_str) + strlen(heading_label) +
strlen(annotation_str) + 3);
+ sprintf(str, "%s\a%s\a%s", heading_label, cand_str, annotation_str);
candidates.push_back((const char *)str);
}
else {
fprintf(stderr, "Warning: cand_str at %d is NULL\n", i);
- candidates.push_back((const char *)strdup("\t"));
+ candidates.push_back((const char *)strdup("\a\a"));
}
uim_candidate_free(cand);
}
--
Subscription settings: http://groups.google.com/group/uim-commit/subscribe?hl=en