Re: Using g_signal_connect in class

2008-07-16 Thread Dave Foster
On Tue, Jul 15, 2008 at 6:36 AM, Gabriele Greco [EMAIL PROTECTED]
wrote:


  static void handle_click_cbk(GtkWidget *mywidget_, MyClass *data) {
 data-handle_click(); }


You can't make a callback function intended to be used by C code be inside
of the C++ class.  It will not be able to find it.

Marco, I recommend using the full gtkmm API - this mix of gtk+ and gtkmm
will lead to a lot of headaches unless you know where the boundaries of the
two are (you can use them together, but typically not in a way you are using
it now).

Read the excellent docs at http://gtkmm.org/documentation.shtml,
specifically the book at
http://gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/index.html

dave
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Using g_signal_connect in class

2008-07-15 Thread Marco Rocco

Hello, this is my first post on this mailing list, now i do my request:
can i use g_signal_connect  in a method of my class, using as c_handler 
a private function of class? ...and if i can, how i can do ?

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Using g_signal_connect in class

2008-07-15 Thread Gabriele Greco
On Tue, Jul 15, 2008 at 12:09 PM, Marco Rocco [EMAIL PROTECTED] wrote:

 Hello, this is my first post on this mailing list, now i do my request:
 can i use g_signal_connect  in a method of my class, using as c_handler a
 private function of class? ...and if i can, how i can do ?


If you use C++ and plain GTK, supposing you are initializing your callback
in the  you should do something like this:

class MyClass
{
  GtkWidget *mywidget_;
  static void handle_click_cbk(GtkWidget *mywidget_, MyClass *data) {
data-handle_click(); }

  void handle_click(); // your real callback
public:
  MyClass() {
 mywidget_ = gtk_button_new();
 g_signal_connect(mywidget_, clicked, GCallback(handle_click_cbk),
this);
  }
};

-- 
Bye,
 Gabry
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Using g_signal_connect in class

2008-07-15 Thread Marco Rocco

Hello, this is my first post on this mailing list, now i do my request:
can i use g_signal_connect  in a method of my class, using as c_handler 
a private function of class? ...and if i can, how i can do ?

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Using g_signal_connect in class

2008-07-15 Thread Marco Rocco
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; incolonne; 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);
}

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list