2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file Trans.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Matthias Ettrich
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Trans.h"
|
2007-04-30 21:44:00 +00:00
|
|
|
|
|
|
|
|
|
#include "Buffer.h"
|
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "Cursor.h"
|
|
|
|
|
#include "CutAndPaste.h"
|
|
|
|
|
#include "Lexer.h"
|
|
|
|
|
#include "LyXRC.h"
|
|
|
|
|
#include "Text.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
|
#include "support/convert.h"
|
|
|
|
|
#include "support/debug.h"
|
|
|
|
|
#include "support/docstream.h"
|
2007-12-17 16:04:46 +00:00
|
|
|
|
#include "support/FileName.h"
|
2007-04-30 21:44:00 +00:00
|
|
|
|
#include "support/filetools.h"
|
|
|
|
|
#include "support/lstrings.h"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
|
using namespace lyx::support;
|
2007-12-12 10:16:00 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2007-04-30 21:44:00 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// TeXAccents
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/* the names used by TeX and XWindows for deadkeys/accents are not the same
|
|
|
|
|
so here follows a table to clearify the differences. Please correct this
|
|
|
|
|
if I got it wrong
|
|
|
|
|
|
|
|
|
|
|------------------|------------------|------------------|--------------|
|
|
|
|
|
| TeX | XWindows | \bind/LFUN | used by intl |
|
|
|
|
|
|------------------|------------------|------------------|--------------|
|
|
|
|
|
| grave | grave |LFUN_ACCENT_GRAVE | grave
|
|
|
|
|
| acute | acute |LFUN_ACCENT_ACUTE | acute
|
|
|
|
|
| circumflex | circumflex |LFUN_ACCENT_CIRCUMFLEX | circumflex
|
|
|
|
|
| umlaut/dieresis | diaeresis |LFUN_ACCENT_UMLAUT | umlaut
|
|
|
|
|
| tilde | tilde |LFUN_ACCENT_TILDE | tilde
|
|
|
|
|
| macron | maron |LFUN_ACCENT_MACRON | macron
|
|
|
|
|
| dot | abovedot |LFUN_ACCENT_DOT | dot
|
|
|
|
|
| cedilla | cedilla |LFUN_ACCENT_CEDILLA | cedilla
|
|
|
|
|
| underdot | |LFUN_ACCENT_UNDERDOT | underdot
|
|
|
|
|
| underbar | |LFUN_ACCENT_UNDERBAR | underbar
|
|
|
|
|
| h<EFBFBD>cek | caron |LFUN_ACCENT_CARON | caron
|
|
|
|
|
| breve | breve |LFUN_ACCENT_BREVE | breve
|
|
|
|
|
| tie | |LFUN_ACCENT_TIE | tie
|
|
|
|
|
| Hungarian umlaut | doubleacute |LFUN_ACCENT_HUNGARIAN_UMLAUT | hungarian umlaut
|
|
|
|
|
| circle | abovering |LFUN_ACCENT_CIRCLE | circle
|
|
|
|
|
| | ogonek | |
|
|
|
|
|
| | iota | |
|
|
|
|
|
| | voiced_sound | |
|
|
|
|
|
| | semivoiced_sound | |
|
|
|
|
|
| | |LFUN_ACCENT_SPECIAL_CARON| special caron
|
|
|
|
|
*/
|
|
|
|
|
static tex_accent_struct lyx_accent_table[] = {
|
|
|
|
|
{TEX_NOACCENT, 0, "", LFUN_NOACTION},
|
|
|
|
|
{TEX_ACUTE, 0x0301, "acute", LFUN_ACCENT_ACUTE},
|
|
|
|
|
{TEX_GRAVE, 0x0300, "grave", LFUN_ACCENT_GRAVE},
|
|
|
|
|
{TEX_MACRON, 0x0304, "macron", LFUN_ACCENT_MACRON},
|
|
|
|
|
{TEX_TILDE, 0x0303, "tilde", LFUN_ACCENT_TILDE},
|
|
|
|
|
{TEX_UNDERBAR, 0x0320, "underbar", LFUN_ACCENT_UNDERBAR},
|
|
|
|
|
{TEX_CEDILLA, 0x0327, "cedilla", LFUN_ACCENT_CEDILLA},
|
|
|
|
|
{TEX_UNDERDOT, 0x0323, "underdot", LFUN_ACCENT_UNDERDOT},
|
|
|
|
|
{TEX_CIRCUMFLEX, 0x0302, "circumflex", LFUN_ACCENT_CIRCUMFLEX},
|
|
|
|
|
{TEX_CIRCLE, 0x030a, "circle", LFUN_ACCENT_CIRCLE},
|
|
|
|
|
{TEX_TIE, 0x0361, "tie", LFUN_ACCENT_TIE},
|
|
|
|
|
{TEX_BREVE, 0x0306, "breve", LFUN_ACCENT_BREVE},
|
|
|
|
|
{TEX_CARON, 0x030c, "caron", LFUN_ACCENT_CARON},
|
|
|
|
|
// {TEX_SPECIAL_CARON, 0x030c, "ooo", LFUN_ACCENT_SPECIAL_CARON},
|
|
|
|
|
// Don't fix this typo for compatibility reasons!
|
|
|
|
|
{TEX_HUNGUML, 0x030b, "hugarian_umlaut", LFUN_ACCENT_HUNGARIAN_UMLAUT},
|
|
|
|
|
{TEX_UMLAUT, 0x0308, "umlaut", LFUN_ACCENT_UMLAUT},
|
|
|
|
|
{TEX_DOT, 0x0307, "dot", LFUN_ACCENT_DOT},
|
|
|
|
|
{TEX_OGONEK, 0x0328, "ogonek", LFUN_ACCENT_OGONEK}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tex_accent_struct get_accent(kb_action action)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-04-30 21:44:00 +00:00
|
|
|
|
int i = 0;
|
|
|
|
|
while (i <= TEX_MAX_ACCENT) {
|
|
|
|
|
if (lyx_accent_table[i].action == action)
|
|
|
|
|
return lyx_accent_table[i];
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
struct tex_accent_struct temp = { static_cast<tex_accent>(0), 0,
|
|
|
|
|
0, static_cast<kb_action>(0)};
|
|
|
|
|
return temp;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-30 21:44:00 +00:00
|
|
|
|
static docstring const doAccent(docstring const & s, tex_accent accent)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-04-30 21:44:00 +00:00
|
|
|
|
if (s.empty())
|
|
|
|
|
return docstring(1, lyx_accent_table[accent].ucs4);
|
|
|
|
|
|
|
|
|
|
odocstringstream os;
|
|
|
|
|
os.put(s[0]);
|
|
|
|
|
os.put(lyx_accent_table[accent].ucs4);
|
|
|
|
|
if (s.length() > 1) {
|
|
|
|
|
if (accent != TEX_TIE || s.length() > 2)
|
|
|
|
|
lyxerr << "Warning: Too many characters given for accent "
|
2007-12-12 19:28:07 +00:00
|
|
|
|
<< lyx_accent_table[accent].name << '.' << endl;
|
2007-04-30 21:44:00 +00:00
|
|
|
|
os << s.substr(1);
|
|
|
|
|
}
|
2007-07-05 14:45:00 +00:00
|
|
|
|
return normalize_c(os.str());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-30 21:44:00 +00:00
|
|
|
|
static docstring const doAccent(char_type c, tex_accent accent)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-04-30 21:44:00 +00:00
|
|
|
|
return doAccent(docstring(1, c), accent);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-30 21:44:00 +00:00
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Trans
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2007-03-31 08:12:08 +00:00
|
|
|
|
void Trans::insertException(KmodException & exclist, char_type c,
|
2007-04-30 21:44:00 +00:00
|
|
|
|
docstring const & data, bool flag, tex_accent accent)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-16 15:42:57 +00:00
|
|
|
|
Keyexc p;
|
|
|
|
|
p.c = c;
|
|
|
|
|
p.data = data;
|
|
|
|
|
p.combined = flag;
|
|
|
|
|
p.accent = accent;
|
|
|
|
|
exclist.insert(exclist.begin(), p);
|
|
|
|
|
// or just
|
|
|
|
|
// exclist.push_back(p);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-04-09 00:26:19 +00:00
|
|
|
|
void Trans::freeException(KmodException & exclist)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-16 15:42:57 +00:00
|
|
|
|
exclist.clear();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-04-09 00:26:19 +00:00
|
|
|
|
void Trans::freeKeymap()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-16 15:42:57 +00:00
|
|
|
|
kmod_list_.clear();
|
|
|
|
|
keymap_.clear();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-04-09 00:26:19 +00:00
|
|
|
|
bool Trans::isDefined() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
return !name_.empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-10-30 21:53:29 +00:00
|
|
|
|
enum kmaptags_ {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
KCOMB = 1,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
KMOD,
|
|
|
|
|
KMAP,
|
|
|
|
|
KXMOD,
|
|
|
|
|
K_LAST
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
|
struct keyword_item kmapTags[K_LAST - 1] = {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
{"\\kcomb", KCOMB },
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{ "\\kmap", KMAP },
|
|
|
|
|
{ "\\kmod", KMOD },
|
|
|
|
|
{ "\\kxmod", KXMOD }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
tex_accent getkeymod(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2007-03-31 08:12:08 +00:00
|
|
|
|
void Trans::addDeadkey(tex_accent accent, docstring const & keys)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-07-16 15:42:57 +00:00
|
|
|
|
KmodInfo tmp;
|
|
|
|
|
tmp.data = keys;
|
|
|
|
|
tmp.accent = accent;
|
|
|
|
|
kmod_list_[accent] = tmp;
|
|
|
|
|
|
2007-03-31 08:12:08 +00:00
|
|
|
|
for (docstring::size_type i = 0; i < keys.length(); ++i) {
|
|
|
|
|
// FIXME This is a hack.
|
|
|
|
|
// tmp is no valid UCS4 string, but misused to store the
|
|
|
|
|
// accent.
|
|
|
|
|
docstring tmp;
|
|
|
|
|
tmp += char_type(0);
|
|
|
|
|
tmp += char_type(accent);
|
2001-07-16 15:42:57 +00:00
|
|
|
|
keymap_[keys[i]] = tmp;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
int Trans::load(Lexer & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
bool error = false;
|
|
|
|
|
|
2001-08-06 19:12:46 +00:00
|
|
|
|
while (lex.isOK() && !error) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (lex.lex()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case KMOD:
|
|
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "KMOD:\t" << lex.getString());
|
|
|
|
|
if (!lex.next(true))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return -1;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "key\t`" << lex.getString() << '\'');
|
|
|
|
|
|
2007-03-31 08:12:08 +00:00
|
|
|
|
docstring const keys = lex.getDocString();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
if (!lex.next(true))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "accent\t`" << lex.getString() << '\'');
|
|
|
|
|
|
2001-08-06 19:12:46 +00:00
|
|
|
|
tex_accent accent = getkeymod(lex.getString());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
if (accent == TEX_NOACCENT)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
2001-07-12 11:11:10 +00:00
|
|
|
|
#if 1
|
2007-08-10 11:47:12 +00:00
|
|
|
|
// FIXME: This code should be removed...
|
2001-07-12 11:11:10 +00:00
|
|
|
|
// But we need to fix up all the kmap files first
|
|
|
|
|
// so that this field is not present anymore.
|
2007-11-15 20:04:51 +00:00
|
|
|
|
if (!lex.next(true))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "allowed\t`" << lex.getString() << '\'');
|
|
|
|
|
|
2002-01-14 12:56:05 +00:00
|
|
|
|
/* string const allowed = lex.getString(); */
|
2006-04-09 00:26:19 +00:00
|
|
|
|
addDeadkey(accent, keys /*, allowed*/);
|
2001-07-12 11:11:10 +00:00
|
|
|
|
#else
|
2006-04-09 00:26:19 +00:00
|
|
|
|
addDeadkey(accent, keys);
|
2001-07-12 11:11:10 +00:00
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case KCOMB: {
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string str;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "KCOMB:");
|
|
|
|
|
if (!lex.next(true))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return -1;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
str = lex.getString();
|
|
|
|
|
LYXERR(Debug::KBMAP, str);
|
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
tex_accent accent_1 = getkeymod(str);
|
2007-11-15 20:04:51 +00:00
|
|
|
|
if (accent_1 == TEX_NOACCENT)
|
|
|
|
|
return -1;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
if (!lex.next(true))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
str = lex.getString();
|
|
|
|
|
LYXERR(Debug::KBMAP, str);
|
|
|
|
|
|
2007-04-30 21:44:00 +00:00
|
|
|
|
tex_accent accent_2 = getkeymod(str);
|
1999-11-15 12:01:38 +00:00
|
|
|
|
if (accent_2 == TEX_NOACCENT) return -1;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-03-31 08:12:08 +00:00
|
|
|
|
map<tex_accent, KmodInfo>::iterator it1 =
|
2001-07-16 15:42:57 +00:00
|
|
|
|
kmod_list_.find(accent_1);
|
2007-03-31 08:12:08 +00:00
|
|
|
|
map<tex_accent, KmodInfo>::iterator it2 =
|
2001-07-16 15:42:57 +00:00
|
|
|
|
kmod_list_.find(accent_2);
|
2007-11-15 20:04:51 +00:00
|
|
|
|
if (it1 == kmod_list_.end() || it2 == kmod_list_.end())
|
2001-07-16 15:42:57 +00:00
|
|
|
|
return -1;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
// Find what key accent_2 is on - should
|
|
|
|
|
// check about accent_1 also
|
2007-03-31 08:12:08 +00:00
|
|
|
|
map<char_type, docstring>::iterator it = keymap_.begin();
|
|
|
|
|
map<char_type, docstring>::iterator end = keymap_.end();
|
2001-07-16 15:42:57 +00:00
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
if (!it->second.empty()
|
|
|
|
|
&& it->second[0] == 0
|
|
|
|
|
&& it->second[1] == accent_2)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-03-31 08:12:08 +00:00
|
|
|
|
docstring allowed;
|
2007-11-15 20:04:51 +00:00
|
|
|
|
if (!lex.next())
|
2001-07-16 15:42:57 +00:00
|
|
|
|
return -1;
|
2007-11-15 20:04:51 +00:00
|
|
|
|
|
|
|
|
|
allowed = lex.getDocString();
|
|
|
|
|
LYXERR(Debug::KBMAP, "allowed: " << to_utf8(allowed));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2006-04-09 00:26:19 +00:00
|
|
|
|
insertException(kmod_list_[accent_1].exception_list,
|
2007-11-15 20:04:51 +00:00
|
|
|
|
it->first, allowed, true, accent_2);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case KMAP: {
|
1999-12-10 00:07:59 +00:00
|
|
|
|
unsigned char key_from;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "KMAP:\t" << lex.getString());
|
2007-04-01 14:44:10 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
if (!lex.next(true))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
key_from = lex.getString()[0];
|
|
|
|
|
LYXERR(Debug::KBMAP, "\t`" << lex.getString() << '\'');
|
|
|
|
|
|
|
|
|
|
if (!lex.next(true))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
docstring const string_to = lex.getDocString();
|
|
|
|
|
keymap_[key_from] = string_to;
|
|
|
|
|
LYXERR(Debug::KBMAP, "\t`" << to_utf8(string_to) << '\'');
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case KXMOD: {
|
|
|
|
|
tex_accent accent;
|
2007-03-31 08:12:08 +00:00
|
|
|
|
char_type key;
|
|
|
|
|
docstring str;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "KXMOD:\t" << lex.getString());
|
2007-04-01 14:44:10 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
if (!lex.next(true))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "\t`" << lex.getString() << '\'');
|
|
|
|
|
accent = getkeymod(lex.getString());
|
|
|
|
|
|
|
|
|
|
if (!lex.next(true))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "\t`" << lex.getString() << '\'');
|
|
|
|
|
key = lex.getDocString()[0];
|
|
|
|
|
|
|
|
|
|
if (!lex.next(true))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "\t`" << lex.getString() << '\'');
|
|
|
|
|
str = lex.getDocString();
|
|
|
|
|
|
2006-04-09 00:26:19 +00:00
|
|
|
|
insertException(kmod_list_[accent].exception_list,
|
1999-12-16 06:43:25 +00:00
|
|
|
|
key, str);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-04-26 11:30:54 +00:00
|
|
|
|
case Lexer::LEX_FEOF:
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::PARSER, "End of parsing");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2007-11-15 20:04:51 +00:00
|
|
|
|
lex.printError("ParseKeymapFile: Unknown tag: `$$Token'");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-03-31 08:12:08 +00:00
|
|
|
|
map<tex_accent, KmodInfo>::const_iterator cit = kmod_list_.find(accent);
|
2007-11-15 20:04:51 +00:00
|
|
|
|
if (cit == kmod_list_.end())
|
|
|
|
|
return false;
|
|
|
|
|
i = cit->second;
|
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-03-31 08:12:08 +00:00
|
|
|
|
docstring const Trans::process(char_type c, TransManager & k)
|
2001-07-07 17:52:03 +00:00
|
|
|
|
{
|
2007-03-31 08:12:08 +00:00
|
|
|
|
docstring const t = match(c);
|
2001-07-07 17:52:03 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
if (t.empty() && c != 0)
|
2001-07-07 17:52:03 +00:00
|
|
|
|
return k.normalkey(c);
|
2007-11-15 20:04:51 +00:00
|
|
|
|
|
|
|
|
|
if (!t.empty() && t[0] != 0)
|
|
|
|
|
return t; //return k.normalkey(c);
|
|
|
|
|
|
|
|
|
|
return k.deadkey(c, kmod_list_[static_cast<tex_accent>(t[1])]);
|
2001-07-07 17:52:03 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2006-04-09 00:26:19 +00:00
|
|
|
|
int Trans::load(string const & language)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-12-12 19:57:42 +00:00
|
|
|
|
FileName const filename = libFileSearch("kbd", language, "kmap");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (filename.empty())
|
|
|
|
|
return -1;
|
|
|
|
|
|
2006-04-09 00:26:19 +00:00
|
|
|
|
freeKeymap();
|
2007-04-26 11:30:54 +00:00
|
|
|
|
Lexer lex(kmapTags, K_LAST - 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
lex.setFile(filename);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2006-04-09 00:26:19 +00:00
|
|
|
|
int const res = load(lex);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2007-04-30 21:44:00 +00:00
|
|
|
|
if (res == 0)
|
1999-11-15 12:01:38 +00:00
|
|
|
|
name_ = language;
|
2007-04-30 21:44:00 +00:00
|
|
|
|
else
|
2000-05-04 10:57:00 +00:00
|
|
|
|
name_.erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
tex_accent getkeymod(string const & p)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/* return modifier - decoded from p and update p */
|
|
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
|
for (int i = 1; i <= TEX_MAX_ACCENT; ++i) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "p = " << p
|
2007-04-01 14:44:10 +00:00
|
|
|
|
<< ", lyx_accent_table[" << i
|
2007-11-15 20:04:51 +00:00
|
|
|
|
<< "].name = `" << lyx_accent_table[i].name << '\'');
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (lyx_accent_table[i].name
|
1999-12-16 06:43:25 +00:00
|
|
|
|
&& contains(p, lyx_accent_table[i].name)) {
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "Found it!");
|
1999-12-13 00:05:34 +00:00
|
|
|
|
return static_cast<tex_accent>(i);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return TEX_NOACCENT;
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
2007-04-30 21:44:00 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// TransState
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TransFSMData
|
|
|
|
|
TransFSMData::TransFSMData()
|
|
|
|
|
{
|
|
|
|
|
deadkey_ = deadkey2_ = 0;
|
|
|
|
|
deadkey_info_.accent = deadkey2_info_.accent = TEX_NOACCENT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TransState
|
|
|
|
|
char_type const TransState::TOKEN_SEP = 4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TransInitState
|
|
|
|
|
TransInitState::TransInitState()
|
|
|
|
|
{
|
|
|
|
|
init_state_ = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring const TransInitState::normalkey(char_type c)
|
|
|
|
|
{
|
|
|
|
|
docstring res;
|
|
|
|
|
res = c;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring const TransInitState::deadkey(char_type c, KmodInfo d)
|
|
|
|
|
{
|
|
|
|
|
deadkey_ = c;
|
|
|
|
|
deadkey_info_ = d;
|
|
|
|
|
currentState = deadkey_state_;
|
|
|
|
|
return docstring();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TransDeadkeyState
|
|
|
|
|
TransDeadkeyState::TransDeadkeyState()
|
|
|
|
|
{
|
|
|
|
|
deadkey_state_ = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring const TransDeadkeyState::normalkey(char_type c)
|
|
|
|
|
{
|
|
|
|
|
docstring res;
|
|
|
|
|
|
|
|
|
|
KmodException::iterator it = deadkey_info_.exception_list.begin();
|
|
|
|
|
KmodException::iterator end = deadkey_info_.exception_list.end();
|
|
|
|
|
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
if (it->c == c) {
|
|
|
|
|
res = it->data;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (it == end) {
|
|
|
|
|
res = doAccent(c, deadkey_info_.accent);
|
|
|
|
|
}
|
|
|
|
|
currentState = init_state_;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring const TransDeadkeyState::deadkey(char_type c, KmodInfo d)
|
|
|
|
|
{
|
|
|
|
|
docstring res;
|
|
|
|
|
|
|
|
|
|
// Check if the same deadkey was typed twice
|
|
|
|
|
if (deadkey_ == c) {
|
|
|
|
|
res = deadkey_;
|
|
|
|
|
deadkey_ = 0;
|
|
|
|
|
deadkey_info_.accent = TEX_NOACCENT;
|
|
|
|
|
currentState = init_state_;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if it is a combination or an exception
|
|
|
|
|
KmodException::const_iterator cit = deadkey_info_.exception_list.begin();
|
|
|
|
|
KmodException::const_iterator end = deadkey_info_.exception_list.end();
|
|
|
|
|
for (; cit != end; ++cit) {
|
|
|
|
|
if (cit->combined == true && cit->accent == d.accent) {
|
|
|
|
|
deadkey2_ = c;
|
|
|
|
|
deadkey2_info_ = d;
|
|
|
|
|
comb_info_ = (*cit);
|
|
|
|
|
currentState = combined_state_;
|
|
|
|
|
return docstring();
|
|
|
|
|
}
|
|
|
|
|
if (cit->c == c) {
|
|
|
|
|
res = cit->data;
|
|
|
|
|
deadkey_ = 0;
|
|
|
|
|
deadkey_info_.accent = TEX_NOACCENT;
|
|
|
|
|
currentState = init_state_;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Not a combination or an exception.
|
|
|
|
|
// Output deadkey1 and keep deadkey2
|
|
|
|
|
|
|
|
|
|
if (deadkey_!= 0)
|
|
|
|
|
res = deadkey_;
|
|
|
|
|
deadkey_ = c;
|
|
|
|
|
deadkey_info_ = d;
|
|
|
|
|
currentState = deadkey_state_;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TransCombinedState::TransCombinedState()
|
|
|
|
|
{
|
|
|
|
|
combined_state_ = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring const TransCombinedState::normalkey(char_type c)
|
|
|
|
|
{
|
|
|
|
|
docstring const temp = doAccent(c, deadkey2_info_.accent);
|
|
|
|
|
docstring const res = doAccent(temp, deadkey_info_.accent);
|
|
|
|
|
currentState = init_state_;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docstring const TransCombinedState::deadkey(char_type c, KmodInfo d)
|
|
|
|
|
{
|
|
|
|
|
// Third key in a row. Output the first one and
|
|
|
|
|
// reenter with shifted deadkeys
|
|
|
|
|
docstring res;
|
|
|
|
|
if (deadkey_ != 0)
|
|
|
|
|
res = deadkey_;
|
|
|
|
|
res += TOKEN_SEP;
|
|
|
|
|
deadkey_ = deadkey2_;
|
|
|
|
|
deadkey_info_ = deadkey2_info_;
|
|
|
|
|
res += deadkey_state_->deadkey(c, d);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TransFSM
|
2007-11-15 20:04:51 +00:00
|
|
|
|
TransFSM::TransFSM()
|
|
|
|
|
: TransFSMData(), TransInitState(), TransDeadkeyState(), TransCombinedState()
|
2007-04-30 21:44:00 +00:00
|
|
|
|
{
|
|
|
|
|
currentState = init_state_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TransManager
|
|
|
|
|
|
|
|
|
|
// Initialize static member.
|
|
|
|
|
Trans TransManager::default_;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TransManager::TransManager()
|
2007-09-17 22:04:17 +00:00
|
|
|
|
: active_(0)
|
2007-04-30 21:44:00 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int TransManager::setPrimary(string const & language)
|
|
|
|
|
{
|
2007-09-17 22:04:17 +00:00
|
|
|
|
if (t1_.getName() == language)
|
2007-04-30 21:44:00 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
2007-09-17 22:04:17 +00:00
|
|
|
|
return t1_.load(language);
|
2007-04-30 21:44:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int TransManager::setSecondary(string const & language)
|
|
|
|
|
{
|
2007-09-17 22:04:17 +00:00
|
|
|
|
if (t2_.getName() == language)
|
2007-04-30 21:44:00 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
2007-09-17 22:04:17 +00:00
|
|
|
|
return t2_.load(language);
|
2007-04-30 21:44:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransManager::enablePrimary()
|
|
|
|
|
{
|
2007-09-17 22:04:17 +00:00
|
|
|
|
if (t1_.isDefined())
|
|
|
|
|
active_ = &t1_;
|
2007-04-30 21:44:00 +00:00
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "Enabling primary keymap");
|
2007-04-30 21:44:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransManager::enableSecondary()
|
|
|
|
|
{
|
2007-09-17 22:04:17 +00:00
|
|
|
|
if (t2_.isDefined())
|
|
|
|
|
active_ = &t2_;
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "Enabling secondary keymap");
|
2007-04-30 21:44:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransManager::disableKeymap()
|
|
|
|
|
{
|
|
|
|
|
active_ = &default_;
|
2007-11-15 20:04:51 +00:00
|
|
|
|
LYXERR(Debug::KBMAP, "Disabling keymap");
|
2007-04-30 21:44:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransManager::translateAndInsert(char_type c, Text * text, Cursor & cur)
|
|
|
|
|
{
|
|
|
|
|
docstring res = active_->process(c, *this);
|
|
|
|
|
|
|
|
|
|
// Process with tokens
|
|
|
|
|
docstring temp;
|
|
|
|
|
|
|
|
|
|
while (res.length() > 0) {
|
|
|
|
|
res = split(res, temp, TransState::TOKEN_SEP);
|
|
|
|
|
insert(temp, text, cur);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransManager::insert(docstring const & str, Text * text, Cursor & cur)
|
|
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
|
for (size_t i = 0, n = str.size(); i != n; ++i)
|
2007-04-30 21:44:00 +00:00
|
|
|
|
text->insertChar(cur, str[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TransManager::deadkey(char_type c, tex_accent accent, Text * t, Cursor & cur)
|
|
|
|
|
{
|
|
|
|
|
if (c == 0 && active_ != &default_) {
|
|
|
|
|
// A deadkey was pressed that cannot be printed
|
|
|
|
|
// or a accent command was typed in the minibuffer
|
|
|
|
|
KmodInfo i;
|
|
|
|
|
if (active_->isAccentDefined(accent, i) == true) {
|
|
|
|
|
docstring const res = trans_fsm_
|
|
|
|
|
.currentState->deadkey(c, i);
|
|
|
|
|
insert(res, t, cur);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (active_ == &default_ || c == 0) {
|
|
|
|
|
KmodInfo i;
|
|
|
|
|
i.accent = accent;
|
|
|
|
|
i.data.erase();
|
|
|
|
|
docstring res = trans_fsm_.currentState->deadkey(c, i);
|
|
|
|
|
insert(res, t, cur);
|
|
|
|
|
} else {
|
|
|
|
|
// Go through the translation
|
|
|
|
|
translateAndInsert(c, t, cur);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|