]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GLyXKeySym.C
Change glob() API to accept a dir parameter.
[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 _GLIBCPP_CONCEPT_CHECKS
15 #undef _GLIBCPP_CONCEPT_CHECKS
16 #endif
17
18 #include "GLyXKeySym.h"
19 #include "kbmap.h"
20
21 #include "support/lstrings.h"
22
23 #include <gtkmm.h>
24 #include <gdk/gdkkeysyms.h>
25
26 using std::string;
27
28
29 GLyXKeySym::GLyXKeySym() : keyval_(GDK_VoidSymbol)
30 {
31 }
32
33
34 GLyXKeySym::GLyXKeySym(unsigned int keyval) : keyval_(keyval)
35 {
36 }
37
38
39 void GLyXKeySym::setKeyval(unsigned int keyval)
40 {
41         keyval_ = keyval;
42 }
43
44
45 void GLyXKeySym::init(string const & symbolname)
46 {
47         keyval_ = gdk_keyval_from_name(symbolname.c_str());
48 }
49
50
51 bool GLyXKeySym::isOK() const
52 {
53         return keyval_ != GDK_VoidSymbol;
54 }
55
56
57 bool GLyXKeySym::isModifier() const
58 {
59         return ((keyval_ >= GDK_Shift_L && keyval_ <= GDK_Hyper_R)
60                 || keyval_ == GDK_Mode_switch || keyval_ == 0);
61 }
62
63
64 string GLyXKeySym::getSymbolName() const
65 {
66         const char * name = gdk_keyval_name(keyval_);
67         return name ? name : string();
68 }
69
70
71 char GLyXKeySym::getISOEncoded(string const & /*encoding*/) const
72 {
73         if (keyval_ == GDK_VoidSymbol)
74                 return 0;
75
76         unsigned int c = keyval_;
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 // Produce a human readable version (eg "Ctrl+N")
105 string const GLyXKeySym::print(key_modifier::state mod) const
106 {
107         string buf;
108
109         if (mod & key_modifier::ctrl)
110                 buf += "Ctrl+";
111         if (mod & key_modifier::shift)
112                 buf += "Shift+";
113         if (mod & key_modifier::alt)
114                 buf += "Alt+";
115
116         // Uppercase the first letter, for Ctrl+N rather than Ctrl+n,
117         // and for Ctrl+Greater rather than Ctrl+GREATER
118         string symname = getSymbolName();
119         if (!symname.empty()) {
120           symname[0] = lyx::support::uppercase(symname[0]);
121           buf += symname;
122         }
123
124         return buf;
125 }
126
127
128 bool operator==(LyXKeySym const & k1, LyXKeySym const & k2)
129 {
130         return static_cast<GLyXKeySym const &>(k1).getKeyval()
131                 == static_cast<GLyXKeySym const &>(k2).getKeyval();
132 }