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