FindFocus() returns NULL pointer wxWidgets 2.9.2 trunk 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
okurtsev
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jan 25, 2010 3:26 pm
Location: Ukraine, Kiev

FindFocus() returns NULL pointer wxWidgets 2.9.2 trunk

Post by okurtsev »

Because of the problem I described here - http://forums.wxwidgets.org/viewtopic.php?p=124275 I've tried to migrate to 2.9.2 where it was fixed, but here is also one more big problem.

I have an edit control in AUI panel. Using EVT_UPDATE_UI I update it, but of course only when it is not in focus.

Code: Select all

void CMainFrame::OnUpdateFrameNumber(wxUpdateUIEvent& i_event)
{
...
	wxWindow* wnd = FindFocus();
	if (!wnd || (wnd->GetId() != ID_FRAME_EDIT_CONTROL))//Frame editbox is not in focus
	{

		GetFrameNumber();
...
It works very well with 2.8.11, but in 2.9.2 FindFocus() almost always returns NULL! 2.9.1 behaves similarly. So it is impossible to make any input in the edit box, because any input is immediately spoiled by GetFrameNumber().

I would stand with 2.8.11, but 2.9.x has some very pleasant fixes. Probably someone knows what happens with FindFocus in 2.9.2? Probably I just should make some changes in code. Any help would be greatly appreciated.

Thank you.
C++, Win XP-32, Win7-64, WinVista-32, MS VS 2005, 2008, 2010
jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche »

I suppose that you hope that the focus is the one which emit the event. So, you can use the event ID (which is the control ID that emit the event).

Code: Select all

void CMainFrame::OnUpdateFrameNumber(wxUpdateUIEvent& i_event)
{
...
        if (i_event->GetId() != ID_FRAME_EDIT_CONTROL)
        {
                GetFrameNumber();
...
Jérémie
okurtsev
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jan 25, 2010 3:26 pm
Location: Ukraine, Kiev

Post by okurtsev »

There is
EVT_UPDATE_UI(ID_FRAME_EDIT_CONTROL, CMainFrame::OnUpdateFrameNumber)

Unfortunately i_event.GetId() is always equal ID_FRAME_EDIT_CONTROL.
I need this update almost always - then document is changed, frame of video is changed, but I do not need it if the user edit the value manually. Probably there is another way except FindFocus() - which doesn't work for some reason - to check where is the input focus?
C++, Win XP-32, Win7-64, WinVista-32, MS VS 2005, 2008, 2010
jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche »

EVT_UPDATE_UI(ID_FRAME_EDIT_CONTROL, CMainFrame::OnUpdateFrameNumber)
Jérémie
okurtsev
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jan 25, 2010 3:26 pm
Location: Ukraine, Kiev

Post by okurtsev »

Pardon me?
C++, Win XP-32, Win7-64, WinVista-32, MS VS 2005, 2008, 2010
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

I don't know if the FindFocus() behavior on wx 2.9.x changed and/or if this is a new bug, but as a workaround you could catch wxEVT_SET_FOCUS & wxEVT_KILL_FOCUS on the textcontrol and set a flag yourself.

http://docs.wxwidgets.org/stable/wx_wxf ... focusevent
Use the source, Luke!
jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche »

Oups, my post was not correctly sent :shock:

I was asking you why did you choose to manage the EVT_UPDATE_UI of the ID_FRAME_EDIT_CONTROL, if you don't really want to. You could manage it for the control you really need.
Jérémie
okurtsev
Experienced Solver
Experienced Solver
Posts: 54
Joined: Mon Jan 25, 2010 3:26 pm
Location: Ukraine, Kiev

Post by okurtsev »

I was asking you why did you choose to manage the EVT_UPDATE_UI of the ID_FRAME_EDIT_CONTROL, if you don't really want to. You could manage it for the control you really need.
Sorry, don't understand what is it about. Off course I want to manage it, and off course I really need it.

Probably it would help somebody - http://trac.wxwidgets.org/ticket/12713
C++, Win XP-32, Win7-64, WinVista-32, MS VS 2005, 2008, 2010
ngpaton
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue May 20, 2008 8:23 am

Post by ngpaton »

Hi,

I notice that the AUI code itself is not Skipping focus events. See wxAuiTabCtrl::OnSetFocus() and wxAuiTabCtrl::OnKillFocus() in auibook.cpp.

Surprising that the need to Skip the event is not mentioned in the documentation for the wxFocusEvent.

Cheers

Nigel
Post Reply