RE: [gtk-list] Clicking on tables
- From: "Damon Chaplin" <DAChaplin email msn com>
- To: <gtk-list redhat com>
- Subject: RE: [gtk-list] Clicking on tables
- Date: Sun, 31 May 1998 12:19:21 +0100
> I have a table with pixmaps in each cell and I want to be able to have the
> user click on any cell and have it call a function with the coordinates of
> the cell as a parameter, however I dont know how to do this.
> Can anyone tell me how or give me an example of where its done?
I can think of two ways. Both require you to add "button_press" signals to
all the pixmaps in the table.
1) When creating the table, put the coordinates of each pixmap in its data
hash, with something like:
gtk_object_set_data(GTK_OBJECT(pixmap), "x", (gpointer) x);
gtk_object_set_data(GTK_OBJECT(pixmap), "y", (gpointer) y);
gtk_signal_connect(GTK_OBJECT (pixmap), "button_press_event",
GTK_SIGNAL_FUNC(on_button_press), NULL);
Then in the signal handler you can retrieve the coordinates with
static gint
on_button_press(GtkWidget *pixmap,
GdkEventButton *event,
gpointer data)
{
gint x, y;
x = (gint)gtk_object_get_data(GTK_OBJECT(pixmap), "x");
y = (gint)gtk_object_get_data(GTK_OBJECT(pixmap), "y");
...
2) In the signal handler, step through each of the table's children and
compare with the selected pixmap.
static gint
on_button_press(GtkWidget *pixmap,
GdkEventButton *event,
gpointer data)
{
gint x, y; GList *children;
GtkTableChild *child;
children = GTK_TABLE(table)->children;
while (children) {
child = children->data;
if (child->widget == widget) {
x = child->left_attach;
y = child->top_attach;
break;
}
children = children->next;
}
...
Damon
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]