]> git.tdb.fi Git - libs/gltk.git/blob - source/systemkeyboardinput.cpp
fe803a6ddd2e407abbe1cdbcadaed5ec4ce989da
[libs/gltk.git] / source / systemkeyboardinput.cpp
1 #include <msp/input/keys.h>
2 #include "root.h"
3 #include "systemkeyboardinput.h"
4
5 namespace Msp {
6 namespace GLtk {
7
8 SystemKeyboardInput::SystemKeyboardInput(Root &r, Input::Keyboard &k):
9         InputMethod(r),
10         keyboard(k)
11 {
12         keyboard.signal_button_press.connect(sigc::mem_fun(this, &SystemKeyboardInput::key_press));
13         keyboard.signal_button_release.connect(sigc::mem_fun(this, &SystemKeyboardInput::key_release));
14         keyboard.signal_character.connect(sigc::mem_fun(this, &SystemKeyboardInput::character));
15 }
16
17 bool SystemKeyboardInput::key_press(unsigned key)
18 {
19         // TODO modifiers
20         if(root.key_press(key, 0))
21                 return true;
22         
23         switch(key)
24         {
25         case Input::KEY_LEFT: return root.navigate(NAV_LEFT);
26         case Input::KEY_RIGHT: return root.navigate(NAV_RIGHT);
27         case Input::KEY_UP: return root.navigate(NAV_UP);
28         case Input::KEY_DOWN: return root.navigate(NAV_DOWN);
29         case Input::KEY_TAB: return root.navigate(NAV_NEXT);
30         case Input::KEY_SPACE: return root.navigate(NAV_ACTIVATE);
31         case Input::KEY_ENTER: return root.navigate(NAV_ACCEPT);
32         case Input::KEY_ESC: return root.navigate(NAV_CANCEL);
33         }
34
35         return false;
36 }
37
38 bool SystemKeyboardInput::key_release(unsigned key)
39 {
40         return root.key_release(key, 0);
41 }
42
43 bool SystemKeyboardInput::character(StringCodec::unichar ch)
44 {
45         return root.character(ch);
46 }
47
48 } // namespace GLtk
49 } // namespace Msp