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. extern void rtgui_topwin_do_clip(rtgui_widget_t* widget);
  17. static void _rtgui_toplevel_constructor(rtgui_toplevel_t *toplevel)
  18. {
  19. /* set event handler */
  20. rtgui_widget_set_event_handler(RTGUI_WIDGET(toplevel), rtgui_toplevel_event_handler);
  21. /* set toplevel to self */
  22. RTGUI_WIDGET(toplevel)->toplevel = RTGUI_WIDGET(toplevel);
  23. /* init toplevel property */
  24. toplevel->drawing = 0;
  25. /* hide toplevel default */
  26. RTGUI_WIDGET_HIDE(RTGUI_WIDGET(toplevel));
  27. /* set server as RT_NULL (no connected) */
  28. toplevel->server = RT_NULL;
  29. }
  30. static void _rtgui_toplevel_destructor(rtgui_toplevel_t* toplevel)
  31. {
  32. /* release external clip info */
  33. toplevel->drawing = 0;
  34. }
  35. DEFINE_CLASS_TYPE(toplevel, "toplevel",
  36. RTGUI_CONTAINER_TYPE,
  37. _rtgui_toplevel_constructor,
  38. _rtgui_toplevel_destructor,
  39. sizeof(struct rtgui_toplevel));
  40. rt_bool_t rtgui_toplevel_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
  41. {
  42. rtgui_toplevel_t* toplevel = (rtgui_toplevel_t*)widget;
  43. switch (event->type)
  44. {
  45. case RTGUI_EVENT_KBD:
  46. if (RTGUI_CONTAINER(toplevel)->focused != RT_NULL)
  47. {
  48. RTGUI_CONTAINER(toplevel)->focused->event_handler(RTGUI_CONTAINER(toplevel)->focused, event);
  49. }
  50. break;
  51. case RTGUI_EVENT_CLIP_INFO:
  52. /* update toplevel clip */
  53. rtgui_toplevel_update_clip(toplevel);
  54. break;
  55. case RTGUI_EVENT_TIMER:
  56. {
  57. struct rtgui_timer* timer;
  58. struct rtgui_event_timer* etimer = (struct rtgui_event_timer*) event;
  59. timer = etimer->timer;
  60. if (timer->timeout != RT_NULL)
  61. {
  62. /* call timeout function */
  63. timer->timeout(timer, timer->user_data);
  64. }
  65. }
  66. break;
  67. case RTGUI_EVENT_COMMAND:
  68. if (rtgui_container_dispatch_event(RTGUI_CONTAINER(widget), event) != RT_TRUE)
  69. {
  70. #ifndef RTGUI_USING_SMALL_SIZE
  71. if (widget->on_command != RT_NULL)
  72. {
  73. widget->on_command(widget, event);
  74. }
  75. #endif
  76. }
  77. else return RT_TRUE;
  78. break;
  79. default :
  80. return rtgui_container_event_handler(widget, event);
  81. }
  82. return RT_FALSE;
  83. }
  84. #include <rtgui/driver.h> /* to get screen rect */
  85. void rtgui_toplevel_update_clip(rtgui_toplevel_t* top)
  86. {
  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. }