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