Discussion:
Changing tab order at run-time
Tim Burgess
2014-04-10 09:47:26 UTC
Permalink
Hi,

I have the following scenario:

1 - A frame containing a list box and a variable number of static/text
control pairs (these latter being created at run-time depending on data
coming into the application). Each pair of static/text controls have their
own horizontal sizer and the whole thing is stored as follows:

struct DisplayElement
{
wxBoxSizer * ElementSizer;
wxStaticText * DisplayLabel;
RBTextCtrl * DisplayContents; // This class is just a wxTextCtl with the
read-only property set and enabled for tab navigation
};

2 - I store instances of DisplayElement in a std::map <std::wstring,
DisplayElement>, the key to the map being the value of the text in the
static;

3 - I'm attempting to use MoveBeforeInTabOrder and MoveAfterInTabOrder to
add the first and last DisplayElement instances into the tab order with
respect to the list box (tab navigation works fine between the instances of
DisplayElement within the map). This is done imediately after a
DisplayElement instance has been instantiated and the individual element
values set: In the snippet below, MyDisplays is the name of the map
mentioned above:

Std::pair <std::wstring, DisplayElement> myDisplayPair;
// ... controls created here, added to the pair and inserted into the map

// If this is the first DisplayElement that has been created we want it to
be after the list box in the tab order
if (myDisplays.size() == 1)
{
lbxSurfaces->MoveBeforeInTabOrder(
myDisplayPair.second.DisplayLabel);
}

// Always set the new DisplayElement's text control to the tab order
position immediately prior to the list box.
lbxSurfaces->MoveAfterInTabOrder( myDisplayPair.second.DisplayContents);

This doesn't work. If I click into any of the text controls I can
tab/shift+tab happily between the text controls and get as far as tabbing
onto the list box. However, as soon as I land on the list box I can't tab
away from it again.

Is there any way that I can interrogate the tab order index values so that I
can try to debug this, please? Alternatively, can anybody spot my error?

Best wishes and thanks in advance.
Tim Burgess
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Tim Burgess
2014-04-11 09:57:42 UTC
Permalink
More information on this issue that's making me think it's a focusing
problem rather than an inherent tab order problem. I implemented the
following handler for a test key (F7):

void SurfaceFrame::OnToggleDisplays( wxCommandEvent& event)
{
// Set the focus to the first display, if present
if (myDisplays.size() > 0)
{
if (this->FindFocus() != lbxSurfaces)
{
lbxSurfaces->SetFocus();
}
else
{
// Set focus to the first text box
myDisplays.at( 0).DisplayContents->SetFocus();
}
}
}

If I step through this using a break point, the order of execution is what
I'd expect, but the call to:

myDisplays.at( 0).DisplayContents->SetFocus();

does not seem to do anything. I get no errors or crashes, but the focus
doesn't move. Can anybody suggest a work-around, please? I could take
control of the mouse pointer and get it to click into the desired control
(I've test this and it works), but it's a real cludge and I'd prefer not to
do it this way.

Best wishes.
Tim Burgess

-----Original Message-----
From: wx-***@googlegroups.com [mailto:wx-***@googlegroups.com] On Behalf
Of Tim Burgess
Sent: 10 April 2014 10:47
To: wx-***@googlegroups.com
Subject: Changing tab order at run-time

Hi,

I have the following scenario:

1 - A frame containing a list box and a variable number of static/text
control pairs (these latter being created at run-time depending on data
coming into the application). Each pair of static/text controls have their
own horizontal sizer and the whole thing is stored as follows:

struct DisplayElement
{
wxBoxSizer * ElementSizer;
wxStaticText * DisplayLabel;
RBTextCtrl * DisplayContents; // This class is just a wxTextCtl with the
read-only property set and enabled for tab navigation };

2 - I store instances of DisplayElement in a std::map <std::wstring,
DisplayElement>, the key to the map being the value of the text in the
static;

3 - I'm attempting to use MoveBeforeInTabOrder and MoveAfterInTabOrder to
add the first and last DisplayElement instances into the tab order with
respect to the list box (tab navigation works fine between the instances of
DisplayElement within the map). This is done imediately after a
DisplayElement instance has been instantiated and the individual element
values set: In the snippet below, MyDisplays is the name of the map
mentioned above:

Std::pair <std::wstring, DisplayElement> myDisplayPair; // ... controls
created here, added to the pair and inserted into the map

// If this is the first DisplayElement that has been created we want it to
be after the list box in the tab order if (myDisplays.size() == 1)
{
lbxSurfaces->MoveBeforeInTabOrder(
myDisplayPair.second.DisplayLabel);
}

// Always set the new DisplayElement's text control to the tab order
position immediately prior to the list box.
lbxSurfaces->MoveAfterInTabOrder( myDisplayPair.second.DisplayContents);

This doesn't work. If I click into any of the text controls I can
tab/shift+tab happily between the text controls and get as far as tabbing
onto the list box. However, as soon as I land on the list box I can't tab
away from it again.

Is there any way that I can interrogate the tab order index values so that I
can try to debug this, please? Alternatively, can anybody spot my error?

Best wishes and thanks in advance.
Tim Burgess


--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Loading...