X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftrans_mgr.C;h=88b4190e48ee0d3922946376850910e04c3e089b;hb=068e2cfb25bfbab62f80bc0c776ca169032c2219;hp=26beac92ef2753463adbfbac375118410785afdc;hpb=5f3f9ad231bc0c24d34c00e3936e226d9834589a;p=lyx.git diff --git a/src/trans_mgr.C b/src/trans_mgr.C index 26beac92ef..88b4190e48 100644 --- a/src/trans_mgr.C +++ b/src/trans_mgr.C @@ -16,10 +16,11 @@ #include "lyxrc.h" #include "support/lstrings.h" -extern LyXRC * lyxrc; -extern string DoAccent(string const &, tex_accent); -extern void InsertCorrectQuote(); -extern string DoAccent(char, tex_accent); +using std::endl; +using std::pair; + +extern string const DoAccent(string const &, tex_accent); +extern string const DoAccent(char, tex_accent); extern BufferView * current_view; @@ -43,17 +44,17 @@ TransInitState::TransInitState() } -string TransInitState::normalkey(char c, char * t) +string const TransInitState::normalkey(char c, string const & t) { string res; - if (t) res = t; + if (!t.empty()) res = t; else res = c; return res; } -string TransInitState::deadkey(char c, KmodInfo d) +string const TransInitState::deadkey(char c, KmodInfo d) { deadkey_ = c; deadkey_info_ = d; @@ -69,7 +70,7 @@ TransDeadkeyState::TransDeadkeyState() } -string TransDeadkeyState::normalkey(char c, char * trans) +string const TransDeadkeyState::normalkey(char c, string const & trans) { string res; @@ -84,8 +85,7 @@ string TransDeadkeyState::normalkey(char c, char * trans) } if (l == 0) { // Not an exception. Check if it allowed - if (current_view->buffer()->params.allowAccents == true || - countChar(deadkey_info_.allowed, c) > 0) { + if (countChar(deadkey_info_.allowed, c) > 0) { res = DoAccent(c, deadkey_info_.accent); } else { // Not allowed @@ -100,7 +100,7 @@ string TransDeadkeyState::normalkey(char c, char * trans) } -string TransDeadkeyState::deadkey(char c, KmodInfo d) +string const TransDeadkeyState::deadkey(char c, KmodInfo d) { string res; @@ -153,7 +153,7 @@ TransCombinedState::TransCombinedState() } -string TransCombinedState::normalkey(char c, char * trans) +string const TransCombinedState::normalkey(char c, string const & trans) { string res; @@ -177,7 +177,7 @@ string TransCombinedState::normalkey(char c, char * trans) } -string TransCombinedState::deadkey(char c, KmodInfo d) +string const TransCombinedState::deadkey(char c, KmodInfo d) { // Third key in a row. Output the first one and // reenter with shifted deadkeys @@ -205,14 +205,15 @@ TransFSM::TransFSM(): // TransManager +// Initialize static member. +Trans TransManager::default_; + + TransManager::TransManager() : active_(0), t1_(new Trans), t2_(new Trans) {} -Trans * TransManager::default_ = new Trans; - - TransManager::~TransManager() { delete t1_; @@ -238,9 +239,9 @@ int TransManager::SetSecondary(string const & language) } -bool TransManager::setCharset(char const * set) +bool TransManager::setCharset(string const & str) { - return chset_.loadFile(set); + return chset_.loadFile(str); } @@ -263,7 +264,7 @@ void TransManager::EnableSecondary() void TransManager::DisableKeymap() { - active_ = default_; + active_ = &default_; lyxerr[Debug::KBMAP] << "Disabling keymap" << endl; } @@ -284,20 +285,22 @@ void TransManager::TranslateAndInsert(char c, LyXText * text) void TransManager::insertVerbatim(string const & str, LyXText * text) { - int l = str.length(); + string::size_type const l = str.length(); - for (int i = 0; i < l; ++i){ + for (string::size_type i = 0; i < l; ++i) { if (str[i] == '\"' - && text->GetFont(text->cursor.par, - text->cursor.pos).latex() == LyXFont::OFF) - InsertCorrectQuote(); + && text->GetFont(current_view->buffer(),text->cursor.par(), + text->cursor.pos()).latex() == LyXFont::OFF + && text->GetFont(current_view->buffer(),text->cursor.par(), + text->cursor.pos()).language()->lang() != "hebrew") + current_view->insertCorrectQuote(); else - text->InsertChar(str[i]); + text->InsertChar(current_view, str[i]); } } -void TransManager::insert(string str, LyXText * text) +void TransManager::insert(string const & str, LyXText * text) { // Go through the character encoding only if the current // encoding (chset_->name()) matches the current font_norm @@ -306,12 +309,12 @@ void TransManager::insert(string str, LyXText * text) // Is false to speak about "only if" the current encoding will // almost always be equal to font_norm. pair enc = chset_.encodeString(str); - if (chset_.getName() != lyxrc->font_norm || + if (chset_.getName() != lyxrc.font_norm || !enc.first) { // Could not find an encoding InsetLatexAccent ins(str); if (ins.CanDisplay()) { - text->InsertInset(new InsetLatexAccent(ins)); + text->InsertInset(current_view, new InsetLatexAccent(ins)); } else { insertVerbatim(str, text); } @@ -324,7 +327,7 @@ void TransManager::insert(string str, LyXText * text) void TransManager::deadkey(char c, tex_accent accent, LyXText * t) { - if (c == 0 && active_ != default_) { + if (c == 0 && active_ != &default_) { // A deadkey was pressed that cannot be printed // or a accent command was typed in the minibuffer KmodInfo i; @@ -335,11 +338,11 @@ void TransManager::deadkey(char c, tex_accent accent, LyXText * t) } } - if (active_ == default_ || c == 0) { + if (active_ == &default_ || c == 0) { KmodInfo i; i.accent = accent; i.allowed = lyx_accent_table[accent].native; - i.data.clear(); + i.data.erase(); i.exception_list = 0; string res = trans_fsm_.currentState->deadkey(c, i);