I put a simple code to test which a button
is clicked There are two buttons. I would know which button is clicked in the
function “on_window_partition()”. Any idea? Regards, /* ************** recog_darea.c
****************************************/ #include <gtk/gtk.h> #include <stdio.h> typedef struct dm_t_tag { int nwin; int clicked; } dm_t; /* Function Prototypes */ GtkWidget *makeFixedContainer(GtkWidget
*window, dm_t *dm); int main(int argc,char *argv[]) { GtkWidget *window; GtkWidget *topbox; dm_t dm; gtk_init (&argc,
&argv); window =
gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_object_set_data
(GTK_OBJECT (window), "window", window); gtk_widget_set_usize (window, 260,
150);
gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE); gtk_window_set_position (GTK_WINDOW
(window), GTK_WIN_POS_CENTER); gtk_window_set_default_size
(GTK_WINDOW (window), 260, 150);
gtk_signal_connect(GTK_OBJECT(window), "destroy",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL); topbox = gtk_hbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), topbox);
gtk_container_set_border_width(GTK_CONTAINER(topbox), 5); makeFixedContainer (topbox,
&dm); gtk_widget_show_all(window); gtk_main(); return 0; } void on_window_partition (GtkWidget
*widget, dm_t *dm) { fprintf (stderr, "darea %d is
clicked.\n", dm->clicked); } GtkWidget *makeFixedContainer(GtkWidget
*window, dm_t *dm) { int i, j, num; GtkWidget *table; GtkWidget *afixed; GtkWidget *button[2]; GtkWidget *darea[2]; GtkWidget *fixed[2]; afixed = gtk_fixed_new (); gtk_box_pack_start
(GTK_BOX(window), afixed, FALSE, TRUE, 0); gtk_widget_show (afixed); for(j = 0; j < 1; j++) { for(i = 0; i < 2;
i++) { num = i + 2
* j; button[num]
= gtk_button_new(); fixed[num]
= afixed; darea[num]
= gtk_drawing_area_new ();
gtk_drawing_area_size (GTK_DRAWING_AREA(darea[num]), 100, 80);
gtk_container_add (GTK_CONTAINER(button[num]), darea[num]);
gtk_signal_connect (GTK_OBJECT(button[num]), "clicked",
GTK_SIGNAL_FUNC(on_window_partition), dm);
gtk_fixed_put (GTK_FIXED(fixed[num]), button[num], 120*i, 85*j);
gtk_widget_realize (darea[num]); } } return table; } |