From 8a397b0541653d7a8ddd1baa0602a340b54559e4 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Wed, 5 Feb 2020 13:40:10 +0100 Subject: [PATCH] BTabView: use the back/forward buttons to switch tabs Note that for this to work well, the child views in the tabs must propagate MouseDown events up for these buttons. --- src/kits/interface/TabView.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/kits/interface/TabView.cpp b/src/kits/interface/TabView.cpp index 9cefad36f4..d503065bb2 100644 --- a/src/kits/interface/TabView.cpp +++ b/src/kits/interface/TabView.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -640,6 +641,8 @@ BTabView::MessageReceived(BMessage* message) } #if 0 + // TODO this would be annoying as-is, but maybe it makes sense with + // a modifier or using only deltaX (not the main mouse wheel) case B_MOUSE_WHEEL_CHANGED: { float deltaX = 0.0f; @@ -712,11 +715,31 @@ BTabView::KeyDown(const char* bytes, int32 numBytes) void BTabView::MouseDown(BPoint where) { - for (int32 i = 0; i < CountTabs(); i++) { - if (TabFrame(i).Contains(where) - && i != Selection()) { - Select(i); - return; + // Which button is pressed? + uint32 buttons = 0; + BMessage* currentMessage = Window()->CurrentMessage(); + if (currentMessage != NULL) { + currentMessage->FindInt32("buttons", (int32*)&buttons); + } + + int32 selection = Selection(); + int32 numTabs = CountTabs(); + if (buttons & B_BACK_MOUSE_BUTTON) { + // The "back" mouse button moves to previous tab + if (selection > 0 && numTabs > 1) + Select(Selection() - 1); + } else if (buttons & B_FORWARD_MOUSE_BUTTON) { + // The "forward" mouse button moves to next tab + if (selection < numTabs - 1) + Select(Selection() + 1); + } else { + // Other buttons are used to select a tab by clicking directly on it + for (int32 i = 0; i < CountTabs(); i++) { + if (TabFrame(i).Contains(where) + && i != Selection()) { + Select(i); + return; + } } }