Re: on_*_event return



On Sat, 2008-01-12 at 10:02 -0500, JLM wrote:
> Some widget event handler functions return a boolean value.
> on_expose_event is one. I think the return value is supposed to tell the
> caller whether this widget handled the event or not. 

Yes:
http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-xeventsignals.html

> What exactly does it mean to handle the event?

It means that no further signal handler will be asked to handle the
event too.

> For example, I have an on_expose_event function set up for my widget
> that is subclassed from DrawingArea.

When overeriding, remember also to call the base class's implementation.
Sometimes it does something useful.
 
>  It only does something if the
> widget is realized, so I put everything in an if(is_realized()) { ... }
> block. So should I return false if the widget is not realized when this
> function is called? Or is the widget considered to handle the event, but
> it just happens to not do anything?
>
> Are there any rules of thumb for when to return true versus false in
> these cases?

I have often wondered the same thing in similar situations. I don't
think I have a general answer, but maybe someone else does. I am
generally not a fan of these signals or this technique because I think
it requires you to have a knowledge of what the default implementation
is.

But that would be the same with the more-traditional C++ technique of
override-and-sometimes-call-the-base-handler.

-- 
murrayc murrayc com
www.murrayc.com
www.openismus.com



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