Steve Maas wrote:
> Hi,
> 
> I've been trying to figure out how to modify the decorations of a window 
> depending on whether a child widget has the focus or not. If you have VS2009 
> you may have noticed that the title bar color of the currently active window 
> changes. This is what I am trying to emulate. Below is what I've tried so 
> far, but it doesn't work and I'm not sure why.
> 
> class MyWindow : public Fl_Group

This is strange. Why do you derive from Fl_Group (and not Fl_Window) ?

> {
>   // some stuff ...
>   int handle(int nevent);
> };
> 
> int MyWindow::handle(int nevent)
> {
>   int nret = Fl_Group::handle(nevent);
> 
>   switch (nevent)
>   {
>     case FL_FOCUS:

FL_FOCUS is used to ask if a widget is willing or capable to take the focus 
[1]. 
It doesn't mean that a widget gets or has the focus.

And the widget that gets the FL_FOCUS event will probably be selected by other 
means, e.g. by a mouse click or by pressing the TAB key, when another widget 
has 
the focus. This will "shortcut" your MyWindow::handle() method, and therefore 
your window/group won't get FL_FOCUS events in most cases.

>        if (nret == 1)
>        {
>           // change decorations to indicate a child has the focus
>        }
>        break;
>     case FL_UNFOCUS:
>        // change decorations to indicate a child does not have the focus

This wouldn't work, too. The FL_UNFOCUS event goes directly to the Fl::focus() 
widget, not to any parent group.

>        break;
>   }
> 
>   return nret;
> }
> 
> It seems that the code never reaches the if-statement and I don't understand 
> why. I hope my explanation is clear enough. Any advice on why this is not 
> working or any alternative suggestions how to solve this problem would be 
> greatly appreciated.

You could try something like:

   if (Fl::focus() && [ this-> ] contains(Fl::focus())) {

      // change decorations to indicate a child has the focus

   } else {

      // change decorations to indicate a child does not have the focus
   }

but you would need to do this "somewhere" else, and I don't know where this 
place should be. Maybe when handling FL_MOVE events or ...

Your window class should also keep track of the last state to avoid changing 
decorations, if the focus didn't change.

Another way would be to derive your own classes for all widgets inside the 
window or group. Then they could all signal their FL_FOCUS events to their 
parent group or window, if they know that their parent window knows how to 
handle it, e.g.

MyWidget::handle(int event) {

...

   case FL_FOCUS:
     take_focus();
     ((MyWindow *)window())->child_has_focus(this);
     return 1;
...
}

or something like that.

Maybe someone else has a better idea?

Albrecht

[1] http://www.fltk.org/doc-1.1/events.html
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to