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