Re: Naive questions #3




nelson-gtk@crynwr.com writes:

> Why does gtk_event_box_expose override gtk_bin_expose?

No reason I can see. It looks line-by-line identical. I suspect
I thought I needed it when I started writing the widget, and
never looked closely enough to see that it could be removed.
 
> Oughtn't gtk_bin_draw have this check:
>   g_return_if_fail (area != NULL);
> just like gtk_event_box_draw has?

That isn't really necessary. gtk_bin_draw() will be only ever called
from gtk_widget_draw() which does something like

  if (event->area == NULL)
    [ set event->area to widget->allocation ]

But there is a problem with the current gtk_eventbox_draw (which is
in effect identical to gtk_widget_draw()) :

For widgets with a window; the area passed to gtk_widget_draw() is
relative to the allocation of the widget, not too the widget's
window. But for the eventbox, widget->window may be smaller than the
allocation if the widget has a border.

So the current gtk_eventbox_draw() is incorrect. In needs to
look like:

======
static void
gtk_event_box_draw (GtkWidget    *widget,
		   GdkRectangle *area)
{
  GtkBin *bin;
  GdkRectangle tmp_area;

  GdkRectangle child_area;

  g_return_if_fail (widget != NULL);
  g_return_if_fail (GTK_IS_EVENT_BOX (widget));

  if (GTK_WIDGET_DRAWABLE (widget))
    {
      bin = GTK_BIN (widget);
      tmp_area = *area;
      tmp_area.x -= GTK_CONTAINER (widget)->border_width;
      tmp_area.y -= GTK_CONTAINER (widget)->border_width;
      
      if (bin->child)
	{
	  if (gtk_widget_intersect (bin->child, &tmp_area, &child_area))
	    gtk_widget_draw (bin->child, &child_area);
	}
    }
}
=======

This wasn't much if a problem in practice, since gtk_widget_draw()
seldom gets called with an area other than NULL (except for the
Viewport widget's children), and for area=NULL, it works out OK,
because it is just too large, and intersecting with the child widget
fixes things.

This problem is not confined to this widget. A quick check reveals
the Frame widget suffers from the same problem. Looks like there
is some fixing to do...
 
> Why doesn't gtk_bin_draw use this test:
>   /var/spool/fax/incoming/ff50763cdS0.01
> just like gtk_event_box_draw?

Hmmm, interesting code ;-)

I think you mean GTK_WIDGET_DRAWABLE (widget).

No good reason - I think gtk_bin_draw() may have been written 
before GTK_WIDGET_DRAWABLE. (Which is defined to be the 
  GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)
)

Thanks for the questions!
                                        Owen





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