From 9da4015f5ee04071d4375b78c6e7095ec94d83da Mon Sep 17 00:00:00 2001 From: Rye Mutt <rye@alchemyviewer.org> Date: Thu, 19 Mar 2020 13:20:05 -0400 Subject: [PATCH] Add scroll wheel support to comboboxes - Liru --- indra/llui/llcombobox.cpp | 24 +++++++++++++++++++----- indra/llui/llcombobox.h | 1 + 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/indra/llui/llcombobox.cpp b/indra/llui/llcombobox.cpp index c7f0326ed49..03071b554bf 100644 --- a/indra/llui/llcombobox.cpp +++ b/indra/llui/llcombobox.cpp @@ -959,11 +959,8 @@ void LLComboBox::onTextEntry(LLLineEditor* line_editor) void LLComboBox::updateSelection() { - LLWString left_wstring = mTextEntry->getWText().substr(0, mTextEntry->getCursor()); - // user-entered portion of string, based on assumption that any selected - // text was a result of auto-completion - LLWString user_wstring = mHasAutocompletedText ? left_wstring : mTextEntry->getWText(); - std::string full_string = mTextEntry->getText(); + const LLWString left_wstring = mTextEntry->getWText().substr(0, mTextEntry->getCursor()); + const std::string& full_string = mTextEntry->getText(); // go ahead and arrange drop down list on first typed character, even // though we aren't showing it... some code relies on prearrange @@ -991,6 +988,10 @@ void LLComboBox::updateSelection() } else // no matching items found { + // user-entered portion of string, based on assumption that any selected + // text was a result of auto-completion + const LLWString user_wstring = mHasAutocompletedText ? left_wstring : mTextEntry->getWText(); + mList->deselectAllItems(); mTextEntry->setText(wstring_to_utf8str(user_wstring)); // removes text added by autocompletion mTextEntry->setTentative(mTextEntryTentative); @@ -1138,6 +1139,19 @@ BOOL LLComboBox::selectItemRange( S32 first, S32 last ) return mList->selectItemRange(first, last); } +// virtual +BOOL LLComboBox::handleScrollWheel(S32 x, S32 y, S32 clicks) +{ + if (mList->getVisible()) return mList->handleScrollWheel(x, y, clicks); + if (mAllowTextEntry) // We might be editable + if (!mList->getFirstSelected()) // We aren't in the list, don't kill their text + return false; + + setCurrentByIndex(llclamp(getCurrentIndex() + clicks, 0, getItemCount() - 1)); + prearrangeList(); + onCommit(); + return true; +} static LLDefaultChildRegistry::Register<LLIconsComboBox> register_icons_combo_box("icons_combo_box"); diff --git a/indra/llui/llcombobox.h b/indra/llui/llcombobox.h index 7d38c051a5a..704e3754713 100644 --- a/indra/llui/llcombobox.h +++ b/indra/llui/llcombobox.h @@ -107,6 +107,7 @@ class LLComboBox virtual BOOL handleToolTip(S32 x, S32 y, MASK mask); virtual BOOL handleKeyHere(KEY key, MASK mask); virtual BOOL handleUnicodeCharHere(llwchar uni_char); + BOOL handleScrollWheel(S32 x, S32 y, S32 clicks) final override; // LLUICtrl interface virtual void clear(); // select nothing -- GitLab