Page 1 of 1

Append HTML to wxHtmlWindow without reloading

Posted: Mon Apr 15, 2019 5:17 pm
by palacs
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.

Re: Append HTML to wxHtmlWindow without reloading

Posted: Mon Apr 15, 2019 5:58 pm
by doublemax
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

Re: Append HTML to wxHtmlWindow without reloading

Posted: Mon Apr 15, 2019 6:28 pm
by palacs
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.

Re: Append HTML to wxHtmlWindow without reloading

Posted: Mon Apr 15, 2019 7:22 pm
by doublemax
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.

Re: Append HTML to wxHtmlWindow without reloading

Posted: Tue Apr 16, 2019 3:05 pm
by palacs
Couldn't wxHtmlWindow source code be modified to re-parse and re-draw only the appended part?

Re: Append HTML to wxHtmlWindow without reloading

Posted: Tue Apr 16, 2019 3:49 pm
by ONEEYEMAN
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.

Re: Append HTML to wxHtmlWindow without reloading

Posted: Tue Apr 16, 2019 4:36 pm
by doublemax
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.