Revision: 6444
Author: deton.kih
Date: Sun Jun 13 01:28:24 2010
Log: * Change to be able to commit a candidate by clicking a button
on table style candidate window
* gtk/uim-cand-win-tbl-gtk.c
- (struct index_button): New struct
- (button_clicked): New function which emits "index-changed" signal
- (uim_cand_win_tbl_gtk_init): Add initialization of index_button.
Add "clicked" signal connection for each button
- (uim_cand_win_tbl_gtk_dispose): Add free of index_button
- (set_candidate): Add parameter idx.
Add update of cand_index_in_page of index_button
- (uim_cand_win_tbl_gtk_set_candidates): Follow the parameter addition
of set_candidate()
- (uim_cand_win_tbl_gtk_set_page_candidates): Ditto
- (get_button): New function
- (update_table_button): Change to use get_button()
- (is_empty_block): Ditto
- (show_table): Ditto
* helper/candwin-tbl-gtk.c
- (struct index_button): New struct
- (button_clicked): Add implementation to emit "index-changed" signal
- (cb_table_view_destroy): Add free of index_button
- (candidate_window_init): Add initialization of index_button
- (set_candidate): Add parameter idx.
Add update of cand_index_in_page of index_button
- (candwin_activate): Follow the parameter addition
of set_candidate()
- (uim_cand_win_gtk_set_page_candidates): Ditto
- (get_button): New function
- (update_table_button): Change to use get_button()
- (is_empty_block): Ditto
- (show_table): Ditto
* scm/tutcode.scm
- (tutcode-set-candidate-index-handler): Change to commit candidate
http://code.google.com/p/uim/source/detail?r=6444
Modified:
/trunk/gtk/uim-cand-win-tbl-gtk.c
/trunk/helper/candwin-tbl-gtk.c
/trunk/scm/tutcode.scm
=======================================
--- /trunk/gtk/uim-cand-win-tbl-gtk.c Sun Jun 13 00:30:03 2010
+++ /trunk/gtk/uim-cand-win-tbl-gtk.c Sun Jun 13 01:28:24 2010
@@ -102,11 +102,18 @@
#define SPACING_UPPER_FAR_ROW 0
#define SPACING_SHIFT_UPPER_FAR_ROW 4
+struct index_button {
+ gint cand_index_in_page;
+ GtkButton *button;
+};
+
static void uim_cand_win_tbl_gtk_init (UIMCandWinTblGtk
*cwin);
static void uim_cand_win_tbl_gtk_class_init (UIMCandWinGtkClass *klass);
static void uim_cand_win_tbl_gtk_dispose (GObject *obj);
static gchar *init_labelchar_table(void);
+static void button_clicked(GtkButton *button, gpointer data);
static void show_table(GtkTable *view, GPtrArray *buttons);
+static GtkButton *get_button(GPtrArray *buttons, gint idx);
static GType cand_win_tbl_type = 0;
@@ -178,10 +185,17 @@
for (row = 0; row < LABELCHAR_NR_ROWS; row++) {
for (col = 0; col < LABELCHAR_NR_COLUMNS; col++) {
GtkWidget *button;
+ struct index_button *idxbutton;
button = gtk_button_new_with_label(" ");
+ g_signal_connect(button, "clicked", G_CALLBACK(button_clicked),
ctblwin);
gtk_table_attach_defaults(GTK_TABLE(cwin->view), button,
col, col + 1, row, row + 1);
- g_ptr_array_add(ctblwin->buttons, button);
+ idxbutton = g_malloc(sizeof(struct index_button));
+ if (idxbutton) {
+ idxbutton->button = GTK_BUTTON(button);
+ idxbutton->cand_index_in_page = -1;
+ }
+ g_ptr_array_add(ctblwin->buttons, idxbutton);
}
}
gtk_table_set_col_spacing(GTK_TABLE(cwin->view),
SPACING_LEFT_BLOCK_COLUMN,
@@ -245,6 +259,46 @@
free(ary0);
return table;
}
+
+static void
+button_clicked(GtkButton *button, gpointer data)
+{
+ UIMCandWinTblGtk *ctblwin = data;
+ UIMCandWinGtk *cwin = UIM_CAND_WIN_GTK(ctblwin);
+ gint i;
+ gint idx = -1;
+
+ for (i = 0; i < LABELCHAR_NR_CELLS; i++) {
+ GtkButton *p;
+ struct index_button *idxbutton;
+ idxbutton = g_ptr_array_index(ctblwin->buttons, i);
+ if (!idxbutton) {
+ continue;
+ }
+ p = idxbutton->button;
+ if (p == button) {
+ GtkReliefStyle relief;
+ relief = gtk_button_get_relief(button);
+ if (relief != GTK_RELIEF_NORMAL) {
+ return;
+ }
+ idx = idxbutton->cand_index_in_page;
+ break;
+ }
+ }
+ if (idx >= 0 && cwin->display_limit) {
+ if (idx >= (gint)cwin->display_limit) {
+ idx %= cwin->display_limit;
+ }
+ cwin->candidate_index = cwin->page_index * cwin->display_limit + idx;
+ } else {
+ cwin->candidate_index = idx;
+ }
+ if (cwin->candidate_index >= (gint)cwin->nr_candidates) {
+ cwin->candidate_index = -1;
+ }
+ g_signal_emit_by_name(G_OBJECT(cwin), "index-changed");
+}
static void
uim_cand_win_tbl_gtk_dispose (GObject *obj)
@@ -260,6 +314,13 @@
ctblwin->labelchar_table = NULL;
}
if (ctblwin->buttons) {
+ guint i;
+ for (i = 0; i < ctblwin->buttons->len; i++) {
+ if (ctblwin->buttons->pdata[i]) {
+ g_free(ctblwin->buttons->pdata[i]);
+ /* GtkButton is destroyed by container */
+ }
+ }
g_ptr_array_free(ctblwin->buttons, TRUE);
ctblwin->buttons = NULL;
}
@@ -293,7 +354,7 @@
}
static void
-set_candidate(UIMCandWinTblGtk *ctblwin, GSList *node, GtkListStore *store)
+set_candidate(UIMCandWinTblGtk *ctblwin, GSList *node, GtkListStore
*store, gint idx)
{
if (node) {
GtkTreeIter ti;
@@ -303,6 +364,7 @@
const char *heading_label = NULL;
const char *cand_str = NULL;
uim_candidate cand = node->data;
+ struct index_button *idxbutton;
heading_label = uim_candidate_get_heading_label(cand);
cand_str = uim_candidate_get_cand_str(cand);
@@ -313,6 +375,11 @@
gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &ti);
}
gtk_list_store_set(store, &ti, col, cand_str, TERMINATOR);
+
+ idxbutton = g_ptr_array_index(ctblwin->buttons, INDEX(row, col));
+ if (idxbutton) {
+ idxbutton->cand_index_in_page = idx;
+ }
} else {
/* No need to set any data for empty row. */
}
@@ -382,7 +449,7 @@
display_limit ? j < display_limit * (i + 1) : j < cwin->nr_candidates;
j++, node = g_slist_next(node))
{
- set_candidate(ctblwin, node, store);
+ set_candidate(ctblwin, node, store, j);
}
}
@@ -428,7 +495,7 @@
j < len;
j++, node = g_slist_next(node))
{
- set_candidate(ctblwin, node, store);
+ set_candidate(ctblwin, node, store, j);
}
}
@@ -468,8 +535,8 @@
for (col = 0; col < LABELCHAR_NR_COLUMNS; col++) {
GValue value = {0};
const gchar *str = NULL;
- GtkButton *button;
- button = g_ptr_array_index(buttons, INDEX(row, col));
+ GtkButton *button = NULL;
+ button = get_button(buttons, INDEX(row, col));
if (hasValue) {
gtk_tree_model_get_value(model, &ti, col, &value);
str = g_value_get_string(&value);
@@ -546,9 +613,9 @@
gint row, col;
for (row = rowstart; row < rowend; row++) {
for (col = colstart; col < colend; col++) {
- GtkButton *button;
+ GtkButton *button = NULL;
GtkReliefStyle relief;
- button = g_ptr_array_index(buttons, INDEX(row, col));
+ button = get_button(buttons, INDEX(row, col));
relief = gtk_button_get_relief(button);
if (relief == GTK_RELIEF_NORMAL) {
return FALSE;
@@ -607,8 +674,8 @@
for (row = 0; row < LABELCHAR_NR_ROWS; row++) {
for (col = 0; col < LABELCHAR_NR_COLUMNS; col++) {
- GtkButton *button;
- button = g_ptr_array_index(buttons, INDEX(row, col));
+ GtkButton *button = NULL;
+ button = get_button(buttons, INDEX(row, col));
if (row >= hide_row || col >= hide_col) {
gtk_widget_hide(GTK_WIDGET(button));
} else {
@@ -637,3 +704,16 @@
/* gtk_table_resize(view, hide_row, hide_col); */
gtk_widget_show(GTK_WIDGET(view));
}
+
+static GtkButton *
+get_button(GPtrArray *buttons, gint idx)
+{
+ GtkButton *button = NULL;
+ struct index_button *idxbutton;
+
+ idxbutton = g_ptr_array_index(buttons, idx);
+ if (idxbutton) {
+ button = idxbutton->button;
+ }
+ return button;
+}
=======================================
--- /trunk/helper/candwin-tbl-gtk.c Sun Jun 13 00:29:13 2010
+++ /trunk/helper/candwin-tbl-gtk.c Sun Jun 13 01:28:24 2010
@@ -176,6 +176,11 @@
#define SPACING_UPPER_FAR_ROW 0
#define SPACING_SHIFT_UPPER_FAR_ROW 4
+struct index_button {
+ gint cand_index_in_page;
+ GtkButton *button;
+};
+
static void candidate_window_init(UIMCandidateWindow *cwin);
static void candidate_window_class_init(UIMCandidateWindowClass *klass);
@@ -209,6 +214,7 @@
static void candwin_show_page(gchar **str);
static void str_parse(char *str);
static gchar *init_labelchar_table(void);
+static GtkButton *get_button(GPtrArray *buttons, gint idx);
static void index_changed_cb(UIMCandidateWindow *cwin)
{
@@ -263,8 +269,42 @@
}
static void
-button_clicked(GtkButton *button, gpointer cwin)
-{
+button_clicked(GtkButton *button, gpointer data)
+{
+ UIMCandidateWindow *cwin = UIM_CANDIDATE_WINDOW(data);
+ gint i;
+ gint idx = -1;
+
+ for (i = 0; i < LABELCHAR_NR_CELLS; i++) {
+ GtkButton *p;
+ struct index_button *idxbutton;
+ idxbutton = g_ptr_array_index(cwin->buttons, i);
+ if (!idxbutton) {
+ continue;
+ }
+ p = idxbutton->button;
+ if (p == button) {
+ GtkReliefStyle relief;
+ relief = gtk_button_get_relief(button);
+ if (relief != GTK_RELIEF_NORMAL) {
+ return;
+ }
+ idx = idxbutton->cand_index_in_page;
+ break;
+ }
+ }
+ if (idx >= 0 && cwin->display_limit) {
+ if (idx >= (gint)cwin->display_limit) {
+ idx %= cwin->display_limit;
+ }
+ cwin->candidate_index = cwin->page_index * cwin->display_limit + idx;
+ } else {
+ cwin->candidate_index = idx;
+ }
+ if (cwin->candidate_index >= (gint)cwin->nr_candidates) {
+ cwin->candidate_index = -1;
+ }
+ g_signal_emit_by_name(G_OBJECT(cwin), "index-changed");
}
static void
@@ -283,6 +323,12 @@
}
g_ptr_array_free(cwin->stores, TRUE);
+ for (i = 0; i < (gint)cwin->buttons->len; i++) {
+ if (cwin->buttons->pdata[i]) {
+ g_free(cwin->buttons->pdata[i]);
+ /* GtkButton is destroyed by container */
+ }
+ }
g_ptr_array_free(cwin->buttons, TRUE);
if (cwin->labelchar_table != default_labelchar_table) {
@@ -332,11 +378,17 @@
for (row = 0; row < LABELCHAR_NR_ROWS; row++) {
for (col = 0; col < LABELCHAR_NR_COLUMNS; col++) {
GtkWidget *button;
+ struct index_button *idxbutton;
button = gtk_button_new_with_label(" ");
g_signal_connect(button, "clicked", G_CALLBACK(button_clicked),
cwin);
gtk_table_attach_defaults(GTK_TABLE(cwin->view), button,
col, col + 1, row, row + 1);
- g_ptr_array_add(cwin->buttons, button);
+ idxbutton = g_malloc(sizeof(struct index_button));
+ if (idxbutton) {
+ idxbutton->button = GTK_BUTTON(button);
+ idxbutton->cand_index_in_page = -1;
+ }
+ g_ptr_array_add(cwin->buttons, idxbutton);
}
}
gtk_table_set_col_spacing(GTK_TABLE(cwin->view),
SPACING_LEFT_BLOCK_COLUMN,
@@ -429,13 +481,14 @@
}
static void
-set_candidate(UIMCandidateWindow *cwin, GSList *node, GtkListStore *store)
+set_candidate(UIMCandidateWindow *cwin, GSList *node, GtkListStore *store,
gint idx)
{
if (node) {
GtkTreeIter ti;
gint row = 0;
gint col = 0;
gint i;
+ struct index_button *idxbutton;
gchar *str = node->data;
/* "heading label char\acandidate\aannotation" */
gchar **column = g_strsplit(str, "\a", 3);
@@ -446,6 +499,11 @@
gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &ti);
}
gtk_list_store_set(store, &ti, col, column[1], TERMINATOR);
+
+ idxbutton = g_ptr_array_index(cwin->buttons, INDEX(row, col));
+ if (idxbutton) {
+ idxbutton->cand_index_in_page = idx;
+ }
g_strfreev(column);
g_free(str);
@@ -541,7 +599,7 @@
display_limit ? j < display_limit * (i + 1) : j < cwin->nr_candidates;
j++, node = g_slist_next(node))
{
- set_candidate(cwin, node, store);
+ set_candidate(cwin, node, store, j);
}
}
g_slist_free(candidates);
@@ -848,8 +906,8 @@
for (col = 0; col < LABELCHAR_NR_COLUMNS; col++) {
GValue value = {0};
const gchar *str = NULL;
- GtkButton *button;
- button = g_ptr_array_index(buttons, INDEX(row, col));
+ GtkButton *button = NULL;
+ button = get_button(buttons, INDEX(row, col));
if (hasValue) {
gtk_tree_model_get_value(model, &ti, col, &value);
str = g_value_get_string(&value);
@@ -954,7 +1012,7 @@
j < len;
j++, node = g_slist_next(node))
{
- set_candidate(cwin, node, store);
+ set_candidate(cwin, node, store, j);
}
}
@@ -987,9 +1045,9 @@
gint row, col;
for (row = rowstart; row < rowend; row++) {
for (col = colstart; col < colend; col++) {
- GtkButton *button;
+ GtkButton *button = NULL;
GtkReliefStyle relief;
- button = g_ptr_array_index(buttons, INDEX(row, col));
+ button = get_button(buttons, INDEX(row, col));
relief = gtk_button_get_relief(button);
if (relief == GTK_RELIEF_NORMAL) {
return FALSE;
@@ -1048,8 +1106,8 @@
for (row = 0; row < LABELCHAR_NR_ROWS; row++) {
for (col = 0; col < LABELCHAR_NR_COLUMNS; col++) {
- GtkButton *button;
- button = g_ptr_array_index(buttons, INDEX(row, col));
+ GtkButton *button = NULL;
+ button = get_button(buttons, INDEX(row, col));
if (row >= hide_row || col >= hide_col) {
gtk_widget_hide(GTK_WIDGET(button));
} else {
@@ -1102,3 +1160,16 @@
return FALSE;
}
+
+static GtkButton *
+get_button(GPtrArray *buttons, gint idx)
+{
+ GtkButton *button = NULL;
+ struct index_button *idxbutton;
+
+ idxbutton = g_ptr_array_index(buttons, idx);
+ if (idxbutton) {
+ button = idxbutton->button;
+ }
+ return button;
+}
=======================================
--- /trunk/scm/tutcode.scm Sun Jun 13 00:54:35 2010
+++ /trunk/scm/tutcode.scm Sun Jun 13 01:28:24 2010
@@ -1072,12 +1072,20 @@
(label (nth n tutcode-heading-label-char-list)))
(list cand label "")))))
-;;; ¸õÊ䥦¥£¥ó¥É¥¦¤¬¸õÊä¤òÁªÂò¤·¤¿¤È¤¤Ë¸Æ¤Ö´Ø¿ô
-(define (tutcode-set-candidate-index-handler tc idx)
- (if (tutcode-context-candidate-window tc)
+;;; ¸õÊ䥦¥£¥ó¥É¥¦¤¬¸õÊä¤òÁªÂò¤·¤¿¤È¤¤Ë¸Æ¤Ö´Ø¿ô¡£
+;;; ÁªÂò¤µ¤ì¤¿¸õÊä¤ò³ÎÄꤹ¤ë¡£
+(define (tutcode-set-candidate-index-handler pc idx)
+ (if (and
+ (tutcode-context-candidate-window pc)
+ (>= idx 0)
+ (< idx (tutcode-context-nr-candidates pc)))
(begin
- (tutcode-context-set-nth! tc idx)
- (tutcode-update-preedit tc))))
+ (tutcode-context-set-nth! pc idx)
+ (im-commit pc
+ (if (eq? (tutcode-context-state pc) 'tutcode-state-kigou)
+ (tutcode-prepare-commit-string-for-kigou-mode pc)
+ (tutcode-prepare-commit-string pc)))
+ (tutcode-update-preedit pc))))
(tutcode-configure-widgets)