widget.c 15.8 KB
Newer Older
B
bernard.xiong 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * File      : widget.c
 * This file is part of RTGUI in RT-Thread RTOS
 * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.org/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2009-10-04     Bernard      first version
13
 * 2010-06-26     Bernard      add user_data to widget structure
B
bernard.xiong 已提交
14
 */
15

B
bernard.xiong 已提交
16
#include <rtgui/dc_client.h>
17
#include <rtgui/rtgui_app.h>
B
bernard.xiong 已提交
18 19
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/window.h>
20 21
#include <rtgui/widgets/container.h>
#include <rtgui/widgets/notebook.h>
B
bernard.xiong 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

static void _rtgui_widget_constructor(rtgui_widget_t *widget)
{
   if (!widget) return;

	/* set default flag */
	widget->flag = RTGUI_WIDGET_FLAG_DEFAULT;

	/* init list */
	rtgui_list_init(&(widget->sibling));

	/* init gc */
	widget->gc.foreground = default_foreground;
	widget->gc.background = default_background;
	widget->gc.font = rtgui_font_default();
37
	widget->gc.textstyle = RTGUI_TEXTSTYLE_NORMAL;
B
bernard.xiong 已提交
38 39 40 41
	widget->gc.textalign = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
	widget->align = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;

	/* set parent and toplevel root */
42 43
	widget->parent        = RT_NULL;
	widget->toplevel      = RT_NULL;
B
bernard.xiong 已提交
44 45

	/* some common event handler */
46 47 48 49
	widget->on_focus_in   = RT_NULL;
	widget->on_focus_out  = RT_NULL;
	widget->on_show       = RT_NULL;
	widget->on_hide       = RT_NULL;
50 51

#ifndef RTGUI_USING_SMALL_SIZE
52 53 54 55 56
	widget->on_draw       = RT_NULL;
	widget->on_mouseclick = RT_NULL;
	widget->on_key        = RT_NULL;
	widget->on_size       = RT_NULL;
	widget->on_command    = RT_NULL;
57
#endif
B
bernard.xiong 已提交
58 59

	/* set default event handler */
60
	rtgui_object_set_event_handler(RTGUI_OBJECT(widget), rtgui_widget_event_handler);
B
bernard.xiong 已提交
61

62 63 64
	/* init user data private to 0 */
	widget->user_data = 0;

65
	/* init clip information */
B
bernard.xiong 已提交
66
	rtgui_region_init(&(widget->clip));
67 68

	/* init hardware dc */
B
bernard.xiong 已提交
69
	rtgui_dc_client_init(widget);
B
bernard.xiong 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
}

/* Destroys the widget */
static void _rtgui_widget_destructor(rtgui_widget_t *widget)
{
	if (widget == RT_NULL) return;

	if (widget->parent != RT_NULL)
	{
		/* remove widget from parent's children list */
		rtgui_list_remove(&(RTGUI_CONTAINER(widget->parent)->children), &(widget->sibling));

		widget->parent = RT_NULL;
	}

	/* fini clip region */
	rtgui_region_fini(&(widget->clip));
}

89
DEFINE_CLASS_TYPE(widget, "widget",
90 91 92 93
	RTGUI_OBJECT_TYPE,
	_rtgui_widget_constructor,
	_rtgui_widget_destructor,
	sizeof(struct rtgui_widget));
B
bernard.xiong 已提交
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

rtgui_widget_t *rtgui_widget_create(rtgui_type_t *widget_type)
{
	struct rtgui_widget* widget;

	widget = RTGUI_WIDGET(rtgui_object_create(widget_type));

	return widget;
}

void rtgui_widget_destroy(rtgui_widget_t* widget)
{
	rtgui_object_destroy(RTGUI_OBJECT(widget));
}

