Add keyboard navigation to Ribbon (PR #27046)

8 views
Skip to first unread message

Blake-Madden

unread,
Sep 21, 2026, 2:56:48 PM (2 days ago) Sep 21
to wx-...@googlegroups.com, Subscribed

Supports navigating between tabs, as well as their buttons, toolbars, and galleries.

There are new public implementation functions, but I didn't document them as they seem more like internal functions that client don't really need to see.

Tested on MSW, macOS, and Linux Mint.


You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/27046

Commit Summary

  • c33455a Add keyboard navigation to ribbon button bar (tabs and buttons)
  • a7de985 Add keyboard navigation to ribbon panel
  • 6275a0e Add ribbon toolbar keyboard navigation
  • 71494f3 Add keyboard navigation to ribbon gallery
  • 065d774 Handle tabbing in/out when not inside of navigation supporting parent
  • 2ab4d01 Document ribbon keyboard navigation

File Changes

(13 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/27046@github.com>

VZ

unread,
Sep 21, 2026, 3:24:21 PM (2 days ago) Sep 21
to wx-...@googlegroups.com, Subscribed

@vadz approved this pull request.

Thanks!

There is a lot of new code here and it's a bit surprising that it seems to be completely independent of all the existing code supporting keyboard navigation (e.g. shouldn't wxWindow::DoNavigateIn() be overridden somewhere?) but, as with the PR adding accelerators display, this is clearly valuable for the users, so let's merge it if nobody sees any problems with it (I'll leave it unmerged for a couple of days to give people a chance to comment).


In include/wx/ribbon/bar.h:

> @@ -263,6 +303,11 @@ class WXDLLIMPEXP_RIBBON wxRibbonBar : public wxRibbonControl
 
     wxVector<wxImageList*> m_image_lists;
 
+    // The control whose item has the keyboard focus, null if it's on the tabs.
+    wxWeakRef<wxRibbonControl> m_focusedStop;

Why is it called "stop"?


In include/wx/ribbon/control.h:

> @@ -62,6 +64,31 @@ class WXDLLIMPEXP_RIBBON wxRibbonControl : public wxControl
     // Finds the best width and height given the parent's width and height
     virtual wxSize GetBestSizeForParentSize(const wxSize& WXUNUSED(parentSize)) const { return GetBestSize(); }
 
+    // Implementation only: keyboard navigation of the items inside a control.
+    //
+    // The keyboard focus always stays on wxRibbonBar, which forwards the keys
+    // to these functions. A control with items which can be selected with the
+    // keyboard returns true from HasFocusableItems() and overrides the rest.
+    virtual bool HasFocusableItems() const { return false; }

Is this really different from wxWindow::CanAcceptFocus()?


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/27046/review/5270809047@github.com>

Blake-Madden

unread,
Sep 21, 2026, 3:38:18 PM (2 days ago) Sep 21
to wx-...@googlegroups.com, Subscribed

@Blake-Madden commented on this pull request.


In include/wx/ribbon/bar.h:

> @@ -263,6 +303,11 @@ class WXDLLIMPEXP_RIBBON wxRibbonBar : public wxRibbonControl
 
     wxVector<wxImageList*> m_image_lists;
 
+    // The control whose item has the keyboard focus, null if it's on the tabs.
+    wxWeakRef<wxRibbonControl> m_focusedStop;

Yes, "control" or "item" is a better name. I was thinking that as you tab or arrow, it "stops" on that control. I'll reword that...


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/27046/review/5271009005@github.com>

Blake-Madden

unread,
Sep 21, 2026, 3:50:46 PM (2 days ago) Sep 21
to wx-...@googlegroups.com, Subscribed

@Blake-Madden commented on this pull request.


In include/wx/ribbon/control.h:

> @@ -62,6 +64,31 @@ class WXDLLIMPEXP_RIBBON wxRibbonControl : public wxControl
     // Finds the best width and height given the parent's width and height
     virtual wxSize GetBestSizeForParentSize(const wxSize& WXUNUSED(parentSize)) const { return GetBestSize(); }
 
+    // Implementation only: keyboard navigation of the items inside a control.
+    //
+    // The keyboard focus always stays on wxRibbonBar, which forwards the keys
+    // to these functions. A control with items which can be selected with the
+    // keyboard returns true from HasFocusableItems() and overrides the rest.
+    virtual bool HasFocusableItems() const { return false; }

I was thinking CanAcceptFocus() is about if the window itself can receive the focus. Here, the ribbon bar always keeps the focus. This checks if the control has any item the bar can move the focus to. (For example, a button bar with all buttons disabled has none.) I'm updating the comment.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/27046/review/5271133209@github.com>

Blake-Madden

unread,
Sep 21, 2026, 4:05:18 PM (2 days ago) Sep 21
to wx-...@googlegroups.com, Push

@Blake-Madden pushed 1 commit.

  • bf5e428 Fix confusing var names, improve comment


View it on GitHub or unsubscribe.


Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/27046/before/2ab4d013d571c3f4cfec93591a6a776789aefa68/after/bf5e42866c7c0f06c8e9bb0a62557a70706262dc@github.com>

VZ

unread,
Sep 21, 2026, 8:47:06 PM (2 days ago) Sep 21
to wx-...@googlegroups.com, Subscribed

Merged #27046 into master.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/27046/issue_event/31568222808@github.com>

Reply all
Reply to author
Forward
0 new messages