Consider the case where there is not any layout name.
[lyx.git] / src / trans_mgr.h
bloba9e45777eb364e0b5e26a37c0fb17054b6a696f6
1 // -*- C++ -*-
2 /**
3 * \file trans_mgr.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Matthias Ettrich
9 * \author John Levon
11 * Full author contact details are available in file CREDITS.
14 #ifndef TRANS_MANAGER_H
15 #define TRANS_MANAGER_H
17 #include "chset.h"
18 #include "trans_decl.h"
20 #include <boost/scoped_ptr.hpp>
22 class LyXText;
23 class Trans;
25 /// Translation state
26 class TransState {
27 public:
28 ///
29 virtual ~TransState() {}
30 ///
31 virtual std::string const normalkey(char) = 0;
32 ///
33 virtual bool backspace() = 0;
34 ///
35 virtual std::string const deadkey(char, KmodInfo) = 0;
36 ///
37 static char const TOKEN_SEP;
41 /// Translation FSM
42 class TransFSMData {
43 protected:
44 ///
45 virtual ~TransFSMData() {}
46 ///
47 char deadkey_;
48 ///
49 KmodInfo deadkey_info_;
50 ///
51 char deadkey2_;
52 ///
53 KmodInfo deadkey2_info_;
54 ///
55 Keyexc comb_info_;
56 ///
57 TransState * init_state_;
58 ///
59 TransState * deadkey_state_;
60 ///
61 TransState * combined_state_;
62 ///
63 public:
64 ///
65 TransFSMData();
66 ///
67 TransState * currentState;
71 /// Init State
72 class TransInitState :virtual public TransFSMData, public TransState {
73 public:
74 ///
75 TransInitState();
76 ///
77 virtual std::string const normalkey(char);
78 ///
79 virtual bool backspace() { return true; }
80 ///
81 virtual std::string const deadkey(char, KmodInfo);
85 /// Deadkey State
86 class TransDeadkeyState : virtual public TransFSMData, public TransState {
87 public:
88 ///
89 TransDeadkeyState();
90 ///
91 virtual std::string const normalkey(char);
92 ///
93 virtual bool backspace() {
94 currentState = init_state_;
95 return false;
97 ///
98 virtual std::string const deadkey(char, KmodInfo);
102 /// Combined State
103 class TransCombinedState : virtual public TransFSMData, public TransState {
104 public:
106 TransCombinedState();
108 virtual std::string const normalkey(char);
110 virtual bool backspace() {
111 // cancel the second deadkey
112 deadkey2_ = 0;
113 deadkey2_info_.accent = TEX_NOACCENT;
114 currentState = deadkey_state_;
116 return false;
119 virtual std::string const deadkey(char, KmodInfo);
124 class TransFSM : virtual public TransFSMData,
125 public TransInitState,
126 public TransDeadkeyState,
127 public TransCombinedState {
128 public:
130 TransFSM();
135 class TransManager {
136 private:
138 TransFSM trans_fsm_;
140 Trans * active_;
142 boost::scoped_ptr<Trans> t1_;
144 boost::scoped_ptr<Trans> t2_;
146 static Trans default_;
148 CharacterSet chset_;
150 void insert(std::string const &, LyXText *);
152 void insertVerbatim(std::string const &, LyXText *);
153 public:
155 TransManager();
157 ~TransManager();
159 int SetPrimary(std::string const &);
161 int SetSecondary(std::string const &);
163 void EnablePrimary();
165 void EnableSecondary();
167 void DisableKeymap();
169 bool setCharset(std::string const &);
171 bool backspace() {
172 return trans_fsm_.currentState->backspace();
175 void TranslateAndInsert(char, LyXText *);
177 std::string const deadkey(char, KmodInfo);
179 std::string const normalkey(char);
181 void deadkey(char, tex_accent, LyXText *);
185 inline
186 std::string const TransManager::normalkey(char c)
188 return trans_fsm_.currentState->normalkey(c);
192 inline
193 std::string const TransManager::deadkey(char c, KmodInfo t)
195 return trans_fsm_.currentState->deadkey(c, t);
198 #endif // TRANS_MANAGER_H