2003-09-02 10:29:05 +00:00
|
|
|
/**
|
|
|
|
* \file GLyXKeySym.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Huang Ying
|
|
|
|
*
|
2003-09-02 17:02:32 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-09-02 10:29:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2004-11-16 23:18:46 +00:00
|
|
|
// Too hard to make concept checks work with this file
|
2005-01-29 15:09:14 +00:00
|
|
|
#ifdef _GLIBCXX_CONCEPT_CHECKS
|
|
|
|
#undef _GLIBCXX_CONCEPT_CHECKS
|
|
|
|
#endif
|
2004-11-16 23:18:46 +00:00
|
|
|
#ifdef _GLIBCPP_CONCEPT_CHECKS
|
|
|
|
#undef _GLIBCPP_CONCEPT_CHECKS
|
|
|
|
#endif
|
|
|
|
|
2003-09-02 10:29:05 +00:00
|
|
|
#include "GLyXKeySym.h"
|
2004-03-26 15:12:35 +00:00
|
|
|
#include "kbmap.h"
|
|
|
|
|
2004-10-02 23:21:36 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2004-09-26 18:36:07 +00:00
|
|
|
#include <gtkmm.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2003-09-02 10:29:05 +00:00
|
|
|
|
|
|
|
GLyXKeySym::GLyXKeySym() : keyval_(GDK_VoidSymbol)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GLyXKeySym::GLyXKeySym(unsigned int keyval) : keyval_(keyval)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GLyXKeySym::setKeyval(unsigned int keyval)
|
|
|
|
{
|
|
|
|
keyval_ = keyval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GLyXKeySym::init(string const & symbolname)
|
|
|
|
{
|
|
|
|
keyval_ = gdk_keyval_from_name(symbolname.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GLyXKeySym::isOK() const
|
|
|
|
{
|
|
|
|
return keyval_ != GDK_VoidSymbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GLyXKeySym::isModifier() const
|
|
|
|
{
|
|
|
|
return ((keyval_ >= GDK_Shift_L && keyval_ <= GDK_Hyper_R)
|
|
|
|
|| keyval_ == GDK_Mode_switch || keyval_ == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string GLyXKeySym::getSymbolName() const
|
|
|
|
{
|
|
|
|
const char * name = gdk_keyval_name(keyval_);
|
|
|
|
return name ? name : string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char GLyXKeySym::getISOEncoded(string const & /*encoding*/) const
|
|
|
|
{
|
|
|
|
if (keyval_ == GDK_VoidSymbol)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
unsigned int c = keyval_;
|
|
|
|
|
|
|
|
switch (c & 0x0000FF00) {
|
|
|
|
// latin 1 byte 3 = 0
|
|
|
|
case 0x00000000: break;
|
|
|
|
// latin 2 byte 3 = 1
|
|
|
|
case 0x00000100:
|
|
|
|
// latin 3 byte 3 = 2
|
|
|
|
case 0x00000200:
|
|
|
|
// latin 4 byte 3 = 3
|
|
|
|
case 0x00000300:
|
|
|
|
// cyrillic KOI8 & Co
|
|
|
|
case 0x00000600:
|
|
|
|
// greek
|
|
|
|
case 0x00000700:
|
|
|
|
// latin 8 byte 3 = 18 (0x12)
|
|
|
|
case 0x00001200:
|
|
|
|
// latin 9 byte 3 = 19 (0x13)
|
|
|
|
case 0x00001300:
|
|
|
|
c &= 0x000000FF;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
c = 0;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-10 15:10:37 +00:00
|
|
|
// Produce a human readable version (eg "Ctrl+N")
|
2004-03-26 15:12:35 +00:00
|
|
|
string const GLyXKeySym::print(key_modifier::state mod) const
|
|
|
|
{
|
2004-10-02 23:21:36 +00:00
|
|
|
string buf;
|
|
|
|
|
|
|
|
if (mod & key_modifier::ctrl)
|
|
|
|
buf += "Ctrl+";
|
|
|
|
if (mod & key_modifier::shift)
|
|
|
|
buf += "Shift+";
|
|
|
|
if (mod & key_modifier::alt)
|
|
|
|
buf += "Alt+";
|
|
|
|
|
2004-10-10 15:10:37 +00:00
|
|
|
// Uppercase the first letter, for Ctrl+N rather than Ctrl+n,
|
|
|
|
// and for Ctrl+Greater rather than Ctrl+GREATER
|
2004-10-02 23:21:36 +00:00
|
|
|
string symname = getSymbolName();
|
2004-10-05 10:11:42 +00:00
|
|
|
if (!symname.empty()) {
|
2004-10-02 23:21:36 +00:00
|
|
|
symname[0] = lyx::support::uppercase(symname[0]);
|
|
|
|
buf += symname;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
2004-03-26 15:12:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-02 10:29:05 +00:00
|
|
|
bool operator==(LyXKeySym const & k1, LyXKeySym const & k2)
|
|
|
|
{
|
|
|
|
return static_cast<GLyXKeySym const &>(k1).getKeyval()
|
|
|
|
== static_cast<GLyXKeySym const &>(k2).getKeyval();
|
|
|
|
}
|