Gtk-- Faq
(If you have suggestions of what to add to this page, let me know)
How do I compile applications with gtk-- installed?
replace all instances of $prefix from the next line with the prefix
you used with configure and it'll compile you a testme1.cc into
testme1 executable file. (this has been tested with sparc+solaris)
g++ `gtk-config --cflags` -o testme1 testme1.cc -lgtkmm `gtk-config --libs`
Is there a way to override widget's draw method?
There's virtual function table in every widget in gtk and derived
widgets can override methods in their class_init by setting function
pointers to point to new implementation. Gtk-- of course maps this to
C++'s virtual functions and thus for overriding draw method, you just
implement a method with signature(you'll find this information from
gtk-- reference):
// this is inside anything derived from Gtk_Widget
virtual void draw_impl(GdkRectangle* r)
{
/* draw with low level gdk functions */
}
But if it exists, why doesnt everyone use it?
Because there's easier way to do the same thing - in gtk and
thus also in gtk--, you can add other widgets inside almost
everything, like buttons. So there's rarely need to do it in
low level. This does not mean that it isnt possible.
How do I prevent some event from happening?
You can always override some of the *_event signal's default
implementation. This is done under gtk-- like this:
class Entry_with_numbers_only : public Gtk_Entry {
...
virtual gint key_press_event_impl(GdkEventKey* e)
{
gint retval;
if (e->keyval<GDK_0 || e->keyval>GDK_9) {
// do something, usually call virtual function
// to let derived classes trap invalid key presses
retval=0;
} else {
// do what you are doing normally.
retval=Gtk_Entry::key_press_event_impl(e);
}
return retval;
}
...
};
Note, It might be better to override changed_impl() method from Gtk_Entry
to do this. Depends of course what you want to do. Playing with low level
details is usually bad thing.
Why doesnt my expose_event handler get called?
This is because some *_events need to be enabled with
Gtk_Widget::set_events() -call. The flags needed for set_events()
can be found from gdktypes.h/GdkEventMask. For example:
...
set_events(get_events()|GDK_EXPOSURE_MASK);
...
Tero Pulkkinen (terop@modeemi.cs.tut.fi)