Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » RichText,QTF,RTF... » RichText scrolling problem
RichText scrolling problem [message #25362] Fri, 19 February 2010 04:51 Go to next message
javelin is currently offline  javelin
Messages: 3
Registered: November 2009
Junior Member
Hi, my name's Mark and I've been lurking for a long time in this forum to my lasting shame. I'm currently involved in a mobile IM and chat project that has enjoyed moderate success here in my country. We also have a desktop version of our app made in wxWdigets and I hope to rewrite the whole stuff in U++ from the ground up. So far i've managed to do fairly well resulting to this:

http://4.bp.blogspot.com/_PkUv5qu-Esc/S34FpnPFIuI/AAAAAAAAADk/5dQIG1u-QTo/s1600-h/uzzap2.jpg

My question is this: My chat and IM views use the RichTextView controls and I need to scroll down to the very bottom every time a new message comes up only IF the view is already scrolled down to the bottom. If the user is viewing some back messages or he is not currently scrolled to the very bottom, the view should only scroll down to where the he was at before the new message came. I did this but I'm not satisfied because sometimes the view still scrolls one line down when it's not at the bottom:

int sb = output_.GetSb(), tsb = output_.GetSbTotal(), tsb2;
output_ <<= ~output + qtf;
tsb2 = output_.GetSbTotal();
_output_.SetSb(sb + abs(tsb2 - tsb));
_output_.BackPaint();


Could anyone suggest another and better (,perhaps easier) way to do this?
Re: RichText scrolling problem [message #25363 is a reply to message #25362] Fri, 19 February 2010 05:19 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 736
Registered: January 2008
Location: Moscow, Russia
Contributor

Try to view ExpandFrame from Bazaar.
There are many useful code for your project.

I also try to understand how to scroll the window automatically in the right place, and I even partly understand
(Hint: try to use scroll.Set(somepos) and then scroller.Scroll(*this,scroll.Get())Wink


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Fri, 19 February 2010 05:23]

Report message to a moderator

Re: RichText scrolling problem [message #25364 is a reply to message #25363] Fri, 19 February 2010 07:14 Go to previous messageGo to next message
javelin is currently offline  javelin
Messages: 3
Registered: November 2009
Junior Member
Hello Sergey,

Thanks for the suggestion but the scollbar and scroller instances of RichTextView are private and so can't be accessed. Anyway, I think I found the solution. I found out that if you get the difference of ScrollBar::Get() and ScrollBar::GetTotal() (both exposed respectively as RichTextView::GetSb() and RichTextView::GetSbTotal()), you get a certain magic number which means that you're scrolled to the very bottom of the whole text. I don't know how to get this number so I just did a sort of hack to get it:

int sb = output_.GetSb(), tsb = output_.GetSbTotal();

output_ <<= ~output + qtf;

if (!sb && !tsb) { //Both are still zero if view has nothing.
    _output.ScrollEnd();
    _sbConst = _output_.GetSbTotal() - _output_.GetSb(); //_sbConst is a member var initialized here to contain the magic number
} else {
    ASSERT(_sbConst > 0);
    if (tsb - sb != _sbConst) _output_.SetSb(sb);
    else _output_.ScrollEnd();
}


Thanks to all the people behind U++ for such an awesome platform!

Mark
Re: RichText scrolling problem [message #25369 is a reply to message #25364] Fri, 19 February 2010 12:28 Go to previous messageGo to next message
javelin is currently offline  javelin
Messages: 3
Registered: November 2009
Junior Member
Woops there's a bug in my code. When initializing _sbConst I was assuming that tsb will always be bigger than the page size. The code below corrects this:

int sb = output_.GetSb(), tsb = output_.GetSbTotal();

output_ <<= ~output_ + qtf;

if (!_sbConst) {
    output_.ScrollEnd();
    sb = output_.GetSb();
    tsb = output_.GetSbTotal();
    if (tsb > sb && tsb > output_.GetSbPage())
        _sbConst = tsb - sb;
} else {
    if (abs(tsb - sb) != _sbConst) output_.SetSb(sb);
    else output_.ScrollEnd();
}


But this now requires that ScrollBar::GetPage() be exposed as RichTextView::GetSbPage(). Sad Can we do this guys?

Mark
Re: RichText scrolling problem [message #25371 is a reply to message #25369] Fri, 19 February 2010 15:27 Go to previous message
sergeynikitin is currently offline  sergeynikitin
Messages: 736
Registered: January 2008
Location: Moscow, Russia
Contributor

GetPage()+GetPos(Last Position) = GetTotal()
Rect in same unit - GetScreenRect(of window) - Size and position of window
Rect in same unit - GetScreenRect(of ctrl) - Size and position of ctrl

Try this aprove.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Fri, 19 February 2010 15:28]

Report message to a moderator

Previous Topic: Default font and fontsize in RichEdit
Next Topic: Strange memory problem in QTF RichView
Goto Forum:
  


Current Time: Sat Sep 21 01:09:51 CEST 2019

Total time taken to generate the page: 0.18565 seconds