Opened 3 years ago

Closed 18 months ago

#13271 closed defect (fixed)

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: Blocking:
Patch: no

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 (2)

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

Download all attachments as: .zip

Change History (8)

comment:1 Changed 3 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.

comment:2 Changed 3 years 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 19 months ago by alexandrub

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

comment:3 Changed 19 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).

comment:4 Changed 19 months ago by vadz

  • Milestone set to 2.9.5
  • Owner set to vadz
  • Status changed from confirmed to accepted

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 19 months ago by vadz

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

comment:5 Changed 18 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.

comment:6 Changed 18 months ago by VZ

  • Resolution set to fixed
  • Status changed from accepted to closed

(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.