[no subject]



The callback function is selected from a structure like this

typedef struct  _GtkIFCBData            GtkIFCBData;
struct _GtkIFCBData
{
  GtkItemFactoryCallback  func;
  guint                   callback_type;
  gpointer                func_data;
  guint                   callback_action;
};


in this way:

static void
gtk_item_factory_callback_marshal (GtkWidget *widget,
                                   gpointer   func_data)
{
  GtkIFCBData *data;

  data =3D func_data;

  if (data->callback_type =3D=3D 1)
    {
      GtkItemFactoryCallback1 func1 =3D (GtkItemFactoryCallback1)
data->func;
      func1 (data->func_data, data->callback_action, widget);
    }
  else if (data->callback_type =3D=3D 2)
    {
      GtkItemFactoryCallback2 func2 =3D (GtkItemFactoryCallback2)
data->func;
      func2 (widget, data->func_data, data->callback_action);
    }
}

and this chunck in gtk_item_factory_add_item sets up the structure:

  if (callback)
    {
      GtkIFCBData *data;

      data =3D g_chunk_new (GtkIFCBData, ifactory_cb_data_chunks);
      data->func =3D callback;
      data->callback_type =3D callback_type;
      data->func_data =3D callback_data;
      data->callback_action =3D callback_action;

      gtk_object_weakref (GTK_OBJECT (widget),
                          ifactory_cb_data_free,
                          data);
      gtk_signal_connect (GTK_OBJECT (widget),
                          "activate",
                          GTK_SIGNAL_FUNC (gtk_item_factory_callback_marshal),
                          data);
    }


In other words, using

void callback (GtkWidget *w, gpointer data, guint action) { ... }
gtk_item_factory_add_item (factory, path, accel,
                           callback, act, data, 2,//<- select cb. type 2
                           item_type, widget);

should connect 'callback' to the item, such that the call back is called
with 'data' as its second argument and 'act' as its third.  The callback
type is not passed to the callback.

The reason you (Russell) have gotten away with treating you pointer as
the action could be that you have in fact been using callback type 1,
which gives you the data as first argument and action as second
argument, and you have ignored the data pointer (which you considered to
be the widget pointer).  Am I right?

I think that the action is a way of parameterising the callback.
(Someone who knows more of the intended API correct me if I'm wrong).
If you don't need this parameterisation it should be safe to ignore it.

        /mailund

--=20
A computer lets you make more mistakes faster than any invention in
human history - with the possible exceptions of handguns and tequila.

Mitch Ratcliffe, "Technology Review" (1992)

--=-6RlobYwwP2aPaCXsuL6Y
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQA7jttY+FW2bc8dyE4RAuemAJsH4O73UrLZ2+DKHHIhuN3NrmXt0QCfduZw
QPdCx8iTyDQ5IIpTo8MmeeQ=
=w6OT
-----END PGP SIGNATURE-----

--=-6RlobYwwP2aPaCXsuL6Y--




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