toplevel.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * File : toplevel.c
  3. * This file is part of 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-16 Bernard first version
  13. */
  14. #include <rtgui/rtgui_system.h>
  15. #include <rtgui/widgets/toplevel.h>
  16. static void _rtgui_toplevel_constructor(rtgui_toplevel_t *toplevel)
  17. {
  18. /* set event handler */
  19. rtgui_widget_set_event_handler(RTGUI_WIDGET(toplevel), rtgui_toplevel_event_handler);
  20. /* set toplevel to self */
  21. RTGUI_WIDGET(toplevel)->toplevel = RTGUI_WIDGET(toplevel);
  22. /* init toplevel property */
  23. toplevel->drawing = 0;
  24. /* hide toplevel default */
  25. RTGUI_WIDGET_HIDE(RTGUI_WIDGET(toplevel));
  26. /* set server as RT_NULL (no connected) */
  27. toplevel->server = RT_NULL;
  28. }
  29. static void _rtgui_toplevel_destructor(rtgui_toplevel_t* toplevel)
  30. {
  31. /* release external clip info */
  32. toplevel->drawing = 0;
  33. }
  34. DEFINE_CLASS_TYPE(toplevel, "toplevel",
  35. RTGUI_CONTAINER_TYPE,
  36. _rtgui_toplevel_constructor,
  37. _rtgui_toplevel_destructor,
  38. sizeof(struct rtgui_toplevel));
  39. rt_bool_t rtgui_toplevel_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
  40. {
  41. rtgui_toplevel_t* toplevel = (rtgui_toplevel_t*)widget;
  42. switch (event->type)
  43. {
  44. case RTGUI_EVENT_KBD:
  45. if (RTGUI_CONTAINER(toplevel)->focused != RT_NULL)
  46. {
  47. RTGUI_CONTAINER(toplevel)->focused->event_handler(RTGUI_CONTAINER(toplevel)->focused, event);
  48. }
  49. break;
  50. case RTGUI_EVENT_CLIP_INFO:
  51. /* update toplevel clip */
  52. rtgui_toplevel_update_clip(toplevel);
  53. break;
  54. case RTGUI_EVENT_TIMER:
  55. {
  56. struct rtgui_timer* timer;
  57. struct rtgui_event_timer* etimer = (struct rtgui_event_timer*) event;
  58. timer = etimer->timer;
  59. if (timer->timeout != RT_NULL)
  60. {
  61. /* call timeout function */
  62. timer->timeout(timer, timer->user_data);
  63. }
  64. }
  65. break;
  66. case RTGUI_EVENT_COMMAND:
  67. if (rtgui_container_dispatch_event(RTGUI_CONTAINER(widget), event) != RT_TRUE)
  68. {
  69. #ifndef RTGUI_USING_SMALL_SIZE
  70. if (widget->on_command != RT_NULL)
  71. {
  72. widget->on_command(widget, event);
  73. }
  74. #endif
  75. }
  76. else return RT_TRUE;
  77. break;
  78. default :
  79. return rtgui_container_event_handler(widget, event);
  80. }
  81. return RT_FALSE;
  82. }
  83. #include <rtgui/driver.h> /* to get screen rect */
  84. void rtgui_toplevel_update_clip(rtgui_toplevel_t* top)
  85. {
  86. rt_uint32_t idx;
  87. rtgui_container_t* container;
  88. struct rtgui_list_node* node;
  89. rtgui_rect_t screen_rect;
  90. if (top == RT_NULL) return;
  91. /* reset toplevel widget clip to extent */
  92. rtgui_region_reset(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->extent));
  93. /* subtract the screen rect */
  94. screen_rect.x1 = screen_rect.y1 = 0;
  95. screen_rect.x2 = rtgui_graphic_driver_get_default()->width;
  96. screen_rect.y2 = rtgui_graphic_driver_get_default()->height;
  97. rtgui_region_intersect_rect(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->clip),
  98. &screen_rect);
  99. /* subtract the external rect */
  100. rtgui_topwin_do_clip(RTGUI_WIDGET(top));
  101. /* update the clip info of each child */
  102. container = RTGUI_CONTAINER(top);
  103. rtgui_list_foreach(node, &(container->children))
  104. {
  105. rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling);
  106. rtgui_widget_update_clip(child);
  107. }
  108. }