#45 ScrollView should not scroll horizontally if not needed (2)

Unstable (example)
closed-fixed
None
5
2014-02-18
2012-10-13
Nenad Stefanovic
No

From WTL Group on Yahoo:

Hi Nenad,

I have controls derived from 'CScrollWindowImpl<MyControl, CFSBWindow>' and particularly a DataGrid.
I noticed that when I turned my mouse's wheel (even if I dont need to scroll) some parts of my control were flickering.
So I checked the atlscrl.h file's code, more precisely CScrollImpl and the OnMouseWheel handler (line #491 for the latest version of WTL) and found this:

if(m_sizeAll.cy > m_sizeClient.cy)
{
for(int i = 0; i < zTotal; i += WHEEL_DELTA)
{
pT->DoScroll(SB_VERT, nScrollCode, (int&)m_ptOffset.y, m_sizeAll.cy, m_sizePage.cy, m_sizeLine.cy);
pT->UpdateWindow();
}
}
else // can't scroll vertically, scroll horizontally
{
for(int i = 0; i < zTotal; i += WHEEL_DELTA)
{
pT->DoScroll(SB_HORZ, nScrollCode, (int&)m_ptOffset.x, m_sizeAll.cx, m_sizePage.cx, m_sizeLine.cx);
pT->UpdateWindow();
}
}

This code means that if the mouse's wheel is turned then
if(m_sizeAll.cy > m_sizeClient.cy)
it will scroll vertically and update (repaint) the client rect of the control
else
it will scroll horizontally and update (repaint) the client rect of the control

Which is by the way a very good idea.

But before scrolling horizontally (and update the window) we have to check if it is necessary and it is necessary only
if(m_sizeAll.cx > m_sizeClient.cx) as there's no reason to scroll horizontally if the control width is not larger than the client width ;o)

I modified it like this:

if(m_sizeAll.cy > m_sizeClient.cy)
{
for(int i = 0; i < zTotal; i += WHEEL_DELTA)
{
pT->DoScroll(SB_VERT, nScrollCode, (int&)m_ptOffset.y, m_sizeAll.cy, m_sizePage.cy, m_sizeLine.cy);
pT->UpdateWindow();
}
}
else // can't scroll vertically, scroll horizontally
{
if(m_sizeAll.cx > m_sizeClient.cx)
{
for(int i = 0; i < zTotal; i += WHEEL_DELTA)
{
pT->DoScroll(SB_HORZ, nScrollCode, (int&)m_ptOffset.x, m_sizeAll.cx, m_sizePage.cx, m_sizeLine.cx);
pT->UpdateWindow();
}
}
}

and everything is perfect with my Grid, no more flickering!

I know it's a minor problem but this flickering was so annoying so I hope it helps.
Long live WTL and all the best to you and the WTL team.

Philippe Marechal

Discussion


Anonymous


Cancel   Add attachments