[Glade-users] extend Drawing Area class

Tristan Van Berkom tvb@gnome.org
Tue, 22 Mar 2005 14:31:07 -0500


Jeff Simpson wrote:
> I'm hoping somebody can point me in the right direction for a project
> I'm working on. Basically, I need to add a few extra functions to the
> DrawingArea object, and I'd like to use Glade / gtkmm as much as
> possible. The code needs to be in C++ due to some already existing
> functions that I'd like to not have to re-write.
> 
> Can anybody point me in the right direction for how to create a new
> custom class/object based on DrawingArea? I'd like it to have all the
> existing functions of DrawingArea (draw_line, etc) but also have a few
> customized functions. Thanks for any help!

First of all, you should read this:
     http://www.le-hacker.org/papers/gobject/
(that is; if you haven't already ;-p )

IIRC, with glade-2 or the original glade; you would treat this as
a "custom widget", you'd add it to your project and use a few generic
parameters (int 1, int 2, string 1, string 2) and a "create function"
to be looked up in the program by libglade.

I always used "string 1" to be the name of an xml file that I would
parse in my create_function() (but that's unimportant).

Note also that GtkDrawingArea is just a simple GtkWidget with its
own GdkWindow, the DrawingArea does *not* implement any "draw_line"
method or whatnot; it is the responsability of the DrawingArea user
to trap the "expose-event" signal and draw to GTK_WIDGET (darea)->window
using the GdkDrawable API.

http://developer.gnome.org/doc/API/2.0/gdk/gdk-Drawing-Primitives.html

Cheers,
                            -Tristan