]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GLyXKeySym.C
Add ShowFile dialog
[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 #include "GLyXKeySym.h"
14 #include "kbmap.h"
15
16 #include "support/lstrings.h"
17
18 #include <gtkmm.h>
19 #include <gdk/gdkkeysyms.h>
20
21 using std::string;
22
23
24 GLyXKeySym::GLyXKeySym() : keyval_(GDK_VoidSymbol)
25 {
26 }
27
28
29 GLyXKeySym::GLyXKeySym(unsigned int keyval) : keyval_(keyval)
30 {
31 }
32
33
34 void GLyXKeySym::setKeyval(unsigned int keyval)
35 {
36         keyval_ = keyval;
37 }
38
39
40 void GLyXKeySym::init(string const & symbolname)
41 {
42         keyval_ = gdk_keyval_from_name(symbolname.c_str());
43 }
44
45
46 bool GLyXKeySym::isOK() const
47 {
48         return keyval_ != GDK_VoidSymbol;
49 }
50
51
52 bool GLyXKeySym::isModifier() const
53 {
54         return ((keyval_ >= GDK_Shift_L && keyval_ <= GDK_Hyper_R)
55                 || keyval_ == GDK_Mode_switch || keyval_ == 0);
56 }
57
58
59 string GLyXKeySym::getSymbolName() const
60 {
61         const char * name = gdk_keyval_name(keyval_);
62         return name ? name : string();
63 }
64
65
66 char GLyXKeySym::getISOEncoded(string const & /*encoding*/) const
67 {
68         if (keyval_ == GDK_VoidSymbol)
69                 return 0;
70
71         unsigned int c = keyval_;
72
73         switch (c & 0x0000FF00) {
74                 // latin 1 byte 3 = 0
75         case 0x00000000: break;
76                 // latin 2 byte 3 = 1
77         case 0x00000100:
78                 // latin 3 byte 3 = 2
79         case 0x00000200:
80                 // latin 4 byte 3 = 3
81         case 0x00000300:
82                 // cyrillic KOI8 & Co
83         case 0x00000600:
84                 // greek
85         case 0x00000700:
86                 // latin 8 byte 3 = 18 (0x12)
87         case 0x00001200:
88                 // latin 9 byte 3 = 19 (0x13)
89         case 0x00001300:
90                 c &= 0x000000FF;
91                 break;
92         default:
93                 c = 0;
94         }
95         return c;
96 }
97
98
99 //Produce a human readable version (eg "Ctrl+N")
100 string const GLyXKeySym::print(key_modifier::state mod) const
101 {
102         string buf;
103
104         if (mod & key_modifier::ctrl)
105                 buf += "Ctrl+";
106         if (mod & key_modifier::shift)
107                 buf += "Shift+";
108         if (mod & key_modifier::alt)
109                 buf += "Alt+";
110
111         //Uppercase the first letter, for Ctrl+N rather than Ctrl+n,
112         //and for Ctrl+Greater rather than Ctrl+GREATER
113         string symname = getSymbolName();
114         if (!symname.empty()) {
115           symname[0] = lyx::support::uppercase(symname[0]);
116           buf += symname;
117         }
118
119         return buf;
120 }
121
122
123 bool operator==(LyXKeySym const & k1, LyXKeySym const & k2)
124 {
125         return static_cast<GLyXKeySym const &>(k1).getKeyval()
126                 == static_cast<GLyXKeySym const &>(k2).getKeyval();
127 }