Re: Callback signals for Custom Widgets

On Mon, Jun 13, 2005 at 12:04:42PM -0400, Michal Porzuczek wrote:
I have created my own custom widget, and I was wondering how I can
link or map GDK event types to my custom widget in particular the
key_press_event and button_press_event.

In widget's realize method: set which events its Gdk window
should receive, e.g.:

    attributes.event_mask = gtk_widget_get_events(widget);
    attributes.event_mask |= (GDK_EXPOSURE_MASK
                              | GDK_BUTTON_PRESS_MASK
                              | GDK_KEY_PRESS_MASK);
    widget->window = gdk_window_new(gtk_widget_get_parent_window(widget),
                                    &attributes, attributes_mask);

In widget's class init function: set the function that
implements particular event handlers, e.g.:

static void
my_widget_class_init(MyWidgetClass *klass)
    GtkWidgetClass *widget_class;
    widget_class = (GtkWidgetClass*)klass;
    widget_class->key_press_event = my_widget_key_press;
    widget_class->button_press_event = my_widget_button_press;

Furthermore, after a event type has been specified, say the
button_press_event, will I have to actually specify what
button_press_event should do? That this, will I have to actually
specify that button_press_event is a mouse activity or will this
automatically be done when I add the function to the my widget.

Button press event meaning is precisely defined, there's
nothing you can specify about it.  You only define *what
happens* when it occurs.

I recommend to look at existing Gtk+ widget implementation
and Event handling section in tutorial:


A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]