2000-02-04 09:38:32 +00:00
|
|
|
/* This file is part of
|
2001-11-30 13:25:38 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
2000-02-04 09:38:32 +00:00
|
|
|
* LyX, The Document Processor
|
2001-11-30 13:25:38 +00:00
|
|
|
*
|
2000-02-04 09:38:32 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
2000-02-04 09:38:32 +00:00
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#include <config.h>
|
2001-05-31 02:23:46 +00:00
|
|
|
//#include <cstring>
|
2000-02-04 09:38:32 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "kbsequence.h"
|
|
|
|
#include "kbmap.h"
|
2002-01-12 20:00:47 +00:00
|
|
|
#include "commandtags.h"
|
2000-02-04 09:38:32 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
|
|
using std::vector;
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::hex;
|
|
|
|
using std::dec;
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
// The only modifiers that we handle. We want to throw away things
|
2001-11-30 13:25:38 +00:00
|
|
|
// like NumLock.
|
2000-02-04 09:38:32 +00:00
|
|
|
enum { ModsMask = ShiftMask | ControlMask | Mod1Mask };
|
|
|
|
|
|
|
|
|
2002-01-12 20:00:47 +00:00
|
|
|
int kb_sequence::addkey(unsigned int key, unsigned int mod, unsigned int nmod)
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
2001-11-30 13:25:38 +00:00
|
|
|
// adding a key to a deleted sequence
|
|
|
|
// starts a new sequence
|
|
|
|
if (deleted_) {
|
|
|
|
deleted_ = false;
|
|
|
|
length_ = 0;
|
2000-11-15 14:53:04 +00:00
|
|
|
sequence.clear();
|
|
|
|
modifiers.clear();
|
|
|
|
}
|
2000-11-17 00:07:41 +00:00
|
|
|
|
2001-12-10 15:59:20 +00:00
|
|
|
modifiers.push_back(mod + (nmod << 16));
|
2000-11-15 14:53:04 +00:00
|
|
|
sequence.push_back(key);
|
2001-11-30 13:25:38 +00:00
|
|
|
++length_;
|
2000-11-17 00:07:41 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
if (curmap) {
|
2000-02-04 09:38:32 +00:00
|
|
|
return curmap->lookup(key, mod, this);
|
2001-11-30 13:25:38 +00:00
|
|
|
}
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
return LFUN_UNKNOWN_ACTION;
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-01 15:31:59 +00:00
|
|
|
string::size_type kb_sequence::parse(string const & s)
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
2000-11-04 10:00:12 +00:00
|
|
|
if (s.empty()) return 1;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
string::size_type i = 0;
|
2001-11-30 13:25:38 +00:00
|
|
|
unsigned int mod = 0;
|
2001-12-10 15:59:20 +00:00
|
|
|
unsigned int nmod = 0;
|
2000-09-14 17:53:12 +00:00
|
|
|
while (i < s.length()) {
|
2001-11-14 11:31:14 +00:00
|
|
|
if (s[i] == ' ')
|
|
|
|
++i;
|
|
|
|
if (i >= s.length())
|
|
|
|
break;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
if (i + 1 < s.length() && s[i + 1] == '-') {
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (s[i]) {
|
2000-02-04 09:38:32 +00:00
|
|
|
case 's': case 'S':
|
|
|
|
mod |= ShiftMask;
|
|
|
|
i += 2;
|
|
|
|
continue;
|
|
|
|
case 'c': case 'C':
|
|
|
|
mod |= ControlMask;
|
|
|
|
i += 2;
|
|
|
|
continue;
|
|
|
|
case 'm': case 'M':
|
|
|
|
mod |= Mod1Mask;
|
|
|
|
i += 2;
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
return i + 1;
|
|
|
|
}
|
2001-05-29 14:16:39 +00:00
|
|
|
} else if (i + 2 < s.length() && s[i] == '~'
|
|
|
|
&& s[i + 2] == '-') {
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (s[i + 1]) {
|
2000-02-04 09:38:32 +00:00
|
|
|
case 's': case 'S':
|
2001-12-10 15:59:20 +00:00
|
|
|
nmod |= ShiftMask;
|
2000-02-04 09:38:32 +00:00
|
|
|
i += 3;
|
|
|
|
continue;
|
|
|
|
case 'c': case 'C':
|
2001-12-10 15:59:20 +00:00
|
|
|
nmod |= ControlMask;
|
2000-02-04 09:38:32 +00:00
|
|
|
i += 3;
|
|
|
|
continue;
|
|
|
|
case 'm': case 'M':
|
2001-12-10 15:59:20 +00:00
|
|
|
nmod |= Mod1Mask;
|
2000-02-04 09:38:32 +00:00
|
|
|
i += 3;
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
return i + 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
string tbuf;
|
2000-09-26 13:54:57 +00:00
|
|
|
string::size_type j = i;
|
2001-11-14 11:31:14 +00:00
|
|
|
for (; j < s.length() && s[j] != ' '; ++j)
|
2000-02-04 09:38:32 +00:00
|
|
|
tbuf += s[j]; // (!!!check bounds :-)
|
|
|
|
|
|
|
|
KeySym key = XStringToKeysym(tbuf.c_str());
|
2000-11-04 10:00:12 +00:00
|
|
|
if (key == NoSymbol) {
|
2000-02-04 09:38:32 +00:00
|
|
|
lyxerr[Debug::KBMAP]
|
|
|
|
<< "kbmap.C: No such keysym: "
|
|
|
|
<< tbuf << endl;
|
|
|
|
return j;
|
|
|
|
}
|
|
|
|
i = j;
|
|
|
|
|
2001-12-10 15:59:20 +00:00
|
|
|
addkey(key, mod, nmod);
|
2000-02-04 09:38:32 +00:00
|
|
|
mod = 0;
|
|
|
|
}
|
|
|
|
}
|
2001-11-14 11:31:14 +00:00
|
|
|
|
|
|
|
// empty sequence?
|
2001-11-30 13:25:38 +00:00
|
|
|
if (!length_)
|
2001-11-14 11:31:14 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// everything is fine
|
|
|
|
return string::npos;
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
string const kb_sequence::print() const
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
2001-11-30 13:25:38 +00:00
|
|
|
string buf;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
if (deleted_)
|
|
|
|
return buf;
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
for (vector<unsigned int>::size_type i = 0; i < length_; ++i) {
|
2001-11-30 13:25:38 +00:00
|
|
|
buf += kb_keymap::printKeysym(sequence[i], modifiers[i] & 0xffff);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
// append a blank
|
|
|
|
if (i + 1 < length_) {
|
2000-02-04 09:38:32 +00:00
|
|
|
buf += ' ';
|
|
|
|
}
|
|
|
|
}
|
2001-11-30 13:25:38 +00:00
|
|
|
return buf;
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
string const kb_sequence::printOptions() const
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
2001-11-30 13:25:38 +00:00
|
|
|
string buf;
|
|
|
|
|
|
|
|
buf += print();
|
2001-12-10 15:59:20 +00:00
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
if (!curmap)
|
|
|
|
return buf;
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
buf += _(" options: ");
|
2001-11-30 13:25:38 +00:00
|
|
|
buf += curmap->print();
|
|
|
|
return buf;
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
void kb_sequence::mark_deleted()
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
2001-11-30 13:25:38 +00:00
|
|
|
deleted_ = true;
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int kb_sequence::getsym() const
|
|
|
|
{
|
2001-11-30 13:25:38 +00:00
|
|
|
if (length_ == 0) return NoSymbol;
|
|
|
|
return sequence[length_ - 1];
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char kb_sequence::getiso() const
|
|
|
|
{
|
2001-05-16 07:53:23 +00:00
|
|
|
unsigned int const c = getsym();
|
|
|
|
|
2001-07-09 10:32:44 +00:00
|
|
|
lyxerr[Debug::KBMAP] << "Raw keysym: "
|
2002-02-16 15:59:55 +00:00
|
|
|
<< hex << c << dec << endl;
|
2001-07-09 10:32:44 +00:00
|
|
|
lyxerr[Debug::KBMAP] << "byte 3: "
|
2002-02-16 15:59:55 +00:00
|
|
|
<< hex << (c & 0xff00) << dec
|
2001-07-09 10:32:44 +00:00
|
|
|
<< endl;
|
2001-11-30 13:25:38 +00:00
|
|
|
return kb_keymap::getiso(c);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void kb_sequence::reset()
|
|
|
|
{
|
2001-11-30 13:25:38 +00:00
|
|
|
mark_deleted();
|
2000-02-04 09:38:32 +00:00
|
|
|
curmap = stdmap;
|
|
|
|
}
|
|
|
|
|
2001-11-30 13:25:38 +00:00
|
|
|
void kb_sequence::clear()
|
|
|
|
{
|
|
|
|
length_ = 0;
|
|
|
|
reset();
|
|
|
|
}
|