wxHtmlWindow scrolling problem Topic is solved

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
Jhorsh
Knows some wx things
Knows some wx things
Posts: 26
Joined: Fri Oct 13, 2006 12:24 pm

wxHtmlWindow scrolling problem

Post by Jhorsh » Thu Feb 08, 2007 3:25 pm

Hi

Currently I used wxHtmlWindow for my application as Output window.
I update window using AppendPage method. Everything seems to be fine,
but each adding operation automatically scroll window to NULL position.
Also I've seen this situation, when trying to change window size.
Is anybody knows how to stop this action?

Thanks

Jhorsh
Knows some wx things
Knows some wx things
Posts: 26
Joined: Fri Oct 13, 2006 12:24 pm

Post by Jhorsh » Thu Feb 15, 2007 8:22 am

No ideas?

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Thu Feb 15, 2007 9:06 pm

What's your platform? wxWidgets version?
And could you provide some code (a minimal compilable sample is always the best)

It actually may just be the way that the wxHtml component behaves - however i don't see why scrolling should change when frame is resized

Jhorsh
Knows some wx things
Knows some wx things
Posts: 26
Joined: Fri Oct 13, 2006 12:24 pm

Post by Jhorsh » Mon Feb 19, 2007 10:32 am

OS: WinXP SP2, wxWidgets 2.8.0

The problem is when I call SetSize() methods of wxHtmlWindow control, it changes its size, but content automatically scrolled up.

JSThePatriot
Earned some good credits
Earned some good credits
Posts: 146
Joined: Sun Nov 26, 2006 7:37 am
Location: Tennessee, USA
Contact:

Post by JSThePatriot » Mon Feb 19, 2007 7:52 pm

Does it scroll all the way to the top, or just partially up (in relation to the size change)?

Windows seems to handle resize functions by scrolling up the contents of the window based on the resize performed.

JS

Jhorsh
Knows some wx things
Knows some wx things
Posts: 26
Joined: Fri Oct 13, 2006 12:24 pm

Post by Jhorsh » Tue Feb 20, 2007 9:28 am

It always scrolls to the top of the HTML window.
I've tried to handle resize function and block resize, but no result.
After SetPage() method calling window is scrolled up to the top.

Jhorsh
Knows some wx things
Knows some wx things
Posts: 26
Joined: Fri Oct 13, 2006 12:24 pm

Post by Jhorsh » Mon Feb 26, 2007 11:12 am

Is anyone check the same problem?

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Tue Feb 27, 2007 12:07 am

