Revision: 6452
Author: deton.kih
Date: Thu Jun 17 06:10:31 2010
Log: * Fix the table style candidate window to place candidates
which have empty or duplicate heading label on free cell [uim-ja 236]
* gtk/uim-cand-win-tbl-gtk.c
- (BLOCK_LR_NR_CELLS): New
- (BLOCK_LRS_NR_CELLS): New
- (assign_cellbutton): Rename from get_row_column()
and add function to find free cell
if specified heading label is empty, not found or already used
- (update_table_button): Add argument display_limit for
assign_cellbutton().
Move update of cand_index_in_page to assign_cellbutton().
Change to update button only needed.
Rename hasNext to has_next.
- (uim_cand_win_tbl_gtk_set_page): Follow the change of argument addition
to update_table_button
* helper/candwin-tbl-gtk.c
- (BLOCK_LR_NR_CELLS): New
- (BLOCK_LRS_NR_CELLS): New
- (assign_cellbutton): Rename from get_row_column()
and add function to find free cell
if specified heading label is empty, not found or already used
- (update_table_button): Add argument display_limit for
assign_cellbutton().
Move update of cand_index_in_page to assign_cellbutton().
Change to update button only needed.
Rename hasNext to has_next.
- (uim_cand_win_gtk_set_page): Follow the change of argument addition
to update_table_button
http://code.google.com/p/uim/source/detail?r=6452
Modified:
/trunk/gtk/uim-cand-win-tbl-gtk.c
/trunk/helper/candwin-tbl-gtk.c
=======================================
--- /trunk/gtk/uim-cand-win-tbl-gtk.c Wed Jun 16 02:58:53 2010
+++ /trunk/gtk/uim-cand-win-tbl-gtk.c Thu Jun 17 06:10:31 2010
@@ -80,6 +80,8 @@
#define BLOCK_AS_ROW_END BLOCK_LRS_ROW_END
#define BLOCK_AS_COLUMN_START BLOCK_LRS_COLUMN_END
#define BLOCK_AS_COLUMN_END LABELCHAR_NR_COLUMNS
+#define BLOCK_LR_NR_CELLS (BLOCK_A_ROW_END * BLOCK_A_COLUMN_START)
+#define BLOCK_LRS_NR_CELLS ((BLOCK_LRS_ROW_END - BLOCK_LRS_ROW_START) *
(BLOCK_LRS_COLUMN_END - BLOCK_LRS_COLUMN_START))
#define BLOCK_SPACING 20
#define HOMEPOSITION_SPACING 2
@@ -325,19 +327,54 @@
return UIM_CAND_WIN_TBL_GTK(obj);
}
-static void
-get_row_column(gchar *labelchar_table, const gchar labelchar, gint *row,
gint *col)
+static GtkButton*
+assign_cellbutton(gchar *labelchar_table, const gchar labelchar,
+ gint cand_index, gint display_limit, GPtrArray *buttons, gboolean
*has_label)
{
gint i;
+ struct index_button *idxbutton;
+
+ if (labelchar != '\0') {
+ /* find button by labelchar */
+ for (i = 0; i < LABELCHAR_NR_CELLS; i++) {
+ if (labelchar_table[i] == labelchar) {
+ idxbutton = g_ptr_array_index(buttons, i);
+ if (!idxbutton) {
+ continue;
+ }
+ if (idxbutton->cand_index_in_page != -1) {
+ break; /* already used */
+ }
+ idxbutton->cand_index_in_page = cand_index;
+ *has_label = TRUE;
+ return idxbutton->button;
+ }
+ }
+ }
+ /* labelchar not found || already used */
+
+ /* find free cell */
for (i = 0; i < LABELCHAR_NR_CELLS; i++) {
- if (labelchar_table[i] == labelchar) {
- *row = i / LABELCHAR_NR_COLUMNS;
- *col = i % LABELCHAR_NR_COLUMNS;
- return;
+ if (display_limit && display_limit <= BLOCK_LR_NR_CELLS +
BLOCK_LRS_NR_CELLS
+ && i % LABELCHAR_NR_COLUMNS >= BLOCK_A_COLUMN_START) {
+ /* skip blockA which is far from home position */
+ i += LABELCHAR_NR_COLUMNS - BLOCK_A_COLUMN_START - 1;
+ continue;
+ }
+ idxbutton = g_ptr_array_index(buttons, i);
+ if (!idxbutton) {
+ continue;
+ }
+ if (idxbutton->cand_index_in_page == -1) {
+ idxbutton->cand_index_in_page = cand_index;
+ *has_label = FALSE;
+ return idxbutton->button;
}
}
- *row = 0;
- *col = 0;
+
+ /* failed to assign button */
+ *has_label = FALSE;
+ return NULL;
}
void
@@ -391,47 +428,39 @@
}
static void
-update_table_button(GtkTreeModel *model, GPtrArray *buttons, gchar
*labelchar_table)
+update_table_button(GtkTreeModel *model, GPtrArray *buttons,
+ gchar *labelchar_table, gint display_limit)
{
GtkTreeIter ti;
- gboolean hasNext;
+ gboolean has_next;
gint cand_index = 0;
clear_buttons(buttons, labelchar_table);
- hasNext = gtk_tree_model_get_iter_first(model, &ti);
- while (hasNext) {
+ has_next = gtk_tree_model_get_iter_first(model, &ti);
+ while (has_next) {
gchar *heading = NULL;
gchar *cand_str = NULL;
GtkButton *button = NULL;
- struct index_button *idxbutton;
- gint row = 0, col = 0;
gtk_tree_model_get(model, &ti, COLUMN_HEADING, &heading,
COLUMN_CANDIDATE, &cand_str, TERMINATOR);
- get_row_column(labelchar_table, heading[0], &row, &col);
-
- idxbutton = g_ptr_array_index(buttons, INDEX(row, col));
- if (idxbutton) {
- button = idxbutton->button;
- idxbutton->cand_index_in_page = cand_index;
- }
- if (cand_str == NULL) {
- if (labelchar_table[INDEX(row, col)] == '\0') {
- gtk_button_set_relief(button, GTK_RELIEF_NONE);
- } else {
- gtk_button_set_relief(button, GTK_RELIEF_HALF);
- }
- gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
- } else {
- gtk_button_set_relief(button, GTK_RELIEF_NORMAL);
- gtk_widget_set_sensitive(GTK_WIDGET(button), TRUE);
- }
- gtk_button_set_label(button, (cand_str == NULL) ? " " : cand_str);
+ if (cand_str != NULL) {
+ gboolean has_label = FALSE;
+ gchar ch = (heading == NULL) ? '\0' : heading[0];
+ button = assign_cellbutton(labelchar_table, ch, cand_index,
+ display_limit, buttons, &has_label);
+ if (button != NULL) {
+ gtk_button_set_relief(button,
+ has_label ? GTK_RELIEF_NORMAL : GTK_RELIEF_HALF);
+ gtk_widget_set_sensitive(GTK_WIDGET(button), TRUE);
+ gtk_button_set_label(button, cand_str);
+ }
+ }
g_free(cand_str);
g_free(heading);
cand_index++;
- hasNext = gtk_tree_model_iter_next(model, &ti);
+ has_next = gtk_tree_model_iter_next(model, &ti);
}
}
@@ -457,7 +486,8 @@
new_page = page;
update_table_button(GTK_TREE_MODEL(cwin->stores->pdata[new_page]),
- ctblwin->buttons, ctblwin->labelchar_table);
+ ctblwin->buttons, ctblwin->labelchar_table,
+ cwin->display_limit);
show_table(GTK_TABLE(cwin->view), ctblwin->buttons);
cwin->page_index = new_page;
=======================================
--- /trunk/helper/candwin-tbl-gtk.c Wed Jun 16 02:58:53 2010
+++ /trunk/helper/candwin-tbl-gtk.c Thu Jun 17 06:10:31 2010
@@ -154,6 +154,8 @@
#define BLOCK_AS_ROW_END BLOCK_LRS_ROW_END
#define BLOCK_AS_COLUMN_START BLOCK_LRS_COLUMN_END
#define BLOCK_AS_COLUMN_END LABELCHAR_NR_COLUMNS
+#define BLOCK_LR_NR_CELLS (BLOCK_A_ROW_END * BLOCK_A_COLUMN_START)
+#define BLOCK_LRS_NR_CELLS ((BLOCK_LRS_ROW_END - BLOCK_LRS_ROW_START) *
(BLOCK_LRS_COLUMN_END - BLOCK_LRS_COLUMN_START))
#define BLOCK_SPACING 20
#define HOMEPOSITION_SPACING 2
@@ -454,19 +456,54 @@
return table;
}
-static void
-get_row_column(gchar *labelchar_table, const gchar labelchar, gint *row,
gint *col)
+static GtkButton*
+assign_cellbutton(gchar *labelchar_table, const gchar labelchar,
+ gint cand_index, gint display_limit, GPtrArray *buttons, gboolean
*has_label)
{
gint i;
+ struct index_button *idxbutton;
+
+ if (labelchar != '\0') {
+ /* find button by labelchar */
+ for (i = 0; i < LABELCHAR_NR_CELLS; i++) {
+ if (labelchar_table[i] == labelchar) {
+ idxbutton = g_ptr_array_index(buttons, i);
+ if (!idxbutton) {
+ continue;
+ }
+ if (idxbutton->cand_index_in_page != -1) {
+ break; /* already used */
+ }
+ idxbutton->cand_index_in_page = cand_index;
+ *has_label = TRUE;
+ return idxbutton->button;
+ }
+ }
+ }
+ /* labelchar not found || already used */
+
+ /* find free cell */
for (i = 0; i < LABELCHAR_NR_CELLS; i++) {
- if (labelchar_table[i] == labelchar) {
- *row = i / LABELCHAR_NR_COLUMNS;
- *col = i % LABELCHAR_NR_COLUMNS;
- return;
+ if (display_limit && display_limit <= BLOCK_LR_NR_CELLS +
BLOCK_LRS_NR_CELLS
+ && i % LABELCHAR_NR_COLUMNS >= BLOCK_A_COLUMN_START) {
+ /* skip blockA which is far from home position */
+ i += LABELCHAR_NR_COLUMNS - BLOCK_A_COLUMN_START - 1;
+ continue;
+ }
+ idxbutton = g_ptr_array_index(buttons, i);
+ if (!idxbutton) {
+ continue;
+ }
+ if (idxbutton->cand_index_in_page == -1) {
+ idxbutton->cand_index_in_page = cand_index;
+ *has_label = FALSE;
+ return idxbutton->button;
}
}
- *row = 0;
- *col = 0;
+
+ /* failed to assign button */
+ *has_label = FALSE;
+ return NULL;
}
static void
@@ -883,47 +920,39 @@
}
static void
-update_table_button(GtkTreeModel *model, GPtrArray *buttons, gchar
*labelchar_table)
+update_table_button(GtkTreeModel *model, GPtrArray *buttons,
+ gchar *labelchar_table, gint display_limit)
{
GtkTreeIter ti;
- gboolean hasNext;
+ gboolean has_next;
gint cand_index = 0;
clear_buttons(buttons, labelchar_table);
- hasNext = gtk_tree_model_get_iter_first(model, &ti);
- while (hasNext) {
+ has_next = gtk_tree_model_get_iter_first(model, &ti);
+ while (has_next) {
gchar *heading = NULL;
gchar *cand_str = NULL;
GtkButton *button = NULL;
- struct index_button *idxbutton;
- gint row = 0, col = 0;
gtk_tree_model_get(model, &ti, COLUMN_HEADING, &heading,
COLUMN_CANDIDATE, &cand_str, TERMINATOR);
- get_row_column(labelchar_table, heading[0], &row, &col);
-
- idxbutton = g_ptr_array_index(buttons, INDEX(row, col));
- if (idxbutton) {
- button = idxbutton->button;
- idxbutton->cand_index_in_page = cand_index;
- }
- if (cand_str == NULL) {
- if (labelchar_table[INDEX(row, col)] == '\0') {
- gtk_button_set_relief(button, GTK_RELIEF_NONE);
- } else {
- gtk_button_set_relief(button, GTK_RELIEF_HALF);
- }
- gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
- } else {
- gtk_button_set_relief(button, GTK_RELIEF_NORMAL);
- gtk_widget_set_sensitive(GTK_WIDGET(button), TRUE);
- }
- gtk_button_set_label(button, (cand_str == NULL) ? " " : cand_str);
+ if (cand_str != NULL) {
+ gboolean has_label = FALSE;
+ gchar ch = (heading == NULL) ? '\0' : heading[0];
+ button = assign_cellbutton(labelchar_table, ch, cand_index,
+ display_limit, buttons, &has_label);
+ if (button != NULL) {
+ gtk_button_set_relief(button,
+ has_label ? GTK_RELIEF_NORMAL : GTK_RELIEF_HALF);
+ gtk_widget_set_sensitive(GTK_WIDGET(button), TRUE);
+ gtk_button_set_label(button, cand_str);
+ }
+ }
g_free(cand_str);
g_free(heading);
cand_index++;
- hasNext = gtk_tree_model_iter_next(model, &ti);
+ has_next = gtk_tree_model_iter_next(model, &ti);
}
}
@@ -948,7 +977,8 @@
new_page = page;
update_table_button(GTK_TREE_MODEL(cwin->stores->pdata[new_page]),
- cwin->buttons, cwin->labelchar_table);
+ cwin->buttons, cwin->labelchar_table,
+ cwin->display_limit);
cwin->page_index = new_page;