Re: Handling events in custom widgets
- From: Clive Hobson <clivetown-dev01 yahoo com au>
- To: Teodosiy Kirilov <tdik123 googlemail com>
- Cc: gtkmm-list gnome org
- Subject: Re: Handling events in custom widgets
- Date: Sun, 29 Jun 2008 02:32:06 -0700 (PDT)
Sorry for the delayed response...
> From: Teodosiy Kirilov <tdik123 googlemail com>
> Sent: Tuesday, 24 June, 2008 2:17:45 AM
> Subject: Re: Handling events in custom widgets
>
> On Mon, Jun 23, 2008 at 2:31 PM, Clive Hobson wrote:
> > ...
> > Alternatively, you can derive from a widget that already creates a Gdk/X
> window and use add_events()/set_events(). The tutorial section you mentioned
> (http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-custom-widgets.html)
> has the code in on_realize() to create the window and set it for the widget.
>
> That's the first thing I did (inherited from DrawingArea). But then
> for some reasons I decided to inherit from Gtk::Widget and create the
> underlying window myself.
> I've created the window with the values from the tutorial example and
> m_refGdkWindow = Gdk::Window::create(get_parent_window(),
> &attributes, GDK_WA_X | GDK_WA_Y);
> m_refGdkWindow->set_events(Gdk::EXPOSURE_MASK | Gdk::BUTTON_PRESS_MASK
> | Gdk::KEY_PRESS_MASK |
> Gdk::ENTER_NOTIFY_MASK );
> unset_flags(Gtk::NO_WINDOW);
> set_window(m_refGdkWindow);
>
> also tried calling Gtk::Widget::add_events(), setting window class and
> other things but with no success. So probably there is something
> missing...
I ran into a similar problem (events didn't arrive) when inheriting from Gtk::Bin, but didn't investigate further because for other reasons I changed to using a child widget for drawing/events and had the child inherit from Gtk::DrawingArea.
>
> Anyway, when I'm inheriting from DrawingArea, everything works as
> expected - the event-handlers like e.g on_motion_notify() are
> triggered. I had to set the CAN_FOCUS flag and put a "grab_focus()" in
> on_enter_notify_event in order to handle keyboard input within the
> hovered widget, but I guess there is no easier way... I even got rid
> of my earlyer problem by disabling the double buffering of the widget
> (...).
[small aside]: It might annoy people who prefer click-to-focus if your widget takes keyboard focus every time the mouse enters.
>
> But it's still interesting to know:
> What do I need to do to convert something that inherits from
> DrawingArea to something only inheriting from Widget, preserving all
> functionality.
[snip]
Sorry, I can't help with an explanation. However, I think that's the whole point of Gtk::DrawingArea - to be a Gtk::Widget with convenient access to events and drawing.
Regards,
Clive
Get the name you always wanted with the new y7mail email address.
www.yahoo7.com.au/mail
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]