#19203: Don't call gtk_widget_set_can_focus(FALSE) for the panels
------------------------------------+-------------------------
Reporter: vadz | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxGTK | Version: dev-latest
Keywords: wxPanel mnemonic focus | Blocked By:
Blocking: | Patch: 0
------------------------------------+-------------------------
We currently do this, from
`wxControlContainerBase::UpdateParentCanFocus()` and there is a comment
there saying that not doing this breaks native focus handling. However
doing this breaks native mnemonic handling as can be seen with this patch
(from
https://stackoverflow.com/q/67633687/15275):
{{{
#!diff
diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp
index 135595c9fb..b656000879 100644
--- a/samples/minimal/minimal.cpp
+++ b/samples/minimal/minimal.cpp
@@ -172,6 +172,26 @@ MyFrame::MyFrame(const wxString& title)
CreateStatusBar(2);
SetStatusText("Welcome to wxWidgets!");
#endif // wxUSE_STATUSBAR
+
+ wxPanel *root = new wxPanel(this); {
+ wxStaticText *label = new wxStaticText(root, wxID_ANY,
wxS("T&est"));
+ wxPanel *panel = new wxPanel(root); {
+ wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+ wxTextCtrl *text = new wxTextCtrl(panel, wxID_ANY);
+ sizer->Add(text, wxSizerFlags(0).Expand());
+ panel->SetSizerAndFit(sizer);
+ }
+
+ wxTextCtrl *text2 = new wxTextCtrl(root, wxID_ANY);
+
+ wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+
+ sizer->Add(label, wxSizerFlags(0).Expand());
+ sizer->Add(panel, wxSizerFlags(0).Expand());
+ sizer->Add(text2, wxSizerFlags(0).Expand());
+
+ root->SetSizerAndFit(sizer);
+ }
}
}}}
as `gtk_widget_real_mnemonic_activate()` can't give focus to the panel
following the label with the mnemonic.
Just not calling `SetCanFocus(false)` is not enough to fix this (the panel
still doesn't give focus to the next child) and almost certianly breaks
something else, but maybe not doing this ''and'' handling `grab-focus`
signal and doing something there could be a solution.
This might not be that important in practice, but what worries me is that
GTK clearly doesn't want `gtk_widget_set_can_focus(FALSE)` to be called on
a widget with focusable children and it seems wrong to go against it in
wxGTK code.
--
Ticket URL: <
https://trac.wxwidgets.org/ticket/19203>