@@ -291,6 +291,7 @@ static void Slider_OnMouseUp(LCUI_Widget slider, LCUI_WidgetEvent e, void *arg)
291291{
292292 LCUI_Widget w = e -> data ;
293293 LCUI_ScrollBar scrollbar = Widget_GetData (w , self .prototype );
294+
294295 Widget_UnbindEvent (slider , "mousemove" , Slider_OnMouseMove );
295296 Widget_UnbindEvent (slider , "mouseup" , Slider_OnMouseUp );
296297 Widget_ReleaseMouseCapture (slider );
@@ -302,6 +303,7 @@ static void Slider_OnMouseDown(LCUI_Widget slider, LCUI_WidgetEvent e,
302303{
303304 LCUI_Widget w = e -> data ;
304305 LCUI_ScrollBar scrollbar = Widget_GetData (w , self .prototype );
306+
305307 if (scrollbar -> is_dragged ) {
306308 return ;
307309 }
@@ -323,6 +325,13 @@ static void ScrollBar_OnLink(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
323325 }
324326}
325327
328+ static void ScrollBar_OnBoxDestroy (LCUI_Widget box , LCUI_WidgetEvent e , void * arg )
329+ {
330+ LCUI_Widget w = e -> data ;
331+
332+ ScrollBar_BindBox (e -> data , box == w -> parent ? NULL : w -> parent );
333+ }
334+
326335static void ScrollBar_OnInit (LCUI_Widget w )
327336{
328337 LCUI_Widget slider ;
@@ -353,6 +362,7 @@ static void ScrollBar_UpdateSize(LCUI_Widget w)
353362 float n = 1.0 , size , box_size ;
354363 LCUI_ScrollBar scrollbar = Widget_GetData (w , self .prototype );
355364 LCUI_Widget slider = scrollbar -> slider ;
365+
356366 if (!scrollbar -> box ) {
357367 return ;
358368 }
@@ -526,12 +536,17 @@ static void ScrollBar_OnSetPosition(LCUI_Widget box, LCUI_WidgetEvent e,
526536void ScrollBar_BindBox (LCUI_Widget w , LCUI_Widget box )
527537{
528538 LCUI_ScrollBar scrollbar = Widget_GetData (w , self .prototype );
539+
529540 if (scrollbar -> box ) {
530541 Widget_UnbindEvent (scrollbar -> box , "resize" ,
531542 ScrollBar_OnUpdateSize );
532- Widget_UnbindEvent (box , "setscroll" , ScrollBar_OnSetPosition );
533- Widget_UnbindEvent (box , "mousewheel" , ScrollBox_OnWheel );
534- Widget_UnbindEvent (box , "touch" , ScrollBox_OnTouch );
543+ Widget_UnbindEvent (scrollbar -> box , "setscroll" ,
544+ ScrollBar_OnSetPosition );
545+ Widget_UnbindEvent (scrollbar -> box , "mousewheel" ,
546+ ScrollBox_OnWheel );
547+ Widget_UnbindEvent (scrollbar -> box , "touch" , ScrollBox_OnTouch );
548+ Widget_UnbindEvent (scrollbar -> box , "destroy" ,
549+ ScrollBar_OnBoxDestroy );
535550 }
536551 scrollbar -> box = box ;
537552 if (box ) {
@@ -541,13 +556,16 @@ void ScrollBar_BindBox(LCUI_Widget w, LCUI_Widget box)
541556 NULL );
542557 Widget_BindEvent (box , "mousewheel" , ScrollBox_OnWheel , w , NULL );
543558 Widget_BindEvent (box , "touch" , ScrollBox_OnTouch , w , NULL );
559+ Widget_BindEvent (box , "destroy" , ScrollBar_OnBoxDestroy , w ,
560+ NULL );
544561 }
545562 ScrollBar_UpdateSize (w );
546563}
547564
548565void ScrollBar_BindTarget (LCUI_Widget w , LCUI_Widget target )
549566{
550567 LCUI_ScrollBar scrollbar = Widget_GetData (w , self .prototype );
568+
551569 if (scrollbar -> target ) {
552570 Widget_RemoveClass (scrollbar -> target , "scrollbar-target" );
553571 Widget_UnbindEvent (scrollbar -> target , "resize" ,
@@ -633,6 +651,7 @@ int ScrollBar_SetPosition(LCUI_Widget w, int pos)
633651void ScrollBar_SetDirection (LCUI_Widget w , int direction )
634652{
635653 LCUI_ScrollBar scrollbar = Widget_GetData (w , self .prototype );
654+
636655 if (direction == SBD_HORIZONTAL ) {
637656 Widget_RemoveClass (w , "scrollbar-horizontal" );
638657 } else {
@@ -645,6 +664,7 @@ static void ScrollBar_OnSetAttr(LCUI_Widget w, const char *name,
645664 const char * value )
646665{
647666 LCUI_Widget target ;
667+
648668 if (strcmp (name , "parent" ) == 0 ) {
649669 target = LCUIWidget_GetById (value );
650670 if (target ) {
@@ -661,6 +681,7 @@ static void ScrollBar_OnSetAttr(LCUI_Widget w, const char *name,
661681void LCUIWidget_AddTScrollBar (void )
662682{
663683 int setscroll_event_id ;
684+
664685 self .prototype = LCUIWidget_NewPrototype ("scrollbar" , NULL );
665686 self .prototype -> init = ScrollBar_OnInit ;
666687 self .prototype -> setattr = ScrollBar_OnSetAttr ;
0 commit comments