static GtkEventBox* assign_cellbutton(UIMCandWinHorizontalGtk *horizontal_cwin, gint cand_index, gint display_limit) { struct index_button *idxbutton; int len; GPtrArray *buttons; buttons = horizontal_cwin->buttons; len = buttons->len; if (len <= cand_index) { GtkWidget *button; GtkWidget *label; button = gtk_event_box_new(); gtk_event_box_set_above_child(GTK_EVENT_BOX(button), TRUE); label = gtk_label_new(""); gtk_container_add(GTK_CONTAINER(button), label); scale_label(GTK_EVENT_BOX(button), PANGO_SCALE_LARGE); g_signal_connect(button, "button-press-event", G_CALLBACK(button_clicked), horizontal_cwin); #if GTK_CHECK_VERSION(2, 90, 0) g_signal_connect_after(label, "draw", G_CALLBACK(label_draw), horizontal_cwin); #else g_signal_connect_after(label, "expose-event", G_CALLBACK(label_exposed), horizontal_cwin); #endif #if GTK_CHECK_VERSION(3, 4, 0) gtk_widget_set_hexpand(button, TRUE); gtk_widget_set_vexpand(button, TRUE); gtk_grid_attach(GTK_GRID(UIM_CAND_WIN_GTK(horizontal_cwin)->view), button, cand_index, 0, 1, 1); #else gtk_table_attach_defaults(GTK_TABLE(UIM_CAND_WIN_GTK(horizontal_cwin)->view), button, cand_index, cand_index + 1, 0, 1); #endif idxbutton = g_malloc(sizeof(struct index_button)); if (idxbutton) { idxbutton->button = GTK_EVENT_BOX(button); clear_button(idxbutton, cand_index); idxbutton->cand_index_in_page = cand_index; } g_ptr_array_add(horizontal_cwin->buttons, idxbutton); } else { idxbutton = g_ptr_array_index(buttons, cand_index); idxbutton->cand_index_in_page = cand_index; } return idxbutton->button; }
static gboolean tree_view_button_press(GtkWidget *widget, GdkEventButton *event, gpointer data) { UIMCandWinVerticalGtk *vertical_cwin; UIMCandWinGtk *cwin; GtkTreePath *path; gboolean exist, retval = FALSE; gint *indicies; g_return_val_if_fail(GTK_IS_TREE_VIEW(widget), FALSE); g_return_val_if_fail(UIM_CAND_WIN_VERTICAL_GTK(data), FALSE); vertical_cwin = UIM_CAND_WIN_VERTICAL_GTK(data); cwin = UIM_CAND_WIN_GTK(vertical_cwin); exist = gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), event->x, event->y, &path, NULL, NULL, NULL); if (!exist) return FALSE; indicies = gtk_tree_path_get_indices(path); /* don't relay button press event to empty row */ if (cwin->display_limit * cwin->page_index + *indicies >= cwin->nr_candidates) retval = TRUE; gtk_tree_path_free(path); return retval; }
static void uim_cand_win_gtk_dispose (GObject *obj) { UIMCandWinGtk *cwin; g_return_if_fail(UIM_IS_CAND_WIN_GTK(obj)); cwin = UIM_CAND_WIN_GTK(obj); if (cwin->stores) { guint i; for (i = 0; i < cwin->stores->len; i++) { if (cwin->stores->pdata[i]) g_object_unref(G_OBJECT(cwin->stores->pdata[i])); } g_ptr_array_free(cwin->stores, TRUE); cwin->stores = NULL; } if (cwin->sub_window.window) { gtk_widget_destroy(cwin->sub_window.window); cwin->sub_window.window = NULL; cwin->sub_window.scrolled_window = NULL; cwin->sub_window.text_view = NULL; } if (G_OBJECT_CLASS (parent_class)->dispose) G_OBJECT_CLASS (parent_class)->dispose(obj); }
static void pagebutton_clicked(GtkButton *button, gpointer data) { UIMCandWinGtk *cwin = UIM_CAND_WIN_GTK(data); gboolean has_candidates = FALSE; if (cwin->candidate_index < 0) { /* if candidate_index < 0, "index-changed" signal is not emitted * and candidates for new page is not set. */ cwin->candidate_index = cwin->page_index * cwin->display_limit; } if (button == GTK_BUTTON(cwin->prev_page_button)) { uim_cand_win_gtk_shift_page(cwin, FALSE); } else if (button == GTK_BUTTON(cwin->next_page_button)) { uim_cand_win_gtk_shift_page(cwin, TRUE); } else { return; } if (cwin->stores->pdata[cwin->page_index]) { has_candidates = TRUE; } if (cwin->candidate_index >= 0) { g_signal_emit(G_OBJECT(cwin), cand_win_gtk_signals[INDEX_CHANGED_SIGNAL], 0); } /* if got candidates, update view */ if (!has_candidates && cwin->stores->pdata[cwin->page_index]) { uim_cand_win_gtk_set_page(cwin, cwin->page_index); } }
void uim_cand_win_vertical_gtk_set_index(UIMCandWinVerticalGtk *vertical_cwin, gint index) { UIMCandWinGtk *cwin; UIMCandWinVerticalGtkClass *vertical_cwin_class; UIMCandWinGtkClass *cwin_class; g_return_if_fail(UIM_IS_CAND_WIN_VERTICAL_GTK(vertical_cwin)); cwin = UIM_CAND_WIN_GTK(vertical_cwin); /* call parent method */ vertical_cwin_class = UIM_CAND_WIN_VERTICAL_GTK_GET_CLASS(vertical_cwin); cwin_class = g_type_class_peek_parent(vertical_cwin_class); cwin_class->set_index(cwin, index); if (cwin->candidate_index >= 0) { GtkTreePath *path; gint pos = index; if (cwin->display_limit) pos = cwin->candidate_index % cwin->display_limit; path = gtk_tree_path_new_from_indices(pos, -1); gtk_tree_view_set_cursor(GTK_TREE_VIEW(cwin->view), path, NULL, FALSE); gtk_tree_path_free(path); } else { GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cwin->view)); gtk_tree_selection_unselect_all(selection); uim_cand_win_gtk_update_label(cwin); } }
UIMCandWinGtk * uim_cand_win_gtk_new (void) { GObject *obj = g_object_new(UIM_TYPE_CAND_WIN_GTK, "type", GTK_WINDOW_POPUP, NULL); return UIM_CAND_WIN_GTK(obj); }
void uim_cand_win_gtk_set_cursor_location(UIMCandWinGtk *cwin, GdkRectangle *area) { g_return_if_fail(UIM_CAND_WIN_GTK(cwin)); g_return_if_fail(area); cwin->cursor = *area; }
void uim_cand_win_horizontal_gtk_layout_sub_window(UIMCandWinHorizontalGtk *horizontal_cwin) { UIMCandWinGtk *cwin; #if GTK_CHECK_VERSION(2, 90, 0) gint x, y, w, h, x2, y2, w2, h2, x3, y3; #else gint x, y, w, h, d, x2, y2, w2, h2, d2, x3, y3; #endif struct index_button *idxbutton; g_return_if_fail(UIM_IS_CAND_WIN_HORIZONTAL_GTK(horizontal_cwin)); cwin = UIM_CAND_WIN_GTK(horizontal_cwin); if (!cwin->sub_window.window) return; #if GTK_CHECK_VERSION(2, 90, 0) gdk_window_get_geometry(gtk_widget_get_window(GTK_WIDGET(cwin)), &x, &y, &w, &h); #else gdk_window_get_geometry(gtk_widget_get_window(GTK_WIDGET(cwin)), &x, &y, &w, &h, &d); #endif gdk_window_get_origin(gtk_widget_get_window(GTK_WIDGET(cwin)), &x, &y); #if GTK_CHECK_VERSION(2, 90, 0) gdk_window_get_geometry(gtk_widget_get_window(cwin->sub_window.window), &x2, &y2, &w2, &h2); #else gdk_window_get_geometry(gtk_widget_get_window(cwin->sub_window.window), &x2, &y2, &w2, &h2, &d2); #endif if (horizontal_cwin->selected) { GtkWidget *button; idxbutton = horizontal_cwin->selected; button = GTK_WIDGET(idxbutton->button); gdk_window_get_origin(gtk_widget_get_window(button), &x3, &y3); #if GTK_CHECK_VERSION(2, 18, 0) if (!gtk_widget_get_has_window(button)) { GtkAllocation allocation; gtk_widget_get_allocation(button, &allocation); x3 += allocation.x; } #else if (GTK_WIDGET_NO_WINDOW(button)) x3 += button->allocation.x; #endif } y = y + h; gtk_window_move(GTK_WINDOW(cwin->sub_window.window), x3, y); }
static void uim_cand_win_gtk_unmap (GtkWidget *widget) { UIMCandWinGtk *cwin = UIM_CAND_WIN_GTK(widget); if (cwin->sub_window.window) gtk_widget_hide(cwin->sub_window.window); if (GTK_WIDGET_CLASS (parent_class)->unmap) GTK_WIDGET_CLASS (parent_class)->unmap(widget); }
static void uim_cand_win_vertical_gtk_init (UIMCandWinVerticalGtk *vertical_cwin) { UIMCandWinGtk *cwin; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkTreeSelection *selection; cwin = UIM_CAND_WIN_GTK(vertical_cwin); cwin->view = gtk_tree_view_new(); gtk_container_add(GTK_CONTAINER(cwin->scrolled_window), cwin->view); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(cwin->view)); gtk_tree_selection_set_select_function(selection, 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, (const gchar *)NULL); column = gtk_tree_view_column_new_with_attributes("No", renderer, "text", COLUMN_HEADING, (const gchar *)NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(cwin->view), column); gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); renderer = gtk_cell_renderer_text_new(); g_object_set(renderer, "scale", 1.2, (const gchar *)NULL); /* g_object_set(renderer, "size-points", 20.0, NULL); */ column = gtk_tree_view_column_new_with_attributes("Text", renderer, "text", COLUMN_CANDIDATE, (const gchar *)NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(cwin->view), column); gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(cwin->view), TRUE); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(cwin->view), FALSE); gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); g_signal_connect(G_OBJECT(cwin->view), "button-press-event", G_CALLBACK(tree_view_button_press), cwin); gtk_widget_show(cwin->view); }
static gboolean tree_selection_changed(GtkTreeSelection *selection, gpointer data) { GtkTreeModel *model; GtkTreeIter iter; UIMCandWinVerticalGtk *vertical_cwin = UIM_CAND_WIN_VERTICAL_GTK(data); UIMCandWinGtk *cwin = UIM_CAND_WIN_GTK(vertical_cwin); if (gtk_tree_selection_get_selected(selection, &model, &iter)) { char *annotation = NULL; gtk_tree_model_get(model, &iter, COLUMN_ANNOTATION, &annotation, -1); 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; } } if (cwin->index_changed) { cwin->index_changed = FALSE; g_signal_emit_by_name(G_OBJECT(cwin), "index-changed"); } return TRUE; }
void uim_cand_win_horizontal_gtk_set_page(UIMCandWinHorizontalGtk *horizontal_cwin, gint page) { guint len, new_page; gint new_index; UIMCandWinGtk *cwin; g_return_if_fail(UIM_IS_CAND_WIN_HORIZONTAL_GTK(horizontal_cwin)); cwin = UIM_CAND_WIN_GTK(horizontal_cwin); g_return_if_fail(cwin->stores); len = cwin->stores->len; g_return_if_fail(len); if (page < 0) new_page = len - 1; else if (page >= (gint) len) new_page = 0; else new_page = page; update_table_button(horizontal_cwin, new_page); #if GTK_CHECK_VERSION(3, 4, 0) show_table(GTK_GRID(cwin->view), horizontal_cwin->buttons); #else show_table(GTK_TABLE(cwin->view), horizontal_cwin->buttons); #endif cwin->page_index = new_page; if (cwin->display_limit) { if (cwin->candidate_index >= 0) new_index = (new_page * cwin->display_limit) + (cwin->candidate_index % cwin->display_limit); else new_index = -1; } else { new_index = cwin->candidate_index; } if (new_index >= (gint) cwin->nr_candidates) new_index = cwin->nr_candidates - 1; /* check if (cwin->candidate_index != new_index) ?? */ uim_cand_win_gtk_set_index(cwin, new_index); }
static gboolean tree_selection_change(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_currently_selected, gpointer data) { UIMCandWinVerticalGtk *vertical_cwin = UIM_CAND_WIN_VERTICAL_GTK(data); UIMCandWinGtk *cwin = UIM_CAND_WIN_GTK(vertical_cwin); gint *indicies; gint idx; if (!cwin) return TRUE; if (cwin->block_index_selection) return TRUE; indicies = gtk_tree_path_get_indices(path); g_return_val_if_fail(indicies, TRUE); idx = *indicies + cwin->display_limit * cwin->page_index; if (!path_currently_selected && cwin->candidate_index != idx) { if (cwin->candidate_index >= 0) { cwin->candidate_index = idx; /* if emit "index-changed" here and IM deactivates this candwin, * activates new candwin and selects a candidate on new candwin * from index-changed callback, SEGV occurs in gtk because gtk tries to * select on old candwin after return of this tree_selection_change(). * To avoid SEGV, instead of emitting before selection change by gtk, * emit after selection changed by gtk. */ cwin->index_changed = TRUE; } uim_cand_win_gtk_update_label(cwin); if (cwin->candidate_index < 0) return FALSE; else return TRUE; } else { uim_cand_win_gtk_update_label(cwin); return TRUE; } }
static void button_clicked(GtkEventBox *button, GdkEventButton *event, gpointer data) { UIMCandWinHorizontalGtk *horizontal_cwin = data; UIMCandWinGtk *cwin = UIM_CAND_WIN_GTK(horizontal_cwin); gint i; gint idx = -1; struct index_button *prev_selected; prev_selected = horizontal_cwin->selected; if (prev_selected) { GtkWidget *label = gtk_bin_get_child(GTK_BIN(prev_selected->button)); gtk_widget_queue_draw(label); } for (i = 0; i < (gint)horizontal_cwin->buttons->len; i++) { GtkEventBox *p; struct index_button *idxbutton; idxbutton = g_ptr_array_index(horizontal_cwin->buttons, i); if (!idxbutton) { continue; } p = idxbutton->button; if (p == button) { GtkWidget *label = gtk_bin_get_child(GTK_BIN(button)); idx = idxbutton->cand_index_in_page; gtk_widget_queue_draw(label); horizontal_cwin->selected = idxbutton; 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"); }
void uim_cand_win_vertical_gtk_set_page(UIMCandWinVerticalGtk *vertical_cwin, gint page) { guint len, new_page; gint new_index; UIMCandWinGtk *cwin; g_return_if_fail(UIM_IS_CAND_WIN_VERTICAL_GTK(vertical_cwin)); cwin = UIM_CAND_WIN_GTK(vertical_cwin); g_return_if_fail(cwin->stores); len = cwin->stores->len; g_return_if_fail(len); if (page < 0) new_page = len - 1; else if (page >= (gint) len) new_page = 0; else new_page = page; gtk_tree_view_set_model(GTK_TREE_VIEW(cwin->view), GTK_TREE_MODEL(cwin->stores->pdata[new_page])); cwin->page_index = new_page; if (cwin->display_limit) { if (cwin->candidate_index >= 0) new_index = (new_page * cwin->display_limit) + (cwin->candidate_index % cwin->display_limit); else new_index = -1; } else { new_index = cwin->candidate_index; } if (new_index >= (gint) cwin->nr_candidates) new_index = cwin->nr_candidates - 1; uim_cand_win_gtk_set_index(cwin, new_index); }
void uim_cand_win_horizontal_gtk_create_sub_window(UIMCandWinHorizontalGtk *horizontal_cwin) { GtkWidget *window, *scrwin, *text_view, *frame; GdkGeometry hints; UIMCandWinGtk *cwin; g_return_if_fail(UIM_IS_CAND_WIN_HORIZONTAL_GTK(horizontal_cwin)); cwin = UIM_CAND_WIN_GTK(horizontal_cwin); if (cwin->sub_window.window) return; cwin->sub_window.window = window = gtk_window_new(GTK_WINDOW_POPUP); frame = gtk_frame_new(NULL); gtk_container_set_border_width(GTK_CONTAINER(frame), 0); hints.min_width = UIM_ANNOTATION_WIN_WIDTH; hints.min_height = UIM_ANNOTATION_WIN_HEIGHT; hints.max_width = UIM_ANNOTATION_WIN_WIDTH; hints.max_height = UIM_ANNOTATION_WIN_HEIGHT; gtk_window_set_geometry_hints(GTK_WINDOW(window), frame, &hints, GDK_HINT_MAX_SIZE | GDK_HINT_MIN_SIZE); 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_CHAR); gtk_widget_show(text_view); gtk_container_add(GTK_CONTAINER(scrwin), text_view); gtk_container_add(GTK_CONTAINER(frame), scrwin); gtk_container_add(GTK_CONTAINER(window), frame); gtk_widget_show(frame); gtk_widget_show(scrwin); gtk_widget_show(text_view); }
static void uim_cand_win_horizontal_gtk_init (UIMCandWinHorizontalGtk *horizontal_cwin) { gint col; GtkWidget *viewport; UIMCandWinGtk *cwin; cwin = UIM_CAND_WIN_GTK(horizontal_cwin); horizontal_cwin->buttons = g_ptr_array_new(); horizontal_cwin->selected = NULL; #if GTK_CHECK_VERSION(3, 4, 0) cwin->view = gtk_grid_new(); gtk_grid_set_column_spacing(GTK_GRID(cwin->view), 10); #else cwin->view = gtk_table_new(1, DEFAULT_NR_CELLS, FALSE); gtk_table_set_col_spacings(GTK_TABLE(cwin->view), 10); #endif viewport = gtk_viewport_new(NULL, NULL); gtk_container_add(GTK_CONTAINER(viewport), cwin->view); gtk_container_add(GTK_CONTAINER(cwin->scrolled_window), viewport); gtk_container_set_resize_mode(GTK_CONTAINER(viewport), GTK_RESIZE_PARENT); for (col = 0; col < DEFAULT_NR_CELLS; col++) { GtkWidget *button; GtkWidget *label; struct index_button *idxbutton; button = gtk_event_box_new(); gtk_event_box_set_above_child(GTK_EVENT_BOX(button), TRUE); label = gtk_label_new(""); gtk_container_add(GTK_CONTAINER(button), label); scale_label(GTK_EVENT_BOX(button), PANGO_SCALE_LARGE); g_signal_connect(button, "button-press-event", G_CALLBACK(button_clicked), horizontal_cwin); #if GTK_CHECK_VERSION(2, 90, 0) g_signal_connect_after(label, "draw", G_CALLBACK(label_draw), horizontal_cwin); #else g_signal_connect_after(label, "expose-event", G_CALLBACK(label_exposed), horizontal_cwin); #endif #if GTK_CHECK_VERSION(3, 4, 0) gtk_widget_set_hexpand(button, TRUE); gtk_widget_set_vexpand(button, TRUE); gtk_grid_attach(GTK_GRID(cwin->view), button, col, 0, 1, 1); #else gtk_table_attach_defaults(GTK_TABLE(cwin->view), button, col, col + 1, 0, 1); #endif idxbutton = g_malloc(sizeof(struct index_button)); if (idxbutton) { idxbutton->button = GTK_EVENT_BOX(button); clear_button(idxbutton, col); } g_ptr_array_add(horizontal_cwin->buttons, idxbutton); } gtk_widget_show_all(cwin->view); gtk_widget_show(viewport); gtk_widget_set_size_request(cwin->num_label, DEFAULT_MIN_WINDOW_WIDTH, -1); gtk_window_set_default_size(GTK_WINDOW(cwin), DEFAULT_MIN_WINDOW_WIDTH, -1); gtk_window_set_resizable(GTK_WINDOW(cwin), FALSE); }
void uim_cand_win_horizontal_gtk_set_index(UIMCandWinHorizontalGtk *horizontal_cwin, gint index) { gint new_page, prev_index; UIMCandWinGtk *cwin; g_return_if_fail(UIM_IS_CAND_WIN_HORIZONTAL_GTK(horizontal_cwin)); cwin = UIM_CAND_WIN_GTK(horizontal_cwin); prev_index = cwin->candidate_index; if (index >= (gint) cwin->nr_candidates) cwin->candidate_index = 0; else cwin->candidate_index = index; if (cwin->candidate_index >= 0 && cwin->display_limit) new_page = cwin->candidate_index / cwin->display_limit; else new_page = cwin->page_index; if (cwin->page_index != new_page) uim_cand_win_gtk_set_page(cwin, new_page); if (cwin->candidate_index >= 0) { gint pos; struct index_button *idxbutton, *prev_selected; GtkWidget *label; if (cwin->display_limit) pos = cwin->candidate_index % cwin->display_limit; else pos = cwin->candidate_index; idxbutton = g_ptr_array_index(horizontal_cwin->buttons, pos); prev_selected = (gpointer)horizontal_cwin->selected; if (prev_selected && prev_index != cwin->candidate_index) { label = gtk_bin_get_child(GTK_BIN(prev_selected->button)); gtk_widget_queue_draw(label); } label = gtk_bin_get_child(GTK_BIN(idxbutton->button)); gtk_widget_queue_draw(label); horizontal_cwin->selected = idxbutton; /* show subwin */ if (cwin->stores->pdata[new_page]) { char *annotation = NULL; GtkTreeModel *model = GTK_TREE_MODEL(cwin->stores->pdata[new_page]); GtkTreeIter iter; gtk_tree_model_iter_nth_child(model, &iter, NULL, pos); gtk_tree_model_get(model, &iter, COLUMN_ANNOTATION, &annotation, -1); 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 { horizontal_cwin->selected = NULL; if (cwin->sub_window.window) { gtk_widget_hide(cwin->sub_window.window); cwin->sub_window.active = FALSE; } } uim_cand_win_gtk_update_label(cwin); }
static void update_table_button(UIMCandWinHorizontalGtk *horizontal_cwin, guint new_page) { UIMCandWinGtk *cwin; GtkTreeModel *model; GPtrArray *buttons; GtkTreeIter ti; gboolean has_next; gint display_limit, len, cand_index = 0; cwin = UIM_CAND_WIN_GTK(horizontal_cwin); if (!cwin->stores->pdata[new_page]) { return; } model = GTK_TREE_MODEL(cwin->stores->pdata[new_page]); buttons = horizontal_cwin->buttons; display_limit = cwin->display_limit; len = buttons->len; clear_all_buttons(buttons); has_next = gtk_tree_model_get_iter_first(model, &ti); while (has_next) { gchar *heading; gchar *cand_str; GtkEventBox *button = NULL; gtk_tree_model_get(model, &ti, COLUMN_HEADING, &heading, COLUMN_CANDIDATE, &cand_str, TERMINATOR); if (cand_str != NULL) { button = assign_cellbutton(horizontal_cwin, cand_index, display_limit); if (button != NULL) { GtkWidget *label; label = gtk_bin_get_child(GTK_BIN(button)); if (heading && heading[0] != '\0') { gchar *text = g_strdup_printf("%s: %s", heading, cand_str); gtk_label_set_text(GTK_LABEL(label), text); g_free(text); } else { gtk_label_set_text(GTK_LABEL(label), cand_str); } scale_label(button, PANGO_SCALE_LARGE); } } g_free(cand_str); g_free(heading); cand_index++; has_next = gtk_tree_model_iter_next(model, &ti); } if (cand_index < len) { gint i; for (i = len - 1; i >= cand_index; i--) { struct index_button *idxbutton; idxbutton = g_ptr_array_index(buttons, i); if (idxbutton == horizontal_cwin->selected) horizontal_cwin->selected = NULL; gtk_widget_destroy(GTK_WIDGET(idxbutton->button)); g_free(idxbutton); g_ptr_array_remove_index(buttons, i); } #if !GTK_CHECK_VERSION(3, 4, 0) gtk_table_resize(GTK_TABLE(cwin->view), 1, cand_index); #endif } }