Using g_signal_connect in class
- From: Marco Rocco <mr85mr gmail com>
- To: gtk-app-devel-list gnome org
- Subject: Using g_signal_connect in class
- Date: Tue, 15 Jul 2008 14:32:37 +0200
Thanks, I have done, but i have the problem of how i get treepath, and
how i can pass to callback functions,
look my class:
class GtkCtree{
private:
GtkWidget *treeview;
GtkListStore *liststore;
Tdata string_to_data(const char *data_string);
static void cell_edited_cbk(GtkWidget treeview, GtkCtree *data){
data->cell_edited();
}
void cell_edited(GtkCellRendererText *cell, const gchar
*path_string, const gchar *new_text,
gpointer data){
/* get column */
guint column_number=
GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(cell), "my_column_num"));
/* get row */
GtkTreePath *path = gtk_tree_path_new_from_string(path_string);
/* update model */
GtkTreeIter iter;
gtk_tree_model_get_iter(GTK_TREE_MODEL(liststore), &iter, path);
gchar *old_text;
gtk_tree_model_get(GTK_TREE_MODEL(liststore), &iter,
column_number,
&old_text, -1);
gtk_list_store_set(GTK_LIST_STORE(liststore), &iter,
column_number, new_text, -1);
g_free(old_text);
}
public:
GtkCtree();
GtkWidget *get_widget();
void set(GladeXML *xml_file_glade, const char *nome_treeview, int
ncolonne, ...);
void inserisci_colonna(const char *titolo_colonna, const char
*tipo_dato_gtk, int ncolonna);
void inserisci_riga(int ncolonne, ...);
int get_ID_selezionato();
Tdata get_data_selezionata();
void clear();
void inserisci_colonna_editable(const char *titolo_colonna, const
char *tipo_dato_gtk,
int ncolonna);
};
void GtkCtree::inserisci_colonna_editable(const char *titolo_colonna,
const char *tipo_dato_gtk,
int ncolonna){
GtkCellRenderer *renderer;
GtkTreeViewColumn *colonna;
gtk_tree_view_set_model(GTK_TREE_VIEW(treeview),
GTK_TREE_MODEL(liststore));
renderer= gtk_cell_renderer_text_new();
colonna= gtk_tree_view_column_new_with_attributes(titolo_colonna,
renderer,
tipo_dato_gtk, ncolonna,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), colonna);
g_object_set_data(G_OBJECT(renderer), "my_column_num",
GUINT_TO_POINTER(1));
g_object_set(renderer, "editable", TRUE, NULL); //setta il testo
editabile
g_signal_connect(renderer, "edited", (GCallback) cell_edited_cbk,
liststore);
}
void GtkClist::set(GladeXML *xml_file_glade, const char *nome_treeview,
int ncolonne, ...){
treeview= glade_xml_get_widget(xml_file_glade, nome_treeview);
va_list arg_pt;
va_start(arg_pt, ncolonne);
GType *array;
array= new GType[ncolonne];
for (int i=0; i<ncolonne; i++)
array[i]= va_arg(arg_pt, GType);
liststore = gtk_list_store_newv(ncolonne, array);
va_end(arg_pt);
}
void GtkClist::inserisci_riga(int ncolonne, ...){
va_list args;
va_start(args, ncolonne);
GtkTreeIter newrow;
gtk_list_store_append(GTK_LIST_STORE(liststore), &newrow);
gtk_list_store_set_valist(GTK_LIST_STORE(liststore), &newrow, args);
va_end(args);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]