B
bernard.xiong@gmail.com 已提交
109
void rtgui_widget_set_rect(rtgui_widget_t* widget, const rtgui_rect_t* rect)
B
bernard.xiong 已提交
110 111 112
{
	if (widget == RT_NULL || rect == RT_NULL) return;

B
bernard.xiong 已提交
113 114 115 116
	widget->extent = *rect;

	/* reset mini width and height */
	widget->mini_width  = rtgui_rect_width(widget->extent);
B
bernard.xiong 已提交
117 118 119 120 121 122 123 124 125 126
	widget->mini_height = rtgui_rect_height(widget->extent);

	/* it's not empty, fini it */
	if (rtgui_region_not_empty(&(widget->clip)))
	{
		rtgui_region_fini(&(widget->clip));
	}

	/* reset clip info */
	rtgui_region_init_with_extents(&(widget->clip), rect);
127 128 129
	if ((widget->parent != RT_NULL) && (widget->toplevel != RT_NULL))
	{
		/* update widget clip */
130
		rtgui_widget_update_clip(widget->parent);
131
	}
B
bernard.xiong 已提交
132 133
}

134 135 136 137 138 139 140 141 142 143
void rtgui_widget_set_rectangle(rtgui_widget_t* widget, int x, int y, int width, int height)
{
	rtgui_rect_t rect;

	rect.x1 = x; rect.y1 = y;
	rect.x2 = x + width; rect.y2 = y + height;

	rtgui_widget_set_rect(widget, &rect);
}

144 145 146 147 148 149 150 151 152 153 154 155 156
void rtgui_widget_set_parent(rtgui_widget_t* widget, rtgui_widget_t* parent)
{
	/* set parent and toplevel widget */
	widget->parent = parent;

	/* update children toplevel */
	if (parent->toplevel != RT_NULL &&
		RTGUI_IS_TOPLEVEL(parent->toplevel))
	{
		widget->toplevel = rtgui_widget_get_toplevel(parent);
	}
}

157 158 159 160 161 162 163 164
void rtgui_widget_get_extent(rtgui_widget_t* widget, rtgui_rect_t *rect)
{
	RT_ASSERT(widget != RT_NULL);
	RT_ASSERT(rect != RT_NULL);

	*rect = widget->extent;
}

B
bernard.xiong 已提交
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
void rtgui_widget_set_miniwidth(rtgui_widget_t* widget, int width)
{
	RT_ASSERT(widget != RT_NULL);

	widget->mini_width = width;
}

void rtgui_widget_set_miniheight(rtgui_widget_t* widget, int height)
{
	RT_ASSERT(widget != RT_NULL);

	widget->mini_height = height;
}

/*
 * This function moves widget and its children to a logic point
 */
void rtgui_widget_move_to_logic(rtgui_widget_t* widget, int dx, int dy)
{
	struct rtgui_list_node* node;
	rtgui_widget_t* child;

	if (widget == RT_NULL) return;

	rtgui_rect_moveto(&(widget->extent), dx, dy);

	/* move each child */
	if (RTGUI_IS_CONTAINER(widget))
	{
		rtgui_list_foreach(node, &(RTGUI_CONTAINER(widget)->children))
		{
			child = rtgui_list_entry(node, rtgui_widget_t, sibling);

			rtgui_widget_move_to_logic(child, dx, dy);
		}
	}
}

void rtgui_widget_get_rect(rtgui_widget_t* widget, rtgui_rect_t *rect)
{
	RT_ASSERT(widget != RT_NULL);

	if (rect != RT_NULL)
	{
		rect->x1 = rect->y1 = 0;
		rect->x2 = widget->extent.x2 - widget->extent.x1;
		rect->y2 = widget->extent.y2 - widget->extent.y1;
	}
}

215
void rtgui_widget_set_onfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
B
bernard.xiong 已提交
216 217 218
{
	RT_ASSERT(widget != RT_NULL);

219
	widget->on_focus_in = handler;
B
bernard.xiong 已提交
220 221
}

222
void rtgui_widget_set_onunfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
B
bernard.xiong 已提交
223 224 225
{
	RT_ASSERT(widget != RT_NULL);

226
	widget->on_focus_out = handler;
B
bernard.xiong 已提交
227 228
}

