Your event handlers can't be part of a C++ class. In fact, you have to link them as C code since this is what gtk expects.
Best thing to do is put event handlers in their own file, and compile that file as a C file, and refer to it from C++ using the extern "C" macro.
Thus, create a file sighandlers.c which contains, for instance,
Code:
G_MODULE_EXPORT void on_drawingarea1_expose_event( GtkWidget *widget, GdkEventExpose *event )
{
drawarea_expose_event(widget,event);
}
Then in the sighandlers.h file, put this code:
Code:
extern "C" {
void on_drawingarea1_expose_event( GtkWidget *widget, GdkEventExpose *event );
}
and include sighandlers.h in your main file.
I should note that you'll probably also need an on_configure_event handler as well as the on_expose_event handler for your drawing area updates.
Now, in the particular example I just gave, the function drawarea_expose_event() is another C function, kept in another C file (which I call cmd_button_handlers.c), and it looks like this:
Code:
gboolean drawarea_expose_event(GtkWidget *widget, GdkEventExpose *event)
{
draw_drawingarea_drawable(widget,event);
return FALSE;
}
and draw_drawingarea_drawable() is a routine kept in a C++ file that looks like this:
Code:
void draw_drawingarea_drawable(GtkWidget *object,GdkEventExpose *event)
{
drawing_area* da=get_drawing_area_object(object);
da->draw_drawable(event);
}
which is obviously C++ code referring to the drawing_area class which I wrote for this application.
When you make this, you need something that looks like this (only a partial makefile):
Code:
GTKLIBS= -export-dynamic -lgthread-2.0 `pkg-config --libs gtkmm-2.4` `pkg-config --libs gtk+-2.0`
OBJFILES= commander.o cmd_parser.o main_window.o requesters.o requester_base.o sighandlers.o tcp_connect.o cmd_button_handlers.o commander_classes.o drawing_area.o libunp.a
commander: $(OBJFILES)
$(CXX) -o commander $(GTKLIBS) $(OBJFILES)
sighandlers.o:
$(CC) -o $@ $(CFLAGS) -c sighandlers.c
tcp_connect.o:
$(CC) -o $@ $(CFLAGS) -c tcp_connect.c
cmd_button_handlers.o
$(CC) -o $@ $(CFLAGS) -c cmd_button_handlers.c