Is it possible to highlight texts in a wxHtmlWindow or wxWebView?

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
hao
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Dec 20, 2018 3:53 am

Is it possible to highlight texts in a wxHtmlWindow or wxWebView?

Post by hao »

I want to highlight texts in a rendered HTML with a background color or underline, given the start and end position of the portion of the text to highlight.

I wonder if this highlight function is already supported by current wxWidgets, when using wxWebView/wxHtmlWindow to render a HTML page.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is it possible to highlight texts in a wxHtmlWindow or wxWebView?

Post by doublemax »

This is not supported by either control.

If the HTML code is under your control, you could just change it there. But i can't think of any way to do this for any random website. If you find some JavaScript code that does this, you can execute it with wxWebView::RunScript().
Use the source, Luke!
hao
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Dec 20, 2018 3:53 am

Re: Is it possible to highlight texts in a wxHtmlWindow or wxWebView?

Post by hao »

doublemax wrote:This is not supported by either control.

If the HTML code is under your control, you could just change it there. But i can't think of any way to do this for any random website. If you find some JavaScript code that does this, you can execute it with wxWebView::RunScript().
Thanks! Yes, I do have full control of the HTML, and I can use JavaScript to highlight, but more than that I also want users to interact with the page. For example, clicking on the highlighted text can trigger a wxDialog showing up. Is that possible?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is it possible to highlight texts in a wxHtmlWindow or wxWebView?

Post by doublemax »

This is something that had to be done on the JavaScript side. Transferring the information back to the C++ code is the problem. There is no function for that. The common workaround is to change the title of the html page with JS and catch the wxEVT_WEBVIEW_TITLE_CHANGED event on the C++ side. That way you can transmit small pieces of information.
Use the source, Luke!
hao
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Dec 20, 2018 3:53 am

Re: Is it possible to highlight texts in a wxHtmlWindow or wxWebView?

Post by hao »

doublemax wrote:This is something that had to be done on the JavaScript side. Transferring the information back to the C++ code is the problem. There is no function for that. The common workaround is to change the title of the html page with JS and catch the wxEVT_WEBVIEW_TITLE_CHANGED event on the C++ side. That way you can transmit small pieces of information.
thanks a lot, I think i'll try the workaround.
Post Reply