diff --git a/sfx2/inc/notebookbar/NotebookbarTabControl.hxx b/sfx2/inc/notebookbar/NotebookbarTabControl.hxx index 22cf51b7827f..42eec08d766e 100644 --- a/sfx2/inc/notebookbar/NotebookbarTabControl.hxx +++ b/sfx2/inc/notebookbar/NotebookbarTabControl.hxx @@ -9,6 +9,7 @@ #pragma once +#include #include #include @@ -25,11 +26,14 @@ public: ~NotebookbarTabControl() override; virtual void KeyInput( const KeyEvent& rKEvt ) override; + virtual void Command( const CommandEvent& rCEvt ) override; virtual bool EventNotify( NotifyEvent& rNEvt ) override; virtual void StateChanged(StateChangedType nStateChange) override; virtual Size calculateRequisition() const override; private: + // time-based debounce: track when the last tab switch via scroll happened + std::chrono::steady_clock::time_point m_lastTabSwitch{}; static void FillShortcutsToolBox(css::uno::Reference const & xContext, const css::uno::Reference& xFrame, const OUString& aModuleName, diff --git a/sfx2/source/notebookbar/NotebookbarTabControl.cxx b/sfx2/source/notebookbar/NotebookbarTabControl.cxx index acad2a2e5ea5..2bf850857b89 100644 --- a/sfx2/source/notebookbar/NotebookbarTabControl.cxx +++ b/sfx2/source/notebookbar/NotebookbarTabControl.cxx @@ -17,7 +17,9 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include #include +#include #include #include #include @@ -222,6 +224,30 @@ void NotebookbarTabControl::KeyInput( const KeyEvent& rKEvt ) return NotebookbarTabControlBase::KeyInput( rKEvt ); } +void NotebookbarTabControl::Command( const CommandEvent& rCEvt ) +{ + if ( rCEvt.GetCommand() == CommandEventId::Wheel ) + { + const CommandWheelData* pData = rCEvt.GetWheelData(); + if ( pData && !pData->GetModifier() + && pData->GetMode() == CommandWheelMode::SCROLL + && pData->GetDelta() != 0 ) + { + // Debounce: require at least 100 ms between tab switches so that + // casual scrolling does not rapidly cycle through tabs. + auto now = std::chrono::steady_clock::now(); + static constexpr auto debounceMs = std::chrono::milliseconds(100); + if ( now - m_lastTabSwitch >= debounceMs ) + { + m_lastTabSwitch = now; + ImplActivateTabPage( pData->GetDelta() < 0 ); + } + return; + } + } + NotebookbarTabControlBase::Command( rCEvt ); +} + bool NotebookbarTabControl::EventNotify( NotifyEvent& rNEvt ) { if ( rNEvt.GetType() == NotifyEventType::KEYINPUT )