]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/systemkeyboardinput.cpp
Only pass key and navigation events to enabled widgets
[libs/gltk.git] / source / systemkeyboardinput.cpp
index cedddd1817d170b21c6f34eb3ac7fec07d3951ec..f5657bd7d49066d4c854279bfbfde8705ddbd55a 100644 (file)
@@ -16,21 +16,42 @@ SystemKeyboardInput::SystemKeyboardInput(Root &r, Input::Keyboard &k):
 
 bool SystemKeyboardInput::key_press(unsigned key)
 {
+       if(!root.is_visible())
+               return false;
+
        // TODO modifiers
        if(root.key_press(key, 0))
                return true;
        
+       switch(key)
+       {
+       case Input::KEY_LEFT: return root.navigate(NAV_LEFT);
+       case Input::KEY_RIGHT: return root.navigate(NAV_RIGHT);
+       case Input::KEY_UP: return root.navigate(NAV_UP);
+       case Input::KEY_DOWN: return root.navigate(NAV_DOWN);
+       case Input::KEY_TAB: return root.navigate(NAV_NEXT);
+       case Input::KEY_SPACE: return root.navigate(NAV_ACTIVATE);
+       case Input::KEY_ENTER: return root.navigate(NAV_ACCEPT);
+       case Input::KEY_ESC: return root.navigate(NAV_CANCEL);
+       }
+
        return false;
 }
 
 bool SystemKeyboardInput::key_release(unsigned key)
 {
-       return root.key_release(key, 0);
+       if(root.is_visible())
+               return root.key_release(key, 0);
+       else
+               return false;
 }
 
 bool SystemKeyboardInput::character(StringCodec::unichar ch)
 {
-       return root.character(ch);
+       if(root.is_visible())
+               return root.character(ch);
+       else
+               return false;
 }
 
 } // namespace GLtk