Append HTML to wxHtmlWindow without reloading

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
palacs
Knows some wx things
Knows some wx things
Posts: 45
Joined: Mon May 30, 2016 11:11 am

Append HTML to wxHtmlWindow without reloading

Post by palacs » Mon Apr 15, 2019 5:17 pm

I would like to implement a log viewer that can display formatted HTML text then append small portions of HTML to the existing (usually very long) document. wxHtmlWindow seems to be good for the purpose.

As far as I know this is possible with AppendToPage but I find it really annoying and problematic that it reloads (re-parses, redraws) the entire page every time. At very long HTML documents this can take several seconds. I would like to achieve that wxHtmlWindow loads, parses and draws only the appended part, same as document.write() JavaScript would do to an HTML document in a browser.

Any help is appreciated.
Last edited by palacs on Mon Apr 15, 2019 6:29 pm, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 13288
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Append HTML to wxHtmlWindow without reloading

Post by doublemax » Mon Apr 15, 2019 5:58 pm

I would like to achieve that wxHtmlWindow loads...
Just to be clear: Don't mix up wxHtmlWindow and wxWebView. wxHtmlWindow uses wxWidgets' internal HTML parser which is limited and will be too slow for your purpose. wxWebView is a wrapper around the native browser on the respective platform.
...parses and draws only the appended part, same as document.write() JavaScript would do to an HTML document in a browser.
I think that's exactly what you need to do.

https://docs.wxwidgets.org/trunk/classw ... 5ef9fd0240
Use the source, Luke!

palacs
Knows some wx things
Knows some wx things
Posts: 45
Joined: Mon May 30, 2016 11:11 am

Re: Append HTML to wxHtmlWindow without reloading

Post by palacs » Mon Apr 15, 2019 6:28 pm

Thanks. I know the difference between the two.

However, I would insist using wxHtmlWindow because it's much more resource-efficient when compiled with wxGTK. WebKit is slow, increases loading time and eats up a lot of memory. Basically I need text with basic formatting. Not CSS and JavaScript capabilities. Also, I find running extra javascript code an overkill. It needs to be parsed and run every time a log message arrives. You also need to take care of extra escaping of special characters. This would be a waste of resources. document.write() was just an example of the behavior I want, not an alternative.

So, to be clear, I want the same behavior of document.write() but in wxHtmlWindow. Appending without reloading.

User avatar
doublemax
Moderator
Moderator
Posts: 13288
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Append HTML to wxHtmlWindow without reloading

Post by doublemax » Mon Apr 15, 2019 7:22 pm

I want the same behavior of document.write() but in wxHtmlWindow. Appending without reloading.
I don't think you can get that. It will always parse the whole document if anything changes. And this will get pretty slow the bigger the HTML data gets.

wxRichTextCtrl will be too slow for lots of data, too.

Depending on what kind of formatting abilities you need, you should check wxStyledTextCtrl.
https://docs.wxwidgets.org/trunk/classw ... _ctrl.html

I still think wxWebView is your best option.
Use the source, Luke!

palacs
Knows some wx things
Knows some wx things
Posts: 45
Joined: Mon May 30, 2016 11:11 am

Re: Append HTML to wxHtmlWindow without reloading

Post by palacs » Tue Apr 16, 2019 3:05 pm

Couldn't wxHtmlWindow source code be modified to re-parse and re-draw only the appended part?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3155
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Append HTML to wxHtmlWindow without reloading

Post by ONEEYEMAN » Tue Apr 16, 2019 3:49 pm

Hi,
Well, its an open source project.
You can do whatever.

And if you think it will be beneficial - send an e-mail to wx-dev to ask if this will be a good contribution to the library.

Keep in mind though that wxHtmlWindow supports very limited set of HTML4 tags and the best way of doing what you want is through the wxWebView, just like doublemax suggested.

Thank you.

User avatar
doublemax
Moderator
Moderator
Posts: 13288
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Append HTML to wxHtmlWindow without reloading

Post by doublemax » Tue Apr 16, 2019 4:36 pm

palacs wrote:
Tue Apr 16, 2019 3:05 pm
Couldn't wxHtmlWindow source code be modified to re-parse and re-draw only the appended part?
Theoretically: yes
Practically: Huge effort with no guarantee for success.
Use the source, Luke!

Post Reply