3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "GLyXKeySym.h"
16 #include "support/lstrings.h"
19 #include <gdk/gdkkeysyms.h>
24 GLyXKeySym::GLyXKeySym() : keyval_(GDK_VoidSymbol)
29 GLyXKeySym::GLyXKeySym(unsigned int keyval) : keyval_(keyval)
34 void GLyXKeySym::setKeyval(unsigned int keyval)
40 void GLyXKeySym::init(string const & symbolname)
42 keyval_ = gdk_keyval_from_name(symbolname.c_str());
46 bool GLyXKeySym::isOK() const
48 return keyval_ != GDK_VoidSymbol;
52 bool GLyXKeySym::isModifier() const
54 return ((keyval_ >= GDK_Shift_L && keyval_ <= GDK_Hyper_R)
55 || keyval_ == GDK_Mode_switch || keyval_ == 0);
59 string GLyXKeySym::getSymbolName() const
61 const char * name = gdk_keyval_name(keyval_);
62 return name ? name : string();
66 char GLyXKeySym::getISOEncoded(string const & /*encoding*/) const
68 if (keyval_ == GDK_VoidSymbol)
71 unsigned int c = keyval_;
73 switch (c & 0x0000FF00) {
75 case 0x00000000: break;
86 // latin 8 byte 3 = 18 (0x12)
88 // latin 9 byte 3 = 19 (0x13)
99 //Produce a human readable version (eg "Ctrl+N")
100 string const GLyXKeySym::print(key_modifier::state mod) const
104 if (mod & key_modifier::ctrl)
106 if (mod & key_modifier::shift)
108 if (mod & key_modifier::alt)
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]);
123 bool operator==(LyXKeySym const & k1, LyXKeySym const & k2)
125 return static_cast<GLyXKeySym const &>(k1).getKeyval()
126 == static_cast<GLyXKeySym const &>(k2).getKeyval();