wxRichTechCtrl scroll weirdness, autoscroll/scroll cutting off text.

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
koekhaos
Earned a small fee
Earned a small fee
Posts: 17
Joined: Tue Jun 13, 2017 7:55 pm

wxRichTechCtrl scroll weirdness, autoscroll/scroll cutting off text.

Post by koekhaos »

TL;DR
1: Why does wxRichtTextControl randomly place lines at the end of the scroll sometimes cutting them off? Is there a way to fix it?
2: Why doesn't wxRichTextControl have an autoscroll option like wxTextControl?
3: Is there some sort of way to have text begin on the bottom and as you add to it move upwards instead of start at the top and move downwards?

I'm trying to build a cross platform telnet client, mostly for my own interests in learning sockets and such when connecting to a MUD, and chose wxWidgets for use. I started out using wxTextCtrl which worked great since it autoscrolled and didn't cut anything off but then learned it could only go to, basically, under 400 lines which for playing on a mud where I would want 20,000 lines of scroll back just wouldn't work. I found that perhaps wxRichTextCtrl was the answer to this so I started working with it but then found it doesn't have an option to autoscroll. I found a few posts indicating how to make auto scrolling work. Next I found out, using auto scroll or not, that wxRichTextControl randomly ends the scroll sometimes cutting off characters even though the scroll bar is isn't all the way at the bottom. I included an image of it for example. Is there a way around this? I searched through the bug tacker but couldn't find anything about this anywhere. One other question I had has to do with where text starts. By default it starts at the top left and new appends go below it. Is there a way to start on the bottom of the control instead so that I don't have to use "/n" filling up the screen to get to the same effect?

Here are various examples when I append a new 'g' into the window and how they show up in random alignments. Each has the scroll bar fully to the bottom.
scrollerror.png
scrollerror.png (5.41 KiB) Viewed 2724 times
Related posts:
http://wxwidgets.10942.n7.nabble.com/wx ... 32666.html (Here Julian Smart is talking about it being a bug but this is ancient!)
viewtopic.php?t=20928
viewtopic.php?t=25725
viewtopic.php?t=20062

The interesting thing about these posts are that they specifically are talking about this weird scroll spacing in relation to trying to implement auto-scrolling but I found it to do it even if without any sort of code for scrolling to the bottom. Manually results in the same issue.
Last edited by koekhaos on Tue Jun 13, 2017 11:04 pm, edited 2 times in total.
User avatar
doublemax
Moderator
Moderator
Posts: 19161
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxRichTechCtrl scroll weirdness, autoscroll/scroll cutting off text.

Post by doublemax »

Regardless of the scrolling bug - which i can say nothing about - i'm pretty sure wxRTC will be too slow if you fill it with 20000 lines.

I would suggest to look into wxStyledTextCtrl which is a wrapper around Scintilla. Unfortunately there is practically no (useful) documentation except for the original from Scintilla. Which is not very helpful either.
Use the source, Luke!
koekhaos
Earned a small fee
Earned a small fee
Posts: 17
Joined: Tue Jun 13, 2017 7:55 pm

Re: wxRichTechCtrl scroll weirdness, autoscroll/scroll cutting off text.

Post by koekhaos »

Hmm, I'll take a look at the Scintilla thing though I don't know anything about it. It should be quicker you think? I've also tried taking a look at the behind the scenes code for wxRichTextCtrl which I noticed says " // TODO: reimplement scrolling so we scroll by line, not by fixed number
// of pixels. See e.g. wxVScrolledWindow for ideas." which makes me think this was something that was being looked at at some point in the past. I'm only an amateur programmer so not sure if it would be something I could figure out or not as some of this stuff is pretty complex.
koekhaos
Earned a small fee
Earned a small fee
Posts: 17
Joined: Tue Jun 13, 2017 7:55 pm

Re: wxRichTechCtrl scroll weirdness, autoscroll/scroll cutting off text.

Post by koekhaos »