229 230 231 232 233 234 235 236 237 238 239 240 241 242
void rtgui_widget_set_onshow(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{
	RT_ASSERT(widget != RT_NULL);

	widget->on_show = handler;
}

void rtgui_widget_set_onhide(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{
	RT_ASSERT(widget != RT_NULL);

	widget->on_hide = handler;
}

243 244
#ifndef RTGUI_USING_SMALL_SIZE
void rtgui_widget_set_ondraw(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
B
bernard.xiong 已提交
245 246 247
{
	RT_ASSERT(widget != RT_NULL);

248
	widget->on_draw = handler;
B
bernard.xiong 已提交
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
}

void rtgui_widget_set_onmouseclick(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{
	RT_ASSERT(widget != RT_NULL);

	widget->on_mouseclick = handler;
}

void rtgui_widget_set_onkey(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{
	RT_ASSERT(widget != RT_NULL);

	widget->on_key = handler;
}

void rtgui_widget_set_onsize(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{
	RT_ASSERT(widget != RT_NULL);

	widget->on_size = handler;
}

void rtgui_widget_set_oncommand(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{
	RT_ASSERT(widget != RT_NULL);

	widget->on_command = handler;
}
278
#endif
B
bernard.xiong 已提交
279 280

/**
B
bernard.xiong 已提交
281
 * @brief Focuses the widget. The focused widget is the widget which can receive the keyboard events
B
bernard.xiong 已提交
282 283 284 285 286
 * @param widget a widget
 * @note The widget has to be attached to a toplevel widget, otherwise it will have no effect
 */
void rtgui_widget_focus(rtgui_widget_t *widget)
{
287
	struct rtgui_widget *old_focus;
B
bernard.xiong 已提交
288 289

	RT_ASSERT(widget != RT_NULL);
B
bernard.xiong 已提交
290

B
bernard.xiong 已提交
291
	if (!RTGUI_WIDGET_IS_FOCUSABLE(widget) || !RTGUI_WIDGET_IS_ENABLE(widget))
B
bernard.xiong 已提交
292 293
		return;

294 295 296
	old_focus = RTGUI_WIN(widget->toplevel)->focused_widget;
	if (old_focus == widget)
		return; /* it's the same focused widget */
B
bernard.xiong 已提交
297

B
bernard.xiong 已提交
298
	/* unfocused the old widget */
299 300
	if (old_focus != RT_NULL)
		rtgui_widget_unfocus(old_focus);
B
bernard.xiong 已提交
301

302 303 304
	/* set widget as focused */
	widget->flag |= RTGUI_WIDGET_FLAG_FOCUS;
	RTGUI_WIN(widget->toplevel)->focused_widget = widget;
B
bernard.xiong 已提交
305 306

	/* invoke on focus in call back */
307
	if (widget->on_focus_in != RT_NULL)
308
		widget->on_focus_in(RTGUI_OBJECT(widget), RT_NULL);
B
bernard.xiong 已提交
309 310 311 312 313 314 315 316
}

/**
 * @brief Unfocused the widget
 * @param widget a widget
 */
void rtgui_widget_unfocus(rtgui_widget_t *widget)
{
317

B
bernard.xiong 已提交
318
	RT_ASSERT(widget != RT_NULL);
B
bernard.xiong 已提交
319

B
bernard.xiong 已提交
320
	if (!widget->toplevel || !RTGUI_WIDGET_IS_FOCUSED(widget))
B
bernard.xiong 已提交
321 322
		return;

323 324
	widget->flag &= ~RTGUI_WIDGET_FLAG_FOCUS;

325
	if (widget->on_focus_out != RT_NULL)
326 327 328
		widget->on_focus_out(RTGUI_OBJECT(widget), RT_NULL);

	RTGUI_WIN(widget->toplevel)->focused_widget = RT_NULL;
329 330 331

	/* refresh widget */
	rtgui_widget_update(widget);
B
bernard.xiong 已提交
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
}

void rtgui_widget_point_to_device(rtgui_widget_t* widget, rtgui_point_t* point)
{
	RT_ASSERT(widget != RT_NULL);

	if (point != RT_NULL)
	{
		point->x += widget->extent.x1;
		point->y += widget->extent.y1;
	}
}

void rtgui_widget_rect_to_device(rtgui_widget_t* widget, rtgui_rect_t* rect)
{
	RT_ASSERT(widget != RT_NULL);

	if (rect != RT_NULL)
	{
		rect->x1 += widget->extent.x1;
		rect->x2 += widget->extent.x1;

		rect->y1 += widget->extent.y1;
		rect->y2 += widget->extent.y1;
	}
}

void rtgui_widget_point_to_logic(rtgui_widget_t* widget, rtgui_point_t* point)
{
	RT_ASSERT(widget != RT_NULL);

	if (point != RT_NULL)
	{
		point->x -= widget->extent.x1;
		point->y -= widget->extent.y1;
	}
}

void rtgui_widget_rect_to_logic(rtgui_widget_t* widget, rtgui_rect_t* rect)
{
	RT_ASSERT(widget != RT_NULL);

	if (rect != RT_NULL)
	{
		rect->x1 -= widget->extent.x1;
		rect->x2 -= widget->extent.x1;

		rect->y1 -= widget->extent.y1;
		rect->y2 -= widget->extent.y1;
	}
}

384
struct rtgui_win* rtgui_widget_get_toplevel(rtgui_widget_t* widget)
B
bernard.xiong 已提交
385 386 387 388 389
{
	rtgui_widget_t* r;

	RT_ASSERT(widget != RT_NULL);

390 391
	if (widget->toplevel)
		return widget->toplevel;
B
bernard.xiong 已提交
392

393
	rt_kprintf("widget->toplevel not properly set\n");
B
bernard.xiong 已提交
394 395
	r = widget;
	/* get the toplevel widget */
396 397
	while (r->parent != RT_NULL)
		r = r->parent;
B
bernard.xiong 已提交
398 399

	/* set toplevel */
400
	widget->toplevel = RTGUI_WIN(r);
B
bernard.xiong 已提交
401

402
	return RTGUI_WIN(r);
B
bernard.xiong 已提交
403 404
}

405
rt_bool_t rtgui_widget_event_handler(struct rtgui_object* object, rtgui_event_t* event)
B
bernard.xiong 已提交
406
{
407 408 409
	RT_ASSERT(object != RT_NULL);
	RT_ASSERT(event != RT_NULL);

B
bernard.xiong 已提交
410 411
	switch (event->type)
	{
412 413 414 415 416
	case RTGUI_EVENT_SHOW:
		return rtgui_widget_onshow(object, event);
	case RTGUI_EVENT_HIDE:
		return rtgui_widget_onhide(object, event);
#ifndef RTGUI_USING_SMALL_SIZE
B
bernard.xiong 已提交
417
	case RTGUI_EVENT_PAINT:
418 419
		if (widget->on_draw != RT_NULL)
			return widget->on_draw(RTGUI_OBJECT(widget), event);
B
bernard.xiong 已提交
420 421 422
		break;

	case RTGUI_EVENT_KBD:
423 424
		if (widget->on_key != RT_NULL)
			return widget->on_key(RTGUI_OBJECT(widget), event);
B
bernard.xiong 已提交
425 426 427
		break;

	case RTGUI_EVENT_MOUSE_BUTTON:
428 429
		if (widget->on_mouseclick != RT_NULL)
			return widget->on_mouseclick(RTGUI_OBJECT(widget), event);
B
bernard.xiong 已提交
430 431 432
		break;

	case RTGUI_EVENT_COMMAND:
433 434
		if (widget->on_command != RT_NULL)
			return widget->on_command(RTGUI_OBJECT(widget), event);
B
bernard.xiong 已提交
435 436 437
		break;

	case RTGUI_EVENT_RESIZE:
438 439
		if (widget->on_size != RT_NULL)
			return widget->on_size(RTGUI_OBJECT(widget), event);
B
bernard.xiong 已提交
440
		break;
441
#endif
442
	}
B
bernard.xiong 已提交
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458

	return RT_FALSE;
}

/*
 * This function updates the clip info of widget
 */
void rtgui_widget_update_clip(rtgui_widget_t* widget)
{
	struct rtgui_list_node* node;
	rtgui_widget_t *parent;

	/* no widget or widget is hide, no update clip */
	if (widget == RT_NULL || RTGUI_WIDGET_IS_HIDE(widget)) return;

	parent = widget->parent;
459
	/* if there is no parent, there is no clip to update. */
460 461 462 463
	if (parent == RT_NULL)
	{
		return;
	}
B
bernard.xiong 已提交
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

	/* reset clip to extent */
	rtgui_region_reset(&(widget->clip), &(widget->extent));

	/* limit widget extent in parent extent */
	rtgui_region_intersect(&(widget->clip), &(widget->clip), &(parent->clip));

	/* get the no transparent parent */
	while (parent != RT_NULL && parent->flag & RTGUI_WIDGET_FLAG_TRANSPARENT)
	{
		parent = parent->parent;
	}

	if (parent != RT_NULL)
	{
		/* subtract widget clip in parent clip */
		if (!(widget->flag & RTGUI_WIDGET_FLAG_TRANSPARENT))
		{
			rtgui_region_subtract_rect(&(parent->clip), &(parent->clip),
				&(widget->extent));
		}
	}

	/*
	 * note: since the layout widget introduction, the sibling widget will not
	 * intersect.
	 */

492
	/* if it's a view object, update the clip info of children */
B
bernard.xiong 已提交
493 494 495 496 497 498 499 500 501 502
	if (RTGUI_IS_CONTAINER(widget))
	{
		rtgui_widget_t* child;
		rtgui_list_foreach(node, &(RTGUI_CONTAINER(widget)->children))
		{
			child = rtgui_list_entry(node, rtgui_widget_t, sibling);

			rtgui_widget_update_clip(child);
		}
	}
503 504 505 506
	else if (RTGUI_IS_NOTEBOOK(widget))
	{
		rtgui_widget_update_clip(rtgui_notebook_get_current(RTGUI_NOTEBOOK(widget)));
	}
B
bernard.xiong 已提交
507 508
}

509
void rtgui_widget_show(struct rtgui_widget *widget)
B
bernard.xiong 已提交
510
{
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
	struct rtgui_event_show eshow;
	RT_ASSERT(widget != RT_NULL);

    if (!RTGUI_WIDGET_IS_HIDE(widget))
        return;

	RTGUI_EVENT_SHOW_INIT(&eshow);
	if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
	{
		RTGUI_OBJECT(widget)->event_handler(
				RTGUI_OBJECT(widget),
				&eshow);
	}
}

rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *event)
{
	struct rtgui_widget *widget = RTGUI_WIDGET(object);
B
bernard.xiong 已提交
529 530 531 532

	/* update the clip info of widget */
	RTGUI_WIDGET_UNHIDE(widget);
	rtgui_widget_update_clip(widget);
533 534 535

	if (widget->on_show != RT_NULL)
		widget->on_show(RTGUI_OBJECT(widget), RT_NULL);
536 537

	return RT_FALSE;
B
bernard.xiong 已提交
538 539
}

540
rt_bool_t rtgui_widget_onhide(struct rtgui_object *object, struct rtgui_event *event)
B
bernard.xiong 已提交
541
{
542 543
	struct rtgui_widget *widget = RTGUI_WIDGET(object);

B
bernard.xiong 已提交
544 545 546
	/* hide this widget */
	RTGUI_WIDGET_HIDE(widget);

547 548 549 550 551 552 553 554 555 556 557 558
	if (widget->parent != RT_NULL)
	{
		rtgui_widget_t *parent;

		parent = widget->parent;
		/* get the no transparent parent */
		while (parent != RT_NULL && parent->flag & RTGUI_WIDGET_FLAG_TRANSPARENT)
		{
			parent = parent->parent;
		}

		/* union widget rect */
559
		rtgui_region_union_rect(&(parent->clip), &(parent->clip), &(widget->extent));
560
	}
561 562 563

	if (widget->on_hide != RT_NULL)
		widget->on_hide(RTGUI_OBJECT(widget), RT_NULL);
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582

	return RT_FALSE;
}

void rtgui_widget_hide(struct rtgui_widget *widget)
{
	struct rtgui_event_hide ehide;
	RT_ASSERT(widget != RT_NULL);

    if (RTGUI_WIDGET_IS_HIDE(widget))
        return;

	RTGUI_EVENT_HIDE_INIT(&ehide);
	if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
	{
		RTGUI_OBJECT(widget)->event_handler(
				RTGUI_OBJECT(widget),
				&ehide);
	}
B
bernard.xiong 已提交
583 584
}

B
bernard.xiong 已提交
585 586 587
rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t* widget)
{
	rtgui_widget_t* parent;
588

B
bernard.xiong 已提交
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
	/* get parent widget */
	parent = widget->parent;
	while (parent->parent != RT_NULL && (RTGUI_WIDGET_FLAG(parent) & RTGUI_WIDGET_FLAG_TRANSPARENT))
		parent = parent->parent;

	/* get parent's color */
	if (parent != RT_NULL)
		return RTGUI_WIDGET_FOREGROUND(parent);

	return RTGUI_WIDGET_FOREGROUND(widget);
}

rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t* widget)
{
	rtgui_widget_t* parent;
	
	/* get parent widget */
	parent = widget->parent;
	while (parent->parent != RT_NULL && (RTGUI_WIDGET_FLAG(parent) & RTGUI_WIDGET_FLAG_TRANSPARENT))
		parent = parent->parent;

	/* get parent's color */
	if (parent != RT_NULL)
		return RTGUI_WIDGET_BACKGROUND(parent);

	return RTGUI_WIDGET_BACKGROUND(widget);
}

B
bernard.xiong 已提交
617 618 619 620 621 622 623 624
void rtgui_widget_update(rtgui_widget_t* widget)
{
	struct rtgui_event_paint paint;
	RTGUI_EVENT_PAINT_INIT(&paint);
	paint.wid = RT_NULL;

	RT_ASSERT(widget != RT_NULL);

625 626 627
    if (RTGUI_WIDGET_IS_HIDE(widget))
        return;

628
	if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
B
bernard.xiong 已提交
629
	{
630 631 632
		RTGUI_OBJECT(widget)->event_handler(
				RTGUI_OBJECT(widget),
				&paint.parent);
B
bernard.xiong 已提交
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
	}
}

rtgui_widget_t* rtgui_widget_get_next_sibling(rtgui_widget_t* widget)
{
	rtgui_widget_t* sibling = RT_NULL;

	if (widget->sibling.next != RT_NULL)
	{
		sibling = rtgui_list_entry(widget->sibling.next, rtgui_widget_t, sibling);
	}

	return sibling;
}

rtgui_widget_t* rtgui_widget_get_prev_sibling(rtgui_widget_t* widget)
{
	struct rtgui_list_node* node;
B
bernard.xiong 已提交
651
	rtgui_widget_t *sibling, *parent;
B
bernard.xiong 已提交
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667

	node = RT_NULL; sibling = RT_NULL;
	parent = widget->parent;
	if (parent != RT_NULL)
	{
		rtgui_list_foreach(node, &(RTGUI_CONTAINER(parent)->children))
		{
			if (node->next == &(widget->sibling))
				break;
		}
	}

	if (node != RT_NULL)
		sibling = rtgui_list_entry(node, rtgui_widget_t, sibling);

	return sibling;
B
bernard.xiong 已提交
668
}
B
bernard.xiong 已提交
669 670 671 672 673 674 675 676 677 678 679 680 681

#ifdef RTGUI_WIDGET_DEBUG
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/button.h>
void rtgui_widget_dump(rtgui_widget_t* widget)
{
	struct rtgui_object *obj;

	obj = RTGUI_OBJECT(widget);
	rt_kprintf("widget type: %s ", obj->type->name);

	if (RTGUI_IS_WIN(widget) == RT_TRUE)
		rt_kprintf(":%s ", RTGUI_WIN(widget)->title);
682
	else if ((RTGUI_IS_LABEL(widget) == RT_TRUE) || (RTGUI_IS_BUTTON(widget) == RT_TRUE))
B
bernard.xiong 已提交
683 684 685 686 687 688 689
		rt_kprintf(":%s ", RTGUI_LABEL(widget)->text);

	rt_kprintf("extent(%d, %d) - (%d, %d)\n", widget->extent.x1, 
		widget->extent.y1, widget->extent.x2, widget->extent.y2);
	// rtgui_region_dump(&(widget->clip));
}
#endif