1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
1999-11-15 12:01:38 +00:00
|
|
|
#ifndef Trans_Manager_h
|
|
|
|
#define Trans_Manager_h
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "tex-accent.h"
|
|
|
|
#include "trans_decl.h"
|
1999-11-15 12:01:38 +00:00
|
|
|
#include "chset.h"
|
|
|
|
#include "LString.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
class LyXText;
|
|
|
|
class Trans;
|
|
|
|
|
|
|
|
/// Translation State
|
|
|
|
class TransState {
|
|
|
|
public:
|
|
|
|
///
|
1999-12-10 00:07:59 +00:00
|
|
|
virtual ~TransState() {}
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
virtual string const normalkey(char, string const &) = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
virtual bool backspace() = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
virtual string const deadkey(char, KmodInfo) = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
static char const TOKEN_SEP;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Translation FSM
|
|
|
|
class TransFSMData {
|
|
|
|
protected:
|
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
virtual ~TransFSMData() {}
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
char deadkey_;
|
|
|
|
///
|
|
|
|
KmodInfo deadkey_info_;
|
|
|
|
///
|
|
|
|
char deadkey2_;
|
|
|
|
///
|
|
|
|
KmodInfo deadkey2_info_;
|
|
|
|
///
|
|
|
|
KmodException comb_info_;
|
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
TransState * init_state_;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
TransState * deadkey_state_;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
TransState * combined_state_;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
TransFSMData();
|
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
TransState * currentState;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Init State
|
2000-08-07 20:58:24 +00:00
|
|
|
class TransInitState : virtual public TransFSMData, public TransState {
|
1999-09-27 18:44:28 +00:00
|
|
|
public:
|
1999-12-21 06:10:21 +00:00
|
|
|
///
|
|
|
|
TransInitState();
|
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
virtual string const normalkey(char, string const &);
|
1999-12-21 06:10:21 +00:00
|
|
|
///
|
|
|
|
virtual bool backspace() { return true; }
|
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
virtual string const deadkey(char, KmodInfo);
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Deadkey State
|
2000-08-07 20:58:24 +00:00
|
|
|
class TransDeadkeyState : virtual public TransFSMData, public TransState {
|
1999-09-27 18:44:28 +00:00
|
|
|
public:
|
1999-12-21 06:10:21 +00:00
|
|
|
///
|
|
|
|
TransDeadkeyState();
|
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
virtual string const normalkey(char, string const &);
|
1999-12-21 06:10:21 +00:00
|
|
|
///
|
|
|
|
virtual bool backspace() {
|
1999-11-15 12:01:38 +00:00
|
|
|
currentState = init_state_;
|
1999-09-27 18:44:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
1999-12-21 06:10:21 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
virtual string const deadkey(char, KmodInfo);
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Combined State
|
2000-08-07 20:58:24 +00:00
|
|
|
class TransCombinedState : virtual public TransFSMData, public TransState {
|
1999-09-27 18:44:28 +00:00
|
|
|
public:
|
1999-12-21 06:10:21 +00:00
|
|
|
///
|
|
|
|
TransCombinedState();
|
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
virtual string const normalkey(char, string const &);
|
1999-12-21 06:10:21 +00:00
|
|
|
///
|
|
|
|
virtual bool backspace() {
|
1999-09-27 18:44:28 +00:00
|
|
|
// cancel the second deadkey
|
1999-11-15 12:01:38 +00:00
|
|
|
deadkey2_ = 0;
|
|
|
|
deadkey2_info_.accent = TEX_NOACCENT;
|
|
|
|
currentState = deadkey_state_;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
1999-12-21 06:10:21 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
virtual string const deadkey(char, KmodInfo);
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///
|
2000-08-07 20:58:24 +00:00
|
|
|
class TransFSM : virtual public TransFSMData,
|
|
|
|
public TransInitState,
|
|
|
|
public TransDeadkeyState,
|
|
|
|
public TransCombinedState {
|
1999-09-27 18:44:28 +00:00
|
|
|
public:
|
|
|
|
///
|
|
|
|
TransFSM();
|
|
|
|
};
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-21 06:10:21 +00:00
|
|
|
class TransManager {
|
1999-09-27 18:44:28 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
TransFSM trans_fsm_;
|
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
Trans * active_;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
Trans * t1_;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
Trans * t2_;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2001-03-06 19:29:58 +00:00
|
|
|
static Trans default_;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
CharacterSet chset_;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-06-01 00:01:17 +00:00
|
|
|
void insert(string const &, LyXText *);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
void insertVerbatim(string const &, LyXText *);
|
1999-09-27 18:44:28 +00:00
|
|
|
public:
|
|
|
|
///
|
|
|
|
TransManager();
|
|
|
|
///
|
|
|
|
virtual ~TransManager();
|
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
int SetPrimary(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
int SetSecondary(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void EnablePrimary();
|
|
|
|
///
|
|
|
|
void EnableSecondary();
|
|
|
|
///
|
|
|
|
void DisableKeymap();
|
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
bool setCharset(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-21 06:10:21 +00:00
|
|
|
bool backspace() {
|
1999-09-27 18:44:28 +00:00
|
|
|
return trans_fsm_.currentState->backspace();
|
|
|
|
}
|
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
void TranslateAndInsert(char, LyXText *);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
inline string const deadkey(char, KmodInfo);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
inline string const normalkey(char, string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
void deadkey(char, tex_accent, LyXText *);
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const TransManager::normalkey(char c, string const & t)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
return trans_fsm_.currentState->normalkey(c, t);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const TransManager::deadkey(char c, KmodInfo t)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
return trans_fsm_.currentState->deadkey(c, t);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|