Refactoring FListView scroll bar callbacks

This commit is contained in:
Markus Gans 2018-02-20 23:35:10 +01:00
parent 4778de5c52
commit 8bc40459e0
2 changed files with 26 additions and 47 deletions

View File

@ -354,6 +354,7 @@ class FListView : public FWidget
void scrollToY (int); void scrollToY (int);
void scrollTo (const FPoint &); void scrollTo (const FPoint &);
void scrollTo (int, int); void scrollTo (int, int);
void scrollBy (int, int);
// Callback methods // Callback methods
void cb_VBarChange (FWidget*, data_ptr); void cb_VBarChange (FWidget*, data_ptr);

View File

@ -2054,14 +2054,25 @@ void FListView::scrollTo (int x, int y)
scrollToY(y); scrollToY(y);
} }
//----------------------------------------------------------------------
void FListView::scrollBy (int dx, int dy)
{
scrollToX(xoffset + dx);
if ( dy > 0 )
stepForward(dy);
if ( dy < 0 )
stepBackward(-dy);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::cb_VBarChange (FWidget*, data_ptr) void FListView::cb_VBarChange (FWidget*, data_ptr)
{ {
FScrollbar::sType scrollType; FScrollbar::sType scrollType = vbar->getScrollType();
int distance = 1; int distance = 1
int first_line_position_before = first_visible_line.getPosition(); , pagesize = 4
, first_line_position_before = first_visible_line.getPosition();
scrollType = vbar->getScrollType();
switch ( scrollType ) switch ( scrollType )
{ {
@ -2086,22 +2097,15 @@ void FListView::cb_VBarChange (FWidget*, data_ptr)
{ {
int value = vbar->getValue(); int value = vbar->getValue();
scrollToY (value); scrollToY (value);
break; break;
} }
case FScrollbar::scrollWheelUp: case FScrollbar::scrollWheelUp:
{ wheelUp (pagesize);
FWheelEvent wheel_ev (fc::MouseWheel_Event, FPoint(2,2), fc::WheelUp);
onWheel(&wheel_ev);
}
break; break;
case FScrollbar::scrollWheelDown: case FScrollbar::scrollWheelDown:
{ wheelDown (pagesize);
FWheelEvent wheel_ev (fc::MouseWheel_Event, FPoint(2,2), fc::WheelDown);
onWheel(&wheel_ev);
}
break; break;
} }
@ -2125,12 +2129,10 @@ void FListView::cb_VBarChange (FWidget*, data_ptr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::cb_HBarChange (FWidget*, data_ptr) void FListView::cb_HBarChange (FWidget*, data_ptr)
{ {
FScrollbar::sType scrollType; FScrollbar::sType scrollType = hbar->getScrollType();
int distance = 1 int distance = 1
, pagesize = 4 , pagesize = 4
, xoffset_before = xoffset , xoffset_before = xoffset;
, xoffset_end = max_line_width - getClientWidth();
scrollType = hbar->getScrollType();
switch ( scrollType ) switch ( scrollType )
{ {
@ -2141,24 +2143,14 @@ void FListView::cb_HBarChange (FWidget*, data_ptr)
distance = getClientWidth(); distance = getClientWidth();
// fall through // fall through
case FScrollbar::scrollStepBackward: case FScrollbar::scrollStepBackward:
xoffset -= distance; scrollBy (-distance, 0);
if ( xoffset < 0 )
xoffset = 0;
break; break;
case FScrollbar::scrollPageForward: case FScrollbar::scrollPageForward:
distance = getClientWidth(); distance = getClientWidth();
// fall through // fall through
case FScrollbar::scrollStepForward: case FScrollbar::scrollStepForward:
xoffset += distance; scrollBy (distance, 0);
if ( xoffset > xoffset_end )
xoffset = xoffset_end;
if ( xoffset < 0 )
xoffset = 0;
break; break;
case FScrollbar::scrollJump: case FScrollbar::scrollJump:
@ -2169,25 +2161,11 @@ void FListView::cb_HBarChange (FWidget*, data_ptr)
} }
case FScrollbar::scrollWheelUp: case FScrollbar::scrollWheelUp:
if ( xoffset == 0 ) scrollBy (-pagesize, 0);
break;
xoffset -= pagesize;
if ( xoffset < 0 )
xoffset = 0;
break; break;
case FScrollbar::scrollWheelDown: case FScrollbar::scrollWheelDown:
if ( xoffset == xoffset_end ) scrollBy (pagesize, 0);
break;
xoffset += pagesize;
if ( xoffset > xoffset_end )
xoffset = xoffset_end;
break; break;
} }