+/////////////////////////////////////////////////////////////////////
+//
+// 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();
+ ///
+ docstring const normalkey(char_type) override;
+ ///
+ bool backspace() override { return true; }
+ ///
+ docstring const deadkey(char_type, KmodInfo) override;
+};
+
+
+/// Deadkey State
+class TransDeadkeyState : virtual public TransFSMData, public TransState {
+public:
+ ///
+ TransDeadkeyState();
+ ///
+ docstring const normalkey(char_type) override;
+ ///
+ bool backspace() override {
+ currentState = init_state_;
+ return false;
+ }
+ ///
+ docstring const deadkey(char_type, KmodInfo) override;
+};
+
+
+/// Combined State
+class TransCombinedState : virtual public TransFSMData, public TransState {
+public:
+ ///
+ TransCombinedState();
+ ///
+ docstring const normalkey(char_type) override;
+ ///
+ bool backspace() override {
+ // cancel the second deadkey
+ deadkey2_ = 0;
+ deadkey2_info_.accent = TEX_NOACCENT;
+ currentState = deadkey_state_;
+
+ return false;
+ }
+ ///
+ docstring const deadkey(char_type, KmodInfo) override;
+};
+
+
+///
+class TransFSM : virtual public TransFSMData,
+ public TransInitState,
+ public TransDeadkeyState,
+ public TransCombinedState {
+public:
+ ///
+ TransFSM();
+};
+
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// TransManager
+//
+/////////////////////////////////////////////////////////////////////
+
+class TransManager {
+private:
+ ///
+ TransFSM trans_fsm_;
+ ///
+ Trans * active_;
+ ///
+ Trans t1_;
+ ///
+ Trans t2_;
+ ///
+ 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 &);
+};
+