Re: drawing_area->window != NULL



Your expose_event handler is of the wrong prototype.
If you look at the RDP for GtkWidget you'll see the
correct prototype:

"expose-event"
            gboolean    user_function      (GtkWidget *widget,
                                            GdkEventExpose *event,
                                            gpointer user_data);

The first field is supplied by GTK+ and is the widget causing
the function to be invoked.  Your data comes through the
third field... In your second (working) piece of code, you attach
the signal to the drawing area widget.  When
on_gtk_newlabel_expose_event is invoked, GTK+ Kindly supplies the
widget that caused the function to be invoked as the first argument
(i.e. your drawing area received an expose event).  Your data would appear
in the third parameter (which you don't have).  So, by coincidence,
it works when you send the same info that GTK+ is supplying :-)

In looking back through the archives (because I'm behind and wanted to be
sure no one else already answered this...) it looks as though Esteban
Quijano Vincenzi addressed this quite well in his response to your
newbie question on Monday....  It also looks like you're making great
strides
each day, so perhaps you already figured all this out!

HTH,
Donna

----- Original Message -----
From: "Andrés Giraldo" <andres_giraldo yahoo com>
To: "Gtk List" <gtk-list gnome org>
Sent: Tuesday, June 12, 2001 1:35 PM
Subject: Re: drawing_area->window != NULL


> Thanks for your help...
>
> Ok I've got it! The window is not realized yet, so I
> put the drawing code in the expose_event function,
> but...
>
> It only works if I connect the expose event signal to
> the drawing_area member, not if I connect it to the
> entire structure... why?
>
> This is using the entire structure (That's how I want
> it). It doesn't work...
>
>
> /*****************************************************/
>
> typedef struct _GtkNewLabel GtkNewLabel;
>
> struct _GtkNewLabel
>   {
>     GtkVBox vbox;
>
>     GtkWidget *drawing_area;
>   };
>
> static void gtk_newlabel_init (GtkNewLabel *newlabel)
>   {
>     GtkWidget *table;
>
>     table = gtk_table_new (1, 1, TRUE);
>     gtk_container_add (GTK_CONTAINER (newlabel),
> table);
>     gtk_widget_show (table);
>
>     newlabel->drawing_area = gtk_drawing_area_new ();
>     gtk_table_attach_defaults (GTK_TABLE(table),
> newlabel->drawing_area, 0, 1, 0, 1);
>
>     gtk_widget_show (GTK_WIDGET (newlabel));
>
>     gtk_signal_connect(GTK_OBJECT (newlabel),
> "expose_event",
>                        GTK_SIGNAL_FUNC
> (on_gtk_newlabel_expose_event), &newlabel);
>   }
>
> void on_gtk_newlabel_expose_event (GtkNewLabel
> *newlabel)
>   {
>     GdkGC *gc_back, *gc_fore;
>     GdkDrawable *drawable;
>
>     drawable = newlabel->drawing_area->window;
>
>     gc_back = GetPen (NewColor (newlabel->back_red,
> newlabel->back_green,
>                                 newlabel->back_blue),
> drawable);
>   }
>
>
> GdkGC *GetPen (GdkColor *c, GdkDrawable *drawable)
>   {
>     GdkGC *gc;
>
>     gc = gdk_gc_new (drawable);
>
>     gdk_gc_set_foreground (gc, c);
>
>     return (gc);
>   }
>
> GdkColor *NewColor (long red, long green, long blue)
>   {
>     GdkColor *c = (GdkColor *) g_malloc (sizeof
> (GdkColor));
>
>     c->red = red;
>     c->green = green;
>     c->blue = blue;
>
>     gdk_color_alloc (gdk_colormap_get_system (), c);
>
>     return (c);
>   }
>
> /*****************************************************/
>
> And this is using the drawing_area member, It Works...
>
>
>
> static void gtk_newlabel_init (GtkNewLabel *newlabel)
>   {
>     GtkWidget *table;
>
>     table = gtk_table_new (1, 1, TRUE);
>     gtk_container_add (GTK_CONTAINER (newlabel),
> table);
>     gtk_widget_show (table);
>
>     newlabel->drawing_area = gtk_drawing_area_new ();
>     gtk_table_attach_defaults (GTK_TABLE(table),
> newlabel->drawing_area, 0, 1, 0, 1);
>
>     gtk_widget_show (newlabel->drawing_area);
>
>     gtk_signal_connect(GTK_OBJECT
> (newlabel->drawing_area), "expose_event",
>                        GTK_SIGNAL_FUNC
> (on_gtk_newlabel_expose_event), NULL);
>   }
>
> void on_gtk_newlabel_expose_event (gpointer data)
>   {
>     GdkGC *gc_back, *gc_fore;
>     GdkDrawable *drawable = GTK_WIDGET(data)->window;
>
>     drawable = newlabel->drawing_area->window;
>
>     gc_back = GetPen (NewColor (newlabel->back_red,
> newlabel->back_green,
>                                 newlabel->back_blue),
> drawable);
>   }
>
> So... what I'm doing wrong?
>
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail - only $35
> a year!  http://personal.mail.yahoo.com/
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>





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