scrollbar.c 16.0 KB
Newer Older
B
bernard.xiong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
#include <rtgui/dc.h>
#include <rtgui/widgets/scrollbar.h>

static void _rtgui_scrollbar_constructor(rtgui_scrollbar_t *bar)
{
	struct rtgui_rect rect = {0, 0, RTGUI_DEFAULT_SB_WIDTH, RTGUI_DEFAULT_SB_HEIGHT};

	/* set event handler */
	rtgui_widget_set_event_handler(RTGUI_WIDGET(bar), rtgui_scrollbar_event_handler);

	rtgui_scrollbar_set_range(bar, 0, 100);
	rtgui_scrollbar_set_page_step(bar, 20);
	rtgui_scrollbar_set_line_step(bar, 10);

	bar->thumb_position = 0;
	bar->thumb_size = 16;
	bar->on_scroll = RT_NULL;

	bar->orient = RTGUI_HORIZONTAL;
	bar->bar_width = RTGUI_DEFAULT_SB_HEIGHT;
	rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);

	/* set gc */
	RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(bar)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
}

rt_inline rt_uint32_t _rtgui_scrollbar_get_length(rtgui_scrollbar_t *bar)
{
	struct rtgui_rect rect;

	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);

	if (bar->orient & RTGUI_VERTICAL)
		return rect.y2 - 2 * (rect.x2 - rect.x1);

	return rect.x2 - 2 * (rect.y2 - rect.y1);
}

rt_inline rt_uint32_t _rtgui_scrollbar_get_thumb_position(rtgui_scrollbar_t* bar)
{
	rt_uint32_t thumb_position;

	/* calculate thumb position */
	thumb_position = (rtgui_scrollbar_get_value(bar) - bar->min_position) * _rtgui_scrollbar_get_length(bar) / 
		(bar->max_position - bar->min_position);

	return thumb_position;
}

rt_inline void _rtgui_scrollbar_get_thumb_rect(rtgui_scrollbar_t *bar, rtgui_rect_t *rect)
{
	struct rtgui_rect scrollbar_rect;

	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &scrollbar_rect);
	if (bar->orient & RTGUI_VERTICAL)
	{
		rt_uint32_t btn_width = scrollbar_rect.x2 - scrollbar_rect.x1;

		/* vertical scroll bar */
		rect->x1 = scrollbar_rect.x1;
		rect->x2 = scrollbar_rect.x2;
		rect->y1 = scrollbar_rect.y1 + btn_width + _rtgui_scrollbar_get_thumb_position(bar);
		rect->y2 = rect->y1 + btn_width;
	}
	else
	{
		rt_uint32_t btn_height = scrollbar_rect.y2 - scrollbar_rect.y1;

		/* horizontal scroll bar */
		rect->x1 = scrollbar_rect.x1 + btn_height + _rtgui_scrollbar_get_thumb_position(bar);
		rect->x2 = rect->x1 + btn_height;

		rect->y1 = scrollbar_rect.y1;
		rect->y2 = scrollbar_rect.y2;
	}
}

rtgui_type_t *rtgui_scrollbar_type_get(void)
{
	static rtgui_type_t *scrollbar_type = RT_NULL;

	if (!scrollbar_type)
	{
		scrollbar_type = rtgui_type_create("scrollbar", RTGUI_WIDGET_TYPE,
			sizeof(rtgui_scrollbar_t), RTGUI_CONSTRUCTOR(_rtgui_scrollbar_constructor), RT_NULL);
	}

	return scrollbar_type;
}

static void _rtgui_scrollbar_ondraw(struct rtgui_scrollbar* bar);
static void _rtgui_scrollbar_on_mouseclick(struct rtgui_widget * widget, struct rtgui_event * event);

rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_widget * widget,
	struct rtgui_event * event)
{
	struct rtgui_scrollbar* bar = (struct rtgui_scrollbar*)widget;

	switch (event->type)
	{
    	case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
    		if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
    		else
#endif
    		{
    			_rtgui_scrollbar_ondraw(bar);
    		}

    		break;

        case RTGUI_EVENT_MOUSE_BUTTON:
			if (RTGUI_WIDGET_IS_ENABLE(widget))
			{
#ifndef RTGUI_USING_SMALL_SIZE
				if (widget->on_mouseclick != RT_NULL)
				{
					widget->on_mouseclick(widget, event);
				}
				else
#endif
				{
					_rtgui_scrollbar_on_mouseclick(widget, event);
				}
			}

            break;

        default:
            break;
	}

