title.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/widgets/title.h>
  15. #include <rtgui/rtgui_system.h>
  16. /* there is no event handler in wintitle but handle the event on topwin of server */
  17. static void _rtgui_wintitle_constructor(rtgui_wintitle_t *wintitle)
  18. {
  19. wintitle->title = RT_NULL;
  20. RTGUI_WIDGET(wintitle)->flag = RTGUI_WIDGET_FLAG_DEFAULT;
  21. RTGUI_WIDGET_TEXTALIGN(wintitle) = RTGUI_ALIGN_CENTER_VERTICAL;
  22. }
  23. static void _rtgui_wintitle_deconstructor(rtgui_wintitle_t *wintitle)
  24. {
  25. if (wintitle->title != RT_NULL)
  26. rt_free(wintitle->title);
  27. wintitle->title = RT_NULL;
  28. }
  29. DEFINE_CLASS_TYPE(wintitle, "wintitle",
  30. RTGUI_WIDGET_TYPE,
  31. _rtgui_wintitle_constructor,
  32. _rtgui_wintitle_deconstructor,
  33. sizeof(struct rtgui_wintitle));
  34. rtgui_wintitle_t *rtgui_wintitle_create(struct rtgui_win *window, const char *title)
  35. {
  36. rtgui_wintitle_t *wintitle;
  37. wintitle = (rtgui_wintitle_t *)rtgui_widget_create(RTGUI_WINTITLE_TYPE);
  38. if (wintitle != RT_NULL)
  39. {
  40. rtgui_wintitle_set_title(wintitle, title);
  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. void rtgui_wintitle_set_title(rtgui_wintitle_t *wintitle, const char *title)
  50. {
  51. RT_ASSERT(wintitle != RT_NULL);
  52. if (wintitle->title != RT_NULL)
  53. {
  54. rt_free(wintitle->title);
  55. }
  56. if (title != RT_NULL) wintitle->title = (char *)rt_strdup((const char *)title);
  57. else wintitle->title = RT_NULL;
  58. }
  59. char *rtgui_wintitle_get_title(rtgui_wintitle_t *wintitle)
  60. {
  61. RT_ASSERT(wintitle != RT_NULL);
  62. return wintitle->title;
  63. }