Re: Redundant code in gtk_propagate_event()
- From: Owen Taylor <otaylor redhat com>
- To: "Padraig O'Briain" <Padraig Obriain Sun COM>
- Cc: gtk-devel-list gnome org
- Subject: Re: Redundant code in gtk_propagate_event()
- Date: 04 Oct 2001 08:09:13 -0400
"Padraig O'Briain" <Padraig Obriain Sun COM> writes:
> While looking at the the code of gtk_propagate_event() I noticed what looks like 
> redundant code.
> 
> Ok to commit?
> 
> --- gtkmain.c   2001/09/21 19:58:35     1.176
> +++ gtkmain.c   2001/10/04 08:24:42
> @@ -1724,12 +1724,8 @@ gtk_propagate_event (GtkWidget *widget,
>           
>           if (!handled_event)
>             {
> -             window = gtk_widget_get_toplevel (widget);
> -             if (window && GTK_IS_WINDOW (window))
> -               {
> -                 if (GTK_WIDGET_IS_SENSITIVE (window))
> -                   gtk_widget_event (window, event);
> -               }
> +               if (GTK_WIDGET_IS_SENSITIVE (window))
> +                 gtk_widget_event (window, event);
>             }
>                   
>           handled_event = TRUE; /* don't send to widget */
Why do you think this is redundant code? Well, you could
simplify to:
   window = gtk_widget_get_toplevel (widget);
   if (GTK_IS_WINDOW (window))
     {
     }
Since get_toplevel() never returns NULL for valid arguments;
but the GTK_IS_WINDOW() check is needed; in various 
pathological cases you can have widgets that receive events
where the toplevel widget is not GtkWindow. Those would
mostly be:
 - Someone called gtk_propagate_event() directly.
 - A widget was force-realized via gtk_widget_realize()
   while anchored.
Both of those are programmer errors .... but still, I think
it's worth having this check to get a bit of extra safety.
Regards,
                                        Owen
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]