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; }
/* 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; 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; } } return TRUE; }
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); }