wxEVT_FILL_FOCUS event and GetWindow function ? 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

wxEVT_FILL_FOCUS event and GetWindow function ?

Post by Muetdhiver » Tue Oct 04, 2011 10:15 am

Hi,

I have this window :
Image

Let's consider the focus is set on the bottom right text control (right to AAEGTX).
The next widget to be focused, when pressing the down arrow for example, is the button "Corriger".

The documentation says, about the GetWindow function of the kill focus event :
wxFocusEvent::GetWindow
Returns the window associated with this event, that is the window which had the focus before for the wxEVT_SET_FOCUS event and the window which is going to receive focus for the wxEVT_KILL_FOCUS one.

Warning: the window pointer may be NULL!
That is, I try to get the following window (my button) during the kill focus event of my text control.
When I do :

Code: Select all

void
CTrainingGameWordControl::OnLeaveFocus( wxFocusEvent& event )
{
	// When leaving the focus, set the new focus on the following element of the widget list
	// If the window this is about to receive the focus is a button, set the focus on the following text control
	wxWindow*	loc_po_window = event.GetWindow() ;
and in this example, window always return NULL.

Is this normal, or there is a problem with this function ?

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

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

Re: wxEVT_FILL_FOCUS event and GetWindow function ?

Post by doublemax » Tue Oct 04, 2011 11:08 am

How does the focus change happen? I think the behavior described in the docs does only happen, if e.g. the focus is in a text control and you click on the "Corriger" button.

What are you trying to achieve? If you're trying to change the normal tab-order, maybe the following methods can help:
wxWindow::MoveAfterInTabOrder
wxWindow::MoveBeforeInTabOrder
wxWindow::Navigate
http://docs.wxwidgets.org/stable/wx_wxw ... intaborder
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: wxEVT_FILL_FOCUS event and GetWindow function ?

Post by Muetdhiver » Tue Oct 04, 2011 2:50 pm

Hi Doublemax and thanks for your answer and your help.
What I want to do does not work yet, even with your advice.

What I want to achieve :

1) Never focus on any button
2) With Tab or keyboard arrow, go to a linked list of all text control (in my example, 30 text controls).
That is to say, when the text control 1 is focused, pressing tab or down arrow key sets the focus on text control 2.
Pressing shift tab or up arrow key sets the focus on text control 30.

Same thing, in text control 30, pressing down key leads to text control 1 ... and so on.
I want to have a "closed circuit" of text control and never focus on buttons.

I also tried what you say :
I think the behavior described in the docs does only happen, if e.g. the focus is in a text control and you click on the "Corriger" button.
In a text control, I clicked on a button, so I came into the EVT_KILL_FOCUS event function, and the GetWindow always returns NULL....... even with a mouse click !!!! What is the condition to have no null window ?

BTW, also tried
wxWindow::MoveAfterInTabOrder
like this :

Code: Select all

for (unsigned char loc_uc_i = 0; loc_uc_i < m_o_widget_words.size() ; loc_uc_i++ )
		{
			if ( loc_uc_i == 0 )
			{
				m_o_widget_words[ 0 ]->MoveAfterInTabOrder(m_o_widget_words[m_o_widget_words.size()-1]);
			}
			else
			{
				m_o_widget_words[loc_uc_i]->MoveAfterInTabOrder(m_o_widget_words[loc_uc_i-1]);
			}
		}
that just make a linked list of text controls, like this:
textControl[0]->MovAfterInTabOrder(textControl[29])
textControl[1]->MovAfterInTabOrder(textControl[0])
textControl[2]->MovAfterInTabOrder(textControl[1])
textControl[3]->MovAfterInTabOrder(textControl[2])
textControl[4]->MovAfterInTabOrder(textControl[3])
etc...
textControl[29]->MovAfterInTabOrder(textControl[28])

But this doesn't work. produced effect is exactly the same as without this code, that is to say, after textControl 29, button is focused, and before the textControl 0, button is also focused.....

It seems there is no way never focus the button....

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

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

Re: wxEVT_FILL_FOCUS event and GetWindow function ?

Post by Muetdhiver » Thu Oct 06, 2011 8:17 am

Please, help ???
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

catalin
Moderator
Moderator
Posts: 1596
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: wxEVT_FILL_FOCUS event and GetWindow function ?

Post by catalin » Thu Oct 06, 2011 11:50 am

Muetdhiver wrote:In a text control, I clicked on a button, so I came into the EVT_KILL_FOCUS event function, and the GetWindow always returns NULL
wxW docs wrote:wxWindow * GetWindow () const
Returns the window associated with this event, that is the window which had the focus before for the wxEVT_SET_FOCUS event and the window which is going to receive focus for the wxEVT_KILL_FOCUS one.
So you should try to handle wxEVT_SET_FOCUS for each button and set the focus back to the window returned by GetWindow().

If that is also NULL (which sounds like a bug somewhere to me), you could try the following:
- have a wxWindow pointer (focusedWin) accessible for every button and every text ctrl;
- in the wxEVT_SET_FOCUS of a text ctrl assign the focused text ctrl to focusedWin;
- in the wxEVT_SET_FOCUS of a button set the focus back to focusedWin;

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

Re: wxEVT_FILL_FOCUS event and GetWindow function ?

Post by Muetdhiver » Thu Oct 06, 2011 1:48 pm

Thanks for your answer.

After trying a lots of solution, I finally move back and I tried something different, but I think it is more in the wxWidgets philosophy....

Instead of trying to catch focus events, and changing the original way of doing, I just thought about using 2 panels : the first one has all text controls and using tab works to go from the first to the last. The second panel thus never receive the focus (so buttons are never focused) instead of course when clicking on a button, but it is desired.

My panels are encapsulated into the vertical sizer. Then, I attach this main sizer to the parent wxFrame with SetSizerAndFit( m_po_sizer_all ) ;

Again thanks for your help.
Bye.
OS: Ubuntu 11.10
Compiler: g++ 4.6.1 (Eclipse CDT Indigo)
wxWidgets: 2.9.3

Post Reply