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
11 * Full author contact details are available in file CREDITS.
19 #include "support/docstring.h"
31 namespace support { class Lexer; }
73 TEX_MAX_ACCENT = TEX_OGONEK
80 /// UCS4 code point of this accent
89 extern TeXAccent get_accent(FuncCode action);
95 Keyexc() : c('\0'), combined(false), accent(TEX_NOACCENT) {}
96 /// character to make exception
100 /// Combination with another deadkey
102 /// The accent comined with
107 typedef std::list<Keyexc> KmodException;
113 KmodInfo() : accent(TEX_NOACCENT) {}
119 KmodException exception_list;
123 /////////////////////////////////////////////////////////////////////
125 // Trans: holds a .kmap file
127 /////////////////////////////////////////////////////////////////////
134 ~Trans() { freeKeymap(); }
137 int load(std::string const & language);
139 bool isDefined() const;
141 std::string const & getName() const { return name_; }
143 docstring const process(char_type, TransManager &);
145 bool isAccentDefined(tex_accent, KmodInfo &) const;
149 void addDeadkey(tex_accent, docstring const &);
153 int load(support::Lexer &);
155 docstring const & match(char_type c);
157 void insertException(KmodException & exclist, char_type c,
158 docstring const & data, bool = false,
159 tex_accent = TEX_NOACCENT);
161 void freeException(KmodException & exclist);
166 std::map<char_type, docstring> keymap_;
168 std::map<tex_accent, KmodInfo> kmod_list_;
173 inline docstring const & Trans::match(char_type c)
175 std::map<char_type, docstring>::iterator it = keymap_.find(c);
176 if (it != keymap_.end()) {
179 static docstring dummy;
184 /////////////////////////////////////////////////////////////////////
188 /////////////////////////////////////////////////////////////////////
190 /// Translation state
194 virtual ~TransState() {}
196 virtual docstring const normalkey(char_type) = 0;
198 virtual bool backspace() = 0;
200 virtual docstring const deadkey(char_type, KmodInfo) = 0;
202 static char_type const TOKEN_SEP;
210 virtual ~TransFSMData() {}
214 KmodInfo deadkey_info_;
218 KmodInfo deadkey2_info_;
222 TransState * init_state_;
224 TransState * deadkey_state_;
226 TransState * combined_state_;
232 TransState * currentState;
237 class TransInitState : virtual public TransFSMData, public TransState {
242 docstring const normalkey(char_type) override;
244 bool backspace() override { return true; }
246 docstring const deadkey(char_type, KmodInfo) override;
251 class TransDeadkeyState : virtual public TransFSMData, public TransState {
256 docstring const normalkey(char_type) override;
258 bool backspace() override {
259 currentState = init_state_;
263 docstring const deadkey(char_type, KmodInfo) override;
268 class TransCombinedState : virtual public TransFSMData, public TransState {
271 TransCombinedState();
273 docstring const normalkey(char_type) override;
275 bool backspace() override {
276 // cancel the second deadkey
278 deadkey2_info_.accent = TEX_NOACCENT;
279 currentState = deadkey_state_;
284 docstring const deadkey(char_type, KmodInfo) override;
289 class TransFSM : virtual public TransFSMData,
290 public TransInitState,
291 public TransDeadkeyState,
292 public TransCombinedState {
300 /////////////////////////////////////////////////////////////////////
304 /////////////////////////////////////////////////////////////////////
317 static Trans default_;
319 void insert(docstring const &, Text *, Cursor & cur);
324 int setPrimary(std::string const &);
326 int setSecondary(std::string const &);
328 void enablePrimary();
330 void enableSecondary();
332 void disableKeymap();
334 bool backspace() { return trans_fsm_.currentState->backspace(); }
336 void translateAndInsert(char_type, Text *, Cursor &);
338 docstring const deadkey(char_type c, KmodInfo t)
339 { return trans_fsm_.currentState->deadkey(c, t); }
341 docstring const normalkey(char_type c)
342 { return trans_fsm_.currentState->normalkey(c); }
344 void deadkey(char_type, tex_accent, Text *, Cursor &);