Re: [gtk-list] Passing a Structure to a Function
- From: Tim Janik <timj gtk org>
- To: "gtk-list redhat com" <gtk-list redhat com>
- Subject: Re: [gtk-list] Passing a Structure to a Function
- Date: Thu, 11 Jun 1998 17:09:53 +0200 (CEST)
On Thu, 11 Jun 1998, Marc wrote:
> I've got a little program in which I want to pass a struct to a
> function.
> For this I use :
> -> gtk_signal_connect (object, "event", my_function,
> pointer_to_struct)
> -> my_function (GtkWidget *widget, gpointer data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the signature of the function you are connecting to a certain
signal depends on the signal.
the above signature would work for GtkButton::clicked, but since you connect
to GtkWidget::event, the signature needs to look like
gint my_function (GtkWidget *widget,
GdkEvent *event,
gpointer data);
where `data' will have the value of `pointer_to_struct' and the return
value is one of TRUE or FALSE, indicating whether you handled the event
or not (if you didn't handle it, or just want to snoop events, you would
probably want to return FALSE, so gtk will continue to proccess this
event).
as a general rule, you can figure the exact signature of a certain signal
by looking at the widget class structure which introduces the signal you
are connecting to and append "gpointer data" to it's signature (signals
are by convention named after the corresponding class function), thus
_GtkWidgetClass looks as follows:
struct _GtkWidgetClass
{
[...]
/* events */
gint (* event) (GtkWidget *widget,
GdkEvent *event);
[...]
};
wheras GtkButton::clicked would have worked for your function, because of:
struct _GtkButtonClass
{
[...]
void (* clicked) (GtkButton *button);
[...]
};
> The problem is that, in my_function, I do not receive the good pointer
> (even with the appropriate cast).
> ( I saw that Alex Roberts and Ewan Laurence did the same thing in gEdit
> 0.3.2 and it worked ! )
>
> Does anybody knows why this is not working for me ?
>
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]