]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GLyXKeySym.C
some tabular fixes for the problems reported by Helge
[lyx.git] / src / frontends / gtk / GLyXKeySym.C
1 /**
2  * \file GLyXKeySym.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Huang Ying
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "GLyXKeySym.h"
22 #include "kbmap.h"
23
24 #include "support/lstrings.h"
25
26 #include <gtkmm.h>
27 #include <gdk/gdkkeysyms.h>
28
29 using std::string;
30
31
32 GLyXKeySym::GLyXKeySym() : keyval_(GDK_VoidSymbol)
33 {
34 }
35
36
37 GLyXKeySym::GLyXKeySym(unsigned int keyval) : keyval_(keyval)
38 {
39 }
40
41
42 void GLyXKeySym::setKeyval(unsigned int keyval)
43 {
44         keyval_ = keyval;
45 }
46
47
48 void GLyXKeySym::init(string const & symbolname)
49 {
50         keyval_ = gdk_keyval_from_name(symbolname.c_str());
51 }
52
53
54 bool GLyXKeySym::isOK() const
55 {
56         return keyval_ != GDK_VoidSymbol;
57 }
58
59
60 bool GLyXKeySym::isModifier() const
61 {
62         return ((keyval_ >= GDK_Shift_L && keyval_ <= GDK_Hyper_R)
63                 || keyval_ == GDK_Mode_switch || keyval_ == 0);
64 }
65
66
67 string GLyXKeySym::getSymbolName() const
68 {
69         const char * name = gdk_keyval_name(keyval_);
70         return name ? name : string();
71 }
72
73
74 char GLyXKeySym::getISOEncoded(string const & /*encoding*/) const
75 {
76         if (keyval_ == GDK_VoidSymbol)
77                 return 0;
78
79         unsigned int c = keyval_;
80
81         switch (c & 0x0000FF00) {
82                 // latin 1 byte 3 = 0
83         case 0x00000000: break;
84                 // latin 2 byte 3 = 1
85         case 0x00000100:
86                 // latin 3 byte 3 = 2
87         case 0x00000200:
88                 // latin 4 byte 3 = 3
89         case 0x00000300:
90                 // cyrillic KOI8 & Co
91         case 0x00000600:
92                 // greek
93         case 0x00000700:
94                 // latin 8 byte 3 = 18 (0x12)
95         case 0x00001200:
96                 // latin 9 byte 3 = 19 (0x13)
97         case 0x00001300:
98                 c &= 0x000000FF;
99                 break;
100         default:
101                 c = 0;
102         }
103         return c;
104 }
105
106
107 // Produce a human readable version (eg "Ctrl+N")
108 string const GLyXKeySym::print(key_modifier::state mod) const
109 {
110         string buf;
111
112         if (mod & key_modifier::ctrl)
113                 buf += "Ctrl+";
114         if (mod & key_modifier::shift)
115                 buf += "Shift+";
116         if (mod & key_modifier::alt)
117                 buf += "Alt+";
118
119         // Uppercase the first letter, for Ctrl+N rather than Ctrl+n,
120         // and for Ctrl+Greater rather than Ctrl+GREATER
121         string symname = getSymbolName();
122         if (!symname.empty()) {
123           symname[0] = lyx::support::uppercase(symname[0]);
124           buf += symname;
125         }
126
127         return buf;
128 }
129
130
131 bool operator==(LyXKeySym const & k1, LyXKeySym const & k2)
132 {
133         return static_cast<GLyXKeySym const &>(k1).getKeyval()
134                 == static_cast<GLyXKeySym const &>(k2).getKeyval();
135 }