GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Oct 21, 2014 9:37 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [Solved] error in gtk3 GtkWidget documentation
PostPosted: Thu Aug 23, 2012 3:38 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
I'm converting over my code from gtk2 to gtk3 and one major part of it is a custom widget. Online documentation for making one was quite extensive for gtk2 so though it was a complex process there were very good guides available. My main hassle is converting over the expose_event handler to the draw handler. Again examples abounded for gtk2 but I can't find much assistance in gtk3 andit doesn't help that the documentation contains a few mistakes. Does anyone know of a good example to follow for converting an expose_event handler?.

The draw signal states that the callback is of the form gboolean (* draw) (GtkWidget *widget, cairo_t *cr); (http://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidgetClass) yet later on describes it as gboolean user_function (GtkWidget *widget, CairoContext *cr, gpointer user_data): Run Last (http://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-draw).
This latter description I know is wrong as on compilation you get the error: error: unknown type name 'CairoContext', however I can't even get the former to work:
Code:
static gboolean gtk_plot_linear_draw(GtkWidget *widget, cairo_t *cr, gpointer data)
{
   draw(widget, cr);
   drawz(widget, cr);
   return FALSE;
}

static void gtk_plot_linear_class_init(GtkPlotLinearClass *klass)
{
   GtkWidgetClass *widget_klass;

   widget_klass=GTK_WIDGET_CLASS(klass);
   ...
   (widget_klass->draw)=gtk_plot_linear_draw;
}

This gives the warning for the (widget_klass->draw) line:
warning: assignment from incompatible pointer type [enabled by default]
True it is only a warning, but it's indicative of something being wrong.
There are other signal handlers I override without any trouble. Just wondering if there's anything else in the documentation that might be erroneous or that my approach is wrong and something is missing.

btw my gtk2 code was:
Code:
static gboolean gtk_plot_linear_expose(GtkWidget *widget, GdkEventExpose *event)
{
   cairo_t *cr;

   cr=gdk_cairo_create(gtk_widget_get_window(widget));
   cairo_rectangle(cr, event->area.x, event->area.y, event->area.width, event->area.height);
   cairo_clip(cr);
   draw(widget, cr);
   drawz(widget, cr);
   cairo_destroy(cr);
   return FALSE;
}

static void gtk_plot_linear_class_init(GtkPlotLinearClass *klass)
{
   GtkWidgetClass *widget_klass;

   widget_klass=GTK_WIDGET_CLASS(klass);
   ...
   (widget_klass->expose_event)=gtk_plot_linear_expose;
}

Thanks!


Last edited by Paul Childs on Thu Aug 23, 2012 11:31 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: error in gtk3 GtkWidget documentation
PostPosted: Thu Aug 23, 2012 5:45 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

Converting GtkWidget::expose-event handler to GtkWidget::draw handler should really not be that difficult, since you already use cairo to do the drawing. As a matter of fact, your draw handler is actually correct, the only thing you got wrong is function header, which should be:
Code:
static gboolean gtk_plot_linear_draw(GtkWidget *widget, cairo_t *cr)


Now to explain some of the troubles you're having. CairoContext is (from user perspective) simply a typedef for cairo_t (but properly registered with GType type system), so you can use any of them. As for conflicting callback prototypes, all signal handlers have always had two different prototypes: one with gpointer user_data as last parameter and one without it. The first version is used when one is connecting to this signal using g_signal_connect() macro and the second one is used when directly overriding virtual function in derived widget.

Hope this helps,
Tadej


Top
 Profile  
 
 Post subject: SOLVED: error in gtk3 GtkWidget documentation
PostPosted: Thu Aug 23, 2012 11:24 am 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Excellent that seems to do the trick and the warnings gone too. Not used to warnings not being that big a deal like leaving on a unused pointer that shouldn't be there. Anyway that seems to be the last thing that is inhibiting packaging it in the gtk version. Just need to do some testing and refinement for a bit.
Many thanks,
hopefully I can figure out how to change the post to say SOLVED too.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group