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"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-11-03 17:47:28 +00:00
|
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
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
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual std::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
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual std::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
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual std::string const normalkey(char);
|
1999-12-21 06:10:21 +00:00
|
|
|
|
///
|
|
|
|
|
virtual bool backspace() { return true; }
|
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual std::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
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual std::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
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual std::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
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual std::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
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual std::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
|
|
|
|
///
|
2003-11-03 17:47:28 +00:00
|
|
|
|
boost::scoped_ptr<Trans> t1_;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2003-11-03 17:47:28 +00:00
|
|
|
|
boost::scoped_ptr<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
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void insert(std::string const &, LyXText *);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void insertVerbatim(std::string const &, LyXText *);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
public:
|
|
|
|
|
///
|
|
|
|
|
TransManager();
|
|
|
|
|
///
|
2003-11-03 17:47:28 +00:00
|
|
|
|
~TransManager();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2006-04-09 00:26:19 +00:00
|
|
|
|
int setPrimary(std::string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2006-04-09 00:26:19 +00:00
|
|
|
|
int setSecondary(std::string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2006-04-09 00:26:19 +00:00
|
|
|
|
void enablePrimary();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2006-04-09 00:26:19 +00:00
|
|
|
|
void enableSecondary();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2006-04-09 00:26:19 +00:00
|
|
|
|
void disableKeymap();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
bool setCharset(std::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();
|
|
|
|
|
}
|
|
|
|
|
///
|
2006-04-09 00:26:19 +00:00
|
|
|
|
void translateAndInsert(char, LyXText *);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string const deadkey(char, KmodInfo);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::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
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string const TransManager::normalkey(char c)
|
2001-07-07 17:52:03 +00:00
|
|
|
|
{
|
|
|
|
|
return trans_fsm_.currentState->normalkey(c);
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2001-07-07 17:52:03 +00:00
|
|
|
|
inline
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::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
|
|
|
|
}
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
|
#endif // TRANS_MANAGER_H
|