1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
2002-07-22 16:05:17 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file Trans.h
|
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.
|
2002-07-22 16:05:17 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Matthias Ettrich
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-07-22 16:05:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TRANS_H
|
|
|
|
#define TRANS_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2008-03-15 01:20:36 +00:00
|
|
|
#include "FuncCode.h"
|
|
|
|
|
2007-04-30 21:44:00 +00:00
|
|
|
#include "support/docstring.h"
|
2001-07-16 15:42:57 +00:00
|
|
|
|
2007-04-30 21:44:00 +00:00
|
|
|
#include <list>
|
2003-09-07 01:45:40 +00:00
|
|
|
#include <map>
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2007-04-30 21:44:00 +00:00
|
|
|
class Cursor;
|
|
|
|
class Text;
|
2007-04-26 11:30:54 +00:00
|
|
|
class Lexer;
|
1999-09-27 18:44:28 +00:00
|
|
|
class TransManager;
|
|
|
|
|
2007-04-30 21:44:00 +00:00
|
|
|
///
|
|
|
|
enum tex_accent {
|
|
|
|
///
|
|
|
|
TEX_NOACCENT = 0,
|
|
|
|
///
|
|
|
|
TEX_ACUTE,
|
|
|
|
///
|
|
|
|
TEX_GRAVE,
|
|
|
|
///
|
|
|
|
TEX_MACRON,
|
|
|
|
///
|
|
|
|
TEX_TILDE,
|
|
|
|
///
|
2015-08-13 09:15:19 +00:00
|
|
|
TEX_PERISPOMENI,
|
|
|
|
///
|
2007-04-30 21:44:00 +00:00
|
|
|
TEX_UNDERBAR,
|
|
|
|
///
|
|
|
|
TEX_CEDILLA,
|
|
|
|
///
|
|
|
|
TEX_UNDERDOT,
|
|
|
|
///
|
|
|
|
TEX_CIRCUMFLEX,
|
|
|
|
///
|
|
|
|
TEX_CIRCLE,
|
|
|
|
///
|
|
|
|
TEX_TIE,
|
|
|
|
///
|
|
|
|
TEX_BREVE,
|
|
|
|
///
|
|
|
|
TEX_CARON,
|
|
|
|
// TEX_SPECIAL_CARON,
|
|
|
|
///
|
|
|
|
TEX_HUNGUML,
|
|
|
|
///
|
|
|
|
TEX_UMLAUT,
|
|
|
|
///
|
|
|
|
TEX_DOT,
|
|
|
|
///
|
|
|
|
TEX_OGONEK,
|
|
|
|
///
|
|
|
|
TEX_MAX_ACCENT = TEX_OGONEK
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-15 01:20:36 +00:00
|
|
|
struct TeXAccent {
|
2007-04-30 21:44:00 +00:00
|
|
|
///
|
|
|
|
tex_accent accent;
|
|
|
|
/// UCS4 code point of this accent
|
|
|
|
char_type ucs4;
|
|
|
|
///
|
|
|
|
char const * name;
|
|
|
|
///
|
2008-03-15 01:20:36 +00:00
|
|
|
FuncCode action;
|
2007-04-30 21:44:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///
|
2008-03-15 01:20:36 +00:00
|
|
|
extern TeXAccent get_accent(FuncCode action);
|
2007-04-30 21:44:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
struct Keyexc {
|
2015-10-10 19:04:28 +00:00
|
|
|
///
|
|
|
|
Keyexc() : c('\0'), combined(false), accent(TEX_NOACCENT) {}
|
2007-04-30 21:44:00 +00:00
|
|
|
/// character to make exception
|
|
|
|
char_type c;
|
|
|
|
/// exception data
|
|
|
|
docstring data;
|
|
|
|
/// Combination with another deadkey
|
|
|
|
bool combined;
|
|
|
|
/// The accent comined with
|
|
|
|
tex_accent accent;
|
|
|
|
};
|
|
|
|
|
|
|
|
///
|
|
|
|
typedef std::list<Keyexc> KmodException;
|
|
|
|
|
|
|
|
///
|
|
|
|
class KmodInfo {
|
|
|
|
public:
|
2015-10-10 19:04:28 +00:00
|
|
|
///
|
|
|
|
KmodInfo() : accent(TEX_NOACCENT) {}
|
2007-04-30 21:44:00 +00:00
|
|
|
///
|
|
|
|
docstring data;
|
|
|
|
///
|
|
|
|
tex_accent accent;
|
|
|
|
///
|
|
|
|
KmodException exception_list;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Trans: holds a .kmap file
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-07-16 15:42:57 +00:00
|
|
|
class Trans {
|
1999-09-27 18:44:28 +00:00
|
|
|
public:
|
|
|
|
///
|
2007-04-30 21:44:00 +00:00
|
|
|
Trans() {}
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2007-04-30 21:44:00 +00:00
|
|
|
~Trans() { freeKeymap(); }
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
///
|
2006-04-09 00:26:19 +00:00
|
|
|
int load(std::string const & language);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2006-04-09 00:26:19 +00:00
|
|
|
bool isDefined() const;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2007-04-30 21:44:00 +00:00
|
|
|
std::string const & getName() const { return name_; }
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2007-03-31 08:12:08 +00:00
|
|
|
docstring const process(char_type, TransManager &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
bool isAccentDefined(tex_accent, KmodInfo &) const;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
private:
|
2001-07-12 11:11:10 +00:00
|
|
|
///
|
2007-03-31 08:12:08 +00:00
|
|
|
void addDeadkey(tex_accent, docstring const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2006-04-09 00:26:19 +00:00
|
|
|
void freeKeymap();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2007-04-26 11:30:54 +00:00
|
|
|
int load(Lexer &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2007-03-31 08:12:08 +00:00
|
|
|
docstring const & match(char_type c);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2007-03-31 08:12:08 +00:00
|
|
|
void insertException(KmodException & exclist, char_type c,
|
2007-05-28 22:27:45 +00:00
|
|
|
docstring const & data, bool = false,
|
1999-09-27 18:44:28 +00:00
|
|
|
tex_accent = TEX_NOACCENT);
|
|
|
|
///
|
2006-04-09 00:26:19 +00:00
|
|
|
void freeException(KmodException & exclist);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
std::string name_;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2007-03-31 08:12:08 +00:00
|
|
|
std::map<char_type, docstring> keymap_;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2007-03-31 08:12:08 +00:00
|
|
|
std::map<tex_accent, KmodInfo> kmod_list_;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2008-03-15 01:20:36 +00:00
|
|
|
inline docstring const & Trans::match(char_type c)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2007-03-31 08:12:08 +00:00
|
|
|
std::map<char_type, docstring>::iterator it = keymap_.find(c);
|
2001-07-16 15:42:57 +00:00
|
|
|
if (it != keymap_.end()) {
|
|
|
|
return it->second;
|
|
|
|
}
|
2007-03-31 08:12:08 +00:00
|
|
|
static docstring dummy;
|
2001-07-16 15:42:57 +00:00
|
|
|
return dummy;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-04-30 21:44:00 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// TransState
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/// Translation state
|
|
|
|
class TransState {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
virtual ~TransState() {}
|
|
|
|
///
|
|
|
|
virtual docstring const normalkey(char_type) = 0;
|
|
|
|
///
|
|
|
|
virtual bool backspace() = 0;
|
|
|
|
///
|
|
|
|
virtual docstring const deadkey(char_type, KmodInfo) = 0;
|
|
|
|
///
|
|
|
|
static char_type const TOKEN_SEP;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Translation FSM
|
|
|
|
class TransFSMData {
|
|
|
|
protected:
|
|
|
|
///
|
|
|
|
virtual ~TransFSMData() {}
|
|
|
|
///
|
|
|
|
char_type deadkey_;
|
|
|
|
///
|
|
|
|
KmodInfo deadkey_info_;
|
|
|
|
///
|
|
|
|
char_type deadkey2_;
|
|
|
|
///
|
|
|
|
KmodInfo deadkey2_info_;
|
|
|
|
///
|
|
|
|
Keyexc comb_info_;
|
|
|
|
///
|
|
|
|
TransState * init_state_;
|
|
|
|
///
|
|
|
|
TransState * deadkey_state_;
|
|
|
|
///
|
|
|
|
TransState * combined_state_;
|
|
|
|
///
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
TransFSMData();
|
|
|
|
///
|
|
|
|
TransState * currentState;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Init State
|
|
|
|
class TransInitState : virtual public TransFSMData, public TransState {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
TransInitState();
|
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
docstring const normalkey(char_type) override;
|
2007-04-30 21:44:00 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool backspace() override { return true; }
|
2007-04-30 21:44:00 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
docstring const deadkey(char_type, KmodInfo) override;
|
2007-04-30 21:44:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Deadkey State
|
|
|
|
class TransDeadkeyState : virtual public TransFSMData, public TransState {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
TransDeadkeyState();
|
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
docstring const normalkey(char_type) override;
|
2007-04-30 21:44:00 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool backspace() override {
|
2007-04-30 21:44:00 +00:00
|
|
|
currentState = init_state_;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
docstring const deadkey(char_type, KmodInfo) override;
|
2007-04-30 21:44:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Combined State
|
|
|
|
class TransCombinedState : virtual public TransFSMData, public TransState {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
TransCombinedState();
|
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
docstring const normalkey(char_type) override;
|
2007-04-30 21:44:00 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
bool backspace() override {
|
2007-04-30 21:44:00 +00:00
|
|
|
// cancel the second deadkey
|
|
|
|
deadkey2_ = 0;
|
|
|
|
deadkey2_info_.accent = TEX_NOACCENT;
|
|
|
|
currentState = deadkey_state_;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
docstring const deadkey(char_type, KmodInfo) override;
|
2007-04-30 21:44:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
class TransFSM : virtual public TransFSMData,
|
|
|
|
public TransInitState,
|
|
|
|
public TransDeadkeyState,
|
|
|
|
public TransCombinedState {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
TransFSM();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// TransManager
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TransManager {
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
TransFSM trans_fsm_;
|
|
|
|
///
|
|
|
|
Trans * active_;
|
|
|
|
///
|
2007-09-17 22:04:17 +00:00
|
|
|
Trans t1_;
|
2007-04-30 21:44:00 +00:00
|
|
|
///
|
2007-09-17 22:04:17 +00:00
|
|
|
Trans t2_;
|
2007-04-30 21:44:00 +00:00
|
|
|
///
|
|
|
|
static Trans default_;
|
|
|
|
///
|
|
|
|
void insert(docstring const &, Text *, Cursor & cur);
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
TransManager();
|
|
|
|
///
|
|
|
|
int setPrimary(std::string const &);
|
|
|
|
///
|
|
|
|
int setSecondary(std::string const &);
|
|
|
|
///
|
|
|
|
void enablePrimary();
|
|
|
|
///
|
|
|
|
void enableSecondary();
|
|
|
|
///
|
|
|
|
void disableKeymap();
|
|
|
|
///
|
|
|
|
bool backspace() { return trans_fsm_.currentState->backspace(); }
|
|
|
|
///
|
|
|
|
void translateAndInsert(char_type, Text *, Cursor &);
|
|
|
|
///
|
|
|
|
docstring const deadkey(char_type c, KmodInfo t)
|
|
|
|
{ return trans_fsm_.currentState->deadkey(c, t); }
|
|
|
|
///
|
|
|
|
docstring const normalkey(char_type c)
|
|
|
|
{ return trans_fsm_.currentState->normalkey(c); }
|
|
|
|
///
|
|
|
|
void deadkey(char_type, tex_accent, Text *, Cursor &);
|
|
|
|
};
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|
|
|
|
|
2002-07-22 16:05:17 +00:00
|
|
|
#endif // TRANS_H
|