toplevel.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #include <rtgui/widgets/window.h>
  17. #include <rtgui/widgets/title.h>
  18. static void _rtgui_toplevel_constructor(rtgui_toplevel_t *toplevel)
  19. {
  20. /* set event handler */
  21. rtgui_object_set_event_handler(RTGUI_OBJECT(toplevel), rtgui_toplevel_event_handler);
  22. /* set toplevel to self */
  23. if (RTGUI_IS_WINTITLE(toplevel))
  24. RTGUI_WIDGET(toplevel)->toplevel = (struct rtgui_win*)toplevel;
  25. else
  26. RTGUI_WIDGET(toplevel)->toplevel = RTGUI_WIN(toplevel);
  27. /* init toplevel property */
  28. toplevel->drawing = 0;
  29. /* hide toplevel default */
  30. RTGUI_WIDGET_HIDE(RTGUI_WIDGET(toplevel));
  31. }
  32. static void _rtgui_toplevel_destructor(rtgui_toplevel_t* toplevel)
  33. {
  34. /* release external clip info */
  35. toplevel->drawing = 0;
  36. }
  37. DEFINE_CLASS_TYPE(toplevel, "toplevel",
  38. RTGUI_CONTAINER_TYPE,
  39. _rtgui_toplevel_constructor,
  40. _rtgui_toplevel_destructor,
  41. sizeof(struct rtgui_toplevel));
  42. rt_bool_t rtgui_toplevel_event_handler(struct rtgui_object* object, rtgui_event_t* event)
  43. {
  44. struct rtgui_toplevel* toplevel;
  45. RT_ASSERT(object != RT_NULL);
  46. RT_ASSERT(event != RT_NULL);
  47. toplevel = RTGUI_TOPLEVEL(object);
  48. switch (event->type)
  49. {
  50. case RTGUI_EVENT_CLIP_INFO:
  51. /* update toplevel clip */
  52. rtgui_toplevel_update_clip(toplevel);
  53. break;
  54. case RTGUI_EVENT_COMMAND:
  55. if (rtgui_container_dispatch_event(RTGUI_CONTAINER(object), event) != RT_TRUE)
  56. {
  57. #ifndef RTGUI_USING_SMALL_SIZE
  58. if (RTGUI_WIDGET(object)->on_command != RT_NULL)
  59. {
  60. RTGUI_WIDGET(object)->on_command(object, event);
  61. }
  62. #endif
  63. }
  64. else return RT_TRUE;
  65. break;
  66. default :
  67. return rtgui_container_event_handler(object, event);
  68. }
  69. return RT_FALSE;
  70. }
  71. void rtgui_toplevel_update_clip(rtgui_toplevel_t* top)
  72. {
  73. rtgui_container_t* view;
  74. struct rtgui_list_node* node;
  75. if (top == RT_NULL)
  76. return;
  77. /* update the clip info of each child */
  78. view = RTGUI_CONTAINER(top);
  79. rtgui_list_foreach(node, &(view->children))
  80. {
  81. rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling);
  82. rtgui_widget_update_clip(child);
  83. }
  84. }