]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/XLyXKeySym.C
whitespace
[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
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() 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 bool XLyXKeySym::operator==(LyXKeySym const & k) const
105 {
106         // This is dangerous! Ideally, we should use dynamic_cast instead,
107         // but on the other hand, we are sure that we will always get
108         // the right type, because we decide at compile time which
109         // frontend we use. (Asger)
110         return keysym == static_cast<XLyXKeySym const &>(k).keysym;
111 }