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"
72 TEX_MAX_ACCENT = TEX_OGONEK
79 /// UCS4 code point of this accent
88 extern TeXAccent get_accent(FuncCode action);
94 Keyexc() : c('\0'), combined(false), accent(TEX_NOACCENT) {}
95 /// character to make exception
99 /// Combination with another deadkey
101 /// The accent comined with
106 typedef std::list<Keyexc> KmodException;
112 KmodInfo() : accent(TEX_NOACCENT) {}
118 KmodException exception_list;
122 /////////////////////////////////////////////////////////////////////
124 // Trans: holds a .kmap file
126 /////////////////////////////////////////////////////////////////////
133 ~Trans() { freeKeymap(); }
136 int load(std::string const & language);
138 bool isDefined() const;
140 std::string const & getName() const { return name_; }
142 docstring const process(char_type, TransManager &);
144 bool isAccentDefined(tex_accent, KmodInfo &) const;
148 void addDeadkey(tex_accent, docstring const &);
154 docstring const & match(char_type c);
156 void insertException(KmodException & exclist, char_type c,
157 docstring const & data, bool = false,
158 tex_accent = TEX_NOACCENT);
160 void freeException(KmodException & exclist);
165 std::map<char_type, docstring> keymap_;
167 std::map<tex_accent, KmodInfo> kmod_list_;
172 inline docstring const & Trans::match(char_type c)
174 std::map<char_type, docstring>::iterator it = keymap_.find(c);
175 if (it != keymap_.end()) {
178 static docstring dummy;
183 /////////////////////////////////////////////////////////////////////
187 /////////////////////////////////////////////////////////////////////
189 /// Translation state
193 virtual ~TransState() {}
195 virtual docstring const normalkey(char_type) = 0;
197 virtual bool backspace() = 0;
199 virtual docstring const deadkey(char_type, KmodInfo) = 0;
201 static char_type const TOKEN_SEP;
209 virtual ~TransFSMData() {}
213 KmodInfo deadkey_info_;
217 KmodInfo deadkey2_info_;
221 TransState * init_state_;
223 TransState * deadkey_state_;
225 TransState * combined_state_;
231 TransState * currentState;
236 class TransInitState : virtual public TransFSMData, public TransState {
241 docstring const normalkey(char_type) override;
243 bool backspace() override { return true; }
245 docstring const deadkey(char_type, KmodInfo) override;
250 class TransDeadkeyState : virtual public TransFSMData, public TransState {
255 docstring const normalkey(char_type) override;
257 bool backspace() override {
258 currentState = init_state_;
262 docstring const deadkey(char_type, KmodInfo) override;
267 class TransCombinedState : virtual public TransFSMData, public TransState {
270 TransCombinedState();
272 docstring const normalkey(char_type) override;
274 bool backspace() override {
275 // cancel the second deadkey
277 deadkey2_info_.accent = TEX_NOACCENT;
278 currentState = deadkey_state_;
283 docstring const deadkey(char_type, KmodInfo) override;
288 class TransFSM : virtual public TransFSMData,
289 public TransInitState,
290 public TransDeadkeyState,
291 public TransCombinedState {
299 /////////////////////////////////////////////////////////////////////
303 /////////////////////////////////////////////////////////////////////
316 static Trans default_;
318 void insert(docstring const &, Text *, Cursor & cur);
323 int setPrimary(std::string const &);
325 int setSecondary(std::string const &);
327 void enablePrimary();
329 void enableSecondary();
331 void disableKeymap();
333 bool backspace() { return trans_fsm_.currentState->backspace(); }
335 void translateAndInsert(char_type, Text *, Cursor &);
337 docstring const deadkey(char_type c, KmodInfo t)
338 { return trans_fsm_.currentState->deadkey(c, t); }
340 docstring const normalkey(char_type c)
341 { return trans_fsm_.currentState->normalkey(c); }
343 void deadkey(char_type, tex_accent, Text *, Cursor &);