On Tue, May 30, 2006 at 10:43:33AM +0200, Daniel Haude wrote: > say I have a table filled with some widgets. Now I'd like to replace one > of these widgets (A) with some other widget B. I guess I just go ahead and > destroy widget A, and then attach widget B. My problem is that in order to > do that, I need to know the position (row and column) that A had within > the table. > > To put the question simpler: Given a table and a widget within the table > (or box), how can I find the position of the widget within the table (or > box)?
To remember where you put it is usually the best solution. You can also use something like the attached function (for tables). Note however, it accesses the private `children' field of GtkTable. In the case of boxes the field is public (read-only), but you have to deal with start-packing and end-packing. Yeti -- Anonyms eat their boogers. ======================================================================= /** * gwy_table_get_child_widget: * @table: A #GtkTable. * @row: Row in @table. * @col: Column in @table. * * Finds a widget in #GtkTable by its coordinates. * * Coordinates (@col, @row) are taken as coordinates of widget top left corner. * More precisely, the returned widget either contains the specified grid * point or it is attached by its left side, top side, or top left corner to * this point. * * If there are multiple matches due to overlapping widgets, a random * match is returned. * * Returns: The widget at (@col, @row) or %NULL if there is no such widget. **/ GtkWidget* gwy_table_get_child_widget(GtkWidget *table, gint row, gint col) { GList *l; g_return_val_if_fail(GTK_IS_TABLE(table), NULL); for (l = GTK_TABLE(table)->children; l; l = g_list_next(l)) { GtkTableChild *child = (GtkTableChild*)l->data; if (child->left_attach <= col && child->right_attach > col && child->top_attach <= row && child->bottom_attach > row) return child->widget; } return NULL; } _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list