SetFocus fails on wxSTC control inside AuiNotebook (OSX, 2.9.5)

57 views
Skip to first unread message

paulc...@gmail.com

unread,
Feb 25, 2013, 6:44:24 PM2/25/13
to wx-u...@googlegroups.com
Hi All,
 
I ran into this very weird, but reproducible issue with wxSTC control not getting focus inside an AuiNotebook tab (doesn't work on OSX, works on Windows running the same 2.9.5 code from trunk; also works correctly on all platforms with 2.8.12).
 
Steps to reproduce. (1) Take the aui sample and add OnNotebookPageChanged linked to EVT_AUINOTEBOOK_PAGE_CHANGED event:
 
void MyFrame::OnNotebookPageChanged(wxAuiNotebookEvent& evt) {
  wxAuiNotebook* ctrl = (wxAuiNotebook*)evt.GetEventObject();
  ctrl->GetPage(ctrl->GetSelection())->SetFocus();
  evt.Skip();
}
 
Now when the tab is clicked, the focus is on the wxTextCtrl in that tab and you can start typing text right away.
 
(2) Modify two of the tabs to use wxStyledTextCtrl instead of wxTextCtrl. Now when *these* tabs are clicked, the focus is still on the tab itself (you can see this because arrow keys will move control between tabs) and the text cannot be typed into the editor control (you can click on the editor window, but I need to set the focus programmatically).
 
I tried various workarounds with dynamic casting, but nothing helps. wxNotebook doesn't seem to have this issue. Can someone tell me what is going on? Is there a workaround I can use? Or is this a known issue that can be fixed (my search didn't find anything relevant)? This issue is very noticeable to the users and I'd like this to work correctly. Thank you.
 
Paul.

Stefano Mtangoo

unread,
Feb 27, 2013, 12:25:11 AM2/27/13
to wx-users
you mean something like this?
http://forums.wxwidgets.org/viewtopic.php?t=34250&p=140811
>
> Paul.

paulc...@gmail.com

unread,
Feb 27, 2013, 12:43:29 AM2/27/13
to wx-u...@googlegroups.com
Hi Stefano,
yes; My problem was originally in Lua where I do both SetFocus and SetSTCFocus, but it still doesn't work. I was just trying to simplify it to make it more reproducible.
 
> ctrl->GetPage(ctrl->GetSelection())->SetFocus();
I can try adding SetSTCFocus to this example. How do I cast to make SetSTCFocus call (I'm not very familiar with C++ calls in wxwidgets)? Thank you.
 
Paul.

paulc...@gmail.com

unread,
Feb 27, 2013, 12:53:50 AM2/27/13
to wx-u...@googlegroups.com
Hi Stefano,
 
Just to add to this. From the SetSTCFocus description: "The internal focus flag can be set with SetSTCFocus. This is used by clients which have complex focus requirements such as having their own window which gets the real focus but with the need to indicate that Scintilla has the logical focus."
 
I can confirm that in my case it *works* on Windows with or without SetSTCFocus (as I don't have any complex focus requirements). It *doesn't work* on OSX with or without SetSTCFocus (using the same version of wxwidgets 2.9.5 running in my wxlua application). I'll try directly in C++ example if you can help me with SetSTCFocus call. Thanks.
 
Paul.

John Labenski

unread,
Feb 27, 2013, 1:07:04 AM2/27/13
to wx-u...@googlegroups.com
On Wed, Feb 27, 2013 at 12:43 AM, <paulc...@gmail.com> wrote:
> Hi Stefano,
>> you mean something like this?
> http://forums.wxwidgets.org/viewtopic.php?t=34250&p=140811
> yes; My problem was originally in Lua where I do both SetFocus and
> SetSTCFocus, but it still doesn't work. I was just trying to simplify it to
> make it more reproducible.
>
>> ctrl->GetPage(ctrl->GetSelection())->SetFocus();
> I can try adding SetSTCFocus to this example. How do I cast to make
> SetSTCFocus call (I'm not very familiar with C++ calls in wxwidgets)? Thank
> you.

I'm guessing that you are wondering how to turn a wxObject*,
wxWindow*, or other base class of a wxStyledTextCtrl into a
wxStyledTextCtrl* itself (assuming that it really is of that type).

In wxLua : stc = window:DynamicCast("wxStyledTextCtrl")
In C++ : wxStyledTextCtrl* stc = wxDynamicCast(window, wxStyledTextCtrl);

http://docs.wxwidgets.org/2.8/wx_rttimacros.html#wxdynamiccast

Regards,
John

paulc...@gmail.com

unread,
Feb 27, 2013, 1:12:00 AM2/27/13
to wx-u...@googlegroups.com
Hi John,
 
>In wxLua : stc = window:DynamicCast("wxStyledTextCtrl")
>In C++ : wxStyledTextCtrl* stc = wxDynamicCast(window, wxStyledTextCtrl);
Right; thank you. Just wasn't sure how to do it in C++.
 
Paul.

paulc...@gmail.com

unread,
Feb 27, 2013, 11:58:18 AM2/27/13
to wx-u...@googlegroups.com
Hi Teh,
 
Thank you for the link; it doesn't seem to be the same issue, but I agree that it's possibly related as the ticket you referenced and two tickets referenced from it (http://trac.wxwidgets.org/ticket/14142 and http://trac.wxwidgets.org/ticket/13495) all talk about focus events.
 
Stefano, can someone look at these tickets? I tried with SetSTCFocus, but it still doesn't work. The only difference that SetSTCFocus call made is that the cursor can now be seen in the STC tab, but the keyboard input doesn't go to the window (without SetSTCFocus call no cursor is seen). With wxTextCtrl you can see the cursor when you switch to that tab (and SetFocus call is executed) and everything works as expected.
 
Paul.

On Tuesday, February 26, 2013 7:54:25 PM UTC-8, CHON TEH wrote:
Hi,
 
I also face the same problem for this issue.
I create a ticket for this, but didn't explain show details.
 
Still wait for release of 2.95, hope someone will solve it :)
 
Teh

paulc...@gmail.com

unread,
Feb 28, 2013, 12:44:51 PM2/28/13
to wx-u...@googlegroups.com
I opened a ticket for this issue: http://trac.wxwidgets.org/ticket/15070
 
Paul.
 

paulc...@gmail.com

unread,
Mar 4, 2013, 12:54:08 PM3/4/13
to wx-u...@googlegroups.com
Does anyone have any suggestions for a fix or a workaround? (ticket: http://trac.wxwidgets.org/ticket/15070)
 
Paul.
Reply all
Reply to author
Forward
0 new messages