Page 1 of 2

Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 2:51 am
by purplex88
I am looking for a control that will be able to load large scrollable text (e.g. say, 25 MB).

The text doesn't have to be editable, but just viewable.

I also need to highlight the lines in text on mouse clicks.

Which control will be a suitable choice?

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 6:28 am
by doublemax
I would try wxStyledTextCtrl or wxWebView.

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 7:09 am
by PB
If the text is line-oriented (e.g., a CSV file) instead of being paragraph-oriented (text can be wrapped), I would try using wxListCtrl in virtual mode.

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 2:17 pm
by purplex88
Thanks. I am looking at wxWebView. It seems like a complete web browser. I am not using wxListCtrl because its a paragraph oriented text, yes.

Any hints on which functions I will need to paste text into wxWebView and highlight particular lines with mouse clicks? For starters, I need just basic functionality.

After creating it I get this:
WEBbrowserpng.png
WEBbrowserpng.png (13.56 KiB) Viewed 1646 times
It seems like a web browser.

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 5:27 pm
by doublemax
Yes, it is a webbrowser. And as such much better optimized to display large amounts of text than any other control. That's why i suggested it.

In the most simple form, you just call wxWebView::SetPage() with a basic html page.

Code: Select all

<html><body><pre>
your text here
</pre></body></html>
ny hints on which functions I will need to paste text into wxWebView and highlight particular lines with mouse clicks?
What exactly do you need? When i read your first post i thought you meant simple text selection for copy and paste. That should work out of the box.

If you need more fancy stuff, you might need to know at least basic things about HTML (eventually CSS) and JavaScript.

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 6:48 pm
by purplex88
I want to just display a large .txt file.

So for example, here's how a "sample text" should appear:
WEBbrowserpng.jpg
WEBbrowserpng.jpg (67.53 KiB) Viewed 1627 times

That's a photoshopped image just for example.

I should be able to mouse hover lines and highlight text on mouse clicks.

Do I need to add html tags to display text and highlight?

Here's what I tried:

Code: Select all

wxString str = "<html><body><pre>your text here</pre></body></html>";
TextViewer->SetPage(str, "");
The output was:
WEBbrowserpng.png
WEBbrowserpng.png (13.56 KiB) Viewed 1627 times

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 6:51 pm
by ONEEYEMAN
Hi,
Are you trying to run it underWindows 10?
It is possible you default browser is set to M$ Edge and not IE....

Thank you.

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 6:54 pm
by purplex88
Hi, It is Windows 8.1 OS and wxWidgets-3.1.2 setup environment under MSVS 2019. I am not exactly going to use the control to load internet web pages, but just local text (.txt/ .html) files.

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 7:57 pm
by doublemax
Can you show the code where you create the webview control?
E.g. you should not pass "" as url when creating it. The default is "about:blank".

It's also possible that you need to wait for the wxEVT_WEBVIEW_LOADED event and set the new page from there.

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 8:15 pm
by purplex88
Okay, I see.

I changed this:

Code: Select all

TextViewer = wxWebView::New(m_panel, wxID_ANY, "");
to:

Code: Select all

TextViewer = wxWebView::New(m_panel, wxID_ANY, "about:blank");
Now, it appears to work.

It seems I will need to convert the text files into html to display the data and highlight it.

I am not much aware of web development languages.. So to get started,
  • Do I need to use JavaScript here for mouse hover actions on text and highlight?
  • Can I disable horizontal scroll and do word wrap of text?

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 8:35 pm
by doublemax
Do I need to use JavaScript here for mouse hover actions on text and highlight?
Text selection and copy/paste should work out of the box. For hover action you'll need either CSS or JS, depending on what you need. Can you explain?
Can I disable horizontal scroll and do word wrap of text?
Remove the <pre></pre> tags.

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 9:23 pm
by purplex88
@doublemax: I have a 20 secs photoshopped clip in which I tried to explain exactly what I am tying to do. I want to hover the mouse over text and it should highlight the line. When I mouseclick over it then it changes highlight.

Okay, to achieve this. I know where the lines start and end. So, basically, do I need to add some JavaScript here for mouse events and dynamic highlights?

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 9:34 pm
by doublemax
The hover effect could be done with CSS alone. For the click handling you need JS. As this code has to be added to every single line of text, this might at least double the length of the text.

Did you already make a test how the control behaves with 25mb of text?

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 10:12 pm
by purplex88
I'd be happy if it works with at least 2 MB of text for now. Yes, I tried it with ~25 MB file and it appears to load it fine as well but because there's too much to scroll, it can get slow and unresponsive.

Currently, I'd just focus on highlighting and seems like I'd need to learn some CSS / Javascript stuff.

Re: Control for text display, highlight and scroll

Posted: Wed Dec 11, 2019 10:42 pm
by purplex88
So, is it really not possible to edit and save text as html within this control? Maybe via. Javascript again?