void uim_cand_win_gtk_layout(UIMCandWinGtk *cwin, gint topwin_x, gint topwin_y, gint topwin_width, gint topwin_height) { GtkRequisition req; int x, y; int cursor_x, cursor_y; int sc_he, cw_he; /*screen height, candidate window height*/ int sc_wi, cw_wi; g_return_if_fail(UIM_IS_CAND_WIN_GTK(cwin)); #if GTK_CHECK_VERSION(3, 0, 0) gtk_widget_get_preferred_size(GTK_WIDGET(cwin), &req, NULL); #else gtk_widget_size_request(GTK_WIDGET(cwin), &req); #endif cw_wi = req.width; cw_he = req.height; sc_he = gdk_screen_get_height(gdk_screen_get_default ()); sc_wi = gdk_screen_get_width (gdk_screen_get_default ()); /* FIXME */ switch (cwin->position) { case UIM_CAND_WIN_POS_LEFT: cursor_x = 0; break; case UIM_CAND_WIN_POS_RIGHT: cursor_x = topwin_width - cw_wi; break; default: cursor_x = cwin->cursor.x; break; } cursor_y = cwin->cursor.y; if (sc_wi < topwin_x + cursor_x + cw_wi) { /* x = topwin_x + cursor_x - cw_wi; */ x = sc_wi - cw_wi; } else { x = topwin_x + cursor_x; } if (sc_he < topwin_y + cursor_y + cwin->cursor.height + cw_he) { y = topwin_y + cursor_y - cw_he; } else { y = topwin_y + cursor_y + cwin->cursor.height; } gtk_window_move(GTK_WINDOW(cwin), x, y); #if GTK_CHECK_VERSION(3, 7, 8) if (gtk_widget_get_mapped(cwin->view) && GTK_IS_TREE_VIEW(cwin->view)) gtk_widget_queue_resize_no_redraw(cwin->view); #endif uim_cand_win_gtk_layout_sub_window(cwin); }
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; }
static void uim_cand_win_gtk_layout() { int x, y; int screen_width, screen_height; screen_width = gdk_screen_get_width(gdk_screen_get_default()); screen_height = gdk_screen_get_height(gdk_screen_get_default()); if (screen_width < cwin->pos_x + cwin->width) x = cwin->pos_x - cwin->width; else x = cwin->pos_x; if (screen_height < cwin->pos_y + cwin->height) y = cwin->pos_y - cwin->height - 20; /* FIXME: Preedit height is needed to be sent by uim-xim */ else y = cwin->pos_y; gtk_window_move(GTK_WINDOW(cwin), x, y); uim_cand_win_gtk_layout_sub_window(cwin); }
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); }