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: 80
Joined: Thu Nov 16, 2017 9:32 pm

wxWebView::SetPage() without losing focus

Post by saifcoder »

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 1605 times
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: wxWebView::SetPage() without losing focus

Post by saifcoder »

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.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: wxWebView::SetPage() without losing focus

Post by saifcoder »

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.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: wxWebView::SetPage() without losing focus

Post by saifcoder »

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.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: wxWebView::SetPage() without losing focus

Post by evstevemd »

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

Re: wxWebView::SetPage() without losing focus

Post by saifcoder »

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.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: wxWebView::SetPage() without losing focus

Post by saifcoder »

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.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: wxWebView::SetPage() without losing focus

Post by evstevemd »

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

Re: wxWebView::SetPage() without losing focus

Post by saifcoder »

Yes, but I didn't find focus event for the wxWebview in the documentation! is there one?
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: wxWebView::SetPage() without losing focus

Post by saifcoder »

maybe this is the problem: IProtectFocus interface https://docs.microsoft.com/en-us/previo ... dfrom=MSDN
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: wxWebView::SetPage() without losing focus

Post by evstevemd »

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?
Post Reply