So I tried adding the wxSytledTextCtrl but it seems to be missing from wxSmith oddly! I then messed a bit more with wxRichTextCtrl and it actually works fine with even 40,000 lines of text mostly. I tested it by loading in a file, which is a little bit slow to load in but I am not planning to load in files anyhow so I don't worry about that. It's just the continued problem from above where it cuts off text on the bottom when scrolled all the way down. Also doesn't seem to handle LF correctly as it ignores some of them but might just be me needing to edit in CRLF or something internal.
User avatar
doublemax
Moderator
Moderator
Posts: 19161
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxRichTechCtrl scroll weirdness, autoscroll/scroll cutting off text.

Post by doublemax »

The way i understand it, all you really need is to scroll the window to the very bottom?

Did you try something like this?

Code: Select all

m_richTextCtrl->AppendText("\njust another line");
m_richTextCtrl->Scroll( 0, m_richTextCtrl->GetVirtualSize().y - m_richTextCtrl->GetClientSize().y ); 
Use the source, Luke!
koekhaos
Earned a small fee
Earned a small fee
Posts: 17
Joined: Tue Jun 13, 2017 7:55 pm

Re: wxRichTechCtrl scroll weirdness, autoscroll/scroll cutting off text.

Post by koekhaos »

I actually have been messing around with the controls a bit and just tried putting more text from a file just to test them and found that the normal wxTextCtrl can easily handle even 2MB of text! I guess all the API Docs/book claiming it can only handle 64k unless you use rich mode are outdated now? Or maybe it is based on the underlying version of the operating system? Anyhow, this makes me happy! It's also quite fast to scroll through it after it loads. Loading 2MB itself only took 8 seconds. I'll let you know how it goes as I actually get an implementation going. For curiosity I tried loading a 120MB text file but after several minutes of it just churning away in the background I killed the process. So while 2MB works fine it seems there is some limit. Also note that I did this in Windows 8.1. Edit: I tested a 13MB file and it took 90 seconds to load, so even 13MB is possible, but it starts getting MUCH slower. I assume then that 120MB would load eventually but the time to load seems to take exponentially longer. Hopefully this info will help others deciding if they can use this too!

I do have one new question though. When using wxTextFile or wxTextInputStream it seems that \n get stripped when I output the text. Is there a way to preserve that information so I don't have to add the second AppendText with a \n? Sorry if this is a stupid question but text formatting is a whole new area for me and I couldn't understand a lot of the examples I've seen which seem to indicate they should handle this automatically. Example below.

Code: Select all

    wxFileInputStream input("D:\\CF\\Mudlist.txt");
    wxTextInputStream text(input);

    while(input.IsOk() && !input.Eof())
    {
        TextBox->AppendText(text.ReadLine());
        TextBox->AppendText(_("\n"));
    }
User avatar
doublemax
Moderator
Moderator
Posts: 19161
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxRichTechCtrl scroll weirdness, autoscroll/scroll cutting off text.

Post by doublemax »

Is there a reason why you load the file line-by-line?
I would use wxFFile::ReadAll to read the whole file into a wxString one go:
http://docs.wxwidgets.org/trunk/classwx ... b179b40af3
Use the source, Luke!
koekhaos
Earned a small fee
Earned a small fee
Posts: 17
Joined: Tue Jun 13, 2017 7:55 pm

Re: wxRichTechCtrl scroll weirdness, autoscroll/scroll cutting off text.

Post by koekhaos »

Wow, that makes a huge difference! I can actually open that 130MB text file, which has 132 million characters, in 28 seconds using the readall method! And the standard wxTextCtrl can hold the entire thing and preserves the \n this way. Even better, the 2MB text file opens instantly which is likely the maximum size I would want to even open. Awesome! Thanks a ton for the help. :) I'm sure I'll have other strange questions in the future but this gives me a good starting point to continue from!

Example below for those who stumble across this.

Code: Select all

    wxFFile file("D:\\CF\\Mudlist.txt");
    wxString input;
    file.ReadAll(&input);
    TextBox->AppendText(input);
Figuring out how to build in Linux right now, which I think I just got working, and then Mac next so I can see how they handle it. I'll let people know how that goes just for other people coming with questions on this topic since I saw a lot of posts about it but with little real feedback or how they got along. Thanks again!

Edit: Got it to compile and works great on Ubuntu 16.04 so wxTextCtrl can handle more than it used to on at least modern Windows and Linux OS. :D
Post Reply