diff options
author | Neil <nyamatongwe@gmail.com> | 2022-08-13 19:58:27 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2022-08-13 19:58:27 +1000 |
commit | a3ad77a3499097ae3db33d95176458a0ef0dec2b (patch) | |
tree | 0683fc5d1bd5b933328b169fb23334d5f2350680 | |
parent | 5a19e2ac572bb0f3cd614836145a9d759263fd2d (diff) | |
download | scintilla-mirror-a3ad77a3499097ae3db33d95176458a0ef0dec2b.tar.gz |
Move ModifierFlags to ScintillaTypes.h as it is globally useful and not tied
to Editor.
-rw-r--r-- | include/ScintillaTypes.h | 9 | ||||
-rw-r--r-- | qt/ScintillaEditBase/ScintillaEditBase.cpp | 8 | ||||
-rw-r--r-- | src/Editor.cxx | 9 | ||||
-rw-r--r-- | src/Editor.h | 1 |
4 files changed, 13 insertions, 14 deletions
diff --git a/include/ScintillaTypes.h b/include/ScintillaTypes.h index 343dec749..5fc18b71b 100644 --- a/include/ScintillaTypes.h +++ b/include/ScintillaTypes.h @@ -818,6 +818,15 @@ constexpr KeyMod operator&(KeyMod a, KeyMod b) noexcept { return static_cast<KeyMod>(static_cast<int>(a) & static_cast<int>(b)); } +constexpr KeyMod ModifierFlags(bool shift, bool ctrl, bool alt, bool meta=false, bool super=false) noexcept { + return + (shift ? KeyMod::Shift : KeyMod::Norm) | + (ctrl ? KeyMod::Ctrl : KeyMod::Norm) | + (alt ? KeyMod::Alt : KeyMod::Norm) | + (meta ? KeyMod::Meta : KeyMod::Norm) | + (super ? KeyMod::Super : KeyMod::Norm); +} + // Test if an enum class value has some bit flag(s) of test set. template <typename T> constexpr bool FlagSet(T value, T test) { diff --git a/qt/ScintillaEditBase/ScintillaEditBase.cpp b/qt/ScintillaEditBase/ScintillaEditBase.cpp index c390f4039..da415d2b4 100644 --- a/qt/ScintillaEditBase/ScintillaEditBase.cpp +++ b/qt/ScintillaEditBase/ScintillaEditBase.cpp @@ -257,7 +257,7 @@ void ScintillaEditBase::keyPressEvent(QKeyEvent *event) bool consumed = false; bool added = sqt->KeyDownWithModifiers(static_cast<Keys>(key), - ScintillaQt::ModifierFlags(shift, ctrl, alt), + ModifierFlags(shift, ctrl, alt), &consumed) != 0; if (!consumed) consumed = added; @@ -331,7 +331,7 @@ void ScintillaEditBase::mousePressEvent(QMouseEvent *event) bool alt = QApplication::keyboardModifiers() & Qt::AltModifier; #endif - sqt->ButtonDownWithModifiers(pos, time.elapsed(), ScintillaQt::ModifierFlags(shift, ctrl, alt)); + sqt->ButtonDownWithModifiers(pos, time.elapsed(), ModifierFlags(shift, ctrl, alt)); } if (event->button() == Qt::RightButton) { @@ -373,7 +373,7 @@ void ScintillaEditBase::mouseMoveEvent(QMouseEvent *event) bool alt = QApplication::keyboardModifiers() & Qt::AltModifier; #endif - const KeyMod modifiers = ScintillaQt::ModifierFlags(shift, ctrl, alt); + const KeyMod modifiers = ModifierFlags(shift, ctrl, alt); sqt->ButtonMoveWithModifiers(pos, time.elapsed(), modifiers); } @@ -826,5 +826,5 @@ KeyMod ScintillaEditBase::ModifiersOfKeyboard() const bool ctrl = QApplication::keyboardModifiers() & Qt::ControlModifier; const bool alt = QApplication::keyboardModifiers() & Qt::AltModifier; - return ScintillaQt::ModifierFlags(shift, ctrl, alt); + return ModifierFlags(shift, ctrl, alt); } diff --git a/src/Editor.cxx b/src/Editor.cxx index e80ec647b..8e8de16b1 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -2358,15 +2358,6 @@ void Editor::DelCharBack(bool allowLineStartDeletion) { ShowCaretAtCurrentPosition(); } -KeyMod Editor::ModifierFlags(bool shift, bool ctrl, bool alt, bool meta, bool super) noexcept { - return - (shift ? KeyMod::Shift : KeyMod::Norm) | - (ctrl ? KeyMod::Ctrl : KeyMod::Norm) | - (alt ? KeyMod::Alt : KeyMod::Norm) | - (meta ? KeyMod::Meta : KeyMod::Norm) | - (super ? KeyMod::Super : KeyMod::Norm); -} - void Editor::NotifyFocus(bool focus) { NotificationData scn = {}; scn.nmhdr.code = focus ? Notification::FocusIn : Notification::FocusOut; diff --git a/src/Editor.h b/src/Editor.h index e96ed391e..a30edff90 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -443,7 +443,6 @@ protected: // ScintillaBase subclass needs access to much of Editor void DelCharBack(bool allowLineStartDeletion); virtual void ClaimSelection() = 0; - static Scintilla::KeyMod ModifierFlags(bool shift, bool ctrl, bool alt, bool meta=false, bool super=false) noexcept; virtual void NotifyChange() = 0; virtual void NotifyFocus(bool focus); virtual void SetCtrlID(int identifier); |