Exemple #1
0
void
uim_cand_win_gtk_shift_page(UIMCandWinGtk *cwin, gboolean forward)
{
    g_return_if_fail(UIM_IS_CAND_WIN_GTK(cwin));

    if (forward) {
        uim_cand_win_gtk_set_page(cwin, cwin->page_index + 1);
    } else {
        uim_cand_win_gtk_set_page(cwin, cwin->page_index - 1);
    }
}
Exemple #2
0
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);
    }
}
Exemple #3
0
static void
candwin_show_page(gchar **str)
{
  int page;

  sscanf(str[1], "%d", &page);

  uim_cand_win_gtk_set_page(cwin, page);
  gtk_widget_show_all(GTK_WIDGET(cwin));
#if GTK_CHECK_VERSION(3, 7, 8)
  gtk_widget_queue_resize_no_redraw(cwin->view);
#endif
}
Exemple #4
0
static void
pagebutton_clicked(GtkButton *button, gpointer data)
{
  UIMCandidateWindow *cwin = UIM_CANDIDATE_WINDOW(data);

  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_set_page(cwin, cwin->page_index - 1);
  } else if (button == GTK_BUTTON(cwin->next_page_button)) {
    uim_cand_win_gtk_set_page(cwin, cwin->page_index + 1);
  } else {
    return;
  }
  if (cwin->candidate_index >= 0) {
    g_signal_emit(G_OBJECT(cwin),
                  cand_win_gtk_signals[INDEX_CHANGED_SIGNAL], 0);
  }
  if (!cwin->stores->pdata[cwin->page_index]) {
    /*       candwin                         uim-xim
     * pagebutton_clicked()
     *            ---------"index"------------>
     *                                      InputContext::candidate_select()
     *            <---"set_page_candidates"----
     *                                        Canddisp::select()
     *            <--------"select"------------
     * candwin_update()
     *   uim_cand_win_gtk_set_index()
     *     uim_cand_win_gtk_set_page()
     */
    cwin->need_page_update = TRUE;
  }
}
Exemple #5
0
static void
uim_cand_win_gtk_real_set_index(UIMCandWinGtk *cwin, gint index)
{
    gint new_page;

    g_return_if_fail(UIM_IS_CAND_WIN_GTK(cwin));

    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);
}
Exemple #6
0
/* copied from uim-cand-win-gtk.c */
static void
uim_cand_win_gtk_set_index(UIMCandidateWindow *cwin, gint index)
{
  gint new_page;

  g_return_if_fail(UIM_IS_CANDIDATE_WINDOW(cwin));

  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 || cwin->need_page_update)
    uim_cand_win_gtk_set_page(cwin, new_page);

  if (cwin->candidate_index >= 0 && cwin->need_hilite) {
    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);
    update_label(cwin);
  }
}
Exemple #7
0
void
uim_cand_win_gtk_set_candidates(UIMCandWinGtk *cwin,
                                guint display_limit,
                                GSList *candidates)
{
    gint i, nr_stores = 1;

    g_return_if_fail(UIM_IS_CAND_WIN_GTK(cwin));

    if (cwin->stores == NULL)
        cwin->stores = g_ptr_array_new();

    /* remove old data */
    if (cwin->page_index >= 0 && cwin->page_index < (int) cwin->stores->len) {
        /* Remove data from current page to shrink the window */
        if (cwin->stores->pdata[cwin->page_index])
            gtk_list_store_clear(cwin->stores->pdata[cwin->page_index]);
    }
    for (i = cwin->stores->len - 1; i >= 0; i--) {
        GtkListStore *store = g_ptr_array_remove_index(cwin->stores, i);
        if (store)
            g_object_unref(G_OBJECT(store));
    }

    cwin->candidate_index = -1;
    cwin->nr_candidates = g_slist_length(candidates);
    cwin->display_limit = display_limit;

    cwin->sub_window.active = FALSE;

    if (candidates == NULL)
        return;

    /* calculate number of GtkListStores to create */
    if (display_limit) {
        nr_stores = cwin->nr_candidates / display_limit;
        if (cwin->nr_candidates > display_limit * nr_stores)
            nr_stores++;
    }

    /* create GtkListStores, and set candidates */
    for (i = 0; i < nr_stores; i++) {
        GtkListStore *store = gtk_list_store_new(NR_COLUMNS,
                              G_TYPE_STRING,
                              G_TYPE_STRING,
                              G_TYPE_STRING);
        GSList *node;
        guint j;

        g_ptr_array_add(cwin->stores, store);

        /* set candidates */
        for (j = i * display_limit, node = g_slist_nth(candidates, j);
                display_limit ? j < display_limit * (i + 1) : j < cwin->nr_candidates;
                j++, node = g_slist_next(node))
        {
            GtkTreeIter ti;

            if (node) {
                uim_candidate cand = node->data;
                gtk_list_store_append(store, &ti);
                gtk_list_store_set(store, &ti,
                                   COLUMN_HEADING,    uim_candidate_get_heading_label(cand),
                                   COLUMN_CANDIDATE,  uim_candidate_get_cand_str(cand),
                                   COLUMN_ANNOTATION, uim_candidate_get_annotation_str(cand),
                                   TERMINATOR);
            } else {
#if 0
                /*
                * 2004-07-22 Takuro Ashie <*****@*****.**>
                 *
                 * FIXME!:
                 *   I think we shoudn't set any data for empty row.
                 *   It may cause incorrect action.
                 */
                gtk_list_store_append(store, &ti);
                gtk_list_store_set(store, &ti,
                                   COLUMN_HEADING,    "",
                                   COLUMN_CANDIDATE,  "",
                                   COLUMN_ANNOTATION, NULL,
                                   TERMINATOR);
#endif
            }
        }
    }

    if (cwin->nr_candidates <= cwin->display_limit) {
        gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), FALSE);
        gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), FALSE);
    } else {
        gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), TRUE);
        gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), TRUE);
    }

    uim_cand_win_gtk_set_page(cwin, 0);

    uim_cand_win_gtk_update_label(cwin);
}
Exemple #8
0
static void
candwin_activate(gchar **str)
{
  gsize rbytes, wbytes;
  gint i, nr_stores = 1;
  guint j = 1;
  gchar *utf8_str;
  const gchar *charset;
  guint display_limit;
  GSList *candidates = NULL;

  if (cwin->stores == NULL)
    cwin->stores = g_ptr_array_new();

  /* remove old data */
  for (i = cwin->stores->len - 1; i >= 0; i--) {
    GtkListStore *store = g_ptr_array_remove_index(cwin->stores, i);
    if (store) {
      gtk_list_store_clear(store);
      g_object_unref(G_OBJECT(store));
    }
  }

  if (!strncmp(str[1], "charset=", 8))
    charset = str[1] + 8;
  else
    charset = "UTF-8";

  if (!strncmp(str[2], "display_limit=", 14)) {
    display_limit = atoi(str[2] + 14);
    i = 3;
  } else {
    display_limit = 0;
    i = 2;
  }

  for ( ; str[i]; i++) {
    if (strcmp(str[i], "") == 0) {
      break;
    }
    utf8_str = g_convert(str[i],
			 -1,
			 "UTF-8",
			 charset,
			 &rbytes, &wbytes, NULL);

    candidates = g_slist_prepend(candidates, utf8_str);
    j++;
  }
  candidates = g_slist_reverse(candidates);

  cwin->candidate_index = -1;
  cwin->nr_candidates = j - 1;
  cwin->display_limit = display_limit;
  cwin->need_hilite = FALSE;
  cwin->need_page_update = FALSE;

  if (candidates == NULL)
    return;

  /* calculate number of GtkListStores to create */
  if (display_limit) {
    nr_stores = cwin->nr_candidates / display_limit;
    if (cwin->nr_candidates > display_limit * nr_stores)
      nr_stores++;
  }

  /* create GtkListStores, and set candidates */
  for (i = 0; i < nr_stores; i++) {
    GtkListStore *store = gtk_list_store_new(NR_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
    GSList *node;

    g_ptr_array_add(cwin->stores, store);

    /* set candidates */
    for (j = i * display_limit, node = g_slist_nth(candidates, j);
	 display_limit ? j < display_limit * (i + 1) : j < cwin->nr_candidates;
	 j++, node = g_slist_next(node))
    {
      GtkTreeIter ti;
      if (node) {
	gchar *str = node->data;
	gchar **column = g_strsplit(str, "\a", 3);
	gtk_list_store_append(store, &ti);
	gtk_list_store_set(store, &ti,
			   COLUMN_HEADING, column[0],
			   COLUMN_CANDIDATE, column[1],
			   COLUMN_ANNOTATION, column[2],
			   TERMINATOR);
	g_strfreev(column);
	g_free(str);
      } else {
	/* No need to set any data for empty row. */
      }
    }
  }
  g_slist_free(candidates);

  if (cwin->nr_candidates <= cwin->display_limit) {
    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), FALSE);
    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), FALSE);
  } else {
    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), TRUE);
    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), TRUE);
  }

  uim_cand_win_gtk_set_page(cwin, 0);
  update_label(cwin);

  gtk_widget_show_all(GTK_WIDGET(cwin));
  cwin->is_active = 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);
}