1999-09-27 18:44:28 +00:00
|
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file trans_mgr.h
|
|
|
|
|
* 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
|
|
|
|
|
* \author John Levon
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
|
#ifndef TRANS_MANAGER_H
|
|
|
|
|
#define TRANS_MANAGER_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
#include "chset.h"
|
2003-09-07 01:45:40 +00:00
|
|
|
|
#include "trans_decl.h"
|
2003-09-05 17:23:11 +00:00
|
|
|
|
#include "support/std_string.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
class LyXText;
|
|
|
|
|
class Trans;
|
|
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
|
/// Translation state
|
1999-09-27 18:44:28 +00:00
|
|
|
|
class TransState {
|
|
|
|
|
public:
|
|
|
|
|
///
|
1999-12-10 00:07:59 +00:00
|
|
|
|
virtual ~TransState() {}
|
2001-07-07 17:52:03 +00:00
|
|
|
|
///
|
|
|
|
|
virtual string const normalkey(char) = 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_;
|
2001-07-16 15:42:57 +00:00
|
|
|
|
///
|
|
|
|
|
Keyexc comb_info_;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
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
|
2003-08-11 09:09:01 +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();
|
2001-07-07 17:52:03 +00:00
|
|
|
|
///
|
|
|
|
|
virtual string const normalkey(char);
|
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();
|
2001-07-07 17:52:03 +00:00
|
|
|
|
///
|
|
|
|
|
virtual string const normalkey(char);
|
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();
|
2001-07-07 17:52:03 +00:00
|
|
|
|
///
|
|
|
|
|
virtual string const normalkey(char);
|
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_;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
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
|
|
|
|
///
|
2001-07-07 17:52:03 +00:00
|
|
|
|
string const deadkey(char, KmodInfo);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2001-07-07 17:52:03 +00:00
|
|
|
|
string const normalkey(char);
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2001-07-07 17:52:03 +00:00
|
|
|
|
inline
|
|
|
|
|
string const TransManager::normalkey(char c)
|
|
|
|
|
{
|
|
|
|
|
return trans_fsm_.currentState->normalkey(c);
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2001-07-07 17:52:03 +00:00
|
|
|
|
inline
|
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
|
|
|
|
}
|
|
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
|
#endif // TRANS_MANAGER_H
|