Button Callback Arguments
- From: author <millward Ms UManitoba CA>
- To: gtk-app-devel-list gnome org
- Subject: Button Callback Arguments
- Date: Sun, 14 Oct 2001 11:28:55 -0500
I'm just a newbie and I'm puzzled by the limitations on
arguments to callbacks triggered by a simple button.
It is true that you can only use 2 arguments as in:
void button_callback(GtkWidet * widget, gpointer * data) ?
I want to write a callback, triggered by a simple button click,
that will:
1) There is an array buffer in main with 6 char strings
each of which will be displayed in a label
which has been created in main.
2) obtain the present state of this label
gtk_label_get(GTK_LABEL(label), &str);
3) Detect if it is at the end of the array buffer and needs to
be reset to the the front of the buffer ( index = 0 ).
4) Change the character string on the label to another
held in the array buffer.
This is simple stuff but I keep getting 'segmentation default'
whenever I try to use one of the label functions inside the callback.
I have to import into the callback
1) GtkWidget * widget for the button
2) gint array_size for the number of strings in the
array buffer
3) GtkWidget * label the label to be altered
4) char buffer[][26] the array buffer that holds the strings.
I suspect this might be impossible using a simple button
since every example I see using a button callback only
has 2 arguments. I hope this isn't true. I can't see how
a button would be of any practical use if it was limited to
2 arguments for its callback function. Everything would
have to be defined as global.
Here is my buggy code:
#include <stdio.h>
#include <gtk/gtk.h>
void button_callback(GtkWidget * widget, GtkWidget * label,
gint array_size, char buffer[][26] )
{
static int i = 0;
char * str = NULL;
gtk_label_get(GTK_LABEL(label), &str);
if ( strcmp( str, "Today + 2")==0 )
{
**** do something no yet defined ****
}
if( i >= array_size )
{
i = 0;
gtk_label_set_text(GTK_LABEL(label), buffer[ i ++] );
}
else
{
gtk_label_set_text(GTK_LABEL(label), buffer[ i ++] );
}
}
In Main the following is defined ( plus a lot of other stuff )
static char buffer[6][26] = { "Yesterday","Today","Tomorrow",
"Today + 2 ","Today + 3 ","Today + 4"};
button = gtk_button_new_with_label("Change the Day");
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(button_callback),
& buffer[0] );
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]