mercredi 3 octobre 2018

How to emit 'editing-done' signal on 'gtk_cell_renderer_text'

I use GTK+3.0 and I have a gtk_list_store with gtk_cell_renderer_text. I need to change the gtk_cell_renderer_text background color when the cell is clicked. To do this I've attached a code to the editing-started signal of the gtk_cell_renderer_text and after assigning the color the editing-done signal must be called in order to exit the cell without prompting for input. So this is my G_CALLBACK function to the editing-started signal:

void CAD::cell_color_edited_callback(GtkCellRendererText *cell,
                                     gchar *path_string,
                                     gchar *new_text, gpointer user_data)
{
  GtkTreeModel *model = (GtkTreeModel *)user_data;
  GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
  GtkTreeIter iter;

  gtk_tree_model_get_iter(model, &iter, path);

  gint response = gtk_dialog_run(GTK_DIALOG(colorchooserdialog));
  GdkRGBA color;
  if (response == GTK_RESPONSE_OK) {
    gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(colorchooserdialog), &color);
  }

// this line is not calling the 'editing-done' signal at all!!!
  gtk_cell_renderer_stop_editing(GTK_CELL_RENDERER(cell), FALSE);

// neither this one is calling 'editing-done' signal
  gtk_cell_editable_editing_done(GTK_CELL_EDITABLE(cell));

  gtk_list_store_set(GTK_LIST_STORE(model), &iter, 3,
                     gdk_rgba_to_string(&color), -1);

  gtk_widget_hide(GTK_WIDGET(colorchooserdialog));
  gtk_tree_path_free(path);

}

How to make this function to emit 'editing-done' signal? Also, is there a better cell type for the purpose of colorful background cell in gtk_list_store?

Aucun commentaire:

Enregistrer un commentaire