I have a dynamic array of check buttons and I’m having difficulty, within the call back function, identifying which check button has been toggled.
My regular buttons and their call backs work as expected.
I have a work around that involves using the name of the button widget as an identifier but this seems crude.
film_strip_data[k].check_box = gtk_check_button_new_with_label("Move");
sprintf(widget_name, "%d", k + 1); // 'name' the widget
gtk_widget_set_name(film_strip_data[k].check_box, widget_name);
The signal connect looks like this:
g_signal_connect
(
film_strip_data[k].check_box, // AKA check_button
"toggled",
G_CALLBACK(toggle_image_check_mark_callback),
&film_strip_data[k + 1]
);
The data pointer passed is good and works for regular buttons. It identifies which button or check_button is pressed etc.
The call back itself looks like this
void toggle_image_check_mark_callback
(
GtkWidget *widget,
GdkEventButton *button_event,
FILM_STRIP *film_strip_frame
)
{
char widget_name[WIDGET_NAME_LENGTH];
int frame;
// this seg faults -- but why ?
//gui_printf("check mark toggled %s\n", film_strip_frame->file_name);
strcpy(widget_name, gtk_widget_get_name(widget));
frame = atoi(widget_name);
gui_printf("check mark %2d toggled\n", frame);
film_strip_data[frame].mode = !film_strip_data[frame].mode;
}
Any attempt to access the pointer data causes a seg fault. This is odd since it works just fine for regular buttons.
Once the data is identified toggling works just fine. You can see my work around but it seems really crude to us a widget name for this purpose. What am I doing wrong ?