Can you provide a minimal working example (yes i know i'm always asking for that :P)

Jhorsh
Knows some wx things
Knows some wx things
Posts: 26
Joined: Fri Oct 13, 2006 12:24 pm

Post by Jhorsh » Tue Mar 06, 2007 10:34 am

You may use as example wxWidgets HTML window sample.
When you resize window HTML content will be scrolled up automatically.

User avatar
doublemax
Moderator
Moderator
Posts: 15283
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Tue Mar 06, 2007 12:15 pm

the scroll position is explicitly reset to 0,0 in wxHtmlWindow::CreateLayout()

You could change the code in the wxWidgets library (that's what i did), but it should also be possible to override the method, copy the original contents and make the changes there:

Code: Select all

void wxHtmlWindow::CreateLayout()
{
    int ClientWidth, ClientHeight;

    if (!m_Cell) return;

    if ( HasFlag(wxHW_SCROLLBAR_NEVER) )
    {
        SetScrollbars(1, 1, 0, 0); // always off
        GetClientSize(&ClientWidth, &ClientHeight);
        m_Cell->Layout(ClientWidth);
    }
    else // !wxHW_SCROLLBAR_NEVER
    {
        GetClientSize(&ClientWidth, &ClientHeight);
        m_Cell->Layout(ClientWidth);
        if (ClientHeight < m_Cell->GetHeight() + GetCharHeight())
        {
// ** new code start ********************************
          int x=0;
          int y=0;
          if(m_keepScrollPosition) {
            GetViewStart(&x, &y);
          }
// ** new code end *************************************

            SetScrollbars(
                  wxHTML_SCROLL_STEP, wxHTML_SCROLL_STEP,
                  m_Cell->GetWidth() / wxHTML_SCROLL_STEP,
                  (m_Cell->GetHeight() + GetCharHeight()) / wxHTML_SCROLL_STEP
// ** new code start *********************************************
                 ,x,y
// ** new code end *********************************************
                  /*cheat: top-level frag is always container*/);
        }
        else /* we fit into window, no need for scrollbars */
        {
            SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // disable...
            GetClientSize(&ClientWidth, &ClientHeight);
            m_Cell->Layout(ClientWidth); // ...and relayout
        }
    }
}
Use the source, Luke!

Jhorsh
Knows some wx things
Knows some wx things
Posts: 26
Joined: Fri Oct 13, 2006 12:24 pm

Post by Jhorsh » Tue Mar 06, 2007 1:30 pm

doublemax wrote:the scroll position is explicitly reset to 0,0 in wxHtmlWindow::CreateLayout() ...
Thanks a lot, It's work.
If someone plans to use this code, make CreateLayout function virtual and rebuild wxWidgets solution.

Jhorsh
Knows some wx things
Knows some wx things
Posts: 26
Joined: Fri Oct 13, 2006 12:24 pm

Post by Jhorsh » Tue Oct 30, 2007 2:58 pm

Still the same problem, when I updated wxWidgets version from 2.8.0 to 2.8.6. html window automatically scrolls up to null position.
If I use Scroll() function to scroll window to the and, window scrolls back to the null position.

Have anyone any ideas or solutions?

Thanks.

Here is my code:

Code: Select all

//------------------------------------------------------------------------------
void CustomHtmlWindow::OnSize (wxSizeEvent& a_Event)
{
    wxScrolledWindow::OnSize(a_Event);
    CreateLayout();

    // Recompute selection if necessary:z
    if ( m_selection )
    {
        m_selection->Set(m_selection->GetFromCell(),
            m_selection->GetToCell());
        m_selection->ClearPrivPos();
    }
    Refresh();
}

//------------------------------------------------------------------------------
void CustomHtmlWindow::CreateLayout()
{
    int ClientWidth, ClientHeight;

    if (!m_Cell) 
        return;

    if ( HasFlag(wxHW_SCROLLBAR_NEVER) )
    {
	SetScrollbars(1, 1, 0, 0); // always off
	GetClientSize(&ClientWidth, &ClientHeight);
	    m_Cell->Layout(ClientWidth);
    }
    else // !wxHW_SCROLLBAR_NEVER
    {
        int t_XPos = 0;
        int t_YPos = 0;

	GetClientSize(&ClientWidth, &ClientHeight);
	m_Cell->Layout(ClientWidth);
	if (ClientHeight < m_Cell->GetHeight() + GetCharHeight())
	{
	    GetViewStart(&t_XPos, &t_YPos);
						
	    SetScrollbars(wxHTML_SCROLL_STEP, wxHTML_SCROLL_STEP, m_Cell->GetWidth() / wxHTML_SCROLL_STEP,
(m_Cell->GetHeight() + GetCharHeight()) / wxHTML_SCROLL_STEP,
               t_XPos, t_YPos);
	}
	else /* we fit into window, no need for scrollbars */
	{
		SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // disable...
		GetClientSize(&ClientWidth, &ClientHeight);
			m_Cell->Layout(ClientWidth); 
                // ...and relayout
	}
    }
}

Jhorsh
Knows some wx things
Knows some wx things
Posts: 26
Joined: Fri Oct 13, 2006 12:24 pm

Post by Jhorsh » Tue Oct 30, 2007 3:33 pm

Problem has just fixed.
Please make sure when you update wxWindgets version, you should make void CreateLayout() function virtual in htmlwin.h.

P.S. To developers: could you please add this change to next wxwidgets version?

Thanks

Post Reply