Control for text display, highlight and scroll

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.
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Control for text display, highlight and scroll

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Control for text display, highlight and scroll

Post by doublemax »

I would try wxStyledTextCtrl or wxWebView.
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Control for text display, highlight and scroll

Post 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.
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Control for text display, highlight and scroll

Post 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 1643 times
It seems like a web browser.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Control for text display, highlight and scroll

Post 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.
Use the source, Luke!
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Control for text display, highlight and scroll

Post 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 1624 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 1624 times
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Control for text display, highlight and scroll

Post 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.
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Control for text display, highlight and scroll

Post 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.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Control for text display, highlight and scroll

Post 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.
Use the source, Luke!
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Control for text display, highlight and scroll

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Control for text display, highlight and scroll

Post 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.
Use the source, Luke!
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Control for text display, highlight and scroll

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Control for text display, highlight and scroll

Post 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?
Use the source, Luke!
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Control for text display, highlight and scroll

Post 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.
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Control for text display, highlight and scroll

Post by purplex88 »

So, is it really not possible to edit and save text as html within this control? Maybe via. Javascript again?
Post Reply