]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/XLyXKeySym.C
Remove all unnecessary #includes from header files.
[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
17 #include <X11/keysym.h>
18
19 using std::endl;
20
21
22 XLyXKeySym::XLyXKeySym()
23         : LyXKeySym(), keysym_(NoSymbol)
24 {
25 }
26
27
28 void XLyXKeySym::initFromKeySym(KeySym ks)
29 {
30         keysym_ = ks;
31 }
32
33
34 void XLyXKeySym::init(string const & symbolname)
35 {
36         keysym_ = XStringToKeysym(symbolname.c_str());
37         if (keysym_ == NoSymbol) {
38                 lyxerr[Debug::KBMAP]
39                         << "XLyXKeySym.C: No such keysym: "
40                         << symbolname << endl;
41         }
42 }
43
44
45 bool XLyXKeySym::isOK() const
46 {
47         return keysym_ != NoSymbol;
48 }
49
50
51 bool XLyXKeySym::isModifier() const
52 {
53         // Can we be sure that this will work for all X Window
54         // implementations? (Lgb)
55         // Perhaps all of them should be explictly mentioned?
56         return ((keysym_ >= XK_Shift_L && keysym_ <= XK_Hyper_R)
57             || keysym_ == XK_Mode_switch || keysym_ == 0x0);
58 }
59
60
61 string XLyXKeySym::getSymbolName() const
62 {
63         char * name = XKeysymToString(keysym_);
64         return name ? name : string();
65 }
66
67
68 char XLyXKeySym::getISOEncoded(string const &) const
69 {
70         if (keysym_ == NoSymbol) {
71                 return 0;
72         }
73
74         unsigned int c = keysym_;
75
76         switch (c & 0x0000FF00) {
77                 // latin 1 byte 3 = 0
78         case 0x00000000: break;
79                 // latin 2 byte 3 = 1
80         case 0x00000100:
81                 // latin 3 byte 3 = 2
82         case 0x00000200:
83                 // latin 4 byte 3 = 3
84         case 0x00000300:
85                 // cyrillic KOI8 & Co
86         case 0x00000600:
87                 // greek
88         case 0x00000700:
89                 // latin 8 byte 3 = 18 (0x12)
90         case 0x00001200:
91                 // latin 9 byte 3 = 19 (0x13)
92         case 0x00001300:
93                 c &= 0x000000FF;
94                 break;
95         default:
96                 c = 0;
97         }
98         return c;
99 }
100
101
102 bool operator==(LyXKeySym const & k1, LyXKeySym const & k2)
103 {
104         return static_cast<XLyXKeySym const &>(k1).keysym()
105                 == static_cast<XLyXKeySym const &>(k2).keysym();
106 }