]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/XLyXKeySym.C
display key binding in native UI style
[lyx.git] / src / frontends / xforms / XLyXKeySym.C
1 /**
2  * \file XLyXKeySym.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger and Jürgen
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "XLyXKeySym.h"
14
15 #include "debug.h"
16 #include "kbmap.h"
17
18 #include <X11/keysym.h>
19
20 using std::endl;
21 using std::string;
22
23
24 XLyXKeySym::XLyXKeySym()
25         : LyXKeySym(), keysym_(NoSymbol)
26 {
27 }
28
29
30 void XLyXKeySym::initFromKeySym(KeySym ks)
31 {
32         keysym_ = ks;
33 }
34
35
36 void XLyXKeySym::init(string const & symbolname)
37 {
38         keysym_ = XStringToKeysym(symbolname.c_str());
39         if (keysym_ == NoSymbol) {
40                 lyxerr[Debug::KBMAP]
41                         << "XLyXKeySym.C: No such keysym: "
42                         << symbolname << endl;
43         }
44 }
45
46
47 bool XLyXKeySym::isOK() const
48 {
49         return keysym_ != NoSymbol;
50 }
51
52
53 bool XLyXKeySym::isModifier() const
54 {
55         // Can we be sure that this will work for all X Window
56         // implementations? (Lgb)
57         // Perhaps all of them should be explictly mentioned?
58         return ((keysym_ >= XK_Shift_L && keysym_ <= XK_Hyper_R)
59             || keysym_ == XK_Mode_switch || keysym_ == 0x0);
60 }
61
62
63 string XLyXKeySym::getSymbolName() const
64 {
65         char * name = XKeysymToString(keysym_);
66         return name ? name : string();
67 }
68
69
70 char XLyXKeySym::getISOEncoded(string const &) const
71 {
72         if (keysym_ == NoSymbol) {
73                 return 0;
74         }
75
76         unsigned int c = keysym_;
77
78         switch (c & 0x0000FF00) {
79                 // latin 1 byte 3 = 0
80         case 0x00000000: break;
81                 // latin 2 byte 3 = 1
82         case 0x00000100:
83                 // latin 3 byte 3 = 2
84         case 0x00000200:
85                 // latin 4 byte 3 = 3
86         case 0x00000300:
87                 // cyrillic KOI8 & Co
88         case 0x00000600:
89                 // greek
90         case 0x00000700:
91                 // latin 8 byte 3 = 18 (0x12)
92         case 0x00001200:
93                 // latin 9 byte 3 = 19 (0x13)
94         case 0x00001300:
95                 c &= 0x000000FF;
96                 break;
97         default:
98                 c = 0;
99         }
100         return c;
101 }
102
103
104 string const XLyXKeySym::print(key_modifier::state mod) const
105 {
106         return kb_keymap::printKeySym(*this, mod);
107 }
108
109
110 bool operator==(LyXKeySym const & k1, LyXKeySym const & k2)
111 {
112         return static_cast<XLyXKeySym const &>(k1).keysym()
113                 == static_cast<XLyXKeySym const &>(k2).keysym();
114 }