]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/panel.cpp
Add key events
[libs/gltk.git] / source / panel.cpp
index f6aad86a856d90aa0440ebb1f0634544a2b3f51b..d3e8df0c374c0f190e4da38ffb50617a588613a4 100644 (file)
@@ -7,7 +7,8 @@ namespace GLtk {
 Panel::Panel(const Resources &r):
        Widget(r),
        pointer_focus(0),
-       pointer_grab(0)
+       pointer_grab(0),
+       input_focus(0)
 {
        update_style();
 }
@@ -29,6 +30,7 @@ void Panel::button_press(int x, int y, unsigned btn)
                        {
                                (*i)->button_press(x-geom.x, y-geom.y, btn);
                                pointer_grab=btn;
+                               set_input_focus(*i);
                        }
        }
 }
@@ -79,6 +81,23 @@ void Panel::pointer_motion(int x, int y)
        }
 }
 
+void Panel::key_press(unsigned key, unsigned mod, wchar_t ch)
+{
+       if(input_focus)
+               input_focus->key_press(key, mod, ch);
+}
+
+void Panel::key_release(unsigned key, unsigned mod)
+{
+       if(input_focus)
+               input_focus->key_release(key, mod);
+}
+
+void Panel::focus_out()
+{
+       set_input_focus(0);
+}
+
 void Panel::add(Widget &wdg)
 {
        children.push_back(&wdg);
@@ -109,5 +128,19 @@ void Panel::set_pointer_focus(Widget *wdg)
        }
 }
 
+void Panel::set_input_focus(Widget *wdg)
+{
+       if(wdg!=input_focus)
+       {
+               if(input_focus)
+                       input_focus->focus_out();
+
+               input_focus=wdg;
+
+               if(input_focus)
+                       input_focus->focus_in();
+       }
+}
+
 } // namespace GLtk
 } // namespace Msp