3 #pragma implementation "trans_mgr.h"
13 #include "insets/insetlatexaccent.h"
14 #include "BufferView.h"
19 extern LString DoAccent(const LString&,tex_accent);
20 extern void InsertCorrectQuote();
21 extern LString DoAccent(char,tex_accent);
22 extern BufferView* current_view;
26 TransFSMData::TransFSMData()
29 deadkey_info_.accent=deadkey2_info_.accent=TEX_NOACCENT;
35 const char TransState::TOKEN_SEP=4;
38 TransState::~TransState()
43 TransInitState::TransInitState()
49 LString TransInitState::normalkey(char c,char *t)
61 //bool TransInitState::backspace()
67 LString TransInitState::deadkey(char c,KmodInfo d)
71 currentState=deadkey_state_;
77 TransDeadkeyState::TransDeadkeyState()
83 LString TransDeadkeyState::normalkey(char c,char *trans)
87 // Check if it is an exception
88 KmodException l=deadkey_info_.exception_list;
97 // Not an exception. Check if it allowed
98 if (current_view->currentBuffer()->params.allowAccents==true ||
99 deadkey_info_.allowed.countChar(c)>0) {
100 res=DoAccent(c,deadkey_info_.accent);
109 currentState=init_state_;
114 //bool TransDeadkeyState::backspace()
116 // currentState=init_state_;
121 LString TransDeadkeyState::deadkey(char c,KmodInfo d)
125 // Check if the same deadkey was typed twice
129 deadkey_info_.accent=TEX_NOACCENT;
130 currentState=init_state_;
134 // Check if it is a combination or an exception
136 l=deadkey_info_.exception_list;
139 if (l->combined==true && l->accent==d.accent) {
143 currentState=combined_state_;
149 deadkey_info_.accent=TEX_NOACCENT;
150 currentState=init_state_;
157 // Not a combination or an exception.
158 // Output deadkey1 and keep deadkey2
164 currentState=deadkey_state_;
169 TransCombinedState::TransCombinedState()
171 combined_state_=this;
175 LString TransCombinedState::normalkey(char c,char *trans)
179 // Check if the key is allowed on the combination
180 if (comb_info_->data.countChar(c)>0) {
182 temp=DoAccent(c,deadkey2_info_.accent);
183 res=DoAccent(temp,deadkey_info_.accent);
184 currentState=init_state_;
186 // Not allowed. Output deadkey1 and check deadkey2 + c
191 deadkey_info_=deadkey2_info_;
192 // Call deadkey state and leave it to setup the FSM
193 res+=deadkey_state_->normalkey(c,trans);
199 // bool TransCombinedState::backspace()
201 // // cancel the second deadkey
203 // deadkey2_info_.accent=TEX_NOACCENT;
204 // currentState=deadkey_state_;
210 LString TransCombinedState::deadkey(char c,KmodInfo d)
212 // Third key in a row. Output the first one and
213 // reenter with shifted deadkeys
219 deadkey_info_=deadkey2_info_;
220 res+=deadkey_state_->deadkey(c,d);
226 TransFSM::TransFSM():
232 currentState=init_state_;
238 TransManager::TransManager()
239 : active_(NULL),t1_(new Trans),t2_(new Trans),chset_(new CharacterSet)
243 Trans* TransManager::default_=new Trans;
246 TransManager::~TransManager()
254 int TransManager::SetPrimary(LString const & language)
256 if (t1_->GetName()==language)
259 return t1_->Load(language);
263 int TransManager::SetSecondary(LString const & language)
265 if (t2_->GetName()==language)
268 return t2_->Load(language);
272 bool TransManager::setCharset(const char *set)
274 return chset_->loadFile(set);
278 void TransManager::EnablePrimary()
280 if (t1_->IsDefined())
283 lyxerr.debug("Enabling primary keymap",Error::KBMAP);
287 void TransManager::EnableSecondary()
289 if (t2_->IsDefined( ))
291 lyxerr.debug("Enabling secondary keymap",Error::KBMAP);
295 void TransManager::DisableKeymap()
298 lyxerr.debug("Disabling keymap",Error::KBMAP);
302 void TransManager::TranslateAndInsert(char c,LyXText *text)
306 res=active_->process(c,*this);
308 // Process with tokens
311 while(res.length()>0) {
312 res.split(temp,TransState::TOKEN_SEP);
318 void TransManager::insertVerbatim(const LString& str,LyXText *text)
322 for (int i=0;i<l;i++){
324 && text->GetFont(text->cursor.par,
325 text->cursor.pos).latex() == LyXFont::OFF)
326 InsertCorrectQuote();
328 text->InsertChar(str[i]);
333 void TransManager::insert(LString str,LyXText *text)
337 // Go through the character encoding only if the current
338 // encoding (chset_->name()) matches the current font_norm
341 if (chset_->getName()!=lyxrc->font_norm ||
342 chset_->encodeString(str)==false) {
343 // Could not find an encoding
344 InsetLatexAccent ins(str);
345 if (ins.CanDisplay()) {
346 text->InsertInset(new InsetLatexAccent(ins));
351 insertVerbatim(str,text);
355 //bool TransManager::backspace()
357 // return trans_fsm_.currentState->backspace();
361 void TransManager::deadkey(char c,tex_accent accent,LyXText *t)
366 if (c==0 && active_!=default_) {
367 // A deadkey was pressed that cannot be printed
368 // or a accent command was typed in the minibuffer
370 if (active_->isAccentDefined(accent,i)==true) {
371 res=trans_fsm_.currentState->deadkey(c,i);
376 // Fall through to the next case
379 if (active_==default_ || c==0) {
381 i.allowed=lyx_accent_table[accent].native;
383 i.exception_list=NULL;
385 LString res=trans_fsm_.currentState->deadkey(c,i);
388 // Go through the translation
389 TranslateAndInsert(c,t);