From c4033d401202ffc57b5a04ef9cf83b494b7ddfa0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 2 Oct 2007 21:51:54 +0000 Subject: [PATCH] cosmetics git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20671 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/KeyMap.cpp | 22 +++++------- src/KeyMap.h | 13 ++++--- src/KeySequence.cpp | 20 +++++------ src/KeySequence.h | 16 ++++----- src/LyXFunc.cpp | 37 +++++++++----------- src/LyXFunc.h | 4 +-- src/frontends/{key_state.h => KeyModifier.h} | 25 ++++++------- src/frontends/KeySymbol.h | 6 ++-- src/frontends/Makefile.am | 2 +- src/frontends/WorkArea.cpp | 10 +++--- src/frontends/WorkArea.h | 7 ++-- src/frontends/qt4/GuiKeySymbol.cpp | 32 +++++++---------- src/frontends/qt4/GuiKeySymbol.h | 2 +- src/frontends/qt4/GuiView.cpp | 2 +- 14 files changed, 88 insertions(+), 110 deletions(-) rename src/frontends/{key_state.h => KeyModifier.h} (51%) diff --git a/src/KeyMap.cpp b/src/KeyMap.cpp index 69aa1ec605..8e4458d485 100644 --- a/src/KeyMap.cpp +++ b/src/KeyMap.cpp @@ -20,8 +20,6 @@ #include "LyXAction.h" #include "Lexer.h" -#include "frontends/KeySymbol.h" - #include "support/filetools.h" #include @@ -36,18 +34,17 @@ using support::FileName; using support::i18nLibFileSearch; -string const KeyMap::printKeySym(KeySymbol const & key, - key_modifier::state mod) +string const KeyMap::printKeySym(KeySymbol const & key, KeyModifier mod) { string buf; string const s = key.getSymbolName(); - if (mod & key_modifier::shift) + if (mod & ShiftModifier) buf += "S-"; - if (mod & key_modifier::ctrl) + if (mod & ControlModifier) buf += "C-"; - if (mod & key_modifier::alt) + if (mod & AltModifier) buf += "M-"; buf += s; @@ -171,7 +168,7 @@ bool KeyMap::read(string const & bind_file) FuncRequest const & KeyMap::lookup(KeySymbol const &key, - key_modifier::state mod, KeySequence * seq) const + KeyModifier mod, KeySequence * seq) const { static FuncRequest const unknown(LFUN_UNKNOWN_ACTION); @@ -183,9 +180,8 @@ FuncRequest const & KeyMap::lookup(KeySymbol const &key, Table::const_iterator end = table.end(); for (Table::const_iterator cit = table.begin(); cit != end; ++cit) { - key_modifier::state mask(cit->mod.second); - key_modifier::state check = - static_cast(mod & ~mask); + KeyModifier mask = cit->mod.second; + KeyModifier check = static_cast(mod & ~mask); if (cit->code == key && cit->mod.first == check) { // match found @@ -229,8 +225,8 @@ void KeyMap::defkey(KeySequence * seq, FuncRequest const & func, unsigned int r) if (!code.isOK()) return; - key_modifier::state const mod1 = seq->modifiers[r].first; - key_modifier::state const mod2 = seq->modifiers[r].second; + KeyModifier const mod1 = seq->modifiers[r].first; + KeyModifier const mod2 = seq->modifiers[r].second; // check if key is already there Table::iterator end = table.end(); diff --git a/src/KeyMap.h b/src/KeyMap.h index 8dad6fa805..bb28d37433 100644 --- a/src/KeyMap.h +++ b/src/KeyMap.h @@ -16,7 +16,7 @@ #include "FuncRequest.h" -#include "frontends/key_state.h" +#include "frontends/KeyModifier.h" #include "frontends/KeySymbol.h" #include "support/docstream.h" @@ -60,8 +60,7 @@ public: * @return the action / LFUN_COMMAND_PREFIX / LFUN_UNKNOWN_ACTION */ FuncRequest const & - lookup(KeySymbol const & key, - key_modifier::state mod, KeySequence * seq) const; + lookup(KeySymbol const & key, KeyModifier mod, KeySequence * seq) const; /// typedef std::deque Bindings; @@ -77,7 +76,7 @@ public: * The KeySymbol pointer is 0 is no key is found. * [only used by the Qt/Mac frontend] */ - std::pair + std::pair find1keybinding(FuncRequest const & func) const; @@ -87,9 +86,9 @@ public: * @param mod the modifiers */ static std::string const printKeySym(KeySymbol const & key, - key_modifier::state mod); + KeyModifier mod); - typedef std::pair modifier_pair; + typedef std::pair ModifierPair; private: /// @@ -98,7 +97,7 @@ private: KeySymbol code; /// Modifier masks - modifier_pair mod; + ModifierPair mod; /// Keymap for prefix keys boost::shared_ptr table; diff --git a/src/KeySequence.cpp b/src/KeySequence.cpp index 1967738874..fa354003ea 100644 --- a/src/KeySequence.cpp +++ b/src/KeySequence.cpp @@ -27,7 +27,7 @@ using std::string; namespace lyx { FuncRequest const & KeySequence::addkey(KeySymbol const & key, - key_modifier::state mod, key_modifier::state nmod) + KeyModifier mod, KeyModifier nmod) { // adding a key to a deleted sequence // starts a new sequence @@ -55,8 +55,8 @@ size_t KeySequence::parse(string const & s) return 1; size_t i = 0; - key_modifier::state mod = key_modifier::none; - key_modifier::state nmod = key_modifier::none; + KeyModifier mod = NoModifier; + KeyModifier nmod = NoModifier; while (i < s.length()) { if (s[i] == ' ') @@ -67,15 +67,15 @@ size_t KeySequence::parse(string const & s) if (i + 1 < s.length() && s[i + 1] == '-') { switch (s[i]) { case 's': case 'S': - mod |= key_modifier::shift; + mod |= ShiftModifier; i += 2; continue; case 'c': case 'C': - mod |= key_modifier::ctrl; + mod |= ControlModifier; i += 2; continue; case 'm': case 'M': - mod |= key_modifier::alt; + mod |= AltModifier; i += 2; continue; default: @@ -85,15 +85,15 @@ size_t KeySequence::parse(string const & s) && s[i + 2] == '-') { switch (s[i + 1]) { case 's': case 'S': - nmod |= key_modifier::shift; + nmod |= ShiftModifier; i += 3; continue; case 'c': case 'C': - nmod |= key_modifier::ctrl; + nmod |= ControlModifier; i += 3; continue; case 'm': case 'M': - nmod |= key_modifier::alt; + nmod |= AltModifier; i += 3; continue; default: @@ -114,7 +114,7 @@ size_t KeySequence::parse(string const & s) i = j; addkey(key, mod, nmod); - mod = key_modifier::none; + mod = NoModifier; } } diff --git a/src/KeySequence.h b/src/KeySequence.h index e39d6e2d35..b59e86d2df 100644 --- a/src/KeySequence.h +++ b/src/KeySequence.h @@ -10,10 +10,10 @@ * Full author contact details are available in file CREDITS. */ -#ifndef KB_SEQUENCE_H -#define KB_SEQUENCE_H +#ifndef KEYSEQUENCE_H +#define KEYSEQUENCE_H -#include "frontends/key_state.h" +#include "frontends/KeyModifier.h" #include "frontends/KeySymbol.h" #include @@ -45,9 +45,8 @@ public: * @param nmod which modifiers to mask out for equality test * @return the action matching this key sequence or LFUN_UNKNOWN_ACTION */ - FuncRequest const & - addkey(KeySymbol const & keysym, key_modifier::state mod, - key_modifier::state nmod = key_modifier::none); + FuncRequest const & addkey(KeySymbol const & keysym, KeyModifier mod, + KeyModifier nmod = NoModifier); /** * Add a sequence of keys from a string to the sequence @@ -105,11 +104,10 @@ private: */ Sequence sequence; - typedef std::pair - modifier_pair; + typedef std::pair ModifierPair; /// modifiers for keys in the sequence - std::vector modifiers; + std::vector modifiers; /// is keysequence deleted ? bool deleted_; diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index e0eafe9b99..37a8fd59b3 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -202,7 +202,7 @@ Change::Type lookupChangeType(DocIterator const & dit, bool outer = false) LyXFunc::LyXFunc() - : lyx_view_(0), encoded_last_key(0), meta_fake_bit(key_modifier::none) + : lyx_view_(0), encoded_last_key(0), meta_fake_bit(NoModifier) { } @@ -289,8 +289,7 @@ void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer) } -void LyXFunc::processKeySym(KeySymbol const & keysym, - key_modifier::state state) +void LyXFunc::processKeySym(KeySymbol const & keysym, KeyModifier state) { LYXERR(Debug::KEY) << "KeySym is " << keysym.getSymbolName() << endl; @@ -323,7 +322,7 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, // When not cancel or meta-fake, do the normal lookup. // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards. - // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5. + // Mostly, meta_fake_bit = NoModifier. RVDK_PATCH_5. if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_PREFIX)) { // remove Caps Lock and Mod2 as a modifiers func = keyseq.addkey(keysym, (state | meta_fake_bit)); @@ -333,12 +332,11 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, } // Dont remove this unless you know what you are doing. - meta_fake_bit = key_modifier::none; + meta_fake_bit = NoModifier; // Can this happen now ? - if (func.action == LFUN_NOACTION) { + if (func.action == LFUN_NOACTION) func = FuncRequest(LFUN_COMMAND_PREFIX); - } LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION << " Key [action=" @@ -350,17 +348,15 @@ void LyXFunc::processKeySym(KeySymbol const & keysym, // why not return already here if action == -1 and // num_bytes == 0? (Lgb) - if (keyseq.length() > 1) { + if (keyseq.length() > 1) lyx_view_->message(keyseq.print(true)); - } // Maybe user can only reach the key via holding down shift. // Let's see. But only if shift is the only modifier - if (func.action == LFUN_UNKNOWN_ACTION && - state == key_modifier::shift) { + if (func.action == LFUN_UNKNOWN_ACTION && state == ShiftModifier) { LYXERR(Debug::KEY) << "Trying without shift" << endl; - func = keyseq.addkey(keysym, key_modifier::none); + func = keyseq.addkey(keysym, NoModifier); LYXERR(Debug::KEY) << "Action now " << func.action << endl; } @@ -894,7 +890,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) case LFUN_CANCEL: BOOST_ASSERT(lyx_view_ && lyx_view_->view()); keyseq.reset(); - meta_fake_bit = key_modifier::none; + meta_fake_bit = NoModifier; if (lyx_view_->buffer()) // cancel any selection dispatch(FuncRequest(LFUN_MARK_OFF)); @@ -902,18 +898,19 @@ void LyXFunc::dispatch(FuncRequest const & cmd) break; case LFUN_META_PREFIX: - meta_fake_bit = key_modifier::alt; + meta_fake_bit = AltModifier; setMessage(keyseq.print(true)); break; - case LFUN_BUFFER_TOGGLE_READ_ONLY: + case LFUN_BUFFER_TOGGLE_READ_ONLY: { BOOST_ASSERT(lyx_view_ && lyx_view_->view() && lyx_view_->buffer()); - if (lyx_view_->buffer()->lyxvc().inUse()) - lyx_view_->buffer()->lyxvc().toggleReadOnly(); + Buffer * buf = lyx_view_->buffer(); + if (buf->lyxvc().inUse()) + buf->lyxvc().toggleReadOnly(); else - lyx_view_->buffer()->setReadonly( - !lyx_view_->buffer()->isReadonly()); + buf->setReadonly(!lyx_view_->buffer()->isReadonly()); break; + } // --- Menus ----------------------------------------------- case LFUN_BUFFER_NEW: @@ -2312,7 +2309,7 @@ BufferView * LyXFunc::view() const bool LyXFunc::wasMetaKey() const { - return (meta_fake_bit != key_modifier::none); + return (meta_fake_bit != NoModifier); } diff --git a/src/LyXFunc.h b/src/LyXFunc.h index 56c5f7cf7e..6dc89890bd 100644 --- a/src/LyXFunc.h +++ b/src/LyXFunc.h @@ -60,7 +60,7 @@ public: docstring const viewStatusMessage(); /// - void processKeySym(KeySymbol const & key, key_modifier::state state); + void processKeySym(KeySymbol const & key, KeyModifier state); /// FuncStatus getStatus(FuncRequest const & action) const; @@ -99,7 +99,7 @@ private: /// KeySequence cancel_meta_seq; /// - key_modifier::state meta_fake_bit; + KeyModifier meta_fake_bit; /// Error status, only Dispatch can change this flag mutable bool errorstat; diff --git a/src/frontends/key_state.h b/src/frontends/KeyModifier.h similarity index 51% rename from src/frontends/key_state.h rename to src/frontends/KeyModifier.h index 94736ecdc8..db5beffd43 100644 --- a/src/frontends/key_state.h +++ b/src/frontends/KeyModifier.h @@ -11,37 +11,34 @@ * Full author contact details are available in file CREDITS. */ -#ifndef KEY_STATE_H -#define KEY_STATE_H +#ifndef KEYMODIFIER_H +#define KEYMODIFIER_H namespace lyx { /// modifier key states -namespace key_modifier { -enum state { - none = 0, //< no modifiers held - ctrl = 1, //< control button held - alt = 2, //< alt/meta key held - shift = 4 //< shift key held +enum KeyModifier { + NoModifier = 0, //< no modifiers held + ControlModifier = 1, //< control button held + AltModifier = 2, //< alt/meta key held + ShiftModifier = 4 //< shift key held }; -inline state operator|(state const & s1, state const & s2) +inline KeyModifier operator|(KeyModifier s1, KeyModifier s2) { int const i1 = static_cast(s1); int const i2 = static_cast(s2); - return static_cast(i1 | i2); + return static_cast(i1 | i2); } -inline void operator|=(state & s1, state s2) +inline void operator|=(KeyModifier & s1, KeyModifier s2) { - s1 = static_cast(s1 | s2); + s1 = static_cast(s1 | s2); } -} // namespace key_modifier - } // namespace lyx diff --git a/src/frontends/KeySymbol.h b/src/frontends/KeySymbol.h index c60651f8dd..dc71a966e6 100644 --- a/src/frontends/KeySymbol.h +++ b/src/frontends/KeySymbol.h @@ -12,9 +12,7 @@ #ifndef KEYSYMBOL_H #define KEYSYMBOL_H -#include - -#include "key_state.h" +#include "KeyModifier.h" #include "support/docstring.h" @@ -58,7 +56,7 @@ public: * Use the native UI format when \c forgui is true. * i.e. (translated and with special characters for Mac OS X) */ - docstring const print(key_modifier::state mod, bool forgui) const; + docstring const print(KeyModifier mod, bool forgui) const; /// int key() const { return key_; } diff --git a/src/frontends/Makefile.am b/src/frontends/Makefile.am index e6b6412606..c9dbfa3c48 100644 --- a/src/frontends/Makefile.am +++ b/src/frontends/Makefile.am @@ -25,6 +25,7 @@ liblyxfrontends_la_SOURCES = \ FileDialog.h \ FontLoader.h \ FontMetrics.h \ + KeyModifier.h \ KeySymbol.h \ LyXView.cpp \ LyXView.h \ @@ -37,5 +38,4 @@ liblyxfrontends_la_SOURCES = \ WorkArea.h \ WorkAreaManager.cpp \ WorkAreaManager.h \ - key_state.h \ mouse_state.h diff --git a/src/frontends/WorkArea.cpp b/src/frontends/WorkArea.cpp index e97903a929..dadb3e10c5 100644 --- a/src/frontends/WorkArea.cpp +++ b/src/frontends/WorkArea.cpp @@ -163,18 +163,18 @@ void WorkArea::redraw() } -void WorkArea::processKeySym(KeySymbol const & key, key_modifier::state state) +void WorkArea::processKeySym(KeySymbol const & key, KeyModifier mod) { // In order to avoid bad surprise in the middle of an operation, we better stop // the blinking cursor. stopBlinkingCursor(); theLyXFunc().setLyXView(lyx_view_); - theLyXFunc().processKeySym(key, state); + theLyXFunc().processKeySym(key, mod); } -void WorkArea::dispatch(FuncRequest const & cmd0, key_modifier::state k) +void WorkArea::dispatch(FuncRequest const & cmd0, KeyModifier mod) { // Handle drag&drop if (cmd0.action == LFUN_FILE_OPEN) { @@ -187,9 +187,9 @@ void WorkArea::dispatch(FuncRequest const & cmd0, key_modifier::state k) FuncRequest cmd; if (cmd0.action == LFUN_MOUSE_PRESS) { - if (k == key_modifier::shift) + if (mod == ShiftModifier) cmd = FuncRequest(cmd0, "region-select"); - else if (k == key_modifier::ctrl) + else if (mod == ControlModifier) cmd = FuncRequest(cmd0, "paragraph-select"); else cmd = cmd0; diff --git a/src/frontends/WorkArea.h b/src/frontends/WorkArea.h index a541dca6b6..74a875f241 100644 --- a/src/frontends/WorkArea.h +++ b/src/frontends/WorkArea.h @@ -14,7 +14,7 @@ #ifndef BASE_WORKAREA_H #define BASE_WORKAREA_H -#include "frontends/key_state.h" +#include "frontends/KeyModifier.h" #include "frontends/Delegates.h" #include "support/Timeout.h" @@ -98,7 +98,7 @@ public: /// Process Key pressed event. /// This needs to be public because it is accessed externally by GuiView. - void processKeySym(KeySymbol const & key, key_modifier::state state); + void processKeySym(KeySymbol const & key, KeyModifier mod); /// close this work area. /// Slot for Buffer::closing signal. @@ -108,8 +108,7 @@ protected: /// cause the display of the given area of the work area virtual void expose(int x, int y, int w, int h) = 0; /// - void dispatch(FuncRequest const & cmd0, - key_modifier::state = key_modifier::none); + void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier); /// void resizeBufferView(); diff --git a/src/frontends/qt4/GuiKeySymbol.cpp b/src/frontends/qt4/GuiKeySymbol.cpp index 0d9a343805..8a3a1a3017 100644 --- a/src/frontends/qt4/GuiKeySymbol.cpp +++ b/src/frontends/qt4/GuiKeySymbol.cpp @@ -10,8 +10,6 @@ #include -#include "frontends/KeySymbol.h" - #include "KeySymbol.h" #include "qlkey.h" @@ -43,9 +41,7 @@ using lyx::support::contains; using lyx::support::getEnv; -namespace { - -char encode(string const & encoding, QString const & str) +static char encode(string const & encoding, QString const & str) { typedef map EncodingMap; EncodingMap encoding_map; @@ -77,8 +73,6 @@ char encode(string const & encoding, QString const & str) return codec->fromUnicode(str).data()[0]; } -} // anon namespace - void setKeySymbol(KeySymbol * sym, QKeyEvent * ev) { @@ -152,16 +146,16 @@ char_type KeySymbol::getUCSEncoded() const } -docstring const KeySymbol::print(key_modifier::state mod, bool forgui) const +docstring const KeySymbol::print(KeyModifier mod, bool forgui) const { int tmpkey = key_; - if (mod & key_modifier::shift) - tmpkey += Qt::SHIFT; - if (mod & key_modifier::ctrl) - tmpkey += Qt::CTRL; - if (mod & key_modifier::alt) - tmpkey += Qt::ALT; + if (mod & ShiftModifier) + tmpkey += Qt::ShiftModifier; + if (mod & ControlModifier) + tmpkey += Qt::ControlModifier; + if (mod & AltModifier) + tmpkey += Qt::AltModifier; QKeySequence seq(tmpkey); @@ -190,15 +184,15 @@ bool KeySymbol::operator==(KeySymbol const & ks) const } -key_modifier::state q_key_state(Qt::KeyboardModifiers state) +KeyModifier q_key_state(Qt::KeyboardModifiers state) { - key_modifier::state k = key_modifier::none; + KeyModifier k = NoModifier; if (state & Qt::ControlModifier) - k |= key_modifier::ctrl; + k |= ControlModifier; if (state & Qt::ShiftModifier) - k |= key_modifier::shift; + k |= ShiftModifier; if (state & Qt::AltModifier || state & Qt::MetaModifier) - k |= key_modifier::alt; + k |= AltModifier; return k; } diff --git a/src/frontends/qt4/GuiKeySymbol.h b/src/frontends/qt4/GuiKeySymbol.h index 6212c65098..953dc4c46f 100644 --- a/src/frontends/qt4/GuiKeySymbol.h +++ b/src/frontends/qt4/GuiKeySymbol.h @@ -23,7 +23,7 @@ namespace lyx { void setKeySymbol(KeySymbol * sym, QKeyEvent * ev); /// return the LyX key state from Qt's -key_modifier::state q_key_state(Qt::KeyboardModifiers state); +KeyModifier q_key_state(Qt::KeyboardModifiers state); } // namespace lyx diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 12bd110929..372cad79b4 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -750,7 +750,7 @@ bool GuiViewBase::event(QEvent * e) if (ke->key() == Qt::Key_Tab || ke->key() == Qt::Key_Backtab) { KeySymbol sym; setKeySymbol(&sym, ke); - currentWorkArea()->processKeySym(sym, key_modifier::none); + currentWorkArea()->processKeySym(sym, NoModifier); e->accept(); return true; } -- 2.39.5