Tab traversal doesn't work for my wxTextCtrl ? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Tab traversal doesn't work for my wxTextCtrl ?

Post by Muetdhiver » Sun Jan 22, 2012 11:21 pm

Hi all,

I've got the following configuration :

My application is composed of a wxFrame. It contains a notebook with several panels (wxPanel).
Each panel have the tabTraversal default style.

In a specific panel, I've got two inner panel. In the inner top panel (that also have default style), I've got a lots of text control (wxTextCtrl). Actually, I derived my own text control.
Style of each custom text control is wxTE_MULTILINE | wxTE_RICH.
I written my own function regarding the EVT_KEY_DOWN : the OnKey function.

There is something in :

Code: Select all

void
CTrainingGameWordControl::OnKey(wxKeyEvent & event)
{
	long loc_l_code = event.GetKeyCode() ;

	// Find the letter among the ordered letters
	long loc_l_index = m_po_st_label->GetLabelText().Find( wxUniChar(loc_l_code) );

	if ( 		loc_l_index != wxNOT_FOUND
			|| 	(loc_l_code == WXK_BACK) /* Backspace */
			|| 	(loc_l_code == WXK_UP)
			|| 	(loc_l_code == WXK_DOWN)
			|| 	(loc_l_code == WXK_DELETE)
			|| 	(loc_l_code == WXK_RETURN ))
	{
		// ........
	}
	else
	{
		if( loc_l_code >= 'A' &&  loc_l_code <= 'Z' )
		{
			wxBell();
		}
		else
		{
			// LEFT and RIGHT keys need to be threaten by EVT_CHAR, others don't
			// Add : Other keys must also be threaten
			if ( 	loc_l_code == WXK_LEFT
				|| 	loc_l_code == WXK_RIGHT
				||	loc_l_code == WXK_TAB
				||  loc_l_code == WXK_HOME
				||  loc_l_code == WXK_END
			)
			{
				event.Skip();
			}
		}
	}
}
As you can see, when a press left, right, tab, home and end keys, I do event.Skip().

I don't know where can be my problem, but when I pressed "tab" key, a "tab" is done into my text control.... instead of navigating to the following text control.....
I've check all styles, wxTAB_TRAVERSAL is written for all parent wxPanel, and there is no wxTE_PROCESS_TAB for my own text control.

Could you help me please ?

Thanks.
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

User avatar
doublemax
Moderator
Moderator
Posts: 15278
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Tab traversal doesn't work for my wxTextCtrl ?

Post by doublemax » Sun Jan 22, 2012 11:39 pm

Did you confirm that loc_l_code contains the correct value and that the if(loc_l_code == WXK_TAB) is actually hit?

I tested this in the "text" sample and it works, even if i add the wxTE_RICH style flag.

If everything fails, you could try to navigate to the next control manually:
http://docs.wxwidgets.org/stable/wx_wxw ... ownavigate
Use the source, Luke!

Muetdhiver
Super wx Problem Solver
Super wx Problem Solver
Posts: 323
Joined: Sun Jun 08, 2008 11:59 am
Location: Bordeaux, France

Re: Tab traversal doesn't work for my wxTextCtrl ?

Post by Muetdhiver » Mon Jan 23, 2012 9:52 am

Hello,

thanks doublemax for your answer.

I confirm that my code run to event.Skip() when Tab is hit (so loc_l_code == WXK_TAB).

But you are right, I found a workaround just after posting this message, I actually do the job of the Skip function, that is to say Navigate to the next text control when tab is hit :

Code: Select all


if (       loc_l_index != wxNOT_FOUND
         ||    (loc_l_code == WXK_BACK) /* Backspace */
         ||    (loc_l_code == WXK_UP)
         ||    (loc_l_code == WXK_DOWN)
         ||    (loc_l_code == WXK_TAB)
         ||    (loc_l_code == WXK_DELETE)
         ||    (loc_l_code == WXK_RETURN ))
   {
    if ( .......)
     {
          .......
      }
      else if ( loc_l_code == WXK_DOWN || loc_l_code == WXK_TAB)
	{
			   // Set the focus to the next word control
			   Navigate(); 
        }
....
But it is very strange that style of my parent panels set to wxTAB_TRAVERSAL doesn't work.... I really don't understand why.
If my memory is good, it was working with wx2.8.12 .... Since wx2.9.3 it doesn't work anymore.... really strange.

Thanks, bye.
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

Post Reply