wxWebView::SetPage() without losing focus

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
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Thu Nov 16, 2017 9:32 pm

wxWebView::SetPage() without losing focus

Post by saifcoder » Sat Nov 16, 2019 11:36 pm

I'm working on a WYSIWYG (https://en.wikipedia.org/wiki/WYSIWYG) project, I'm trying to show the result immediately after any change happened to wxTextCtrl, the problem is when I update the wxWebView by SetPage(), cursor focus set automatically to the wxWebView, so user need to click again on wxTextCtrl to make new change!

Code: Select all

MyWebView->SetPage(MyTextCtrl->GetValue(), "");
Question: How to use wxWebView::SetPage() without cursor focus?
Attachments
screenshoot.png
screenshoot.png (46.86 KiB) Viewed 334 times
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Thu Nov 16, 2017 9:32 pm

Re: wxWebView::SetPage() without losing focus

Post by saifcoder » Sat Nov 16, 2019 11:52 pm

I fixed it by MyTextCtrl->Setfocus(), but is this is the best solution? I mean Setfocus() after every char added (OnKeyDown) ?
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Thu Nov 16, 2017 9:32 pm

Re: wxWebView::SetPage() without losing focus

Post by saifcoder » Sun Nov 17, 2019 5:24 pm

Ops, when user Click on Webview, then back to code editor (STC) the Setfocus() stop working!

Anyone have an idea how to use MyWebView->SetPage() without losing focus ?
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Thu Nov 16, 2017 9:32 pm

Re: wxWebView::SetPage() without losing focus

Post by saifcoder » Sun Nov 17, 2019 6:07 pm

I search a way to get the event when wxWebview is focused, selected, left click.. to set back the focus to the code editor.

any idea ?
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2292
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: wxWebView::SetPage() without losing focus

Post by evstevemd » Sun Nov 17, 2019 6:35 pm

Soon after updating wxWebView you need to call setFocus to your wxSTC
If that doesn't work try wxStyledTextCtrl::SetSTCFocus
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Thu Nov 16, 2017 9:32 pm

Re: wxWebView::SetPage() without losing focus

Post by saifcoder » Sun Nov 17, 2019 7:24 pm

after updating wxWebView you need to call setFocus to your wxSTC
Yes it's work, but when user just click on the wxWebView so no update event created and the focus still on the wxWebView!
try wxStyledTextCtrl::SetSTCFocus
I don't know what this function do, but I use SetSTCFocus(true) everywhere! and the focus still on the webview!
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Thu Nov 16, 2017 9:32 pm

Re: wxWebView::SetPage() without losing focus

Post by saifcoder » Sun Nov 17, 2019 7:28 pm

I searching how to show the Webview and set it not clickable like mywxWebview->SetEditable(false) but no effect!

Is there any way to create an transparent object (like toSizer) on the top of the window and it hold full form to block any click on the webview !!
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2292
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: wxWebView::SetPage() without losing focus

Post by evstevemd » Sun Nov 17, 2019 8:07 pm

If wxWebView is the only thing that eats the focus then all you need is catch the focus received event for wxWebview object, swnd it back to wxStc same as you do now and skip the event. That way, every time wxWV receives a focus it focuses wxStc
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Thu Nov 16, 2017 9:32 pm

Re: wxWebView::SetPage() without losing focus

Post by saifcoder » Sun Nov 17, 2019 8:11 pm

Yes, but I didn't find focus event for the wxWebview in the documentation! is there one?
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 70
Joined: Thu Nov 16, 2017 9:32 pm

Re: wxWebView::SetPage() without losing focus

Post by saifcoder » Sun Nov 17, 2019 9:15 pm

maybe this is the problem: IProtectFocus interface https://docs.microsoft.com/en-us/previo ... dfrom=MSDN
Debian 9 - GCC 6 - wxWidgets 3.1 U
Win 7 - GCC 5 - wxWidgets 3.1 U
Mac OS X 10.6 - GCC 4 - wxWidgets 3.1 U
i am in love with WX. Yes.

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2292
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: wxWebView::SetPage() without losing focus

Post by evstevemd » Mon Nov 18, 2019 5:49 am

saifcoder wrote:
Sun Nov 17, 2019 8:11 pm
Yes, but I didn't find focus event for the wxWebview in the documentation! is there one?
wxWebView inherits from wxControl which in turn inherits from wxWindow (shown in docs inheritance tree). So you have wxEVT_SET_FOCUS. See documentation at https://docs.wxwidgets.org/3.0/classwx_window.html
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

Post Reply