Re: Button from an image (round Button)



2008/2/29 Demetris Zavorotnichenko <fgcity4652 cytanet com cy>:
>
> I want to create a keypad with 34 buttons
>
> So I create the buttons in a loop.
>
> And assign a callback function to the button
>
> But I have only 1 callback function and 34 buttons so how do I know which
> button has been pressed in that callback ?

The buttons are normal GObject so you can attach any piece of user
data to them with:

g_object_set_data (G_OBJECT (button), "button_id", GINT_TO_POINTER (button_id));

assuming button_id identifies your particular button among the 34.

GINT_TO_POINTER is here to fit the integer in a pointer value, which
this function expect.

Then in the callback handler you can retrieve the button ID like this:

button_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
"button_id"));

Hope this helps.

cheers, Christophe.


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