widget.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. * File : widget.c
  3. * This file is part of RTGUI in RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-04 Bernard first version
  13. * 2010-06-26 Bernard add user_data to widget structure
  14. */
  15. #include <rtgui/dc_client.h>
  16. #include <rtgui/rtgui_app.h>
  17. #include <rtgui/widgets/widget.h>
  18. #include <rtgui/widgets/window.h>
  19. #include <rtgui/widgets/container.h>
  20. #include <rtgui/widgets/notebook.h>
  21. static void _rtgui_widget_constructor(rtgui_widget_t *widget)
  22. {
  23. if (!widget) return;
  24. /* set default flag */
  25. widget->flag = RTGUI_WIDGET_FLAG_DEFAULT;
  26. /* init list */
  27. rtgui_list_init(&(widget->sibling));
  28. /* init gc */
  29. widget->gc.foreground = default_foreground;
  30. widget->gc.background = default_background;
  31. widget->gc.font = rtgui_font_default();
  32. widget->gc.textstyle = RTGUI_TEXTSTYLE_NORMAL;
  33. widget->gc.textalign = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
  34. widget->align = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
  35. /* set parent and toplevel root */
  36. widget->parent = RT_NULL;
  37. widget->toplevel = RT_NULL;
  38. /* some common event handler */
  39. widget->on_focus_in = RT_NULL;
  40. widget->on_focus_out = RT_NULL;
  41. widget->on_show = RT_NULL;
  42. widget->on_hide = RT_NULL;
  43. #ifndef RTGUI_USING_SMALL_SIZE
  44. widget->on_draw = RT_NULL;
  45. widget->on_mouseclick = RT_NULL;
  46. widget->on_key = RT_NULL;
  47. widget->on_size = RT_NULL;
  48. widget->on_command = RT_NULL;
  49. #endif
  50. /* set default event handler */
  51. rtgui_object_set_event_handler(RTGUI_OBJECT(widget), rtgui_widget_event_handler);
  52. /* init user data private to 0 */
  53. widget->user_data = 0;
  54. /* init clip information */
  55. rtgui_region_init(&(widget->clip));
  56. /* init hardware dc */
  57. rtgui_dc_client_init(widget);
  58. }
  59. /* Destroys the widget */
  60. static void _rtgui_widget_destructor(rtgui_widget_t *widget)
  61. {
  62. if (widget == RT_NULL) return;
  63. if (widget->parent != RT_NULL)
  64. {
  65. /* remove widget from parent's children list */
  66. rtgui_list_remove(&(RTGUI_CONTAINER(widget->parent)->children), &(widget->sibling));
  67. widget->parent = RT_NULL;
  68. }
  69. /* fini clip region */
  70. rtgui_region_fini(&(widget->clip));
  71. }
  72. DEFINE_CLASS_TYPE(widget, "widget",
  73. RTGUI_OBJECT_TYPE,
  74. _rtgui_widget_constructor,
  75. _rtgui_widget_destructor,
  76. sizeof(struct rtgui_widget));
  77. rtgui_widget_t *rtgui_widget_create(rtgui_type_t *widget_type)
  78. {
  79. struct rtgui_widget* widget;
  80. widget = RTGUI_WIDGET(rtgui_object_create(widget_type));
  81. return widget;
  82. }
  83. void rtgui_widget_destroy(rtgui_widget_t* widget)
  84. {
  85. rtgui_object_destroy(RTGUI_OBJECT(widget));
  86. }
  87. void rtgui_widget_set_rect(rtgui_widget_t* widget, const rtgui_rect_t* rect)
  88. {
  89. if (widget == RT_NULL || rect == RT_NULL) return;
  90. widget->extent = *rect;
  91. /* reset mini width and height */
  92. widget->mini_width = rtgui_rect_width(widget->extent);
  93. widget->mini_height = rtgui_rect_height(widget->extent);
  94. /* it's not empty, fini it */
  95. if (rtgui_region_not_empty(&(widget->clip)))
  96. {
  97. rtgui_region_fini(&(widget->clip));
  98. }
  99. /* reset clip info */
  100. rtgui_region_init_with_extents(&(widget->clip), rect);
  101. if ((widget->parent != RT_NULL) && (widget->toplevel != RT_NULL))
  102. {
  103. /* update widget clip */
  104. rtgui_widget_update_clip(widget->parent);
  105. }
  106. }
  107. void rtgui_widget_set_rectangle(rtgui_widget_t* widget, int x, int y, int width, int height)
  108. {
  109. rtgui_rect_t rect;
  110. rect.x1 = x; rect.y1 = y;
  111. rect.x2 = x + width; rect.y2 = y + height;
  112. rtgui_widget_set_rect(widget, &rect);
  113. }
  114. void rtgui_widget_set_parent(rtgui_widget_t* widget, rtgui_widget_t* parent)
  115. {
  116. /* set parent and toplevel widget */
  117. widget->parent = parent;
  118. /* update children toplevel */
  119. if (parent->toplevel != RT_NULL &&
  120. RTGUI_IS_TOPLEVEL(parent->toplevel))
  121. {
  122. widget->toplevel = rtgui_widget_get_toplevel(parent);
  123. }
  124. }
  125. void rtgui_widget_get_extent(rtgui_widget_t* widget, rtgui_rect_t *rect)
  126. {
  127. RT_ASSERT(widget != RT_NULL);
  128. RT_ASSERT(rect != RT_NULL);
  129. *rect = widget->extent;
  130. }
  131. void rtgui_widget_set_miniwidth(rtgui_widget_t* widget, int width)
  132. {
  133. RT_ASSERT(widget != RT_NULL);
  134. widget->mini_width = width;
  135. }
  136. void rtgui_widget_set_miniheight(rtgui_widget_t* widget, int height)
  137. {
  138. RT_ASSERT(widget != RT_NULL);
  139. widget->mini_height = height;
  140. }
  141. /*
  142. * This function moves widget and its children to a logic point
  143. */
  144. void rtgui_widget_move_to_logic(rtgui_widget_t* widget, int dx, int dy)
  145. {
  146. struct rtgui_list_node* node;
  147. rtgui_widget_t* child;
  148. if (widget == RT_NULL) return;
  149. rtgui_rect_moveto(&(widget->extent), dx, dy);
  150. /* move each child */
  151. if (RTGUI_IS_CONTAINER(widget))
  152. {
  153. rtgui_list_foreach(node, &(RTGUI_CONTAINER(widget)->children))
  154. {
  155. child = rtgui_list_entry(node, rtgui_widget_t, sibling);
  156. rtgui_widget_move_to_logic(child, dx, dy);
  157. }
  158. }
  159. }
  160. void rtgui_widget_get_rect(rtgui_widget_t* widget, rtgui_rect_t *rect)
  161. {
  162. RT_ASSERT(widget != RT_NULL);
  163. if (rect != RT_NULL)
  164. {
  165. rect->x1 = rect->y1 = 0;
  166. rect->x2 = widget->extent.x2 - widget->extent.x1;
  167. rect->y2 = widget->extent.y2 - widget->extent.y1;
  168. }
  169. }
  170. void rtgui_widget_set_onfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
  171. {
  172. RT_ASSERT(widget != RT_NULL);
  173. widget->on_focus_in = handler;
  174. }
  175. void rtgui_widget_set_onunfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
  176. {
  177. RT_ASSERT(widget != RT_NULL);
  178. widget->on_focus_out = handler;
  179. }
  180. void rtgui_widget_set_onshow(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
  181. {
  182. RT_ASSERT(widget != RT_NULL);
  183. widget->on_show = handler;
  184. }
  185. void rtgui_widget_set_onhide(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
  186. {
  187. RT_ASSERT(widget != RT_NULL);
  188. widget->on_hide = handler;
  189. }
  190. #ifndef RTGUI_USING_SMALL_SIZE
  191. void rtgui_widget_set_ondraw(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
  192. {
  193. RT_ASSERT(widget != RT_NULL);
  194. widget->on_draw = handler;
  195. }
  196. void rtgui_widget_set_onmouseclick(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
  197. {
  198. RT_ASSERT(widget != RT_NULL);
  199. widget->on_mouseclick = handler;
  200. }
  201. void rtgui_widget_set_onkey(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
  202. {
  203. RT_ASSERT(widget != RT_NULL);
  204. widget->on_key = handler;
  205. }
  206. void rtgui_widget_set_onsize(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
  207. {
  208. RT_ASSERT(widget != RT_NULL);
  209. widget->on_size = handler;
  210. }
  211. void rtgui_widget_set_oncommand(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
  212. {
  213. RT_ASSERT(widget != RT_NULL);
  214. widget->on_command = handler;
  215. }
  216. #endif
  217. /**
  218. * @brief Focuses the widget. The focused widget is the widget which can receive the keyboard events
  219. * @param widget a widget
  220. * @note The widget has to be attached to a toplevel widget, otherwise it will have no effect
  221. */
  222. void rtgui_widget_focus(rtgui_widget_t *widget)
  223. {
  224. struct rtgui_widget *old_focus;
  225. RT_ASSERT(widget != RT_NULL);
  226. if (!RTGUI_WIDGET_IS_FOCUSABLE(widget) || !RTGUI_WIDGET_IS_ENABLE(widget))
  227. return;
  228. old_focus = RTGUI_WIN(widget->toplevel)->focused_widget;
  229. if (old_focus == widget)
  230. return; /* it's the same focused widget */
  231. /* unfocused the old widget */
  232. if (old_focus != RT_NULL)
  233. rtgui_widget_unfocus(old_focus);
  234. /* set widget as focused */
  235. widget->flag |= RTGUI_WIDGET_FLAG_FOCUS;
  236. RTGUI_WIN(widget->toplevel)->focused_widget = widget;
  237. /* invoke on focus in call back */
  238. if (widget->on_focus_in != RT_NULL)
  239. widget->on_focus_in(RTGUI_OBJECT(widget), RT_NULL);
  240. }
  241. /**
  242. * @brief Unfocused the widget
  243. * @param widget a widget
  244. */
  245. void rtgui_widget_unfocus(rtgui_widget_t *widget)
  246. {
  247. RT_ASSERT(widget != RT_NULL);
  248. if (!widget->toplevel || !RTGUI_WIDGET_IS_FOCUSED(widget))
  249. return;
  250. widget->flag &= ~RTGUI_WIDGET_FLAG_FOCUS;
  251. if (widget->on_focus_out != RT_NULL)
  252. widget->on_focus_out(RTGUI_OBJECT(widget), RT_NULL);
  253. RTGUI_WIN(widget->toplevel)->focused_widget = RT_NULL;
  254. /* refresh widget */
  255. rtgui_widget_update(widget);
  256. }
  257. void rtgui_widget_point_to_device(rtgui_widget_t* widget, rtgui_point_t* point)
  258. {
  259. RT_ASSERT(widget != RT_NULL);
  260. if (point != RT_NULL)
  261. {
  262. point->x += widget->extent.x1;
  263. point->y += widget->extent.y1;
  264. }
  265. }
  266. void rtgui_widget_rect_to_device(rtgui_widget_t* widget, rtgui_rect_t* rect)
  267. {
  268. RT_ASSERT(widget != RT_NULL);
  269. if (rect != RT_NULL)
  270. {
  271. rect->x1 += widget->extent.x1;
  272. rect->x2 += widget->extent.x1;
  273. rect->y1 += widget->extent.y1;
  274. rect->y2 += widget->extent.y1;
  275. }
  276. }
  277. void rtgui_widget_point_to_logic(rtgui_widget_t* widget, rtgui_point_t* point)
  278. {
  279. RT_ASSERT(widget != RT_NULL);
  280. if (point != RT_NULL)
  281. {
  282. point->x -= widget->extent.x1;
  283. point->y -= widget->extent.y1;
  284. }
  285. }
  286. void rtgui_widget_rect_to_logic(rtgui_widget_t* widget, rtgui_rect_t* rect)
  287. {
  288. RT_ASSERT(widget != RT_NULL);
  289. if (rect != RT_NULL)
  290. {
  291. rect->x1 -= widget->extent.x1;
  292. rect->x2 -= widget->extent.x1;
  293. rect->y1 -= widget->extent.y1;
  294. rect->y2 -= widget->extent.y1;
  295. }
  296. }
  297. struct rtgui_win* rtgui_widget_get_toplevel(rtgui_widget_t* widget)
  298. {
  299. rtgui_widget_t* r;
  300. RT_ASSERT(widget != RT_NULL);
  301. if (widget->toplevel)
  302. return widget->toplevel;
  303. rt_kprintf("widget->toplevel not properly set\n");
  304. r = widget;
  305. /* get the toplevel widget */
  306. while (r->parent != RT_NULL)
  307. r = r->parent;
  308. /* set toplevel */
  309. widget->toplevel = RTGUI_WIN(r);
  310. return RTGUI_WIN(r);
  311. }
  312. rt_bool_t rtgui_widget_event_handler(struct rtgui_object* object, rtgui_event_t* event)
  313. {
  314. RT_ASSERT(object != RT_NULL);
  315. RT_ASSERT(event != RT_NULL);
  316. switch (event->type)
  317. {
  318. case RTGUI_EVENT_SHOW:
  319. return rtgui_widget_onshow(object, event);
  320. case RTGUI_EVENT_HIDE:
  321. return rtgui_widget_onhide(object, event);
  322. #ifndef RTGUI_USING_SMALL_SIZE
  323. case RTGUI_EVENT_PAINT:
  324. if (widget->on_draw != RT_NULL)
  325. return widget->on_draw(RTGUI_OBJECT(widget), event);
  326. break;
  327. case RTGUI_EVENT_KBD:
  328. if (widget->on_key != RT_NULL)
  329. return widget->on_key(RTGUI_OBJECT(widget), event);
  330. break;
  331. case RTGUI_EVENT_MOUSE_BUTTON:
  332. if (widget->on_mouseclick != RT_NULL)
  333. return widget->on_mouseclick(RTGUI_OBJECT(widget), event);
  334. break;
  335. case RTGUI_EVENT_COMMAND:
  336. if (widget->on_command != RT_NULL)
  337. return widget->on_command(RTGUI_OBJECT(widget), event);
  338. break;
  339. case RTGUI_EVENT_RESIZE:
  340. if (widget->on_size != RT_NULL)
  341. return widget->on_size(RTGUI_OBJECT(widget), event);
  342. break;
  343. #endif
  344. }
  345. return RT_FALSE;
  346. }
  347. /*
  348. * This function updates the clip info of widget
  349. */
  350. void rtgui_widget_update_clip(rtgui_widget_t* widget)
  351. {
  352. struct rtgui_list_node* node;
  353. rtgui_widget_t *parent;
  354. /* no widget or widget is hide, no update clip */
  355. if (widget == RT_NULL || RTGUI_WIDGET_IS_HIDE(widget)) return;
  356. parent = widget->parent;
  357. /* if there is no parent, there is no clip to update. */
  358. if (parent == RT_NULL)
  359. {
  360. return;
  361. }
  362. /* reset clip to extent */
  363. rtgui_region_reset(&(widget->clip), &(widget->extent));
  364. /* limit widget extent in parent extent */
  365. rtgui_region_intersect(&(widget->clip), &(widget->clip), &(parent->clip));
  366. /* get the no transparent parent */
  367. while (parent != RT_NULL && parent->flag & RTGUI_WIDGET_FLAG_TRANSPARENT)
  368. {
  369. parent = parent->parent;
  370. }
  371. if (parent != RT_NULL)
  372. {
  373. /* subtract widget clip in parent clip */
  374. if (!(widget->flag & RTGUI_WIDGET_FLAG_TRANSPARENT))
  375. {
  376. rtgui_region_subtract_rect(&(parent->clip), &(parent->clip),
  377. &(widget->extent));
  378. }
  379. }
  380. /*
  381. * note: since the layout widget introduction, the sibling widget will not
  382. * intersect.
  383. */
  384. /* if it's a view object, update the clip info of children */
  385. if (RTGUI_IS_CONTAINER(widget))
  386. {
  387. rtgui_widget_t* child;
  388. rtgui_list_foreach(node, &(RTGUI_CONTAINER(widget)->children))
  389. {
  390. child = rtgui_list_entry(node, rtgui_widget_t, sibling);
  391. rtgui_widget_update_clip(child);
  392. }
  393. }
  394. else if (RTGUI_IS_NOTEBOOK(widget))
  395. {
  396. rtgui_widget_update_clip(rtgui_notebook_get_current(RTGUI_NOTEBOOK(widget)));
  397. }
  398. }
  399. void rtgui_widget_show(struct rtgui_widget *widget)
  400. {
  401. struct rtgui_event_show eshow;
  402. RT_ASSERT(widget != RT_NULL);
  403. if (!RTGUI_WIDGET_IS_HIDE(widget))
  404. return;
  405. RTGUI_EVENT_SHOW_INIT(&eshow);
  406. if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
  407. {
  408. RTGUI_OBJECT(widget)->event_handler(
  409. RTGUI_OBJECT(widget),
  410. &eshow);
  411. }
  412. }
  413. rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *event)
  414. {
  415. struct rtgui_widget *widget = RTGUI_WIDGET(object);
  416. /* update the clip info of widget */
  417. RTGUI_WIDGET_UNHIDE(widget);
  418. rtgui_widget_update_clip(widget);
  419. if (widget->on_show != RT_NULL)
  420. widget->on_show(RTGUI_OBJECT(widget), RT_NULL);
  421. return RT_FALSE;
  422. }
  423. rt_bool_t rtgui_widget_onhide(struct rtgui_object *object, struct rtgui_event *event)
  424. {
  425. struct rtgui_widget *widget = RTGUI_WIDGET(object);
  426. /* hide this widget */
  427. RTGUI_WIDGET_HIDE(widget);
  428. if (widget->parent != RT_NULL)
  429. {
  430. rtgui_widget_t *parent;
  431. parent = widget->parent;
  432. /* get the no transparent parent */
  433. while (parent != RT_NULL && parent->flag & RTGUI_WIDGET_FLAG_TRANSPARENT)
  434. {
  435. parent = parent->parent;
  436. }
  437. /* union widget rect */
  438. rtgui_region_union_rect(&(parent->clip), &(parent->clip), &(widget->extent));
  439. }
  440. if (widget->on_hide != RT_NULL)
  441. widget->on_hide(RTGUI_OBJECT(widget), RT_NULL);
  442. return RT_FALSE;
  443. }
  444. void rtgui_widget_hide(struct rtgui_widget *widget)
  445. {
  446. struct rtgui_event_hide ehide;
  447. RT_ASSERT(widget != RT_NULL);
  448. if (RTGUI_WIDGET_IS_HIDE(widget))
  449. return;
  450. RTGUI_EVENT_HIDE_INIT(&ehide);
  451. if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
  452. {
  453. RTGUI_OBJECT(widget)->event_handler(
  454. RTGUI_OBJECT(widget),
  455. &ehide);
  456. }
  457. }
  458. rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t* widget)
  459. {
  460. rtgui_widget_t* parent;
  461. /* get parent widget */
  462. parent = widget->parent;
  463. while (parent->parent != RT_NULL && (RTGUI_WIDGET_FLAG(parent) & RTGUI_WIDGET_FLAG_TRANSPARENT))
  464. parent = parent->parent;
  465. /* get parent's color */
  466. if (parent != RT_NULL)
  467. return RTGUI_WIDGET_FOREGROUND(parent);
  468. return RTGUI_WIDGET_FOREGROUND(widget);
  469. }
  470. rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t* widget)
  471. {
  472. rtgui_widget_t* parent;
  473. /* get parent widget */
  474. parent = widget->parent;
  475. while (parent->parent != RT_NULL && (RTGUI_WIDGET_FLAG(parent) & RTGUI_WIDGET_FLAG_TRANSPARENT))
  476. parent = parent->parent;
  477. /* get parent's color */
  478. if (parent != RT_NULL)
  479. return RTGUI_WIDGET_BACKGROUND(parent);
  480. return RTGUI_WIDGET_BACKGROUND(widget);
  481. }
  482. void rtgui_widget_update(rtgui_widget_t* widget)
  483. {
  484. struct rtgui_event_paint paint;
  485. RTGUI_EVENT_PAINT_INIT(&paint);
  486. paint.wid = RT_NULL;
  487. RT_ASSERT(widget != RT_NULL);
  488. if (RTGUI_WIDGET_IS_HIDE(widget))
  489. return;
  490. if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
  491. {
  492. RTGUI_OBJECT(widget)->event_handler(
  493. RTGUI_OBJECT(widget),
  494. &paint.parent);
  495. }
  496. }
  497. rtgui_widget_t* rtgui_widget_get_next_sibling(rtgui_widget_t* widget)
  498. {
  499. rtgui_widget_t* sibling = RT_NULL;
  500. if (widget->sibling.next != RT_NULL)
  501. {
  502. sibling = rtgui_list_entry(widget->sibling.next, rtgui_widget_t, sibling);
  503. }
  504. return sibling;
  505. }
  506. rtgui_widget_t* rtgui_widget_get_prev_sibling(rtgui_widget_t* widget)
  507. {
  508. struct rtgui_list_node* node;
  509. rtgui_widget_t *sibling, *parent;
  510. node = RT_NULL; sibling = RT_NULL;
  511. parent = widget->parent;
  512. if (parent != RT_NULL)
  513. {
  514. rtgui_list_foreach(node, &(RTGUI_CONTAINER(parent)->children))
  515. {
  516. if (node->next == &(widget->sibling))
  517. break;
  518. }
  519. }
  520. if (node != RT_NULL)
  521. sibling = rtgui_list_entry(node, rtgui_widget_t, sibling);
  522. return sibling;
  523. }
  524. #ifdef RTGUI_WIDGET_DEBUG
  525. #include <rtgui/widgets/label.h>
  526. #include <rtgui/widgets/button.h>
  527. void rtgui_widget_dump(rtgui_widget_t* widget)
  528. {
  529. struct rtgui_object *obj;
  530. obj = RTGUI_OBJECT(widget);
  531. rt_kprintf("widget type: %s ", obj->type->name);
  532. if (RTGUI_IS_WIN(widget) == RT_TRUE)
  533. rt_kprintf(":%s ", RTGUI_WIN(widget)->title);
  534. else if ((RTGUI_IS_LABEL(widget) == RT_TRUE) || (RTGUI_IS_BUTTON(widget) == RT_TRUE))
  535. rt_kprintf(":%s ", RTGUI_LABEL(widget)->text);
  536. rt_kprintf("extent(%d, %d) - (%d, %d)\n", widget->extent.x1,
  537. widget->extent.y1, widget->extent.x2, widget->extent.y2);
  538. // rtgui_region_dump(&(widget->clip));
  539. }
  540. #endif