title.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * File : title.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/rtgui_theme.h>
  16. #include <rtgui/widgets/window.h>
  17. #include <rtgui/widgets/title.h>
  18. //#include "../server/mouse.h"
  19. /* there is no event handler in wintitle but handle the event on topwin of server */
  20. static void _rtgui_wintitle_constructor(rtgui_wintitle_t *wintitle)
  21. {
  22. RTGUI_WIDGET(wintitle)->flag = RTGUI_WIDGET_FLAG_DEFAULT;
  23. RTGUI_WIDGET_TEXTALIGN(wintitle) = RTGUI_ALIGN_CENTER_VERTICAL;
  24. rtgui_object_set_event_handler(RTGUI_OBJECT(wintitle),
  25. rtgui_wintile_event_handler);
  26. }
  27. static void _rtgui_wintitle_deconstructor(rtgui_wintitle_t *wintitle)
  28. {
  29. }
  30. DEFINE_CLASS_TYPE(wintitle, "wintitle",
  31. RTGUI_PARENT_TYPE(widget),
  32. _rtgui_wintitle_constructor,
  33. _rtgui_wintitle_deconstructor,
  34. sizeof(struct rtgui_wintitle));
  35. rtgui_wintitle_t *rtgui_wintitle_create(struct rtgui_win *window)
  36. {
  37. rtgui_wintitle_t *wintitle;
  38. wintitle = (rtgui_wintitle_t *)rtgui_widget_create(RTGUI_WINTITLE_TYPE);
  39. if (wintitle != RT_NULL)
  40. {
  41. RTGUI_WIDGET(wintitle)->toplevel = window;
  42. }
  43. return wintitle;
  44. }
  45. void rtgui_wintitle_destroy(rtgui_wintitle_t *wintitle)
  46. {
  47. rtgui_widget_destroy(RTGUI_WIDGET(wintitle));
  48. }
  49. rt_bool_t rtgui_wintile_event_handler(struct rtgui_object *obj, rtgui_event_t *eve)
  50. {
  51. struct rtgui_wintitle *wint;
  52. struct rtgui_win *win;
  53. RT_ASSERT(obj);
  54. RT_ASSERT(eve);
  55. wint = RTGUI_WINTITLE(obj);
  56. win = RTGUI_WIDGET(wint)->toplevel;
  57. RT_ASSERT(win);
  58. switch (eve->type)
  59. {
  60. case RTGUI_EVENT_PAINT:
  61. rtgui_theme_draw_win(wint);
  62. return RT_FALSE;
  63. case RTGUI_EVENT_MOUSE_BUTTON: {
  64. struct rtgui_event_mouse *emou = (struct rtgui_event_mouse *)eve;
  65. if (win->style & RTGUI_WIN_STYLE_CLOSEBOX)
  66. {
  67. rtgui_rect_t rect;
  68. /* get close button rect (device value) */
  69. rect.x1 = RTGUI_WIDGET(wint)->extent.x2 - WINTITLE_BORDER_SIZE - WINTITLE_CB_WIDTH - 3;
  70. rect.y1 = RTGUI_WIDGET(wint)->extent.y1 + WINTITLE_BORDER_SIZE + 3;
  71. rect.x2 = rect.x1 + WINTITLE_CB_WIDTH;
  72. rect.y2 = rect.y1 + WINTITLE_CB_HEIGHT;
  73. if (emou->button & RTGUI_MOUSE_BUTTON_LEFT)
  74. {
  75. if (emou->button & RTGUI_MOUSE_BUTTON_DOWN)
  76. {
  77. if (rtgui_rect_contains_point(&rect, emou->x, emou->y) == RT_EOK)
  78. {
  79. win->flag |= RTGUI_WIN_FLAG_CB_PRESSED;
  80. rtgui_theme_draw_win(wint);
  81. }
  82. #ifdef RTGUI_USING_WINMOVE
  83. else
  84. {
  85. rtgui_winrect_set(win);
  86. }
  87. #endif
  88. }
  89. else if (emou->button & RTGUI_MOUSE_BUTTON_UP)
  90. {
  91. if (win->flag & RTGUI_WIN_FLAG_CB_PRESSED &&
  92. rtgui_rect_contains_point(&rect,
  93. emou->x, emou->y) == RT_EOK)
  94. {
  95. rtgui_win_close(win);
  96. return RT_TRUE;
  97. }
  98. win->flag &= ~RTGUI_WIN_FLAG_CB_PRESSED;
  99. rtgui_theme_draw_win(wint);
  100. #ifdef RTGUI_USING_WINMOVE
  101. /* Reset the window movement state machine. */
  102. rtgui_winrect_moved_done(RT_NULL, RT_NULL);
  103. #endif
  104. }
  105. }
  106. }
  107. else if (emou->button & RTGUI_MOUSE_BUTTON_DOWN)
  108. {
  109. #ifdef RTGUI_USING_WINMOVE
  110. rtgui_winrect_set(win);
  111. #endif
  112. }
  113. }
  114. return RT_TRUE;
  115. default:
  116. return rtgui_widget_event_handler(obj, eve);
  117. }
  118. }