#19203: Don't call gtk_widget_set_can_focus(FALSE) for the panels

12 views
Skip to first unread message

wxTrac

unread,
Jun 16, 2021, 5:02:20 PM6/16/21
to wx-...@googlegroups.com
#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>

wxTrac

unread,
Jun 17, 2021, 2:58:11 AM6/17/21
to wx-...@googlegroups.com
#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
Resolution: | Keywords: wxPanel mnemonic focus
Blocked By: | Blocking:
Patch: 0 |
---------------------+------------------------------------

Comment (by leio):

This kind of change discussed here reads to me like GTK4, because that's
where such changes were done:

https://gitlab.gnome.org/GNOME/gtk/-/issues/2553
https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/1652
https://docs.gtk.org/gtk4/migrating-3to4.html#focus-handling-changes

I'm guessing this is something to do with the compound widget in wxGTK,
with the widget after the label not being focusable itself or something?

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19203#comment:1>

wxTrac

unread,
Jun 17, 2021, 5:31:35 AM6/17/21
to wx-...@googlegroups.com
#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
Resolution: | Keywords: wxPanel mnemonic focus
Blocked By: | Blocking:
Patch: 0 |
---------------------+------------------------------------

Comment (by vadz):

wx can't be compiled with GTK 4 yet, so no, this is not related to it, the
problem exists with GTK 3.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19203#comment:2>
Reply all
Reply to author
Forward
0 new messages