Re: passing 3 widgets as parameters to g_signal_connect (Working)



Thanks to all!

It Works!

Just for history I'm pasting here the code that works for me.

Many thanks,

LEslie

------
typedef struct 
{
  GtkWidget *op1;
  GtkWidget *op2;
  GtkWidget *res;
}CALC;


GtkWidget*
create_window1 (void)
{
  GtkWidget *window1;
  GtkWidget *table1;
  GtkWidget *vezes;

  CALC *elementos;
  elementos = g_new(CALC,1);

  elementos->op1 = gtk_entry_new ();
  elementos->op2 = gtk_entry_new ();
  elementos->res = gtk_entry_new ();
......
 
  vezes = gtk_button_new_with_mnemonic ("*");
  gtk_widget_show (vezes);
  gtk_table_attach (GTK_TABLE (table1), vezes, 2, 3, 2, 3,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);


  g_signal_connect ((gpointer) vezes, "clicked",
                    G_CALLBACK (on_vezes_clicked),
                     (gpointer) elementos);

  return window1;
}


void
on_vezes_clicked                       (GtkButton       *button,
                                        gpointer         user_data)
{

  CALC *elem;
  gint iope1 , iope2, ires;
  gchar result[80];
  const gchar *oper1,*oper2; 

  elem = (CALC *) user_data;
  oper1 = gtk_entry_get_text(GTK_ENTRY(elem->op1));
  oper2 = gtk_entry_get_text(GTK_ENTRY(elem->op2));
  iope1 = atoi (oper1);
  iope2 = atoi (oper2);
  ires = iope1 * iope2;
  g_snprintf(result,80,"%4d",ires);
  gtk_entry_set_text(GTK_ENTRY(elem->res), result);

}
-----------


Cheers

LEslie



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]