Ticket #13271 (closed defect: fixed)

Opened 2 years ago

Last modified 8 months ago

wxStaticBox parent, broken Tab order

Reported by: rollmark Owned by: vadz
Priority: normal Milestone: 2.9.5
Component: wxMSW Version: 2.9.1
Keywords: msw wxStaticBox tab Cc:
Blocked By: Patch: no
Blocking:

Description

Hi,

I'm using wxWidgets wxWidgets-2.9.1 with Visual C++ 2010 on Windows 7
with DialogBlocks 4.40.
I noticed that the new recommended way is to use the wxStaticBox as
a parent to other controls (this change is also reflectd in the code
generated from DialogBlocks).

However there seems to be a bug with regard to the resulting tab
order. The controls that are grouped as children of the wxStaticBox
are not reachable via TAB key. Instead the next control that is not a
child of the wxStaticBox ist selected.

You can reproduce this behaviour in the controls sample. After line
996 in controls.cpp (where the wxStaticBoxSizer with the label 'Show
Buttons' is created) add these lines:

wxStaticBox* txtParent = csizer->GetStaticBox();
// wxPanel* txtParent = panel;
csizer->Add(new wxTextCtrl( txtParent, wxID_ANY, s, wxPoint(20,160),
wxSize(80,wxDefaultCoord)));
csizer->Add(new wxTextCtrl( txtParent, wxID_ANY, s, wxPoint(20,160),
wxSize(80,wxDefaultCoord)));
csizer->Add(new wxTextCtrl( txtParent, wxID_ANY, s, wxPoint(20,160),
wxSize(80,wxDefaultCoord)));

Place the cursor in the first text control on the wxSizer page. If the
static box is the wxTextCtrl parent, then pressing TAB moves the focus to the
checkbox with the label '1'. If the panel ist the parent, then
pressing TAB moves the focus to the second text control as expected.

Regards,

Attachments

static_sizer_tab_traversal.patch download (3.0 KB) - added by alexandrub 8 months ago.
Xrc sample modified to demonstrate the problem and a possible solution.
focus-debug.patch download (2.4 KB) - added by vadz 8 months ago.
Patch to the minimal sample reproducing the problem and showing current focus

Change History

Changed 2 years ago by vadz

  • status changed from new to confirmed

We probably need to use wxControlContainer in wxStaticBox to make this work.

Alternatively, we could try to finally understand why doesn't Windows native TAB navigation (as implemented by ::IsDialogMessage()) work for wxWidgets programs.

Changed 22 months ago by staticinline

Is any quick workaround known? I use a lot of wxStaticBoxSizer's, and MSW tab traversal broke in moving to wxWidgets 2.9.

Changed 8 months ago by alexandrub

Xrc sample modified to demonstrate the problem and a possible solution.

Changed 8 months ago by alexandrub

Hi,

Using the latest trunk the problem is still noticeable (even after changeset r72523) but can be solved by setting wxTAB_TRAVERSAL on static box creation. I'm not sure how this flag is to be used generally but maybe this should be default on static boxes now? The same thing happens with wxChoiceBook (demonstrated with the patch above by removing and reapplying changes to xh_sizer.cpp and xh_choicbk.cpp).

Changed 8 months ago by vadz

  • owner set to vadz
  • status changed from confirmed to accepted
  • milestone set to 2.9.5

We do indeed need wxTAB_TRAVERSAL for wxStaticBox but it's not the only problem here, we also need to ensure that it doesn't get the focus itself which is possible since r72523. I'm going to look at this, thanks.

Changed 8 months ago by vadz

Patch to the minimal sample reproducing the problem and showing current focus

Changed 8 months ago by VZ

(In [72663]) Allow using windows that can't be focused with wxNavigationEnabled<>.

The code in wxNavigationEnabled<> assumed that the window itself could be
focused if it didn't have any focusable children because it was originally
extracted from wxPanel that can, indeed, be focused. This is however not the
case for all windows, notably not for wxStaticBox which now derives from
wxNavigationEnabled as well but can never be focused itself.

Add wxControlContainer::DisableSelfFocus() and call it from wxStaticBox to
support this situation. This required splitting m_acceptsFocus flag into
m_acceptsFocusSelf and m_acceptsFocusChildren and updating various methods
using them.

See #13271.

Changed 8 months ago by VZ

  • status changed from accepted to closed
  • resolution set to fixed

(In [72664]) Set wxTAB_TRAVERSAL for wxNavigationEnabled<> windows with focusable children.

We need to have this flag under wxMSW in order for navigation events to be
generated for the window. As wxNavigationEnabled can't set this flag on
creation because its ctor is called too early, do it in overridden AddChild().

Closes #13271.

Note: See TracTickets for help on using tickets.