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