9 #include "insets/insetlatexaccent.h"
10 #include "BufferView.h"
13 #include "support/lstrings.h"
18 extern string const DoAccent(string const &, tex_accent);
19 extern string const DoAccent(char, tex_accent);
23 TransFSMData::TransFSMData()
25 deadkey_ = deadkey2_ = 0;
26 deadkey_info_.accent = deadkey2_info_.accent = TEX_NOACCENT;
31 char const TransState::TOKEN_SEP = 4;
35 TransInitState::TransInitState()
41 string const TransInitState::normalkey(char c)
49 string const TransInitState::deadkey(char c, KmodInfo d)
53 currentState = deadkey_state_;
59 TransDeadkeyState::TransDeadkeyState()
61 deadkey_state_ = this;
65 string const TransDeadkeyState::normalkey(char c)
69 KmodException::iterator it = deadkey_info_.exception_list.begin();
70 KmodException::iterator end = deadkey_info_.exception_list.end();
72 for (; it != end; ++it) {
79 res = DoAccent(c, deadkey_info_.accent);
81 currentState = init_state_;
86 string const TransDeadkeyState::deadkey(char c, KmodInfo d)
90 // Check if the same deadkey was typed twice
94 deadkey_info_.accent = TEX_NOACCENT;
95 currentState = init_state_;
99 // Check if it is a combination or an exception
100 KmodException::const_iterator cit = deadkey_info_.exception_list.begin();
101 KmodException::const_iterator end = deadkey_info_.exception_list.end();
102 for (; cit != end; ++cit) {
103 if (cit->combined == true && cit->accent == d.accent) {
107 currentState = combined_state_;
113 deadkey_info_.accent = TEX_NOACCENT;
114 currentState = init_state_;
119 // Not a combination or an exception.
120 // Output deadkey1 and keep deadkey2
126 currentState = deadkey_state_;
131 TransCombinedState::TransCombinedState()
133 combined_state_ = this;
137 string const TransCombinedState::normalkey(char c)
139 string const temp = DoAccent(c, deadkey2_info_.accent);
140 string const res = DoAccent(temp, deadkey_info_.accent);
141 currentState = init_state_;
146 string const TransCombinedState::deadkey(char c, KmodInfo d)
148 // Third key in a row. Output the first one and
149 // reenter with shifted deadkeys
154 deadkey_ = deadkey2_;
155 deadkey_info_ = deadkey2_info_;
156 res += deadkey_state_->deadkey(c, d);
162 TransFSM::TransFSM():
168 currentState = init_state_;
174 // Initialize static member.
175 Trans TransManager::default_;
178 TransManager::TransManager()
179 : active_(0), t1_(new Trans), t2_(new Trans)
183 TransManager::~TransManager()
190 int TransManager::SetPrimary(string const & language)
192 if (t1_->GetName() == language)
195 return t1_->Load(language);
199 int TransManager::SetSecondary(string const & language)
201 if (t2_->GetName() == language)
204 return t2_->Load(language);
208 bool TransManager::setCharset(string const & str)
210 return chset_.loadFile(str);
214 void TransManager::EnablePrimary()
216 if (t1_->IsDefined())
219 lyxerr[Debug::KBMAP] << "Enabling primary keymap" << endl;
223 void TransManager::EnableSecondary()
225 if (t2_->IsDefined())
227 lyxerr[Debug::KBMAP] << "Enabling secondary keymap" << endl;
231 void TransManager::DisableKeymap()
234 lyxerr[Debug::KBMAP] << "Disabling keymap" << endl;
238 void TransManager::TranslateAndInsert(char c, LyXText * text)
240 string res = active_->process(c, *this);
242 // Process with tokens
245 while (res.length() > 0) {
246 res = split(res, temp, TransState::TOKEN_SEP);
252 void TransManager::insertVerbatim(string const & str, LyXText * text)
254 string::size_type const l = str.length();
256 for (string::size_type i = 0; i < l; ++i) {
257 text->insertChar(str[i]);
262 void TransManager::insert(string const & str, LyXText * text)
264 // Go through the character encoding only if the current
265 // encoding (chset_->name()) matches the current font_norm
266 // (lyrxc->font_norm)
268 // Is false to speak about "only if" the current encoding will
269 // almost always be equal to font_norm.
270 pair<bool, int> enc = chset_.encodeString(str);
271 if (chset_.getName() != lyxrc.font_norm ||
273 // Could not find an encoding
274 InsetLatexAccent ins(str);
275 if (ins.canDisplay()) {
277 new InsetLatexAccent(ins));
279 insertVerbatim(str, text);
284 tmp += static_cast<char>(enc.second);
285 insertVerbatim(tmp, text);
289 void TransManager::deadkey(char c, tex_accent accent, LyXText * t)
291 if (c == 0 && active_ != &default_) {
292 // A deadkey was pressed that cannot be printed
293 // or a accent command was typed in the minibuffer
295 if (active_->isAccentDefined(accent, i) == true) {
296 string const res = trans_fsm_
297 .currentState->deadkey(c, i);
303 if (active_ == &default_ || c == 0) {
307 string res = trans_fsm_.currentState->deadkey(c, i);
310 // Go through the translation
311 TranslateAndInsert(c, t);