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!