	return RT_FALSE;
}

static void _rtgui_scrollbar_on_mouseclick(struct rtgui_widget * widget, struct rtgui_event * event)
{
	rtgui_rect_t btn_rect, bar_rect;
	rt_uint32_t thumb_size, thumb_position;
    struct rtgui_scrollbar* bar = (struct rtgui_scrollbar*)widget;
    struct rtgui_event_mouse* mouse = (struct rtgui_event_mouse*)event;

	/* get the thumb size and position */
	thumb_size = bar->thumb_size * (bar->max_position - bar->min_position) / _rtgui_scrollbar_get_length(bar);
	thumb_position = _rtgui_scrollbar_get_thumb_position(bar);

    if (bar->orient == RTGUI_VERTICAL)
    {
		/* get up arrow button rect */
		btn_rect.x1 = widget->extent.x1;
		btn_rect.x2 = widget->extent.x2;
		btn_rect.y1 = widget->extent.y1;
		btn_rect.y2 = widget->extent.y1 + (widget->extent.x2 - widget->extent.x1);
        if (rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
        {
            if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
				(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
            {
                bar->status |= SBS_UPARROW;

				/* line step */
				bar->thumb_position -= bar->line_step;
				if (bar->thumb_position < bar->min_position) bar->thumb_position = bar->min_position;
            }
            else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
                bar->status = 0;
			}
			goto __exit;
        }

		/* get bar rect */
		bar_rect.x1 = widget->extent.x1;
		bar_rect.x2 = widget->extent.x2;
		bar_rect.y1 = widget->extent.y1 + (widget->extent.x2 - widget->extent.x1);
		bar_rect.y2 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
        if (rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
        {
			if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
				(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
            {
				/* page step */
				if (mouse->y < bar_rect.y1 + thumb_position)
				{
					bar->thumb_position -= bar->page_step;
					if (bar->thumb_position < bar->min_position)					
						bar->thumb_position = bar->min_position;
				}
				else if (mouse->y > thumb_position + bar->thumb_size)
				{
					bar->thumb_position += bar->page_step;
					if (bar->thumb_position > bar->max_position - thumb_size)
						bar->thumb_position = bar->max_position - thumb_size;
				}
            }
			goto __exit;
        }

		/* get down arrow button rect */
        btn_rect.y1 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
        btn_rect.y2 = widget->extent.y2;
        bar_rect.y1 = widget->extent.y1 + ((widget->extent.y2 - widget->extent.y1)/2);
        bar_rect.y2 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
        if (rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
        {
            if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
				(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
            {
                bar->status |= SBS_DOWNARROW;

				/* line step */
				bar->thumb_position += bar->line_step;
				if (bar->thumb_position > bar->max_position - thumb_size)
					bar->thumb_position = bar->max_position - thumb_size;
            }
            else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
                bar->status = 0;
        }
    }
    else
    {
		/* get left arrow button rect */
		btn_rect.x1 = widget->extent.x1;
		btn_rect.x2 = widget->extent.x1 + (widget->extent.y2 - widget->extent.y1);
		btn_rect.y1 = widget->extent.y1;
		btn_rect.y2 = widget->extent.y2;
        if (rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
        {
            if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
				(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
            {
                bar->status |= SBS_LEFTARROW;

				/* line step */
				bar->thumb_position -= bar->line_step;
				if (bar->thumb_position < bar->min_position) bar->thumb_position = bar->min_position;
            }
             else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
                bar->status = 0;
			goto __exit;
       }

		/* get bar rect */
		bar_rect.x1 = widget->extent.x1 + (widget->extent.y2 - widget->extent.y1);
		bar_rect.x2 = widget->extent.x2 - (widget->extent.x2 - widget->extent.x1);
		bar_rect.y1 = widget->extent.y1;
		bar_rect.y2 = widget->extent.y2;
        if (rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
        {
            if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
				(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
            {
				/* page step */
				if (mouse->x <  bar_rect.x1 + thumb_position)
				{
					bar->thumb_position -= bar->page_step;
					if (bar->thumb_position < bar->min_position)					
						bar->thumb_position = bar->min_position;
				}
				else if (mouse->x > thumb_position + bar->thumb_size)
				{
					bar->thumb_position += bar->page_step;
					if (bar->thumb_position > bar->max_position - thumb_size)
						bar->thumb_position = bar->max_position - thumb_size;
				}
            }
			goto __exit;
        }

		/* get right arrow button rect */
        btn_rect.x1 = widget->extent.x2 - (widget->extent.y2 - widget->extent.y1);
        btn_rect.x2 = widget->extent.x2;
        bar_rect.x1 = widget->extent.x1 + ((widget->extent.x2 - widget->extent.x1)/2);
        bar_rect.x2 = widget->extent.x2 - (widget->extent.y2 - widget->extent.y1);
        if (rtgui_rect_contains_point(&btn_rect,
                            mouse->x, mouse->y) == RT_EOK)
        {
            if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
				(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
            {
                bar->status |= SBS_RIGHTARROW;

				/* line step */
				bar->thumb_position += bar->line_step;
				if (bar->thumb_position > bar->max_position - bar->line_step)
					bar->thumb_position = bar->max_position - bar->line_step;
            }
             else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
                bar->status = 0;
        }
    }

__exit:
    _rtgui_scrollbar_ondraw(bar);
	if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
		(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
	{
		if (bar->on_scroll != RT_NULL) bar->on_scroll(widget, RT_NULL);
	}
}

static void _rtgui_scrollbar_ondraw(struct rtgui_scrollbar* bar)
{
	/* draw scroll bar */
	struct rtgui_dc* dc;
	struct rtgui_rect rect;
	int vx[4], vy[4];

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(&(bar->parent));
	if (dc == RT_NULL) return;

	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);

	/* draw background */
	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(236, 236, 229);
	rtgui_dc_fill_rect(dc, &rect);

    if (bar->orient == RTGUI_VERTICAL)
    {
        rtgui_rect_t btn_rect, thum_rect;

		btn_rect = rect;
		btn_rect.y2 = btn_rect.y1 + rect.x2 - rect.x1;
		
		/* draw up button */
		if (bar->status & SBS_UPARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);

		/* draw arrow */
		if (!RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
			RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(201, 201, 194);
		vx[0] = 0; vy[0] = 0;
		vx[1] = rtgui_rect_width(rect); vy[1] = 0;
		vx[2] = vx[1] / 2; vy[2] = 8;
		vx[3] = 0; vy[3] = 0;
		rtgui_dc_fill_polygon(dc, vx, vy, 4);
		// rtgui_dc_draw_arrow(dc, &btn_rect, RTGUI_ARRAW_UP);

		/* draw thumb */
		if (RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
		{
			_rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
			rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
		}

		/* draw down button */
        btn_rect.y1 = rect.y2 - (rect.x2 - rect.x1);
        btn_rect.y2 = rect.y2;

		if (bar->status & SBS_DOWNARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);

		if (!RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
			RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(201, 201, 194);

		vx[0] = 0; vy[0] = rtgui_rect_height(rect);
		vx[1] = rtgui_rect_width(rect); vy[1] = rtgui_rect_height(rect);
		vx[2] = vx[1] / 2; vy[2] = rtgui_rect_height(rect) - 8;
		vx[0] = 0; vy[0] = rtgui_rect_height(rect);
		rtgui_dc_fill_polygon(dc, vx, vy, 4);
		// rtgui_dc_draw_arrow(dc, &btn_rect, RTGUI_ARRAW_DOWN);
    }
    else
    {
        rtgui_rect_t btn_rect, thum_rect;

        btn_rect.x1 = rect.x1;
        btn_rect.x2 = rect.y2;
        btn_rect.y1 = rect.y1;
        btn_rect.y2 = rect.y2;

		/* draw left button */
		if (bar->status & SBS_LEFTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);

		if (!RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
			RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(201, 201, 194);

		vx[0] = 0; vy[0] = 0;
		vx[1] = 0; vy[1] = rtgui_rect_height(rect);
		vx[2] = 8; vy[2] = rtgui_rect_height(rect)/2;
		vx[3] = 0; vy[3] = 0;
		rtgui_dc_fill_polygon(dc, vx, vy, 4);
		// rtgui_dc_draw_arrow(dc, &btn_rect, RTGUI_ARRAW_LEFT);

		/* draw thumb */
		if (RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
		{
			_rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
			rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
		}

        btn_rect.x1 = rect.x2 - rect.y2;
        btn_rect.x2 = rect.x2;

		/* draw right button */
		if (bar->status & SBS_RIGHTARROW) rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
		else rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);

		if (!RTGUI_WIDGET_IS_ENABLE(RTGUI_WIDGET(bar)))
			RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(bar)) = RTGUI_RGB(201, 201, 194);
		vx[0] = rtgui_rect_width(rect); vy[0] = 0;
		vx[1] = rtgui_rect_width(rect) - 8; vy[1] = rtgui_rect_height(rect)/2;
		vx[2] = rtgui_rect_width(rect); vy[2] = rtgui_rect_height(rect);
		vx[0] = rtgui_rect_width(rect); vy[0] = 0;
		rtgui_dc_fill_polygon(dc, vx, vy, 4);
		// rtgui_dc_draw_arrow(dc, &btn_rect, RTGUI_ARRAW_RIGHT);
    }

	/* end drawing */
	rtgui_dc_end_drawing(dc);
	return;
}

struct rtgui_scrollbar* rtgui_scrollbar_create(int orient, rtgui_rect_t* r)
{
    struct rtgui_scrollbar* bar;

    bar = (struct rtgui_scrollbar*) rtgui_widget_create (RTGUI_SCROLLBAR_TYPE);
    if (bar != RT_NULL)
    {
		if (r != RT_NULL)
			rtgui_widget_set_rect(RTGUI_WIDGET(bar), r);

		bar->orient = orient;
    }

    return bar;
}

void rtgui_scrollbar_destroy(struct rtgui_scrollbar* bar)
{
	rtgui_widget_destroy(RTGUI_WIDGET(bar));
}

void rtgui_scrollbar_set_orientation(rtgui_scrollbar_t* bar, int orientation)
{
	RT_ASSERT(bar != RT_NULL);

	bar->orient = orientation;
	bar->bar_width = RTGUI_DEFAULT_SB_HEIGHT;
#ifndef RTGUI_USING_SMALL_SIZE
	if (bar->orient == RTGUI_HORIZONTAL)
	{
		/* horizontal */
		rtgui_widget_set_miniwidth(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_WIDTH);
		rtgui_widget_set_miniheight(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_HEIGHT);
	}
	else 
	{
		/* vertical */
		rtgui_widget_set_miniwidth(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_HEIGHT);
		rtgui_widget_set_miniheight(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_WIDTH);
	}
#endif
}

void rtgui_scrollbar_set_range(struct rtgui_scrollbar* bar, int min, int max)
{
	RT_ASSERT(bar != RT_NULL);

	if (min >= max )
	{
		RTGUI_WIDGET_DISABLE(RTGUI_WIDGET(bar));
		return;
	}

	bar->min_position = (rt_int16_t)min;
	bar->max_position = (rt_int16_t)max;
}

void rtgui_scrollbar_set_page_step(struct rtgui_scrollbar* bar, int step)
{
	RT_ASSERT(bar != RT_NULL);

	bar->page_step = step;
		
	/* disable or enable scrollbar */
	if (bar->page_step > (bar->max_position - bar->min_position))
	{
		/* disable bar */
		RTGUI_WIDGET_DISABLE(RTGUI_WIDGET(bar));
	}
	else
	{
		/* enable bar */
		RTGUI_WIDGET_ENABLE(RTGUI_WIDGET(bar));
	}
}

void rtgui_scrollbar_set_line_step(struct rtgui_scrollbar* bar, int step)
{
	RT_ASSERT(bar != RT_NULL);

	bar->line_step = step;
}

rt_int16_t rtgui_scrollbar_get_value(struct rtgui_scrollbar* bar)
{
	RT_ASSERT(bar != RT_NULL);

	return bar->thumb_position;
}

void rtgui_scrollbar_set_value(struct rtgui_scrollbar* bar, rt_int16_t position)
{
	RT_ASSERT(bar != RT_NULL);

	bar->thumb_position = position;
	rtgui_widget_update(RTGUI_WIDGET(bar));
}

void rtgui_scrollbar_set_onscroll(struct rtgui_scrollbar* bar,
								  rtgui_event_handler_ptr handler)
{
	if (bar == RT_NULL || handler == RT_NULL) return;

	bar->on_scroll = handler;
}