Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sfx2/inc/notebookbar/NotebookbarTabControl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#pragma once

#include <chrono>
#include <vcl/tabctrl.hxx>

#include <com/sun/star/frame/XFrame.hpp>
Expand All @@ -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<css::uno::XComponentContext> const & xContext,
const css::uno::Reference<css::frame::XFrame>& xFrame,
const OUString& aModuleName,
Expand Down
26 changes: 26 additions & 0 deletions sfx2/source/notebookbar/NotebookbarTabControl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/

#include <chrono>
#include <vcl/builderfactory.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/layout.hxx>
#include <vcl/notebookbar/notebookbar.hxx>
#include <vcl/tabpage.hxx>
Expand Down Expand Up @@ -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 )
Expand Down