@@ -179,8 +179,10 @@ static void StartInertialScrolling(LCUI_Widget w)
179179{
180180 int distance ;
181181 int64_t time_delta ;
182+
182183 LCUI_ScrollBar scrollbar ;
183184 InertialScrolling effect ;
185+
184186 scrollbar = Widget_GetData (w , self .prototype );
185187 effect = & scrollbar -> effect ;
186188 effect -> end_pos = scrollbar -> pos ;
@@ -386,12 +388,13 @@ static void ScrollBar_UpdateSize(LCUI_Widget w)
386388 }
387389}
388390
389- static void ScrollLayer_OnWheel (LCUI_Widget target , LCUI_WidgetEvent e ,
390- void * arg )
391+ static void ScrollBox_OnWheel (LCUI_Widget box , LCUI_WidgetEvent e , void * arg )
391392{
392393 int pos , new_pos ;
394+
393395 LCUI_Widget w = e -> data ;
394396 LCUI_ScrollBar scrollbar = Widget_GetData (w , self .prototype );
397+
395398 pos = ScrollBar_GetPosition (w );
396399 if (e -> wheel .delta > 0 ) {
397400 new_pos = pos - scrollbar -> scroll_step ;
@@ -405,15 +408,16 @@ static void ScrollLayer_OnWheel(LCUI_Widget target, LCUI_WidgetEvent e,
405408 }
406409}
407410
408- /** 滚动层的触屏事件响应 */
409- static void ScrollLayer_OnTouch (LCUI_Widget target , LCUI_WidgetEvent e ,
410- void * arg )
411+ /** 容器的触屏事件响应 */
412+ static void ScrollBox_OnTouch (LCUI_Widget box , LCUI_WidgetEvent e , void * arg )
411413{
412414 uint_t time_delta ;
413415 int i , pos , distance ;
414- LCUI_TouchPoint point ;
416+
415417 LCUI_Widget w = e -> data ;
416418 LCUI_ScrollBar scrollbar ;
419+ LCUI_TouchPoint point ;
420+
417421 if (e -> touch .n_points < 1 ) {
418422 return ;
419423 }
@@ -451,14 +455,14 @@ static void ScrollLayer_OnTouch(LCUI_Widget target, LCUI_WidgetEvent e,
451455 scrollbar -> is_draggable = TRUE;
452456 break ;
453457 case LCUI_WEVENT_TOUCHUP :
454- Widget_ReleaseTouchCapture (target , -1 );
458+ Widget_ReleaseTouchCapture (box , -1 );
455459 time_delta = (uint_t )LCUI_GetTimeDelta (scrollbar -> timestamp );
456460 if (scrollbar -> is_dragged && time_delta < 50 ) {
457461 StartInertialScrolling (w );
458462 }
459463 scrollbar -> touch_point_id = -1 ;
460464 scrollbar -> is_dragged = FALSE;
461- Widget_BlockEvent (target , FALSE);
465+ Widget_BlockEvent (box , FALSE);
462466 break ;
463467 case LCUI_WEVENT_TOUCHMOVE :
464468 if (!scrollbar -> is_draggable ) {
@@ -495,11 +499,11 @@ static void ScrollLayer_OnTouch(LCUI_Widget target, LCUI_WidgetEvent e,
495499 e -> cancel_bubble = FALSE;
496500 break ;
497501 }
498- /* start drag action and block all events of target */
502+ /* start drag action and block all events of box */
499503 scrollbar -> is_dragged = TRUE;
500504 LCUIWidget_ClearEventTarget (NULL );
501- Widget_BlockEvent (target , TRUE);
502- Widget_SetTouchCapture (target , point -> id );
505+ Widget_BlockEvent (box , TRUE);
506+ Widget_SetTouchCapture (box , point -> id );
503507 default :
504508 break ;
505509 }
@@ -525,13 +529,18 @@ void ScrollBar_BindBox(LCUI_Widget w, LCUI_Widget box)
525529 if (scrollbar -> box ) {
526530 Widget_UnbindEvent (scrollbar -> box , "resize" ,
527531 ScrollBar_OnUpdateSize );
532+ Widget_UnbindEvent (box , "setscroll" , ScrollBar_OnSetPosition );
533+ Widget_UnbindEvent (box , "mousewheel" , ScrollBox_OnWheel );
534+ Widget_UnbindEvent (box , "touch" , ScrollBox_OnTouch );
528535 }
529536 scrollbar -> box = box ;
530537 if (box ) {
531538 Widget_BindEvent (box , "resize" , ScrollBar_OnUpdateSize , w ,
532539 NULL );
533540 Widget_BindEvent (box , "setscroll" , ScrollBar_OnSetPosition , w ,
534541 NULL );
542+ Widget_BindEvent (box , "mousewheel" , ScrollBox_OnWheel , w , NULL );
543+ Widget_BindEvent (box , "touch" , ScrollBox_OnTouch , w , NULL );
535544 }
536545 ScrollBar_UpdateSize (w );
537546}
@@ -547,8 +556,6 @@ void ScrollBar_BindTarget(LCUI_Widget w, LCUI_Widget target)
547556 scrollbar -> target = target ;
548557 Widget_AddClass (target , "scrollbar-target" );
549558 Widget_BindEvent (target , "resize" , ScrollBar_OnUpdateSize , w , NULL );
550- Widget_BindEvent (target , "mousewheel" , ScrollLayer_OnWheel , w , NULL );
551- Widget_BindEvent (target , "touch" , ScrollLayer_OnTouch , w , NULL );
552559 ScrollBar_UpdateSize (w );
553560}
554561
0 commit comments