Re: gtk_widget_get_allocation



Cody Russell wrote:
On Thu, 2008-09-25 at 02:02 +0200, Christian Dywan wrote:
     * gtk_widget_get_allocation
       Removed in 2.14.1
The prototype of this function was not agreed upon among the core
developers. So the decision was deferred to the next Gtk version.
It had to be removed before final API freeze, otherwise it could not
have been changed anymore.

This is rather old, but it never came up again after this so I'd like to
see what thoughts are about how to implement this in C.  It was in 2.13
but removed before 2.14 because of disagreement, but I can't find any
public record of the disagreement in gtk-devel-list.  Can anyone comment
on what was not liked, or how a better implementation could be made?

For reference, this is the previous implementation:

GtkAllocation
gtk_widget_get_allocation (GtkWidget *widget)
{
  static GtkAllocation allocation = { 0 };
  g_return_val_if_fail (GTK_IS_WIDGET (widget), allocation);

  return widget->allocation;
}

I assume the issue was with returning a non-primitive type by-value and not as a pointer. For modern compilers this isn't a big deal, I don't think (but might be inefficient on some arches), but I imagine people want to compile gtk on all sorts of systems. An implementation like this avoids that problem, though perhaps isn't as nice to use[1]:

void
gtk_widget_get_allocation (GtkWidget     *widget,
                           GtkAllocation *allocation)
{
    g_return_if_fail (GTK_IS_WIDGET (widget) && allocation);

    memcpy (allocation, &widget->allocation, sizeof(*allocation));
}

(Could also have it return gboolean, but I tend to think it's unnecessary to have a success/fail return value when the only reason it would fail is if the programmer is using the function incorrectly.)

This seems to be a similar pattern to how other things like this are done in gtk...

	-brian

[1] I guess part of the motivation for the original (rejected) implementation is so that you can do things like this:

gint width = gtk_widget_get_allocation (widget).width;

Oh well.


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